10 #include "llvm/Support/ErrorHandling.h"
11 #include "llvm/Support/raw_ostream.h"
16 using namespace presburger;
19 if (value ==
nullptr || other.value ==
nullptr)
21 assert(value == other.value && idType == other.idType &&
22 "Values of Identifiers are equal but their types do not match.");
23 return value == other.value;
27 os <<
"Id<" << value <<
">";
64 llvm_unreachable(
"VarKind does not exist!");
76 llvm_unreachable(
"VarKind does not exist!");
84 unsigned varLimit)
const {
90 unsigned overlapStart =
std::max(varStart, varRangeStart);
91 unsigned overlapEnd =
std::min(varLimit, varRangeEnd);
93 if (overlapStart > overlapEnd)
95 return overlapEnd - overlapStart;
99 assert(pos <
getNumVars() &&
"`pos` should represent a valid var position");
108 llvm_unreachable(
"`pos` should represent a valid var position");
128 identifiers.insert(identifiers.begin() + absolutePos, num,
Identifier());
135 assert(varLimit <=
getNumVarKind(kind) &&
"invalid var limit");
137 if (varStart >= varLimit)
140 unsigned numVarsEliminated = varLimit - varStart;
142 numDomain -= numVarsEliminated;
144 numRange -= numVarsEliminated;
146 numSymbols -= numVarsEliminated;
148 numLocals -= numVarsEliminated;
160 assert(srcKind != dstKind &&
"cannot convert variables to the same kind");
162 "invalid range for source variables");
164 "invalid position for destination variables");
170 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
172 if (dstOffset < srcOffset)
174 std::move(identifiers.begin() + srcOffset,
175 identifiers.begin() + srcOffset + num,
176 identifiers.begin() + dstOffset);
177 identifiers.erase(identifiers.begin() + srcOffset,
178 identifiers.begin() + srcOffset + num);
180 identifiers.erase(identifiers.begin() + srcOffset,
181 identifiers.begin() + srcOffset + num);
183 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
186 auto addVars = [&](
VarKind kind,
int num) {
203 addVars(srcKind, -(
signed)num);
204 addVars(dstKind, num);
225 std::swap(
getId(kindA, posA),
getId(kindB, posB));
244 "Both spaces should be using ids");
289 "invalid separation position");
290 numRange = numRange + numSymbols - newSymbolCount;
291 numSymbols = newSymbolCount;
303 auto printIds = [&](
VarKind kind) {
326 llvm::errs() <<
"\n";
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
static bool areIdsEqual(const PresburgerSpace &spaceA, const PresburgerSpace &spaceB, VarKind kind)
Checks if the number of ids of the given kind in the two spaces are equal and if the ids are equal.
An Identifier stores a pointer to an object, such as a Value or an Operation.
bool isEqual(const Identifier &other) const
Check if the two identifiers are equal.
void print(llvm::raw_ostream &os) const
PresburgerSpace is the space of all possible values of a tuple of integer valued variables/variables.
unsigned getNumRangeVars() const
PresburgerSpace getRangeSpace() const
unsigned getNumSymbolVars() const
unsigned getNumVarKind(VarKind kind) const
Get the number of vars of the specified kind.
unsigned getNumDimAndSymbolVars() const
bool isEqual(const PresburgerSpace &other) const
Returns true if both the spaces are equal including local variables i.e.
PresburgerSpace getDomainSpace() const
Get the domain/range space of this space.
Identifier & getId(VarKind kind, unsigned pos)
Get the identifier of the specified variable.
bool isUsingIds() const
Returns if identifiers are being used.
void convertVarKind(VarKind srcKind, unsigned srcPos, unsigned num, VarKind dstKind, unsigned dstPos)
Converts variables of the specified kind in the column range [srcPos, srcPos + num) to variables of t...
void removeVarRange(VarKind kind, unsigned varStart, unsigned varLimit)
Removes variables of the specified kind in the column range [varStart, varLimit).
unsigned getVarKindOffset(VarKind kind) const
Return the index at which the specified kind of var starts.
void setVarSymbolSeperation(unsigned newSymbolCount)
Changes the partition between dimensions and symbols.
unsigned getVarKindEnd(VarKind kind) const
Return the index at Which the specified kind of var ends.
unsigned getNumVars() const
unsigned getNumLocalVars() const
VarKind getVarKindAt(unsigned pos) const
Return the VarKind of the var at the specified position.
unsigned getNumDomainVars() const
unsigned getVarKindOverlap(VarKind kind, unsigned varStart, unsigned varLimit) const
Get the number of elements of the specified kind in the range [varStart, varLimit).
ArrayRef< Identifier > getIds(VarKind kind) const
bool isCompatible(const PresburgerSpace &other) const
Returns true if both the spaces are compatible i.e.
void print(llvm::raw_ostream &os) const
bool isAligned(const PresburgerSpace &other) const
Check if the spaces are compatible, and the non-local variables having same identifiers are in the sa...
PresburgerSpace getSpaceWithoutLocals() const
Get the space without local variables.
unsigned getNumDimVars() const
void swapVar(VarKind kindA, VarKind kindB, unsigned posA, unsigned posB)
Swaps the posA^th variable of kindA and posB^th variable of kindB.
unsigned insertVar(VarKind kind, unsigned pos, unsigned num=1)
Insert num variables of the specified kind at position pos.
Include the generated interface declarations.