mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-26 22:19:02 +00:00
Add ADT/IntEqClasses.h as a light-weight implementation of EquivalenceClasses.h.
This implementation already exists as ConnectedVNInfoEqClasses in LiveInterval.cpp, and it seems to be generally useful to have a light-weight way of forming equivalence classes of small integers. IntEqClasses doesn't allow enumeration of the elements in a class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122293 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
81
include/llvm/ADT/IntEqClasses.h
Normal file
81
include/llvm/ADT/IntEqClasses.h
Normal file
@@ -0,0 +1,81 @@
|
||||
//===-- llvm/ADT/IntEqClasses.h - Equiv. Classes of Integers ----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Equivalence classes for small integers. This is a mapping of the integers
|
||||
// 0 .. N-1 into M equivalence classes numbered 0 .. M-1.
|
||||
//
|
||||
// Initially each integer has its own equivalence class. Classes are joined by
|
||||
// passing a representative member of each class to join().
|
||||
//
|
||||
// Once the classes are built, compress() will number them 0 .. M-1 and prevent
|
||||
// further changes.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_ADT_INTEQCLASSES_H
|
||||
#define LLVM_ADT_INTEQCLASSES_H
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class IntEqClasses {
|
||||
/// EC - When uncompressed, map each integer to a smaller member of its
|
||||
/// equivalence class. The class leader is the smallest member and maps to
|
||||
/// itself.
|
||||
///
|
||||
/// When compressed, EC[i] is the equivalence class of i.
|
||||
SmallVector<unsigned, 8> EC;
|
||||
|
||||
/// NumClasses - The number of equivalence classes when compressed, or 0 when
|
||||
/// uncompressed.
|
||||
unsigned NumClasses;
|
||||
|
||||
public:
|
||||
/// IntEqClasses - Create an equivalence class mapping for 0 .. N-1.
|
||||
IntEqClasses(unsigned N) : NumClasses(0) { grow(N); }
|
||||
|
||||
/// grow - Increase capacity to hold 0 .. N-1, putting new integers in unique
|
||||
/// equivalence classes.
|
||||
/// This requires an uncompressed map.
|
||||
void grow(unsigned N);
|
||||
|
||||
/// join - Join the equivalence classes of a and b. After joining classes,
|
||||
/// findLeader(a) == findLeader(b).
|
||||
/// This requires an uncompressed map.
|
||||
void join(unsigned a, unsigned b);
|
||||
|
||||
/// findLeader - Compute the leader of a's equivalence class. This is the
|
||||
/// smallest member of the class.
|
||||
/// This requires an uncompressed map.
|
||||
unsigned findLeader(unsigned a) const;
|
||||
|
||||
/// compress - Compress equivalence classes by numbering them 0 .. M.
|
||||
/// This makes the equivalence class map immutable.
|
||||
void compress();
|
||||
|
||||
/// getNumClasses - Return the number of equivalence classes after compress()
|
||||
/// was called.
|
||||
unsigned getNumClasses() const { return NumClasses; }
|
||||
|
||||
/// operator[] - Return a's equivalence class number, 0 .. getNumClasses()-1.
|
||||
/// This requires a compressed map.
|
||||
unsigned operator[](unsigned a) const {
|
||||
assert(NumClasses && "operator[] called before compress()");
|
||||
return EC[a];
|
||||
}
|
||||
|
||||
/// uncompress - Change back to the uncompressed representation that allows
|
||||
/// editing.
|
||||
void uncompress();
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user