diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -294,14 +294,14 @@ : ifOp{ifOp}, builder{builder} {} template IfBuilder &genThen(CC func) { - builder.setInsertionPointToStart(&ifOp.thenRegion().front()); + builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); func(); return *this; } template IfBuilder &genElse(CC func) { - assert(!ifOp.elseRegion().empty() && "must have else region"); - builder.setInsertionPointToStart(&ifOp.elseRegion().front()); + assert(!ifOp.getElseRegion().empty() && "must have else region"); + builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); func(); return *this; } diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.td b/flang/include/flang/Optimizer/Dialect/FIRDialect.td --- a/flang/include/flang/Optimizer/Dialect/FIRDialect.td +++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.td @@ -24,7 +24,7 @@ def fir_Dialect : Dialect { let name = "fir"; let cppNamespace = "::fir"; - let emitAccessorPrefix = kEmitAccessorPrefix_Both; + let emitAccessorPrefix = kEmitAccessorPrefix_Prefixed; let useDefaultTypePrinterParser = 0; let useDefaultAttributePrinterParser = 0; } 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 @@ -167,12 +167,12 @@ let extraClassDeclaration = [{ mlir::Type getAllocatedType(); - bool hasLenParams() { return !typeparams().empty(); } - bool hasShapeOperands() { return !shape().empty(); } - unsigned numLenParams() { return typeparams().size(); } - operand_range getLenParams() { return typeparams(); } - unsigned numShapeOperands() { return shape().size(); } - operand_range getShapeOperands() { return shape(); } + bool hasLenParams() { return !getTypeparams().empty(); } + bool hasShapeOperands() { return !getShape().empty(); } + unsigned numLenParams() { return getTypeparams().size(); } + operand_range getLenParams() { return getTypeparams(); } + unsigned numShapeOperands() { return getShape().size(); } + operand_range getShapeOperands() { return getShape(); } static mlir::Type getRefTy(mlir::Type ty); }]; } @@ -221,12 +221,12 @@ let extraClassDeclaration = [{ mlir::Type getAllocatedType(); - bool hasLenParams() { return !typeparams().empty(); } - bool hasShapeOperands() { return !shape().empty(); } - unsigned numLenParams() { return typeparams().size(); } - operand_range getLenParams() { return typeparams(); } - unsigned numShapeOperands() { return shape().size(); } - operand_range getShapeOperands() { return shape(); } + bool hasLenParams() { return !getTypeparams().empty(); } + bool hasShapeOperands() { return !getShape().empty(); } + unsigned numLenParams() { return getTypeparams().size(); } + operand_range getLenParams() { return getTypeparams(); } + unsigned numShapeOperands() { return getShape().size(); } + operand_range getShapeOperands() { return getShape(); } static mlir::Type getRefTy(mlir::Type ty); }]; } @@ -872,8 +872,8 @@ let hasVerifier = 1; let extraClassDeclaration = [{ - bool hasLenParams() { return !typeparams().empty(); } - unsigned numLenParams() { return typeparams().size(); } + bool hasLenParams() { return !getTypeparams().empty(); } + unsigned numLenParams() { return getTypeparams().size(); } }]; } @@ -1804,7 +1804,7 @@ let extraClassDeclaration = [{ static constexpr llvm::StringRef fieldAttrName() { return "field_id"; } static constexpr llvm::StringRef typeAttrName() { return "on_type"; } - llvm::StringRef getFieldName() { return field_id(); } + llvm::StringRef getFieldName() { return getFieldId(); } }]; } @@ -1868,7 +1868,7 @@ // Logically unzip the origins from the extent values. std::vector getOrigins() { std::vector result; - for (auto i : llvm::enumerate(pairs())) + for (auto i : llvm::enumerate(getPairs())) if (!(i.index() & 1)) result.push_back(i.value()); return result; @@ -1877,7 +1877,7 @@ // Logically unzip the extents from the origin values. std::vector getExtents() { std::vector result; - for (auto i : llvm::enumerate(pairs())) + for (auto i : llvm::enumerate(getPairs())) if (i.index() & 1) result.push_back(i.value()); return result; @@ -1970,7 +1970,7 @@ let hasVerifier = 1; let extraClassDeclaration = [{ - unsigned getOutRank() { return getOutputRank(triples()); } + unsigned getOutRank() { return getOutputRank(getTriples()); } static unsigned getOutputRank(mlir::ValueRange triples); }]; } @@ -2182,10 +2182,10 @@ } /// Get the body of the loop - mlir::Block *getBody() { return ®ion().front(); } + mlir::Block *getBody() { return &getRegion().front(); } void setUnordered() { - unorderedAttr(mlir::UnitAttr::get(getContext())); + setUnorderedAttr(mlir::UnitAttr::get(getContext())); } mlir::BlockArgument iterArgToBlockArg(mlir::Value iterArg); @@ -2229,13 +2229,13 @@ let extraClassDeclaration = [{ mlir::OpBuilder getThenBodyBuilder() { - assert(!thenRegion().empty() && "Unexpected empty 'where' region."); - mlir::Block &body = thenRegion().front(); + assert(!getThenRegion().empty() && "Unexpected empty 'where' region."); + mlir::Block &body = getThenRegion().front(); return mlir::OpBuilder(&body, std::prev(body.end())); } mlir::OpBuilder getElseBodyBuilder() { - assert(!elseRegion().empty() && "Unexpected empty 'other' region."); - mlir::Block &body = elseRegion().front(); + assert(!getElseRegion().empty() && "Unexpected empty 'other' region."); + mlir::Block &body = getElseRegion().front(); return mlir::OpBuilder(&body, std::prev(body.end())); } @@ -2298,7 +2298,7 @@ static constexpr llvm::StringRef getFinalValueAttrNameStr() { return "finalValue"; } - mlir::Block *getBody() { return ®ion().front(); } + mlir::Block *getBody() { return &getRegion().front(); } mlir::Value getIterateVar() { return getBody()->getArgument(1); } mlir::Value getInductionVar() { return getBody()->getArgument(0); } mlir::OpBuilder getBodyBuilder() { @@ -2777,7 +2777,7 @@ mlir::Type resultType(); /// Return the initializer attribute if it exists, or a null attribute. - Attribute getValueOrNull() { return initVal().getValueOr(Attribute()); } + Attribute getValueOrNull() { return getInitVal().getValueOr(Attribute()); } /// Append the next initializer value to the `GlobalOp` to construct /// the variable's initial value. diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -138,8 +138,8 @@ mlir::Value boxCharLen; if (auto *definingOp = character.getDefiningOp()) { if (auto box = dyn_cast(definingOp)) { - base = box.memref(); - boxCharLen = box.len(); + base = box.getMemref(); + boxCharLen = box.getLen(); } } if (!boxCharLen) { diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -436,7 +436,7 @@ auto ifOp = builder.create(loc, isAllocated, /*withElseRegion=*/false); auto insPt = builder.saveInsertionPoint(); - builder.setInsertionPointToStart(&ifOp.thenRegion().front()); + builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); genFinalizeAndFree(builder, loc, addr); builder.restoreInsertionPoint(insPt); } diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -309,7 +309,7 @@ mlir::ConversionPatternRewriter &rewriter) const override { auto ty = convertType(addr.getType()); rewriter.replaceOpWithNewOp( - addr, ty, addr.symbol().getRootReference().getValue()); + addr, ty, addr.getSymbol().getRootReference().getValue()); return success(); } }; @@ -416,7 +416,7 @@ mlir::Value a = adaptor.getOperands()[0]; auto loc = boxaddr.getLoc(); mlir::Type ty = convertType(boxaddr.getType()); - if (auto argty = boxaddr.val().getType().dyn_cast()) { + if (auto argty = boxaddr.getVal().getType().dyn_cast()) { rewriter.replaceOp(boxaddr, loadBaseAddrFromBox(loc, ty, a, rewriter)); } else { auto c0attr = rewriter.getI32IntegerAttr(0); @@ -640,7 +640,7 @@ mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); mlir::MLIRContext *ctxt = cmp.getContext(); - mlir::Type eleTy = convertType(getComplexEleTy(cmp.lhs().getType())); + mlir::Type eleTy = convertType(getComplexEleTy(cmp.getLhs().getType())); mlir::Type resTy = convertType(cmp.getType()); mlir::Location loc = cmp.getLoc(); auto pos0 = mlir::ArrayAttr::get(ctxt, rewriter.getI32IntegerAttr(0)); @@ -716,8 +716,8 @@ mlir::LogicalResult matchAndRewrite(fir::ConvertOp convert, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto fromTy = convertType(convert.value().getType()); - auto toTy = convertType(convert.res().getType()); + auto fromTy = convertType(convert.getValue().getType()); + auto toTy = convertType(convert.getRes().getType()); mlir::Value op0 = adaptor.getOperands()[0]; if (fromTy == toTy) { rewriter.replaceOp(convert, op0); @@ -739,18 +739,18 @@ return rewriter.create(loc, toTy, val); }; // Complex to complex conversion. - if (fir::isa_complex(convert.value().getType()) && - fir::isa_complex(convert.res().getType())) { + if (fir::isa_complex(convert.getValue().getType()) && + fir::isa_complex(convert.getRes().getType())) { // Special case: handle the conversion of a complex such that both the // real and imaginary parts are converted together. auto zero = mlir::ArrayAttr::get(convert.getContext(), rewriter.getI32IntegerAttr(0)); auto one = mlir::ArrayAttr::get(convert.getContext(), rewriter.getI32IntegerAttr(1)); - auto ty = convertType(getComplexEleTy(convert.value().getType())); + auto ty = convertType(getComplexEleTy(convert.getValue().getType())); auto rp = rewriter.create(loc, ty, op0, zero); auto ip = rewriter.create(loc, ty, op0, one); - auto nt = convertType(getComplexEleTy(convert.res().getType())); + auto nt = convertType(getComplexEleTy(convert.getRes().getType())); auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(ty); auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(nt); auto rc = convertFpToFp(rp, fromBits, toBits, nt); @@ -1051,29 +1051,29 @@ tyAttr = tyAttr.cast().getElementType(); auto loc = global.getLoc(); mlir::Attribute initAttr{}; - if (global.initVal()) - initAttr = global.initVal().getValue(); - auto linkage = convertLinkage(global.linkName()); - auto isConst = global.constant().hasValue(); + if (global.getInitVal()) + initAttr = global.getInitVal().getValue(); + auto linkage = convertLinkage(global.getLinkName()); + auto isConst = global.getConstant().hasValue(); auto g = rewriter.create( loc, tyAttr, isConst, linkage, global.getSymName(), initAttr); auto &gr = g.getInitializerRegion(); - rewriter.inlineRegionBefore(global.region(), gr, gr.end()); + rewriter.inlineRegionBefore(global.getRegion(), gr, gr.end()); if (!gr.empty()) { // Replace insert_on_range with a constant dense attribute if the // initialization is on the full range. auto insertOnRangeOps = gr.front().getOps(); for (auto insertOp : insertOnRangeOps) { - if (isFullRange(insertOp.coor(), insertOp.getType())) { + if (isFullRange(insertOp.getCoor(), insertOp.getType())) { auto seqTyAttr = convertType(insertOp.getType()); - auto *op = insertOp.val().getDefiningOp(); + auto *op = insertOp.getVal().getDefiningOp(); auto constant = mlir::dyn_cast(op); if (!constant) { auto convertOp = mlir::dyn_cast(op); if (!convertOp) continue; constant = cast( - convertOp.value().getDefiningOp()); + convertOp.getValue().getDefiningOp()); } mlir::Type vecType = mlir::VectorType::get( insertOp.getType().getShape(), constant.getType()); @@ -1248,7 +1248,7 @@ mlir::ConversionPatternRewriter &rewriter) { unsigned conds = select.getNumConditions(); auto cases = select.getCases().getValue(); - mlir::Value selector = adaptor.selector(); + mlir::Value selector = adaptor.getSelector(); auto loc = select.getLoc(); assert(conds > 0 && "select must have cases"); @@ -1372,7 +1372,7 @@ mlir::LogicalResult matchAndRewrite(fir::StoreOp store, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - if (store.value().getType().isa()) { + if (store.getValue().getType().isa()) { // fir.box value is actually in memory, load it first before storing it. mlir::Location loc = store.getLoc(); mlir::Type boxPtrTy = adaptor.getOperands()[0].getType(); @@ -2277,7 +2277,7 @@ mlir::LogicalResult doRewrite(fir::ExtractValueOp extractVal, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto attrs = collectIndices(rewriter, extractVal.coor()); + auto attrs = collectIndices(rewriter, extractVal.getCoor()); toRowMajor(attrs, adaptor.getOperands()[0].getType()); auto position = mlir::ArrayAttr::get(extractVal.getContext(), attrs); rewriter.replaceOpWithNewOp( @@ -2296,7 +2296,7 @@ mlir::LogicalResult doRewrite(fir::InsertValueOp insertVal, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto attrs = collectIndices(rewriter, insertVal.coor()); + auto attrs = collectIndices(rewriter, insertVal.getCoor()); toRowMajor(attrs, adaptor.getOperands()[0].getType()); auto position = mlir::ArrayAttr::get(insertVal.getContext(), attrs); rewriter.replaceOpWithNewOp( @@ -2339,7 +2339,7 @@ SmallVector uBounds; // Unzip the upper and lower bound and convert to a row major format. - mlir::DenseIntElementsAttr coor = range.coor(); + mlir::DenseIntElementsAttr coor = range.getCoor(); auto reversedCoor = llvm::reverse(coor.getValues()); for (auto i = reversedCoor.begin(), e = reversedCoor.end(); i != e; ++i) { uBounds.push_back(*i++); @@ -2759,7 +2759,7 @@ mlir::Location loc = isPresent.getLoc(); auto ptr = adaptor.getOperands()[0]; - if (isPresent.val().getType().isa()) { + if (isPresent.getVal().getType().isa()) { auto structTy = ptr.getType().cast(); assert(!structTy.isOpaque() && !structTy.getBody().empty()); @@ -2900,8 +2900,8 @@ mlir::LogicalResult matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - auto recTy = field.on_type().cast(); - unsigned index = recTy.getFieldIndex(field.field_id()); + auto recTy = field.getOnType().cast(); + unsigned index = recTy.getFieldIndex(field.getFieldId()); if (!fir::hasDynamicSize(recTy)) { // Derived type has compile-time constant layout. Return index of the @@ -2915,7 +2915,7 @@ // generated function to determine the byte offset of the field at runtime. // This returns a non-constant. FlatSymbolRefAttr symAttr = mlir::SymbolRefAttr::get( - field.getContext(), getOffsetMethodName(recTy, field.field_id())); + field.getContext(), getOffsetMethodName(recTy, field.getFieldId())); NamedAttribute callAttr = rewriter.getNamedAttr("callee", symAttr); NamedAttribute fieldAttr = rewriter.getNamedAttr( "field", mlir::IntegerAttr::get(lowerTy().indexType(), index)); @@ -3069,7 +3069,8 @@ // %lenp = fir.len_param_index len1, !fir.type // %addr = coordinate_of %box, %lenp if (coor.getNumOperands() == 2) { - mlir::Operation *coordinateDef = (*coor.coor().begin()).getDefiningOp(); + mlir::Operation *coordinateDef = + (*coor.getCoor().begin()).getDefiningOp(); if (isa_and_nonnull(coordinateDef)) { TODO(loc, "fir.coordinate_of - fir.len_param_index is not supported yet"); diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp @@ -31,15 +31,15 @@ static void populateShape(llvm::SmallVectorImpl &vec, ShapeOp shape) { - vec.append(shape.extents().begin(), shape.extents().end()); + vec.append(shape.getExtents().begin(), shape.getExtents().end()); } // Operands of fir.shape_shift split into two vectors. static void populateShapeAndShift(llvm::SmallVectorImpl &shapeVec, llvm::SmallVectorImpl &shiftVec, ShapeShiftOp shift) { - auto endIter = shift.pairs().end(); - for (auto i = shift.pairs().begin(); i != endIter;) { + auto endIter = shift.getPairs().end(); + for (auto i = shift.getPairs().begin(); i != endIter;) { shiftVec.push_back(*i++); shapeVec.push_back(*i++); } @@ -47,7 +47,7 @@ static void populateShift(llvm::SmallVectorImpl &vec, ShiftOp shift) { - vec.append(shift.origins().begin(), shift.origins().end()); + vec.append(shift.getOrigins().begin(), shift.getOrigins().end()); } namespace { @@ -101,8 +101,8 @@ shapeOpers.push_back(extVal); } auto xbox = rewriter.create( - loc, embox.getType(), embox.memref(), shapeOpers, llvm::None, - llvm::None, llvm::None, llvm::None, embox.typeparams()); + loc, embox.getType(), embox.getMemref(), shapeOpers, llvm::None, + llvm::None, llvm::None, llvm::None, embox.getTypeparams()); LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n'); rewriter.replaceOp(embox, xbox.getOperation()->getResults()); return mlir::success(); @@ -127,13 +127,16 @@ llvm::SmallVector substrOpers; if (auto s = embox.getSlice()) if (auto sliceOp = dyn_cast_or_null(s.getDefiningOp())) { - sliceOpers.assign(sliceOp.triples().begin(), sliceOp.triples().end()); - subcompOpers.assign(sliceOp.fields().begin(), sliceOp.fields().end()); - substrOpers.assign(sliceOp.substr().begin(), sliceOp.substr().end()); + sliceOpers.assign(sliceOp.getTriples().begin(), + sliceOp.getTriples().end()); + subcompOpers.assign(sliceOp.getFields().begin(), + sliceOp.getFields().end()); + substrOpers.assign(sliceOp.getSubstr().begin(), + sliceOp.getSubstr().end()); } auto xbox = rewriter.create( - loc, embox.getType(), embox.memref(), shapeOpers, shiftOpers, - sliceOpers, subcompOpers, substrOpers, embox.typeparams()); + loc, embox.getType(), embox.getMemref(), shapeOpers, shiftOpers, + sliceOpers, subcompOpers, substrOpers, embox.getTypeparams()); LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n'); rewriter.replaceOp(embox, xbox.getOperation()->getResults()); return mlir::success(); @@ -162,7 +165,7 @@ auto loc = rebox.getLoc(); llvm::SmallVector shapeOpers; llvm::SmallVector shiftOpers; - if (auto shapeVal = rebox.shape()) { + if (auto shapeVal = rebox.getShape()) { if (auto shapeOp = dyn_cast(shapeVal.getDefiningOp())) populateShape(shapeOpers, shapeOp); else if (auto shiftOp = dyn_cast(shapeVal.getDefiningOp())) @@ -175,16 +178,19 @@ llvm::SmallVector sliceOpers; llvm::SmallVector subcompOpers; llvm::SmallVector substrOpers; - if (auto s = rebox.slice()) + if (auto s = rebox.getSlice()) if (auto sliceOp = dyn_cast_or_null(s.getDefiningOp())) { - sliceOpers.append(sliceOp.triples().begin(), sliceOp.triples().end()); - subcompOpers.append(sliceOp.fields().begin(), sliceOp.fields().end()); - substrOpers.append(sliceOp.substr().begin(), sliceOp.substr().end()); + sliceOpers.append(sliceOp.getTriples().begin(), + sliceOp.getTriples().end()); + subcompOpers.append(sliceOp.getFields().begin(), + sliceOp.getFields().end()); + substrOpers.append(sliceOp.getSubstr().begin(), + sliceOp.getSubstr().end()); } auto xRebox = rewriter.create( - loc, rebox.getType(), rebox.box(), shapeOpers, shiftOpers, sliceOpers, - subcompOpers, substrOpers); + loc, rebox.getType(), rebox.getBox(), shapeOpers, shiftOpers, + sliceOpers, subcompOpers, substrOpers); LLVM_DEBUG(llvm::dbgs() << "rewriting " << rebox << " to " << xRebox << '\n'); rewriter.replaceOp(rebox, xRebox.getOperation()->getResults()); @@ -215,7 +221,7 @@ auto loc = arrCoor.getLoc(); llvm::SmallVector shapeOpers; llvm::SmallVector shiftOpers; - if (auto shapeVal = arrCoor.shape()) { + if (auto shapeVal = arrCoor.getShape()) { if (auto shapeOp = dyn_cast(shapeVal.getDefiningOp())) populateShape(shapeOpers, shapeOp); else if (auto shiftOp = dyn_cast(shapeVal.getDefiningOp())) @@ -227,17 +233,20 @@ } llvm::SmallVector sliceOpers; llvm::SmallVector subcompOpers; - if (auto s = arrCoor.slice()) + if (auto s = arrCoor.getSlice()) if (auto sliceOp = dyn_cast_or_null(s.getDefiningOp())) { - sliceOpers.append(sliceOp.triples().begin(), sliceOp.triples().end()); - subcompOpers.append(sliceOp.fields().begin(), sliceOp.fields().end()); - assert(sliceOp.substr().empty() && + sliceOpers.append(sliceOp.getTriples().begin(), + sliceOp.getTriples().end()); + subcompOpers.append(sliceOp.getFields().begin(), + sliceOp.getFields().end()); + assert(sliceOp.getSubstr().empty() && "Don't allow substring operations on array_coor. This " "restriction may be lifted in the future."); } auto xArrCoor = rewriter.create( - loc, arrCoor.getType(), arrCoor.memref(), shapeOpers, shiftOpers, - sliceOpers, subcompOpers, arrCoor.indices(), arrCoor.typeparams()); + loc, arrCoor.getType(), arrCoor.getMemref(), shapeOpers, shiftOpers, + sliceOpers, subcompOpers, arrCoor.getIndices(), + arrCoor.getTypeparams()); LLVM_DEBUG(llvm::dbgs() << "rewriting " << arrCoor << " to " << xArrCoor << '\n'); rewriter.replaceOp(arrCoor, xArrCoor.getOperation()->getResults()); diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -199,7 +199,7 @@ // to call. int dropFront = 0; if constexpr (std::is_same_v, fir::CallOp>) { - if (!callOp.callee().hasValue()) { + if (!callOp.getCallee().hasValue()) { newInTys.push_back(fnTy.getInput(0)); newOpers.push_back(callOp.getOperand(0)); dropFront = 1; @@ -236,10 +236,10 @@ .template Case([&](BoxCharType boxTy) { bool sret; if constexpr (std::is_same_v, fir::CallOp>) { - sret = callOp.callee() && + sret = callOp.getCallee() && functionArgIsSRet(index, getModule().lookupSymbol( - *callOp.callee())); + *callOp.getCallee())); } else { // TODO: dispatch case; how do we put arguments on a call? // We cannot put both an sret and the dispatch object first. @@ -274,7 +274,7 @@ if (factory::isCharacterProcedureTuple(tuple)) { mlir::ModuleOp module = getModule(); if constexpr (std::is_same_v, fir::CallOp>) { - if (callOp.callee()) { + if (callOp.getCallee()) { llvm::StringRef charProcAttr = fir::getCharacterProcedureDummyAttrName(); // The charProcAttr attribute is only used as a safety to @@ -282,7 +282,7 @@ // It cannot be used to match because attributes are not // available in case of indirect calls. auto funcOp = - module.lookupSymbol(*callOp.callee()); + module.lookupSymbol(*callOp.getCallee()); if (funcOp && !funcOp.template getArgAttrOfType( index, charProcAttr)) @@ -314,8 +314,8 @@ newOpers.insert(newOpers.end(), trailingOpers.begin(), trailingOpers.end()); if constexpr (std::is_same_v, fir::CallOp>) { fir::CallOp newCall; - if (callOp.callee().hasValue()) { - newCall = rewriter->create(loc, callOp.callee().getValue(), + if (callOp.getCallee().hasValue()) { + newCall = rewriter->create(loc, callOp.getCallee().getValue(), newResTys, newOpers); } else { // Force new type on the input operand. @@ -414,7 +414,7 @@ // replace this op with a new one with the updated signature auto newTy = rewriter->getFunctionType(newInTys, newResTys); auto newOp = - rewriter->create(addrOp.getLoc(), newTy, addrOp.symbol()); + rewriter->create(addrOp.getLoc(), newTy, addrOp.getSymbol()); replaceOp(addrOp, newOp.getResult()); } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -135,12 +135,13 @@ template static void printAllocatableOp(mlir::OpAsmPrinter &p, OP &op) { - p << ' ' << op.in_type(); - if (!op.typeparams().empty()) { - p << '(' << op.typeparams() << " : " << op.typeparams().getTypes() << ')'; + p << ' ' << op.getInType(); + if (!op.getTypeparams().empty()) { + p << '(' << op.getTypeparams() << " : " << op.getTypeparams().getTypes() + << ')'; } // print the shape of the allocation (if any); all must be index type - for (auto sh : op.shape()) { + for (auto sh : op.getShape()) { p << ", "; p.printOperand(sh); } @@ -339,13 +340,13 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ArrayCoorOp::verify() { - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); auto arrTy = eleTy.dyn_cast(); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); - if (auto shapeOp = shape()) { + if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; if (auto s = shapeTy.dyn_cast()) { @@ -355,18 +356,18 @@ } else { auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!memref().getType().isa()) + if (!getMemref().getType().isa()) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) return emitOpError("rank of dimension mismatched"); - if (shapeTyRank != indices().size()) + if (shapeTyRank != getIndices().size()) return emitOpError("number of indices do not match dim rank"); } - if (auto sliceOp = slice()) { + if (auto sliceOp = getSlice()) { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) - if (!sl.substr().empty()) + if (!sl.getSubstr().empty()) return emitOpError("array_coor cannot take a slice with substring"); if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) @@ -394,7 +395,7 @@ } std::vector fir::ArrayLoadOp::getExtents() { - if (auto sh = shape()) + if (auto sh = getShape()) if (auto *op = sh.getDefiningOp()) { if (auto shOp = dyn_cast(op)) { auto extents = shOp.getExtents(); @@ -406,13 +407,13 @@ } mlir::LogicalResult ArrayLoadOp::verify() { - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); auto arrTy = eleTy.dyn_cast(); if (!arrTy) return emitOpError("must be a reference to an array"); auto arrDim = arrTy.getDimension(); - if (auto shapeOp = shape()) { + if (auto shapeOp = getShape()) { auto shapeTy = shapeOp.getType(); unsigned shapeTyRank = 0; if (auto s = shapeTy.dyn_cast()) { @@ -422,16 +423,16 @@ } else { auto s = shapeTy.cast(); shapeTyRank = s.getRank(); - if (!memref().getType().isa()) + if (!getMemref().getType().isa()) return emitOpError("shift can only be provided with fir.box memref"); } if (arrDim && arrDim != shapeTyRank) return emitOpError("rank of dimension mismatched"); } - if (auto sliceOp = slice()) { + if (auto sliceOp = getSlice()) { if (auto sl = mlir::dyn_cast_or_null(sliceOp.getDefiningOp())) - if (!sl.substr().empty()) + if (!sl.getSubstr().empty()) return emitOpError("array_load cannot take a slice with substring"); if (auto sliceTy = sliceOp.getType().dyn_cast()) if (sliceTy.getRank() != arrDim) @@ -446,25 +447,25 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ArrayMergeStoreOp::verify() { - if (!isa(original().getDefiningOp())) + if (!isa(getOriginal().getDefiningOp())) return emitOpError("operand #0 must be result of a fir.array_load op"); - if (auto sl = slice()) { + if (auto sl = getSlice()) { if (auto sliceOp = mlir::dyn_cast_or_null(sl.getDefiningOp())) { - if (!sliceOp.substr().empty()) + if (!sliceOp.getSubstr().empty()) return emitOpError( "array_merge_store cannot take a slice with substring"); - if (!sliceOp.fields().empty()) { + if (!sliceOp.getFields().empty()) { // This is an intra-object merge, where the slice is projecting the // subfields that are to be overwritten by the merge operation. - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); if (auto seqTy = eleTy.dyn_cast()) { auto projTy = - fir::applyPathToType(seqTy.getEleTy(), sliceOp.fields()); - if (fir::unwrapSequenceType(original().getType()) != projTy) + fir::applyPathToType(seqTy.getEleTy(), sliceOp.getFields()); + if (fir::unwrapSequenceType(getOriginal().getType()) != projTy) return emitOpError( "type of origin does not match sliced memref type"); - if (fir::unwrapSequenceType(sequence().getType()) != projTy) + if (fir::unwrapSequenceType(getSequence().getType()) != projTy) return emitOpError( "type of sequence does not match sliced memref type"); return mlir::success(); @@ -474,10 +475,10 @@ } return mlir::success(); } - auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(memref().getType()); - if (original().getType() != eleTy) + auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); + if (getOriginal().getType() != eleTy) return emitOpError("type of origin does not match memref element type"); - if (sequence().getType() != eleTy) + if (getSequence().getType() != eleTy) return emitOpError("type of sequence does not match memref element type"); return mlir::success(); } @@ -489,22 +490,22 @@ // Template function used for both array_fetch and array_update verification. template mlir::Type validArraySubobject(A op) { - auto ty = op.sequence().getType(); - return fir::applyPathToType(ty, op.indices()); + auto ty = op.getSequence().getType(); + return fir::applyPathToType(ty, op.getIndices()); } mlir::LogicalResult ArrayFetchOp::verify() { - auto arrTy = sequence().getType().cast(); - auto indSize = indices().size(); + auto arrTy = getSequence().getType().cast(); + auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - ::adjustedElementType(element().getType()) != arrTy.getEleTy()) + ::adjustedElementType(getElement().getType()) != arrTy.getEleTy()) return emitOpError("return type does not match array"); auto ty = validArraySubobject(*this); if (!ty || ty != ::adjustedElementType(getType())) return emitOpError("return type and/or indices do not type check"); - if (!isa(sequence().getDefiningOp())) + if (!isa(getSequence().getDefiningOp())) return emitOpError("argument #0 must be result of fir.array_load"); return mlir::success(); } @@ -514,12 +515,12 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ArrayAccessOp::verify() { - auto arrTy = sequence().getType().cast(); - std::size_t indSize = indices().size(); + auto arrTy = getSequence().getType().cast(); + std::size_t indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - element().getType() != fir::ReferenceType::get(arrTy.getEleTy())) + getElement().getType() != fir::ReferenceType::get(arrTy.getEleTy())) return emitOpError("return type does not match array"); mlir::Type ty = validArraySubobject(*this); if (!ty || fir::ReferenceType::get(ty) != getType()) @@ -532,17 +533,17 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ArrayUpdateOp::verify() { - if (fir::isa_ref_type(merge().getType())) + if (fir::isa_ref_type(getMerge().getType())) return emitOpError("does not support reference type for merge"); - auto arrTy = sequence().getType().cast(); - auto indSize = indices().size(); + auto arrTy = getSequence().getType().cast(); + auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices != dimension of array"); if (indSize == arrTy.getDimension() && - ::adjustedElementType(merge().getType()) != arrTy.getEleTy()) + ::adjustedElementType(getMerge().getType()) != arrTy.getEleTy()) return emitOpError("merged value does not have element type"); auto ty = validArraySubobject(*this); - if (!ty || ty != ::adjustedElementType(merge().getType())) + if (!ty || ty != ::adjustedElementType(getMerge().getType())) return emitOpError("merged value and/or indices do not type check"); return mlir::success(); } @@ -552,8 +553,8 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ArrayModifyOp::verify() { - auto arrTy = sequence().getType().cast(); - auto indSize = indices().size(); + auto arrTy = getSequence().getType().cast(); + auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) return emitOpError("number of indices must match array dimension"); return mlir::success(); @@ -564,11 +565,11 @@ //===----------------------------------------------------------------------===// mlir::OpFoldResult fir::BoxAddrOp::fold(llvm::ArrayRef opnds) { - if (auto v = val().getDefiningOp()) { + if (auto v = getVal().getDefiningOp()) { if (auto box = dyn_cast(v)) - return box.memref(); + return box.getMemref(); if (auto box = dyn_cast(v)) - return box.memref(); + return box.getMemref(); } return {}; } @@ -579,9 +580,9 @@ mlir::OpFoldResult fir::BoxCharLenOp::fold(llvm::ArrayRef opnds) { - if (auto v = val().getDefiningOp()) { + if (auto v = getVal().getDefiningOp()) { if (auto box = dyn_cast(v)) - return box.len(); + return box.getLen(); } return {}; } @@ -608,10 +609,10 @@ } void fir::CallOp::print(mlir::OpAsmPrinter &p) { - bool isDirect = callee().hasValue(); + bool isDirect = getCallee().hasValue(); p << ' '; if (isDirect) - p << callee().getValue(); + p << getCallee().getValue(); else p << getOperand(0); p << '(' << (*this)->getOperands().drop_front(isDirect ? 0 : 1) << ')'; @@ -694,12 +695,12 @@ assert(predSym.hasValue() && "invalid symbol value for predicate"); p << '"' << mlir::arith::stringifyCmpFPredicate(predSym.getValue()) << '"' << ", "; - p.printOperand(op.lhs()); + p.printOperand(op.getLhs()); p << ", "; - p.printOperand(op.rhs()); + p.printOperand(op.getRhs()); p.printOptionalAttrDict(op->getAttrs(), /*elidedAttrs=*/{OPTY::getPredicateAttrName()}); - p << " : " << op.lhs().getType(); + p << " : " << op.getLhs().getType(); } template @@ -742,8 +743,8 @@ t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)); return t.dyn_cast(); }; - auto inTy = unwrap(from().getType()); - auto outTy = unwrap(to().getType()); + auto inTy = unwrap(getFrom().getType()); + auto outTy = unwrap(getTo().getType()); if (!(inTy && outTy)) return emitOpError("not a reference to a character"); if (inTy.getFKind() == outTy.getFKind()) @@ -824,21 +825,22 @@ } mlir::OpFoldResult fir::ConvertOp::fold(llvm::ArrayRef opnds) { - if (value().getType() == getType()) - return value(); - if (matchPattern(value(), m_Op())) { - auto inner = cast(value().getDefiningOp()); + if (getValue().getType() == getType()) + return getValue(); + if (matchPattern(getValue(), m_Op())) { + auto inner = cast(getValue().getDefiningOp()); // (convert (convert 'a : logical -> i1) : i1 -> logical) ==> forward 'a if (auto toTy = getType().dyn_cast()) - if (auto fromTy = inner.value().getType().dyn_cast()) + if (auto fromTy = inner.getValue().getType().dyn_cast()) if (inner.getType().isa() && (toTy == fromTy)) - return inner.value(); + return inner.getValue(); // (convert (convert 'a : i1 -> logical) : logical -> i1) ==> forward 'a if (auto toTy = getType().dyn_cast()) - if (auto fromTy = inner.value().getType().dyn_cast()) + if (auto fromTy = + inner.getValue().getType().dyn_cast()) if (inner.getType().isa() && (toTy == fromTy) && (fromTy.getWidth() == 1)) - return inner.value(); + return inner.getValue(); } return {}; } @@ -860,7 +862,7 @@ } mlir::LogicalResult ConvertOp::verify() { - auto inType = value().getType(); + auto inType = getValue().getType(); auto outType = getType(); if (inType == outType) return mlir::success(); @@ -882,7 +884,7 @@ //===----------------------------------------------------------------------===// void CoordinateOp::print(mlir::OpAsmPrinter &p) { - p << ' ' << ref() << ", " << coor(); + p << ' ' << getRef() << ", " << getCoor(); p.printOptionalAttrDict((*this)->getAttrs(), /*elideAttrs=*/{"baseType"}); p << " : "; p.printFunctionalType(getOperandTypes(), (*this)->getResultTypes()); @@ -912,7 +914,7 @@ } mlir::LogicalResult CoordinateOp::verify() { - auto refTy = ref().getType(); + auto refTy = getRef().getType(); if (fir::isa_ref_type(refTy)) { auto eleTy = fir::dyn_cast_ptrEleTy(refTy); if (auto arrTy = eleTy.dyn_cast()) { @@ -928,11 +930,11 @@ // Recovering a LEN type parameter only makes sense from a boxed value. For a // bare reference, the LEN type parameters must be passed as additional // arguments to `op`. - for (auto co : coor()) + for (auto co : getCoor()) if (dyn_cast_or_null(co.getDefiningOp())) { if (getNumOperands() != 2) return emitOpError("len_param_index must be last argument"); - if (!ref().getType().isa()) + if (!getRef().getType().isa()) return emitOpError("len_param_index must be used on box type"); } return mlir::success(); @@ -975,10 +977,10 @@ void DispatchOp::print(mlir::OpAsmPrinter &p) { p << ' ' << getMethodAttr() << '('; - p.printOperand(object()); - if (!args().empty()) { + p.printOperand(getObject()); + if (!getArgs().empty()) { p << ", "; - p.printOperands(args()); + p.printOperands(getArgs()); } p << ") : "; p.printFunctionalType(getOperation()->getOperandTypes(), @@ -1045,7 +1047,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult EmboxOp::verify() { - auto eleTy = fir::dyn_cast_ptrEleTy(memref().getType()); + auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); bool isArray = false; if (auto seqTy = eleTy.dyn_cast()) { eleTy = seqTy.getEleTy(); @@ -1063,7 +1065,7 @@ } else { return emitOpError("LEN parameters require CHARACTER or derived type"); } - for (auto lp : typeparams()) + for (auto lp : getTypeparams()) if (!fir::isa_integer(lp.getType())) return emitOpError("LEN parameters must be integral type"); } @@ -1079,7 +1081,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult EmboxCharOp::verify() { - auto eleTy = fir::dyn_cast_ptrEleTy(memref().getType()); + auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); if (!eleTy.dyn_cast_or_null()) return mlir::failure(); return mlir::success(); @@ -1120,7 +1122,7 @@ void EmboxProcOp::print(mlir::OpAsmPrinter &p) { p << ' ' << getOperation()->getAttr("funcname"); - auto h = host(); + auto h = getHost(); if (h) { p << ", "; p.printOperand(h); @@ -1133,7 +1135,7 @@ mlir::LogicalResult EmboxProcOp::verify() { // host bindings (optional) must be a reference to a tuple - if (auto h = host()) { + if (auto h = getHost()) { if (auto r = h.getType().dyn_cast()) { if (!r.getEleTy().dyn_cast()) return mlir::failure(); @@ -1244,8 +1246,8 @@ } void GlobalOp::print(mlir::OpAsmPrinter &p) { - if (linkName().hasValue()) - p << ' ' << linkName().getValue(); + if (getLinkName().hasValue()) + p << ' ' << getLinkName().getValue(); p << ' '; p.printAttributeWithoutType(getSymrefAttr()); if (auto val = getValueOrNull()) @@ -1277,9 +1279,10 @@ result.addAttribute(symbolAttrNameStr(), SymbolRefAttr::get(builder.getContext(), name)); if (isConstant) - result.addAttribute(constantAttrName(result.name), builder.getUnitAttr()); + result.addAttribute(getConstantAttrName(result.name), + builder.getUnitAttr()); if (initialVal) - result.addAttribute(initValAttrName(result.name), initialVal); + result.addAttribute(getInitValAttrName(result.name), initialVal); if (linkage) result.addAttribute(linkageAttrName(), linkage); result.attributes.append(attrs.begin(), attrs.end()); @@ -1391,9 +1394,9 @@ << ", " << getOperation()->getAttr(fir::FieldIndexOp::typeAttrName()); if (getNumOperands()) { p << '('; - p.printOperands(typeparams()); + p.printOperands(getTypeparams()); const auto *sep = ") : "; - for (auto op : typeparams()) { + for (auto op : getTypeparams()) { p << sep; if (op) p.printType(op.getType()); @@ -1462,9 +1465,9 @@ /// Range bounds must be nonnegative, and the range must not be empty. mlir::LogicalResult InsertOnRangeOp::verify() { - if (fir::hasDynamicSize(seq().getType())) + if (fir::hasDynamicSize(getSeq().getType())) return emitOpError("must have constant shape and size"); - mlir::DenseIntElementsAttr coorAttr = coor(); + mlir::DenseIntElementsAttr coorAttr = getCoor(); if (coorAttr.size() < 2 || coorAttr.size() % 2 != 0) return emitOpError("has uneven number of values in ranges"); bool rangeIsKnownToBeNonempty = false; @@ -1510,14 +1513,14 @@ if (!insval || !insval.getType().isa()) return mlir::failure(); auto insval2 = - dyn_cast_or_null(insval.adt().getDefiningOp()); - if (!insval2 || !isa(insval2.adt().getDefiningOp())) + dyn_cast_or_null(insval.getAdt().getDefiningOp()); + if (!insval2 || !isa(insval2.getAdt().getDefiningOp())) return mlir::failure(); - auto binf = dyn_cast_or_null(insval.val().getDefiningOp()); - auto binf2 = dyn_cast_or_null(insval2.val().getDefiningOp()); - if (!binf || !binf2 || insval.coor().size() != 1 || - !isOne(insval.coor()[0]) || insval2.coor().size() != 1 || - !isZero(insval2.coor()[0])) + auto binf = dyn_cast_or_null(insval.getVal().getDefiningOp()); + auto binf2 = dyn_cast_or_null(insval2.getVal().getDefiningOp()); + if (!binf || !binf2 || insval.getCoor().size() != 1 || + !isOne(insval.getCoor()[0]) || insval2.getCoor().size() != 1 || + !isZero(insval2.getCoor()[0])) return mlir::failure(); auto eai = dyn_cast_or_null(binf.getLhs().getDefiningOp()); @@ -1527,14 +1530,14 @@ dyn_cast_or_null(binf2.getLhs().getDefiningOp()); auto ebr = dyn_cast_or_null(binf2.getRhs().getDefiningOp()); - if (!eai || !ebi || !ear || !ebr || ear.adt() != eai.adt() || - ebr.adt() != ebi.adt() || eai.coor().size() != 1 || - !isOne(eai.coor()[0]) || ebi.coor().size() != 1 || - !isOne(ebi.coor()[0]) || ear.coor().size() != 1 || - !isZero(ear.coor()[0]) || ebr.coor().size() != 1 || - !isZero(ebr.coor()[0])) + if (!eai || !ebi || !ear || !ebr || ear.getAdt() != eai.getAdt() || + ebr.getAdt() != ebi.getAdt() || eai.getCoor().size() != 1 || + !isOne(eai.getCoor()[0]) || ebi.getCoor().size() != 1 || + !isOne(ebi.getCoor()[0]) || ear.getCoor().size() != 1 || + !isZero(ear.getCoor()[0]) || ebr.getCoor().size() != 1 || + !isZero(ebr.getCoor()[0])) return mlir::failure(); - rewriter.replaceOpWithNewOp(op, ear.adt(), ebr.adt()); + rewriter.replaceOpWithNewOp(op, ear.getAdt(), ebr.getAdt()); return mlir::success(); } }; @@ -1687,7 +1690,7 @@ "the induction variable"); auto opNumResults = op.getNumResults(); - if (op.finalValue()) { + if (op.getFinalValue()) { // Result type must be "(index, i1, ...)". if (!op.getResult(0).getType().isa()) return op.emitOpError("result #0 expected to be index"); @@ -1711,7 +1714,7 @@ auto iterOperands = op.getIterOperands(); auto iterArgs = op.getRegionIterArgs(); auto opResults = - op.finalValue() ? op.getResults().drop_front() : op.getResults(); + op.getFinalValue() ? op.getResults().drop_front() : op.getResults(); unsigned i = 0; for (auto e : llvm::zip(iterOperands, iterArgs, opResults)) { if (std::get<0>(e).getType() != std::get<2>(e).getType()) @@ -1727,8 +1730,8 @@ } static void print(mlir::OpAsmPrinter &p, fir::IterWhileOp op) { - p << " (" << op.getInductionVar() << " = " << op.lowerBound() << " to " - << op.upperBound() << " step " << op.step() << ") and ("; + p << " (" << op.getInductionVar() << " = " << op.getLowerBound() << " to " + << op.getUpperBound() << " step " << op.getStep() << ") and ("; assert(op.hasIterOperands()); auto regionArgs = op.getRegionIterArgs(); auto operands = op.getIterOperands(); @@ -1740,22 +1743,22 @@ [&](auto it) { p << std::get<0>(it) << " = " << std::get<1>(it); }); p << ") -> ("; llvm::interleaveComma( - llvm::drop_begin(op.getResultTypes(), op.finalValue() ? 0 : 1), p); + llvm::drop_begin(op.getResultTypes(), op.getFinalValue() ? 0 : 1), p); p << ")"; - } else if (op.finalValue()) { + } else if (op.getFinalValue()) { p << " -> (" << op.getResultTypes() << ')'; } p.printOptionalAttrDictWithKeyword(op->getAttrs(), {op.getFinalValueAttrNameStr()}); p << ' '; - p.printRegion(op.region(), /*printEntryBlockArgs=*/false, + p.printRegion(op.getRegion(), /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/true); } -mlir::Region &fir::IterWhileOp::getLoopBody() { return region(); } +mlir::Region &fir::IterWhileOp::getLoopBody() { return getRegion(); } bool fir::IterWhileOp::isDefinedOutsideOfLoop(mlir::Value value) { - return !region().isAncestor(value.getParentRegion()); + return !getRegion().isAncestor(value.getParentRegion()); } mlir::LogicalResult @@ -1766,23 +1769,23 @@ } mlir::BlockArgument fir::IterWhileOp::iterArgToBlockArg(mlir::Value iterArg) { - for (auto i : llvm::enumerate(initArgs())) + for (auto i : llvm::enumerate(getInitArgs())) if (iterArg == i.value()) - return region().front().getArgument(i.index() + 1); + return getRegion().front().getArgument(i.index() + 1); return {}; } void fir::IterWhileOp::resultToSourceOps( llvm::SmallVectorImpl &results, unsigned resultNum) { - auto oper = finalValue() ? resultNum + 1 : resultNum; - auto *term = region().front().getTerminator(); + auto oper = getFinalValue() ? resultNum + 1 : resultNum; + auto *term = getRegion().front().getTerminator(); if (oper < term->getNumOperands()) results.push_back(term->getOperand(oper)); } mlir::Value fir::IterWhileOp::blockArgToSourceOp(unsigned blockArgNum) { - if (blockArgNum > 0 && blockArgNum <= initArgs().size()) - return initArgs()[blockArgNum - 1]; + if (blockArgNum > 0 && blockArgNum <= getInitArgs().size()) + return getInitArgs()[blockArgNum - 1]; return {}; } @@ -1862,9 +1865,9 @@ void LoadOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(memref()); + p.printOperand(getMemref()); p.printOptionalAttrDict(getOperation()->getAttrs(), {}); - p << " : " << memref().getType(); + p << " : " << getMemref().getType(); } //===----------------------------------------------------------------------===// @@ -1880,7 +1883,8 @@ result.addOperands(iterArgs); if (finalCountValue) { result.addTypes(builder.getIndexType()); - result.addAttribute(finalValueAttrName(result.name), builder.getUnitAttr()); + result.addAttribute(getFinalValueAttrName(result.name), + builder.getUnitAttr()); } for (auto v : iterArgs) result.addTypes(v.getType()); @@ -1893,7 +1897,8 @@ iterArgs.getTypes(), SmallVector(iterArgs.size(), result.location)); if (unordered) - result.addAttribute(unorderedAttrName(result.name), builder.getUnitAttr()); + result.addAttribute(getUnorderedAttrName(result.name), + builder.getUnitAttr()); result.addAttributes(attributes); } @@ -1950,7 +1955,7 @@ // Induction variable. if (prependCount) - result.addAttribute(DoLoopOp::finalValueAttrName(result.name), + result.addAttribute(DoLoopOp::getFinalValueAttrName(result.name), builder.getUnitAttr()); else argTypes.push_back(indexType); @@ -1994,8 +1999,8 @@ if (opNumResults == 0) return success(); - if (op.finalValue()) { - if (op.unordered()) + if (op.getFinalValue()) { + if (op.getUnordered()) return op.emitOpError("unordered loop has no final value"); opNumResults--; } @@ -2008,7 +2013,7 @@ auto iterOperands = op.getIterOperands(); auto iterArgs = op.getRegionIterArgs(); auto opResults = - op.finalValue() ? op.getResults().drop_front() : op.getResults(); + op.getFinalValue() ? op.getResults().drop_front() : op.getResults(); unsigned i = 0; for (auto e : llvm::zip(iterOperands, iterArgs, opResults)) { if (std::get<0>(e).getType() != std::get<2>(e).getType()) @@ -2025,9 +2030,9 @@ static void print(mlir::OpAsmPrinter &p, fir::DoLoopOp op) { bool printBlockTerminators = false; - p << ' ' << op.getInductionVar() << " = " << op.lowerBound() << " to " - << op.upperBound() << " step " << op.step(); - if (op.unordered()) + p << ' ' << op.getInductionVar() << " = " << op.getLowerBound() << " to " + << op.getUpperBound() << " step " << op.getStep(); + if (op.getUnordered()) p << " unordered"; if (op.hasIterOperands()) { p << " iter_args("; @@ -2038,21 +2043,21 @@ }); p << ") -> (" << op.getResultTypes() << ')'; printBlockTerminators = true; - } else if (op.finalValue()) { + } else if (op.getFinalValue()) { p << " -> " << op.getResultTypes(); printBlockTerminators = true; } p.printOptionalAttrDictWithKeyword(op->getAttrs(), {"unordered", "finalValue"}); p << ' '; - p.printRegion(op.region(), /*printEntryBlockArgs=*/false, + p.printRegion(op.getRegion(), /*printEntryBlockArgs=*/false, printBlockTerminators); } -mlir::Region &fir::DoLoopOp::getLoopBody() { return region(); } +mlir::Region &fir::DoLoopOp::getLoopBody() { return getRegion(); } bool fir::DoLoopOp::isDefinedOutsideOfLoop(mlir::Value value) { - return !region().isAncestor(value.getParentRegion()); + return !getRegion().isAncestor(value.getParentRegion()); } mlir::LogicalResult @@ -2065,9 +2070,9 @@ /// Translate a value passed as an iter_arg to the corresponding block /// argument in the body of the loop. mlir::BlockArgument fir::DoLoopOp::iterArgToBlockArg(mlir::Value iterArg) { - for (auto i : llvm::enumerate(initArgs())) + for (auto i : llvm::enumerate(getInitArgs())) if (iterArg == i.value()) - return region().front().getArgument(i.index() + 1); + return getRegion().front().getArgument(i.index() + 1); return {}; } @@ -2075,8 +2080,8 @@ /// to the `fir.result` Op. void fir::DoLoopOp::resultToSourceOps( llvm::SmallVectorImpl &results, unsigned resultNum) { - auto oper = finalValue() ? resultNum + 1 : resultNum; - auto *term = region().front().getTerminator(); + auto oper = getFinalValue() ? resultNum + 1 : resultNum; + auto *term = getRegion().front().getTerminator(); if (oper < term->getNumOperands()) results.push_back(term->getOperand(oper)); } @@ -2084,8 +2089,8 @@ /// Translate the block argument (by index number) to the corresponding value /// passed as an iter_arg to the parent DoLoopOp. mlir::Value fir::DoLoopOp::blockArgToSourceOp(unsigned blockArgNum) { - if (blockArgNum > 0 && blockArgNum <= initArgs().size()) - return initArgs()[blockArgNum - 1]; + if (blockArgNum > 0 && blockArgNum <= getInitArgs().size()) + return getInitArgs()[blockArgNum - 1]; return {}; } @@ -2141,7 +2146,7 @@ } mlir::LogicalResult ReboxOp::verify() { - auto inputBoxTy = box().getType(); + auto inputBoxTy = getBox().getType(); if (fir::isa_unknown_size_box(inputBoxTy)) return emitOpError("box operand must not have unknown rank or type"); auto outBoxTy = getType(); @@ -2152,11 +2157,11 @@ auto outRank = getBoxRank(outBoxTy); auto outEleTy = getBoxScalarEleTy(outBoxTy); - if (auto sliceVal = slice()) { + if (auto sliceVal = getSlice()) { // Slicing case if (sliceVal.getType().cast().getRank() != inputRank) return emitOpError("slice operand rank must match box operand rank"); - if (auto shapeVal = shape()) { + if (auto shapeVal = getShape()) { if (auto shiftTy = shapeVal.getType().dyn_cast()) { if (shiftTy.getRank() != inputRank) return emitOpError("shape operand and input box ranks must match " @@ -2175,7 +2180,7 @@ } else { // Reshaping case unsigned shapeRank = inputRank; - if (auto shapeVal = shape()) { + if (auto shapeVal = getShape()) { auto ty = shapeVal.getType(); if (auto shapeTy = ty.dyn_cast()) { shapeRank = shapeTy.getRank(); @@ -2224,14 +2229,14 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult SaveResultOp::verify() { - auto resultType = value().getType(); - if (resultType != fir::dyn_cast_ptrEleTy(memref().getType())) + auto resultType = getValue().getType(); + if (resultType != fir::dyn_cast_ptrEleTy(getMemref().getType())) return emitOpError("value type must match memory reference type"); if (fir::isa_unknown_size_box(resultType)) return emitOpError("cannot save !fir.box of unknown rank or type"); if (resultType.isa()) { - if (shape() || !typeparams().empty()) + if (getShape() || !getTypeparams().empty()) return emitOpError( "must not have shape or length operands if the value is a fir.box"); return mlir::success(); @@ -2239,7 +2244,7 @@ // fir.record or fir.array case. unsigned shapeTyRank = 0; - if (auto shapeVal = shape()) { + if (auto shapeVal = getShape()) { auto shapeTy = shapeVal.getType(); if (auto s = shapeTy.dyn_cast()) shapeTyRank = s.getRank(); @@ -2260,15 +2265,15 @@ } if (auto recTy = eleTy.dyn_cast()) { - if (recTy.getNumLenParams() != typeparams().size()) + if (recTy.getNumLenParams() != getTypeparams().size()) emitOpError("length parameters number must match with the value type " "length parameters"); } else if (auto charTy = eleTy.dyn_cast()) { - if (typeparams().size() > 1) + if (getTypeparams().size() > 1) emitOpError("no more than one length parameter must be provided for " "character value"); } else { - if (!typeparams().empty()) + if (!getTypeparams().empty()) emitOpError("length parameters must not be provided for this value type"); } @@ -2324,7 +2329,7 @@ llvm::Optional fir::SelectOp::getMutableSuccessorOperands(unsigned oper) { - return ::getMutableSuccessorOperands(oper, targetArgsMutable(), + return ::getMutableSuccessorOperands(oper, getTargetArgsMutable(), getTargetOffsetAttr()); } @@ -2360,7 +2365,7 @@ fir::SelectCaseOp::getCompareOperands(unsigned cond) { auto a = (*this)->getAttrOfType( getCompareOffsetAttr()); - return {getSubOperands(cond, compareArgs(), a)}; + return {getSubOperands(cond, getCompareArgs(), a)}; } llvm::Optional> @@ -2385,7 +2390,7 @@ llvm::Optional fir::SelectCaseOp::getMutableSuccessorOperands(unsigned oper) { - return ::getMutableSuccessorOperands(oper, targetArgsMutable(), + return ::getMutableSuccessorOperands(oper, getTargetArgsMutable(), getTargetOffsetAttr()); } @@ -2643,7 +2648,7 @@ llvm::Optional fir::SelectRankOp::getMutableSuccessorOperands(unsigned oper) { - return ::getMutableSuccessorOperands(oper, targetArgsMutable(), + return ::getMutableSuccessorOperands(oper, getTargetArgsMutable(), getTargetOffsetAttr()); } @@ -2688,7 +2693,7 @@ llvm::Optional fir::SelectTypeOp::getMutableSuccessorOperands(unsigned oper) { - return ::getMutableSuccessorOperands(oper, targetArgsMutable(), + return ::getMutableSuccessorOperands(oper, getTargetArgsMutable(), getTargetOffsetAttr()); } @@ -2828,7 +2833,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ShapeOp::verify() { - auto size = extents().size(); + auto size = getExtents().size(); auto shapeTy = getType().dyn_cast(); assert(shapeTy && "must be a shape type"); if (shapeTy.getRank() != size) @@ -2841,7 +2846,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ShapeShiftOp::verify() { - auto size = pairs().size(); + auto size = getPairs().size(); if (size < 2 || size > 16 * 2) return emitOpError("incorrect number of args"); if (size % 2 != 0) @@ -2858,7 +2863,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult ShiftOp::verify() { - auto size = origins().size(); + auto size = getOrigins().size(); auto shiftTy = getType().dyn_cast(); assert(shiftTy && "must be a shift type"); if (shiftTy.getRank() != size) @@ -2894,7 +2899,7 @@ } mlir::LogicalResult SliceOp::verify() { - auto size = triples().size(); + auto size = getTriples().size(); if (size < 3 || size > 16 * 3) return emitOpError("incorrect number of args for triple"); if (size % 3 != 0) @@ -2932,17 +2937,17 @@ void StoreOp::print(mlir::OpAsmPrinter &p) { p << ' '; - p.printOperand(value()); + p.printOperand(getValue()); p << " to "; - p.printOperand(memref()); + p.printOperand(getMemref()); p.printOptionalAttrDict(getOperation()->getAttrs(), {}); - p << " : " << memref().getType(); + p << " : " << getMemref().getType(); } mlir::LogicalResult StoreOp::verify() { - if (value().getType() != fir::dyn_cast_ptrEleTy(memref().getType())) + if (getValue().getType() != fir::dyn_cast_ptrEleTy(getMemref().getType())) return emitOpError("store value type must match memory reference type"); - if (fir::isa_unknown_size_box(value().getType())) + if (fir::isa_unknown_size_box(getValue().getType())) return emitOpError("cannot store !fir.box of unknown rank or type"); return mlir::success(); } @@ -3076,7 +3081,7 @@ //===----------------------------------------------------------------------===// mlir::LogicalResult UnboxProcOp::verify() { - if (auto eleTy = fir::dyn_cast_ptrEleTy(refTuple().getType())) + if (auto eleTy = fir::dyn_cast_ptrEleTy(getRefTuple().getType())) if (eleTy.isa()) return mlir::success(); return emitOpError("second output argument has bad type"); @@ -3143,7 +3148,7 @@ } static LogicalResult verify(fir::IfOp op) { - if (op.getNumResults() != 0 && op.elseRegion().empty()) + if (op.getNumResults() != 0 && op.getElseRegion().empty()) return op.emitOpError("must have an else block if defining values"); return mlir::success(); @@ -3151,17 +3156,17 @@ static void print(mlir::OpAsmPrinter &p, fir::IfOp op) { bool printBlockTerminators = false; - p << ' ' << op.condition(); - if (!op.results().empty()) { + p << ' ' << op.getCondition(); + if (!op.getResults().empty()) { p << " -> (" << op.getResultTypes() << ')'; printBlockTerminators = true; } p << ' '; - p.printRegion(op.thenRegion(), /*printEntryBlockArgs=*/false, + p.printRegion(op.getThenRegion(), /*printEntryBlockArgs=*/false, printBlockTerminators); // Print the 'else' regions if it exists and has a block. - auto &otherReg = op.elseRegion(); + auto &otherReg = op.getElseRegion(); if (!otherReg.empty()) { p << " else "; p.printRegion(otherReg, /*printEntryBlockArgs=*/false, @@ -3172,10 +3177,10 @@ void fir::IfOp::resultToSourceOps(llvm::SmallVectorImpl &results, unsigned resultNum) { - auto *term = thenRegion().front().getTerminator(); + auto *term = getThenRegion().front().getTerminator(); if (resultNum < term->getNumOperands()) results.push_back(term->getOperand(resultNum)); - term = elseRegion().front().getTerminator(); + term = getElseRegion().front().getTerminator(); if (resultNum < term->getNumOperands()) results.push_back(term->getOperand(resultNum)); } @@ -3252,7 +3257,7 @@ if (value.getType().isa()) if (auto definingOp = value.getDefiningOp()) if (auto loadOp = mlir::dyn_cast(definingOp)) - value = loadOp.memref(); + value = loadOp.getMemref(); // If this is a function argument, look in the argument attributes. if (auto blockArg = value.dyn_cast()) { if (blockArg.getOwner() && blockArg.getOwner()->isEntryBlock()) @@ -3277,7 +3282,7 @@ return true; if (auto module = definingOp->getParentOfType()) if (auto globalOp = - module.lookupSymbol(addressOfOp.symbol())) + module.lookupSymbol(addressOfOp.getSymbol())) return globalOp->hasAttr(attributeName); } } diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -95,19 +95,19 @@ return mlir::failure(); } auto argType = getResultArgumentType(result.getType(), options); - auto buffer = saveResult.memref(); + auto buffer = saveResult.getMemref(); mlir::Value arg = buffer; if (mustEmboxResult(result.getType(), options)) arg = rewriter.create( - loc, argType, buffer, saveResult.shape(), /*slice*/ mlir::Value{}, - saveResult.typeparams()); + loc, argType, buffer, saveResult.getShape(), /*slice*/ mlir::Value{}, + saveResult.getTypeparams()); llvm::SmallVector newResultTypes; - if (callOp.callee()) { + if (callOp.getCallee()) { llvm::SmallVector newOperands = {arg}; newOperands.append(callOp.getOperands().begin(), callOp.getOperands().end()); - rewriter.create(loc, callOp.callee().getValue(), + rewriter.create(loc, callOp.getCallee().getValue(), newResultTypes, newOperands); } else { // Indirect calls. @@ -163,8 +163,8 @@ bool replacedStorage = false; if (auto *op = returnedValue.getDefiningOp()) if (auto load = mlir::dyn_cast(op)) { - auto resultStorage = load.memref(); - load.memref().replaceAllUsesWith(options.newArg); + auto resultStorage = load.getMemref(); + load.getMemref().replaceAllUsesWith(options.newArg); replacedStorage = true; if (auto *alloc = resultStorage.getDefiningOp()) if (alloc->use_empty()) @@ -197,7 +197,7 @@ auto oldFuncTy = addrOf.getType().cast(); auto newFuncTy = getNewFunctionType(oldFuncTy, options); auto newAddrOf = rewriter.create(addrOf.getLoc(), newFuncTy, - addrOf.symbol()); + addrOf.getSymbol()); // Rather than converting all op a function pointer might transit through // (e.g calls, stores, loads, converts...), cast new type to the abstract // type. A conversion will be added when calling indirect calls of abstract diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -92,23 +92,24 @@ mlir::LogicalResult matchAndRewrite(fir::ConvertOp op, mlir::PatternRewriter &rewriter) const override { - if (op.res().getType().isa()) { + if (op.getRes().getType().isa()) { // due to index calculation moving to affine maps we still need to // add converts for sequence types this has a side effect of losing // some information about arrays with known dimensions by creating: // fir.convert %arg0 : (!fir.ref>) -> // !fir.ref> - if (auto refTy = op.value().getType().dyn_cast()) + if (auto refTy = op.getValue().getType().dyn_cast()) if (auto arrTy = refTy.getEleTy().dyn_cast()) { fir::SequenceType::Shape flatShape = { fir::SequenceType::getUnknownExtent()}; auto flatArrTy = fir::SequenceType::get(flatShape, arrTy.getEleTy()); auto flatTy = fir::ReferenceType::get(flatArrTy); - rewriter.replaceOpWithNewOp(op, flatTy, op.value()); + rewriter.replaceOpWithNewOp(op, flatTy, + op.getValue()); return success(); } rewriter.startRootUpdate(op->getParentOp()); - op.getResult().replaceAllUsesWith(op.value()); + op.getResult().replaceAllUsesWith(op.getValue()); rewriter.finalizeRootUpdate(op->getParentOp()); rewriter.eraseOp(op); } @@ -151,7 +152,7 @@ mlir::ConversionTarget target(*context); target.addIllegalOp(); target.addDynamicallyLegalOp([](fir::ConvertOp op) { - if (op.res().getType().isa()) + if (op.getRes().getType().isa()) return false; return true; }); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -106,7 +106,7 @@ bool analyzeReference(mlir::Value memref, mlir::Operation *op) { if (auto acoOp = memref.getDefiningOp()) { - if (acoOp.memref().getType().isa()) { + if (acoOp.getMemref().getType().isa()) { // TODO: Look if and how fir.box can be promoted to affine. LLVM_DEBUG(llvm::dbgs() << "AffineLoopAnalysis: cannot promote loop, " "array memory operation uses fir.box\n"; @@ -114,7 +114,7 @@ return false; } bool canPromote = true; - for (auto coordinate : acoOp.indices()) + for (auto coordinate : acoOp.getIndices()) canPromote = canPromote && analyzeCoordinate(coordinate, op); return canPromote; } @@ -134,10 +134,10 @@ bool analyzeMemoryAccess(fir::DoLoopOp loopOperation) { for (auto loadOp : loopOperation.getOps()) - if (!analyzeReference(loadOp.memref(), loadOp)) + if (!analyzeReference(loadOp.getMemref(), loadOp)) return false; for (auto storeOp : loopOperation.getOps()) - if (!analyzeReference(storeOp.memref(), storeOp)) + if (!analyzeReference(storeOp.getMemref(), storeOp)) return false; return true; } @@ -334,7 +334,8 @@ } static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) { - if (auto refType = op.memref().getType().dyn_cast_or_null()) { + if (auto refType = + op.getMemref().getType().dyn_cast_or_null()) { if (auto seqType = refType.getEleTy().dyn_cast_or_null()) { return seqType.getEleTy(); } @@ -349,7 +350,7 @@ mlir::PatternRewriter &rewriter) { auto one = rewriter.create( acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); - auto extents = shape.extents(); + auto extents = shape.getExtents(); for (auto i = extents.begin(); i < extents.end(); i++) { indexArgs.push_back(one); indexArgs.push_back(*i); @@ -362,7 +363,7 @@ mlir::PatternRewriter &rewriter) { auto one = rewriter.create( acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); - auto extents = shape.pairs(); + auto extents = shape.getPairs(); for (auto i = extents.begin(); i < extents.end();) { indexArgs.push_back(*i++); indexArgs.push_back(*i++); @@ -373,7 +374,7 @@ static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::SliceOp slice, SmallVectorImpl &indexArgs, mlir::PatternRewriter &rewriter) { - auto extents = slice.triples(); + auto extents = slice.getTriples(); for (auto i = extents.begin(); i < extents.end();) { indexArgs.push_back(*i++); indexArgs.push_back(*i++); @@ -384,11 +385,11 @@ static void populateIndexArgs(fir::ArrayCoorOp acoOp, SmallVectorImpl &indexArgs, mlir::PatternRewriter &rewriter) { - if (auto shape = acoOp.shape().getDefiningOp()) + if (auto shape = acoOp.getShape().getDefiningOp()) return populateIndexArgs(acoOp, shape, indexArgs, rewriter); - if (auto shapeShift = acoOp.shape().getDefiningOp()) + if (auto shapeShift = acoOp.getShape().getDefiningOp()) return populateIndexArgs(acoOp, shapeShift, indexArgs, rewriter); - if (auto slice = acoOp.shape().getDefiningOp()) + if (auto slice = acoOp.getShape().getDefiningOp()) return populateIndexArgs(acoOp, slice, indexArgs, rewriter); return; } @@ -398,9 +399,9 @@ createAffineOps(mlir::Value arrayRef, mlir::PatternRewriter &rewriter) { auto acoOp = arrayRef.getDefiningOp(); auto affineMap = - createArrayIndexAffineMap(acoOp.indices().size(), acoOp.getContext()); + createArrayIndexAffineMap(acoOp.getIndices().size(), acoOp.getContext()); SmallVector indexArgs; - indexArgs.append(acoOp.indices().begin(), acoOp.indices().end()); + indexArgs.append(acoOp.getIndices().begin(), acoOp.getIndices().end()); populateIndexArgs(acoOp, indexArgs, rewriter); @@ -408,14 +409,14 @@ affineMap, indexArgs); auto arrayElementType = coordinateArrayElement(acoOp); auto newType = mlir::MemRefType::get({-1}, arrayElementType); - auto arrayConvert = - rewriter.create(acoOp.getLoc(), newType, acoOp.memref()); + auto arrayConvert = rewriter.create(acoOp.getLoc(), newType, + acoOp.getMemref()); return std::make_pair(affineApply, arrayConvert); } static void rewriteLoad(fir::LoadOp loadOp, mlir::PatternRewriter &rewriter) { rewriter.setInsertionPoint(loadOp); - auto affineOps = createAffineOps(loadOp.memref(), rewriter); + auto affineOps = createAffineOps(loadOp.getMemref(), rewriter); rewriter.replaceOpWithNewOp( loadOp, affineOps.second.getResult(), affineOps.first.getResult()); } @@ -423,8 +424,8 @@ static void rewriteStore(fir::StoreOp storeOp, mlir::PatternRewriter &rewriter) { rewriter.setInsertionPoint(storeOp); - auto affineOps = createAffineOps(storeOp.memref(), rewriter); - rewriter.replaceOpWithNewOp(storeOp, storeOp.value(), + auto affineOps = createAffineOps(storeOp.getMemref(), rewriter); + rewriter.replaceOpWithNewOp(storeOp, storeOp.getValue(), affineOps.second.getResult(), affineOps.first.getResult()); } @@ -481,7 +482,7 @@ private: std::pair createAffineFor(fir::DoLoopOp op, mlir::PatternRewriter &rewriter) const { - if (auto constantStep = constantIntegerLike(op.step())) + if (auto constantStep = constantIntegerLike(op.getStep())) if (constantStep.getValue() > 0) return positiveConstantStep(op, constantStep.getValue(), rewriter); return genericBounds(op, rewriter); @@ -492,10 +493,10 @@ positiveConstantStep(fir::DoLoopOp op, int64_t step, mlir::PatternRewriter &rewriter) const { auto affineFor = rewriter.create( - op.getLoc(), ValueRange(op.lowerBound()), + op.getLoc(), ValueRange(op.getLowerBound()), mlir::AffineMap::get(0, 1, mlir::getAffineSymbolExpr(0, op.getContext())), - ValueRange(op.upperBound()), + ValueRange(op.getUpperBound()), mlir::AffineMap::get(0, 1, 1 + mlir::getAffineSymbolExpr(0, op.getContext())), step); @@ -511,7 +512,7 @@ 0, 3, (upperBound - lowerBound + step).floorDiv(step)); auto genericUpperBound = rewriter.create( op.getLoc(), upperBoundMap, - ValueRange({op.lowerBound(), op.upperBound(), op.step()})); + ValueRange({op.getLowerBound(), op.getUpperBound(), op.getStep()})); auto actualIndexMap = mlir::AffineMap::get( 1, 2, (lowerBound + mlir::getAffineDimExpr(0, op.getContext())) * @@ -527,7 +528,8 @@ rewriter.setInsertionPointToStart(affineFor.getBody()); auto actualIndex = rewriter.create( op.getLoc(), actualIndexMap, - ValueRange({affineFor.getInductionVar(), op.lowerBound(), op.step()})); + ValueRange( + {affineFor.getInductionVar(), op.getLowerBound(), op.getStep()})); return std::make_pair(affineFor, actualIndex.getResult()); } @@ -545,8 +547,8 @@ mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "AffineIfConversion: rewriting if:\n"; op.dump();); - auto &ifOps = op.thenRegion().front().getOperations(); - auto affineCondition = AffineIfCondition(op.condition()); + auto &ifOps = op.getThenRegion().front().getOperations(); + auto affineCondition = AffineIfCondition(op.getCondition()); if (!affineCondition.hasIntegerSet()) { LLVM_DEBUG( llvm::dbgs() @@ -555,13 +557,13 @@ } auto affineIf = rewriter.create( op.getLoc(), affineCondition.getIntegerSet(), - affineCondition.getAffineArgs(), !op.elseRegion().empty()); + affineCondition.getAffineArgs(), !op.getElseRegion().empty()); rewriter.startRootUpdate(affineIf); affineIf.getThenBlock()->getOperations().splice( std::prev(affineIf.getThenBlock()->end()), ifOps, ifOps.begin(), std::prev(ifOps.end())); - if (!op.elseRegion().empty()) { - auto &otherOps = op.elseRegion().front().getOperations(); + if (!op.getElseRegion().empty()) { + auto &otherOps = op.getElseRegion().front().getOperations(); affineIf.getElseBlock()->getOperations().splice( std::prev(affineIf.getElseBlock()->end()), otherOps, otherOps.begin(), std::prev(otherOps.end())); diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -139,7 +139,7 @@ } if (auto mergeStore = mlir::dyn_cast(op)) { if (opIsInsideLoops(mergeStore)) - collectArrayAccessFrom(mergeStore.sequence()); + collectArrayAccessFrom(mergeStore.getSequence()); return; } @@ -149,7 +149,7 @@ for (mlir::Operation *user : op->getUsers()) if (auto store = mlir::dyn_cast(user)) if (opIsInsideLoops(store)) - collectArrayAccessFrom(store.value()); + collectArrayAccessFrom(store.getValue()); return; } @@ -285,7 +285,7 @@ auto structuredLoop = [&](auto ro) { if (auto blockArg = ro.iterArgToBlockArg(operand->get())) { int64_t arg = blockArg.getArgNumber(); - mlir::Value output = ro.getResult(ro.finalValue() ? arg : arg - 1); + mlir::Value output = ro.getResult(ro.getFinalValue() ? arg : arg - 1); appendToQueue(output); appendToQueue(blockArg); } @@ -353,19 +353,19 @@ static bool conflictOnLoad(llvm::ArrayRef reach, ArrayMergeStoreOp st) { mlir::Value load; - mlir::Value addr = st.memref(); + mlir::Value addr = st.getMemref(); auto stEleTy = fir::dyn_cast_ptrOrBoxEleTy(addr.getType()); for (auto *op : reach) { auto ld = mlir::dyn_cast(op); if (!ld) continue; - mlir::Type ldTy = ld.memref().getType(); + mlir::Type ldTy = ld.getMemref().getType(); if (auto boxTy = ldTy.dyn_cast()) ldTy = boxTy.getEleTy(); if (ldTy.isa() && stEleTy == dyn_cast_ptrEleTy(ldTy)) return true; - if (ld.memref() == addr) { - if (ld.getResult() != st.original()) + if (ld.getMemref() == addr) { + if (ld.getResult() != st.getOriginal()) return true; if (load) return true; @@ -391,22 +391,22 @@ llvm::SmallVector compareVector; if (auto u = mlir::dyn_cast(op)) { if (indices.empty()) { - indices = u.indices(); + indices = u.getIndices(); continue; } - compareVector = u.indices(); + compareVector = u.getIndices(); } else if (auto f = mlir::dyn_cast(op)) { if (indices.empty()) { - indices = f.indices(); + indices = f.getIndices(); continue; } - compareVector = f.indices(); + compareVector = f.getIndices(); } else if (auto f = mlir::dyn_cast(op)) { if (indices.empty()) { - indices = f.indices(); + indices = f.getIndices(); continue; } - compareVector = f.indices(); + compareVector = f.getIndices(); } if (compareVector != indices) return true; @@ -428,18 +428,18 @@ topLevelOp->walk([&](Operation *op) { if (auto st = mlir::dyn_cast(op)) { llvm::SmallVector values; - ReachCollector::reachingValues(values, st.sequence()); - const llvm::SmallVector &accesses = - arrayAccesses(mlir::cast(st.original().getDefiningOp())); + ReachCollector::reachingValues(values, st.getSequence()); + const llvm::SmallVector &accesses = arrayAccesses( + mlir::cast(st.getOriginal().getDefiningOp())); if (conflictDetected(values, accesses, st)) { LLVM_DEBUG(llvm::dbgs() << "CONFLICT: copies required for " << st << '\n' << " adding conflicts on: " << op << " and " - << st.original() << '\n'); + << st.getOriginal() << '\n'); conflicts.insert(op); - conflicts.insert(st.original().getDefiningOp()); + conflicts.insert(st.getOriginal().getDefiningOp()); } - auto *ld = st.original().getDefiningOp(); + auto *ld = st.getOriginal().getDefiningOp(); LLVM_DEBUG(llvm::dbgs() << "map: adding {" << *ld << " -> " << st << "}\n"); useMap.insert({ld, op}); @@ -533,22 +533,22 @@ fir::ArrayLoadOp loadOp, llvm::SmallVectorImpl &result) { assert(result.empty()); - if (auto boxTy = loadOp.memref().getType().dyn_cast()) { + if (auto boxTy = loadOp.getMemref().getType().dyn_cast()) { auto rank = fir::dyn_cast_ptrOrBoxEleTy(boxTy) .cast() .getDimension(); auto idxTy = rewriter.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { auto dimVal = rewriter.create(loc, dim); - auto dimInfo = rewriter.create(loc, idxTy, idxTy, idxTy, - loadOp.memref(), dimVal); + auto dimInfo = rewriter.create( + loc, idxTy, idxTy, idxTy, loadOp.getMemref(), dimVal); result.emplace_back(dimInfo.getResult(1)); } auto shapeType = fir::ShapeType::get(rewriter.getContext(), rank); return rewriter.create(loc, shapeType, result); } - getExtents(result, loadOp.shape()); - return loadOp.shape(); + getExtents(result, loadOp.getShape()); + return loadOp.getShape(); } static mlir::Type toRefType(mlir::Type ty) { @@ -657,22 +657,22 @@ mlir::Value shapeOp = getOrReadExtentsAndShapeOp(loc, rewriter, load, extents); auto allocmem = rewriter.create( - loc, dyn_cast_ptrOrBoxEleTy(load.memref().getType()), - load.typeparams(), extents); - genArrayCopy(load.getLoc(), rewriter, allocmem, load.memref(), shapeOp, + loc, dyn_cast_ptrOrBoxEleTy(load.getMemref().getType()), + load.getTypeparams(), extents); + genArrayCopy(load.getLoc(), rewriter, allocmem, load.getMemref(), shapeOp, load.getType()); rewriter.setInsertionPoint(op); mlir::Value coor = genCoorOp( rewriter, loc, getEleTy(load.getType()), lhsEltRefType, allocmem, - shapeOp, load.slice(), update.indices(), load.typeparams(), + shapeOp, load.getSlice(), update.getIndices(), load.getTypeparams(), update->hasAttr(fir::factory::attrFortranArrayOffsets())); assignElement(coor); mlir::Operation *storeOp = useMap.lookup(loadOp); auto store = mlir::cast(storeOp); rewriter.setInsertionPoint(storeOp); // Copy out. - genArrayCopy(store.getLoc(), rewriter, store.memref(), allocmem, shapeOp, - load.getType()); + genArrayCopy(store.getLoc(), rewriter, store.getMemref(), allocmem, + shapeOp, load.getType()); rewriter.create(loc, allocmem); return {coor, load.getResult()}; } @@ -682,8 +682,8 @@ rewriter.setInsertionPoint(op); auto coorTy = getEleTy(load.getType()); mlir::Value coor = genCoorOp( - rewriter, loc, coorTy, lhsEltRefType, load.memref(), load.shape(), - load.slice(), update.indices(), load.typeparams(), + rewriter, loc, coorTy, lhsEltRefType, load.getMemref(), load.getShape(), + load.getSlice(), update.getIndices(), load.getTypeparams(), update->hasAttr(fir::factory::attrFortranArrayOffsets())); assignElement(coor); return {coor, load.getResult()}; @@ -706,9 +706,9 @@ mlir::PatternRewriter &rewriter) const override { auto loc = update.getLoc(); auto assignElement = [&](mlir::Value coor) { - rewriter.create(loc, update.merge(), coor); + rewriter.create(loc, update.getMerge(), coor); }; - auto lhsEltRefType = toRefType(update.merge().getType()); + auto lhsEltRefType = toRefType(update.getMerge().getType()); auto [_, lhsLoadResult] = materializeAssignment( loc, rewriter, update, assignElement, lhsEltRefType); update.replaceAllUsesWith(lhsLoadResult); @@ -755,8 +755,8 @@ auto loc = fetch.getLoc(); mlir::Value coor = genCoorOp(rewriter, loc, getEleTy(load.getType()), - toRefType(fetch.getType()), load.memref(), load.shape(), - load.slice(), fetch.indices(), load.typeparams(), + toRefType(fetch.getType()), load.getMemref(), load.getShape(), + load.getSlice(), fetch.getIndices(), load.getTypeparams(), fetch->hasAttr(fir::factory::attrFortranArrayOffsets())); rewriter.replaceOpWithNewOp(fetch, coor); return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -46,7 +46,7 @@ auto zero = rewriter.create(loc, 0); auto one = rewriter.create(loc, 1); auto idxTy = rewriter.getIndexType(); - auto castCnt = rewriter.create(loc, idxTy, conv.count()); + auto castCnt = rewriter.create(loc, idxTy, conv.getCount()); auto countm1 = rewriter.create(loc, castCnt, one); auto loop = rewriter.create(loc, zero, countm1, one); auto insPt = rewriter.saveInsertionPoint(); @@ -59,8 +59,8 @@ .cast(); return kindMap.getCharacterBitsize(chrTy.getFKind()); }; - auto fromBits = getCharBits(conv.from().getType()); - auto toBits = getCharBits(conv.to().getType()); + auto fromBits = getCharBits(conv.getFrom().getType()); + auto toBits = getCharBits(conv.getTo().getType()); auto pointerType = [&](unsigned bits) { return fir::ReferenceType::get(fir::SequenceType::get( fir::SequenceType::ShapeRef{fir::SequenceType::getUnknownExtent()}, @@ -69,8 +69,9 @@ auto fromPtrTy = pointerType(fromBits); auto toTy = rewriter.getIntegerType(toBits); auto toPtrTy = pointerType(toBits); - auto fromPtr = rewriter.create(loc, fromPtrTy, conv.from()); - auto toPtr = rewriter.create(loc, toPtrTy, conv.to()); + auto fromPtr = + rewriter.create(loc, fromPtrTy, conv.getFrom()); + auto toPtr = rewriter.create(loc, toPtrTy, conv.getTo()); auto getEleTy = [&](unsigned bits) { return fir::ReferenceType::get(rewriter.getIntegerType(bits)); }; diff --git a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp --- a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp +++ b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp @@ -46,12 +46,12 @@ matchAndRewrite(fir::CallOp op, mlir::PatternRewriter &rewriter) const override { rewriter.startRootUpdate(op); - auto callee = op.callee(); + auto callee = op.getCallee(); if (callee.hasValue()) { auto result = fir::NameUniquer::deconstruct( callee.getValue().getRootReference().getValue()); if (fir::NameUniquer::isExternalFacingUniquedName(result)) - op.calleeAttr( + op.setCalleeAttr( SymbolRefAttr::get(op.getContext(), mangleExternalName(result))); } rewriter.finalizeRootUpdate(op); @@ -87,10 +87,10 @@ mlir::PatternRewriter &rewriter) const override { rewriter.startRootUpdate(op); auto result = fir::NameUniquer::deconstruct( - op.symref().getRootReference().getValue()); + op.getSymref().getRootReference().getValue()); if (fir::NameUniquer::isExternalFacingUniquedName(result)) { auto newName = mangleExternalName(result); - op.symrefAttr(mlir::SymbolRefAttr::get(op.getContext(), newName)); + op.setSymrefAttr(mlir::SymbolRefAttr::get(op.getContext(), newName)); SymbolTable::setSymbolName(op, newName); } rewriter.finalizeRootUpdate(op); @@ -106,11 +106,11 @@ matchAndRewrite(fir::AddrOfOp op, mlir::PatternRewriter &rewriter) const override { auto result = fir::NameUniquer::deconstruct( - op.symbol().getRootReference().getValue()); + op.getSymbol().getRootReference().getValue()); if (fir::NameUniquer::isExternalFacingUniquedName(result)) { auto newName = SymbolRefAttr::get(op.getContext(), mangleExternalName(result)); - rewriter.replaceOpWithNewOp(op, op.resTy().getType(), + rewriter.replaceOpWithNewOp(op, op.getResTy().getType(), newName); } return success(); @@ -127,9 +127,9 @@ mlir::PatternRewriter &rewriter) const override { rewriter.startRootUpdate(op); auto result = fir::NameUniquer::deconstruct( - op.funcname().getRootReference().getValue()); + op.getFuncname().getRootReference().getValue()); if (fir::NameUniquer::isExternalFacingUniquedName(result)) - op.funcnameAttr( + op.setFuncnameAttr( SymbolRefAttr::get(op.getContext(), mangleExternalName(result))); rewriter.finalizeRootUpdate(op); return success(); @@ -158,9 +158,9 @@ acc::OpenACCDialect, omp::OpenMPDialect>(); target.addDynamicallyLegalOp([](fir::CallOp op) { - if (op.callee().hasValue()) + if (op.getCallee().hasValue()) return !fir::NameUniquer::needExternalNameMangling( - op.callee().getValue().getRootReference().getValue()); + op.getCallee().getValue().getRootReference().getValue()); return true; }); @@ -170,17 +170,17 @@ target.addDynamicallyLegalOp([](fir::GlobalOp op) { return !fir::NameUniquer::needExternalNameMangling( - op.symref().getRootReference().getValue()); + op.getSymref().getRootReference().getValue()); }); target.addDynamicallyLegalOp([](fir::AddrOfOp op) { return !fir::NameUniquer::needExternalNameMangling( - op.symbol().getRootReference().getValue()); + op.getSymbol().getRootReference().getValue()); }); target.addDynamicallyLegalOp([](fir::EmboxProcOp op) { return !fir::NameUniquer::needExternalNameMangling( - op.funcname().getRootReference().getValue()); + op.getFuncname().getRootReference().getValue()); }); if (failed(applyPartialConversion(op, target, std::move(patterns)))) diff --git a/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp --- a/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp +++ b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp @@ -101,20 +101,20 @@ LoadStoreForwarding lsf(domInfo); f.walk([&](fir::LoadOp loadOp) { auto maybeStore = lsf.findStoreToForward( - loadOp, getSpecificUsers(loadOp.memref())); + loadOp, getSpecificUsers(loadOp.getMemref())); if (maybeStore) { auto storeOp = maybeStore.getValue(); LLVM_DEBUG(llvm::dbgs() << "FlangMemDataFlowOpt: In " << f.getName() << " erasing load " << loadOp << " with value from " << storeOp << '\n'); - loadOp.getResult().replaceAllUsesWith(storeOp.value()); + loadOp.getResult().replaceAllUsesWith(storeOp.getValue()); loadOp.erase(); } }); f.walk([&](fir::AllocaOp alloca) { for (auto &storeOp : getSpecificUsers(alloca.getResult())) { if (!lsf.findReadForWrite( - storeOp, getSpecificUsers(storeOp.memref()))) { + storeOp, getSpecificUsers(storeOp.getMemref()))) { LLVM_DEBUG(llvm::dbgs() << "FlangMemDataFlowOpt: In " << f.getName() << " erasing store " << storeOp << '\n'); storeOp.erase(); diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -115,10 +115,11 @@ return *opt; return {}; }; - auto uniqName = unpackName(alloca.uniq_name()); - auto bindcName = unpackName(alloca.bindc_name()); + auto uniqName = unpackName(alloca.getUniqName()); + auto bindcName = unpackName(alloca.getBindcName()); auto heap = rewriter.create( - loc, varTy, uniqName, bindcName, alloca.typeparams(), alloca.shape()); + loc, varTy, uniqName, bindcName, alloca.getTypeparams(), + alloca.getShape()); auto insPt = rewriter.saveInsertionPoint(); for (mlir::Operation *retOp : returnOps) { rewriter.setInsertionPoint(retOp); diff --git a/flang/lib/Optimizer/Transforms/RewriteLoop.cpp b/flang/lib/Optimizer/Transforms/RewriteLoop.cpp --- a/flang/lib/Optimizer/Transforms/RewriteLoop.cpp +++ b/flang/lib/Optimizer/Transforms/RewriteLoop.cpp @@ -49,20 +49,20 @@ // Split the first DoLoopOp block in two parts. The part before will be the // conditional block since it already has the induction variable and // loop-carried values as arguments. - auto *conditionalBlock = &loop.region().front(); + auto *conditionalBlock = &loop.getRegion().front(); conditionalBlock->addArgument(rewriter.getIndexType(), loc); auto *firstBlock = rewriter.splitBlock(conditionalBlock, conditionalBlock->begin()); - auto *lastBlock = &loop.region().back(); + auto *lastBlock = &loop.getRegion().back(); // Move the blocks from the DoLoopOp between initBlock and endBlock - rewriter.inlineRegionBefore(loop.region(), endBlock); + rewriter.inlineRegionBefore(loop.getRegion(), endBlock); // Get loop values from the DoLoopOp - auto low = loop.lowerBound(); - auto high = loop.upperBound(); + auto low = loop.getLowerBound(); + auto high = loop.getUpperBound(); assert(low && high && "must be a Value"); - auto step = loop.step(); + auto step = loop.getStep(); // Initalization block rewriter.setInsertionPointToEnd(initBlock); @@ -102,8 +102,8 @@ llvm::SmallVector loopCarried; loopCarried.push_back(steppedIndex); - auto begin = loop.finalValue() ? std::next(terminator->operand_begin()) - : terminator->operand_begin(); + auto begin = loop.getFinalValue() ? std::next(terminator->operand_begin()) + : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); loopCarried.push_back(itersMinusOne); rewriter.create(loc, conditionalBlock, loopCarried); @@ -121,7 +121,7 @@ // The result of the loop operation is the values of the condition block // arguments except the induction variable on the last iteration. - auto args = loop.finalValue() + auto args = loop.getFinalValue() ? conditionalBlock->getArguments() : conditionalBlock->getArguments().drop_front(); rewriter.replaceOp(loop, args.drop_back()); @@ -161,7 +161,7 @@ // Move blocks from the "then" region to the region containing 'fir.if', // place it before the continuation block, and branch to it. - auto &ifOpRegion = ifOp.thenRegion(); + auto &ifOpRegion = ifOp.getThenRegion(); auto *ifOpBlock = &ifOpRegion.front(); auto *ifOpTerminator = ifOpRegion.back().getTerminator(); auto ifOpTerminatorOperands = ifOpTerminator->getOperands(); @@ -175,7 +175,7 @@ // 'fir.if', place it before the continuation block and branch to it. It // will be placed after the "then" regions. auto *otherwiseBlock = continueBlock; - auto &otherwiseRegion = ifOp.elseRegion(); + auto &otherwiseRegion = ifOp.getElseRegion(); if (!otherwiseRegion.empty()) { otherwiseBlock = &otherwiseRegion.front(); auto *otherwiseTerm = otherwiseRegion.back().getTerminator(); @@ -189,7 +189,7 @@ rewriter.setInsertionPointToEnd(condBlock); rewriter.create( - loc, ifOp.condition(), ifOpBlock, llvm::ArrayRef(), + loc, ifOp.getCondition(), ifOpBlock, llvm::ArrayRef(), otherwiseBlock, llvm::ArrayRef()); rewriter.replaceOp(ifOp, continueBlock->getArguments()); return success(); @@ -221,11 +221,11 @@ // arguments. Split out all operations from the first block into a new // block. Move all body blocks from the loop body region to the region // containing the loop. - auto *conditionBlock = &whileOp.region().front(); + auto *conditionBlock = &whileOp.getRegion().front(); auto *firstBodyBlock = rewriter.splitBlock(conditionBlock, conditionBlock->begin()); - auto *lastBodyBlock = &whileOp.region().back(); - rewriter.inlineRegionBefore(whileOp.region(), endBlock); + auto *lastBodyBlock = &whileOp.getRegion().back(); + rewriter.inlineRegionBefore(whileOp.getRegion(), endBlock); auto iv = conditionBlock->getArgument(0); auto iterateVar = conditionBlock->getArgument(1); @@ -234,22 +234,23 @@ // operands of the loop terminator. auto *terminator = lastBodyBlock->getTerminator(); rewriter.setInsertionPointToEnd(lastBodyBlock); - auto step = whileOp.step(); + auto step = whileOp.getStep(); mlir::Value stepped = rewriter.create(loc, iv, step); assert(stepped && "must be a Value"); llvm::SmallVector loopCarried; loopCarried.push_back(stepped); - auto begin = whileOp.finalValue() ? std::next(terminator->operand_begin()) - : terminator->operand_begin(); + auto begin = whileOp.getFinalValue() + ? std::next(terminator->operand_begin()) + : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); rewriter.create(loc, conditionBlock, loopCarried); rewriter.eraseOp(terminator); // Compute loop bounds before branching to the condition. rewriter.setInsertionPointToEnd(initBlock); - auto lowerBound = whileOp.lowerBound(); - auto upperBound = whileOp.upperBound(); + auto lowerBound = whileOp.getLowerBound(); + auto upperBound = whileOp.getUpperBound(); assert(lowerBound && upperBound && "must be a Value"); // The initial values of loop-carried values is obtained from the operands @@ -285,7 +286,7 @@ endBlock, llvm::ArrayRef()); // The result of the loop operation is the values of the condition block // arguments except the induction variable on the last iteration. - auto args = whileOp.finalValue() + auto args = whileOp.getFinalValue() ? conditionBlock->getArguments() : conditionBlock->getArguments().drop_front(); rewriter.replaceOp(whileOp, args); diff --git a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp --- a/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp +++ b/flang/unittests/Optimizer/Builder/DoLoopHelperTest.cpp @@ -44,9 +44,9 @@ firBuilder.getUnknownLoc(), firBuilder.getIndexType(), 10); auto loop = helper.createLoop(c10, [&](fir::FirOpBuilder &, mlir::Value index) {}); - checkConstantValue(loop.lowerBound(), 0); - EXPECT_TRUE(mlir::isa(loop.upperBound().getDefiningOp())); - auto subOp = dyn_cast(loop.upperBound().getDefiningOp()); + checkConstantValue(loop.getLowerBound(), 0); + EXPECT_TRUE(mlir::isa(loop.getUpperBound().getDefiningOp())); + auto subOp = dyn_cast(loop.getUpperBound().getDefiningOp()); EXPECT_EQ(c10, subOp.getLhs()); checkConstantValue(subOp.getRhs(), 1); checkConstantValue(loop.getStep(), 1); diff --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp --- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp +++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp @@ -185,13 +185,13 @@ auto global = builder.createGlobal( loc, i64Type, "global1", builder.createInternalLinkage(), {}, true); EXPECT_TRUE(mlir::isa(global)); - EXPECT_EQ("global1", global.sym_name()); - EXPECT_TRUE(global.constant().hasValue()); + EXPECT_EQ("global1", global.getSymName()); + EXPECT_TRUE(global.getConstant().hasValue()); EXPECT_EQ(i64Type, global.type()); - EXPECT_TRUE(global.linkName().hasValue()); - EXPECT_EQ( - builder.createInternalLinkage().getValue(), global.linkName().getValue()); - EXPECT_FALSE(global.initVal().hasValue()); + EXPECT_TRUE(global.getLinkName().hasValue()); + EXPECT_EQ(builder.createInternalLinkage().getValue(), + global.getLinkName().getValue()); + EXPECT_FALSE(global.getInitVal().hasValue()); auto g1 = builder.getNamedGlobal("global1"); EXPECT_EQ(global, g1); @@ -209,16 +209,16 @@ auto global = builder.createGlobal( loc, i32Type, "global2", builder.createLinkOnceLinkage(), attr, false); EXPECT_TRUE(mlir::isa(global)); - EXPECT_EQ("global2", global.sym_name()); - EXPECT_FALSE(global.constant().hasValue()); + EXPECT_EQ("global2", global.getSymName()); + EXPECT_FALSE(global.getConstant().hasValue()); EXPECT_EQ(i32Type, global.type()); - EXPECT_TRUE(global.initVal().hasValue()); - EXPECT_TRUE(global.initVal().getValue().isa()); - EXPECT_EQ( - 16, global.initVal().getValue().cast().getValue()); - EXPECT_TRUE(global.linkName().hasValue()); + EXPECT_TRUE(global.getInitVal().hasValue()); + EXPECT_TRUE(global.getInitVal().getValue().isa()); EXPECT_EQ( - builder.createLinkOnceLinkage().getValue(), global.linkName().getValue()); + 16, global.getInitVal().getValue().cast().getValue()); + EXPECT_TRUE(global.getLinkName().hasValue()); + EXPECT_EQ(builder.createLinkOnceLinkage().getValue(), + global.getLinkName().getValue()); } TEST_F(FIRBuilderTest, uniqueCFIdent) { @@ -263,7 +263,7 @@ mlir::FileLineColLoc::get(builder.getStringAttr("file1.f90"), 10, 5); mlir::Value locToFile = fir::factory::locationToFilename(builder, loc); auto addrOp = dyn_cast(locToFile.getDefiningOp()); - auto symbol = addrOp.symbol().getRootReference().getValue(); + auto symbol = addrOp.getSymbol().getRootReference().getValue(); auto global = builder.getNamedGlobal(symbol); auto stringLitOps = global.getRegion().front().getOps(); EXPECT_TRUE(llvm::hasSingleElement(stringLitOps)); @@ -305,10 +305,10 @@ auto addr = charBox->getBuffer(); EXPECT_TRUE(mlir::isa(addr.getDefiningOp())); auto addrOp = dyn_cast(addr.getDefiningOp()); - auto symbol = addrOp.symbol().getRootReference().getValue(); + auto symbol = addrOp.getSymbol().getRootReference().getValue(); auto global = builder.getNamedGlobal(symbol); - EXPECT_EQ( - builder.createLinkOnceLinkage().getValue(), global.linkName().getValue()); + EXPECT_EQ(builder.createLinkOnceLinkage().getValue(), + global.getLinkName().getValue()); EXPECT_EQ(fir::CharacterType::get(builder.getContext(), 1, strValue.size()), global.type()); @@ -329,13 +329,13 @@ loc, builder.getI64Type(), "", varName, {}, {}, false); EXPECT_TRUE(mlir::isa(var.getDefiningOp())); auto allocaOp = dyn_cast(var.getDefiningOp()); - EXPECT_EQ(builder.getI64Type(), allocaOp.in_type()); - EXPECT_TRUE(allocaOp.bindc_name().hasValue()); - EXPECT_EQ(varName, allocaOp.bindc_name().getValue()); - EXPECT_FALSE(allocaOp.uniq_name().hasValue()); - EXPECT_FALSE(allocaOp.pinned()); - EXPECT_EQ(0u, allocaOp.typeparams().size()); - EXPECT_EQ(0u, allocaOp.shape().size()); + EXPECT_EQ(builder.getI64Type(), allocaOp.getInType()); + EXPECT_TRUE(allocaOp.getBindcName().hasValue()); + EXPECT_EQ(varName, allocaOp.getBindcName().getValue()); + EXPECT_FALSE(allocaOp.getUniqName().hasValue()); + EXPECT_FALSE(allocaOp.getPinned()); + EXPECT_EQ(0u, allocaOp.getTypeparams().size()); + EXPECT_EQ(0u, allocaOp.getShape().size()); } static void checkShapeOp(mlir::Value shape, mlir::Value c10, mlir::Value c100) { diff --git a/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h b/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h --- a/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h +++ b/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h @@ -85,13 +85,13 @@ unsigned nbArgs, bool addLocArgs = true) { EXPECT_TRUE(mlir::isa(*op)); auto callOp = mlir::dyn_cast(*op); - EXPECT_TRUE(callOp.callee().hasValue()); - mlir::SymbolRefAttr callee = *callOp.callee(); + EXPECT_TRUE(callOp.getCallee().hasValue()); + mlir::SymbolRefAttr callee = *callOp.getCallee(); EXPECT_EQ(fctName, callee.getRootReference().getValue()); // sourceFile and sourceLine are added arguments. if (addLocArgs) nbArgs += 2; - EXPECT_EQ(nbArgs, callOp.args().size()); + EXPECT_EQ(nbArgs, callOp.getArgs().size()); } /// Check the call operation from the \p result value. In some cases the @@ -133,8 +133,8 @@ assert(block && "mlir::Block given is a nullptr"); for (auto &op : block->getOperations()) { if (auto callOp = mlir::dyn_cast(op)) { - if (fctName == callOp.callee()->getRootReference().getValue()) { - EXPECT_EQ(nbArgs, callOp.args().size()); + if (fctName == callOp.getCallee()->getRootReference().getValue()) { + EXPECT_EQ(nbArgs, callOp.getArgs().size()); return; } }