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 ||
22 (value == other.value && idType == other.idType &&
23 "Values of Identifiers are equal but their types do not match."));
24 return value == other.value;
28 os <<
"Id<" << value <<
">";
65 llvm_unreachable(
"VarKind does not exist!");
77 llvm_unreachable(
"VarKind does not exist!");
85 unsigned varLimit)
const {
91 unsigned overlapStart =
std::max(varStart, varRangeStart);
92 unsigned overlapEnd =
std::min(varLimit, varRangeEnd);
94 if (overlapStart > overlapEnd)
96 return overlapEnd - overlapStart;
100 assert(pos <
getNumVars() &&
"`pos` should represent a valid var position");
109 llvm_unreachable(
"`pos` should represent a valid var position");
129 identifiers.insert(identifiers.begin() + absolutePos, num,
Identifier());
136 assert(varLimit <=
getNumVarKind(kind) &&
"invalid var limit");
138 if (varStart >= varLimit)
141 unsigned numVarsEliminated = varLimit - varStart;
143 numDomain -= numVarsEliminated;
145 numRange -= numVarsEliminated;
147 numSymbols -= numVarsEliminated;
149 numLocals -= numVarsEliminated;
161 assert(srcKind != dstKind &&
"cannot convert variables to the same kind");
163 "invalid range for source variables");
165 "invalid position for destination variables");
171 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
173 if (dstOffset < srcOffset)
175 std::move(identifiers.begin() + srcOffset,
176 identifiers.begin() + srcOffset + num,
177 identifiers.begin() + dstOffset);
178 identifiers.erase(identifiers.begin() + srcOffset,
179 identifiers.begin() + srcOffset + num);
181 identifiers.erase(identifiers.begin() + srcOffset,
182 identifiers.begin() + srcOffset + num);
184 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
187 auto addVars = [&](
VarKind kind,
int num) {
204 addVars(srcKind, -(
signed)num);
205 addVars(dstKind, num);
226 std::swap(
getId(kindA, posA),
getId(kindB, posB));
245 "Both spaces should be using ids");
290 "invalid separation position");
291 numRange = numRange + numSymbols - newSymbolCount;
292 numSymbols = newSymbolCount;
298 assert(usingIds && other.usingIds &&
299 "Both spaces need to have identifers to merge & align");
309 auto *itr = std::find(findBegin, findEnd, identifier);
310 if (itr != findEnd) {
311 std::swap(findBegin, itr);
333 auto printIds = [&](
VarKind kind) {
356 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
void mergeAndAlignSymbols(PresburgerSpace &other)
Merge and align symbol variables of this and other with respect to identifiers.
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.