30 llvm::raw_string_ostream os(
str);
61 int64_t maxSym = -1, maxVar = -1;
82 const llvm::SmallBitVector &bits =
impl[var.
getKind()];
83 const auto num = var.
getNum();
84 return num < bits.size() && bits[num];
98 assert(
impl[vk].size() >= other.impl[vk].size());
99 impl[vk] &= other.impl[vk];
127 llvm_unreachable(
"unknown AffineExprKind");
135 assert(!
hasNum() &&
"Var::Num is already set");
149 assert(loc1 &&
"Could not get `FileLineColLoc` for first `SMLoc`");
151 assert(loc2 &&
"Could not get `FileLineColLoc` for second `SMLoc`");
152 if (loc1.getFilename() != loc2.getFilename())
154 const auto pair1 = std::make_pair(loc1.getLine(), loc1.getColumn());
155 const auto pair2 = std::make_pair(loc2.getLine(), loc2.getColumn());
156 return pair1 <= pair2 ? sm1 : sm2;
161 const auto &var = env.
access(
id);
162 return (var.getName() == name && var.getID() ==
id);
167 const auto &var = env.
access(
id);
172 const auto iter = ids.find(name);
173 if (iter == ids.end())
175 const auto id = iter->second;
181std::optional<std::pair<VarInfo::ID, bool>>
183 const auto &[iter, didInsert] = ids.try_emplace(name, nextID());
184 const auto id = iter->second;
186 vars.emplace_back(
id, name, loc, vk);
194 return std::make_pair(
id, didInsert);
197std::optional<std::pair<VarInfo::ID, bool>>
200 switch (creationPolicy) {
202 const auto oid =
lookup(name);
207 return std::make_pair(*oid,
false);
210 return create(name, loc, vk,
true);
212 const auto res =
create(name, loc, vk,
false);
213 const auto didCreate = res->second;
219 llvm_unreachable(
"unknown Policy");
226 info.setNum(var.getNum());
231 for (
const auto &var : vars)
234 "Unbound variable: " + var.getName());
static constexpr const VarKind everyVarKind[]
For use in foreach loops.
static llvm::SMLoc minSMLoc(AsmParser &parser, llvm::SMLoc sm1, llvm::SMLoc sm2)
Helper function for assertUsageConsistency to better handle SMLoc mismatches.
static bool isInternalConsistent(VarEnv const &env, VarInfo::ID id, StringRef name)
static bool isUsageConsistent(VarEnv const &env, VarInfo::ID id, llvm::SMLoc loc, VarKind vk)
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual Location getEncodedSourceLoc(SMLoc loc)=0
Re-encode the given source location as an MLIR location and return it.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
This base class exposes generic asm printer hooks, usable across the various derived printers.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
This class represents a diagnostic that is inflight and set to be reported.
SymVar castSymVar() const
AffineExprKind getAffineKind() const
Var castDimLvlVar() const
constexpr AffineExpr getAffineExpr() const
std::tuple< DimLvlExpr, AffineExprKind, DimLvlExpr > unpackBinop() const
constexpr VarKind getAllowedVarKind() const
constexpr unsigned getRank(VarKind vk) const
bool operator==(Ranks const &other) const
constexpr unsigned getSymRank() const
constexpr Ranks(unsigned symRank, unsigned dimRank, unsigned lvlRank)
constexpr bool isValid(Var var) const
Var bindUnusedVar(VarKind vk)
Creates a new variable of the given kind and immediately binds it.
InFlightDiagnostic emitErrorIfAnyUnbound(AsmParser &parser) const
std::optional< std::pair< VarInfo::ID, bool > > lookupOrCreate(Policy creationPolicy, StringRef name, llvm::SMLoc loc, VarKind vk)
Looks up or creates a variable according to the given Policy.
std::optional< VarInfo::ID > lookup(StringRef name) const
Looks up the variable with the given name.
std::optional< std::pair< VarInfo::ID, bool > > create(StringRef name, llvm::SMLoc loc, VarKind vk, bool verifyUsage=false)
Creates a new currently-unbound variable.
Var bindVar(VarInfo::ID id)
Binds the given variable to the next free Var::Num for its VarKind.
VarInfo const & access(VarInfo::ID id) const
Gets the underlying storage for the VarInfo identified by the VarInfo::ID.
constexpr VarKind getKind() const
ID
Newtype for unique identifiers of VarInfo records, to ensure they aren't confused with Var::Num.
constexpr bool hasNum() const
bool contains(Var var) const
For the contains method: if variables occurring in the method parameter are OOB for the VarSet,...
VarSet(Ranks const &ranks)
void add(Var var)
For the add methods: OOB parameters cause undefined behavior.
A concrete variable, to be used in our variant of AffineExpr.
constexpr Num getNum() const
constexpr VarKind getKind() const
void print(llvm::raw_ostream &os) const
static constexpr bool isWF_Num(Num n)
Checks whether the number would be accepted by Var(VarKind,Var::Num).
unsigned Num
Typedef for the type of variable numbers.
VarKind
The three kinds of variables that Var can be.
constexpr char toChar(VarKind vk)
Gets the ASCII character used as the prefix when printing Var.
Include the generated interface declarations.
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ Mul
RHS of mul is always a constant or a symbolic expression.
@ Mod
RHS of mod is always a constant or a symbolic expression with a positive value.
@ DimId
Dimensional identifier.
@ FloorDiv
RHS of floordiv is always a constant or a symbolic expression.
@ Constant
Constant integer.
@ SymbolId
Symbolic identifier.
static void getMaxDimAndSymbol(ArrayRef< AffineExprContainer > exprsList, int64_t &maxDim, int64_t &maxSym)
Calculates maximum dimension and symbol positions from the expressions in exprsLists and stores them ...