[flang-commits] [flang] b077ee9 - [mlir][ods] Allow type attribute/operand for 0 result ops prefixed

Jacques Pienaar via flang-commits flang-commits at lists.llvm.org
Tue Feb 15 12:20:14 PST 2022


Author: Jacques Pienaar
Date: 2022-02-15T12:20:07-08:00
New Revision: b077ee9240f8b603d1dc8b43628fee0d4b94e963

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

LOG: [mlir][ods] Allow type attribute/operand for 0 result ops prefixed

Without results, there is no getType injected and so generating one in prefixed form doesn't result in any failures during C++ compilation.

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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/lib/Optimizer/Dialect/FIROps.cpp
    flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
    mlir/lib/TableGen/Operator.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index bc9f1fdae5f53..dd285032df095 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2768,11 +2768,6 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
     }
     static constexpr llvm::StringRef linkageAttrName() { return "linkName"; }
 
-    /// The printable type of the global
-    mlir::Type getType() {
-      return typeAttr().getValue();
-    }
-
     /// The semantic type of the global
     mlir::Type resultType();
 

diff  --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index cd6930ea2d5bb..935f35db572a0 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1229,7 +1229,7 @@ ParseResult GlobalOp::parse(OpAsmParser &parser, OperationState &result) {
   if (parser.parseColonType(globalType))
     return mlir::failure();
 
-  result.addAttribute(fir::GlobalOp::typeAttrName(result.name),
+  result.addAttribute(fir::GlobalOp::getTypeAttrName(result.name),
                       mlir::TypeAttr::get(globalType));
 
   if (simpleInitializer) {
@@ -1273,7 +1273,7 @@ void fir::GlobalOp::build(mlir::OpBuilder &builder, OperationState &result,
                           Attribute initialVal, StringAttr linkage,
                           ArrayRef<NamedAttribute> attrs) {
   result.addRegion();
-  result.addAttribute(typeAttrName(result.name), mlir::TypeAttr::get(type));
+  result.addAttribute(getTypeAttrName(result.name), mlir::TypeAttr::get(type));
   result.addAttribute(mlir::SymbolTable::getSymbolAttrName(),
                       builder.getStringAttr(name));
   result.addAttribute(symbolAttrNameStr(),

diff  --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
index d19f6d0cec298..d29114cb16080 100644
--- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
+++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
@@ -187,7 +187,7 @@ TEST_F(FIRBuilderTest, createGlobal1) {
   EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
   EXPECT_EQ("global1", global.getSymName());
   EXPECT_TRUE(global.getConstant().hasValue());
-  EXPECT_EQ(i64Type, global.type());
+  EXPECT_EQ(i64Type, global.getType());
   EXPECT_TRUE(global.getLinkName().hasValue());
   EXPECT_EQ(builder.createInternalLinkage().getValue(),
       global.getLinkName().getValue());
@@ -211,7 +211,7 @@ TEST_F(FIRBuilderTest, createGlobal2) {
   EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
   EXPECT_EQ("global2", global.getSymName());
   EXPECT_FALSE(global.getConstant().hasValue());
-  EXPECT_EQ(i32Type, global.type());
+  EXPECT_EQ(i32Type, global.getType());
   EXPECT_TRUE(global.getInitVal().hasValue());
   EXPECT_TRUE(global.getInitVal().getValue().isa<mlir::IntegerAttr>());
   EXPECT_EQ(
@@ -310,7 +310,7 @@ TEST_F(FIRBuilderTest, createStringLiteral) {
   EXPECT_EQ(builder.createLinkOnceLinkage().getValue(),
       global.getLinkName().getValue());
   EXPECT_EQ(fir::CharacterType::get(builder.getContext(), 1, strValue.size()),
-      global.type());
+      global.getType());
 
   auto stringLitOps = global.getRegion().front().getOps<fir::StringLitOp>();
   EXPECT_TRUE(llvm::hasSingleElement(stringLitOps));

diff  --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp
index c9815955062b3..a71ae4d642b13 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -701,8 +701,7 @@ getGetterOrSetterNames(bool isGetter, const Operator &op, StringRef name) {
   // is safer).
   auto skip = [&](StringRef newName) {
     bool shouldSkip = newName == "getAttributeNames" ||
-                      newName == "getAttributes" || newName == "getOperation" ||
-                      newName == "getType";
+                      newName == "getAttributes" || newName == "getOperation";
     if (newName == "getOperands") {
       // To reduce noise, skip generating the prefixed form and the warning if
       // $operands correspond to single variadic argument.
@@ -715,6 +714,11 @@ getGetterOrSetterNames(bool isGetter, const Operator &op, StringRef name) {
         return true;
       shouldSkip = true;
     }
+    if (newName == "getType") {
+      if (op.getNumResults() == 0)
+        return false;
+      shouldSkip = true;
+    }
     if (!shouldSkip)
       return false;
 


        


More information about the flang-commits mailing list