diff options
Diffstat (limited to 'flang/lib/Optimizer/Builder/FIRBuilder.cpp')
-rw-r--r-- | flang/lib/Optimizer/Builder/FIRBuilder.cpp | 145 |
1 files changed, 74 insertions, 71 deletions
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index 5b1dbc44..eaad54e 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -406,10 +406,10 @@ mlir::Value fir::FirOpBuilder::genTempDeclareOp( llvm::ArrayRef<mlir::Value> typeParams, fir::FortranVariableFlagsAttr fortranAttrs) { auto nameAttr = mlir::StringAttr::get(builder.getContext(), name); - return builder.create<fir::DeclareOp>(loc, memref.getType(), memref, shape, - typeParams, - /*dummy_scope=*/nullptr, nameAttr, - fortranAttrs, cuf::DataAttributeAttr{}); + return fir::DeclareOp::create(builder, loc, memref.getType(), memref, shape, + typeParams, + /*dummy_scope=*/nullptr, nameAttr, fortranAttrs, + cuf::DataAttributeAttr{}); } mlir::Value fir::FirOpBuilder::genStackSave(mlir::Location loc) { @@ -585,7 +585,7 @@ mlir::Value fir::factory::createConvert(mlir::OpBuilder &builder, mlir::cast<fir::RecordType>(val.getType()).getTypeList() == mlir::cast<fir::RecordType>(toTy).getTypeList()) && "incompatible record types"); - return builder.create<fir::ConvertOp>(loc, toTy, val); + return fir::ConvertOp::create(builder, loc, toTy, val); } return val; } @@ -824,7 +824,7 @@ genNullPointerComparison(fir::FirOpBuilder &builder, mlir::Location loc, auto intPtrTy = builder.getIntPtrType(); auto ptrToInt = builder.createConvert(loc, intPtrTy, addr); auto c0 = builder.createIntegerConstant(loc, intPtrTy, 0); - return builder.create<mlir::arith::CmpIOp>(loc, condition, ptrToInt, c0); + return mlir::arith::CmpIOp::create(builder, loc, condition, ptrToInt, c0); } mlir::Value fir::FirOpBuilder::genIsNotNullAddr(mlir::Location loc, @@ -1028,8 +1028,8 @@ fir::factory::readExtents(fir::FirOpBuilder &builder, mlir::Location loc, auto idxTy = builder.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { auto dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - box.getAddr(), dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + box.getAddr(), dimVal); result.emplace_back(dimInfo.getResult(1)); } return result; @@ -1061,7 +1061,7 @@ fir::ExtendedValue fir::factory::readBoxValue(fir::FirOpBuilder &builder, assert(!box.hasAssumedRank() && "cannot read unlimited polymorphic or assumed rank fir.box"); auto addr = - builder.create<fir::BoxAddrOp>(loc, box.getMemTy(), box.getAddr()); + fir::BoxAddrOp::create(builder, loc, box.getMemTy(), box.getAddr()); if (box.isCharacter()) { auto len = fir::factory::readCharLen(builder, loc, box); if (box.rank() == 0) @@ -1139,13 +1139,13 @@ static llvm::SmallVector<mlir::Value> getFromBox(mlir::Location loc, } else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) { if (charTy.hasDynamicLen()) { auto idxTy = builder.getIndexType(); - auto eleSz = builder.create<fir::BoxEleSizeOp>(loc, idxTy, boxVal); + auto eleSz = fir::BoxEleSizeOp::create(builder, loc, idxTy, boxVal); auto kindBytes = builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8; mlir::Value charSz = builder.createIntegerConstant(loc, idxTy, kindBytes); mlir::Value len = - builder.create<mlir::arith::DivSIOp>(loc, eleSz, charSz); + mlir::arith::DivSIOp::create(builder, loc, eleSz, charSz); return {len}; } } @@ -1237,11 +1237,11 @@ fir::ExtendedValue fir::factory::createStringLiteral(fir::FirOpBuilder &builder, loc, type, globalName, [&](fir::FirOpBuilder &builder) { auto stringLitOp = builder.createStringLitOp(loc, str); - builder.create<fir::HasValueOp>(loc, stringLitOp); + fir::HasValueOp::create(builder, loc, stringLitOp); }, builder.createLinkOnceLinkage()); - auto addr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + auto addr = fir::AddrOfOp::create(builder, loc, global.resultType(), + global.getSymbol()); auto len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), str.size()); return fir::CharBoxValue{addr, len}; @@ -1255,7 +1255,7 @@ fir::factory::createExtents(fir::FirOpBuilder &builder, mlir::Location loc, for (auto ext : seqTy.getShape()) extents.emplace_back( ext == fir::SequenceType::getUnknownExtent() - ? builder.create<fir::UndefOp>(loc, idxTy).getResult() + ? fir::UndefOp::create(builder, loc, idxTy).getResult() : builder.createIntegerConstant(loc, idxTy, ext)); return extents; } @@ -1396,11 +1396,11 @@ void fir::factory::genScalarAssignment(fir::FirOpBuilder &builder, assert(!fir::hasDynamicSize(type)); auto rhsVal = fir::getBase(rhs); if (fir::isa_ref_type(rhsVal.getType())) - rhsVal = builder.create<fir::LoadOp>(loc, rhsVal); + rhsVal = fir::LoadOp::create(builder, loc, rhsVal); mlir::Value lhsAddr = fir::getBase(lhs); rhsVal = builder.createConvert(loc, fir::unwrapRefType(lhsAddr.getType()), rhsVal); - builder.create<fir::StoreOp>(loc, rhsVal, lhsAddr); + fir::StoreOp::create(builder, loc, rhsVal, lhsAddr); } } @@ -1421,16 +1421,18 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, auto &[lFieldName, lFieldTy] = lhsPair; auto &[rFieldName, rFieldTy] = rhsPair; assert(!fir::hasDynamicSize(lFieldTy) && !fir::hasDynamicSize(rFieldTy)); - mlir::Value rField = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rFieldName, rhsType, fir::getTypeParams(rhs)); + mlir::Value rField = + fir::FieldIndexOp::create(builder, loc, fieldIndexType, rFieldName, + rhsType, fir::getTypeParams(rhs)); auto rFieldRefType = builder.getRefType(rFieldTy); - mlir::Value fromCoor = builder.create<fir::CoordinateOp>( - loc, rFieldRefType, fir::getBase(rhs), rField); - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, lFieldName, lhsType, fir::getTypeParams(lhs)); + mlir::Value fromCoor = fir::CoordinateOp::create( + builder, loc, rFieldRefType, fir::getBase(rhs), rField); + mlir::Value field = + fir::FieldIndexOp::create(builder, loc, fieldIndexType, lFieldName, + lhsType, fir::getTypeParams(lhs)); auto fieldRefType = builder.getRefType(lFieldTy); - mlir::Value toCoor = builder.create<fir::CoordinateOp>( - loc, fieldRefType, fir::getBase(lhs), field); + mlir::Value toCoor = fir::CoordinateOp::create(builder, loc, fieldRefType, + fir::getBase(lhs), field); std::optional<fir::DoLoopOp> outerLoop; if (auto sequenceType = mlir::dyn_cast<fir::SequenceType>(lFieldTy)) { // Create loops to assign array components elements by elements. @@ -1444,7 +1446,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, for (auto extent : llvm::reverse(sequenceType.getShape())) { // TODO: add zero size test ! mlir::Value ub = builder.createIntegerConstant(loc, idxTy, extent - 1); - auto loop = builder.create<fir::DoLoopOp>(loc, zero, ub, one); + auto loop = fir::DoLoopOp::create(builder, loc, zero, ub, one); if (!outerLoop) outerLoop = loop; indices.push_back(loop.getInductionVar()); @@ -1453,19 +1455,19 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, // Set indices in column-major order. std::reverse(indices.begin(), indices.end()); auto elementRefType = builder.getRefType(sequenceType.getEleTy()); - toCoor = builder.create<fir::CoordinateOp>(loc, elementRefType, toCoor, - indices); - fromCoor = builder.create<fir::CoordinateOp>(loc, elementRefType, - fromCoor, indices); + toCoor = fir::CoordinateOp::create(builder, loc, elementRefType, toCoor, + indices); + fromCoor = fir::CoordinateOp::create(builder, loc, elementRefType, + fromCoor, indices); } if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy); mlir::isa<fir::BaseBoxType>(fieldEleTy)) { assert(mlir::isa<fir::PointerType>( mlir::cast<fir::BaseBoxType>(fieldEleTy).getEleTy()) && "allocatable members require deep copy"); - auto fromPointerValue = builder.create<fir::LoadOp>(loc, fromCoor); + auto fromPointerValue = fir::LoadOp::create(builder, loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); - builder.create<fir::StoreOp>(loc, castTo, toCoor); + fir::StoreOp::create(builder, loc, castTo, toCoor); } else { auto from = fir::factory::componentToExtendedValue(builder, loc, fromCoor); @@ -1543,7 +1545,7 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder, // runtime interface, but assume the fir.box is unchanged. // TODO: does this holds true with polymorphic entities ? auto toMutableBox = builder.createTemporary(loc, to.getType()); - builder.create<fir::StoreOp>(loc, to, toMutableBox); + fir::StoreOp::create(builder, loc, to, toMutableBox); if (isTemporaryLHS) fir::runtime::genAssignTemporary(builder, loc, toMutableBox, from); else @@ -1588,12 +1590,12 @@ mlir::Value fir::factory::genLenOfCharacter( auto idxTy = builder.getIndexType(); auto zero = builder.createIntegerConstant(loc, idxTy, 0); auto saturatedDiff = [&](mlir::Value lower, mlir::Value upper) { - auto diff = builder.create<mlir::arith::SubIOp>(loc, upper, lower); + auto diff = mlir::arith::SubIOp::create(builder, loc, upper, lower); auto one = builder.createIntegerConstant(loc, idxTy, 1); - auto size = builder.create<mlir::arith::AddIOp>(loc, diff, one); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, size, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, size, zero); + auto size = mlir::arith::AddIOp::create(builder, loc, diff, one); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, size, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, size, zero); }; if (substring.size() == 2) { auto upper = builder.createConvert(loc, idxTy, substring.back()); @@ -1615,7 +1617,7 @@ mlir::Value fir::factory::genLenOfCharacter( } if (fir::isa_box_type(memref.getType())) { if (mlir::isa<fir::BoxCharType>(memref.getType())) - return builder.create<fir::BoxCharLenOp>(loc, idxTy, memref); + return fir::BoxCharLenOp::create(builder, loc, idxTy, memref); if (mlir::isa<fir::BoxType>(memref.getType())) return CharacterExprHelper(builder, loc).readLengthFromBox(memref); fir::emitFatalError(loc, "memref has wrong type"); @@ -1684,10 +1686,10 @@ mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, if (auto cst = mlir::dyn_cast<mlir::arith::ConstantOp>(definingOp)) if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue())) return intAttr.getInt() > 0 ? value : zero; - mlir::Value valueIsGreater = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, value, zero); - return builder.create<mlir::arith::SelectOp>(loc, valueIsGreater, value, - zero); + mlir::Value valueIsGreater = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, value, zero); + return mlir::arith::SelectOp::create(builder, loc, valueIsGreater, value, + zero); } mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, @@ -1703,8 +1705,8 @@ mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder, mlir::Value one) { mlir::Type type = lb.getType(); // Let the folder deal with the common `ub - <const> + 1` case. - auto diff = builder.create<mlir::arith::SubIOp>(loc, type, ub, lb); - auto rawExtent = builder.create<mlir::arith::AddIOp>(loc, type, diff, one); + auto diff = mlir::arith::SubIOp::create(builder, loc, type, ub, lb); + auto rawExtent = mlir::arith::AddIOp::create(builder, loc, type, diff, one); return fir::factory::genMaxWithZero(builder, loc, rawExtent, zero); } mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder, @@ -1724,8 +1726,8 @@ genCPtrOrCFunptrFieldIndex(fir::FirOpBuilder &builder, mlir::Location loc, auto addrFieldName = recTy.getTypeList()[0].first; mlir::Type addrFieldTy = recTy.getTypeList()[0].second; auto fieldIndexType = fir::FieldType::get(cptrTy.getContext()); - mlir::Value addrFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, addrFieldName, recTy, + mlir::Value addrFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, addrFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); return {addrFieldIndex, addrFieldTy}; } @@ -1736,8 +1738,8 @@ mlir::Value fir::factory::genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Type ty) { auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, ty); - return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy), - cPtr, addrFieldIndex); + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); } mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder, @@ -1748,15 +1750,15 @@ mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder, auto cptrFieldName = recTy.getTypeList()[0].first; mlir::Type cptrFieldTy = recTy.getTypeList()[0].second; auto fieldIndexType = fir::FieldType::get(ty.getContext()); - mlir::Value cptrFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, cptrFieldName, recTy, + mlir::Value cptrFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, cptrFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - auto cptrCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex); + auto cptrCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex); auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, cptrFieldTy); - return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy), - cptrCoord, addrFieldIndex); + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cptrCoord, addrFieldIndex); } mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, @@ -1769,13 +1771,13 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy); mlir::Value cPtrCoor; if (fir::isa_ref_type(cPtr.getType())) { - cPtrCoor = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); + cPtrCoor = fir::CoordinateOp::create( + builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex); } else { auto arrayAttr = builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)}); - cPtrCoor = builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr, - arrayAttr); + cPtrCoor = fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr, + arrayAttr); } return genCPtrOrCFunptrValue(builder, loc, cPtrCoor); } @@ -1783,13 +1785,14 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, if (fir::isa_ref_type(cPtr.getType())) { mlir::Value cPtrAddr = fir::factory::genCPtrOrCFunptrAddr(builder, loc, cPtr, cPtrTy); - return builder.create<fir::LoadOp>(loc, cPtrAddr); + return fir::LoadOp::create(builder, loc, cPtrAddr); } auto [addrFieldIndex, addrFieldTy] = genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy); auto arrayAttr = builder.getArrayAttr({builder.getIntegerAttr(builder.getIndexType(), 0)}); - return builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr, arrayAttr); + return fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr, + arrayAttr); } fir::BoxValue fir::factory::createBoxValue(fir::FirOpBuilder &builder, @@ -1837,8 +1840,8 @@ mlir::Value fir::factory::createNullBoxProc(fir::FirOpBuilder &builder, if (!boxTy) fir::emitFatalError(loc, "Procedure pointer must be of BoxProcType"); auto boxEleTy{fir::unwrapRefType(boxTy.getEleTy())}; - mlir::Value initVal{builder.create<fir::ZeroOp>(loc, boxEleTy)}; - return builder.create<fir::EmboxProcOp>(loc, boxTy, initVal); + mlir::Value initVal{fir::ZeroOp::create(builder, loc, boxEleTy)}; + return fir::EmboxProcOp::create(builder, loc, boxTy, initVal); } void fir::factory::setInternalLinkage(mlir::func::FuncOp func) { @@ -1897,15 +1900,15 @@ llvm::SmallVector<mlir::Value> fir::factory::updateRuntimeExtentsForEmptyArrays( mlir::Type type = extent.getType(); mlir::Value zero = createZeroValue(builder, loc, type); zeroes.push_back(zero); - mlir::Value isZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); - isEmpty = builder.create<mlir::arith::OrIOp>(loc, isEmpty, isZero); + mlir::Value isZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); + isEmpty = mlir::arith::OrIOp::create(builder, loc, isEmpty, isZero); } llvm::SmallVector<mlir::Value> newExtents; for (auto [zero, extent] : llvm::zip_equal(zeroes, extents)) { newExtents.push_back( - builder.create<mlir::arith::SelectOp>(loc, isEmpty, zero, extent)); + mlir::arith::SelectOp::create(builder, loc, isEmpty, zero, extent)); } return newExtents; } @@ -1926,7 +1929,7 @@ void fir::factory::genDimInfoFromBox( for (unsigned i = 0; i < rank; ++i) { mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim); if (lbounds) lbounds->push_back(dimInfo.getLowerBound()); if (extents) @@ -1943,12 +1946,12 @@ mlir::Value fir::factory::genLifetimeStart(mlir::OpBuilder &builder, mlir::Type ptrTy = mlir::LLVM::LLVMPointerType::get( alloc.getContext(), getAllocaAddressSpace(dl)); mlir::Value cast = - builder.create<fir::ConvertOp>(loc, ptrTy, alloc.getResult()); - builder.create<mlir::LLVM::LifetimeStartOp>(loc, size, cast); + fir::ConvertOp::create(builder, loc, ptrTy, alloc.getResult()); + mlir::LLVM::LifetimeStartOp::create(builder, loc, size, cast); return cast; } void fir::factory::genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value cast, int64_t size) { - builder.create<mlir::LLVM::LifetimeEndOp>(loc, size, cast); + mlir::LLVM::LifetimeEndOp::create(builder, loc, size, cast); } |