From 44e58509be72b49c3abc7b4c5a7ffa81a754fe1c Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Tue, 26 Apr 2022 13:44:34 -0700 Subject: [PATCH] [NFC] More synching of sources for upstreaming. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D124476 --- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 275 +++++++++--------- flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 143 ++++----- flang/lib/Optimizer/CodeGen/TypeConverter.h | 16 +- flang/test/Fir/addrof.fir | 2 +- flang/test/Fir/embox.fir | 2 +- flang/test/Fir/rebox.fir | 2 +- 6 files changed, 221 insertions(+), 219 deletions(-) diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 41dd2a3df850..2cc41382f0d1 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -32,8 +32,6 @@ #define DEBUG_TYPE "flang-codegen" -using namespace mlir; - // fir::LLVMTypeConverter for converting to LLVM IR dialect types. #include "TypeConverter.h" @@ -57,8 +55,8 @@ genConstantIndex(mlir::Location loc, mlir::Type ity, return rewriter.create(loc, ity, cattr); } -static Block *createBlock(mlir::ConversionPatternRewriter &rewriter, - mlir::Block *insertBefore) { +static mlir::Block *createBlock(mlir::ConversionPatternRewriter &rewriter, + mlir::Block *insertBefore) { assert(insertBefore && "expected valid insertion block"); return rewriter.createBlock(insertBefore->getParent(), mlir::Region::iterator(insertBefore)); @@ -138,8 +136,8 @@ protected: /// Method to construct code sequence to get the triple for dimension `dim` /// from a box. - SmallVector - getDimsFromBox(mlir::Location loc, ArrayRef retTys, + llvm::SmallVector + getDimsFromBox(mlir::Location loc, llvm::ArrayRef retTys, mlir::Value box, mlir::Value dim, mlir::ConversionPatternRewriter &rewriter) const { mlir::LLVM::ConstantOp c0 = genConstantOffset(loc, rewriter, 0); @@ -248,7 +246,7 @@ protected: mlir::LLVM::GEPOp genGEP(mlir::Location loc, mlir::Type ty, mlir::ConversionPatternRewriter &rewriter, mlir::Value base, ARGS... args) const { - SmallVector cv{args...}; + llvm::SmallVector cv{args...}; return rewriter.create(loc, ty, base, cv); } @@ -288,7 +286,7 @@ struct AddrOfOpConversion : public FIROpConversion { auto ty = convertType(addr.getType()); rewriter.replaceOpWithNewOp( addr, ty, addr.getSymbol().getRootReference().getValue()); - return success(); + return mlir::success(); } }; } // namespace @@ -379,7 +377,7 @@ struct AllocaOpConversion : public FIROpConversion { alloc->getAttrs()); rewriter.replaceOpWithNewOp(alloc, resultTy, al); } - return success(); + return mlir::success(); } }; } // namespace @@ -415,7 +413,7 @@ struct BoxAddrOpConversion : public FIROpConversion { rewriter.replaceOpWithNewOp(boxaddr, ty, a, c0); } - return success(); + return mlir::success(); } }; @@ -438,7 +436,7 @@ struct BoxCharLenOpConversion : public FIROpConversion { mlir::Value lenAfterCast = integerCast(loc, rewriter, returnValTy, len); rewriter.replaceOp(boxCharLen, lenAfterCast); - return success(); + return mlir::success(); } }; @@ -451,7 +449,7 @@ struct BoxDimsOpConversion : public FIROpConversion { mlir::LogicalResult matchAndRewrite(fir::BoxDimsOp boxdims, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - SmallVector resultTypes = { + llvm::SmallVector resultTypes = { convertType(boxdims.getResult(0).getType()), convertType(boxdims.getResult(1).getType()), convertType(boxdims.getResult(2).getType()), @@ -460,7 +458,7 @@ struct BoxDimsOpConversion : public FIROpConversion { getDimsFromBox(boxdims.getLoc(), resultTypes, adaptor.getOperands()[0], adaptor.getOperands()[1], rewriter); rewriter.replaceOp(boxdims, results); - return success(); + return mlir::success(); } }; @@ -477,7 +475,7 @@ struct BoxEleSizeOpConversion : public FIROpConversion { auto ty = convertType(boxelesz.getType()); auto elemSize = getValueFromBox(loc, a, ty, rewriter, kElemLenPosInBox); rewriter.replaceOp(boxelesz, elemSize); - return success(); + return mlir::success(); } }; @@ -494,7 +492,7 @@ struct BoxIsAllocOpConversion : public FIROpConversion { mlir::Value check = genBoxAttributeCheck(loc, box, rewriter, kAttrAllocatable); rewriter.replaceOp(boxisalloc, check); - return success(); + return mlir::success(); } }; @@ -513,7 +511,7 @@ struct BoxIsArrayOpConversion : public FIROpConversion { auto c0 = genConstantOffset(loc, rewriter, 0); rewriter.replaceOpWithNewOp( boxisarray, mlir::LLVM::ICmpPredicate::ne, rank, c0); - return success(); + return mlir::success(); } }; @@ -529,7 +527,7 @@ struct BoxIsPtrOpConversion : public FIROpConversion { auto loc = boxisptr.getLoc(); mlir::Value check = genBoxAttributeCheck(loc, box, rewriter, kAttrPointer); rewriter.replaceOp(boxisptr, check); - return success(); + return mlir::success(); } }; @@ -546,7 +544,7 @@ struct BoxRankOpConversion : public FIROpConversion { mlir::Type ty = convertType(boxrank.getType()); auto result = getValueFromBox(loc, a, ty, rewriter, kRankPosInBox); rewriter.replaceOp(boxrank, result); - return success(); + return mlir::success(); } }; @@ -560,7 +558,7 @@ struct BoxProcHostOpConversion : public FIROpConversion { matchAndRewrite(fir::BoxProcHostOp boxprochost, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(boxprochost.getLoc(), "fir.boxproc_host codegen"); - return failure(); + return mlir::failure(); } }; @@ -580,7 +578,7 @@ struct BoxTypeDescOpConversion : public FIROpConversion { auto typePtrTy = mlir::LLVM::LLVMPointerType::get(typeTy); rewriter.replaceOpWithNewOp(boxtypedesc, typePtrTy, result); - return success(); + return mlir::success(); } }; @@ -595,7 +593,7 @@ struct StringLitOpConversion : public FIROpConversion { auto attr = constop.getValue(); if (attr.isa()) { rewriter.replaceOpWithNewOp(constop, ty, attr); - return success(); + return mlir::success(); } auto charTy = constop.getType().cast(); @@ -619,10 +617,10 @@ struct StringLitOpConversion : public FIROpConversion { index); } } else { - return failure(); + return mlir::failure(); } rewriter.replaceOp(constop, cst); - return success(); + return mlir::success(); } }; @@ -633,12 +631,12 @@ struct CallOpConversion : public FIROpConversion { mlir::LogicalResult matchAndRewrite(fir::CallOp call, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - SmallVector resultTys; + llvm::SmallVector resultTys; for (auto r : call.getResults()) resultTys.push_back(convertType(r.getType())); rewriter.replaceOpWithNewOp( call, resultTys, adaptor.getOperands(), call->getAttrs()); - return success(); + return mlir::success(); } }; } // namespace @@ -667,20 +665,22 @@ struct CmpcOpConversion : public FIROpConversion { mlir::Type resTy = convertType(cmp.getType()); mlir::Location loc = cmp.getLoc(); auto pos0 = mlir::ArrayAttr::get(ctxt, rewriter.getI32IntegerAttr(0)); - SmallVector rp{rewriter.create( - loc, eleTy, operands[0], pos0), - rewriter.create( - loc, eleTy, operands[1], pos0)}; + llvm::SmallVector rp{ + rewriter.create(loc, eleTy, operands[0], + pos0), + rewriter.create(loc, eleTy, operands[1], + pos0)}; auto rcp = rewriter.create(loc, resTy, rp, cmp->getAttrs()); auto pos1 = mlir::ArrayAttr::get(ctxt, rewriter.getI32IntegerAttr(1)); - SmallVector ip{rewriter.create( - loc, eleTy, operands[0], pos1), - rewriter.create( - loc, eleTy, operands[1], pos1)}; + llvm::SmallVector ip{ + rewriter.create(loc, eleTy, operands[0], + pos1), + rewriter.create(loc, eleTy, operands[1], + pos1)}; auto icp = rewriter.create(loc, resTy, ip, cmp->getAttrs()); - SmallVector cp{rcp, icp}; + llvm::SmallVector cp{rcp, icp}; switch (cmp.getPredicate()) { case mlir::arith::CmpFPredicate::OEQ: // .EQ. rewriter.replaceOpWithNewOp(cmp, resTy, cp); @@ -692,7 +692,7 @@ struct CmpcOpConversion : public FIROpConversion { rewriter.replaceOp(cmp, rcp.getResult()); break; } - return success(); + return mlir::success(); } }; @@ -720,10 +720,10 @@ struct ConstcOpConversion : public FIROpConversion { loc, ty, undef, realPart, realIndex); rewriter.replaceOpWithNewOp(conc, ty, setReal, imPart, imIndex); - return success(); + return mlir::success(); } - inline APFloat getValue(mlir::Attribute attr) const { + inline llvm::APFloat getValue(mlir::Attribute attr) const { return attr.cast().getValue(); } }; @@ -746,7 +746,7 @@ struct ConvertOpConversion : public FIROpConversion { mlir::Value op0 = adaptor.getOperands()[0]; if (fromTy == toTy) { rewriter.replaceOp(convert, op0); - return success(); + return mlir::success(); } auto loc = convert.getLoc(); auto convertFpToFp = [&](mlir::Value val, unsigned fromBits, @@ -863,7 +863,7 @@ struct DispatchOpConversion : public FIROpConversion { matchAndRewrite(fir::DispatchOp dispatch, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(dispatch.getLoc(), "fir.dispatch codegen"); - return failure(); + return mlir::failure(); } }; @@ -877,7 +877,7 @@ struct DispatchTableOpConversion matchAndRewrite(fir::DispatchTableOp dispTab, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(dispTab.getLoc(), "fir.dispatch_table codegen"); - return failure(); + return mlir::failure(); } }; @@ -890,7 +890,7 @@ struct DTEntryOpConversion : public FIROpConversion { matchAndRewrite(fir::DTEntryOp dtEnt, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(dtEnt.getLoc(), "fir.dt_entry codegen"); - return failure(); + return mlir::failure(); } }; @@ -902,7 +902,7 @@ struct GlobalLenOpConversion : public FIROpConversion { matchAndRewrite(fir::GlobalLenOp globalLen, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(globalLen.getLoc(), "fir.global_len codegen"); - return failure(); + return mlir::failure(); } }; @@ -930,7 +930,7 @@ struct EmboxCharOpConversion : public FIROpConversion { matchAndRewrite(fir::EmboxCharOp emboxChar, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); - MLIRContext *ctx = emboxChar.getContext(); + auto *ctx = emboxChar.getContext(); mlir::Value charBuffer = operands[0]; mlir::Value charBufferLen = operands[1]; @@ -950,7 +950,7 @@ struct EmboxCharOpConversion : public FIROpConversion { rewriter.replaceOpWithNewOp( emboxChar, llvmStructTy, insertBufferOp, lenAfterCast, c1); - return success(); + return mlir::success(); } }; } // namespace @@ -1021,7 +1021,7 @@ struct AllocMemOpConversion : public FIROpConversion { loc, ::getVoidPtrType(heap.getContext()), size, heap->getAttrs()); rewriter.replaceOpWithNewOp(heap, ty, malloc.getResult(0)); - return success(); + return mlir::success(); } // Compute the (allocation) size of the allocmem type in bytes. @@ -1072,7 +1072,7 @@ struct FreeMemOpConversion : public FIROpConversion { rewriter.create( loc, mlir::TypeRange{}, mlir::ValueRange{bitcast}, freemem->getAttrs()); rewriter.eraseOp(freemem); - return success(); + return mlir::success(); } }; } // namespace @@ -1240,15 +1240,15 @@ struct EmboxCommonConversion : public FIROpConversion { /// Basic pattern to write a field in the descriptor mlir::Value insertField(mlir::ConversionPatternRewriter &rewriter, mlir::Location loc, mlir::Value dest, - ArrayRef fldIndexes, mlir::Value value, - bool bitcast = false) const { + llvm::ArrayRef fldIndexes, + mlir::Value value, bool bitcast = false) const { auto boxTy = dest.getType(); auto fldTy = this->getBoxEleTy(boxTy, fldIndexes); if (bitcast) value = rewriter.create(loc, fldTy, value); else value = this->integerCast(loc, rewriter, fldTy, value); - SmallVector attrs; + llvm::SmallVector attrs; for (auto i : fldIndexes) attrs.push_back(rewriter.getI32IntegerAttr(i)); auto indexesAttr = mlir::ArrayAttr::get(rewriter.getContext(), attrs); @@ -1433,11 +1433,11 @@ struct EmboxOpConversion : public EmboxCommonConversion { if (isDerivedTypeWithLenParams(boxTy)) { TODO(embox.getLoc(), "fir.embox codegen of derived with length parameters"); - return failure(); + return mlir::failure(); } auto result = placeInMemoryIfNotGlobalInit(rewriter, embox.getLoc(), dest); rewriter.replaceOp(embox, result); - return success(); + return mlir::success(); } }; @@ -1619,7 +1619,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion { mlir::Value result = placeInMemoryIfNotGlobalInit(rewriter, loc, dest); rewriter.replaceOp(xbox, result); - return success(); + return mlir::success(); } /// Return true if `xbox` has a normalized lower bounds attribute. A box value @@ -1667,7 +1667,7 @@ struct XReboxOpConversion : public EmboxCommonConversion { const unsigned inputRank = rebox.getRank(); for (unsigned i = 0; i < inputRank; ++i) { mlir::Value dim = genConstantIndex(loc, idxTy, rewriter, i); - SmallVector dimInfo = + llvm::SmallVector dimInfo = getDimsFromBox(loc, {idxTy, idxTy, idxTy}, loweredBox, dim, rewriter); inputExtents.emplace_back(dimInfo[1]); inputStrides.emplace_back(dimInfo[2]); @@ -1714,7 +1714,7 @@ private: mlir::Value result = placeInMemoryIfNotGlobalInit(rewriter, rebox.getLoc(), dest); rewriter.replaceOp(rebox, result); - return success(); + return mlir::success(); } // Apply slice given the base address, extents and strides of the input box. @@ -1864,7 +1864,7 @@ struct EmboxProcOpConversion : public FIROpConversion { matchAndRewrite(fir::EmboxProcOp emboxproc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(emboxproc.getLoc(), "fir.emboxproc codegen"); - return failure(); + return mlir::failure(); } }; @@ -1872,7 +1872,7 @@ struct EmboxProcOpConversion : public FIROpConversion { struct ValueOpCommon { // Translate the arguments pertaining to any multidimensional array to // row-major order for LLVM-IR. - static void toRowMajor(SmallVectorImpl &attrs, + static void toRowMajor(llvm::SmallVectorImpl &attrs, mlir::Type ty) { assert(ty && "type is null"); const auto end = attrs.size(); @@ -1944,7 +1944,7 @@ struct ExtractValueOpConversion auto position = mlir::ArrayAttr::get(extractVal.getContext(), attrs); rewriter.replaceOpWithNewOp( extractVal, ty, adaptor.getOperands()[0], position); - return success(); + return mlir::success(); } }; @@ -1964,7 +1964,7 @@ struct InsertValueOpConversion rewriter.replaceOpWithNewOp( insertVal, ty, adaptor.getOperands()[0], adaptor.getOperands()[1], position); - return success(); + return mlir::success(); } }; @@ -1974,8 +1974,8 @@ struct InsertOnRangeOpConversion using FIROpAndTypeConversion::FIROpAndTypeConversion; // Increments an array of subscripts in a row major fasion. - void incrementSubscripts(const SmallVector &dims, - SmallVector &subscripts) const { + void incrementSubscripts(const llvm::SmallVector &dims, + llvm::SmallVector &subscripts) const { for (size_t i = dims.size(); i > 0; --i) { if (++subscripts[i - 1] < dims[i - 1]) { return; @@ -1997,8 +1997,8 @@ struct InsertOnRangeOpConversion type = t.getElementType(); } - SmallVector lBounds; - SmallVector uBounds; + llvm::SmallVector lBounds; + llvm::SmallVector uBounds; // Unzip the upper and lower bound and convert to a row major format. mlir::DenseIntElementsAttr coor = range.getCoor(); @@ -2016,28 +2016,28 @@ struct InsertOnRangeOpConversion auto i64Ty = rewriter.getI64Type(); while (subscripts != uBounds) { // Convert uint64_t's to Attribute's. - SmallVector subscriptAttrs; + llvm::SmallVector subscriptAttrs; for (const auto &subscript : subscripts) - subscriptAttrs.push_back(IntegerAttr::get(i64Ty, subscript)); + subscriptAttrs.push_back(mlir::IntegerAttr::get(i64Ty, subscript)); lastOp = rewriter.create( loc, ty, lastOp, insertVal, - ArrayAttr::get(range.getContext(), subscriptAttrs)); + mlir::ArrayAttr::get(range.getContext(), subscriptAttrs)); incrementSubscripts(dims, subscripts); } // Convert uint64_t's to Attribute's. - SmallVector subscriptAttrs; + llvm::SmallVector subscriptAttrs; for (const auto &subscript : subscripts) subscriptAttrs.push_back( - IntegerAttr::get(rewriter.getI64Type(), subscript)); + mlir::IntegerAttr::get(rewriter.getI64Type(), subscript)); mlir::ArrayRef arrayRef(subscriptAttrs); rewriter.replaceOpWithNewOp( range, ty, lastOp, insertVal, - ArrayAttr::get(range.getContext(), arrayRef)); + mlir::ArrayAttr::get(range.getContext(), arrayRef)); - return success(); + return mlir::success(); } }; } // namespace @@ -2137,7 +2137,7 @@ struct XArrayCoorOpConversion rewriter.create(loc, voidPtrTy, base, args); if (coor.subcomponent().empty()) { rewriter.replaceOpWithNewOp(coor, baseTy, addr); - return success(); + return mlir::success(); } auto casted = rewriter.create(loc, baseTy, addr); args.clear(); @@ -2153,7 +2153,7 @@ struct XArrayCoorOpConversion args.push_back(operands[i]); rewriter.replaceOpWithNewOp(coor, baseTy, casted, args); - return success(); + return mlir::success(); } // The array was not boxed, so it must be contiguous. offset is therefore an @@ -2198,11 +2198,11 @@ struct XArrayCoorOpConversion base = rewriter.create(loc, newTy, adaptor.getOperands()[0]); } - SmallVector args = {offset}; + llvm::SmallVector args = {offset}; for (auto i = coor.subcomponentOffset(); i != coor.indicesOffset(); ++i) args.push_back(operands[i]); rewriter.replaceOpWithNewOp(coor, ty, base, args); - return success(); + return mlir::success(); } }; } // namespace @@ -2234,7 +2234,7 @@ struct CoordinateOpConversion llvm::SmallVector offs = {c0, operands[1]}; mlir::Value gep = genGEP(loc, ty, rewriter, base, offs); rewriter.replaceOp(coor, gep); - return success(); + return mlir::success(); } // Boxed type - get the base pointer from the box @@ -2261,9 +2261,9 @@ struct CoordinateOpConversion assert(val && val.dyn_cast() && "must not be null value"); mlir::Operation *defop = val.getDefiningOp(); - if (auto constOp = dyn_cast(defop)) + if (auto constOp = mlir::dyn_cast(defop)) return constOp.value(); - if (auto llConstOp = dyn_cast(defop)) + if (auto llConstOp = mlir::dyn_cast(defop)) if (auto attr = llConstOp.getValue().dyn_cast()) return attr.getValue().getSExtValue(); fir::emitFatalError(val.getLoc(), "must be a constant"); @@ -2343,7 +2343,7 @@ private: if (coor.getNumOperands() == 2) { mlir::Operation *coordinateDef = (*coor.getCoor().begin()).getDefiningOp(); - if (isa_and_nonnull(coordinateDef)) + if (mlir::isa_and_nonnull(coordinateDef)) TODO(loc, "fir.coordinate_of - fir.len_param_index is not supported yet"); } @@ -2392,7 +2392,7 @@ private: } auto voidPtrBase = rewriter.create(loc, voidPtrTy, resultAddr); - SmallVector args{off}; + llvm::SmallVector args{off}; resultAddr = rewriter.create(loc, voidPtrTy, voidPtrBase, args); i += arrTy.getDimension() - 1; @@ -2417,7 +2417,7 @@ private: } rewriter.replaceOpWithNewOp(coor, ty, resultAddr); - return success(); + return mlir::success(); } mlir::LogicalResult @@ -2463,14 +2463,14 @@ private: loc, "fir.coordinate_of with a dynamic element size is unsupported"); if (hasKnownShape || columnIsDeferred) { - SmallVector offs; + llvm::SmallVector offs; if (hasKnownShape && hasSubdimension) { mlir::LLVM::ConstantOp c0 = genConstantIndex(loc, lowerTy().indexType(), rewriter, 0); offs.push_back(c0); } - Optional dims; - SmallVector arrIdx; + llvm::Optional dims; + llvm::SmallVector arrIdx; for (std::size_t i = 1, sz = operands.size(); i < sz; ++i) { mlir::Value nxtOpnd = operands[i]; @@ -2519,7 +2519,7 @@ private: mlir::Value base = operands[0]; mlir::Value retval = genGEP(loc, ty, rewriter, base, offs); rewriter.replaceOp(coor, retval); - return success(); + return mlir::success(); } return mlir::emitError( @@ -2544,21 +2544,21 @@ struct FieldIndexOpConversion : public FIROpConversion { // component type in the parent type (to be used in GEP). rewriter.replaceOp(field, mlir::ValueRange{genConstantOffset( field.getLoc(), rewriter, index)}); - return success(); + return mlir::success(); } // Derived type has compile-time constant layout. Call the compiler // generated function to determine the byte offset of the field at runtime. // This returns a non-constant. - FlatSymbolRefAttr symAttr = mlir::SymbolRefAttr::get( + mlir::FlatSymbolRefAttr symAttr = mlir::SymbolRefAttr::get( field.getContext(), getOffsetMethodName(recTy, field.getFieldId())); - NamedAttribute callAttr = rewriter.getNamedAttr("callee", symAttr); - NamedAttribute fieldAttr = rewriter.getNamedAttr( + mlir::NamedAttribute callAttr = rewriter.getNamedAttr("callee", symAttr); + mlir::NamedAttribute fieldAttr = rewriter.getNamedAttr( "field", mlir::IntegerAttr::get(lowerTy().indexType(), index)); rewriter.replaceOpWithNewOp( field, lowerTy().offsetType(), adaptor.getOperands(), llvm::ArrayRef{callAttr, fieldAttr}); - return success(); + return mlir::success(); } // Re-Construct the name of the compiler generated method that calculates the @@ -2577,7 +2577,7 @@ struct FirEndOpConversion : public FIROpConversion { matchAndRewrite(fir::FirEndOp firEnd, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(firEnd.getLoc(), "fir.end codegen"); - return failure(); + return mlir::failure(); } }; @@ -2589,7 +2589,7 @@ struct GenTypeDescOpConversion : public FIROpConversion { matchAndRewrite(fir::GenTypeDescOp gentypedesc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(gentypedesc.getLoc(), "fir.gentypedesc codegen"); - return failure(); + return mlir::failure(); } }; @@ -2600,8 +2600,9 @@ struct HasValueOpConversion : public FIROpConversion { mlir::LogicalResult matchAndRewrite(fir::HasValueOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOpWithNewOp(op, adaptor.getOperands()); - return success(); + rewriter.replaceOpWithNewOp(op, + adaptor.getOperands()); + return mlir::success(); } }; @@ -2640,13 +2641,13 @@ struct GlobalOpConversion : public FIROpConversion { auto convertOp = mlir::dyn_cast(op); if (!convertOp) continue; - constant = cast( + constant = mlir::cast( convertOp.getValue().getDefiningOp()); } mlir::Type vecType = mlir::VectorType::get( insertOp.getType().getShape(), constant.getType()); auto denseAttr = mlir::DenseElementsAttr::get( - vecType.cast(), constant.getValue()); + vecType.cast(), constant.getValue()); rewriter.setInsertionPointAfter(insertOp); rewriter.replaceOpWithNewOp( insertOp, seqTyAttr, denseAttr); @@ -2654,7 +2655,7 @@ struct GlobalOpConversion : public FIROpConversion { } } rewriter.eraseOp(global); - return success(); + return mlir::success(); } bool isFullRange(mlir::DenseIntElementsAttr indexes, @@ -2674,7 +2675,8 @@ struct GlobalOpConversion : public FIROpConversion { // TODO: String comparaison should be avoided. Replace linkName with an // enumeration. - mlir::LLVM::Linkage convertLinkage(Optional optLinkage) const { + mlir::LLVM::Linkage + convertLinkage(llvm::Optional optLinkage) const { if (optLinkage.hasValue()) { auto name = optLinkage.getValue(); if (name == "internal") @@ -2706,12 +2708,11 @@ struct LoadOpConversion : public FIROpConversion { if (load.getType().isa()) { rewriter.replaceOp(load, adaptor.getOperands()[0]); } else { - mlir::Type ty = convertType(load.getType()); - ArrayRef at = load->getAttrs(); rewriter.replaceOpWithNewOp( - load, ty, adaptor.getOperands(), at); + load, convertType(load.getType()), adaptor.getOperands(), + load->getAttrs()); } - return success(); + return mlir::success(); } }; @@ -2725,12 +2726,12 @@ struct NoReassocOpConversion : public FIROpConversion { matchAndRewrite(fir::NoReassocOp noreassoc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOp(noreassoc, adaptor.getOperands()[0]); - return success(); + return mlir::success(); } }; static void genCondBrOp(mlir::Location loc, mlir::Value cmp, mlir::Block *dest, - Optional destOps, + llvm::Optional destOps, mlir::ConversionPatternRewriter &rewriter, mlir::Block *newBlock) { if (destOps.hasValue()) @@ -2741,7 +2742,7 @@ static void genCondBrOp(mlir::Location loc, mlir::Value cmp, mlir::Block *dest, } template -static void genBrOp(A caseOp, mlir::Block *dest, Optional destOps, +static void genBrOp(A caseOp, mlir::Block *dest, llvm::Optional destOps, mlir::ConversionPatternRewriter &rewriter) { if (destOps.hasValue()) rewriter.replaceOpWithNewOp(caseOp, destOps.getValue(), @@ -2752,7 +2753,7 @@ static void genBrOp(A caseOp, mlir::Block *dest, Optional destOps, static void genCaseLadderStep(mlir::Location loc, mlir::Value cmp, mlir::Block *dest, - Optional destOps, + llvm::Optional destOps, mlir::ConversionPatternRewriter &rewriter) { auto *thisBlock = rewriter.getInsertionBlock(); auto *newBlock = createBlock(rewriter, dest); @@ -2792,7 +2793,7 @@ struct SelectCaseOpConversion : public FIROpConversion { auto ty = caseOp.getSelector().getType(); if (ty.isa()) { TODO(caseOp.getLoc(), "fir.select_case codegen with character type"); - return failure(); + return mlir::failure(); } mlir::Value selector = caseOp.getSelector(adaptor.getOperands()); auto loc = caseOp.getLoc(); @@ -2842,7 +2843,7 @@ struct SelectCaseOpConversion : public FIROpConversion { assert((t + 1 == conds) && "unit must be last"); genBrOp(caseOp, dest, destOps, rewriter); } - return success(); + return mlir::success(); } }; @@ -2869,20 +2870,20 @@ static void selectMatchAndRewrite(fir::LLVMTypeConverter &lowering, OP select, if (auto intAttr = attr.template dyn_cast()) { destinations.push_back(dest); destinationsOperands.push_back(destOps.hasValue() ? *destOps - : ValueRange()); + : mlir::ValueRange{}); caseValues.push_back(intAttr.getInt()); continue; } assert(attr.template dyn_cast_or_null()); assert((t + 1 == conds) && "unit must be last"); defaultDestination = dest; - defaultOperands = destOps.hasValue() ? *destOps : ValueRange(); + defaultOperands = destOps.hasValue() ? *destOps : mlir::ValueRange{}; } // LLVM::SwitchOp takes a i32 type for the selector. if (select.getSelector().getType() != rewriter.getI32Type()) - selector = - rewriter.create(loc, rewriter.getI32Type(), selector); + selector = rewriter.create(loc, rewriter.getI32Type(), + selector); rewriter.replaceOpWithNewOp( select, selector, @@ -2891,7 +2892,7 @@ static void selectMatchAndRewrite(fir::LLVMTypeConverter &lowering, OP select, /*caseValues=*/caseValues, /*caseDestinations=*/destinations, /*caseOperands=*/destinationsOperands, - /*branchWeights=*/ArrayRef()); + /*branchWeights=*/llvm::ArrayRef()); } /// conversion of fir::SelectOp to an if-then-else ladder @@ -2902,7 +2903,7 @@ struct SelectOpConversion : public FIROpConversion { matchAndRewrite(fir::SelectOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { selectMatchAndRewrite(lowerTy(), op, adaptor, rewriter); - return success(); + return mlir::success(); } }; @@ -2914,7 +2915,7 @@ struct SelectRankOpConversion : public FIROpConversion { matchAndRewrite(fir::SelectRankOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { selectMatchAndRewrite(lowerTy(), op, adaptor, rewriter); - return success(); + return mlir::success(); } }; @@ -2927,7 +2928,7 @@ struct SelectTypeOpConversion : public FIROpConversion { mlir::ConversionPatternRewriter &rewriter) const override { mlir::emitError(select.getLoc(), "fir.select_type should have already been converted"); - return failure(); + return mlir::failure(); } }; @@ -2951,7 +2952,7 @@ struct StoreOpConversion : public FIROpConversion { rewriter.replaceOpWithNewOp( store, adaptor.getOperands()[0], adaptor.getOperands()[1]); } - return success(); + return mlir::success(); } }; @@ -2965,7 +2966,7 @@ struct UnboxCharOpConversion : public FIROpConversion { mlir::LogicalResult matchAndRewrite(fir::UnboxCharOp unboxchar, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { - MLIRContext *ctx = unboxchar.getContext(); + auto *ctx = unboxchar.getContext(); mlir::Type lenTy = convertType(unboxchar.getType(1)); mlir::Value tuple = adaptor.getOperands()[0]; @@ -2980,8 +2981,8 @@ struct UnboxCharOpConversion : public FIROpConversion { mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, len); rewriter.replaceOp(unboxchar, - ArrayRef{ptrToBuffer, lenAfterCast}); - return success(); + llvm::ArrayRef{ptrToBuffer, lenAfterCast}); + return mlir::success(); } }; @@ -2995,7 +2996,7 @@ struct UnboxProcOpConversion : public FIROpConversion { matchAndRewrite(fir::UnboxProcOp unboxproc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(unboxproc.getLoc(), "fir.unboxproc codegen"); - return failure(); + return mlir::failure(); } }; @@ -3008,7 +3009,7 @@ struct UndefOpConversion : public FIROpConversion { mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp( undef, convertType(undef.getType())); - return success(); + return mlir::success(); } }; @@ -3033,7 +3034,7 @@ struct ZeroOpConversion : public FIROpConversion { zero, "conversion of fir.zero with aggregate type not implemented yet"); } - return success(); + return mlir::success(); } }; @@ -3045,7 +3046,7 @@ struct UnreachableOpConversion : public FIROpConversion { matchAndRewrite(fir::UnreachableOp unreach, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(unreach); - return success(); + return mlir::success(); } }; @@ -3080,7 +3081,7 @@ struct IsPresentOpConversion : public FIROpConversion { rewriter.replaceOpWithNewOp( isPresent, mlir::LLVM::ICmpPredicate::ne, addr, c0); - return success(); + return mlir::success(); } }; @@ -3108,7 +3109,7 @@ struct AbsentOpConversion : public FIROpConversion { } else { rewriter.replaceOpWithNewOp(absent, ty); } - return success(); + return mlir::success(); } }; @@ -3154,7 +3155,7 @@ struct AddcOpConversion : public FIROpConversion { auto r = complexSum(addc, adaptor.getOperands(), rewriter, lowerTy()); rewriter.replaceOp(addc, r.getResult()); - return success(); + return mlir::success(); } }; @@ -3169,7 +3170,7 @@ struct SubcOpConversion : public FIROpConversion { auto r = complexSum(subc, adaptor.getOperands(), rewriter, lowerTy()); rewriter.replaceOp(subc, r.getResult()); - return success(); + return mlir::success(); } }; @@ -3205,7 +3206,7 @@ struct MulcOpConversion : public FIROpConversion { auto r1 = rewriter.create(loc, ty, ra, rr, c0); auto r0 = rewriter.create(loc, ty, r1, ri, c1); rewriter.replaceOp(mulc, r0.getResult()); - return success(); + return mlir::success(); } }; @@ -3247,7 +3248,7 @@ struct DivcOpConversion : public FIROpConversion { auto r1 = rewriter.create(loc, ty, ra, rr, c0); auto r0 = rewriter.create(loc, ty, r1, ri, c1); rewriter.replaceOp(divc, r0.getResult()); - return success(); + return mlir::success(); } }; @@ -3273,7 +3274,7 @@ struct NegcOpConversion : public FIROpConversion { auto nip = rewriter.create(loc, eleTy, ip); auto r = rewriter.create(loc, ty, o0, nrp, c0); rewriter.replaceOpWithNewOp(neg, ty, r, nip, c1); - return success(); + return mlir::success(); } }; @@ -3294,7 +3295,7 @@ struct MustBeDeadConversion : public FIROpConversion { if (!op->getUses().empty()) return rewriter.notifyMatchFailure(op, "op must be dead"); rewriter.eraseOp(op); - return success(); + return mlir::success(); } }; @@ -3331,9 +3332,8 @@ public: void runOnOperation() override final { auto mod = getModule(); - if (!forcedTargetTriple.empty()) { + if (!forcedTargetTriple.empty()) fir::setTargetTriple(mod, forcedTargetTriple); - } auto *context = getModule().getContext(); fir::LLVMTypeConverter typeConverter{getModule()}; @@ -3396,8 +3396,7 @@ struct LLVMIRLoweringPass mlir::OperationPass> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(LLVMIRLoweringPass) - using Printer = fir::LLVMIRLoweringPrinter; - LLVMIRLoweringPass(raw_ostream &output, Printer p) + LLVMIRLoweringPass(llvm::raw_ostream &output, fir::LLVMIRLoweringPrinter p) : output{output}, printer{p} {} mlir::ModuleOp getModule() { return getOperation(); } @@ -3417,8 +3416,8 @@ struct LLVMIRLoweringPass } private: - raw_ostream &output; - Printer printer; + llvm::raw_ostream &output; + fir::LLVMIRLoweringPrinter printer; }; } // namespace @@ -3428,12 +3427,12 @@ std::unique_ptr fir::createFIRToLLVMPass() { } std::unique_ptr -fir::createFIRToLLVMPass(FIRToLLVMPassOptions options) { +fir::createFIRToLLVMPass(fir::FIRToLLVMPassOptions options) { return std::make_unique(options); } std::unique_ptr -fir::createLLVMDialectToLLVMPass(raw_ostream &output, +fir::createLLVMDialectToLLVMPass(llvm::raw_ostream &output, fir::LLVMIRLoweringPrinter printer) { return std::make_unique(output, printer); } diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index ba12e2751952..65932b8d3ab4 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -30,9 +30,6 @@ #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/Debug.h" -using namespace fir; -using namespace mlir; - #define DEBUG_TYPE "flang-target-rewrite" namespace { @@ -69,9 +66,9 @@ struct FixupTy { /// generation that traverses the FIR and modifies types and operations to a /// form that is appropriate for the specific target. LLVM IR has specific /// idioms that are used for distinct target processor and ABI combinations. -class TargetRewrite : public TargetRewriteBase { +class TargetRewrite : public fir::TargetRewriteBase { public: - TargetRewrite(const TargetRewriteOptions &options) { + TargetRewrite(const fir::TargetRewriteOptions &options) { noCharacterConversion = options.noCharacterConversion; noComplexConversion = options.noComplexConversion; } @@ -82,10 +79,10 @@ public: auto mod = getModule(); if (!forcedTargetTriple.empty()) - setTargetTriple(mod, forcedTargetTriple); + fir::setTargetTriple(mod, forcedTargetTriple); - auto specifics = CodeGenSpecifics::get( - mod.getContext(), getTargetTriple(mod), getKindMapping(mod)); + auto specifics = fir::CodeGenSpecifics::get( + mod.getContext(), fir::getTargetTriple(mod), fir::getKindMapping(mod)); setMembers(specifics.get(), &rewriter); // Perform type conversion on signatures and call sites. @@ -97,13 +94,13 @@ public: // Convert ops in target-specific patterns. mod.walk([&](mlir::Operation *op) { - if (auto call = dyn_cast(op)) { + if (auto call = mlir::dyn_cast(op)) { if (!hasPortableSignature(call.getFunctionType())) convertCallOp(call); - } else if (auto dispatch = dyn_cast(op)) { + } else if (auto dispatch = mlir::dyn_cast(op)) { if (!hasPortableSignature(dispatch.getFunctionType())) convertCallOp(dispatch); - } else if (auto addr = dyn_cast(op)) { + } else if (auto addr = mlir::dyn_cast(op)) { if (addr.getType().isa() && !hasPortableSignature(addr.getType())) convertAddrOp(addr); @@ -123,17 +120,17 @@ public: // scalar, including the sret case. assert(m.size() == 1 && "target lowering of complex return not supported"); auto resTy = std::get(m[0]); - auto attr = std::get(m[0]); + auto attr = std::get(m[0]); auto loc = mlir::UnknownLoc::get(resTy.getContext()); if (attr.isSRet()) { - assert(isa_ref_type(resTy)); + assert(fir::isa_ref_type(resTy) && "must be a memory reference type"); mlir::Value stack = - rewriter->create(loc, dyn_cast_ptrEleTy(resTy)); + rewriter->create(loc, fir::dyn_cast_ptrEleTy(resTy)); newInTys.push_back(resTy); newOpers.push_back(stack); return [=](mlir::Operation *) -> mlir::Value { - auto memTy = ReferenceType::get(ty); - auto cast = rewriter->create(loc, memTy, stack); + auto memTy = fir::ReferenceType::get(ty); + auto cast = rewriter->create(loc, memTy, stack); return rewriter->create(loc, cast); }; } @@ -141,8 +138,8 @@ public: return [=](mlir::Operation *call) -> mlir::Value { auto mem = rewriter->create(loc, resTy); rewriter->create(loc, call->getResult(0), mem); - auto memTy = ReferenceType::get(ty); - auto cast = rewriter->create(loc, memTy, mem); + auto memTy = fir::ReferenceType::get(ty); + auto cast = rewriter->create(loc, memTy, mem); return rewriter->create(loc, cast); }; } @@ -156,15 +153,15 @@ public: if (m.size() == 1) { // COMPLEX is a single aggregate auto resTy = std::get(m[0]); - auto attr = std::get(m[0]); - auto oldRefTy = ReferenceType::get(ty); + auto attr = std::get(m[0]); + auto oldRefTy = fir::ReferenceType::get(ty); if (attr.isByVal()) { auto mem = rewriter->create(loc, ty); rewriter->create(loc, oper, mem); - newOpers.push_back(rewriter->create(loc, resTy, mem)); + newOpers.push_back(rewriter->create(loc, resTy, mem)); } else { auto mem = rewriter->create(loc, resTy); - auto cast = rewriter->create(loc, oldRefTy, mem); + auto cast = rewriter->create(loc, oldRefTy, mem); rewriter->create(loc, oper, cast); newOpers.push_back(rewriter->create(loc, mem)); } @@ -178,7 +175,7 @@ public: auto ty = std::get(tup); auto index = e.index(); auto idx = rewriter->getIntegerAttr(iTy, index); - auto val = rewriter->create( + auto val = rewriter->create( loc, ty, oper, rewriter->getArrayAttr(idx)); newInTys.push_back(ty); newOpers.push_back(val); @@ -234,7 +231,7 @@ public: mlir::Value oper = std::get<1>(e.value()); unsigned index = e.index(); llvm::TypeSwitch(ty) - .template Case([&](BoxCharType boxTy) { + .template Case([&](fir::BoxCharType boxTy) { bool sret; if constexpr (std::is_same_v, fir::CallOp>) { sret = callOp.getCallee() && @@ -248,13 +245,14 @@ public: TODO(loc, "dispatch + sret not supported yet"); } auto m = specifics->boxcharArgumentType(boxTy.getEleTy(), sret); - auto unbox = - rewriter->create(loc, std::get(m[0]), - std::get(m[1]), oper); + auto unbox = rewriter->create( + loc, std::get(m[0]), std::get(m[1]), + oper); // unboxed CHARACTER arguments for (auto e : llvm::enumerate(m)) { unsigned idx = e.index(); - auto attr = std::get(e.value()); + auto attr = + std::get(e.value()); auto argTy = std::get(e.value()); if (attr.isAppend()) { trailingInTys.push_back(argTy); @@ -272,12 +270,12 @@ public: rewriteCallComplexInputType(cmplx, oper, newInTys, newOpers); }) .template Case([&](mlir::TupleType tuple) { - if (isCharacterProcedureTuple(tuple)) { + if (fir::isCharacterProcedureTuple(tuple)) { mlir::ModuleOp module = getModule(); if constexpr (std::is_same_v, fir::CallOp>) { if (callOp.getCallee()) { llvm::StringRef charProcAttr = - getCharacterProcedureDummyAttrName(); + fir::getCharacterProcedureDummyAttrName(); // The charProcAttr attribute is only used as a safety to // confirm that this is a dummy procedure and should be split. // It cannot be used to match because attributes are not @@ -294,9 +292,10 @@ public: } mlir::Type funcPointerType = tuple.getType(0); mlir::Type lenType = tuple.getType(1); - FirOpBuilder builder(*rewriter, getKindMapping(module)); + fir::FirOpBuilder builder(*rewriter, fir::getKindMapping(module)); auto [funcPointer, len] = - factory::extractCharacterProcedureTuple(builder, loc, oper); + fir::factory::extractCharacterProcedureTuple(builder, loc, + oper); newInTys.push_back(funcPointerType); newOpers.push_back(funcPointer); trailingInTys.push_back(lenType); @@ -344,7 +343,7 @@ public: } else { for (auto &tup : specifics->complexReturnType(cmplx.getElementType())) { auto argTy = std::get(tup); - if (std::get(tup).isSRet()) + if (std::get(tup).isSRet()) newInTys.push_back(argTy); else newResTys.push_back(argTy); @@ -363,7 +362,7 @@ public: } /// Taking the address of a function. Modify the signature as needed. - void convertAddrOp(AddrOfOp addrOp) { + void convertAddrOp(fir::AddrOfOp addrOp) { rewriter->setInsertionPoint(addrOp); auto addrTy = addrOp.getType().cast(); llvm::SmallVector newResTys; @@ -381,12 +380,12 @@ public: llvm::SmallVector trailingInTys; for (mlir::Type ty : addrTy.getInputs()) { llvm::TypeSwitch(ty) - .Case([&](BoxCharType box) { + .Case([&](auto box) { if (noCharacterConversion) { newInTys.push_back(box); } else { for (auto &tup : specifics->boxcharArgumentType(box.getEleTy())) { - auto attr = std::get(tup); + auto attr = std::get(tup); auto argTy = std::get(tup); llvm::SmallVector &vec = attr.isAppend() ? trailingInTys : newInTys; @@ -401,7 +400,7 @@ public: lowerComplexSignatureArg(ty, newInTys); }) .Case([&](mlir::TupleType tuple) { - if (isCharacterProcedureTuple(tuple)) { + if (fir::isCharacterProcedureTuple(tuple)) { newInTys.push_back(tuple.getType(0)); trailingInTys.push_back(tuple.getType(1)); } else { @@ -414,8 +413,8 @@ public: newInTys.insert(newInTys.end(), trailingInTys.begin(), trailingInTys.end()); // 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.getSymbol()); + auto newOp = rewriter->create(addrOp.getLoc(), newTy, + addrOp.getSymbol()); replaceOp(addrOp, newOp.getResult()); } @@ -436,15 +435,15 @@ public: assert(signature.isa()); auto func = signature.dyn_cast(); for (auto ty : func.getResults()) - if ((ty.isa() && !noCharacterConversion) || - (isa_complex(ty) && !noComplexConversion)) { + if ((ty.isa() && !noCharacterConversion) || + (fir::isa_complex(ty) && !noComplexConversion)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } for (auto ty : func.getInputs()) - if (((ty.isa() || isCharacterProcedureTuple(ty)) && + if (((ty.isa() || fir::isCharacterProcedureTuple(ty)) && !noCharacterConversion) || - (isa_complex(ty) && !noComplexConversion)) { + (fir::isa_complex(ty) && !noComplexConversion)) { LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n"); return false; } @@ -456,7 +455,7 @@ public: static bool hasHostAssociations(mlir::func::FuncOp func) { std::size_t end = func.getFunctionType().getInputs().size(); for (std::size_t i = 0; i < end; ++i) - if (func.getArgAttrOfType(i, getHostAssocAttrName())) + if (func.getArgAttrOfType(i, fir::getHostAssocAttrName())) return true; return false; } @@ -494,7 +493,7 @@ public: auto ty = e.value(); unsigned index = e.index(); llvm::TypeSwitch(ty) - .Case([&](BoxCharType boxTy) { + .Case([&](fir::BoxCharType boxTy) { if (noCharacterConversion) { newInTys.push_back(boxTy); } else { @@ -506,7 +505,7 @@ public: boxTy.getEleTy(), sret))) { auto &tup = e.value(); auto index = e.index(); - auto attr = std::get(tup); + auto attr = std::get(tup); auto argTy = std::get(tup); if (attr.isAppend()) { trailingTys.push_back(argTy); @@ -536,7 +535,7 @@ public: doComplexArg(func, cmplx, newInTys, fixups); }) .Case([&](mlir::TupleType tuple) { - if (isCharacterProcedureTuple(tuple)) { + if (fir::isCharacterProcedureTuple(tuple)) { fixups.emplace_back(FixupTy::Codes::TrailingCharProc, newInTys.size(), trailingTys.size()); newInTys.push_back(tuple.getType(0)); @@ -547,7 +546,7 @@ public: }) .Default([&](mlir::Type ty) { newInTys.push_back(ty); }); if (func.getArgAttrOfType(index, - getHostAssocAttrName())) { + fir::getHostAssocAttrName())) { func.setArgAttr(index, "llvm.nest", rewriter->getUnitAttr()); } } @@ -568,8 +567,9 @@ public: auto newArg = func.front().insertArgument(fixup.index, newInTys[fixup.index], loc); rewriter->setInsertionPointToStart(&func.front()); - auto oldArgTy = ReferenceType::get(oldArgTys[fixup.index - offset]); - auto cast = rewriter->create(loc, oldArgTy, newArg); + auto oldArgTy = + fir::ReferenceType::get(oldArgTys[fixup.index - offset]); + auto cast = rewriter->create(loc, oldArgTy, newArg); auto load = rewriter->create(loc, cast); func.getArgument(fixup.index + 1).replaceAllUsesWith(load); func.front().eraseArgument(fixup.index + 1); @@ -583,8 +583,9 @@ public: auto mem = rewriter->create(loc, newInTys[fixup.index]); rewriter->create(loc, newArg, mem); - auto oldArgTy = ReferenceType::get(oldArgTys[fixup.index - offset]); - auto cast = rewriter->create(loc, oldArgTy, mem); + auto oldArgTy = + fir::ReferenceType::get(oldArgTys[fixup.index - offset]); + auto cast = rewriter->create(loc, oldArgTy, mem); mlir::Value load = rewriter->create(loc, cast); func.getArgument(fixup.index + 1).replaceAllUsesWith(load); func.front().eraseArgument(fixup.index + 1); @@ -601,7 +602,7 @@ public: if (fixup.second == 1) { rewriter->setInsertionPointToStart(&func.front()); auto boxTy = oldArgTys[fixup.index - offset - fixup.second]; - auto box = rewriter->create( + auto box = rewriter->create( loc, boxTy, func.front().getArgument(fixup.index - 1), newArg); func.getArgument(fixup.index + 1).replaceAllUsesWith(box); func.front().eraseArgument(fixup.index + 1); @@ -617,8 +618,9 @@ public: func.walk([&](mlir::func::ReturnOp ret) { rewriter->setInsertionPoint(ret); auto oldOper = ret.getOperand(0); - auto oldOperTy = ReferenceType::get(oldOper.getType()); - auto cast = rewriter->create(loc, oldOperTy, newArg); + auto oldOperTy = fir::ReferenceType::get(oldOper.getType()); + auto cast = + rewriter->create(loc, oldOperTy, newArg); rewriter->create(loc, oldOper, cast); rewriter->create(loc); ret.erase(); @@ -630,10 +632,10 @@ public: func.walk([&](mlir::func::ReturnOp ret) { rewriter->setInsertionPoint(ret); auto oldOper = ret.getOperand(0); - auto oldOperTy = ReferenceType::get(oldOper.getType()); + auto oldOperTy = fir::ReferenceType::get(oldOper.getType()); auto mem = rewriter->create(loc, newResTys[fixup.index]); - auto cast = rewriter->create(loc, oldOperTy, mem); + auto cast = rewriter->create(loc, oldOperTy, mem); rewriter->create(loc, oldOper, cast); mlir::Value load = rewriter->create(loc, mem); rewriter->create(loc, load); @@ -648,14 +650,14 @@ public: if (fixup.second == 1) { rewriter->setInsertionPointToStart(&func.front()); auto cplxTy = oldArgTys[fixup.index - offset - fixup.second]; - auto undef = rewriter->create(loc, cplxTy); + auto undef = rewriter->create(loc, cplxTy); auto iTy = rewriter->getIntegerType(32); auto zero = rewriter->getIntegerAttr(iTy, 0); auto one = rewriter->getIntegerAttr(iTy, 1); - auto cplx1 = rewriter->create( + auto cplx1 = rewriter->create( loc, cplxTy, undef, func.front().getArgument(fixup.index - 1), rewriter->getArrayAttr(zero)); - auto cplx = rewriter->create( + auto cplx = rewriter->create( loc, cplxTy, cplx1, newArg, rewriter->getArrayAttr(one)); func.getArgument(fixup.index + 1).replaceAllUsesWith(cplx); func.front().eraseArgument(fixup.index + 1); @@ -673,8 +675,8 @@ public: func.front().addArgument(trailingTys[fixup.second], loc); auto boxTy = oldArgTys[fixup.index - offset]; rewriter->setInsertionPointToStart(&func.front()); - auto box = - rewriter->create(loc, boxTy, newBufArg, newLenArg); + auto box = rewriter->create(loc, boxTy, newBufArg, + newLenArg); func.getArgument(fixup.index + 1).replaceAllUsesWith(box); func.front().eraseArgument(fixup.index + 1); } break; @@ -689,8 +691,9 @@ public: func.front().addArgument(trailingTys[fixup.second], loc); auto tupleType = oldArgTys[fixup.index - offset]; rewriter->setInsertionPointToStart(&func.front()); - FirOpBuilder builder(*rewriter, getKindMapping(getModule())); - auto tuple = factory::createCharacterProcedureTuple( + fir::FirOpBuilder builder(*rewriter, + fir::getKindMapping(getModule())); + auto tuple = fir::factory::createCharacterProcedureTuple( builder, loc, tupleType, newProcPointerArg, newLenArg); func.getArgument(fixup.index + 1).replaceAllUsesWith(tuple); func.front().eraseArgument(fixup.index + 1); @@ -730,7 +733,7 @@ public: auto m = specifics->complexReturnType(cmplx.getElementType()); assert(m.size() == 1); auto &tup = m[0]; - auto attr = std::get(tup); + auto attr = std::get(tup); auto argTy = std::get(tup); if (attr.isSRet()) { unsigned argNo = newInTys.size(); @@ -760,7 +763,7 @@ public: for (auto e : llvm::enumerate(m)) { auto &tup = e.value(); auto index = e.index(); - auto attr = std::get(tup); + auto attr = std::get(tup); auto argTy = std::get(tup); auto argNo = newInTys.size(); if (attr.isByVal()) { @@ -802,19 +805,19 @@ private: op->erase(); } - inline void setMembers(CodeGenSpecifics *s, mlir::OpBuilder *r) { + inline void setMembers(fir::CodeGenSpecifics *s, mlir::OpBuilder *r) { specifics = s; rewriter = r; } inline void clearMembers() { setMembers(nullptr, nullptr); } - CodeGenSpecifics *specifics{}; - mlir::OpBuilder *rewriter; + fir::CodeGenSpecifics *specifics = nullptr; + mlir::OpBuilder *rewriter = nullptr; }; // namespace } // namespace std::unique_ptr> -fir::createFirTargetRewritePass(const TargetRewriteOptions &options) { +fir::createFirTargetRewritePass(const fir::TargetRewriteOptions &options) { return std::make_unique(options); } diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h index 5d15dade2dd7..aefe5923c139 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -92,8 +92,8 @@ public: addConversion( [&](fir::PointerType pointer) { return convertPointerLike(pointer); }); addConversion([&](fir::RecordType derived, - SmallVectorImpl &results, - ArrayRef callStack) { + llvm::SmallVectorImpl &results, + llvm::ArrayRef callStack) { return convertRecordType(derived, results, callStack); }); addConversion( @@ -138,15 +138,15 @@ public: mlir::Type indexType() { return mlir::IntegerType::get(&getContext(), 64); } // fir.type --> llvm<"%name = { ty... }"> - llvm::Optional + llvm::Optional convertRecordType(fir::RecordType derived, - SmallVectorImpl &results, - ArrayRef callStack) { + llvm::SmallVectorImpl &results, + llvm::ArrayRef callStack) { auto name = derived.getName(); auto st = mlir::LLVM::LLVMStructType::getIdentified(&getContext(), name); if (llvm::count(callStack, derived) > 1) { results.push_back(st); - return success(); + return mlir::success(); } llvm::SmallVector members; for (auto mem : derived.getTypeList()) { @@ -158,9 +158,9 @@ public: members.push_back(convertType(mem.second).cast()); } if (mlir::failed(st.setBody(members, /*isPacked=*/false))) - return failure(); + return mlir::failure(); results.push_back(st); - return success(); + return mlir::success(); } // Is an extended descriptor needed given the element type of a fir.box type ? diff --git a/flang/test/Fir/addrof.fir b/flang/test/Fir/addrof.fir index 6a89c6fa5818..0147f55739c8 100644 --- a/flang/test/Fir/addrof.fir +++ b/flang/test/Fir/addrof.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt %s | tco | FileCheck %s +// RUN: tco %s | FileCheck %s // CHECK: @var_x = external global i32 fir.global @var_x : !fir.int<4> {} diff --git a/flang/test/Fir/embox.fir b/flang/test/Fir/embox.fir index 64eec479a86e..27211550bb3d 100644 --- a/flang/test/Fir/embox.fir +++ b/flang/test/Fir/embox.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt %s | tco | FileCheck %s +// RUN: tco %s | FileCheck %s // CHECK-LABEL: define void @_QPtest_callee({ i32*, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }* %0) diff --git a/flang/test/Fir/rebox.fir b/flang/test/Fir/rebox.fir index c60eace3e604..e26113f52ade 100644 --- a/flang/test/Fir/rebox.fir +++ b/flang/test/Fir/rebox.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt %s | tco | FileCheck %s +// RUN: tco %s | FileCheck %s // Test applying slice on fir.box // subroutine foo(x)