diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h @@ -43,7 +43,7 @@ private: OptionalParseResult parseVar(VarKind vk, bool isOptional, - CreationPolicy creationPolicy, VarInfo::ID &id, + Policy creationPolicy, VarInfo::ID &id, bool &didCreate); FailureOr parseVarUsage(VarKind vk); FailureOr> parseVarBinding(VarKind vk, bool isOptional); diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp @@ -29,7 +29,7 @@ // Our variation on `AffineParser::{parseBareIdExpr,parseIdentifierDefinition}` OptionalParseResult DimLvlMapParser::parseVar(VarKind vk, bool isOptional, - CreationPolicy creationPolicy, + Policy creationPolicy, VarInfo::ID &varID, bool &didCreate) { // Save the current location so that we can have error messages point to @@ -70,21 +70,21 @@ // TODO(wrengr): these error messages make sense for our intended usage, // but not in general; but it's unclear how best to factor that part out. switch (creationPolicy) { - case CreationPolicy::MustNot: + case Policy::MustNot: return parser.emitError(loc, "use of undeclared identifier '" + name + "'"); - case CreationPolicy::May: - llvm_unreachable("got nullopt for CreationPolicy::May"); - case CreationPolicy::Must: + case Policy::May: + llvm_unreachable("got nullopt for Policy::May"); + case Policy::Must: return parser.emitError(loc, "redefinition of identifier '" + name + "'"); } - llvm_unreachable("unknown CreationPolicy"); + llvm_unreachable("unknown Policy"); } FailureOr DimLvlMapParser::parseVarUsage(VarKind vk) { VarInfo::ID varID; bool didCreate; - const auto res = parseVar(vk, /*isOptional=*/false, CreationPolicy::MustNot, - varID, didCreate); + const auto res = + parseVar(vk, /*isOptional=*/false, Policy::MustNot, varID, didCreate); if (!res.has_value() || failed(*res)) return failure(); return varID; @@ -94,8 +94,7 @@ DimLvlMapParser::parseVarBinding(VarKind vk, bool isOptional) { VarInfo::ID id; bool didCreate; - const auto res = - parseVar(vk, isOptional, CreationPolicy::Must, id, didCreate); + const auto res = parseVar(vk, isOptional, Policy::Must, id, didCreate); if (res.has_value()) { FAILURE_IF_FAILED(*res) return std::make_pair(env.bindVar(id), true); diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h @@ -390,8 +390,9 @@ // static_assert(IsZeroCostAbstraction); //===----------------------------------------------------------------------===// -enum class CreationPolicy { MustNot, May, Must }; +enum class Policy { MustNot, May, Must }; +//===----------------------------------------------------------------------===// class VarEnv final { /// Map from `VarKind` to the next free `Var::Num`; used by `bindVar`. VarKindArray nextNum; @@ -448,7 +449,7 @@ VarKind vk, bool verifyUsage = false); /// Attempts to lookup or create a variable according to the given - /// `CreationPolicy`. Returns nullopt in one of two circumstances: + /// `Policy`. Returns nullopt in one of two circumstances: /// (1) the policy says we `Must` create, yet the variable already exists; /// (2) the policy says we `MustNot` create, yet no such variable exists. /// Otherwise, if the variable already exists then it is validated against @@ -458,7 +459,7 @@ // TODO(wrengr): Prolly want to rename this to `create` and move the // current method of that name to being a private `createImpl`. std::optional> - lookupOrCreate(CreationPolicy policy, StringRef name, llvm::SMLoc loc, + lookupOrCreate(Policy creationPolicy, StringRef name, llvm::SMLoc loc, VarKind vk); /// Binds the given variable to the next free `Var::Num` for its `VarKind`. diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp @@ -242,10 +242,10 @@ } std::optional> -VarEnv::lookupOrCreate(CreationPolicy policy, StringRef name, llvm::SMLoc loc, +VarEnv::lookupOrCreate(Policy creationPolicy, StringRef name, llvm::SMLoc loc, VarKind vk) { - switch (policy) { - case CreationPolicy::MustNot: { + switch (creationPolicy) { + case Policy::MustNot: { const auto oid = lookup(name); if (!oid) return std::nullopt; // Doesn't exist, but must not create. @@ -254,9 +254,9 @@ #endif // NDEBUG return std::make_pair(*oid, false); } - case CreationPolicy::May: + case Policy::May: return create(name, loc, vk, /*verifyUsage=*/true); - case CreationPolicy::Must: { + case Policy::Must: { const auto res = create(name, loc, vk, /*verifyUsage=*/false); // const auto id = res.first; const auto didCreate = res.second; @@ -265,7 +265,7 @@ return res; } } - llvm_unreachable("unknown CreationPolicy"); + llvm_unreachable("unknown Policy"); } Var VarEnv::bindUnusedVar(VarKind vk) { return Var(vk, nextNum[vk]++); }