diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -249,7 +249,7 @@ }]; 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() << ')'; @@ -266,27 +266,27 @@ static constexpr llvm::StringRef inType() { return "in_type"; } 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(lenpName())) return val.getInt(); return 0; } - + operand_range getLenParams() { return {operand_begin(), operand_begin() + numLenParams()}; } - + unsigned numShapeOperands() { return operand_end() - operand_begin() + numLenParams(); } - + operand_range getShapeOperands() { return {operand_begin() + numLenParams(), operand_end()}; } - + static mlir::Type getRefTy(mlir::Type ty); /// Get the input type of the allocation @@ -1056,7 +1056,7 @@ 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 @@ 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(lenpName())) + if (auto x = (*this)->getAttrOfType(lenpName())) return x.getInt(); return 0; } @@ -1135,7 +1135,7 @@ }]; let arguments = (ins AnyReferenceLike:$memref, AnyIntegerLike:$len); - + let results = (outs fir_BoxCharType); let assemblyFormat = [{ @@ -1213,13 +1213,13 @@ }]; 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(); @@ -1567,7 +1567,7 @@ p.printFunctionalType((*this)->getOperandTypes(), (*this)->getResultTypes()); }]; - + let verifier = [{ auto refTy = ref().getType(); if (fir::isa_ref_type(refTy)) { @@ -1587,7 +1587,7 @@ if (!ref().getType().dyn_cast()) 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()) return emitOpError("improperly constructed"); } else { @@ -1602,7 +1602,7 @@ CArg<"ArrayRef", "{}">:$attrs)>, OpBuilderDAG<(ins "Type":$type, "ValueRange":$operands, CArg<"ArrayRef", "{}">:$attrs)>]; - + let extraClassDeclaration = [{ static constexpr llvm::StringRef baseType() { return "base_type"; } mlir::Type getBaseType(); @@ -1690,8 +1690,8 @@ let printer = [{ p << getOperationName() << ' ' - << getAttrOfType(fieldAttrName()).getValue() << ", " - << getAttr(typeAttrName()); + << (*this)->getAttrOfType(fieldAttrName()).getValue() + << ", " << (*this)->getAttr(typeAttrName()); if (getNumOperands()) { p << '('; p.printOperands(lenparams()); @@ -1826,8 +1826,8 @@ let printer = [{ p << getOperationName() << ' ' - << getAttrOfType(fieldAttrName()).getValue() << ", " - << getAttr(typeAttrName()); + << (*this)->getAttrOfType(fieldAttrName()).getValue() + << ", " << (*this)->getAttr(typeAttrName()); }]; let builders = [ @@ -1841,7 +1841,7 @@ static constexpr llvm::StringRef fieldAttrName() { return "field_id"; } static constexpr llvm::StringRef typeAttrName() { return "on_type"; } mlir::Type getOnType() { - return getAttrOfType(typeAttrName()).getValue(); + return (*this)->getAttrOfType(typeAttrName()).getValue(); } }]; } @@ -2047,7 +2047,7 @@ CArg<"ValueRange", "llvm::None">:$iterArgs, CArg<"ArrayRef", "{}">:$attributes)> ]; - + let extraClassDeclaration = [{ mlir::Block *getBody() { return ®ion().front(); } mlir::Value getIterateVar() { return getBody()->getArgument(1); } @@ -2166,7 +2166,7 @@ }]; 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 @@ auto eleTy = getType().cast().getEleTy(); if (!eleTy.isa()) return emitOpError("must have !fir.char type"); - if (auto xl = getAttr(xlist())) { + if (auto xl = (*this)->getAttr(xlist())) { auto xList = xl.cast(); for (auto a : xList) if (!a.isa()) @@ -2265,12 +2265,12 @@ 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) @@ -2316,11 +2316,11 @@ }]; let arguments = (ins FirRealAttr:$constant); - + let results = (outs fir_RealType:$res); let assemblyFormat = "`(` $constant `)` attr-dict `:` type($res)"; - + let verifier = [{ if (!getType().isa()) return emitOpError("must be a !fir.real type"); @@ -2381,7 +2381,7 @@ static CmpFPredicate getPredicateByName(llvm::StringRef name); CmpFPredicate getPredicate() { - return (CmpFPredicate)getAttrOfType( + return (CmpFPredicate)(*this)->getAttrOfType( getPredicateAttrName()).getInt(); } }]; @@ -2397,7 +2397,7 @@ }]; let results = (outs fir_ComplexType); - + let parser = [{ fir::RealAttr realp; fir::RealAttr imagp; @@ -2415,11 +2415,11 @@ let printer = [{ p << getOperationName() << " (0x"; - auto f1 = getAttr(realAttrName()).cast(); + auto f1 = (*this)->getAttr(realAttrName()).cast(); auto i1 = f1.getValue().bitcastToAPInt(); p.getStream().write_hex(i1.getZExtValue()); p << ", 0x"; - auto f2 = getAttr(imagAttrName()).cast(); + auto f2 = (*this)->getAttr(imagAttrName()).cast(); auto i2 = f2.getValue().bitcastToAPInt(); p.getStream().write_hex(i2.getZExtValue()); p << ") : "; @@ -2436,8 +2436,8 @@ 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 @@ } CmpFPredicate getPredicate() { - return (CmpFPredicate)getAttrOfType( + return (CmpFPredicate)(*this)->getAttrOfType( getPredicateAttrName()).getInt(); } }]; @@ -2495,7 +2495,7 @@ def fir_AddrOfOp : fir_OneResultOp<"address_of", [NoSideEffect]> { let summary = "convert a symbol to an SSA value"; - + let description = [{ Convert a symbol (a function or global reference) to an SSA-value to be used in other Operations. @@ -2514,7 +2514,7 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoSideEffect]> { let summary = "encapsulates all Fortran scalar type conversions"; - + let description = [{ Generalized type conversion. Convert the ssa value from type T to type U. Not all pairs of types have conversions. When types T and U are the same @@ -2601,7 +2601,7 @@ }]; let printer = [{ - p << getOperationName() << ' ' << getAttr("in_type"); + p << getOperationName() << ' ' << (*this)->getAttr("in_type"); p.printOptionalAttrDict(getAttrs(), {"in_type"}); }]; @@ -2623,7 +2623,7 @@ let extraClassDeclaration = [{ mlir::Type getInType() { // get the type that the type descriptor describes - return getAttrOfType("in_type").getValue(); + return (*this)->getAttrOfType("in_type").getValue(); } }]; } @@ -2697,7 +2697,7 @@ 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,14 +2738,14 @@ /// The printable type of the global mlir::Type getType() { - return getAttrOfType(typeAttrName()).getValue(); + return (*this)->getAttrOfType(typeAttrName()).getValue(); } /// The semantic type of the global mlir::Type resultType() { return fir::AllocaOp::wrapResultType(getType()); } - + /// Return the initializer attribute if it exists, or a null attribute. Attribute getValueOrNull() { return initVal().getValueOr(Attribute()); } @@ -2768,8 +2768,9 @@ } mlir::FlatSymbolRefAttr getSymbol() { - return mlir::FlatSymbolRefAttr::get(getAttrOfType( - mlir::SymbolTable::getSymbolAttrName()).getValue(), getContext()); + return mlir::FlatSymbolRefAttr::get( + (*this)->getAttrOfType( + mlir::SymbolTable::getSymbolAttrName()).getValue(), getContext()); } }]; } @@ -2811,8 +2812,8 @@ }]; let printer = [{ - p << getOperationName() << ' ' << getAttr(lenParamAttrName()) << ", " - << getAttr(intAttrName()); + p << getOperationName() << ' ' << (*this)->getAttr(lenParamAttrName()) + << ", " << (*this)->getAttr(intAttrName()); }]; let extraClassDeclaration = [{ @@ -2865,7 +2866,7 @@ }]; let printer = [{ - auto tableName = getAttrOfType( + auto tableName = (*this)->getAttrOfType( mlir::SymbolTable::getSymbolAttrName()).getValue(); p << getOperationName() << " @" << tableName; @@ -2946,8 +2947,8 @@ }]; let printer = [{ - p << getOperationName() << ' ' << getAttr(methodAttrName()) << ", " - << getAttr(procAttrName()); + p << getOperationName() << ' ' << (*this)->getAttr(methodAttrName()) << ", " + << (*this)->getAttr(procAttrName()); }]; let extraClassDeclaration = [{ diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -123,8 +123,8 @@ return func; auto funTy = getTypeModel()(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/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -98,8 +98,8 @@ builder.setInsertionPointToStart(&block); builder.create(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 @@ const SmallVectorImpl &operandSegments) { llvm::ArrayRef argTy; Op op = builder.create(loc, argTy, operands); - op.setAttr(Op::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr(operandSegments)); + op->setAttr(Op::getOperandSegmentSizeAttr(), + builder.getI32VectorAttr(operandSegments)); return op; } @@ -231,8 +231,8 @@ auto loopOp = createRegionOp( 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 @@ 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(&clause.u)) { - loopOp.setAttr(mlir::acc::LoopOp::getSeqAttrName(), - firOpBuilder.getUnitAttr()); + loopOp->setAttr(mlir::acc::LoopOp::getSeqAttrName(), + firOpBuilder.getUnitAttr()); } else if (std::get_if( &clause.u)) { - loopOp.setAttr(mlir::acc::LoopOp::getIndependentAttrName(), - firOpBuilder.getUnitAttr()); + loopOp->setAttr(mlir::acc::LoopOp::getIndependentAttrName(), + firOpBuilder.getUnitAttr()); } else if (std::get_if(&clause.u)) { - loopOp.setAttr(mlir::acc::LoopOp::getAutoAttrName(), - firOpBuilder.getUnitAttr()); + loopOp->setAttr(mlir::acc::LoopOp::getAutoAttrName(), + firOpBuilder.getUnitAttr()); } } } @@ -425,14 +425,14 @@ 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/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -108,27 +108,6 @@ /// Return the operation that this refers to. Operation *getOperation() { return state; } - /// Return the dialect that this refers to. - Dialect *getDialect() { return getOperation()->getDialect(); } - - /// Return the parent Region of this operation. - Region *getParentRegion() { return getOperation()->getParentRegion(); } - - /// Returns the closest surrounding operation that contains this operation - /// or nullptr if this is a top-level operation. - Operation *getParentOp() { return getOperation()->getParentOp(); } - - /// Return the closest surrounding parent operation that is of type 'OpTy'. - template OpTy getParentOfType() { - return getOperation()->getParentOfType(); - } - - /// Returns the closest surrounding parent operation with trait `Trait`. - template