30 llvm::raw_string_ostream os(
str);
41#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63 int64_t maxSym = -1, maxVar = -1;
84 const llvm::SmallBitVector &bits =
impl[var.
getKind()];
85 const auto num = var.
getNum();
86 return num < bits.size() && bits[num];
100 assert(
impl[vk].size() >= other.impl[vk].size());
101 impl[vk] &= other.impl[vk];
129 llvm_unreachable(
"unknown AffineExprKind");
137 assert(!
hasNum() &&
"Var::Num is already set");
151 assert(loc1 &&
"Could not get `FileLineColLoc` for first `SMLoc`");
153 assert(loc2 &&
"Could not get `FileLineColLoc` for second `SMLoc`");
154 if (loc1.getFilename() != loc2.getFilename())
156 const auto pair1 = std::make_pair(loc1.getLine(), loc1.getColumn());
157 const auto pair2 = std::make_pair(loc2.getLine(), loc2.getColumn());
158 return pair1 <= pair2 ? sm1 : sm2;
163 const auto &var = env.
access(
id);
164 return (var.getName() == name && var.getID() ==
id);
169 const auto &var = env.
access(
id);
174 const auto iter = ids.find(name);
175 if (iter == ids.end())
177 const auto id = iter->second;
183std::optional<std::pair<VarInfo::ID, bool>>
185 const auto &[iter, didInsert] = ids.try_emplace(name, nextID());
186 const auto id = iter->second;
188 vars.emplace_back(
id, name, loc, vk);
196 return std::make_pair(
id, didInsert);
199std::optional<std::pair<VarInfo::ID, bool>>
202 switch (creationPolicy) {
204 const auto oid =
lookup(name);
209 return std::make_pair(*oid,
false);
212 return create(name, loc, vk,
true);
214 const auto res =
create(name, loc, vk,
false);
215 const auto didCreate = res->second;
221 llvm_unreachable(
"unknown Policy");
228 info.setNum(var.getNum());
233 for (
const auto &var : vars)
236 "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
LLVM_DUMP_METHOD void dump() 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.
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 ...
@ 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.