30 llvm::raw_string_ostream os(
str);
61 int64_t maxSym = -1, maxVar = -1;
62 mlir::getMaxDimAndSymbol<ArrayRef<AffineExpr>>({{expr.
getAffineExpr()}},
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");
146 LLVM_ATTRIBUTE_UNUSED
static llvm::SMLoc
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;
160 const auto &var = env.
access(
id);
161 return (var.getName() == name && var.getID() ==
id);
166 const auto &var = env.
access(
id);
171 const auto iter = ids.find(name);
172 if (iter == ids.end())
174 const auto id = iter->second;
180 std::optional<std::pair<VarInfo::ID, bool>>
182 const auto &[iter, didInsert] = ids.try_emplace(name, nextID());
183 const auto id = iter->second;
185 vars.emplace_back(
id, name, loc, vk);
193 return std::make_pair(
id, didInsert);
196 std::optional<std::pair<VarInfo::ID, bool>>
199 switch (creationPolicy) {
201 const auto oid =
lookup(name);
206 return std::make_pair(*oid,
false);
209 return create(name, loc, vk,
true);
211 const auto res =
create(name, loc, vk,
false);
212 const auto didCreate = res->second;
218 llvm_unreachable(
"unknown Policy");
225 info.setNum(var.getNum());
230 for (
const auto &var : vars)
233 "Unbound variable: " + var.getName());
static LLVM_ATTRIBUTE_UNUSED llvm::SMLoc minSMLoc(AsmParser &parser, llvm::SMLoc sm1, llvm::SMLoc sm2)
Helper function for assertUsageConsistency to better handle SMLoc mismatches.
static constexpr const VarKind everyVarKind[]
For use in foreach loops.
bool isUsageConsistent(VarEnv const &env, VarInfo::ID id, llvm::SMLoc loc, VarKind vk)
bool isInternalConsistent(VarEnv const &env, VarInfo::ID id, StringRef name)
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 bool isValid(Var var) const
Var bindUnusedVar(VarKind vk)
Creates a new variable of the given kind and immediately binds it.
VarInfo const & access(VarInfo::ID id) const
Gets the underlying storage for the VarInfo identified by the VarInfo::ID.
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.
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
Efficient representation of a set of Var.
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.