[Mlir-commits] [mlir] 405af8e - [mlir] Make bit enum operators constexpr
Krzysztof Drewniak
llvmlistbot at llvm.org
Tue Sep 6 10:39:52 PDT 2022
Author: Krzysztof Drewniak
Date: 2022-09-06T17:39:44Z
New Revision: 405af8e520ecf3061b64891e8147ea7d9603b89a
URL: https://github.com/llvm/llvm-project/commit/405af8e520ecf3061b64891e8147ea7d9603b89a
DIFF: https://github.com/llvm/llvm-project/commit/405af8e520ecf3061b64891e8147ea7d9603b89a.diff
LOG: [mlir] Make bit enum operators constexpr
This allows using the | operator on the values of enum attributes
in complie-time constants.
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D133159
Added:
Modified:
mlir/tools/mlir-tblgen/EnumsGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index d473ee4173406..44a8035c0c021 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -134,25 +134,27 @@ getAllBitsUnsetCase(llvm::ArrayRef<EnumAttrCase> cases) {
// Emits the following inline function for bit enums:
//
-// inline <enum-type> operator|(<enum-type> a, <enum-type> b);
-// inline <enum-type> operator&(<enum-type> a, <enum-type> b);
-// inline <enum-type> bitEnumContains(<enum-type> a, <enum-type> b);
+// inline constexpr <enum-type> operator|(<enum-type> a, <enum-type> b);
+// inline constexpr <enum-type> operator&(<enum-type> a, <enum-type> b);
+// inline constexpr bool bitEnumContains(<enum-type> a, <enum-type> b);
static void emitOperators(const Record &enumDef, raw_ostream &os) {
EnumAttr enumAttr(enumDef);
StringRef enumName = enumAttr.getEnumClassName();
std::string underlyingType = std::string(enumAttr.getUnderlyingType());
- os << formatv("inline {0} operator|({0} lhs, {0} rhs) {{\n", enumName)
+ os << formatv("inline constexpr {0} operator|({0} lhs, {0} rhs) {{\n",
+ enumName)
<< formatv(" return static_cast<{0}>("
"static_cast<{1}>(lhs) | static_cast<{1}>(rhs));\n",
enumName, underlyingType)
<< "}\n";
- os << formatv("inline {0} operator&({0} lhs, {0} rhs) {{\n", enumName)
+ os << formatv("inline constexpr {0} operator&({0} lhs, {0} rhs) {{\n",
+ enumName)
<< formatv(" return static_cast<{0}>("
"static_cast<{1}>(lhs) & static_cast<{1}>(rhs));\n",
enumName, underlyingType)
<< "}\n";
os << formatv(
- "inline bool bitEnumContains({0} bits, {0} bit) {{\n"
+ "inline constexpr bool bitEnumContains({0} bits, {0} bit) {{\n"
" return (static_cast<{1}>(bits) & static_cast<{1}>(bit)) != 0;\n",
enumName, underlyingType)
<< "}\n";
More information about the Mlir-commits
mailing list