From b6acd3a9523c22ac0ba26dc09865e024cd456256 Mon Sep 17 00:00:00 2001 From: Jay Tsou Date: Sat, 1 Nov 2025 13:05:15 -0700 Subject: [PATCH] [mlir-tblgen] Suffix underscore to prevent conflict In the case where the property name is value, the generated op def file would have a collision for hash_value. --- mlir/test/mlir-tblgen/op-properties.td | 14 +++++++------- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mlir/test/mlir-tblgen/op-properties.td b/mlir/test/mlir-tblgen/op-properties.td index a9c784cba0b6d..cb9bd3dc868fe 100644 --- a/mlir/test/mlir-tblgen/op-properties.td +++ b/mlir/test/mlir-tblgen/op-properties.td @@ -32,7 +32,7 @@ def OpWithProps : NS_Op<"op_with_props"> { ArrayProp:$strings, DefaultValuedProp:$default_int, OptionalProp:$optional, - DefaultI64Array:$intArray + DefaultI64Array:$value ); } @@ -94,10 +94,10 @@ def OpWithOptionalPropsAndAttrs : // DECL: ::llvm::ArrayRef getStrings() // DECL: using default_intTy = int32_t; // DECL: default_intTy default_int = 0; -// DECL: intArrayTy intArray = ::llvm::SmallVector{}; -// DECL: ::llvm::ArrayRef getIntArray() +// DECL: valueTy value = ::llvm::SmallVector{}; +// DECL: ::llvm::ArrayRef getValue() // DECL: return ::llvm::ArrayRef{propStorage} -// DECL: void setIntArray(::llvm::ArrayRef propValue) +// DECL: void setValue(::llvm::ArrayRef propValue) // DECL: propStorage.assign // DECL-LABEL: class OpWithProps : // DECL: setString(::llvm::StringRef newString) @@ -111,14 +111,14 @@ def OpWithOptionalPropsAndAttrs : // DECL-SAME: ::llvm::ArrayRef strings, // DECL-SAME: /*optional*/int32_t default_int = 0, // DECL-SAME: /*optional*/std::optional optional = std::nullopt, -// DECL-SAME: /*optional*/::llvm::ArrayRef intArray = ::llvm::ArrayRef{}); +// DECL-SAME: /*optional*/::llvm::ArrayRef value = ::llvm::ArrayRef{}); // DEFS-LABEL: OpWithProps::computePropertiesHash -// DEFS: hash_intArray +// DEFS: hash_value_ // DEFS: using ::llvm::hash_value; // DEFS-NEXT: return hash_value(::llvm::ArrayRef{propStorage}) // DEFS: hash_value(prop.optional) -// DEFS: hash_intArray(prop.intArray) +// DEFS: hash_value_(prop.value) // ----- diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 371864830a3c1..f92a26fb10e61 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1629,7 +1629,7 @@ void OpEmitter::genPropertiesSupport() { // Hashing for the property const char *propHashFmt = R"decl( - auto hash_{0} = [] (const auto &propStorage) -> llvm::hash_code { + auto hash_{0}_ = [] (const auto &propStorage) -> llvm::hash_code { using ::llvm::hash_value; return {1}; }; @@ -1655,7 +1655,7 @@ void OpEmitter::genPropertiesSupport() { if (const auto *namedProperty = llvm::dyn_cast_if_present(attrOrProp)) { if (!namedProperty->prop.getHashPropertyCall().empty()) { - hashMethod << "\n hash_" << namedProperty->name << "(prop." + hashMethod << "\n hash_" << namedProperty->name << "_(prop." << namedProperty->name << ")"; } else { hashMethod << "\n hash_value(prop." << namedProperty->name