[Mlir-commits] [mlir] a1eb154 - [flang] Use mlir::OpState::operator->() to get to methods of mlir::Operation.

Christian Sigg llvmlistbot at llvm.org
Mon Dec 14 11:05:17 PST 2020


Author: Christian Sigg
Date: 2020-12-14T20:04:53+01:00
New Revision: a1eb154421a00d62f3a25057d262e1cac747e266

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

LOG: [flang] Use mlir::OpState::operator->() to get to methods of mlir::Operation.

This is a preparation step to remove those methods from OpState.

Reviewed By: ftynse

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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
    flang/lib/Lower/CharacterRuntime.cpp
    flang/lib/Lower/IO.cpp
    flang/lib/Lower/IntrinsicCall.cpp
    flang/lib/Lower/OpenACC.cpp
    flang/lib/Optimizer/Dialect/FIROps.cpp
    mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
    mlir/test/mlir-tblgen/op-attribute.td
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
    mlir/unittests/Pass/PassManagerTest.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 4ffca0395804..8d7a6d4af950 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -249,7 +249,7 @@ class fir_AllocatableOp<string mnemonic, list<OpTrait> traits = []> :
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr(inType());
+    p << getOperationName() << ' ' << (*this)->getAttr(inType());
     if (hasLenParams()) {
       // print the LEN parameters to a derived type in parens
       p << '(' << getLenParams() << " : " << getLenParams().getTypes() << ')';
@@ -267,7 +267,7 @@ class fir_AllocatableOp<string mnemonic, list<OpTrait> traits = []> :
     static constexpr llvm::StringRef lenpName() { return "len_param_count"; }
     mlir::Type getAllocatedType();
     
-    bool hasLenParams() { return bool{getAttr(lenpName())}; }
+    bool hasLenParams() { return bool{(*this)->getAttr(lenpName())}; }
     
     unsigned numLenParams() {
       if (auto val = (*this)->getAttrOfType<mlir::IntegerAttr>(lenpName()))
@@ -688,7 +688,7 @@ class fir_IntegralSwitchTerminatorOp<string mnemonic,
     p << getOperationName() << ' ';
     p.printOperand(getSelector());
     p << " : " << getSelector().getType() << " [";
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumConditions();
     for (decltype(count) i = 0; i != count; ++i) {
       if (i)
@@ -711,7 +711,7 @@ class fir_IntegralSwitchTerminatorOp<string mnemonic,
           getSelector().getType().isa<mlir::IndexType>() ||
           getSelector().getType().isa<fir::IntType>()))
       return emitOpError("must be an integer");
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumDest();
     if (count == 0)
       return emitOpError("must have at least one successor");
@@ -810,7 +810,7 @@ def fir_SelectCaseOp : fir_SwitchTerminatorOp<"select_case"> {
     p << getOperationName() << ' ';
     p.printOperand(getSelector());
     p << " : " << getSelector().getType() << " [";
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumConditions();
     for (decltype(count) i = 0; i != count; ++i) {
       if (i)
@@ -839,7 +839,7 @@ def fir_SelectCaseOp : fir_SwitchTerminatorOp<"select_case"> {
           getSelector().getType().isa<fir::LogicalType>() ||
           getSelector().getType().isa<fir::CharacterType>()))
       return emitOpError("must be an integer, character, or logical");
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumDest();
     if (count == 0)
       return emitOpError("must have at least one successor");
@@ -925,7 +925,7 @@ def fir_SelectTypeOp : fir_SwitchTerminatorOp<"select_type"> {
     p << getOperationName() << ' ';
     p.printOperand(getSelector());
     p << " : " << getSelector().getType() << " [";
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumConditions();
     for (decltype(count) i = 0; i != count; ++i) {
       if (i)
@@ -941,7 +941,7 @@ def fir_SelectTypeOp : fir_SwitchTerminatorOp<"select_type"> {
   let verifier = [{
     if (!(getSelector().getType().isa<fir::BoxType>()))
       return emitOpError("must be a boxed type");
-    auto cases = getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
+    auto cases = (*this)->getAttrOfType<mlir::ArrayAttr>(getCasesAttr()).getValue();
     auto count = getNumDest();
     if (count == 0)
       return emitOpError("must have at least one successor");
@@ -1056,7 +1056,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
     if (getNumOperands() == 2) {
       p << ", ";
       p.printOperands(dims());
-    } else if (auto map = getAttr(layoutName())) {
+    } else if (auto map = (*this)->getAttr(layoutName())) {
       p << " [" << map << ']';
     }
     p.printOptionalAttrDict(getAttrs(), {layoutName(), lenpName()});
@@ -1097,9 +1097,9 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
   let extraClassDeclaration = [{
     static constexpr llvm::StringRef layoutName() { return "layout_map"; }
     static constexpr llvm::StringRef lenpName() { return "len_param_count"; }
-    bool hasLenParams() { return bool{getAttr(lenpName())}; }
+    bool hasLenParams() { return bool{(*this)->getAttr(lenpName())}; }
     unsigned numLenParams() {
-      if (auto x = getAttrOfType<mlir::IntegerAttr>(lenpName()))
+      if (auto x = (*this)->getAttrOfType<mlir::IntegerAttr>(lenpName()))
         return x.getInt();
       return 0;
     }
@@ -1213,13 +1213,13 @@ def fir_EmboxProcOp : fir_Op<"emboxproc", [NoSideEffect]> {
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr("funcname");
+    p << getOperationName() << ' ' << (*this)->getAttr("funcname");
     auto h = host();
     if (h) {
       p << ", ";
       p.printOperand(h);
     }
-    p << " : (" << getAttr("functype");
+    p << " : (" << (*this)->getAttr("functype");
     if (h)
       p << ", " << h.getType();
     p << ") -> " << getType();
@@ -1587,7 +1587,7 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoSideEffect]> {
         if (!ref().getType().dyn_cast<BoxType>())
           return emitOpError("len_param_index must be used on box type");
       }
-    if (auto attr = getAttr(CoordinateOp::baseType())) {
+    if (auto attr = (*this)->getAttr(CoordinateOp::baseType())) {
       if (!attr.isa<mlir::TypeAttr>())
         return emitOpError("improperly constructed");
     } else {
@@ -1690,8 +1690,8 @@ def fir_FieldIndexOp : fir_OneResultOp<"field_index", [NoSideEffect]> {
 
   let printer = [{
     p << getOperationName() << ' '
-      << getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue() << ", "
-      << getAttr(typeAttrName());
+      << (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue() 
+      << ", " << (*this)->getAttr(typeAttrName());
     if (getNumOperands()) {
       p << '(';
       p.printOperands(lenparams());
@@ -1826,8 +1826,8 @@ def fir_LenParamIndexOp : fir_OneResultOp<"len_param_index", [NoSideEffect]> {
 
   let printer = [{
     p << getOperationName() << ' '
-      << getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue() << ", "
-      << getAttr(typeAttrName());
+      << (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
+      << ", " << (*this)->getAttr(typeAttrName());
   }];
 
   let builders = [
@@ -1841,7 +1841,7 @@ def fir_LenParamIndexOp : fir_OneResultOp<"len_param_index", [NoSideEffect]> {
     static constexpr llvm::StringRef fieldAttrName() { return "field_id"; }
     static constexpr llvm::StringRef typeAttrName() { return "on_type"; }
     mlir::Type getOnType() {
-      return getAttrOfType<TypeAttr>(typeAttrName()).getValue();
+      return (*this)->getAttrOfType<TypeAttr>(typeAttrName()).getValue();
     }
   }];
 }
@@ -2166,7 +2166,7 @@ def fir_DispatchOp : fir_Op<"dispatch",
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr("method") << '(';
+    p << getOperationName() << ' ' << (*this)->getAttr("method") << '(';
     p.printOperand(object());
     if (arg_operand_begin() != arg_operand_end()) {
       p << ", ";
@@ -2250,7 +2250,7 @@ def fir_StringLitOp : fir_Op<"string_lit", [NoSideEffect]> {
     auto eleTy = getType().cast<fir::SequenceType>().getEleTy();
     if (!eleTy.isa<fir::CharacterType>())
       return emitOpError("must have !fir.char type");
-    if (auto xl = getAttr(xlist())) {
+    if (auto xl = (*this)->getAttr(xlist())) {
       auto xList = xl.cast<mlir::ArrayAttr>();
       for (auto a : xList)
         if (!a.isa<mlir::IntegerAttr>())
@@ -2265,12 +2265,12 @@ def fir_StringLitOp : fir_Op<"string_lit", [NoSideEffect]> {
     static constexpr const char *xlist() { return "xlist"; }
 
     // Get the LEN attribute of this character constant
-    mlir::Attribute getSize() { return getAttr(size()); }
+    mlir::Attribute getSize() { return (*this)->getAttr(size()); }
     // Get the string value of this character constant
     mlir::Attribute getValue() {
-      if (auto attr = getAttr(value()))
+      if (auto attr = (*this)->getAttr(value()))
         return attr;
-      return getAttr(xlist());
+      return (*this)->getAttr(xlist());
     }
 
     /// Is this a wide character literal (1 character > 8 bits)
@@ -2381,7 +2381,7 @@ def fir_CmpfOp : fir_Op<"cmpf",
     static CmpFPredicate getPredicateByName(llvm::StringRef name);
 
     CmpFPredicate getPredicate() {
-      return (CmpFPredicate)getAttrOfType<mlir::IntegerAttr>(
+      return (CmpFPredicate)(*this)->getAttrOfType<mlir::IntegerAttr>(
           getPredicateAttrName()).getInt();
     }
   }];
@@ -2415,11 +2415,11 @@ def fir_ConstcOp : fir_Op<"constc", [NoSideEffect]> {
 
   let printer = [{
     p << getOperationName() << " (0x";
-    auto f1 = getAttr(realAttrName()).cast<mlir::FloatAttr>();
+    auto f1 = (*this)->getAttr(realAttrName()).cast<mlir::FloatAttr>();
     auto i1 = f1.getValue().bitcastToAPInt();
     p.getStream().write_hex(i1.getZExtValue());
     p << ", 0x";
-    auto f2 = getAttr(imagAttrName()).cast<mlir::FloatAttr>();
+    auto f2 = (*this)->getAttr(imagAttrName()).cast<mlir::FloatAttr>();
     auto i2 = f2.getValue().bitcastToAPInt();
     p.getStream().write_hex(i2.getZExtValue());
     p << ") : ";
@@ -2436,8 +2436,8 @@ def fir_ConstcOp : fir_Op<"constc", [NoSideEffect]> {
     static constexpr llvm::StringRef realAttrName() { return "real"; }
     static constexpr llvm::StringRef imagAttrName() { return "imaginary"; }
 
-    mlir::Attribute getReal() { return getAttr(realAttrName()); }
-    mlir::Attribute getImaginary() { return getAttr(imagAttrName()); }
+    mlir::Attribute getReal() { return (*this)->getAttr(realAttrName()); }
+    mlir::Attribute getImaginary() { return (*this)->getAttr(imagAttrName()); }
   }];
 }
 
@@ -2485,7 +2485,7 @@ def fir_CmpcOp : fir_Op<"cmpc",
     }
 
     CmpFPredicate getPredicate() {
-      return (CmpFPredicate)getAttrOfType<mlir::IntegerAttr>(
+      return (CmpFPredicate)(*this)->getAttrOfType<mlir::IntegerAttr>(
           getPredicateAttrName()).getInt();
     }
   }];
@@ -2601,7 +2601,7 @@ def fir_GenTypeDescOp : fir_OneResultOp<"gentypedesc", [NoSideEffect]> {
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr("in_type");
+    p << getOperationName() << ' ' << (*this)->getAttr("in_type");
     p.printOptionalAttrDict(getAttrs(), {"in_type"});
   }];
 
@@ -2623,7 +2623,7 @@ def fir_GenTypeDescOp : fir_OneResultOp<"gentypedesc", [NoSideEffect]> {
   let extraClassDeclaration = [{
     mlir::Type getInType() {
       // get the type that the type descriptor describes
-      return getAttrOfType<mlir::TypeAttr>("in_type").getValue();
+      return (*this)->getAttrOfType<mlir::TypeAttr>("in_type").getValue();
     }
   }];
 }
@@ -2697,7 +2697,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
     if (linkName().hasValue())
       p << ' ' << linkName().getValue();
     p << ' ';
-    p.printAttributeWithoutType(getAttr(symbolAttrName()));
+    p.printAttributeWithoutType((*this)->getAttr(symbolAttrName()));
     if (auto val = getValueOrNull())
       p << '(' << val << ')';
     if ((*this)->getAttr(constantAttrName()))
@@ -2738,7 +2738,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
 
     /// The printable type of the global
     mlir::Type getType() {
-      return getAttrOfType<TypeAttr>(typeAttrName()).getValue();
+      return (*this)->getAttrOfType<TypeAttr>(typeAttrName()).getValue();
     }
 
     /// The semantic type of the global
@@ -2768,8 +2768,9 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
     }
 
     mlir::FlatSymbolRefAttr getSymbol() {
-      return mlir::FlatSymbolRefAttr::get(getAttrOfType<mlir::StringAttr>(
-          mlir::SymbolTable::getSymbolAttrName()).getValue(), getContext());
+      return mlir::FlatSymbolRefAttr::get(
+          (*this)->getAttrOfType<mlir::StringAttr>(
+              mlir::SymbolTable::getSymbolAttrName()).getValue(), getContext());
     }
   }];
 }
@@ -2811,8 +2812,8 @@ def fir_GlobalLenOp : fir_Op<"global_len", []> {
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr(lenParamAttrName()) << ", "
-      << getAttr(intAttrName());
+    p << getOperationName() << ' ' << (*this)->getAttr(lenParamAttrName()) 
+      << ", " << (*this)->getAttr(intAttrName());
   }];
 
   let extraClassDeclaration = [{
@@ -2865,7 +2866,7 @@ def fir_DispatchTableOp : fir_Op<"dispatch_table",
   }];
 
   let printer = [{
-    auto tableName = getAttrOfType<StringAttr>(
+    auto tableName = (*this)->getAttrOfType<StringAttr>(
       mlir::SymbolTable::getSymbolAttrName()).getValue();
     p << getOperationName() << " @" << tableName;
 
@@ -2946,8 +2947,8 @@ def fir_DTEntryOp : fir_Op<"dt_entry", []> {
   }];
 
   let printer = [{
-    p << getOperationName() << ' ' << getAttr(methodAttrName()) << ", "
-      << getAttr(procAttrName());
+    p << getOperationName() << ' ' << (*this)->getAttr(methodAttrName()) << ", "
+      << (*this)->getAttr(procAttrName());
   }];
 
   let extraClassDeclaration = [{

diff  --git a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
index 43588ff17962..2d9ad28981ab 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
+++ b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
@@ -18,7 +18,7 @@ namespace fir {
 /// return true iff the Operation is a non-volatile LoadOp
 inline bool nonVolatileLoad(mlir::Operation *op) {
   if (auto load = dyn_cast<fir::LoadOp>(op))
-    return !load.getAttr("volatile");
+    return !load->getAttr("volatile");
   return false;
 }
 

diff  --git a/flang/lib/Lower/CharacterRuntime.cpp b/flang/lib/Lower/CharacterRuntime.cpp
index af95885f985d..4bfbf5824efb 100644
--- a/flang/lib/Lower/CharacterRuntime.cpp
+++ b/flang/lib/Lower/CharacterRuntime.cpp
@@ -62,7 +62,7 @@ static mlir::FuncOp getRuntimeFunc(mlir::Location loc,
     return func;
   auto funTy = getTypeModel<E>()(builder.getContext());
   func = builder.createFunction(loc, name, funTy);
-  func.setAttr("fir.runtime", builder.getUnitAttr());
+  func->setAttr("fir.runtime", builder.getUnitAttr());
   return func;
 }
 

diff  --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 3f79b79e32ee..ab7387dd3ce6 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -123,8 +123,8 @@ static mlir::FuncOp getIORuntimeFunc(mlir::Location loc,
     return func;
   auto funTy = getTypeModel<E>()(builder.getContext());
   func = builder.createFunction(loc, name, funTy);
-  func.setAttr("fir.runtime", builder.getUnitAttr());
-  func.setAttr("fir.io", builder.getUnitAttr());
+  func->setAttr("fir.runtime", builder.getUnitAttr());
+  func->setAttr("fir.io", builder.getUnitAttr());
   return func;
 }
 

diff  --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp
index 23b084eaf67d..0e0081ef664c 100644
--- a/flang/lib/Lower/IntrinsicCall.cpp
+++ b/flang/lib/Lower/IntrinsicCall.cpp
@@ -497,7 +497,7 @@ static mlir::FuncOp getFuncOp(mlir::Location loc,
                               const RuntimeFunction &runtime) {
   auto function = builder.addNamedFunction(
       loc, runtime.symbol, runtime.typeGenerator(builder.getContext()));
-  function.setAttr("fir.runtime", builder.getUnitAttr());
+  function->setAttr("fir.runtime", builder.getUnitAttr());
   return function;
 }
 
@@ -769,7 +769,7 @@ mlir::FuncOp IntrinsicLibrary::getWrapper(GeneratorType generator,
   if (!function) {
     // First time this wrapper is needed, build it.
     function = builder.createFunction(loc, wrapperName, funcType);
-    function.setAttr("fir.intrinsic", builder.getUnitAttr());
+    function->setAttr("fir.intrinsic", builder.getUnitAttr());
     function.addEntryBlock();
 
     // Create local context to emit code into the newly created function

diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 6f45bb623d7d..12cf97869543 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -98,8 +98,8 @@ static Op createRegionOp(Fortran::lower::FirOpBuilder &builder,
   builder.setInsertionPointToStart(&block);
   builder.create<Terminator>(loc);
 
-  op.setAttr(Op::getOperandSegmentSizeAttr(),
-             builder.getI32VectorAttr(operandSegments));
+  op->setAttr(Op::getOperandSegmentSizeAttr(),
+              builder.getI32VectorAttr(operandSegments));
 
   // Place the insertion point to the start of the first block.
   builder.setInsertionPointToStart(&block);
@@ -114,8 +114,8 @@ static Op createSimpleOp(Fortran::lower::FirOpBuilder &builder,
                          const SmallVectorImpl<int32_t> &operandSegments) {
   llvm::ArrayRef<mlir::Type> argTy;
   Op op = builder.create<Op>(loc, argTy, operands);
-  op.setAttr(Op::getOperandSegmentSizeAttr(),
-             builder.getI32VectorAttr(operandSegments));
+  op->setAttr(Op::getOperandSegmentSizeAttr(),
+              builder.getI32VectorAttr(operandSegments));
   return op;
 }
 
@@ -231,8 +231,8 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
     auto loopOp = createRegionOp<mlir::acc::LoopOp, mlir::acc::YieldOp>(
         firOpBuilder, currentLocation, operands, operandSegments);
 
-    loopOp.setAttr(mlir::acc::LoopOp::getExecutionMappingAttrName(),
-                   firOpBuilder.getI64IntegerAttr(executionMapping));
+    loopOp->setAttr(mlir::acc::LoopOp::getExecutionMappingAttrName(),
+                    firOpBuilder.getI64IntegerAttr(executionMapping));
 
     // Lower clauses mapped to attributes
     for (const auto &clause : accClauseList.v) {
@@ -241,19 +241,19 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
         const auto *expr = Fortran::semantics::GetExpr(collapseClause->v);
         const auto collapseValue = Fortran::evaluate::ToInt64(*expr);
         if (collapseValue) {
-          loopOp.setAttr(mlir::acc::LoopOp::getCollapseAttrName(),
-                         firOpBuilder.getI64IntegerAttr(*collapseValue));
+          loopOp->setAttr(mlir::acc::LoopOp::getCollapseAttrName(),
+                          firOpBuilder.getI64IntegerAttr(*collapseValue));
         }
       } else if (std::get_if<Fortran::parser::AccClause::Seq>(&clause.u)) {
-        loopOp.setAttr(mlir::acc::LoopOp::getSeqAttrName(),
-                       firOpBuilder.getUnitAttr());
+        loopOp->setAttr(mlir::acc::LoopOp::getSeqAttrName(),
+                        firOpBuilder.getUnitAttr());
       } else if (std::get_if<Fortran::parser::AccClause::Independent>(
                      &clause.u)) {
-        loopOp.setAttr(mlir::acc::LoopOp::getIndependentAttrName(),
-                       firOpBuilder.getUnitAttr());
+        loopOp->setAttr(mlir::acc::LoopOp::getIndependentAttrName(),
+                        firOpBuilder.getUnitAttr());
       } else if (std::get_if<Fortran::parser::AccClause::Auto>(&clause.u)) {
-        loopOp.setAttr(mlir::acc::LoopOp::getAutoAttrName(),
-                       firOpBuilder.getUnitAttr());
+        loopOp->setAttr(mlir::acc::LoopOp::getAutoAttrName(),
+                        firOpBuilder.getUnitAttr());
       }
     }
   }
@@ -425,14 +425,14 @@ genACCParallelOp(Fortran::lower::AbstractConverter &converter,
       firOpBuilder, currentLocation, operands, operandSegments);
 
   if (addAsyncAttr)
-    parallelOp.setAttr(mlir::acc::ParallelOp::getAsyncAttrName(),
-                       firOpBuilder.getUnitAttr());
+    parallelOp->setAttr(mlir::acc::ParallelOp::getAsyncAttrName(),
+                        firOpBuilder.getUnitAttr());
   if (addWaitAttr)
-    parallelOp.setAttr(mlir::acc::ParallelOp::getWaitAttrName(),
-                       firOpBuilder.getUnitAttr());
+    parallelOp->setAttr(mlir::acc::ParallelOp::getWaitAttrName(),
+                        firOpBuilder.getUnitAttr());
   if (addSelfAttr)
-    parallelOp.setAttr(mlir::acc::ParallelOp::getSelfAttrName(),
-                       firOpBuilder.getUnitAttr());
+    parallelOp->setAttr(mlir::acc::ParallelOp::getSelfAttrName(),
+                        firOpBuilder.getUnitAttr());
 }
 
 static void genACCDataOp(Fortran::lower::AbstractConverter &converter,

diff  --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 32d04b79c058..4a6c8d50e2ae 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -166,7 +166,7 @@ static void printCallOp(mlir::OpAsmPrinter &p, fir::CallOp &op) {
     p << callee.getValue();
   else
     p << op.getOperand(0);
-  p << '(' << op.getOperands().drop_front(isDirect ? 0 : 1) << ')';
+  p << '(' << op->getOperands().drop_front(isDirect ? 0 : 1) << ')';
   p.printOptionalAttrDict(op.getAttrs(), {fir::CallOp::calleeAttrName()});
   auto resultTypes{op.getResultTypes()};
   llvm::SmallVector<Type, 8> argTypes(
@@ -240,7 +240,8 @@ template <typename OPTY>
 static void printCmpOp(OpAsmPrinter &p, OPTY op) {
   p << op.getOperationName() << ' ';
   auto predSym = mlir::symbolizeCmpFPredicate(
-      op.template getAttrOfType<mlir::IntegerAttr>(OPTY::getPredicateAttrName())
+      op->template getAttrOfType<mlir::IntegerAttr>(
+            OPTY::getPredicateAttrName())
           .getInt());
   assert(predSym.hasValue() && "invalid symbol value for predicate");
   p << '"' << mlir::stringifyCmpFPredicate(predSym.getValue()) << '"' << ", ";
@@ -385,7 +386,10 @@ static mlir::ParseResult parseCoordinateOp(mlir::OpAsmParser &parser,
 }
 
 mlir::Type fir::CoordinateOp::getBaseType() {
-  return getAttr(CoordinateOp::baseType()).cast<mlir::TypeAttr>().getValue();
+  return (*this)
+      ->getAttr(CoordinateOp::baseType())
+      .cast<mlir::TypeAttr>()
+      .getValue();
 }
 
 void fir::CoordinateOp::build(OpBuilder &, OperationState &result,
@@ -412,7 +416,7 @@ void fir::CoordinateOp::build(OpBuilder &builder, OperationState &result,
 //===----------------------------------------------------------------------===//
 
 mlir::FunctionType fir::DispatchOp::getFunctionType() {
-  auto attr = getAttr("fn_type").cast<mlir::TypeAttr>();
+  auto attr = (*this)->getAttr("fn_type").cast<mlir::TypeAttr>();
   return attr.getValue().cast<mlir::FunctionType>();
 }
 
@@ -745,7 +749,7 @@ static void print(mlir::OpAsmPrinter &p, fir::IterWhileOp op) {
         [&](auto it) { p << std::get<0>(it) << " = " << std::get<1>(it); });
     p << ") -> (" << op.getResultTypes().drop_front() << ')';
   }
-  p.printOptionalAttrDictWithKeyword(op.getAttrs(), {});
+  p.printOptionalAttrDictWithKeyword(op->getAttrs(), {});
   p.printRegion(op.region(), /*printEntryBlockArgs=*/false,
                 /*printBlockTerminators=*/true);
 }
@@ -930,7 +934,7 @@ static void print(mlir::OpAsmPrinter &p, fir::LoopOp op) {
     p << ") -> (" << op.getResultTypes() << ')';
     printBlockTerminators = true;
   }
-  p.printOptionalAttrDictWithKeyword(op.getAttrs(),
+  p.printOptionalAttrDictWithKeyword(op->getAttrs(),
                                      {fir::LoopOp::unorderedAttrName()});
   p.printRegion(op.region(), /*printEntryBlockArgs=*/false,
                 printBlockTerminators);
@@ -963,9 +967,9 @@ mlir::OpFoldResult fir::MulfOp::fold(llvm::ArrayRef<mlir::Attribute> opnds) {
 //===----------------------------------------------------------------------===//
 
 static mlir::LogicalResult verify(fir::ResultOp op) {
-  auto parentOp = op.getParentOp();
+  auto *parentOp = op->getParentOp();
   auto results = parentOp->getResults();
-  auto operands = op.getOperands();
+  auto operands = op->getOperands();
 
   if (parentOp->getNumResults() != op.getNumOperands())
     return op.emitOpError() << "parent of result must have same arity";
@@ -1032,15 +1036,16 @@ fir::SelectOp::getMutableSuccessorOperands(unsigned oper) {
 llvm::Optional<llvm::ArrayRef<mlir::Value>>
 fir::SelectOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
                                     unsigned oper) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
-  auto segments =
-      getAttrOfType<mlir::DenseIntElementsAttr>(getOperandSegmentSizeAttr());
+  auto a =
+      (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
+  auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getOperandSegmentSizeAttr());
   return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
 }
 
 unsigned fir::SelectOp::targetOffsetSize() {
-  return denseElementsSize(
-      getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr()));
+  return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getTargetOffsetAttr()));
 }
 
 //===----------------------------------------------------------------------===//
@@ -1049,16 +1054,18 @@ unsigned fir::SelectOp::targetOffsetSize() {
 
 llvm::Optional<mlir::OperandRange>
 fir::SelectCaseOp::getCompareOperands(unsigned cond) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getCompareOffsetAttr());
+  auto a = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getCompareOffsetAttr());
   return {getSubOperands(cond, compareArgs(), a)};
 }
 
 llvm::Optional<llvm::ArrayRef<mlir::Value>>
 fir::SelectCaseOp::getCompareOperands(llvm::ArrayRef<mlir::Value> operands,
                                       unsigned cond) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getCompareOffsetAttr());
-  auto segments =
-      getAttrOfType<mlir::DenseIntElementsAttr>(getOperandSegmentSizeAttr());
+  auto a = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getCompareOffsetAttr());
+  auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getOperandSegmentSizeAttr());
   return {getSubOperands(cond, getSubOperands(1, operands, segments), a)};
 }
 
@@ -1071,9 +1078,10 @@ fir::SelectCaseOp::getMutableSuccessorOperands(unsigned oper) {
 llvm::Optional<llvm::ArrayRef<mlir::Value>>
 fir::SelectCaseOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
                                         unsigned oper) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
-  auto segments =
-      getAttrOfType<mlir::DenseIntElementsAttr>(getOperandSegmentSizeAttr());
+  auto a =
+      (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
+  auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getOperandSegmentSizeAttr());
   return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
 }
 
@@ -1152,13 +1160,13 @@ static mlir::ParseResult parseSelectCase(mlir::OpAsmParser &parser,
 }
 
 unsigned fir::SelectCaseOp::compareOffsetSize() {
-  return denseElementsSize(
-      getAttrOfType<mlir::DenseIntElementsAttr>(getCompareOffsetAttr()));
+  return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getCompareOffsetAttr()));
 }
 
 unsigned fir::SelectCaseOp::targetOffsetSize() {
-  return denseElementsSize(
-      getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr()));
+  return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getTargetOffsetAttr()));
 }
 
 void fir::SelectCaseOp::build(mlir::OpBuilder &builder,
@@ -1262,15 +1270,16 @@ fir::SelectRankOp::getMutableSuccessorOperands(unsigned oper) {
 llvm::Optional<llvm::ArrayRef<mlir::Value>>
 fir::SelectRankOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
                                         unsigned oper) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
-  auto segments =
-      getAttrOfType<mlir::DenseIntElementsAttr>(getOperandSegmentSizeAttr());
+  auto a =
+      (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
+  auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getOperandSegmentSizeAttr());
   return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
 }
 
 unsigned fir::SelectRankOp::targetOffsetSize() {
-  return denseElementsSize(
-      getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr()));
+  return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getTargetOffsetAttr()));
 }
 
 //===----------------------------------------------------------------------===//
@@ -1296,9 +1305,10 @@ fir::SelectTypeOp::getMutableSuccessorOperands(unsigned oper) {
 llvm::Optional<llvm::ArrayRef<mlir::Value>>
 fir::SelectTypeOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
                                         unsigned oper) {
-  auto a = getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
-  auto segments =
-      getAttrOfType<mlir::DenseIntElementsAttr>(getOperandSegmentSizeAttr());
+  auto a =
+      (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
+  auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getOperandSegmentSizeAttr());
   return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
 }
 
@@ -1348,8 +1358,8 @@ static ParseResult parseSelectType(OpAsmParser &parser,
 }
 
 unsigned fir::SelectTypeOp::targetOffsetSize() {
-  return denseElementsSize(
-      getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr()));
+  return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
+      getTargetOffsetAttr()));
 }
 
 //===----------------------------------------------------------------------===//
@@ -1467,7 +1477,7 @@ static void print(mlir::OpAsmPrinter &p, fir::WhereOp op) {
     p.printRegion(otherReg, /*printEntryBlockArgs=*/false,
                   printBlockTerminators);
   }
-  p.printOptionalAttrDict(op.getAttrs());
+  p.printOptionalAttrDict(op->getAttrs());
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 38b54ebadfc7..e0a8420e15b7 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -787,7 +787,7 @@ LogicalResult Importer::processFunction(llvm::Function *f) {
                            convertLinkageFromLLVM(f->getLinkage()));
 
   if (FlatSymbolRefAttr personality = getPersonalityAsAttr(f))
-    fop.setAttr(b.getIdentifier("personality"), personality);
+    fop->setAttr(b.getIdentifier("personality"), personality);
   else if (f->hasPersonalityFn())
     emitWarning(UnknownLoc::get(context),
                 "could not deduce personality, skipping it");

diff  --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index d5daebb57475..833f90dd28a2 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -48,13 +48,13 @@ def AOp : NS_Op<"a_op", []> {
 // ---
 
 // DEF:      some-attr-kind AOp::aAttrAttr()
-// DEF-NEXT:   (*this)->getAttr("aAttr").cast<some-attr-kind>()
+// DEF-NEXT:   (*this)->getAttr("aAttr").template cast<some-attr-kind>()
 // DEF:      some-return-type AOp::aAttr() {
 // DEF-NEXT:   auto attr = aAttrAttr()
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AOp::bAttrAttr()
-// DEF-NEXT:   return (*this)->getAttr("bAttr").dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   return (*this)->getAttr("bAttr").template dyn_cast_or_null<some-attr-kind>()
 // DEF:      some-return-type AOp::bAttr() {
 // DEF-NEXT:   auto attr = bAttrAttr();
 // DEF-NEXT:   if (!attr)
@@ -62,7 +62,7 @@ def AOp : NS_Op<"a_op", []> {
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AOp::cAttrAttr()
-// DEF-NEXT:   return (*this)->getAttr("cAttr").dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   return (*this)->getAttr("cAttr").template dyn_cast_or_null<some-attr-kind>()
 // DEF:      ::llvm::Optional<some-return-type> AOp::cAttr() {
 // DEF-NEXT:   auto attr = cAttrAttr()
 // DEF-NEXT:   return attr ? ::llvm::Optional<some-return-type>(attr.some-convert-from-storage()) : (::llvm::None);

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 5d756e708a43..f2a57fbbb00f 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -90,8 +90,7 @@ const char *adapterSegmentSizeAttrInitCode = R"(
   auto sizeAttr = odsAttrs.get("{0}").cast<::mlir::DenseIntElementsAttr>();
 )";
 const char *opSegmentSizeAttrInitCode = R"(
-  auto sizeAttr =
-      getOperation()->getAttrOfType<::mlir::DenseIntElementsAttr>("{0}");
+  auto sizeAttr = (*this)->getAttrOfType<::mlir::DenseIntElementsAttr>("{0}");
 )";
 const char *attrSizedSegmentValueRangeCalcCode = R"(
   unsigned start = 0;
@@ -521,7 +520,7 @@ void OpEmitter::genAttrGetters() {
     if (!method)
       return;
     auto &body = method->body();
-    body << "  return (*this)->getAttr(\"" << name << "\").";
+    body << "  return (*this)->getAttr(\"" << name << "\").template ";
     if (attr.isOptional() || attr.hasDefaultValue())
       body << "dyn_cast_or_null<";
     else

diff  --git a/mlir/unittests/Pass/PassManagerTest.cpp b/mlir/unittests/Pass/PassManagerTest.cpp
index d576f2b640a9..6e4283d3a3e4 100644
--- a/mlir/unittests/Pass/PassManagerTest.cpp
+++ b/mlir/unittests/Pass/PassManagerTest.cpp
@@ -34,13 +34,13 @@ struct AnnotateFunctionPass
     : public PassWrapper<AnnotateFunctionPass, OperationPass<FuncOp>> {
   void runOnOperation() override {
     FuncOp op = getOperation();
-    Builder builder(op.getParentOfType<ModuleOp>());
+    Builder builder(op->getParentOfType<ModuleOp>());
 
     auto &ga = getAnalysis<GenericAnalysis>();
     auto &sa = getAnalysis<OpSpecificAnalysis>();
 
-    op.setAttr("isFunc", builder.getBoolAttr(ga.isFunc));
-    op.setAttr("isSecret", builder.getBoolAttr(sa.isSecret));
+    op->setAttr("isFunc", builder.getBoolAttr(ga.isFunc));
+    op->setAttr("isSecret", builder.getBoolAttr(sa.isSecret));
   }
 };
 
@@ -66,12 +66,12 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
 
   // Verify that each function got annotated with expected attributes.
   for (FuncOp func : module->getOps<FuncOp>()) {
-    ASSERT_TRUE(func.getAttr("isFunc").isa<BoolAttr>());
-    EXPECT_TRUE(func.getAttr("isFunc").cast<BoolAttr>().getValue());
+    ASSERT_TRUE(func->getAttr("isFunc").isa<BoolAttr>());
+    EXPECT_TRUE(func->getAttr("isFunc").cast<BoolAttr>().getValue());
 
     bool isSecret = func.getName() == "secret";
-    ASSERT_TRUE(func.getAttr("isSecret").isa<BoolAttr>());
-    EXPECT_EQ(func.getAttr("isSecret").cast<BoolAttr>().getValue(), isSecret);
+    ASSERT_TRUE(func->getAttr("isSecret").isa<BoolAttr>());
+    EXPECT_EQ(func->getAttr("isSecret").cast<BoolAttr>().getValue(), isSecret);
   }
 }
 


        


More information about the Mlir-commits mailing list