[Mlir-commits] [mlir] 3df6cad - [mlir] ODS: require DefaultValuedAttr to be const-buildable

Alex Zinenko llvmlistbot at llvm.org
Tue Feb 8 00:31:19 PST 2022


Author: Alex Zinenko
Date: 2022-02-08T09:31:09+01:00
New Revision: 3df6cadec45ec3db8e31706bd7f5015fd2543695

URL: https://github.com/llvm/llvm-project/commit/3df6cadec45ec3db8e31706bd7f5015fd2543695
DIFF: https://github.com/llvm/llvm-project/commit/3df6cadec45ec3db8e31706bd7f5015fd2543695.diff

LOG: [mlir] ODS: require DefaultValuedAttr to be const-buildable

ODS provides a mechanism for defalut-valued attributes based on a wrapper
TableGen class that is recognized by mlir-tblgen. Such attributes, if not set
on the operaiton, can be construted on-the-fly in their getter given a constant
value. In order for this construction to work, the attribute specificaiton in
ODS must set the constBuilderCall field correctly. This has not been verified,
which could lead to invalid C++ code being generated by mlir-tblgen.

Closes #53588.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D119113

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 7060fdfda1c22..6a45e1f7750ff 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -739,6 +739,10 @@ static void emitAttrGetterWithReturnType(FmtContext &fctx,
     // Returns the default value if not set.
     // TODO: this is inefficient, we are recreating the attribute for every
     // call. This should be set instead.
+    if (!attr.isConstBuildable()) {
+      PrintFatalError("DefaultValuedAttr of type " + attr.getAttrDefName() +
+                      " must have a constBuilder");
+    }
     std::string defaultValue = std::string(
         tgfmt(attr.getConstBuilderTemplate(), &fctx, attr.getDefaultValue()));
     body << "    if (!attr)\n      return "


        


More information about the Mlir-commits mailing list