[Mlir-commits] [mlir] ad7a6b6 - [mlir][sparse] Renaming `CreationPolicy` to `Policy`
wren romano
llvmlistbot at llvm.org
Wed Jul 19 12:13:09 PDT 2023
Author: wren romano
Date: 2023-07-19T12:13:02-07:00
New Revision: ad7a6b672c7c30fbdb8b8fe2de78eca0d4741c8d
URL: https://github.com/llvm/llvm-project/commit/ad7a6b672c7c30fbdb8b8fe2de78eca0d4741c8d
DIFF: https://github.com/llvm/llvm-project/commit/ad7a6b672c7c30fbdb8b8fe2de78eca0d4741c8d.diff
LOG: [mlir][sparse] Renaming `CreationPolicy` to `Policy`
This change is mostly for brevity's sake; but it also paves the way for the `Policy` enum to be reuseable for other situations that require the same three-way semantics.
Reviewed By: Peiming
Differential Revision: https://reviews.llvm.org/D155532
Added:
Modified:
mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp
mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h
mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp
index 361425de73cc21..5d3e70e2fb2eb3 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp
@@ -29,7 +29,7 @@ using namespace mlir::sparse_tensor::ir_detail;
// 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 @@ OptionalParseResult DimLvlMapParser::parseVar(VarKind vk, bool isOptional,
// 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<VarInfo::ID> 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 @@ FailureOr<std::pair<Var, bool>>
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/DimLvlMapParser.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h
index 2cdf66b8de4b1c..b14ef370270d6b 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.h
@@ -43,7 +43,7 @@ class DimLvlMapParser final {
private:
OptionalParseResult parseVar(VarKind vk, bool isOptional,
- CreationPolicy creationPolicy, VarInfo::ID &id,
+ Policy creationPolicy, VarInfo::ID &id,
bool &didCreate);
FailureOr<VarInfo::ID> parseVarUsage(VarKind vk);
FailureOr<std::pair<Var, bool>> parseVarBinding(VarKind vk, bool isOptional);
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
index 7b67f8eece0da2..e126dab02b6a02 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
@@ -242,10 +242,10 @@ std::pair<VarInfo::ID, bool> VarEnv::create(StringRef name, llvm::SMLoc loc,
}
std::optional<std::pair<VarInfo::ID, bool>>
-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 @@ VarEnv::lookupOrCreate(CreationPolicy policy, StringRef name, llvm::SMLoc loc,
#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 @@ VarEnv::lookupOrCreate(CreationPolicy policy, StringRef name, llvm::SMLoc loc,
return res;
}
}
- llvm_unreachable("unknown CreationPolicy");
+ llvm_unreachable("unknown Policy");
}
Var VarEnv::bindUnusedVar(VarKind vk) { return Var(vk, nextNum[vk]++); }
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
index e5d5a97b7f3555..8365ff2ae54318 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.h
@@ -390,8 +390,9 @@ class VarInfo final {
// static_assert(IsZeroCostAbstraction<VarInfo>);
//===----------------------------------------------------------------------===//
-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<Var::Num> nextNum;
@@ -448,7 +449,7 @@ class VarEnv final {
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 @@ class VarEnv final {
// TODO(wrengr): Prolly want to rename this to `create` and move the
// current method of that name to being a private `createImpl`.
std::optional<std::pair<VarInfo::ID, bool>>
- 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`.
More information about the Mlir-commits
mailing list