[Mlir-commits] [mlir] 953086d - [mlir][ODS] Use StringLiteral instead of StringRef when applicable
Mehdi Amini
llvmlistbot at llvm.org
Thu Feb 4 09:35:23 PST 2021
Author: Vladislav Vinogradov
Date: 2021-02-04T17:35:15Z
New Revision: 953086ddbb593289fafcf0e7cc6e74847f1635af
URL: https://github.com/llvm/llvm-project/commit/953086ddbb593289fafcf0e7cc6e74847f1635af
DIFF: https://github.com/llvm/llvm-project/commit/953086ddbb593289fafcf0e7cc6e74847f1635af.diff
LOG: [mlir][ODS] Use StringLiteral instead of StringRef when applicable
Use `StringLiteral` for function return type if it is known to return
constant string literals only.
This will make it visible to API users, that such values can be safely
stored, since they refers to constant data, which will never be deallocated.
`StringRef` is general is not safe to store for a long term,
since it might refer to temporal data allocated in heap.
Reviewed By: mehdi_amini, bkramer
Differential Revision: https://reviews.llvm.org/D95945
Added:
Modified:
mlir/include/mlir/IR/OpBase.td
mlir/test/mlir-tblgen/op-decl.td
mlir/tools/mlir-tblgen/DialectGen.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/PassGen.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 0bd1ee38bf1f..cd41902d7824 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1177,7 +1177,7 @@ class EnumAttrInfo<string name, list<EnumAttrCaseInfo> cases> {
// <return-type> <fn-name>(<qualified-enum-class-name>);
// ```
string symbolToStringFnName = "stringify" # name;
- string symbolToStringFnRetType = "::llvm::StringRef";
+ string symbolToStringFnRetType = "::llvm::StringLiteral";
// The name of the utility function that returns the max enum value used
// within the enum class. It will have the following signature:
diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td
index 91e46b59c2e6..955bf00063df 100644
--- a/mlir/test/mlir-tblgen/op-decl.td
+++ b/mlir/test/mlir-tblgen/op-decl.td
@@ -67,7 +67,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
// CHECK: public:
// CHECK: using Op::Op;
// CHECK: using Adaptor = AOpAdaptor;
-// CHECK: static ::llvm::StringRef getOperationName();
+// CHECK: static ::llvm::StringLiteral getOperationName();
// CHECK: ::mlir::Operation::operand_range getODSOperands(unsigned index);
// CHECK: ::mlir::Value a();
// CHECK: ::mlir::Operation::operand_range b();
diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index 43f3968ca9c8..1eb768ec5f27 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -75,7 +75,7 @@ class {0} : public ::mlir::Dialect {
void initialize();
friend class ::mlir::MLIRContext;
public:
- static ::llvm::StringRef getDialectNamespace() { return "{1}"; }
+ static ::llvm::StringLiteral getDialectNamespace() { return "{1}"; }
)";
/// Registration for a single dependent dialect: to be inserted in the ctor
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 2f0b3379d152..d7d3d65403b2 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2180,7 +2180,7 @@ void OpEmitter::genTraits() {
void OpEmitter::genOpNameGetter() {
auto *method = opClass.addMethodAndPrune(
- "::llvm::StringRef", "getOperationName", OpMethod::MP_Static);
+ "::llvm::StringLiteral", "getOperationName", OpMethod::MP_Static);
method->body() << " return \"" << op.getOperationName() << "\";\n";
}
diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index c1664a0c826c..5ffedcc55082 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -45,13 +45,17 @@ const char *const passDeclBegin = R"(
template <typename DerivedT>
class {0}Base : public {1} {
public:
+ using Base = {0}Base;
+
{0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
{0}Base(const {0}Base &) : {1}(::mlir::TypeID::get<DerivedT>()) {{}
/// Returns the command-line argument attached to this pass.
+ static ::llvm::StringLiteral getArgumentName() { return "{2}"; }
::llvm::StringRef getArgument() const override { return "{2}"; }
/// Returns the derived pass name.
+ static ::llvm::StringLiteral getPassName() { return "{0}"; }
::llvm::StringRef getName() const override { return "{0}"; }
/// Support isa/dyn_cast functionality for the derived pass class.
More information about the Mlir-commits
mailing list