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 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
22 assert(value != other.value ||
23 (value == other.value && idType == other.idType &&
24 "Values of Identifiers are equal but their types do not match."));
26 return value == other.value;
30 os <<
"Id<" << value <<
">";
67 llvm_unreachable(
"VarKind does not exist!");
79 llvm_unreachable(
"VarKind does not exist!");
87 unsigned varLimit)
const {
93 unsigned overlapStart =
std::max(varStart, varRangeStart);
94 unsigned overlapEnd =
std::min(varLimit, varRangeEnd);
96 if (overlapStart > overlapEnd)
98 return overlapEnd - overlapStart;
102 assert(pos <
getNumVars() &&
"`pos` should represent a valid var position");
111 llvm_unreachable(
"`pos` should represent a valid var position");
131 identifiers.insert(identifiers.begin() + absolutePos, num,
Identifier());
138 assert(varLimit <=
getNumVarKind(kind) &&
"invalid var limit");
140 if (varStart >= varLimit)
143 unsigned numVarsEliminated = varLimit - varStart;
145 numDomain -= numVarsEliminated;
147 numRange -= numVarsEliminated;
149 numSymbols -= numVarsEliminated;
151 numLocals -= numVarsEliminated;
163 assert(srcKind != dstKind &&
"cannot convert variables to the same kind");
165 "invalid range for source variables");
167 "invalid position for destination variables");
173 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
175 if (dstOffset < srcOffset)
177 std::move(identifiers.begin() + srcOffset,
178 identifiers.begin() + srcOffset + num,
179 identifiers.begin() + dstOffset);
180 identifiers.erase(identifiers.begin() + srcOffset,
181 identifiers.begin() + srcOffset + num);
183 identifiers.erase(identifiers.begin() + srcOffset,
184 identifiers.begin() + srcOffset + num);
186 identifiers.insert(identifiers.begin() + dstOffset, num,
Identifier());
189 auto addVars = [&](
VarKind kind,
int num) {
206 addVars(srcKind, -(
signed)num);
207 addVars(dstKind, num);
248 "Both spaces should be using ids");
293 "invalid separation position");
294 numRange = numRange + numSymbols - newSymbolCount;
295 numSymbols = newSymbolCount;
301 assert(usingIds && other.usingIds &&
302 "Both spaces need to have identifers to merge & align");
312 auto *itr = std::find(findBegin, findEnd, identifier);
313 if (itr != findEnd) {
314 std::swap(findBegin, itr);
336 auto printIds = [&](
VarKind kind) {
359 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
ArrayRef< Identifier > getIds() const
PresburgerSpace getRangeSpace() const
void setId(VarKind kind, unsigned pos, Identifier id)
Set the identifier of pos^th variable of the specified kind.
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.
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.
unsigned getVarKindEnd(VarKind kind) const
Return the index at Which the specified kind of var ends.
Identifier getId(VarKind kind, unsigned pos) const
Get the identifier of pos^th variable of the specified kind.
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.
void setVarSymbolSeparation(unsigned newSymbolCount)
Changes the partition between dimensions and symbols.
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.