diff options
Diffstat (limited to 'flang/lib/Optimizer')
57 files changed, 2086 insertions, 1980 deletions
diff --git a/flang/lib/Optimizer/Builder/CUFCommon.cpp b/flang/lib/Optimizer/Builder/CUFCommon.cpp index dcbf499..cf7588f 100644 --- a/flang/lib/Optimizer/Builder/CUFCommon.cpp +++ b/flang/lib/Optimizer/Builder/CUFCommon.cpp @@ -25,8 +25,8 @@ mlir::gpu::GPUModuleOp cuf::getOrCreateGPUModule(mlir::ModuleOp mod, mlir::UnitAttr::get(ctx)); mlir::OpBuilder builder(ctx); - auto gpuMod = builder.create<mlir::gpu::GPUModuleOp>(mod.getLoc(), - cudaDeviceModuleName); + auto gpuMod = mlir::gpu::GPUModuleOp::create(builder, mod.getLoc(), + cudaDeviceModuleName); mlir::Block::iterator insertPt(mod.getBodyRegion().front().end()); symTab.insert(gpuMod, insertPt); return gpuMod; @@ -84,8 +84,8 @@ void cuf::genPointerSync(const mlir::Value box, fir::FirOpBuilder &builder) { if (auto globalOp = mod.lookupSymbol<fir::GlobalOp>(addrOfOp.getSymbol())) { if (cuf::isRegisteredDeviceGlobal(globalOp)) { - builder.create<cuf::SyncDescriptorOp>(box.getLoc(), - addrOfOp.getSymbol()); + cuf::SyncDescriptorOp::create(builder, box.getLoc(), + addrOfOp.getSymbol()); } } } diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp index 61428ac49..a096099 100644 --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -112,8 +112,8 @@ fir::factory::CharacterExprHelper::materializeValue(mlir::Value str) { } auto len = builder.createIntegerConstant( loc, builder.getCharacterLengthType(), charTy.getLen()); - auto temp = builder.create<fir::AllocaOp>(loc, charTy); - builder.create<fir::StoreOp>(loc, str, temp); + auto temp = fir::AllocaOp::create(builder, loc, charTy); + fir::StoreOp::create(builder, loc, str, temp); LLVM_DEBUG(llvm::dbgs() << "materialized as local: " << str << " -> (" << temp << ", " << len << ")\n"); return {temp, len}; @@ -163,7 +163,7 @@ fir::factory::CharacterExprHelper::toExtendedValue(mlir::Value character, } if (!boxCharLen) { auto unboxed = - builder.create<fir::UnboxCharOp>(loc, refType, lenType, character); + fir::UnboxCharOp::create(builder, loc, refType, lenType, character); base = builder.createConvert(loc, refType, unboxed.getResult(0)); boxCharLen = unboxed.getResult(1); } @@ -208,7 +208,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) { // not in memory. if (!fir::isa_ref_type(buff.getType())) { auto temp = builder.createTemporary(loc, buff.getType()); - builder.create<fir::StoreOp>(loc, buff, temp); + fir::StoreOp::create(builder, loc, buff, temp); buff = temp; } // fir.emboxchar only accepts scalar, cast array buffer to a scalar buffer. @@ -218,7 +218,7 @@ fir::factory::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) { // be used in boxchar. auto len = builder.createConvert(loc, builder.getCharacterLengthType(), box.getLen()); - return builder.create<fir::EmboxCharOp>(loc, boxCharType, buff, len); + return fir::EmboxCharOp::create(builder, loc, boxCharType, buff, len); } fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( @@ -231,8 +231,8 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter( auto lenType = builder.getCharacterLengthType(); auto len = builder.createConvert(loc, lenType, box.getLen()); for (auto extent : box.getExtents()) - len = builder.create<mlir::arith::MulIOp>( - loc, len, builder.createConvert(loc, lenType, extent)); + len = mlir::arith::MulIOp::create( + builder, loc, len, builder.createConvert(loc, lenType, extent)); // TODO: typeLen can be improved in compiled constant cases // TODO: allow bare fir.array<> (no ref) conversion here ? @@ -277,7 +277,7 @@ fir::factory::CharacterExprHelper::createElementAddr(mlir::Value buffer, auto coor = builder.createConvert(loc, coorTy, buffer); auto i = builder.createConvert(loc, builder.getIndexType(), index); - return builder.create<fir::CoordinateOp>(loc, singleRefTy, coor, i); + return fir::CoordinateOp::create(builder, loc, singleRefTy, coor, i); } /// Load a character out of `buff` from offset `index`. @@ -287,7 +287,7 @@ fir::factory::CharacterExprHelper::createLoadCharAt(mlir::Value buff, mlir::Value index) { LLVM_DEBUG(llvm::dbgs() << "load a char: " << buff << " type: " << buff.getType() << " at: " << index << '\n'); - return builder.create<fir::LoadOp>(loc, createElementAddr(buff, index)); + return fir::LoadOp::create(builder, loc, createElementAddr(buff, index)); } /// Store the singleton character `c` to `str` at offset `index`. @@ -299,7 +299,7 @@ void fir::factory::CharacterExprHelper::createStoreCharAt(mlir::Value str, << " type: " << str.getType() << " at: " << index << '\n'); auto addr = createElementAddr(str, index); - builder.create<fir::StoreOp>(loc, c, addr); + fir::StoreOp::create(builder, loc, c, addr); } // FIXME: this temp is useless... either fir.coordinate_of needs to @@ -311,8 +311,8 @@ mlir::Value fir::factory::CharacterExprHelper::getCharBoxBuffer( const fir::CharBoxValue &box) { auto buff = box.getBuffer(); if (fir::isa_char(buff.getType())) { - auto newBuff = builder.create<fir::AllocaOp>(loc, buff.getType()); - builder.create<fir::StoreOp>(loc, buff, newBuff); + auto newBuff = fir::AllocaOp::create(builder, loc, buff.getType()); + fir::StoreOp::create(builder, loc, buff, newBuff); return newBuff; } return buff; @@ -339,19 +339,19 @@ void fir::factory::CharacterExprHelper::createCopy( auto kindBytes = builder.createIntegerConstant(loc, i64Ty, bytes); auto castCount = builder.createConvert(loc, i64Ty, count); auto totalBytes = - builder.create<mlir::arith::MulIOp>(loc, kindBytes, castCount); + mlir::arith::MulIOp::create(builder, loc, kindBytes, castCount); auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); auto toPtr = builder.createConvert(loc, llvmPointerType, toBuff); auto fromPtr = builder.createConvert(loc, llvmPointerType, fromBuff); - builder.create<mlir::LLVM::MemmoveOp>(loc, toPtr, fromPtr, totalBytes, - isVolatile); + mlir::LLVM::MemmoveOp::create(builder, loc, toPtr, fromPtr, totalBytes, + isVolatile); return; } // Convert a CHARACTER of one KIND into a CHARACTER of another KIND. - builder.create<fir::CharConvertOp>(loc, src.getBuffer(), count, - dest.getBuffer()); + fir::CharConvertOp::create(builder, loc, src.getBuffer(), count, + dest.getBuffer()); } void fir::factory::CharacterExprHelper::createPadding( @@ -397,7 +397,7 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createTempFrom( } else { auto ref = builder.createConvert(loc, builder.getRefType(sourceTy), temp.getBuffer()); - builder.create<fir::StoreOp>(loc, charBox->getBuffer(), ref); + fir::StoreOp::create(builder, loc, charBox->getBuffer(), ref); } return temp; } @@ -412,23 +412,23 @@ void fir::factory::CharacterExprHelper::createLengthOneAssign( auto fromCharLen1RefTy = builder.getRefType(getSingletonCharType( builder.getContext(), getCharacterKind(fir::unwrapRefType(val.getType())))); - val = builder.create<fir::LoadOp>( - loc, builder.createConvert(loc, fromCharLen1RefTy, val)); + val = fir::LoadOp::create( + builder, loc, builder.createConvert(loc, fromCharLen1RefTy, val)); } auto toCharLen1Ty = getSingletonCharType(builder.getContext(), getCharacterKind(toTy)); val = builder.createConvert(loc, toCharLen1Ty, val); - builder.create<fir::StoreOp>( - loc, val, + fir::StoreOp::create( + builder, loc, val, builder.createConvert(loc, builder.getRefType(toCharLen1Ty), addr)); } /// Returns the minimum of integer mlir::Value \p a and \b. mlir::Value genMin(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value a, mlir::Value b) { - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, b); - return builder.create<mlir::arith::SelectOp>(loc, cmp, a, b); + auto cmp = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); + return mlir::arith::SelectOp::create(builder, loc, cmp, a, b); } void fir::factory::CharacterExprHelper::createAssign( @@ -479,7 +479,7 @@ void fir::factory::CharacterExprHelper::createAssign( if (!compileTimeSameLength) { auto one = builder.createIntegerConstant(loc, lhs.getLen().getType(), 1); auto maxPadding = - builder.create<mlir::arith::SubIOp>(loc, lhs.getLen(), one); + mlir::arith::SubIOp::create(builder, loc, lhs.getLen(), one); createPadding(lhs, copyCount, maxPadding); } } @@ -490,18 +490,19 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createConcatenate( lhs.getLen()); auto rhsLen = builder.createConvert(loc, builder.getCharacterLengthType(), rhs.getLen()); - mlir::Value len = builder.create<mlir::arith::AddIOp>(loc, lhsLen, rhsLen); + mlir::Value len = mlir::arith::AddIOp::create(builder, loc, lhsLen, rhsLen); auto temp = createCharacterTemp(getCharacterType(rhs), len); createCopy(temp, lhs, lhsLen); auto one = builder.createIntegerConstant(loc, len.getType(), 1); - auto upperBound = builder.create<mlir::arith::SubIOp>(loc, len, one); + auto upperBound = mlir::arith::SubIOp::create(builder, loc, len, one); auto lhsLenIdx = builder.createConvert(loc, builder.getIndexType(), lhsLen); auto fromBuff = getCharBoxBuffer(rhs); auto toBuff = getCharBoxBuffer(temp); fir::factory::DoLoopHelper{builder, loc}.createLoop( lhsLenIdx, upperBound, one, [&](fir::FirOpBuilder &bldr, mlir::Value index) { - auto rhsIndex = bldr.create<mlir::arith::SubIOp>(loc, index, lhsLenIdx); + auto rhsIndex = + mlir::arith::SubIOp::create(bldr, loc, index, lhsLenIdx); auto charVal = createLoadCharAt(fromBuff, rhsIndex); createStoreCharAt(toBuff, index, charVal); }); @@ -514,7 +515,7 @@ mlir::Value fir::factory::CharacterExprHelper::genSubstringBase( if (!one) one = builder.createIntegerConstant(loc, lowerBound.getType(), 1); auto offset = - builder.create<mlir::arith::SubIOp>(loc, lowerBound, one).getResult(); + mlir::arith::SubIOp::create(builder, loc, lowerBound, one).getResult(); auto addr = createElementAddr(stringRawAddr, offset); return builder.createConvert(loc, substringAddrType, addr); } @@ -545,19 +546,19 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createSubstring( mlir::Value substringLen; if (nbounds < 2) { substringLen = - builder.create<mlir::arith::SubIOp>(loc, box.getLen(), castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, box.getLen(), castBounds[0]); } else { substringLen = - builder.create<mlir::arith::SubIOp>(loc, castBounds[1], castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, castBounds[1], castBounds[0]); } - substringLen = builder.create<mlir::arith::AddIOp>(loc, substringLen, one); + substringLen = mlir::arith::AddIOp::create(builder, loc, substringLen, one); // Set length to zero if bounds were reversed (Fortran 2018 9.4.1) auto zero = builder.createIntegerConstant(loc, substringLen.getType(), 0); - auto cdt = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); + auto cdt = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); substringLen = - builder.create<mlir::arith::SelectOp>(loc, cdt, zero, substringLen); + mlir::arith::SelectOp::create(builder, loc, cdt, zero, substringLen); return {substringRef, substringLen}; } @@ -573,11 +574,11 @@ fir::factory::CharacterExprHelper::createLenTrim(const fir::CharBoxValue &str) { auto zero = builder.createIntegerConstant(loc, indexType, 0); auto trueVal = builder.createIntegerConstant(loc, builder.getI1Type(), 1); auto blank = createBlankConstantCode(getCharacterType(str)); - mlir::Value lastChar = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value lastChar = mlir::arith::SubIOp::create(builder, loc, len, one); auto iterWhile = - builder.create<fir::IterWhileOp>(loc, lastChar, zero, minusOne, trueVal, - /*returnFinalCount=*/false, lastChar); + fir::IterWhileOp::create(builder, loc, lastChar, zero, minusOne, trueVal, + /*returnFinalCount=*/false, lastChar); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(iterWhile.getBody()); auto index = iterWhile.getInductionVar(); @@ -586,17 +587,17 @@ fir::factory::CharacterExprHelper::createLenTrim(const fir::CharBoxValue &str) { auto elemAddr = createElementAddr(fromBuff, index); auto codeAddr = builder.createConvert(loc, builder.getRefType(blank.getType()), elemAddr); - auto c = builder.create<fir::LoadOp>(loc, codeAddr); - auto isBlank = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, blank, c); + auto c = fir::LoadOp::create(builder, loc, codeAddr); + auto isBlank = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, blank, c); llvm::SmallVector<mlir::Value> results = {isBlank, index}; - builder.create<fir::ResultOp>(loc, results); + fir::ResultOp::create(builder, loc, results); builder.restoreInsertionPoint(insPt); // Compute length after iteration (zero if all blanks) mlir::Value newLen = - builder.create<mlir::arith::AddIOp>(loc, iterWhile.getResult(1), one); - auto result = builder.create<mlir::arith::SelectOp>( - loc, iterWhile.getResult(0), zero, newLen); + mlir::arith::AddIOp::create(builder, loc, iterWhile.getResult(1), one); + auto result = mlir::arith::SelectOp::create( + builder, loc, iterWhile.getResult(0), zero, newLen); return builder.createConvert(loc, builder.getCharacterLengthType(), result); } @@ -606,7 +607,7 @@ fir::factory::CharacterExprHelper::createCharacterTemp(mlir::Type type, assert(len >= 0 && "expected positive length"); auto kind = recoverCharacterType(type).getFKind(); auto charType = fir::CharacterType::get(builder.getContext(), kind, len); - auto addr = builder.create<fir::AllocaOp>(loc, charType); + auto addr = fir::AllocaOp::create(builder, loc, charType); auto mlirLen = builder.createIntegerConstant(loc, builder.getCharacterLengthType(), len); return {addr, mlirLen}; @@ -690,10 +691,10 @@ fir::factory::CharacterExprHelper::createSingletonFromCode(mlir::Value code, auto bits = builder.getKindMap().getCharacterBitsize(kind); auto intType = builder.getIntegerType(bits); auto cast = builder.createConvert(loc, intType, code); - auto undef = builder.create<fir::UndefOp>(loc, charType); + auto undef = fir::UndefOp::create(builder, loc, charType); auto zero = builder.getIntegerAttr(builder.getIndexType(), 0); - return builder.create<fir::InsertValueOp>(loc, charType, undef, cast, - builder.getArrayAttr(zero)); + return fir::InsertValueOp::create(builder, loc, charType, undef, cast, + builder.getArrayAttr(zero)); } mlir::Value fir::factory::CharacterExprHelper::extractCodeFromSingleton( @@ -703,8 +704,8 @@ mlir::Value fir::factory::CharacterExprHelper::extractCodeFromSingleton( auto bits = builder.getKindMap().getCharacterBitsize(type.getFKind()); auto intType = builder.getIntegerType(bits); auto zero = builder.getIntegerAttr(builder.getIndexType(), 0); - return builder.create<fir::ExtractValueOp>(loc, intType, singleton, - builder.getArrayAttr(zero)); + return fir::ExtractValueOp::create(builder, loc, intType, singleton, + builder.getArrayAttr(zero)); } mlir::Value @@ -716,12 +717,12 @@ fir::factory::CharacterExprHelper::readLengthFromBox(mlir::Value box) { mlir::Value fir::factory::CharacterExprHelper::readLengthFromBox( mlir::Value box, fir::CharacterType charTy) { auto lenTy = builder.getCharacterLengthType(); - auto size = builder.create<fir::BoxEleSizeOp>(loc, lenTy, box); + auto size = fir::BoxEleSizeOp::create(builder, loc, lenTy, box); auto bits = builder.getKindMap().getCharacterBitsize(charTy.getFKind()); auto width = bits / 8; if (width > 1) { auto widthVal = builder.createIntegerConstant(loc, lenTy, width); - return builder.create<mlir::arith::DivSIOp>(loc, size, widthVal); + return mlir::arith::DivSIOp::create(builder, loc, size, widthVal); } return size; } @@ -748,18 +749,18 @@ fir::factory::extractCharacterProcedureTuple(fir::FirOpBuilder &builder, mlir::Value tuple, bool openBoxProc) { mlir::TupleType tupleType = mlir::cast<mlir::TupleType>(tuple.getType()); - mlir::Value addr = builder.create<fir::ExtractValueOp>( - loc, tupleType.getType(0), tuple, + mlir::Value addr = fir::ExtractValueOp::create( + builder, loc, tupleType.getType(0), tuple, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)})); mlir::Value proc = [&]() -> mlir::Value { if (openBoxProc) if (auto addrTy = mlir::dyn_cast<fir::BoxProcType>(addr.getType())) - return builder.create<fir::BoxAddrOp>(loc, addrTy.getEleTy(), addr); + return fir::BoxAddrOp::create(builder, loc, addrTy.getEleTy(), addr); return addr; }(); - mlir::Value len = builder.create<fir::ExtractValueOp>( - loc, tupleType.getType(1), tuple, + mlir::Value len = fir::ExtractValueOp::create( + builder, loc, tupleType.getType(1), tuple, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 1)})); return {proc, len}; @@ -773,14 +774,14 @@ mlir::Value fir::factory::createCharacterProcedureTuple( if (len) len = builder.createConvert(loc, tupleType.getType(1), len); else - len = builder.create<fir::UndefOp>(loc, tupleType.getType(1)); - mlir::Value tuple = builder.create<fir::UndefOp>(loc, tupleType); - tuple = builder.create<fir::InsertValueOp>( - loc, tupleType, tuple, addr, + len = fir::UndefOp::create(builder, loc, tupleType.getType(1)); + mlir::Value tuple = fir::UndefOp::create(builder, loc, tupleType); + tuple = fir::InsertValueOp::create( + builder, loc, tupleType, tuple, addr, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 0)})); - tuple = builder.create<fir::InsertValueOp>( - loc, tupleType, tuple, len, + tuple = fir::InsertValueOp::create( + builder, loc, tupleType, tuple, len, builder.getArrayAttr( {builder.getIntegerAttr(builder.getIndexType(), 1)})); return tuple; @@ -827,10 +828,10 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum( auto currLen = builder.createConvert(loc, builder.getCharacterLengthType(), currChar.getLen()); // biggest len result - mlir::Value lhsBigger = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::uge, biggestLen, currLen); - biggestLen = builder.create<mlir::arith::SelectOp>(loc, lhsBigger, - biggestLen, currLen); + mlir::Value lhsBigger = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, biggestLen, currLen); + biggestLen = mlir::arith::SelectOp::create(builder, loc, lhsBigger, + biggestLen, currLen); auto cmp = predIsMin ? mlir::arith::CmpIPredicate::slt : mlir::arith::CmpIPredicate::sgt; @@ -843,10 +844,10 @@ fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum( resultBuf = builder.createConvert(loc, type, resultBuf); currBuf = builder.createConvert(loc, type, currBuf); - resultBuf = builder.create<mlir::arith::SelectOp>(loc, resultCmp, currBuf, - resultBuf); - resultLen = builder.create<mlir::arith::SelectOp>(loc, resultCmp, currLen, - resultLen); + resultBuf = mlir::arith::SelectOp::create(builder, loc, resultCmp, currBuf, + resultBuf); + resultLen = mlir::arith::SelectOp::create(builder, loc, resultCmp, currLen, + resultLen); } // now that we know the lexicographically biggest/smallest char and which char @@ -876,7 +877,7 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, // As a value, it ought to have a constant LEN value. assert(charTy.hasConstantLen() && "must have constant length"); mlir::Value tmp = builder.createTemporary(loc, charTy); - builder.create<fir::StoreOp>(loc, boxCharAddr, tmp); + fir::StoreOp::create(builder, loc, boxCharAddr, tmp); boxCharAddr = tmp; } auto fromBits = kindMap.getCharacterBitsize( @@ -886,13 +887,13 @@ fir::factory::convertCharacterKind(fir::FirOpBuilder &builder, // Scale by relative ratio to give a buffer of the same length. auto ratio = builder.createIntegerConstant(loc, bufferSize.getType(), fromBits / toBits); - bufferSize = builder.create<mlir::arith::MulIOp>(loc, bufferSize, ratio); + bufferSize = mlir::arith::MulIOp::create(builder, loc, bufferSize, ratio); } mlir::Type toType = fir::CharacterType::getUnknownLen(builder.getContext(), toKind); auto dest = builder.createTemporary(loc, toType, /*name=*/{}, /*shape=*/{}, mlir::ValueRange{bufferSize}); - builder.create<fir::CharConvertOp>(loc, boxCharAddr, srcBoxChar.getLen(), - dest); + fir::CharConvertOp::create(builder, loc, boxCharAddr, srcBoxChar.getLen(), + dest); return fir::CharBoxValue{dest, srcBoxChar.getLen()}; } diff --git a/flang/lib/Optimizer/Builder/Complex.cpp b/flang/lib/Optimizer/Builder/Complex.cpp index 69f97dd..61de988 100644 --- a/flang/lib/Optimizer/Builder/Complex.cpp +++ b/flang/lib/Optimizer/Builder/Complex.cpp @@ -24,7 +24,7 @@ mlir::Type fir::factory::Complex::getComplexPartType(mlir::Value cplx) const { mlir::Value fir::factory::Complex::createComplex(mlir::Type cplxTy, mlir::Value real, mlir::Value imag) { - mlir::Value und = builder.create<fir::UndefOp>(loc, cplxTy); + mlir::Value und = fir::UndefOp::create(builder, loc, cplxTy); return insert<Part::Imag>(insert<Part::Real>(und, real), imag); } diff --git a/flang/lib/Optimizer/Builder/DoLoopHelper.cpp b/flang/lib/Optimizer/Builder/DoLoopHelper.cpp index 4b12e28..0ec91d5 100644 --- a/flang/lib/Optimizer/Builder/DoLoopHelper.cpp +++ b/flang/lib/Optimizer/Builder/DoLoopHelper.cpp @@ -20,7 +20,7 @@ fir::factory::DoLoopHelper::createLoop(mlir::Value lb, mlir::Value ub, auto ubi = builder.convertToIndexType(loc, ub); assert(step && "step must be an actual Value"); auto inc = builder.convertToIndexType(loc, step); - auto loop = builder.create<fir::DoLoopOp>(loc, lbi, ubi, inc); + auto loop = fir::DoLoopOp::create(builder, loc, lbi, ubi, inc); auto insertPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(loop.getBody()); auto index = loop.getInductionVar(); @@ -43,6 +43,6 @@ fir::factory::DoLoopHelper::createLoop(mlir::Value count, auto indexType = builder.getIndexType(); auto zero = builder.createIntegerConstant(loc, indexType, 0); auto one = builder.createIntegerConstant(loc, count.getType(), 1); - auto up = builder.create<mlir::arith::SubIOp>(loc, count, one); + auto up = mlir::arith::SubIOp::create(builder, loc, count, one); return createLoop(zero, up, one, bodyGenerator); } diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index acd5a88..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; } @@ -620,7 +620,7 @@ fir::StringLitOp fir::FirOpBuilder::createStringLitOp(mlir::Location loc, mlir::NamedAttribute sizeAttr(sizeTag, getI64IntegerAttr(data.size())); llvm::SmallVector<mlir::NamedAttribute> attrs{dataAttr, sizeAttr}; return create<fir::StringLitOp>(loc, llvm::ArrayRef<mlir::Type>{type}, - std::nullopt, attrs); + mlir::ValueRange{}, attrs); } mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc, @@ -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); } diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index fb6f0db..c3948f2 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -50,7 +50,7 @@ hlfir::getExplicitExtentsFromShape(mlir::Value shape, int64_t extent = exprShape[i]; mlir::Value extentVal; if (extent == expr.getUnknownExtent()) { - auto op = builder.create<hlfir::GetExtentOp>(shape.getLoc(), shape, i); + auto op = hlfir::GetExtentOp::create(builder, shape.getLoc(), shape, i); extentVal = op.getResult(); } else { extentVal = @@ -150,7 +150,7 @@ static mlir::Value genCharacterVariableLength(mlir::Location loc, return builder.createIntegerConstant(loc, builder.getIndexType(), charType.getLen()); if (var.isMutableBox()) - var = hlfir::Entity{builder.create<fir::LoadOp>(loc, var)}; + var = hlfir::Entity{fir::LoadOp::create(builder, loc, var)}; mlir::Value len = fir::factory::CharacterExprHelper{builder, loc}.getLength( var.getFirBase()); assert(len && "failed to retrieve length"); @@ -164,8 +164,8 @@ static fir::CharBoxValue genUnboxChar(mlir::Location loc, return {emboxChar.getMemref(), emboxChar.getLen()}; mlir::Type refType = fir::ReferenceType::get( mlir::cast<fir::BoxCharType>(boxChar.getType()).getEleTy()); - auto unboxed = builder.create<fir::UnboxCharOp>( - loc, refType, builder.getIndexType(), boxChar); + auto unboxed = fir::UnboxCharOp::create(builder, loc, refType, + builder.getIndexType(), boxChar); mlir::Value addr = unboxed.getResult(0); mlir::Value len = unboxed.getResult(1); if (auto varIface = boxChar.getDefiningOp<fir::FortranVariableOpInterface>()) @@ -278,8 +278,9 @@ hlfir::genDeclare(mlir::Location loc, fir::FirOpBuilder &builder, box.nonDeferredLenParams().end()); }, [](const auto &) {}); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, base, name, shapeOrShift, lenParams, dummyScope, flags, dataAttr); + auto declareOp = + hlfir::DeclareOp::create(builder, loc, base, name, shapeOrShift, + lenParams, dummyScope, flags, dataAttr); return mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation()); } @@ -312,12 +313,12 @@ hlfir::genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder, genLengthParameters(loc, builder, value, lenParams); if (attr) { assert(name.empty() && "It attribute is provided, no-name is expected"); - return builder.create<hlfir::AssociateOp>(loc, source, shape, lenParams, - fir::FortranVariableFlagsAttr{}, - llvm::ArrayRef{*attr}); + return hlfir::AssociateOp::create(builder, loc, source, shape, lenParams, + fir::FortranVariableFlagsAttr{}, + llvm::ArrayRef{*attr}); } - return builder.create<hlfir::AssociateOp>(loc, source, name, shape, lenParams, - fir::FortranVariableFlagsAttr{}); + return hlfir::AssociateOp::create(builder, loc, source, name, shape, + lenParams, fir::FortranVariableFlagsAttr{}); } mlir::Value hlfir::genVariableRawAddress(mlir::Location loc, @@ -326,12 +327,12 @@ mlir::Value hlfir::genVariableRawAddress(mlir::Location loc, assert(var.isVariable() && "only address of variables can be taken"); mlir::Value baseAddr = var.getFirBase(); if (var.isMutableBox()) - baseAddr = builder.create<fir::LoadOp>(loc, baseAddr); + baseAddr = fir::LoadOp::create(builder, loc, baseAddr); // Get raw address. if (mlir::isa<fir::BoxCharType>(var.getType())) baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr(); if (mlir::isa<fir::BaseBoxType>(baseAddr.getType())) - baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr); + baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); return baseAddr; } @@ -350,8 +351,8 @@ mlir::Value hlfir::genVariableBoxChar(mlir::Location loc, fir::BoxCharType::get(builder.getContext(), charType.getFKind()); auto scalarAddr = builder.createConvert(loc, fir::ReferenceType::get(charType), addr); - return builder.create<fir::EmboxCharOp>(loc, boxCharType, scalarAddr, - lengths[0]); + return fir::EmboxCharOp::create(builder, loc, boxCharType, scalarAddr, + lengths[0]); } static hlfir::Entity changeBoxAttributes(mlir::Location loc, @@ -365,8 +366,8 @@ static hlfir::Entity changeBoxAttributes(mlir::Location loc, getNonDefaultLowerBounds(loc, builder, var); if (!lbounds.empty()) shift = builder.genShift(loc, lbounds); - auto rebox = builder.create<fir::ReboxOp>(loc, forceBoxType, var, shift, - /*slice=*/nullptr); + auto rebox = fir::ReboxOp::create(builder, loc, forceBoxType, var, shift, + /*slice=*/nullptr); return hlfir::Entity{rebox}; } @@ -404,9 +405,8 @@ hlfir::Entity hlfir::genVariableBox(mlir::Location loc, fir::ReferenceType::get(fir::unwrapRefType(forceBoxType.getEleTy())); addr = builder.createConvert(loc, baseType, addr); } - auto embox = - builder.create<fir::EmboxOp>(loc, boxType, addr, shape, - /*slice=*/mlir::Value{}, typeParams); + auto embox = fir::EmboxOp::create(builder, loc, boxType, addr, shape, + /*slice=*/mlir::Value{}, typeParams); return hlfir::Entity{embox.getResult()}; } @@ -416,7 +416,7 @@ hlfir::Entity hlfir::loadTrivialScalar(mlir::Location loc, entity = derefPointersAndAllocatables(loc, builder, entity); if (entity.isVariable() && entity.isScalar() && fir::isa_trivial(entity.getFortranElementType())) { - return Entity{builder.create<fir::LoadOp>(loc, entity)}; + return Entity{fir::LoadOp::create(builder, loc, entity)}; } return entity; } @@ -429,8 +429,8 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc, llvm::SmallVector<mlir::Value> lenParams; genLengthParameters(loc, builder, entity, lenParams); if (mlir::isa<hlfir::ExprType>(entity.getType())) - return hlfir::Entity{builder.create<hlfir::ApplyOp>( - loc, entity, oneBasedIndices, lenParams)}; + return hlfir::Entity{hlfir::ApplyOp::create(builder, loc, entity, + oneBasedIndices, lenParams)}; // Build hlfir.designate. The lower bounds may need to be added to // the oneBasedIndices since hlfir.designate expect indices // based on the array operand lower bounds. @@ -445,16 +445,16 @@ hlfir::Entity hlfir::getElementAt(mlir::Location loc, for (auto [oneBased, lb] : llvm::zip(oneBasedIndices, lbounds)) { auto lbIdx = builder.createConvert(loc, idxTy, lb); auto oneBasedIdx = builder.createConvert(loc, idxTy, oneBased); - auto shift = builder.create<mlir::arith::SubIOp>(loc, lbIdx, one); + auto shift = mlir::arith::SubIOp::create(builder, loc, lbIdx, one); mlir::Value index = - builder.create<mlir::arith::AddIOp>(loc, oneBasedIdx, shift); + mlir::arith::AddIOp::create(builder, loc, oneBasedIdx, shift); indices.push_back(index); } - designate = builder.create<hlfir::DesignateOp>(loc, resultType, entity, - indices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + indices, lenParams); } else { - designate = builder.create<hlfir::DesignateOp>(loc, resultType, entity, - oneBasedIndices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + oneBasedIndices, lenParams); } return mlir::cast<fir::FortranVariableOpInterface>(designate.getOperation()); } @@ -467,8 +467,8 @@ static mlir::Value genUBound(mlir::Location loc, fir::FirOpBuilder &builder, return extent; extent = builder.createConvert(loc, one.getType(), extent); lb = builder.createConvert(loc, one.getType(), lb); - auto add = builder.create<mlir::arith::AddIOp>(loc, lb, extent); - return builder.create<mlir::arith::SubIOp>(loc, add, one); + auto add = mlir::arith::AddIOp::create(builder, loc, lb, extent); + return mlir::arith::SubIOp::create(builder, loc, add, one); } llvm::SmallVector<std::pair<mlir::Value, mlir::Value>> @@ -557,8 +557,8 @@ static mlir::Value computeVariableExtent(mlir::Location loc, assert(mlir::isa<fir::BaseBoxType>(variable.getType()) && "array variable with dynamic extent must be boxed"); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - variable, dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + variable, dimVal); return dimInfo.getExtent(); } llvm::SmallVector<mlir::Value> getVariableExtents(mlir::Location loc, @@ -608,14 +608,14 @@ mlir::Value hlfir::genShape(mlir::Location loc, fir::FirOpBuilder &builder, return shape; if (mlir::isa<fir::ShapeShiftType>(shape.getType())) if (auto s = shape.getDefiningOp<fir::ShapeShiftOp>()) - return builder.create<fir::ShapeOp>(loc, s.getExtents()); + return fir::ShapeOp::create(builder, loc, s.getExtents()); } if (mlir::isa<hlfir::ExprType>(entity.getType())) - return builder.create<hlfir::ShapeOfOp>(loc, entity.getBase()); + return hlfir::ShapeOfOp::create(builder, loc, entity.getBase()); // There is no shape lying around for this entity. Retrieve the extents and // build a new fir.shape. - return builder.create<fir::ShapeOp>(loc, - getVariableExtents(loc, builder, entity)); + return fir::ShapeOp::create(builder, loc, + getVariableExtents(loc, builder, entity)); } llvm::SmallVector<mlir::Value> @@ -668,7 +668,7 @@ mlir::Value hlfir::genLBound(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type idxTy = builder.getIndexType(); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, entity, dimVal); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, entity, dimVal); return dimInfo.getLowerBound(); } @@ -708,7 +708,7 @@ void hlfir::genLengthParameters(mlir::Location loc, fir::FirOpBuilder &builder, return; } if (entity.isCharacter()) { - result.push_back(builder.create<hlfir::GetLengthOp>(loc, expr)); + result.push_back(hlfir::GetLengthOp::create(builder, loc, expr)); return; } TODO(loc, "inquire PDTs length parameters of hlfir.expr"); @@ -735,7 +735,7 @@ mlir::Value hlfir::genRank(mlir::Location loc, fir::FirOpBuilder &builder, return builder.createIntegerConstant(loc, resultType, entity.getRank()); assert(entity.isBoxAddressOrValue() && "assumed-ranks are box addresses or values"); - return builder.create<fir::BoxRankOp>(loc, resultType, entity); + return fir::BoxRankOp::create(builder, loc, resultType, entity); } // Return a "shape" that can be used in fir.embox/fir.rebox with \p exv base. @@ -796,20 +796,20 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity) { if (entity.isMutableBox()) { - hlfir::Entity boxLoad{builder.create<fir::LoadOp>(loc, entity)}; + hlfir::Entity boxLoad{fir::LoadOp::create(builder, loc, entity)}; if (entity.isScalar()) { if (!entity.isPolymorphic() && !entity.hasLengthParameters()) - return hlfir::Entity{builder.create<fir::BoxAddrOp>(loc, boxLoad)}; + return hlfir::Entity{fir::BoxAddrOp::create(builder, loc, boxLoad)}; mlir::Type elementType = boxLoad.getFortranElementType(); if (auto charType = mlir::dyn_cast<fir::CharacterType>(elementType)) { - mlir::Value base = builder.create<fir::BoxAddrOp>(loc, boxLoad); + mlir::Value base = fir::BoxAddrOp::create(builder, loc, boxLoad); if (charType.hasConstantLen()) return hlfir::Entity{base}; mlir::Value len = genCharacterVariableLength(loc, builder, entity); auto boxCharType = fir::BoxCharType::get(builder.getContext(), charType.getFKind()); return hlfir::Entity{ - builder.create<fir::EmboxCharOp>(loc, boxCharType, base, len) + fir::EmboxCharOp::create(builder, loc, boxCharType, base, len) .getResult()}; } } @@ -819,7 +819,7 @@ hlfir::Entity hlfir::derefPointersAndAllocatables(mlir::Location loc, // information. Keep them boxed. return boxLoad; } else if (entity.isProcedurePointer()) { - return hlfir::Entity{builder.create<fir::LoadOp>(loc, entity)}; + return hlfir::Entity{fir::LoadOp::create(builder, loc, entity)}; } return entity; } @@ -870,8 +870,8 @@ hlfir::ElementalOp hlfir::genElementalOp( mlir::Value polymorphicMold, mlir::Type exprType) { if (!exprType) exprType = getArrayExprType(elementType, shape, !!polymorphicMold); - auto elementalOp = builder.create<hlfir::ElementalOp>( - loc, exprType, shape, polymorphicMold, typeParams, isUnordered); + auto elementalOp = hlfir::ElementalOp::create( + builder, loc, exprType, shape, polymorphicMold, typeParams, isUnordered); auto insertPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(elementalOp.getBody()); mlir::Value elementResult = genKernel(loc, builder, elementalOp.getIndices()); @@ -881,7 +881,7 @@ hlfir::ElementalOp hlfir::genElementalOp( // here. if (fir::isa_trivial(elementResult.getType())) elementResult = builder.createConvert(loc, elementType, elementResult); - builder.create<hlfir::YieldElementOp>(loc, elementResult); + hlfir::YieldElementOp::create(builder, loc, elementResult); builder.restoreInsertionPoint(insertPt); return elementalOp; } @@ -948,10 +948,10 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, mlir::OpBuilder::InsertionGuard guard(builder); loopNest.oneBasedIndices.assign(extents.size(), mlir::Value{}); // Build loop nest from column to row. - auto one = builder.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); mlir::Type indexType = builder.getIndexType(); if (emitWorkshareLoop) { - auto wslw = builder.create<mlir::omp::WorkshareLoopWrapperOp>(loc); + auto wslw = mlir::omp::WorkshareLoopWrapperOp::create(builder, loc); loopNest.outerOp = wslw; builder.createBlock(&wslw.getRegion()); mlir::omp::LoopNestOperands lnops; @@ -961,12 +961,12 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, lnops.loopUpperBounds.push_back(extent); lnops.loopSteps.push_back(one); } - auto lnOp = builder.create<mlir::omp::LoopNestOp>(loc, lnops); + auto lnOp = mlir::omp::LoopNestOp::create(builder, loc, lnops); mlir::Block *block = builder.createBlock(&lnOp.getRegion()); for (auto extent : llvm::reverse(extents)) block->addArgument(extent.getType(), extent.getLoc()); loopNest.body = block; - builder.create<mlir::omp::YieldOp>(loc); + mlir::omp::YieldOp::create(builder, loc); for (unsigned dim = 0; dim < extents.size(); dim++) loopNest.oneBasedIndices[extents.size() - dim - 1] = lnOp.getRegion().front().getArgument(dim); @@ -975,7 +975,7 @@ hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, for (auto extent : llvm::reverse(extents)) { auto ub = builder.createConvert(loc, indexType, extent); auto doLoop = - builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered); + fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered); if (!couldVectorize) { mlir::LLVM::LoopVectorizeAttr va{mlir::LLVM::LoopVectorizeAttr::get( builder.getContext(), @@ -1002,7 +1002,7 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( bool isUnordered) { assert(!extents.empty() && "must have at least one extent"); // Build loop nest from column to row. - auto one = builder.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); mlir::Type indexType = builder.getIndexType(); unsigned dim = extents.size() - 1; fir::DoLoopOp outerLoop = nullptr; @@ -1018,16 +1018,15 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( // of its parent loop. fir::DoLoopOp doLoop; if (!parentLoop) { - doLoop = builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered, - /*finalCountValue=*/false, - reductionInits); + doLoop = fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered, + /*finalCountValue=*/false, reductionInits); } else { - doLoop = builder.create<fir::DoLoopOp>(loc, one, ub, one, isUnordered, - /*finalCountValue=*/false, - parentLoop.getRegionIterArgs()); + doLoop = fir::DoLoopOp::create(builder, loc, one, ub, one, isUnordered, + /*finalCountValue=*/false, + parentLoop.getRegionIterArgs()); if (!reductionInits.empty()) { // Return the results of the child loop from its parent loop. - builder.create<fir::ResultOp>(loc, doLoop.getResults()); + fir::ResultOp::create(builder, loc, doLoop.getResults()); } } @@ -1044,7 +1043,7 @@ llvm::SmallVector<mlir::Value> hlfir::genLoopNestWithReductions( genBody(loc, builder, oneBasedIndices, parentLoop.getRegionIterArgs()); builder.setInsertionPointToEnd(parentLoop.getBody()); if (!reductionValues.empty()) - builder.create<fir::ResultOp>(loc, reductionValues); + fir::ResultOp::create(builder, loc, reductionValues); builder.setInsertionPointAfter(outerLoop); return outerLoop->getResults(); } @@ -1057,18 +1056,18 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, // Evaluate in some region that will be moved into the actual ifOp (the actual // ifOp can only be created when the result types are known). - auto badIfOp = builder.create<fir::IfOp>(loc, condition.getType(), condition, - /*withElseRegion=*/false); + auto badIfOp = fir::IfOp::create(builder, loc, condition.getType(), condition, + /*withElseRegion=*/false); mlir::Block *preparationBlock = &badIfOp.getThenRegion().front(); builder.setInsertionPointToStart(preparationBlock); fir::ExtendedValue result = genIfTrue(); fir::ResultOp resultOp = result.match( [&](const fir::CharBoxValue &box) -> fir::ResultOp { - return builder.create<fir::ResultOp>( - loc, mlir::ValueRange{box.getAddr(), box.getLen()}); + return fir::ResultOp::create( + builder, loc, mlir::ValueRange{box.getAddr(), box.getLen()}); }, [&](const mlir::Value &addr) -> fir::ResultOp { - return builder.create<fir::ResultOp>(loc, addr); + return fir::ResultOp::create(builder, loc, addr); }, [&](const auto &) -> fir::ResultOp { TODO(loc, "unboxing non scalar optional fir.box"); @@ -1077,8 +1076,8 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, // Create actual fir.if operation. auto ifOp = - builder.create<fir::IfOp>(loc, resultOp->getOperandTypes(), condition, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultOp->getOperandTypes(), condition, + /*withElseRegion=*/true); // Move evaluation into Then block, preparationBlock->moveBefore(&ifOp.getThenRegion().back()); ifOp.getThenRegion().back().erase(); @@ -1087,11 +1086,11 @@ conditionallyEvaluate(mlir::Location loc, fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> absentValues; for (mlir::Type resTy : ifOp->getResultTypes()) { if (fir::isa_ref_type(resTy) || fir::isa_box_type(resTy)) - absentValues.emplace_back(builder.create<fir::AbsentOp>(loc, resTy)); + absentValues.emplace_back(fir::AbsentOp::create(builder, loc, resTy)); else - absentValues.emplace_back(builder.create<fir::ZeroOp>(loc, resTy)); + absentValues.emplace_back(fir::ZeroOp::create(builder, loc, resTy)); } - builder.create<fir::ResultOp>(loc, absentValues); + fir::ResultOp::create(builder, loc, absentValues); badIfOp->erase(); // Build fir::ExtendedValue from the result values. @@ -1139,8 +1138,8 @@ static fir::ExtendedValue translateVariableToExtendedValue( } if (variable.mayBeOptional()) { if (!keepScalarOptionalBoxed && variable.isScalar()) { - mlir::Value isPresent = builder.create<fir::IsPresentOp>( - loc, builder.getI1Type(), variable); + mlir::Value isPresent = fir::IsPresentOp::create( + builder, loc, builder.getI1Type(), variable); return conditionallyEvaluate( loc, builder, isPresent, [&]() -> fir::ExtendedValue { mlir::Value base = genVariableRawAddress(loc, builder, variable); @@ -1249,7 +1248,7 @@ static fir::ExtendedValue placeTrivialInMemory(mlir::Location loc, if (targetType != val.getType()) builder.createStoreWithConvert(loc, val, temp); else - builder.create<fir::StoreOp>(loc, val, temp); + fir::StoreOp::create(builder, loc, val, temp); return temp; } @@ -1369,8 +1368,8 @@ hlfir::createTempFromMold(mlir::Location loc, fir::FirOpBuilder &builder, llvm::ArrayRef<mlir::Value> typeParams, fir::FortranVariableFlagsAttr attrs) -> mlir::Value { auto declareOp = - builder.create<hlfir::DeclareOp>(loc, memref, name, shape, typeParams, - /*dummy_scope=*/nullptr, attrs); + hlfir::DeclareOp::create(builder, loc, memref, name, shape, typeParams, + /*dummy_scope=*/nullptr, attrs); return declareOp.getBase(); }; @@ -1406,8 +1405,8 @@ hlfir::Entity hlfir::createStackTempFromMold(mlir::Location loc, /*shape=*/{}, lenParams); } auto declareOp = - builder.create<hlfir::DeclareOp>(loc, alloc, tmpName, shape, lenParams, - /*dummy_scope=*/nullptr, declAttrs); + hlfir::DeclareOp::create(builder, loc, alloc, tmpName, shape, lenParams, + /*dummy_scope=*/nullptr, declAttrs); return hlfir::Entity{declareOp.getBase()}; } @@ -1422,8 +1421,8 @@ hlfir::convertCharacterKind(mlir::Location loc, fir::FirOpBuilder &builder, if (src.second.has_value()) src.second.value()(); - return hlfir::EntityWithAttributes{builder.create<hlfir::DeclareOp>( - loc, res.getAddr(), ".temp.kindconvert", /*shape=*/nullptr, + return hlfir::EntityWithAttributes{hlfir::DeclareOp::create( + builder, loc, res.getAddr(), ".temp.kindconvert", /*shape=*/nullptr, /*typeparams=*/mlir::ValueRange{res.getLen()}, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{})}; } @@ -1494,10 +1493,10 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder, } auto shapeShiftType = fir::ShapeShiftType::get(builder.getContext(), rank); mlir::Value shapeShift = - builder.create<fir::ShapeShiftOp>(loc, shapeShiftType, lbAndExtents); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, associate.getFirBase(), *associate.getUniqName(), shapeShift, - associate.getTypeparams(), /*dummy_scope=*/nullptr, + fir::ShapeShiftOp::create(builder, loc, shapeShiftType, lbAndExtents); + auto declareOp = hlfir::DeclareOp::create( + builder, loc, associate.getFirBase(), *associate.getUniqName(), + shapeShift, associate.getTypeparams(), /*dummy_scope=*/nullptr, /*flags=*/fir::FortranVariableFlagsAttr{}); hlfir::Entity castWithLbounds = mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation()); @@ -1536,8 +1535,8 @@ std::pair<hlfir::Entity, bool> hlfir::computeEvaluateOpInNewTemp( extents, typeParams); mlir::Value innerMemory = evalInMem.getMemory(); temp = builder.createConvert(loc, innerMemory.getType(), temp); - auto declareOp = builder.create<hlfir::DeclareOp>( - loc, temp, tmpName, shape, typeParams, + auto declareOp = hlfir::DeclareOp::create( + builder, loc, temp, tmpName, shape, typeParams, /*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{}); computeEvaluateOpIn(loc, builder, evalInMem, declareOp.getOriginalBase()); return {hlfir::Entity{declareOp.getBase()}, /*heapAllocated=*/heapAllocated}; @@ -1601,7 +1600,7 @@ hlfir::Entity hlfir::gen1DSection(mlir::Location loc, } } mlir::Value sectionShape = - builder.create<fir::ShapeOp>(loc, extents[dim - 1]); + fir::ShapeOp::create(builder, loc, extents[dim - 1]); // The result type is one of: // !fir.box/class<!fir.array<NxT>> @@ -1617,9 +1616,9 @@ hlfir::Entity hlfir::gen1DSection(mlir::Location loc, fir::SequenceType::get({dimExtent}, seqType.getEleTy()); sectionType = fir::wrapInClassOrBoxType(sectionType, array.isPolymorphic()); - auto designate = builder.create<hlfir::DesignateOp>( - loc, sectionType, array, /*component=*/"", /*componentShape=*/nullptr, - subscripts, + auto designate = hlfir::DesignateOp::create( + builder, loc, sectionType, array, /*component=*/"", + /*componentShape=*/nullptr, subscripts, /*substring=*/mlir::ValueRange{}, /*complexPartAttr=*/std::nullopt, sectionShape, typeParams); return hlfir::Entity{designate.getResult()}; diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index d77a656..323d2fe 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -1110,7 +1110,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, // was just created from user functions with the same name. funcOp->setAttr(fir::FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr()); - auto libCall = builder.create<fir::CallOp>(loc, funcOp, args); + auto libCall = fir::CallOp::create(builder, loc, funcOp, args); // TODO: ensure 'strictfp' setting on the call for "precise/strict" // FP mode. Set appropriate Fast-Math Flags otherwise. // TODO: we should also mark as many libm function as possible @@ -1124,7 +1124,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type soughtFuncType = funcOp.getFunctionType(); if (soughtFuncType == libFuncType) { - libCall = builder.create<fir::CallOp>(loc, funcOp, args); + libCall = fir::CallOp::create(builder, loc, funcOp, args); } else { // A function with the same name might have been declared // before (e.g. with an explicit interface and a binding label). @@ -1138,13 +1138,13 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::Twine("' may lead to undefined behavior."))); mlir::SymbolRefAttr funcSymbolAttr = builder.getSymbolRefAttr(libFuncName); mlir::Value funcPointer = - builder.create<fir::AddrOfOp>(loc, soughtFuncType, funcSymbolAttr); + fir::AddrOfOp::create(builder, loc, soughtFuncType, funcSymbolAttr); funcPointer = builder.createConvert(loc, libFuncType, funcPointer); llvm::SmallVector<mlir::Value, 3> operands{funcPointer}; operands.append(args.begin(), args.end()); - libCall = builder.create<fir::CallOp>(loc, mlir::SymbolRefAttr{}, - libFuncType.getResults(), operands); + libCall = fir::CallOp::create(builder, loc, mlir::SymbolRefAttr{}, + libFuncType.getResults(), operands); } LLVM_DEBUG(libCall.dump(); llvm::dbgs() << "\n"); @@ -1220,7 +1220,7 @@ mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc, LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); } LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n"); return result; @@ -1258,12 +1258,12 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc, // the argument types for an operation if constexpr (T::template hasTrait< mlir::OpTrait::SameOperandsAndResultType>()) { - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } else { auto complexTy = mlir::cast<mlir::ComplexType>(mathLibFuncType.getInput(0)); auto realTy = complexTy.getElementType(); - result = builder.create<T>(loc, realTy, args); + result = T::create(builder, loc, realTy, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } @@ -2461,7 +2461,7 @@ IntrinsicLibrary::outlineInWrapper(GeneratorType generator, nameOS << '.' << fmfString; } mlir::func::FuncOp wrapper = getWrapper(generator, funcName, funcType); - return builder.create<fir::CallOp>(loc, wrapper, args).getResult(0); + return fir::CallOp::create(builder, loc, wrapper, args).getResult(0); } template <typename GeneratorType> @@ -2477,7 +2477,7 @@ fir::ExtendedValue IntrinsicLibrary::outlineInExtendedWrapper( mlirArgs.emplace_back(toValue(extendedVal, builder, loc)); mlir::FunctionType funcType = getFunctionType(resultType, mlirArgs, builder); mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); - auto call = builder.create<fir::CallOp>(loc, wrapper, mlirArgs); + auto call = fir::CallOp::create(builder, loc, wrapper, mlirArgs); if (resultType) return toExtendedValue(call.getResult(0), builder, loc); // Subroutine calls @@ -2595,9 +2595,9 @@ IntrinsicLibrary::readAndAddCleanUp(fir::MutableBoxValue resultMutableBox, return box; }, [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { - auto load = builder.create<fir::LoadOp>(loc, resultType, tempAddr); + auto load = fir::LoadOp::create(builder, loc, resultType, tempAddr); // Temp can be freed right away since it was loaded. - builder.create<fir::FreeMemOp>(loc, tempAddr); + fir::FreeMemOp::create(builder, loc, tempAddr); return load; }, [&](const fir::CharBoxValue &box) -> fir::ExtendedValue { @@ -2650,9 +2650,9 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, // So, implement abs here without branching. mlir::Value shift = builder.createIntegerConstant(loc, intType, intType.getWidth() - 1); - auto mask = builder.create<mlir::arith::ShRSIOp>(loc, arg, shift); - auto xored = builder.create<mlir::arith::XOrIOp>(loc, arg, mask); - return builder.create<mlir::arith::SubIOp>(loc, xored, mask); + auto mask = mlir::arith::ShRSIOp::create(builder, loc, arg, shift); + auto xored = mlir::arith::XOrIOp::create(builder, loc, arg, mask); + return mlir::arith::SubIOp::create(builder, loc, xored, mask); } llvm_unreachable("unexpected type in ABS argument"); } @@ -2671,7 +2671,7 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ADJUSTL & ADJUSTR @@ -2824,7 +2824,7 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ATAND, ATAN2D @@ -2838,8 +2838,8 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, // atand = atan * 180/pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2849,7 +2849,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } // ATANPI, ATAN2PI @@ -2863,8 +2863,8 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, // atanpi = atan / pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2874,7 +2874,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, @@ -2882,8 +2882,8 @@ static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, mlir::Value arg1) { auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); arg0 = builder.createConvert(loc, llvmPointerType, arg0); - return builder.create<mlir::LLVM::AtomicRMWOp>( - loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); + return mlir::LLVM::AtomicRMWOp::create(builder, loc, binOp, arg0, arg1, + mlir::LLVM::AtomicOrdering::seq_cst); } mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, @@ -2941,11 +2941,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, auto bitCastFloat = [&](mlir::Value arg) -> mlir::Value { if (mlir::isa<mlir::Float32Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI32Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI32Type(), + arg); if (mlir::isa<mlir::Float64Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI64Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI64Type(), + arg); return arg; }; @@ -2958,11 +2958,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, } auto address = - builder.create<mlir::UnrealizedConversionCastOp>(loc, llvmPtrTy, arg0) + mlir::UnrealizedConversionCastOp::create(builder, loc, llvmPtrTy, arg0) .getResult(0); - auto cmpxchg = builder.create<mlir::LLVM::AtomicCmpXchgOp>( - loc, address, arg1, arg2, successOrdering, failureOrdering); - return builder.create<mlir::LLVM::ExtractValueOp>(loc, cmpxchg, 1); + auto cmpxchg = mlir::LLVM::AtomicCmpXchgOp::create( + builder, loc, address, arg1, arg2, successOrdering, failureOrdering); + return mlir::LLVM::ExtractValueOp::create(builder, loc, cmpxchg, 1); } mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, @@ -3038,31 +3038,31 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::isa<fir::BoxProcType>(ptrTy))) { mlir::Value pointerBoxProc = fir::isBoxProcAddressType(ptrTy) - ? builder.create<fir::LoadOp>(loc, fir::getBase(args[0])) + ? fir::LoadOp::create(builder, loc, fir::getBase(args[0])) : fir::getBase(args[0]); mlir::Value pointerTarget = - builder.create<fir::BoxAddrOp>(loc, pointerBoxProc); + fir::BoxAddrOp::create(builder, loc, pointerBoxProc); if (isStaticallyAbsent(args[1])) return builder.genIsNotNullAddr(loc, pointerTarget); mlir::Value target = fir::getBase(args[1]); if (fir::isBoxProcAddressType(target.getType())) - target = builder.create<fir::LoadOp>(loc, target); + target = fir::LoadOp::create(builder, loc, target); if (mlir::isa<fir::BoxProcType>(target.getType())) - target = builder.create<fir::BoxAddrOp>(loc, target); + target = fir::BoxAddrOp::create(builder, loc, target); mlir::Type intPtrTy = builder.getIntPtrType(); mlir::Value pointerInt = builder.createConvert(loc, intPtrTy, pointerTarget); mlir::Value targetInt = builder.createConvert(loc, intPtrTy, target); - mlir::Value sameTarget = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); + mlir::Value sameTarget = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); mlir::Value zero = builder.createIntegerConstant(loc, intPtrTy, 0); - mlir::Value notNull = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); + mlir::Value notNull = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); // The not notNull test covers the following two cases: // - TARGET is a procedure that is OPTIONAL and absent at runtime. // - TARGET is a procedure pointer that is NULL. // In both cases, ASSOCIATED should be false if POINTER is NULL. - return builder.create<mlir::arith::AndIOp>(loc, sameTarget, notNull); + return mlir::arith::AndIOp::create(builder, loc, sameTarget, notNull); } auto *pointer = args[0].match([&](const fir::MutableBoxValue &x) { return &x; }, @@ -3075,7 +3075,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::Value targetBox = builder.createBox(loc, target); mlir::Value pointerBoxRef = fir::factory::getMutableIRBox(builder, loc, *pointer); - auto pointerBox = builder.create<fir::LoadOp>(loc, pointerBoxRef); + auto pointerBox = fir::LoadOp::create(builder, loc, pointerBoxRef); return fir::runtime::genAssociated(builder, loc, pointerBox, targetBox); } @@ -3106,12 +3106,12 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselJnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3123,7 +3123,7 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_JN(n2) and BESSEL_JN(n2 - 1) since they // are the anchors of the recursion. - mlir::Value n2_1 = builder.create<mlir::arith::SubIOp>(loc, n2, one); + mlir::Value n2_1 = mlir::arith::SubIOp::create(builder, loc, n2, one); mlir::Value bn2 = genRuntimeCall("bessel_jn", resultType, {n2, x}); mlir::Value bn2_1 = genRuntimeCall("bessel_jn", resultType, {n2_1, x}); fir::runtime::genBesselJn(builder, loc, resultBox, n1, n2, x, bn2, bn2_1); @@ -3191,12 +3191,12 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselYnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3208,7 +3208,7 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_YN(n1) and BESSEL_YN(n1 + 1) since they // are the anchors of the recursion. - mlir::Value n1_1 = builder.create<mlir::arith::AddIOp>(loc, n1, one); + mlir::Value n1_1 = mlir::arith::AddIOp::create(builder, loc, n1, one); mlir::Value bn1 = genRuntimeCall("bessel_yn", resultType, {n1, x}); mlir::Value bn1_1 = genRuntimeCall("bessel_yn", resultType, {n1_1, x}); fir::runtime::genBesselYn(builder, loc, resultBox, n1, n2, x, bn1, bn1_1); @@ -3280,12 +3280,12 @@ IntrinsicLibrary::genBitwiseCompare(mlir::Type resultType, if (arg0Ty.isUnsignedInteger()) arg0 = builder.createConvert(loc, signlessType, arg0); else if (bits0 < widest) - arg0 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg0); + arg0 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg0); if (arg1Ty.isUnsignedInteger()) arg1 = builder.createConvert(loc, signlessType, arg1); else if (bits1 < widest) - arg1 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg1); - return builder.create<mlir::arith::CmpIOp>(loc, pred, arg0, arg1); + arg1 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg1); + return mlir::arith::CmpIOp::create(builder, loc, pred, arg0, arg1); } // BTEST @@ -3304,9 +3304,9 @@ mlir::Value IntrinsicLibrary::genBtest(mlir::Type resultType, word = builder.createConvert(loc, signlessType, word); mlir::Value shiftCount = builder.createConvert(loc, signlessType, args[1]); mlir::Value shifted = - builder.create<mlir::arith::ShRUIOp>(loc, word, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, word, shiftCount); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); - mlir::Value bit = builder.create<mlir::arith::AndIOp>(loc, shifted, one); + mlir::Value bit = mlir::arith::AndIOp::create(builder, loc, shifted, one); return builder.createConvert(loc, resultType, bit); } @@ -3317,11 +3317,11 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder, mlir::Value addr{nullptr}; if (isFunc) { auto funcTy = mlir::cast<fir::BoxProcType>(argValue.getType()).getEleTy(); - addr = builder.create<fir::BoxAddrOp>(loc, funcTy, argValue); + addr = fir::BoxAddrOp::create(builder, loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf<fir::BoxValue>(); - addr = builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), - fir::getBase(*box)); + addr = fir::BoxAddrOp::create(builder, loc, box->getMemTy(), + fir::getBase(*box)); } return addr; } @@ -3331,7 +3331,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args, bool isFunc = false, bool isDevLoc = false) { assert(args.size() == 1); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Value resAddr; if (isDevLoc) resAddr = fir::factory::genCDevPtrAddr(builder, loc, res, resultType); @@ -3342,7 +3342,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value argAddrVal = builder.createConvert( loc, fir::unwrapRefType(resAddr.getType()), argAddr); - builder.create<fir::StoreOp>(loc, argAddrVal, resAddr); + fir::StoreOp::create(builder, loc, argAddrVal, resAddr); return res; } @@ -3355,8 +3355,8 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtrVal1 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr1); mlir::Value zero = builder.createIntegerConstant(loc, cPtrVal1.getType(), 0); - mlir::Value res = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); + mlir::Value res = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); if (isStaticallyPresent(args[1])) { mlir::Type i1Ty = builder.getI1Type(); @@ -3365,15 +3365,16 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, res = builder .genIfOp(loc, {i1Ty}, isDynamicallyAbsent, /*withElseRegion=*/true) - .genThen([&]() { builder.create<fir::ResultOp>(loc, res); }) + .genThen([&]() { fir::ResultOp::create(builder, loc, res); }) .genElse([&]() { mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); - mlir::Value cmpVal = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, cPtrVal2); + mlir::Value cmpVal = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, + cPtrVal2); mlir::Value newRes = - builder.create<mlir::arith::AndIOp>(loc, res, cmpVal); - builder.create<fir::ResultOp>(loc, newRes); + mlir::arith::AndIOp::create(builder, loc, res, cmpVal); + fir::ResultOp::create(builder, loc, newRes); }) .getResults()[0]; } @@ -3428,9 +3429,9 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type idxType = builder.getIndexType(); for (int i = 0; i < arrayRank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxType, i); - mlir::Value var = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(shapeElementType), shape, index); - mlir::Value load = builder.create<fir::LoadOp>(loc, var); + mlir::Value var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(shapeElementType), shape, index); + mlir::Value load = fir::LoadOp::create(builder, loc, var); extents.push_back(builder.createConvert(loc, idxType, load)); } } @@ -3474,8 +3475,8 @@ void IntrinsicLibrary::genCFProcPointer( mlir::Value cptrCast = builder.createConvert(loc, boxProcType.getEleTy(), cptr); mlir::Value cptrBox = - builder.create<fir::EmboxProcOp>(loc, boxProcType, cptrCast); - builder.create<fir::StoreOp>(loc, cptrBox, fptr); + fir::EmboxProcOp::create(builder, loc, boxProcType, cptrCast); + fir::StoreOp::create(builder, loc, cptrBox, fptr); } // C_FUNLOC @@ -3505,7 +3506,7 @@ IntrinsicLibrary::genCPtrCompare(mlir::Type resultType, mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); mlir::Value cmp = - builder.create<mlir::arith::CmpIOp>(loc, pred, cPtrVal1, cPtrVal2); + mlir::arith::CmpIOp::create(builder, loc, pred, cPtrVal1, cPtrVal2); return builder.createConvert(loc, resultType, cmp); } @@ -3604,7 +3605,7 @@ mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType, mlir::Value cplx = args[0]; auto imag = fir::factory::Complex{builder, loc}.extractComplexPart( cplx, /*isImagPart=*/true); - auto negImag = builder.create<mlir::arith::NegFOp>(loc, imag); + auto negImag = mlir::arith::NegFOp::create(builder, loc, imag); return fir::factory::Complex{builder, loc}.insertComplexPart( cplx, negImag, /*isImagPart=*/true); } @@ -3620,7 +3621,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3635,7 +3636,7 @@ mlir::Value IntrinsicLibrary::genCospi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3696,7 +3697,7 @@ void IntrinsicLibrary::genCpuTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value res1 = fir::runtime::genCpuTime(builder, loc); mlir::Value res2 = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg->getType()), res1); - builder.create<fir::StoreOp>(loc, res2, *arg); + fir::StoreOp::create(builder, loc, res2, *arg); } // CSHIFT @@ -3723,7 +3724,7 @@ IntrinsicLibrary::genCshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar CSHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genCshiftVector(builder, loc, resultIrBox, array, shift); } else { @@ -3749,9 +3750,9 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, assert(args.size() == 1); mlir::Type resTy = fir::SequenceType::get(extent, resultType); mlir::Value arg = fir::getBase(args[0]); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resTy); + mlir::Value res = fir::AllocaOp::create(builder, loc, resTy); if (mlir::isa<fir::BaseBoxType>(arg.getType())) - arg = builder.create<fir::BoxAddrOp>(loc, arg); + arg = fir::BoxAddrOp::create(builder, loc, arg); mlir::Type refResTy = fir::ReferenceType::get(resTy); mlir::FunctionType ftype = mlir::FunctionType::get(arg.getContext(), {refResTy, refResTy}, {}); @@ -3759,7 +3760,7 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, llvm::SmallVector<mlir::Value> funcArgs; funcArgs.push_back(res); funcArgs.push_back(arg); - builder.create<fir::CallOp>(loc, funcOp, funcArgs); + fir::CallOp::create(builder, loc, funcOp, funcArgs); mlir::Value ext = builder.createIntegerConstant(loc, builder.getIndexType(), extent); return fir::ArrayBoxValue(res, {ext}); @@ -3775,8 +3776,8 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value values = fir::getBase(args[3]); if (!values) - values = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())); + values = fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())); fir::runtime::genDateAndTime(builder, loc, charArgs[0], charArgs[1], charArgs[2], values); @@ -3788,17 +3789,17 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, assert(args.size() == 2); if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto diff = builder.create<mlir::arith::SubIOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubIOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } assert(fir::isa_real(resultType) && "Only expects real and integer in DIM"); mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - auto diff = builder.create<mlir::arith::SubFOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubFOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } // DOT_PRODUCT @@ -3816,12 +3817,13 @@ IntrinsicLibrary::genDotProduct(mlir::Type resultType, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } // This operation is only used to pass the result type // information to the DotProduct generator. - auto resultBox = builder.create<fir::AbsentOp>(loc, fir::BoxType::get(eleTy)); + auto resultBox = + fir::AbsentOp::create(builder, loc, fir::BoxType::get(eleTy)); return fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, resultBox); } @@ -3833,7 +3835,7 @@ mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType, "Result must be double precision in DPROD"); mlir::Value a = builder.createConvert(loc, resultType, args[0]); mlir::Value b = builder.createConvert(loc, resultType, args[1]); - return builder.create<mlir::arith::MulFOp>(loc, a, b); + return mlir::arith::MulFOp::create(builder, loc, a, b); } // DSHIFTL @@ -3856,14 +3858,14 @@ mlir::Value IntrinsicLibrary::genDshiftl(mlir::Type resultType, // Per the standard, the value of DSHIFTL(I, J, SHIFT) is equal to // IOR (SHIFTL(I, SHIFT), SHIFTR(J, BIT_SIZE(J) - SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, shift}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, diff}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3889,14 +3891,14 @@ mlir::Value IntrinsicLibrary::genDshiftr(mlir::Type resultType, // Per the standard, the value of DSHIFTR(I, J, SHIFT) is equal to // IOR (SHIFTL(I, BIT_SIZE(I) - SHIFT), SHIFTR(J, SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, diff}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, shift}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3924,8 +3926,8 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle optional BOUNDARY argument mlir::Value boundary = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())) : builder.createBox(loc, args[2]); if (arrayRank == 1) { @@ -3933,7 +3935,7 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar EOSHIFT SHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genEoshiftVector(builder, loc, resultIrBox, array, shift, boundary); } else { @@ -3981,14 +3983,15 @@ void IntrinsicLibrary::genExecuteCommandLine( .genIfOp(loc, {i1Ty}, waitIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto waitLoad = builder.create<fir::LoadOp>(loc, waitAddr); + auto waitLoad = + fir::LoadOp::create(builder, loc, waitAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, waitLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -3996,15 +3999,15 @@ void IntrinsicLibrary::genExecuteCommandLine( mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdstatBox = isStaticallyPresent(cmdstat) ? fir::getBase(cmdstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdmsgBox = isStaticallyPresent(cmdmsg) ? fir::getBase(cmdmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); } @@ -4025,7 +4028,7 @@ IntrinsicLibrary::genEtime(std::optional<mlir::Type> resultType, auto timeAddr = builder.createTemporary(loc, *resultType); auto timeBox = builder.createBox(loc, timeAddr); fir::runtime::genEtime(builder, loc, values, timeBox); - return builder.create<fir::LoadOp>(loc, timeAddr); + return fir::LoadOp::create(builder, loc, timeAddr); } else { // subroutine form mlir::Value time = fir::getBase(args[1]); @@ -4098,8 +4101,8 @@ IntrinsicLibrary::genFindloc(mlir::Type resultType, // Handle optional mask argument auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); // Handle optional kind argument @@ -4288,15 +4291,15 @@ void IntrinsicLibrary::genGetCommand(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value commandBox = isStaticallyPresent(command) ? fir::getBase(command) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommand(builder, loc, commandBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4355,15 +4358,15 @@ void IntrinsicLibrary::genGetCommandArgument( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommandArgument( builder, loc, number, valBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4408,13 +4411,14 @@ void IntrinsicLibrary::genGetEnvironmentVariable( .genIfOp(loc, {i1Ty}, trimNameIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto trimLoad = builder.create<fir::LoadOp>(loc, trimNameAddr); + auto trimLoad = + fir::LoadOp::create(builder, loc, trimNameAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, trimLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -4423,15 +4427,15 @@ void IntrinsicLibrary::genGetEnvironmentVariable( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetEnvVariable(builder, loc, name, valBox, lenBox, trim, errBox); if (isStaticallyPresent(status)) { @@ -4516,8 +4520,8 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -4531,10 +4535,10 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } - auto resultBox = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + auto resultBox = fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())); return func(builder, loc, array, mask, resultBox); } // Handle Product/Sum cases that have an array result. @@ -4581,8 +4585,8 @@ mlir::Value IntrinsicLibrary::genIbclr(mlir::Type resultType, mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value bit = builder.create<mlir::arith::ShLIOp>(loc, one, pos); - mlir::Value mask = builder.create<mlir::arith::XOrIOp>(loc, ones, bit); + mlir::Value bit = mlir::arith::ShLIOp::create(builder, loc, one, pos); + mlir::Value mask = mlir::arith::XOrIOp::create(builder, loc, ones, bit); return builder.createUnsigned<mlir::arith::AndIOp>(loc, resultType, args[0], mask); } @@ -4610,18 +4614,18 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(resultType).getWidth()); mlir::Value shiftCount = - builder.create<mlir::arith::SubIOp>(loc, bitSize, len); + mlir::arith::SubIOp::create(builder, loc, bitSize, len); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value mask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); mlir::Value res1 = builder.createUnsigned<mlir::arith::ShRSIOp>( loc, signlessType, word, pos); - mlir::Value res2 = builder.create<mlir::arith::AndIOp>(loc, res1, mask); - mlir::Value lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::Value res2 = mlir::arith::AndIOp::create(builder, loc, res1, mask); + mlir::Value lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, zero, res2); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, zero, res2); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -4640,7 +4644,7 @@ mlir::Value IntrinsicLibrary::genIbset(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>(loc, one, pos); + mlir::Value mask = mlir::arith::ShLIOp::create(builder, loc, one, pos); return builder.createUnsigned<mlir::arith::OrIOp>(loc, resultType, args[0], mask); } @@ -4674,13 +4678,13 @@ IntrinsicLibrary::genIchar(mlir::Type resultType, fir::CharacterType::get(builder.getContext(), eleType.getFKind(), 1); mlir::Type toTy = builder.getRefType(charType); mlir::Value cast = builder.createConvert(loc, toTy, buffer); - charVal = builder.create<fir::LoadOp>(loc, cast); + charVal = fir::LoadOp::create(builder, loc, cast); } LLVM_DEBUG(llvm::dbgs() << "ichar(" << charVal << ")\n"); auto code = helper.extractCodeFromSingleton(charVal); if (code.getType() == resultType) return code; - return builder.create<mlir::arith::ExtUIOp>(loc, resultType, code); + return mlir::arith::ExtUIOp::create(builder, loc, resultType, code); } // llvm floating point class intrinsic test values @@ -4710,7 +4714,7 @@ mlir::Value IntrinsicLibrary::genIsFPClass(mlir::Type resultType, assert(args.size() == 1); mlir::Type i1Ty = builder.getI1Type(); mlir::Value isfpclass = - builder.create<mlir::LLVM::IsFPClass>(loc, i1Ty, args[0], fpclass); + mlir::LLVM::IsFPClass::create(builder, loc, i1Ty, args[0], fpclass); return builder.createConvert(loc, resultType, isfpclass); } @@ -4725,7 +4729,7 @@ mlir::Value IntrinsicLibrary::genQNan(mlir::Type resultType) { void IntrinsicLibrary::genRaiseExcept(int excepts, mlir::Value cond) { fir::IfOp ifOp; if (cond) { - ifOp = builder.create<fir::IfOp>(loc, cond, /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, cond, /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } mlir::Type i32Ty = builder.getIntegerType(32); @@ -4746,11 +4750,11 @@ getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec, mlir::dyn_cast<fir::RecordType>(fir::unwrapPassByRefType(rec.getType())); assert(index < recType.getTypeList().size() && "not enough components"); auto [fieldName, fieldTy] = recType.getTypeList()[index]; - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(recType.getContext()), fieldName, recType, - fir::getTypeParams(rec)); - return {builder.create<fir::CoordinateOp>(loc, builder.getRefType(fieldTy), - rec, field), + mlir::Value field = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(recType.getContext()), fieldName, + recType, fir::getTypeParams(rec)); + return {fir::CoordinateOp::create(builder, loc, builder.getRefType(fieldTy), + rec, field), fieldTy}; } @@ -4763,9 +4767,9 @@ IntrinsicLibrary::genIeeeTypeCompare(mlir::Type resultType, assert(args.size() == 2); auto [leftRef, fieldTy] = getFieldRef(builder, loc, args[0]); auto [rightRef, ignore] = getFieldRef(builder, loc, args[1]); - mlir::Value left = builder.create<fir::LoadOp>(loc, fieldTy, leftRef); - mlir::Value right = builder.create<fir::LoadOp>(loc, fieldTy, rightRef); - return builder.create<mlir::arith::CmpIOp>(loc, pred, left, right); + mlir::Value left = fir::LoadOp::create(builder, loc, fieldTy, leftRef); + mlir::Value right = fir::LoadOp::create(builder, loc, fieldTy, rightRef); + return mlir::arith::CmpIOp::create(builder, loc, pred, left, right); } // IEEE_CLASS @@ -4796,7 +4800,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, const unsigned intWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(intWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); llvm::StringRef tableName = RTNAME_STRING(IeeeClassTable); uint64_t highSignificandSize = (realType.getWidth() == 80) + 1; @@ -4806,8 +4810,8 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, return builder.createIntegerConstant(loc, intType, k); }; auto createIntegerConstantAPI = [&](const llvm::APInt &apInt) { - return builder.create<mlir::arith::ConstantOp>( - loc, intType, builder.getIntegerAttr(intType, apInt)); + return mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr(intType, apInt)); }; auto getMasksAndShifts = [&](uint64_t totalSize, uint64_t exponentSize, uint64_t significandSize, @@ -4854,50 +4858,52 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, // [s] sign bit int pos = 3 + highSignificandSize; - mlir::Value index = builder.create<mlir::arith::AndIOp>( - loc, builder.create<mlir::arith::ShRUIOp>(loc, intVal, signShift), + mlir::Value index = mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, signShift), createIntegerConstant(1ULL << pos)); // [e] exponent != 0 mlir::Value exponent = - builder.create<mlir::arith::AndIOp>(loc, intVal, exponentMask); + mlir::arith::AndIOp::create(builder, loc, intVal, exponentMask); mlir::Value zero = createIntegerConstant(0); - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, exponent, zero), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, exponent, zero), createIntegerConstant(1ULL << --pos), zero)); // [m] exponent == 1..1 (max exponent) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, exponent, exponentMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, exponent, + exponentMask), createIntegerConstant(1ULL << --pos), zero)); // [l] low-order significand != 0 - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, intVal, - lowSignificandMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, intVal, + lowSignificandMask), zero), createIntegerConstant(1ULL << --pos), zero)); // [h] high-order significand (1 or 2 bits) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::AndIOp>( - loc, - builder.create<mlir::arith::ShRUIOp>(loc, intVal, - highSignificandShift), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, + highSignificandShift), createIntegerConstant((1 << highSignificandSize) - 1))); int tableSize = 1 << (4 + highSignificandSize); @@ -5025,10 +5031,10 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, mlir::RankedTensorType::get(tableSize, int8Ty), values)); } - return builder.create<fir::CoordinateOp>( - loc, builder.getRefType(resultType), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(resultType), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), index); } @@ -5055,34 +5061,36 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType, // Args have the same type. if (xRealType == yRealType) - return builder.create<mlir::math::CopySignOp>(loc, xRealVal, yRealVal); + return mlir::math::CopySignOp::create(builder, loc, xRealVal, yRealVal); // Args have different types. mlir::Type xIntType = builder.getIntegerType(xRealType.getWidth()); mlir::Type yIntType = builder.getIntegerType(yRealType.getWidth()); mlir::Value xIntVal = - builder.create<mlir::arith::BitcastOp>(loc, xIntType, xRealVal); + mlir::arith::BitcastOp::create(builder, loc, xIntType, xRealVal); mlir::Value yIntVal = - builder.create<mlir::arith::BitcastOp>(loc, yIntType, yRealVal); + mlir::arith::BitcastOp::create(builder, loc, yIntType, yRealVal); mlir::Value xZero = builder.createIntegerConstant(loc, xIntType, 0); mlir::Value yZero = builder.createIntegerConstant(loc, yIntType, 0); mlir::Value xOne = builder.createIntegerConstant(loc, xIntType, 1); - mlir::Value ySign = builder.create<mlir::arith::ShRUIOp>( - loc, yIntVal, + mlir::Value ySign = mlir::arith::ShRUIOp::create( + builder, loc, yIntVal, builder.createIntegerConstant(loc, yIntType, yRealType.getWidth() - 1)); - mlir::Value xAbs = builder.create<mlir::arith::ShRUIOp>( - loc, builder.create<mlir::arith::ShLIOp>(loc, xIntVal, xOne), xOne); - mlir::Value xSign = builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::eq, - ySign, yZero), + mlir::Value xAbs = mlir::arith::ShRUIOp::create( + builder, loc, mlir::arith::ShLIOp::create(builder, loc, xIntVal, xOne), + xOne); + mlir::Value xSign = mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::eq, + ySign, yZero), xZero, - builder.create<mlir::arith::ShLIOp>( - loc, xOne, + mlir::arith::ShLIOp::create( + builder, loc, xOne, builder.createIntegerConstant(loc, xIntType, xRealType.getWidth() - 1))); - return builder.create<mlir::arith::BitcastOp>( - loc, xRealType, builder.create<mlir::arith::OrIOp>(loc, xAbs, xSign)); + return mlir::arith::BitcastOp::create( + builder, loc, xRealType, + mlir::arith::OrIOp::create(builder, loc, xAbs, xSign)); } // IEEE_GET_FLAG @@ -5096,16 +5104,16 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value excepts = fir::runtime::genFetestexcept( builder, loc, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - excepts, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, flagValue); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + excepts, zero)); + fir::StoreOp::create(builder, loc, logicalResult, flagValue); } // IEEE_GET_HALTING_MODE @@ -5120,17 +5128,17 @@ void IntrinsicLibrary::genIeeeGetHaltingMode( mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value haltSet = fir::runtime::genFegetexcept(builder, loc); - mlir::Value intResult = builder.create<mlir::arith::AndIOp>( - loc, haltSet, + mlir::Value intResult = mlir::arith::AndIOp::create( + builder, loc, haltSet, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - intResult, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, halting); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + intResult, zero)); + fir::StoreOp::create(builder, loc, logicalResult, halting); } // IEEE_GET_MODES, IEEE_SET_MODES @@ -5155,34 +5163,34 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // allotment. Allocate data space from the heap. auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]), 1); - addr = builder.create<fir::BoxAddrOp>( - loc, builder.create<fir::LoadOp>(loc, fieldRef)); + addr = fir::BoxAddrOp::create(builder, loc, + fir::LoadOp::create(builder, loc, fieldRef)); mlir::Type heapTy = addr.getType(); - mlir::Value allocated = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, + mlir::Value allocated = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, builder.createConvert(loc, i64Ty, addr), builder.createIntegerConstant(loc, i64Ty, 0)); - auto ifOp = builder.create<fir::IfOp>(loc, heapTy, allocated, - /*withElseRegion=*/true); + auto ifOp = fir::IfOp::create(builder, loc, heapTy, allocated, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, addr); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value byteSize = isModes ? fir::runtime::genGetModesTypeSize(builder, loc) : fir::runtime::genGetStatusTypeSize(builder, loc); byteSize = builder.createConvert(loc, builder.getIndexType(), byteSize); - addr = builder.create<fir::AllocMemOp>(loc, extractSequenceType(heapTy), - /*typeparams=*/mlir::ValueRange(), - byteSize); - mlir::Value shape = builder.create<fir::ShapeOp>(loc, byteSize); - builder.create<fir::StoreOp>( - loc, builder.create<fir::EmboxOp>(loc, fieldTy, addr, shape), fieldRef); - builder.create<fir::ResultOp>(loc, addr); + addr = fir::AllocMemOp::create(builder, loc, extractSequenceType(heapTy), + /*typeparams=*/mlir::ValueRange(), byteSize); + mlir::Value shape = fir::ShapeOp::create(builder, loc, byteSize); + fir::StoreOp::create( + builder, loc, fir::EmboxOp::create(builder, loc, fieldTy, addr, shape), + fieldRef); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointAfter(ifOp); - addr = builder.create<fir::ConvertOp>(loc, ptrTy, ifOp.getResult(0)); + addr = fir::ConvertOp::create(builder, loc, ptrTy, ifOp.getResult(0)); } else { // Place floating point environment data in __data storage. - addr = builder.create<fir::ConvertOp>(loc, ptrTy, getBase(args[0])); + addr = fir::ConvertOp::create(builder, loc, ptrTy, getBase(args[0])); } llvm::StringRef func = isModes ? (isGet ? "fegetmode" : "fesetmode") : (isGet ? "fegetenv" : "fesetenv"); @@ -5193,11 +5201,11 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // Check that an explicit ieee_[get|set]_rounding_mode call radix value is 2. static void checkRadix(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value radix, std::string procName) { - mlir::Value notTwo = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, radix, + mlir::Value notTwo = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, radix, builder.createIntegerConstant(loc, radix.getType(), 2)); - auto ifOp = builder.create<fir::IfOp>(loc, notTwo, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, notTwo, + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError(builder, loc, procName + " radix argument must be 2"); @@ -5215,9 +5223,9 @@ void IntrinsicLibrary::genIeeeGetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_get_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mode = builder.createConvert(loc, fieldTy, mode); - builder.create<fir::StoreOp>(loc, mode, fieldRef); + fir::StoreOp::create(builder, loc, mode, fieldRef); } // IEEE_GET_UNDERFLOW_MODE @@ -5242,44 +5250,45 @@ mlir::Value IntrinsicLibrary::genIeeeInt(mlir::Type resultType, mlir::FloatType realType = mlir::cast<mlir::FloatType>(args[0].getType()); mlir::Value realResult = genIeeeRint(realType, {args[0], args[1]}); int intWidth = mlir::cast<mlir::IntegerType>(resultType).getWidth(); - mlir::Value intLBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intLBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/intWidth - 1, /*hi=*/intWidth))); - mlir::Value intUBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intUBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/0, /*hi=*/intWidth - 1))); mlir::Value realLBound = - builder.create<fir::ConvertOp>(loc, realType, intLBound); - mlir::Value realUBound = builder.create<mlir::arith::NegFOp>(loc, realLBound); - mlir::Value aGreaterThanLBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); - mlir::Value aLessThanUBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); - mlir::Value resultIsValid = builder.create<mlir::arith::AndIOp>( - loc, aGreaterThanLBound, aLessThanUBound); + fir::ConvertOp::create(builder, loc, realType, intLBound); + mlir::Value realUBound = + mlir::arith::NegFOp::create(builder, loc, realLBound); + mlir::Value aGreaterThanLBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); + mlir::Value aLessThanUBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); + mlir::Value resultIsValid = mlir::arith::AndIOp::create( + builder, loc, aGreaterThanLBound, aLessThanUBound); // Result is valid. It may be exact or inexact. mlir::Value result; - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, resultIsValid, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, resultIsValid, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); - result = builder.create<fir::ConvertOp>(loc, resultType, realResult); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, realResult); + fir::ResultOp::create(builder, loc, result); // Result is invalid. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - result = builder.create<mlir::arith::SelectOp>(loc, aGreaterThanLBound, - intUBound, intLBound); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, aGreaterThanLBound, + intUBound, intLBound); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); } @@ -5334,7 +5343,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(realType.getWidth()); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Type i1Ty = builder.getI1Type(); int exponentBias, significandSize, nonSignificandSize; @@ -5381,72 +5390,72 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, llvm_unreachable("unknown real type"); } - mlir::Value isZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, realVal, + mlir::Value isZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, realVal, builder.createRealZeroConstant(loc, resultType)); - auto outerIfOp = builder.create<fir::IfOp>(loc, resultType, isZero, - /*withElseRegion=*/true); + auto outerIfOp = fir::IfOp::create(builder, loc, resultType, isZero, + /*withElseRegion=*/true); // X is zero -- result is -infinity builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO); mlir::Value ones = builder.createAllOnesInteger(loc, intType); - mlir::Value result = builder.create<mlir::arith::ShLIOp>( - loc, ones, + mlir::Value result = mlir::arith::ShLIOp::create( + builder, loc, ones, builder.createIntegerConstant(loc, intType, // kind=10 high-order bit is explicit significandSize - (bitWidth == 80))); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); mlir::Value one = builder.createIntegerConstant(loc, intType, 1); mlir::Value shiftLeftOne = - builder.create<mlir::arith::ShLIOp>(loc, intVal, one); + mlir::arith::ShLIOp::create(builder, loc, intVal, one); mlir::Value isFinite = genIsFPClass(i1Ty, args, finiteTest); - auto innerIfOp = builder.create<fir::IfOp>(loc, resultType, isFinite, - /*withElseRegion=*/true); + auto innerIfOp = fir::IfOp::create(builder, loc, resultType, isFinite, + /*withElseRegion=*/true); // X is non-zero finite -- result is unbiased exponent of X builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value isNormal = genIsFPClass(i1Ty, args, normalTest); - auto normalIfOp = builder.create<fir::IfOp>(loc, resultType, isNormal, - /*withElseRegion=*/true); + auto normalIfOp = fir::IfOp::create(builder, loc, resultType, isNormal, + /*withElseRegion=*/true); // X is normal builder.setInsertionPointToStart(&normalIfOp.getThenRegion().front()); - mlir::Value biasedExponent = builder.create<mlir::arith::ShRUIOp>( - loc, shiftLeftOne, + mlir::Value biasedExponent = mlir::arith::ShRUIOp::create( + builder, loc, shiftLeftOne, builder.createIntegerConstant(loc, intType, significandSize + 1)); - result = builder.create<mlir::arith::SubIOp>( - loc, biasedExponent, + result = mlir::arith::SubIOp::create( + builder, loc, biasedExponent, builder.createIntegerConstant(loc, intType, exponentBias)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // X is denormal -- result is (-exponentBias - ctlz(significand)) builder.setInsertionPointToStart(&normalIfOp.getElseRegion().front()); - mlir::Value significand = builder.create<mlir::arith::ShLIOp>( - loc, intVal, + mlir::Value significand = mlir::arith::ShLIOp::create( + builder, loc, intVal, builder.createIntegerConstant(loc, intType, nonSignificandSize)); mlir::Value ctlz = - builder.create<mlir::math::CountLeadingZerosOp>(loc, significand); + mlir::math::CountLeadingZerosOp::create(builder, loc, significand); mlir::Type i32Ty = builder.getI32Type(); - result = builder.create<mlir::arith::SubIOp>( - loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), - builder.create<fir::ConvertOp>(loc, i32Ty, ctlz)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SubIOp::create( + builder, loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), + fir::ConvertOp::create(builder, loc, i32Ty, ctlz)); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToEnd(&innerIfOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, normalIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, normalIfOp.getResult(0)); // X is infinity or NaN -- result is +infinity or NaN builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - result = builder.create<mlir::arith::ShRUIOp>(loc, shiftLeftOne, one); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::ShRUIOp::create(builder, loc, shiftLeftOne, one); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointToEnd(&outerIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -5480,8 +5489,8 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, mlir::Value x1, y1; // X or ABS(X), Y or ABS(Y) if constexpr (isMag) { mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - x1 = builder.create<mlir::math::CopySignOp>(loc, x, zero); - y1 = builder.create<mlir::math::CopySignOp>(loc, y, zero); + x1 = mlir::math::CopySignOp::create(builder, loc, x, zero); + y1 = mlir::math::CopySignOp::create(builder, loc, y, zero); } else { x1 = x; y1 = y; @@ -5492,56 +5501,56 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, // X1 < Y1 -- MAX result is Y; MIN result is X. pred = mlir::arith::CmpFPredicate::OLT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp1 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp1 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); result = isMax ? y : x; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 > Y1 -- MAX result is X; MIN result is Y. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OGT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp2 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp2 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); result = isMax ? x : y; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 == Y1 -- MAX favors a positive result; MIN favors a negative result. builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OEQ; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp3 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp3 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp3.getThenRegion().front()); resultIsX = isMax ? genIsFPClass(i1Ty, x, positiveTest) : genIsFPClass(i1Ty, x, negativeTest); - result = builder.create<mlir::arith::SelectOp>(loc, resultIsX, x, y); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, resultIsX, x, y); + fir::ResultOp::create(builder, loc, result); // X or Y or both are NaNs -- result may be X, Y, or a qNaN builder.setInsertionPointToStart(&ifOp3.getElseRegion().front()); if constexpr (isNum) { pred = mlir::arith::CmpFPredicate::ORD; // check for a non-NaN - resultIsX = builder.create<mlir::arith::CmpFOp>(loc, pred, x, x); - resultIsY = builder.create<mlir::arith::CmpFOp>(loc, pred, y, y); + resultIsX = mlir::arith::CmpFOp::create(builder, loc, pred, x, x); + resultIsY = mlir::arith::CmpFOp::create(builder, loc, pred, y, y); } else { resultIsX = resultIsY = builder.createBool(loc, false); } - result = builder.create<mlir::arith::SelectOp>( - loc, resultIsX, x, - builder.create<mlir::arith::SelectOp>(loc, resultIsY, y, - genQNan(resultType))); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + result = mlir::arith::SelectOp::create( + builder, loc, resultIsX, x, + mlir::arith::SelectOp::create(builder, loc, resultIsY, y, + genQNan(resultType))); + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointAfter(ifOp3); - builder.create<fir::ResultOp>(loc, ifOp3.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp3.getResult(0)); builder.setInsertionPointAfter(ifOp2); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5554,13 +5563,13 @@ IntrinsicLibrary::genIeeeQuietCompare(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { // Compare X and Y with special case treatment of NaN operands. assert(args.size() == 2); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_REAL @@ -5612,14 +5621,14 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, // If the argument is an sNaN, raise an invalid exception and return a qNaN. // Otherwise return the argument. auto processSnan = [&](mlir::Value x) { - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, - genIsFPClass(i1Ty, x, snanTest), - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, + genIsFPClass(i1Ty, x, snanTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - builder.create<fir::ResultOp>(loc, genQNan(resultType)); + fir::ResultOp::create(builder, loc, genQNan(resultType)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); }; @@ -5635,7 +5644,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, a = builder.createConvert(loc, f32Ty, a); aType = f32Ty; } - r = builder.create<fir::ConvertOp>(loc, resultType, a); + r = fir::ConvertOp::create(builder, loc, resultType, a); mlir::IntegerType aIntType = mlir::dyn_cast<mlir::IntegerType>(aType); mlir::FloatType aFloatType = mlir::dyn_cast<mlir::FloatType>(aType); @@ -5647,142 +5656,144 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, return aIntType ? r : processSnan(r); // A possibly inexact conversion result may need to be rounded up or down. - mlir::Value b = builder.create<fir::ConvertOp>(loc, aType, r); + mlir::Value b = fir::ConvertOp::create(builder, loc, aType, r); mlir::Value aEqB; if (aIntType) - aEqB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, a, b); + aEqB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, a, b); else - aEqB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, a, b); + aEqB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::UEQ, a, b); // [a == b] a is a NaN or r is exact (a may be -0, +0, -inf, +inf) -- return r - fir::IfOp ifOp1 = builder.create<fir::IfOp>(loc, resultType, aEqB, - /*withElseRegion=*/true); + fir::IfOp ifOp1 = fir::IfOp::create(builder, loc, resultType, aEqB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, aIntType ? r : processSnan(r)); + fir::ResultOp::create(builder, loc, aIntType ? r : processSnan(r)); // Code common to (a < b) and (a > b) branches. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mlir::Value aIsNegative, aIsPositive; if (aIntType) { mlir::Value zero = builder.createIntegerConstant(loc, aIntType, 0); - aIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, zero); - aIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, a, zero); + aIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, a, zero); + aIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, a, zero); } else { mlir::Value zero = builder.createRealZeroConstant(loc, aFloatType); - aIsNegative = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, zero); - aIsPositive = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, a, zero); + aIsNegative = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, a, zero); + aIsPositive = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, a, zero); } mlir::Type resultIntType = builder.getIntegerType(resultFloatType.getWidth()); mlir::Value resultCast = - builder.create<mlir::arith::BitcastOp>(loc, resultIntType, r); + mlir::arith::BitcastOp::create(builder, loc, resultIntType, r); mlir::Value one = builder.createIntegerConstant(loc, resultIntType, 1); - mlir::Value rIsOdd = builder.create<fir::ConvertOp>( - loc, i1Ty, builder.create<mlir::arith::AndIOp>(loc, resultCast, one)); + mlir::Value rIsOdd = fir::ConvertOp::create( + builder, loc, i1Ty, + mlir::arith::AndIOp::create(builder, loc, resultCast, one)); // Check for a rounding mode match. auto match = [&](int m) { - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, mode, + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, mode, builder.createIntegerConstant(loc, mode.getType(), m)); }; - mlir::Value roundToNearestBit = builder.create<mlir::arith::OrIOp>( - loc, + mlir::Value roundToNearestBit = mlir::arith::OrIOp::create( + builder, loc, // IEEE_OTHER is an alias for IEEE_NEAREST. match(_FORTRAN_RUNTIME_IEEE_NEAREST), match(_FORTRAN_RUNTIME_IEEE_OTHER)); mlir::Value roundToNearest = - builder.create<mlir::arith::AndIOp>(loc, roundToNearestBit, rIsOdd); + mlir::arith::AndIOp::create(builder, loc, roundToNearestBit, rIsOdd); mlir::Value roundToZeroBit = match(_FORTRAN_RUNTIME_IEEE_TO_ZERO); mlir::Value roundAwayBit = match(_FORTRAN_RUNTIME_IEEE_AWAY); mlir::Value roundToZero, roundAway, mustAdjust; fir::IfOp adjustIfOp; mlir::Value aLtB; if (aIntType) - aLtB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, b); + aLtB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); else - aLtB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, b); + aLtB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OLT, a, b); mlir::Value upResult = - builder.create<mlir::arith::AddIOp>(loc, resultCast, one); + mlir::arith::AddIOp::create(builder, loc, resultCast, one); mlir::Value downResult = - builder.create<mlir::arith::SubIOp>(loc, resultCast, one); + mlir::arith::SubIOp::create(builder, loc, resultCast, one); // (a < b): r is inexact -- return r or ieee_next_down(r) - fir::IfOp ifOp2 = builder.create<fir::IfOp>(loc, resultType, aLtB, - /*withElseRegion=*/true); + fir::IfOp ifOp2 = fir::IfOp::create(builder, loc, resultType, aLtB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsPositive); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsNegative); mlir::Value roundDown = match(_FORTRAN_RUNTIME_IEEE_DOWN); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundDown); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundDown); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, false)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsNegative, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsNegative, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // (a > b): r is inexact -- return r or ieee_next_up(r) builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsNegative); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsPositive); mlir::Value roundUp = match(_FORTRAN_RUNTIME_IEEE_UP); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundUp); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundUp); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, true)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsPositive, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsPositive, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // Generate exceptions for (a < b) and (a > b) branches. builder.setInsertionPointAfter(ifOp2); r = ifOp2.getResult(0); - fir::IfOp exceptIfOp1 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, infiniteTest), /*withElseRegion=*/true); + fir::IfOp exceptIfOp1 = + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, r, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp1.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&exceptIfOp1.getElseRegion().front()); - fir::IfOp exceptIfOp2 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), + fir::IfOp exceptIfOp2 = fir::IfOp::create( + builder, loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp2.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | @@ -5790,7 +5801,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, builder.setInsertionPointToStart(&exceptIfOp2.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointAfter(exceptIfOp1); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5806,19 +5817,19 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType, mlir::Value y = args[1]; if (mlir::dyn_cast<mlir::FloatType>(resultType).getWidth() < 32) { mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext()); - x = builder.create<fir::ConvertOp>(loc, f32Ty, x); - y = builder.create<fir::ConvertOp>(loc, f32Ty, y); + x = fir::ConvertOp::create(builder, loc, f32Ty, x); + y = fir::ConvertOp::create(builder, loc, f32Ty, y); } else { - x = builder.create<fir::ConvertOp>(loc, resultType, x); - y = builder.create<fir::ConvertOp>(loc, resultType, y); + x = fir::ConvertOp::create(builder, loc, resultType, x); + y = fir::ConvertOp::create(builder, loc, resultType, y); } // remainder calls do not signal IEEE_UNDERFLOW. - mlir::Value underflow = builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), + mlir::Value underflow = mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), genIsFPClass(builder.getI1Type(), y, infiniteTest)); mlir::Value result = genRuntimeCall("remainder", x.getType(), {x, y}); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW, underflow); - return builder.create<fir::ConvertOp>(loc, resultType, result); + return fir::ConvertOp::create(builder, loc, resultType, result); } // IEEE_RINT @@ -5834,19 +5845,19 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType, mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); mlir::Value mode; if (isStaticallyPresent(args[1])) { - mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mode = fir::CallOp::create(builder, loc, getRound).getResult(0); genIeeeSetRoundingMode({args[1]}); } if (mlir::cast<mlir::FloatType>(resultType).getWidth() == 16) - a = builder.create<fir::ConvertOp>( - loc, mlir::Float32Type::get(builder.getContext()), a); - mlir::Value result = builder.create<fir::ConvertOp>( - loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); + a = fir::ConvertOp::create(builder, loc, + mlir::Float32Type::get(builder.getContext()), a); + mlir::Value result = fir::ConvertOp::create( + builder, loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); if (isStaticallyPresent(args[1])) { - builder.create<fir::CallOp>(loc, setRound, mode); + fir::CallOp::create(builder, loc, setRound, mode); } else { - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], result); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], result); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); } return result; @@ -5862,18 +5873,19 @@ void IntrinsicLibrary::genIeeeSetFlagOrHaltingMode( mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value except = fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field)); - auto ifOp = builder.create<fir::IfOp>( - loc, builder.create<fir::ConvertOp>(loc, i1Ty, getBase(args[1])), + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field)); + auto ifOp = fir::IfOp::create( + builder, loc, + fir::ConvertOp::create(builder, loc, i1Ty, getBase(args[1])), /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); (isFlag ? fir::runtime::genFeraiseexcept : fir::runtime::genFeenableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); (isFlag ? fir::runtime::genFeclearexcept : fir::runtime::genFedisableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointAfter(ifOp); } @@ -5890,7 +5902,7 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_set_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); static_assert( _FORTRAN_RUNTIME_IEEE_TO_ZERO >= 0 && _FORTRAN_RUNTIME_IEEE_TO_ZERO <= 3 && @@ -5898,28 +5910,28 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( _FORTRAN_RUNTIME_IEEE_NEAREST <= 3 && _FORTRAN_RUNTIME_IEEE_UP >= 0 && _FORTRAN_RUNTIME_IEEE_UP <= 3 && _FORTRAN_RUNTIME_IEEE_DOWN >= 0 && _FORTRAN_RUNTIME_IEEE_DOWN <= 3 && "unexpected rounding mode mapping"); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>( - loc, builder.createAllOnesInteger(loc, fieldTy), + mlir::Value mask = mlir::arith::ShLIOp::create( + builder, loc, builder.createAllOnesInteger(loc, fieldTy), builder.createIntegerConstant(loc, fieldTy, 2)); - mlir::Value modeIsSupported = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, - builder.create<mlir::arith::AndIOp>(loc, mode, mask), + mlir::Value modeIsSupported = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, + mlir::arith::AndIOp::create(builder, loc, mode, mask), builder.createIntegerConstant(loc, fieldTy, 0)); mlir::Value nearest = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_NEAREST); - mode = builder.create<mlir::arith::SelectOp>(loc, modeIsSupported, mode, - nearest); - mode = builder.create<fir::ConvertOp>( - loc, setRound.getFunctionType().getInput(0), mode); - builder.create<fir::CallOp>(loc, setRound, mode); + mode = mlir::arith::SelectOp::create(builder, loc, modeIsSupported, mode, + nearest); + mode = fir::ConvertOp::create(builder, loc, + setRound.getFunctionType().getInput(0), mode); + fir::CallOp::create(builder, loc, setRound, mode); } // IEEE_SET_UNDERFLOW_MODE void IntrinsicLibrary::genIeeeSetUnderflowMode( llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - mlir::Value gradual = builder.create<fir::ConvertOp>(loc, builder.getI1Type(), - getBase(args[0])); + mlir::Value gradual = fir::ConvertOp::create( + builder, loc, builder.getI1Type(), getBase(args[0])); fir::runtime::genSetUnderflowMode(builder, loc, {gradual}); } @@ -5933,9 +5945,9 @@ IntrinsicLibrary::genIeeeSignalingCompare(mlir::Type resultType, assert(args.size() == 2); mlir::Value hasNaNOp = genIeeeUnordered(mlir::Type{}, args); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_SIGNBIT @@ -5954,9 +5966,9 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType, } mlir::Type intType = builder.getIntegerType(bitWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Value shift = builder.createIntegerConstant(loc, intType, bitWidth - 1); - mlir::Value sign = builder.create<mlir::arith::ShRUIOp>(loc, intVal, shift); + mlir::Value sign = mlir::arith::ShRUIOp::create(builder, loc, intVal, shift); return builder.createConvert(loc, resultType, sign); } @@ -5969,21 +5981,21 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value flag = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value flag = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value standardFlagMask = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_INVALID | _FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO | _FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - mlir::Value isStandardFlag = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, flag, standardFlagMask), + mlir::Value isStandardFlag = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, flag, standardFlagMask), builder.createIntegerConstant(loc, fieldTy, 0)); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, i1Ty, isStandardFlag, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, i1Ty, isStandardFlag, + /*withElseRegion=*/true); // Standard flags are supported. builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, builder.createBool(loc, true)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, true)); // TargetCharacteristics information for the nonstandard ieee_denorm flag // is not available here. So use a runtime check restricted to possibly @@ -6007,17 +6019,17 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, } } if (mayBeSupported) { - mlir::Value isDenorm = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, flag, + mlir::Value isDenorm = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, flag, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DENORM)); - mlir::Value result = builder.create<mlir::arith::AndIOp>( - loc, isDenorm, + mlir::Value result = mlir::arith::AndIOp::create( + builder, loc, isDenorm, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, flag))); - builder.create<fir::ResultOp>(loc, result); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, flag))); + fir::ResultOp::create(builder, loc, result); } else { - builder.create<fir::ResultOp>(loc, builder.createBool(loc, false)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, false)); } builder.setInsertionPointAfter(ifOp); return builder.createConvert(loc, resultType, ifOp.getResult(0)); @@ -6032,11 +6044,11 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportHalting( assert(args.size() == 1); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); return builder.createConvert( loc, resultType, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); } // IEEE_SUPPORT_ROUNDING @@ -6053,16 +6065,16 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportRounding( // 4 - to nearest, ties away from zero [not supported] assert(args.size() == 1 || args.size() == 2); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); - mlir::Value lbOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, mode, + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); + mlir::Value lbOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_TO_ZERO)); - mlir::Value ubOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sle, mode, + mlir::Value ubOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sle, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DOWN)); return builder.createConvert( - loc, resultType, builder.create<mlir::arith::AndIOp>(loc, lbOk, ubOk)); + loc, resultType, mlir::arith::AndIOp::create(builder, loc, lbOk, ubOk)); } // IEEE_SUPPORT_STANDARD @@ -6086,15 +6098,15 @@ IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType, // If there is no result type return an i1 result. assert(args.size() == 2); if (args[0].getType() == args[1].getType()) { - mlir::Value res = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); + mlir::Value res = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); return resultType ? builder.createConvert(loc, resultType, res) : res; } assert(resultType && "expecting a (mixed arg type) unordered result type"); mlir::Type i1Ty = builder.getI1Type(); mlir::Value xIsNan = genIsFPClass(i1Ty, args[0], nanTest); mlir::Value yIsNan = genIsFPClass(i1Ty, args[1], nanTest); - mlir::Value res = builder.create<mlir::arith::OrIOp>(loc, xIsNan, yIsNan); + mlir::Value res = mlir::arith::OrIOp::create(builder, loc, xIsNan, yIsNan); return builder.createConvert(loc, resultType, res); } @@ -6219,22 +6231,22 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType, mlir::Value which; if (args.size() == 2) { // user call auto [index, ignore] = getFieldRef(builder, loc, args[1]); - which = builder.create<fir::LoadOp>(loc, index); + which = fir::LoadOp::create(builder, loc, index); } else { // compiler generated call which = args[0]; } - mlir::Value bits = builder.create<fir::LoadOp>( - loc, - builder.create<fir::CoordinateOp>( - loc, builder.getRefType(valueTy), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + mlir::Value bits = fir::LoadOp::create( + builder, loc, + fir::CoordinateOp::create( + builder, loc, builder.getRefType(valueTy), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), which)); if (bitWidth > 64) - bits = builder.create<mlir::arith::ShLIOp>( - loc, builder.createConvert(loc, intType, bits), + bits = mlir::arith::ShLIOp::create( + builder, loc, builder.createConvert(loc, intType, bits), builder.createIntegerConstant(loc, intType, bitWidth - 64)); - return builder.create<mlir::arith::BitcastOp>(loc, realType, bits); + return mlir::arith::BitcastOp::create(builder, loc, realType, bits); } // IEOR @@ -6276,13 +6288,14 @@ IntrinsicLibrary::genIndex(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value backOpt = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : makeRefThenEmbox(fir::getBase(args[2])); + mlir::Value backOpt = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : makeRefThenEmbox(fir::getBase(args[2])); mlir::Value kindVal = isStaticallyAbsent(args, 3) ? builder.createIntegerConstant( loc, builder.getIndexType(), @@ -6331,8 +6344,8 @@ mlir::Value IntrinsicLibrary::genIsIostatValue(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, args[0], + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, args[0], builder.createIntegerConstant(loc, args[0].getType(), value)); } @@ -6359,16 +6372,16 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - auto left = builder.create<mlir::arith::ShLIOp>(loc, word, absShift); - auto right = builder.create<mlir::arith::ShRUIOp>(loc, word, absShift); - auto shiftIsLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); - auto shiftIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); + auto left = mlir::arith::ShLIOp::create(builder, loc, word, absShift); + auto right = mlir::arith::ShRUIOp::create(builder, loc, word, absShift); + auto shiftIsLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); + auto shiftIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); auto sel = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNegative, right, left); + mlir::arith::SelectOp::create(builder, loc, shiftIsNegative, right, left); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsLarge, zero, sel); + mlir::arith::SelectOp::create(builder, loc, shiftIsLarge, zero, sel); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6409,42 +6422,42 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value absShift = genAbs(signlessType, {shift}); - auto elseSize = builder.create<mlir::arith::SubIOp>(loc, size, absShift); - auto shiftIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, shift, zero); - auto shiftEqualsSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, absShift, size); + auto elseSize = mlir::arith::SubIOp::create(builder, loc, size, absShift); + auto shiftIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, shift, zero); + auto shiftEqualsSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, absShift, size); auto shiftIsNop = - builder.create<mlir::arith::OrIOp>(loc, shiftIsZero, shiftEqualsSize); - auto shiftIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, shift, zero); - auto leftSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - absShift, elseSize); - auto rightSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - elseSize, absShift); - auto hasUnchanged = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, size, bitSize); - auto unchangedTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, word, size); + mlir::arith::OrIOp::create(builder, loc, shiftIsZero, shiftEqualsSize); + auto shiftIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, shift, zero); + auto leftSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + absShift, elseSize); + auto rightSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + elseSize, absShift); + auto hasUnchanged = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, size, bitSize); + auto unchangedTmp1 = mlir::arith::ShRUIOp::create(builder, loc, word, size); auto unchangedTmp2 = - builder.create<mlir::arith::ShLIOp>(loc, unchangedTmp1, size); - auto unchanged = builder.create<mlir::arith::SelectOp>(loc, hasUnchanged, - unchangedTmp2, zero); + mlir::arith::ShLIOp::create(builder, loc, unchangedTmp1, size); + auto unchanged = mlir::arith::SelectOp::create(builder, loc, hasUnchanged, + unchangedTmp2, zero); auto leftMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, leftSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, leftSize); auto leftMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, leftMaskShift); - auto leftTmp = builder.create<mlir::arith::ShRUIOp>(loc, word, rightSize); - auto left = builder.create<mlir::arith::AndIOp>(loc, leftTmp, leftMask); + mlir::arith::ShRUIOp::create(builder, loc, ones, leftMaskShift); + auto leftTmp = mlir::arith::ShRUIOp::create(builder, loc, word, rightSize); + auto left = mlir::arith::AndIOp::create(builder, loc, leftTmp, leftMask); auto rightMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, rightSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, rightSize); auto rightMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, rightMaskShift); - auto rightTmp = builder.create<mlir::arith::AndIOp>(loc, word, rightMask); - auto right = builder.create<mlir::arith::ShLIOp>(loc, rightTmp, leftSize); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, left); - auto res = builder.create<mlir::arith::OrIOp>(loc, resTmp, right); + mlir::arith::ShRUIOp::create(builder, loc, ones, rightMaskShift); + auto rightTmp = mlir::arith::AndIOp::create(builder, loc, word, rightMask); + auto right = mlir::arith::ShLIOp::create(builder, loc, rightTmp, leftSize); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, left); + auto res = mlir::arith::OrIOp::create(builder, loc, resTmp, right); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNop, word, res); + mlir::arith::SelectOp::create(builder, loc, shiftIsNop, word, res); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6456,7 +6469,7 @@ mlir::Value IntrinsicLibrary::genLeadz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountLeadingZerosOp>(loc, args); + mlir::math::CountLeadingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -6524,18 +6537,18 @@ IntrinsicLibrary::genLoc(mlir::Type resultType, // created when preparing the argument cases, but the box can be safely be // used for all those cases and the address will be null if absent. mlir::Value isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), box); + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), box); return builder .genIfOp(loc, {resultType}, isPresent, /*withElseRegion=*/true) .genThen([&]() { mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value cast = builder.createConvert(loc, resultType, argAddr); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } @@ -6568,12 +6581,12 @@ mlir::Value IntrinsicLibrary::genMask(mlir::Type resultType, // non-deterministic result. Other compilers don't produce a consistent result // in this case either, so we choose the most efficient implementation. mlir::Value shift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, bitsToSet); - mlir::Value shifted = builder.create<Shift>(loc, ones, shift); - mlir::Value isZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); + mlir::arith::SubIOp::create(builder, loc, bitSize, bitsToSet); + mlir::Value shifted = Shift::create(builder, loc, ones, shift); + mlir::Value isZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, isZero, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, isZero, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6591,8 +6604,8 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); mlir::Type retTy = mlir::LLVM::LLVMStructType::getLiteral(context, {resultType, i1Ty}); @@ -6601,10 +6614,10 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, .create<mlir::NVVM::MatchSyncOp>(loc, retTy, args[0], arg1, mlir::NVVM::MatchSyncKind::all) .getResult(); - auto value = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 0); - auto pred = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 1); - auto conv = builder.create<mlir::LLVM::ZExtOp>(loc, resultType, pred); - builder.create<fir::StoreOp>(loc, conv, args[2]); + auto value = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 0); + auto pred = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 1); + auto conv = mlir::LLVM::ZExtOp::create(builder, loc, resultType, pred); + fir::StoreOp::create(builder, loc, conv, args[2]); return value; } @@ -6614,14 +6627,14 @@ mlir::Value IntrinsicLibrary::genVoteSync(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 2); mlir::Value arg1 = - builder.create<fir::ConvertOp>(loc, builder.getI1Type(), args[1]); + fir::ConvertOp::create(builder, loc, builder.getI1Type(), args[1]); mlir::Type resTy = kind == mlir::NVVM::VoteSyncKind::ballot ? builder.getI32Type() : builder.getI1Type(); auto voteRes = - builder.create<mlir::NVVM::VoteSyncOp>(loc, resTy, args[0], arg1, kind) + mlir::NVVM::VoteSyncOp::create(builder, loc, resTy, args[0], arg1, kind) .getResult(); - return builder.create<fir::ConvertOp>(loc, resultType, voteRes); + return fir::ConvertOp::create(builder, loc, resultType, voteRes); } // MATCH_ANY_SYNC @@ -6633,8 +6646,8 @@ IntrinsicLibrary::genMatchAnySync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); return builder .create<mlir::NVVM::MatchSyncOp>(loc, resultType, args[0], arg1, @@ -6718,10 +6731,10 @@ IntrinsicLibrary::genMerge(mlir::Type, mlir::Value other) -> mlir::Value { mlir::Type otherType = other.getType(); if (mlir::isa<fir::BaseBoxType>(otherType)) - return builder.create<fir::ReboxOp>(loc, otherType, polymorphic, - /*shape*/ mlir::Value{}, - /*slice=*/mlir::Value{}); - return builder.create<fir::BoxAddrOp>(loc, otherType, polymorphic); + return fir::ReboxOp::create(builder, loc, otherType, polymorphic, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + return fir::BoxAddrOp::create(builder, loc, otherType, polymorphic); }; if (fir::isPolymorphicType(tsource.getType()) && !fir::isPolymorphicType(fsource.getType())) { @@ -6737,8 +6750,8 @@ IntrinsicLibrary::genMerge(mlir::Type, // fulfill mlir::SelectOp constraint that the MLIR types must be the same. fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); } - auto rslt = builder.create<mlir::arith::SelectOp>(loc, mask, tsourceCast, - fsourceCast); + auto rslt = mlir::arith::SelectOp::create(builder, loc, mask, tsourceCast, + fsourceCast); if (isCharRslt) { // Need a CharBoxValue for character results const fir::CharBoxValue *charBox = args[0].getCharBox(); @@ -6779,7 +6792,7 @@ mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, args[0], args[1]); } if (mlir::isa<mlir::IntegerType>(resultType)) - return builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); + return mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); // Use runtime. return builder.createConvert( @@ -6809,19 +6822,19 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, } if (mlir::isa<mlir::IntegerType>(resultType)) { auto remainder = - builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); - auto argXor = builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]); + mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); + auto argXor = mlir::arith::XOrIOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createIntegerConstant(loc, argXor.getType(), 0); - auto argSignDifferent = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, argXor, zero); - auto remainderIsNotZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, remainder, zero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); + auto argSignDifferent = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, argXor, zero); + auto remainderIsNotZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, remainder, zero); + auto mustAddP = mlir::arith::AndIOp::create( + builder, loc, remainderIsNotZero, argSignDifferent); auto remPlusP = - builder.create<mlir::arith::AddIOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::AddIOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } auto fastMathFlags = builder.getFastMathFlags(); @@ -6834,21 +6847,21 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, loc, resultType, fir::runtime::genModulo(builder, loc, args[0], args[1])); - auto remainder = builder.create<mlir::arith::RemFOp>(loc, args[0], args[1]); + auto remainder = mlir::arith::RemFOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createRealZeroConstant(loc, remainder.getType()); - auto remainderIsNotZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); - auto aLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); - auto pLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); + auto remainderIsNotZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); + auto aLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); + auto pLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); auto argSignDifferent = - builder.create<mlir::arith::XOrIOp>(loc, aLessThanZero, pLessThanZero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); - auto remPlusP = builder.create<mlir::arith::AddFOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::XOrIOp::create(builder, loc, aLessThanZero, pLessThanZero); + auto mustAddP = mlir::arith::AndIOp::create(builder, loc, remainderIsNotZero, + argSignDifferent); + auto remPlusP = mlir::arith::AddFOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { @@ -6863,7 +6876,7 @@ void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value errBox = isStaticallyPresent(errMsg) ? fir::getBase(errMsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); const fir::MutableBoxValue *fromBox = from.getBoxOf<fir::MutableBoxValue>(); const fir::MutableBoxValue *toBox = to.getBoxOf<fir::MutableBoxValue>(); @@ -6920,33 +6933,34 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type toType{fir::dyn_cast_ptrEleTy(toAddr.getType())}; assert(toType.getIntOrFloatBitWidth() == fromType.getIntOrFloatBitWidth() && "mismatched mvbits types"); - auto to = builder.create<fir::LoadOp>(loc, signlessType, toAddr); + auto to = fir::LoadOp::create(builder, loc, signlessType, toAddr); mlir::Value topos = builder.createConvert(loc, signlessType, unbox(args[4])); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(signlessType).getWidth()); - auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len); - auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); - auto unchangedTmp1 = builder.create<mlir::arith::ShLIOp>(loc, mask, topos); + auto shiftCount = mlir::arith::SubIOp::create(builder, loc, bitSize, len); + auto mask = mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); + auto unchangedTmp1 = mlir::arith::ShLIOp::create(builder, loc, mask, topos); auto unchangedTmp2 = - builder.create<mlir::arith::XOrIOp>(loc, unchangedTmp1, ones); - auto unchanged = builder.create<mlir::arith::AndIOp>(loc, unchangedTmp2, to); + mlir::arith::XOrIOp::create(builder, loc, unchangedTmp1, ones); + auto unchanged = mlir::arith::AndIOp::create(builder, loc, unchangedTmp2, to); if (fromType.isUnsignedInteger()) from = builder.createConvert(loc, signlessType, from); - auto frombitsTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, from, frompos); + auto frombitsTmp1 = mlir::arith::ShRUIOp::create(builder, loc, from, frompos); auto frombitsTmp2 = - builder.create<mlir::arith::AndIOp>(loc, frombitsTmp1, mask); - auto frombits = builder.create<mlir::arith::ShLIOp>(loc, frombitsTmp2, topos); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, frombits); - auto lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::arith::AndIOp::create(builder, loc, frombitsTmp1, mask); + auto frombits = + mlir::arith::ShLIOp::create(builder, loc, frombitsTmp2, topos); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, frombits); + auto lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value res = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, to, resTmp); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, to, resTmp); if (toType.isUnsignedInteger()) res = builder.createConvert(loc, toType, res); - builder.create<fir::StoreOp>(loc, res, toAddr); + fir::StoreOp::create(builder, loc, res, toAddr); } // NEAREST, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP @@ -6988,7 +7002,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, // If isNan(Y), set X to a qNaN that will propagate to the resultIsX result. mlir::Value qNan = genQNan(xType); mlir::Value isFPClass = genIsFPClass(i1Ty, args[1], nanTest); - x = builder.create<mlir::arith::SelectOp>(loc, isFPClass, qNan, x); + x = mlir::arith::SelectOp::create(builder, loc, isFPClass, qNan, x); } mlir::Value resultIsX = genIsFPClass(i1Ty, x, nanTest); mlir::Type intType = builder.getIntegerType(xBitWidth); @@ -6999,15 +7013,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if constexpr (proc == NearestProc::Nearest) { // Arg S must not be zero. fir::IfOp ifOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[1], zeroTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[1], zeroTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError( builder, loc, "intrinsic nearest S argument is zero"); builder.setInsertionPointAfter(ifOp); mlir::Value sSign = IntrinsicLibrary::genIeeeSignbit(intType, {args[1]}); - valueUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, sSign, one); + valueUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, sSign, one); } else if constexpr (proc == NearestProc::NextAfter) { // Convert X and Y to a common type to allow comparison. Direct conversions // between kinds 2, 3, 10, and 16 are not all supported. These conversions @@ -7028,58 +7042,58 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if (xBitWidth > 32 && xBitWidth > yBitWidth) y = builder.createConvert(loc, xType, y); } - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x1, y)); - valueUp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, x1, y); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OEQ, x1, y)); + valueUp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, x1, y); } else if constexpr (proc == NearestProc::NextDown) { valueUp = builder.createBool(loc, false); } else if constexpr (proc == NearestProc::NextUp) { valueUp = builder.createBool(loc, true); } - mlir::Value magnitudeUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, valueUp, + mlir::Value magnitudeUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, valueUp, IntrinsicLibrary::genIeeeSignbit(i1Ty, {args[0]})); - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); // Result is X. (For ieee_next_after with isNan(Y), X has been set to a NaN.) - fir::IfOp outerIfOp = builder.create<fir::IfOp>(loc, resultType, resultIsX, - /*withElseRegion=*/true); + fir::IfOp outerIfOp = fir::IfOp::create(builder, loc, resultType, resultIsX, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); if constexpr (proc == NearestProc::NextDown || proc == NearestProc::NextUp) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, genIsFPClass(i1Ty, x, snanTest)); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); // Result is minPositiveSubnormal or minNegativeSubnormal. (X is zero.) builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); - mlir::Value resultIsMinSubnormal = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x, + mlir::Value resultIsMinSubnormal = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, x, builder.createRealZeroConstant(loc, xType)); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, resultType, resultIsMinSubnormal, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultType, resultIsMinSubnormal, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value minPositiveSubnormal = - builder.create<mlir::arith::BitcastOp>(loc, resultType, one); - mlir::Value minNegativeSubnormal = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::ConstantOp>( - loc, intType, + mlir::arith::BitcastOp::create(builder, loc, resultType, one); + mlir::Value minNegativeSubnormal = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr( intType, llvm::APInt::getBitsSetWithWrap( xBitWidth, /*lo=*/xBitWidth - 1, /*hi=*/1)))); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Result is (X + minPositiveSubnormal) or (X - minPositiveSubnormal). builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); @@ -7105,15 +7119,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, genRuntimeCall("feraiseexcept", i32Ty, excepts); genRuntimeCall("feenableexcept", i32Ty, mask); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } else { // Kind 2, 3, 4, 8, 16. Increment or decrement X cast to integer. - mlir::Value intX = builder.create<mlir::arith::BitcastOp>(loc, intType, x); - mlir::Value add = builder.create<mlir::arith::AddIOp>(loc, intX, one); - mlir::Value sub = builder.create<mlir::arith::SubIOp>(loc, intX, one); - result = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, magnitudeUp, add, sub)); + mlir::Value intX = mlir::arith::BitcastOp::create(builder, loc, intType, x); + mlir::Value add = mlir::arith::AddIOp::create(builder, loc, intX, one); + mlir::Value sub = mlir::arith::SubIOp::create(builder, loc, intX, one); + result = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, magnitudeUp, add, sub)); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) { genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | @@ -7123,11 +7137,11 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, _FORTRAN_RUNTIME_IEEE_INEXACT, genIsFPClass(i1Ty, result, subnormalTest)); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } builder.setInsertionPointAfter(innerIfOp); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -7209,7 +7223,7 @@ IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value boxStorage = builder.createTemporary(loc, boxType); mlir::Value box = fir::factory::createUnallocatedBox( builder, loc, boxType, mold->nonDeferredLenParams()); - builder.create<fir::StoreOp>(loc, box, boxStorage); + fir::StoreOp::create(builder, loc, box, boxStorage); return fir::MutableBoxValue(boxStorage, mold->nonDeferredLenParams(), {}); } @@ -7218,7 +7232,7 @@ template <typename OpTy> mlir::Value IntrinsicLibrary::genNVVMTime(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 0 && "expect no arguments"); - return builder.create<OpTy>(loc, resultType).getResult(); + return OpTy::create(builder, loc, resultType).getResult(); } // PACK @@ -7235,10 +7249,11 @@ IntrinsicLibrary::genPack(mlir::Type resultType, mlir::Value mask = builder.createBox(loc, args[1]); // Handle optional vector argument - mlir::Value vector = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value vector = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 1); @@ -7298,7 +7313,7 @@ void IntrinsicLibrary::genPerror(llvm::ArrayRef<fir::ExtendedValue> args) { fir::ExtendedValue str = args[0]; const auto *box = str.getBoxOf<fir::BoxValue>(); mlir::Value addr = - builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), fir::getBase(*box)); + fir::BoxAddrOp::create(builder, loc, box->getMemTy(), fir::getBase(*box)); fir::runtime::genPerror(builder, loc, addr); } @@ -7307,7 +7322,7 @@ mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - mlir::Value count = builder.create<mlir::math::CtPopOp>(loc, args); + mlir::Value count = mlir::math::CtPopOp::create(builder, loc, args); return builder.createConvert(loc, resultType, count); } @@ -7320,7 +7335,7 @@ mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, mlir::Value count = genPopcnt(resultType, args); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - return builder.create<mlir::arith::AndIOp>(loc, count, one); + return mlir::arith::AndIOp::create(builder, loc, count, one); } // PRESENT @@ -7328,8 +7343,8 @@ fir::ExtendedValue IntrinsicLibrary::genPresent(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - return builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(args[0])); + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(args[0])); } // PRODUCT @@ -7394,7 +7409,7 @@ void IntrinsicLibrary::genRandomSeed(llvm::ArrayRef<fir::ExtendedValue> args) { auto getDesc = [&](int i) { return isStaticallyPresent(args[i]) ? fir::getBase(args[i]) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); }; mlir::Value size = getDesc(0); mlir::Value put = getDesc(1); @@ -7438,13 +7453,13 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, bool absentDim = isStaticallyAbsent(args[2]); auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); mlir::Value identity = isStaticallyAbsent(args[4]) - ? builder.create<fir::AbsentOp>(loc, fir::ReferenceType::get(eleTy)) + ? fir::AbsentOp::create(builder, loc, fir::ReferenceType::get(eleTy)) : fir::getBase(args[4]); mlir::Value ordered = isStaticallyAbsent(args[5]) @@ -7460,7 +7475,7 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, ordered, result, argByRef); if (fir::isa_derived(eleTy)) return result; - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } if (fir::isa_char(eleTy)) { auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(resultType); @@ -7510,7 +7525,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, auto statusAddr = builder.createTemporary(loc, *resultType); auto statusBox = builder.createBox(loc, statusAddr); fir::runtime::genRename(builder, loc, path1, path2, statusBox); - return builder.create<fir::LoadOp>(loc, statusAddr); + return fir::LoadOp::create(builder, loc, statusAddr); } else { // code-gen for the procedure form of RENAME mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); @@ -7518,7 +7533,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, mlir::Value statusBox = isStaticallyPresent(status) ? fir::getBase(status) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genRename(builder, loc, path1, path2, statusBox); return {}; } @@ -7563,16 +7578,18 @@ IntrinsicLibrary::genReshape(mlir::Type resultType, TODO(loc, "intrinsic: reshape requires computing rank of result"); // Handle optional pad argument - mlir::Value pad = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value pad = + isStaticallyAbsent(args[2]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Handle optional order argument - mlir::Value order = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[3]); + mlir::Value order = + isStaticallyAbsent(args[3]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[3]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type type = builder.getVarLenSeqTy(resultType, resultRank); @@ -7643,26 +7660,27 @@ mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType, // If X is finite and result is infinite, signal IEEE_OVERFLOW // If X is finite and scale(result, -I) != X, signal IEEE_UNDERFLOW fir::IfOp outerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[0], finiteTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[0], finiteTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, result, infiniteTest), - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, result, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - mlir::Value minusI = builder.create<mlir::arith::MulIOp>( - loc, args[1], builder.createAllOnesInteger(loc, args[1].getType())); + mlir::Value minusI = mlir::arith::MulIOp::create( + builder, loc, args[1], + builder.createAllOnesInteger(loc, args[1].getType())); mlir::Value reverseResult = builder.createConvert( loc, resultType, fir::runtime::genScale( builder, loc, builder.createConvert(loc, f32Ty, result), minusI)); genRaiseExcept( _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT, - builder.create<mlir::arith::CmpFOp>(loc, mlir::arith::CmpFPredicate::ONE, - args[0], reverseResult)); + mlir::arith::CmpFOp::create(builder, loc, mlir::arith::CmpFPredicate::ONE, + args[0], reverseResult)); builder.setInsertionPointAfter(outerIfOp); return result; } @@ -7714,13 +7732,14 @@ IntrinsicLibrary::genScan(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -7761,7 +7780,7 @@ IntrinsicLibrary::genSecond(std::optional<mlir::Type> resultType, genCpuTime(subroutineArgs); if (resultType) - return builder.create<fir::LoadOp>(loc, fir::getBase(result)); + return fir::LoadOp::create(builder, loc, fir::getBase(result)); return {}; } @@ -7808,22 +7827,22 @@ IntrinsicLibrary::genSelectedRealKind(mlir::Type resultType, // Handle optional precision(P) argument mlir::Value precision = isStaticallyAbsent(args[0]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[0]); // Handle optional range(R) argument mlir::Value range = isStaticallyAbsent(args[1]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[1]); // Handle optional radix(RADIX) argument mlir::Value radix = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[2]); return builder.createConvert( @@ -7861,9 +7880,9 @@ createBoxForRuntimeBoundInquiry(mlir::Location loc, fir::FirOpBuilder &builder, // shape information. mlir::Value localShape = builder.createShape(loc, array); mlir::Value oldBox = boxValue.getAddr(); - return builder.create<fir::ReboxOp>(loc, oldBox.getType(), oldBox, - localShape, - /*slice=*/mlir::Value{}); + return fir::ReboxOp::create(builder, loc, oldBox.getType(), oldBox, + localShape, + /*slice=*/mlir::Value{}); }, [&](const auto &) -> mlir::Value { // This is a pointer/allocatable, or an entity not yet tracked with a @@ -7909,7 +7928,7 @@ genBoundInquiry(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value resultBase = builder.createConvert(loc, baseType, resultStorage); mlir::Value rankValue = - builder.create<fir::BoxRankOp>(loc, builder.getIndexType(), arrayBox); + fir::BoxRankOp::create(builder, loc, builder.getIndexType(), arrayBox); return fir::ArrayBoxValue{resultBase, {rankValue}}; } // Result extent is a compile time constant in the other cases. @@ -7939,9 +7958,9 @@ IntrinsicLibrary::genShape(mlir::Type resultType, mlir::Value extent = fir::factory::readExtent(builder, loc, array, dim); extent = builder.createConvert(loc, extentType, extent); auto index = builder.createIntegerConstant(loc, indexType, dim); - auto shapeAddr = builder.create<fir::CoordinateOp>(loc, shapeAddrType, - shapeArray, index); - builder.create<fir::StoreOp>(loc, extent, shapeAddr); + auto shapeAddr = fir::CoordinateOp::create(builder, loc, shapeAddrType, + shapeArray, index); + fir::StoreOp::create(builder, loc, extent, shapeAddr); } mlir::Value shapeArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -7967,18 +7986,18 @@ mlir::Value IntrinsicLibrary::genShift(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value tooSmall = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); - mlir::Value tooLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); + mlir::Value tooSmall = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); + mlir::Value tooLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); mlir::Value outOfBounds = - builder.create<mlir::arith::OrIOp>(loc, tooSmall, tooLarge); + mlir::arith::OrIOp::create(builder, loc, tooSmall, tooLarge); mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value shifted = builder.create<Shift>(loc, word, shift); + mlir::Value shifted = Shift::create(builder, loc, word, shift); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, outOfBounds, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, outOfBounds, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -7993,8 +8012,8 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value bitSize = builder.createIntegerConstant(loc, signlessType, bits); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value shiftGeBitSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); + mlir::Value shiftGeBitSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); // Lowering of mlir::arith::ShRSIOp is using `ashr`. `ashr` is undefined when // the shift amount is equal to the element size. @@ -8006,13 +8025,13 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value valueIsNeg = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, word, zero); + mlir::Value valueIsNeg = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, word, zero); mlir::Value specialRes = - builder.create<mlir::arith::SelectOp>(loc, valueIsNeg, minusOne, zero); - mlir::Value shifted = builder.create<mlir::arith::ShRSIOp>(loc, word, shift); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, shiftGeBitSize, specialRes, shifted); + mlir::arith::SelectOp::create(builder, loc, valueIsNeg, minusOne, zero); + mlir::Value shifted = mlir::arith::ShRSIOp::create(builder, loc, word, shift); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, shiftGeBitSize, specialRes, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -8037,10 +8056,10 @@ mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto neg = builder.create<mlir::arith::SubIOp>(loc, zero, abs); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, args[1], zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, neg, abs); + auto neg = mlir::arith::SubIOp::create(builder, loc, zero, abs); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, args[1], zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, neg, abs); } return genRuntimeCall("sign", resultType, args); } @@ -8056,7 +8075,7 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); } @@ -8100,14 +8119,14 @@ IntrinsicLibrary::genSize(mlir::Type resultType, .genThen([&]() { mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, array)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .genElse([&]() { - mlir::Value dimValue = builder.create<fir::LoadOp>(loc, dim); + mlir::Value dimValue = fir::LoadOp::create(builder, loc, dim); mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSizeDim(builder, loc, array, dimValue)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .getResults()[0]; } @@ -8118,12 +8137,13 @@ IntrinsicLibrary::genSizeOf(mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); mlir::Value box = fir::getBase(args[0]); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, resultType, box); + mlir::Value eleSize = + fir::BoxEleSizeOp::create(builder, loc, resultType, box); if (!fir::isArray(args[0])) return eleSize; mlir::Value arraySize = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, box)); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, arraySize); + return mlir::arith::MulIOp::create(builder, loc, eleSize, arraySize); } // TAND @@ -8137,7 +8157,7 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); } @@ -8147,81 +8167,83 @@ mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); - mlir::Value blockIdX = builder.create<mlir::NVVM::BlockIdXOp>(loc, i32Ty); - mlir::Value blockIdY = builder.create<mlir::NVVM::BlockIdYOp>(loc, i32Ty); - mlir::Value blockIdZ = builder.create<mlir::NVVM::BlockIdZOp>(loc, i32Ty); + mlir::Value blockIdX = mlir::NVVM::BlockIdXOp::create(builder, loc, i32Ty); + mlir::Value blockIdY = mlir::NVVM::BlockIdYOp::create(builder, loc, i32Ty); + mlir::Value blockIdZ = mlir::NVVM::BlockIdZOp::create(builder, loc, i32Ty); - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); - mlir::Value gridDimX = builder.create<mlir::NVVM::GridDimXOp>(loc, i32Ty); - mlir::Value gridDimY = builder.create<mlir::NVVM::GridDimYOp>(loc, i32Ty); - mlir::Value gridDimZ = builder.create<mlir::NVVM::GridDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); + mlir::Value gridDimX = mlir::NVVM::GridDimXOp::create(builder, loc, i32Ty); + mlir::Value gridDimY = mlir::NVVM::GridDimYOp::create(builder, loc, i32Ty); + mlir::Value gridDimZ = mlir::NVVM::GridDimZOp::create(builder, loc, i32Ty); // this_grid.size = ((blockDim.z * gridDim.z) * (blockDim.y * gridDim.y)) * // (blockDim.x * gridDim.x); mlir::Value resZ = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, gridDimZ); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, gridDimZ); mlir::Value resY = - builder.create<mlir::arith::MulIOp>(loc, blockDimY, gridDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimY, gridDimY); mlir::Value resX = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, gridDimX); - mlir::Value resZY = builder.create<mlir::arith::MulIOp>(loc, resZ, resY); - mlir::Value size = builder.create<mlir::arith::MulIOp>(loc, resZY, resX); + mlir::arith::MulIOp::create(builder, loc, blockDimX, gridDimX); + mlir::Value resZY = mlir::arith::MulIOp::create(builder, loc, resZ, resY); + mlir::Value size = mlir::arith::MulIOp::create(builder, loc, resZY, resX); // tmp = ((blockIdx.z * gridDim.y * gridDim.x) + (blockIdx.y * gridDim.x)) + // blockIdx.x; // this_group.rank = tmp * ((blockDim.x * blockDim.y) * blockDim.z) + // ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value r1 = builder.create<mlir::arith::MulIOp>(loc, blockIdZ, gridDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, gridDimX); - mlir::Value r3 = builder.create<mlir::arith::MulIOp>(loc, blockIdY, gridDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value tmp = builder.create<mlir::arith::AddIOp>(loc, r2r3, blockIdX); + mlir::Value r1 = + mlir::arith::MulIOp::create(builder, loc, blockIdZ, gridDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, gridDimX); + mlir::Value r3 = + mlir::arith::MulIOp::create(builder, loc, blockIdY, gridDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value tmp = mlir::arith::AddIOp::create(builder, loc, r2r3, blockIdX); mlir::Value bXbY = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, blockDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimX, blockDimY); mlir::Value bXbYbZ = - builder.create<mlir::arith::MulIOp>(loc, bXbY, blockDimZ); + mlir::arith::MulIOp::create(builder, loc, bXbY, blockDimZ); mlir::Value tZbY = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); mlir::Value tZbYbX = - builder.create<mlir::arith::MulIOp>(loc, tZbY, blockDimX); + mlir::arith::MulIOp::create(builder, loc, tZbY, blockDimX); mlir::Value tYbX = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value rank = builder.create<mlir::arith::MulIOp>(loc, tmp, bXbYbZ); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tZbYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value rank = mlir::arith::MulIOp::create(builder, loc, tmp, bXbYbZ); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tZbYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8232,50 +8254,50 @@ IntrinsicLibrary::genThisThreadBlock(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // this_thread_block%size = blockDim.z * blockDim.y * blockDim.x; - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); mlir::Value size = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, blockDimY); - size = builder.create<mlir::arith::MulIOp>(loc, size, blockDimX); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, blockDimY); + size = mlir::arith::MulIOp::create(builder, loc, size, blockDimX); // this_thread_block%rank = ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); mlir::Value r1 = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, blockDimX); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, blockDimX); mlir::Value r3 = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, r2r3, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, r2r3, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8285,7 +8307,7 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // coalesced_group%size = 32 @@ -8293,28 +8315,28 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); // coalesced_group%rank = threadIdx.x & 31 + 1 - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); mlir::Value mask = builder.createIntegerConstant(loc, i32Ty, 31); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); mlir::Value masked = - builder.create<mlir::arith::AndIOp>(loc, threadIdX, mask); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, masked, one); + mlir::arith::AndIOp::create(builder, loc, threadIdX, mask); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, masked, one); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8324,7 +8346,7 @@ mlir::Value IntrinsicLibrary::genTrailz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountTrailingZerosOp>(loc, args); + mlir::math::CountTrailingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -8352,10 +8374,10 @@ static mlir::Value computeLBOUND(fir::FirOpBuilder &builder, mlir::Location loc, zero = builder.createConvert(loc, extent.getType(), zero); // Note: for assumed size, the extent is -1, and the lower bound should // be returned. It is important to test extent == 0 and not extent > 0. - auto dimIsEmpty = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); + auto dimIsEmpty = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); one = builder.createConvert(loc, lb.getType(), one); - return builder.create<mlir::arith::SelectOp>(loc, dimIsEmpty, one, lb); + return mlir::arith::SelectOp::create(builder, loc, dimIsEmpty, one, lb); } // LBOUND @@ -8391,8 +8413,8 @@ IntrinsicLibrary::genLbound(mlir::Type resultType, lb = builder.createConvert(loc, lbType, lb); auto index = builder.createIntegerConstant(loc, indexType, dim); auto lbAddr = - builder.create<fir::CoordinateOp>(loc, lbAddrType, lbArray, index); - builder.create<fir::StoreOp>(loc, lb, lbAddr); + fir::CoordinateOp::create(builder, loc, lbAddrType, lbArray, index); + fir::StoreOp::create(builder, loc, lb, lbAddr); } mlir::Value lbArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -8431,8 +8453,8 @@ IntrinsicLibrary::genUbound(mlir::Type resultType, mlir::Value lbound = fir::getBase(genLbound(resultType, args)); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - mlir::Value ubound = builder.create<mlir::arith::SubIOp>(loc, lbound, one); - return builder.create<mlir::arith::AddIOp>(loc, ubound, extent); + mlir::Value ubound = mlir::arith::SubIOp::create(builder, loc, lbound, one); + return mlir::arith::AddIOp::create(builder, loc, ubound, extent); } // Handle calls to UBOUND without the DIM argument, which return an array int kindPos = args.size() == 2 ? 1 : 2; @@ -8526,9 +8548,9 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType, box = builder.createBox(loc, args[0], /*isPolymorphic=*/args[0].isPolymorphic()); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, kindTy, box); + mlir::Value eleSize = fir::BoxEleSizeOp::create(builder, loc, kindTy, box); mlir::Value c8 = builder.createIntegerConstant(loc, kindTy, 8); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, c8); + return mlir::arith::MulIOp::create(builder, loc, eleSize, c8); } // SUM @@ -8541,7 +8563,7 @@ IntrinsicLibrary::genSum(mlir::Type resultType, // SYNCTHREADS void IntrinsicLibrary::genSyncThreads(llvm::ArrayRef<fir::ExtendedValue> args) { - builder.create<mlir::NVVM::Barrier0Op>(loc); + mlir::NVVM::Barrier0Op::create(builder, loc); } // SYNCTHREADS_AND @@ -8553,7 +8575,7 @@ IntrinsicLibrary::genSyncThreadsAnd(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_COUNT @@ -8565,7 +8587,7 @@ IntrinsicLibrary::genSyncThreadsCount(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_OR @@ -8577,7 +8599,7 @@ IntrinsicLibrary::genSyncThreadsOr(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCWARP @@ -8589,7 +8611,7 @@ void IntrinsicLibrary::genSyncWarp(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {mask.getType()}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> argsList{mask}; - builder.create<fir::CallOp>(loc, funcOp, argsList); + fir::CallOp::create(builder, loc, funcOp, argsList); } // SYSTEM @@ -8615,25 +8637,26 @@ IntrinsicLibrary::genSystem(std::optional<mlir::Type> resultType, mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); // Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself // when cmdstat is assigned with a non-zero value but not present mlir::Value tempValue = builder.createIntegerConstant(loc, builder.getI16Type(), 0); mlir::Value temp = builder.createTemporary(loc, builder.getI16Type()); - builder.create<fir::StoreOp>(loc, tempValue, temp); + fir::StoreOp::create(builder, loc, tempValue, temp); mlir::Value cmdstatBox = builder.createBox(loc, temp); mlir::Value cmdmsgBox = - builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); if (resultType) { - mlir::Value exitstatAddr = builder.create<fir::BoxAddrOp>(loc, exitstatBox); - return builder.create<fir::LoadOp>(loc, fir::getBase(exitstatAddr)); + mlir::Value exitstatAddr = + fir::BoxAddrOp::create(builder, loc, exitstatBox); + return fir::LoadOp::create(builder, loc, fir::getBase(exitstatAddr)); } return {}; } @@ -8729,7 +8752,7 @@ void IntrinsicLibrary::genThreadFence(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_BLOCK @@ -8740,7 +8763,7 @@ void IntrinsicLibrary::genThreadFenceBlock( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_SYSTEM @@ -8751,7 +8774,7 @@ void IntrinsicLibrary::genThreadFenceSystem( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // TIME @@ -8803,29 +8826,30 @@ static mlir::Value createExtremumCompare(mlir::Location loc, // Return the number if one of the inputs is NaN and the other is // a number. auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto rightIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, right, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto rightIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, right, right); result = - builder.create<mlir::arith::OrIOp>(loc, leftIsResult, rightIsNan); + mlir::arith::OrIOp::create(builder, loc, leftIsResult, rightIsNan); } else if constexpr (behavior == ExtremumBehavior::IeeeMinMaximum) { // Always return NaNs if one the input is NaNs auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto leftIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, left, left); - result = builder.create<mlir::arith::OrIOp>(loc, leftIsResult, leftIsNan); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto leftIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, left, left); + result = + mlir::arith::OrIOp::create(builder, loc, leftIsResult, leftIsNan); } else if constexpr (behavior == ExtremumBehavior::MinMaxss) { // If the left is a NaN, return the right whatever it is. result = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); } else if constexpr (behavior == ExtremumBehavior::PgfortranLlvm) { // If one of the operand is a NaN, return left whatever it is. static constexpr auto unorderedCmp = extremum == Extremum::Max ? mlir::arith::CmpFPredicate::UGT : mlir::arith::CmpFPredicate::ULT; result = - builder.create<mlir::arith::CmpFOp>(loc, unorderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, unorderedCmp, left, right); } else { // TODO: ieeeMinNum/ieeeMaxNum static_assert(behavior == ExtremumBehavior::IeeeMinMaxNum, @@ -8839,8 +8863,8 @@ static mlir::Value createExtremumCompare(mlir::Location loc, left = builder.createConvert(loc, signlessType, left); right = builder.createConvert(loc, signlessType, right); } - result = - builder.create<mlir::arith::CmpIOp>(loc, integerPredicate, left, right); + result = mlir::arith::CmpIOp::create(builder, loc, integerPredicate, left, + right); } else if (fir::isa_char(type) || fir::isa_char(fir::unwrapRefType(type))) { // TODO: ! character min and max is tricky because the result // length is the length of the longest argument! @@ -8961,13 +8985,14 @@ IntrinsicLibrary::genVerify(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -9007,8 +9032,8 @@ IntrinsicLibrary::genExtremumloc(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); // Handle optional kind argument @@ -9090,8 +9115,8 @@ IntrinsicLibrary::genExtremumVal(FN func, FD funcDim, FC funcChar, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -9155,7 +9180,7 @@ mlir::Value IntrinsicLibrary::genExtremum(mlir::Type, for (auto arg : args.drop_front()) { mlir::Value mask = createExtremumCompare<extremum, behavior>(loc, builder, result, arg); - result = builder.create<mlir::arith::SelectOp>(loc, mask, result, arg); + result = mlir::arith::SelectOp::create(builder, loc, mask, result, arg); } return result; } diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp index 93abedc..50c945d 100644 --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -35,7 +35,7 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value shape; if (!extents.empty()) { if (lbounds.empty()) { - shape = builder.create<fir::ShapeOp>(loc, extents); + shape = fir::ShapeOp::create(builder, loc, extents); } else { llvm::SmallVector<mlir::Value> shapeShiftBounds; for (auto [lb, extent] : llvm::zip(lbounds, extents)) { @@ -44,8 +44,8 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, } auto shapeShiftType = fir::ShapeShiftType::get(builder.getContext(), extents.size()); - shape = builder.create<fir::ShapeShiftOp>(loc, shapeShiftType, - shapeShiftBounds); + shape = fir::ShapeShiftOp::create(builder, loc, shapeShiftType, + shapeShiftBounds); } } // Otherwise, this a scalar. Leave the shape empty. @@ -78,8 +78,8 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value emptySlice; auto boxType = fir::updateTypeWithVolatility( box.getBoxTy(), fir::isa_volatile_type(cleanedAddr.getType())); - return builder.create<fir::EmboxOp>(loc, boxType, cleanedAddr, shape, - emptySlice, cleanedLengths, tdesc); + return fir::EmboxOp::create(builder, loc, boxType, cleanedAddr, shape, + emptySlice, cleanedLengths, tdesc); } //===----------------------------------------------------------------------===// @@ -106,7 +106,7 @@ public: bool forceIRBoxRead = false) : builder{builder}, loc{loc}, box{box} { if (forceIRBoxRead || !box.isDescribedByVariables()) - irBox = builder.create<fir::LoadOp>(loc, box.getAddr()); + irBox = fir::LoadOp::create(builder, loc, box.getAddr()); } /// Get base address of allocated/associated entity. mlir::Value readBaseAddress() { @@ -114,10 +114,10 @@ public: auto memrefTy = box.getBoxTy().getEleTy(); if (!fir::isa_ref_type(memrefTy)) memrefTy = builder.getRefType(memrefTy); - return builder.create<fir::BoxAddrOp>(loc, memrefTy, irBox); + return fir::BoxAddrOp::create(builder, loc, memrefTy, irBox); } auto addrVar = box.getMutableProperties().addr; - return builder.create<fir::LoadOp>(loc, addrVar); + return fir::LoadOp::create(builder, loc, addrVar); } /// Return {lbound, extent} values read from the MutableBoxValue given /// the dimension. @@ -125,13 +125,14 @@ public: auto idxTy = builder.getIndexType(); if (irBox) { auto dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - irBox, dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + irBox, dimVal); return {dimInfo.getResult(0), dimInfo.getResult(1)}; } const auto &mutableProperties = box.getMutableProperties(); - auto lb = builder.create<fir::LoadOp>(loc, mutableProperties.lbounds[dim]); - auto ext = builder.create<fir::LoadOp>(loc, mutableProperties.extents[dim]); + auto lb = fir::LoadOp::create(builder, loc, mutableProperties.lbounds[dim]); + auto ext = + fir::LoadOp::create(builder, loc, mutableProperties.extents[dim]); return {lb, ext}; } @@ -146,7 +147,7 @@ public: const auto &deferred = box.getMutableProperties().deferredParams; if (deferred.empty()) fir::emitFatalError(loc, "allocatable entity has no length property"); - return builder.create<fir::LoadOp>(loc, deferred[0]); + return fir::LoadOp::create(builder, loc, deferred[0]); } /// Read and return all extents. If \p lbounds vector is provided, lbounds are @@ -223,7 +224,7 @@ public: /// all that can be described in the new fir.box (e.g. non contiguous entity). void updateWithIrBox(mlir::Value newBox) { assert(!box.isDescribedByVariables()); - builder.create<fir::StoreOp>(loc, newBox, box.getAddr()); + fir::StoreOp::create(builder, loc, newBox, box.getAddr()); } /// Set unallocated/disassociated status for the entity described by /// MutableBoxValue. Deallocation is not performed by this helper. @@ -231,8 +232,8 @@ public: if (box.isDescribedByVariables()) { auto addrVar = box.getMutableProperties().addr; auto nullTy = fir::dyn_cast_ptrEleTy(addrVar.getType()); - builder.create<fir::StoreOp>(loc, builder.createNullConstant(loc, nullTy), - addrVar); + fir::StoreOp::create(builder, loc, + builder.createNullConstant(loc, nullTy), addrVar); } else { // Note that the dynamic type of polymorphic entities must be reset to the // declaration type of the mutable box. See Fortran 2018 7.8.2 NOTE 1. @@ -246,7 +247,7 @@ public: auto deallocatedBox = fir::factory::createUnallocatedBox( builder, loc, box.getBoxTy(), box.nonDeferredLenParams(), typeSourceBox, allocator); - builder.create<fir::StoreOp>(loc, deallocatedBox, box.getAddr()); + fir::StoreOp::create(builder, loc, deallocatedBox, box.getAddr()); } } @@ -286,7 +287,7 @@ private: const bool valueTypeIsVolatile = fir::isa_volatile_type(fir::unwrapRefType(box.getAddr().getType())); irBox = builder.createVolatileCast(loc, valueTypeIsVolatile, irBox); - builder.create<fir::StoreOp>(loc, irBox, box.getAddr()); + fir::StoreOp::create(builder, loc, irBox, box.getAddr()); } /// Update the set of property variables of the MutableBoxValue. @@ -295,8 +296,8 @@ private: mlir::ValueRange lengths) { auto castAndStore = [&](mlir::Value val, mlir::Value addr) { auto type = fir::dyn_cast_ptrEleTy(addr.getType()); - builder.create<fir::StoreOp>(loc, builder.createConvert(loc, type, val), - addr); + fir::StoreOp::create(builder, loc, builder.createConvert(loc, type, val), + addr); }; const auto &mutableProperties = box.getMutableProperties(); castAndStore(addr, mutableProperties.addr); @@ -379,8 +380,8 @@ mlir::Value fir::factory::createUnallocatedBox( } } mlir::Value emptySlice; - auto embox = builder.create<fir::EmboxOp>( - loc, baseBoxType, nullAddr, shape, emptySlice, lenParams, typeSourceBox); + auto embox = fir::EmboxOp::create(builder, loc, baseBoxType, nullAddr, shape, + emptySlice, lenParams, typeSourceBox); if (allocator != 0) embox.setAllocatorIdx(allocator); if (isAssumedRank) @@ -459,7 +460,7 @@ fir::factory::genMutableBoxRead(fir::FirOpBuilder &builder, mlir::Location loc, } mlir::Value sourceBox; if (box.isPolymorphic()) - sourceBox = builder.create<fir::LoadOp>(loc, box.getAddr()); + sourceBox = fir::LoadOp::create(builder, loc, box.getAddr()); if (rank) return fir::ArrayBoxValue{addr, extents, lbounds, sourceBox}; if (box.isPolymorphic()) @@ -490,7 +491,7 @@ static void genFreemem(fir::FirOpBuilder &builder, mlir::Location loc, // so make sure the heap type is restored before deallocation. auto cast = builder.createConvert( loc, fir::HeapType::get(fir::dyn_cast_ptrEleTy(addr.getType())), addr); - builder.create<fir::FreeMemOp>(loc, cast); + fir::FreeMemOp::create(builder, loc, cast); } void fir::factory::genFreememIfAllocated(fir::FirOpBuilder &builder, @@ -498,8 +499,8 @@ void fir::factory::genFreememIfAllocated(fir::FirOpBuilder &builder, const fir::MutableBoxValue &box) { auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress(); auto isAllocated = builder.genIsNotNullAddr(loc, addr); - auto ifOp = builder.create<fir::IfOp>(loc, isAllocated, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, isAllocated, + /*withElseRegion=*/false); auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); ::genFreemem(builder, loc, addr); @@ -553,15 +554,15 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder, if (box.hasAssumedRank()) { assert(arr.hasAssumedRank() && "expect both arr and box to be assumed-rank"); - mlir::Value reboxed = builder.create<fir::ReboxAssumedRankOp>( - loc, box.getBoxTy(), arr.getAddr(), + mlir::Value reboxed = fir::ReboxAssumedRankOp::create( + builder, loc, box.getBoxTy(), arr.getAddr(), fir::LowerBoundModifierAttribute::Preserve); writer.updateWithIrBox(reboxed); } else if (box.isDescribedByVariables()) { // LHS is a contiguous pointer described by local variables. Open RHS // fir.box to update the LHS. - auto rawAddr = builder.create<fir::BoxAddrOp>(loc, arr.getMemTy(), - arr.getAddr()); + auto rawAddr = fir::BoxAddrOp::create(builder, loc, arr.getMemTy(), + arr.getAddr()); auto extents = fir::factory::getExtents(loc, builder, source); llvm::SmallVector<mlir::Value> lenParams; if (arr.isCharacter()) { @@ -576,11 +577,11 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder, if (!newLbounds.empty()) { auto shiftType = fir::ShiftType::get(builder.getContext(), newLbounds.size()); - shift = builder.create<fir::ShiftOp>(loc, shiftType, newLbounds); + shift = fir::ShiftOp::create(builder, loc, shiftType, newLbounds); } auto reboxed = - builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(), - shift, /*slice=*/mlir::Value()); + fir::ReboxOp::create(builder, loc, box.getBoxTy(), arr.getAddr(), + shift, /*slice=*/mlir::Value()); writer.updateWithIrBox(reboxed); } }, @@ -608,9 +609,9 @@ void fir::factory::associateMutableBoxWithRemap( for (auto [lb, ub] : llvm::zip(lbounds, ubounds)) { auto lbi = builder.createConvert(loc, idxTy, lb); auto ubi = builder.createConvert(loc, idxTy, ub); - auto diff = builder.create<mlir::arith::SubIOp>(loc, idxTy, ubi, lbi); + auto diff = mlir::arith::SubIOp::create(builder, loc, idxTy, ubi, lbi); extents.emplace_back( - builder.create<mlir::arith::AddIOp>(loc, idxTy, diff, one)); + mlir::arith::AddIOp::create(builder, loc, idxTy, diff, one)); } } else { // lbounds are default. Upper bounds and extents are the same. @@ -657,8 +658,8 @@ void fir::factory::associateMutableBoxWithRemap( if (box.isDescribedByVariables()) { // LHS is a contiguous pointer described by local variables. Open RHS // fir.box to update the LHS. - auto rawAddr = builder.create<fir::BoxAddrOp>(loc, arr.getMemTy(), - arr.getAddr()); + auto rawAddr = fir::BoxAddrOp::create(builder, loc, arr.getMemTy(), + arr.getAddr()); llvm::SmallVector<mlir::Value> lenParams; if (arr.isCharacter()) { lenParams.emplace_back( @@ -678,10 +679,10 @@ void fir::factory::associateMutableBoxWithRemap( shapeArgs.push_back(ext); } auto shape = - builder.create<fir::ShapeShiftOp>(loc, shapeType, shapeArgs); + fir::ShapeShiftOp::create(builder, loc, shapeType, shapeArgs); auto reboxed = - builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(), - shape, /*slice=*/mlir::Value()); + fir::ReboxOp::create(builder, loc, box.getBoxTy(), arr.getAddr(), + shape, /*slice=*/mlir::Value()); writer.updateWithIrBox(reboxed); } }, @@ -748,8 +749,8 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder, mlir::ValueRange lenParams, llvm::StringRef allocName) { auto lengths = getNewLengths(builder, loc, box, lenParams); - auto newStorage = builder.create<fir::AllocMemOp>( - loc, box.getBaseTy(), allocName, lengths, extents); + auto newStorage = fir::AllocMemOp::create(builder, loc, box.getBaseTy(), + allocName, lengths, extents); if (mlir::isa<fir::RecordType>(box.getEleTy())) { // TODO: skip runtime initialization if this is not required. Currently, // there is no way to know here if a derived type needs it or not. But the @@ -771,8 +772,8 @@ void fir::factory::genInlinedAllocation( llvm::SmallVector<mlir::Value> safeExtents; for (mlir::Value extent : extents) safeExtents.push_back(fir::factory::genMaxWithZero(builder, loc, extent)); - auto heap = builder.create<fir::AllocMemOp>(loc, box.getBaseTy(), allocName, - lengths, safeExtents); + auto heap = fir::AllocMemOp::create(builder, loc, box.getBaseTy(), allocName, + lengths, safeExtents); MutablePropertyWriter{builder, loc, box}.updateMutableBox( heap, lbounds, safeExtents, lengths); if (mlir::isa<fir::RecordType>(box.getEleTy())) { @@ -841,10 +842,11 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( mlir::Value required) { auto castPrevious = builder.createConvert(loc, required.getType(), previous); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, castPrevious, required); - mustReallocate = builder.create<mlir::arith::SelectOp>( - loc, cmp, cmp, mustReallocate); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, castPrevious, + required); + mustReallocate = mlir::arith::SelectOp::create( + builder, loc, cmp, cmp, mustReallocate); }; llvm::SmallVector<mlir::Value> previousExtents = reader.readShape(); if (!shape.empty()) @@ -879,17 +881,17 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( ".auto.alloc"); if (storageHandler) storageHandler(getExtValForStorage(heap)); - builder.create<fir::ResultOp>(loc, heap); + fir::ResultOp::create(builder, loc, heap); }) .genElse([&]() { if (storageHandler) storageHandler(getExtValForStorage(addr)); - builder.create<fir::ResultOp>(loc, addr); + fir::ResultOp::create(builder, loc, addr); }); ifOp.end(); auto newAddr = ifOp.getResults()[0]; - builder.create<fir::ResultOp>( - loc, mlir::ValueRange{mustReallocate, newAddr}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{mustReallocate, newAddr}); }) .genElse([&]() { auto trueValue = builder.createBool(loc, true); @@ -900,15 +902,15 @@ fir::factory::MutableBoxReallocation fir::factory::genReallocIfNeeded( builder, loc, "array left hand side must be allocated when the right hand " "side is a scalar"); - builder.create<fir::ResultOp>(loc, - mlir::ValueRange{trueValue, addr}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{trueValue, addr}); } else { auto heap = allocateAndInitNewStorage( builder, loc, box, shape, lengthParams, ".auto.alloc"); if (storageHandler) storageHandler(getExtValForStorage(heap)); - builder.create<fir::ResultOp>(loc, - mlir::ValueRange{trueValue, heap}); + fir::ResultOp::create(builder, loc, + mlir::ValueRange{trueValue, heap}); } }); ifOp.end(); @@ -976,7 +978,7 @@ mlir::Value fir::factory::genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( builder, loc, boxTy, /*nonDeferredParams=*/{}); - builder.create<fir::StoreOp>(loc, nullBox, boxStorage); + fir::StoreOp::create(builder, loc, nullBox, boxStorage); return boxStorage; } @@ -988,11 +990,11 @@ mlir::Value fir::factory::getAndEstablishBoxStorage( mlir::Value nullAddr = builder.createNullConstant(loc, boxTy.getBaseAddressType()); mlir::Value box = - builder.create<fir::EmboxOp>(loc, boxTy, nullAddr, shape, - /*emptySlice=*/mlir::Value{}, - fir::factory::elideLengthsAlreadyInType( - boxTy.unwrapInnerType(), typeParams), - polymorphicMold); - builder.create<fir::StoreOp>(loc, box, boxStorage); + fir::EmboxOp::create(builder, loc, boxTy, nullAddr, shape, + /*emptySlice=*/mlir::Value{}, + fir::factory::elideLengthsAlreadyInType( + boxTy.unwrapInnerType(), typeParams), + polymorphicMold); + fir::StoreOp::create(builder, loc, box, boxStorage); return boxStorage; } diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp index 0094ce89..03952da 100644 --- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp @@ -17,6 +17,7 @@ #include "flang/Evaluate/common.h" #include "flang/Optimizer/Builder/FIRBuilder.h" #include "flang/Optimizer/Builder/MutableBox.h" +#include "mlir/Dialect/Index/IR/IndexOps.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" namespace fir { @@ -1090,7 +1091,7 @@ void PPCIntrinsicLibrary::genMtfsf(llvm::ArrayRef<fir::ExtendedValue> args) { builder.getContext(), builder); funcOp = builder.createFunction(loc, "llvm.ppc.mtfsf", libFuncType); } - builder.create<fir::CallOp>(loc, funcOp, scalarArgs); + fir::CallOp::create(builder, loc, funcOp, scalarArgs); } // VEC_ABS @@ -1117,7 +1118,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, } funcOp = builder.createFunction(loc, fname, ftype); - auto callOp{builder.create<fir::CallOp>(loc, funcOp, argBases[0])}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, argBases[0])}; return callOp.getResult(0); } else if (auto eleTy = mlir::dyn_cast<mlir::IntegerType>(vTypeInfo.eleTy)) { // vec_abs(arg1) = max(0 - arg1, arg1) @@ -1127,8 +1128,8 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, // construct vector(0,..) auto zeroVal{builder.createIntegerConstant(loc, eleTy, 0)}; auto vZero{ - builder.create<mlir::vector::BroadcastOp>(loc, newVecTy, zeroVal)}; - auto zeroSubVarg1{builder.create<mlir::arith::SubIOp>(loc, vZero, varg1)}; + mlir::vector::BroadcastOp::create(builder, loc, newVecTy, zeroVal)}; + auto zeroSubVarg1{mlir::arith::SubIOp::create(builder, loc, vZero, varg1)}; mlir::func::FuncOp funcOp{nullptr}; switch (eleTy.getWidth()) { @@ -1158,7 +1159,7 @@ PPCIntrinsicLibrary::genVecAbs(mlir::Type resultType, funcOp = builder.createFunction(loc, fname, ftype); mlir::Value args[] = {zeroSubVarg1, varg1}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, args)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, args)}; return builder.createConvert(loc, argBases[0].getType(), callOp.getResult(0)); } @@ -1188,21 +1189,21 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( switch (vop) { case VecOp::Add: if (isInteger) - r = builder.create<mlir::arith::AddIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::AddIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::AddFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::AddFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::Mul: if (isInteger) - r = builder.create<mlir::arith::MulIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::MulIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::MulFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::MulFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::Sub: if (isInteger) - r = builder.create<mlir::arith::SubIOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::SubIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create<mlir::arith::SubFOp>(loc, vargs[0], vargs[1]); + r = mlir::arith::SubFOp::create(builder, loc, vargs[0], vargs[1]); break; case VecOp::And: case VecOp::Xor: { @@ -1216,16 +1217,16 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecAddAndMulSubXor( auto wd{mlir::dyn_cast<mlir::FloatType>(vecTyInfo.eleTy).getWidth()}; auto ftype{builder.getIntegerType(wd)}; auto bcVecTy{mlir::VectorType::get(vecTyInfo.len, ftype)}; - arg1 = builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[0]); - arg2 = builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[1]); + arg1 = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[0]); + arg2 = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[1]); } if (vop == VecOp::And) - r = builder.create<mlir::arith::AndIOp>(loc, arg1, arg2); + r = mlir::arith::AndIOp::create(builder, loc, arg1, arg2); else if (vop == VecOp::Xor) - r = builder.create<mlir::arith::XOrIOp>(loc, arg1, arg2); + r = mlir::arith::XOrIOp::create(builder, loc, arg1, arg2); if (isFloat) - r = builder.create<mlir::vector::BitCastOp>(loc, vargs[0].getType(), r); + r = mlir::vector::BitCastOp::create(builder, loc, vargs[0].getType(), r); break; } @@ -1341,7 +1342,7 @@ PPCIntrinsicLibrary::genVecAnyCompare(mlir::Type resultType, assert((!fname.empty() && ftype) && "invalid type"); mlir::func::FuncOp funcOp{builder.createFunction(loc, fname, ftype)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, cmpArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, cmpArgs)}; return callOp.getResult(0); } @@ -1472,7 +1473,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, // arg1 < arg2 --> vcmpgt(arg2, arg1) mlir::Value vargs[]{argBases[argOrder[vop][0]], argBases[argOrder[vop][1]]}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; res = callOp.getResult(0); break; } @@ -1486,14 +1487,15 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, // Construct a constant vector(-1) auto negOneVal{builder.createIntegerConstant( loc, getConvertedElementType(context, eTy), -1)}; - auto vNegOne{builder.create<mlir::vector::BroadcastOp>( - loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; + auto vNegOne{mlir::vector::BroadcastOp::create( + builder, loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; mlir::Value callRes{callOp.getResult(0)}; auto vargs2{ convertVecArgs(builder, loc, vecTyInfo, mlir::ValueRange{callRes})}; - auto xorRes{builder.create<mlir::arith::XOrIOp>(loc, vargs2[0], vNegOne)}; + auto xorRes{ + mlir::arith::XOrIOp::create(builder, loc, vargs2[0], vNegOne)}; res = builder.createConvert(loc, returnType, xorRes); break; @@ -1518,7 +1520,7 @@ PPCIntrinsicLibrary::genVecCmp(mlir::Type resultType, default: llvm_unreachable("Invalid vector operation for generator"); } - auto callOp{builder.create<fir::CallOp>(loc, funcOp, vargs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, vargs)}; res = callOp.getResult(0); } else llvm_unreachable("invalid vector type"); @@ -1534,13 +1536,13 @@ static inline mlir::Value swapVectorWordPairs(fir::FirOpBuilder &builder, auto vtype{mlir::VectorType::get(16, mlir::IntegerType::get(context, 8))}; if (ty != vtype) - arg = builder.create<mlir::LLVM::BitcastOp>(loc, vtype, arg).getResult(); + arg = mlir::LLVM::BitcastOp::create(builder, loc, vtype, arg).getResult(); llvm::SmallVector<int64_t, 16> mask{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}; - arg = builder.create<mlir::vector::ShuffleOp>(loc, arg, arg, mask); + arg = mlir::vector::ShuffleOp::create(builder, loc, arg, arg, mask); if (ty != vtype) - arg = builder.create<mlir::LLVM::BitcastOp>(loc, ty, arg); + arg = mlir::LLVM::BitcastOp::create(builder, loc, ty, arg); return arg; } @@ -1575,7 +1577,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, : "llvm.ppc.altivec.vcfsx"}; auto funcOp{builder.createFunction(loc, fname, ftype)}; mlir::Value newArgs[] = {argBases[0], convArg}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } else if (width == 64) { @@ -1584,8 +1586,8 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, // vec_vtf(arg1, arg2) = fmul(1.0 / (1 << arg2), llvm.sitofp(arg1)) auto convOp{(isUnsigned) - ? builder.create<mlir::LLVM::UIToFPOp>(loc, ty, vArg1) - : builder.create<mlir::LLVM::SIToFPOp>(loc, ty, vArg1)}; + ? mlir::LLVM::UIToFPOp::create(builder, loc, ty, vArg1) + : mlir::LLVM::SIToFPOp::create(builder, loc, ty, vArg1)}; // construct vector<1./(1<<arg1), 1.0/(1<<arg1)> auto constInt{mlir::dyn_cast_or_null<mlir::IntegerAttr>( @@ -1594,11 +1596,11 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, assert(constInt && "expected integer constant argument"); double f{1.0 / (1 << constInt.getInt())}; llvm::SmallVector<double> vals{f, f}; - auto constOp{builder.create<mlir::arith::ConstantOp>( - loc, ty, builder.getF64VectorAttr(vals))}; + auto constOp{mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getF64VectorAttr(vals))}; - auto mulOp{builder.create<mlir::LLVM::FMulOp>( - loc, ty, convOp->getResult(0), constOp)}; + auto mulOp{mlir::LLVM::FMulOp::create(builder, loc, ty, + convOp->getResult(0), constOp)}; return builder.createConvert(loc, fir::VectorType::get(2, fTy), mulOp); } @@ -1612,7 +1614,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, auto firTy{resTyInfo.toFirVectorType()}; // vec_convert(v, mold) = bitcast v to "type of mold" - auto conv{builder.create<mlir::LLVM::BitcastOp>(loc, moldTy, vArg1)}; + auto conv{mlir::LLVM::BitcastOp::create(builder, loc, moldTy, vArg1)}; return builder.createConvert(loc, firTy, conv); } @@ -1628,7 +1630,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, auto ftype{ genFuncType<Ty::RealVector<8>, Ty::RealVector<4>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } else if (vecTyInfo.isFloat64()) { @@ -1637,7 +1639,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, genFuncType<Ty::RealVector<4>, Ty::RealVector<8>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; newArgs[0] = - builder.create<fir::CallOp>(loc, funcOp, newArgs).getResult(0); + fir::CallOp::create(builder, loc, funcOp, newArgs).getResult(0); auto fvf32Ty{newArgs[0].getType()}; auto f32type{mlir::Float32Type::get(context)}; auto mvf32Ty{mlir::VectorType::get(4, f32type)}; @@ -1661,7 +1663,7 @@ static mlir::Value convertVectorElementOrder(fir::FirOpBuilder &builder, mlir::Value idx) { mlir::Value numSub1{ builder.createIntegerConstant(loc, idx.getType(), vecInfo.len - 1)}; - return builder.create<mlir::LLVM::SubOp>(loc, idx.getType(), numSub1, idx); + return mlir::LLVM::SubOp::create(builder, loc, idx.getType(), numSub1, idx); } // VEC_EXTRACT @@ -1680,12 +1682,14 @@ PPCIntrinsicLibrary::genVecExtract(mlir::Type resultType, // position auto numEle{builder.createIntegerConstant(loc, argTypes[1], vecTyInfo.len)}; mlir::Value uremOp{ - builder.create<mlir::LLVM::URemOp>(loc, argBases[1], numEle)}; + mlir::LLVM::URemOp::create(builder, loc, argBases[1], numEle)}; if (!isNativeVecElemOrderOnLE()) uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp); - return builder.create<mlir::vector::ExtractElementOp>(loc, varg0, uremOp); + mlir::Value index = builder.createOrFold<mlir::index::CastUOp>( + loc, builder.getIndexType(), uremOp); + return mlir::vector::ExtractOp::create(builder, loc, varg0, index); } // VEC_INSERT @@ -1701,14 +1705,16 @@ PPCIntrinsicLibrary::genVecInsert(mlir::Type resultType, auto numEle{builder.createIntegerConstant(loc, argTypes[2], vecTyInfo.len)}; mlir::Value uremOp{ - builder.create<mlir::LLVM::URemOp>(loc, argBases[2], numEle)}; + mlir::LLVM::URemOp::create(builder, loc, argBases[2], numEle)}; if (!isNativeVecElemOrderOnLE()) uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp); - auto res{builder.create<mlir::vector::InsertElementOp>(loc, argBases[0], - varg1, uremOp)}; - return builder.create<fir::ConvertOp>(loc, vecTyInfo.toFirVectorType(), res); + mlir::Value index = builder.createOrFold<mlir::index::CastUOp>( + loc, builder.getIndexType(), uremOp); + mlir::Value res = + mlir::vector::InsertOp::create(builder, loc, argBases[0], varg1, index); + return fir::ConvertOp::create(builder, loc, vecTyInfo.toFirVectorType(), res); } // VEC_MERGEH, VEC_MERGEL @@ -1794,8 +1800,8 @@ PPCIntrinsicLibrary::genVecMerge(mlir::Type resultType, llvm::SmallVector<int64_t, 16> &mergeMask = (isBEVecElemOrderOnLE()) ? rMask : mMask; - auto callOp{builder.create<mlir::vector::ShuffleOp>(loc, vargs[0], vargs[1], - mergeMask)}; + auto callOp{mlir::vector::ShuffleOp::create(builder, loc, vargs[0], vargs[1], + mergeMask)}; return builder.createConvert(loc, resultType, callOp); } @@ -1807,9 +1813,9 @@ static mlir::Value addOffsetToAddress(fir::FirOpBuilder &builder, auto arrRefTy{builder.getRefType(fir::SequenceType::get( {typeExtent}, mlir::IntegerType::get(builder.getContext(), 8)))}; // Convert arg to !fir.ref<!ref.array<?xi8>> - auto resAddr{builder.create<fir::ConvertOp>(loc, arrRefTy, baseAddr)}; + auto resAddr{fir::ConvertOp::create(builder, loc, arrRefTy, baseAddr)}; - return builder.create<fir::CoordinateOp>(loc, arrRefTy, resAddr, offset); + return fir::CoordinateOp::create(builder, loc, arrRefTy, resAddr, offset); } static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder, @@ -1821,8 +1827,8 @@ static mlir::Value reverseVectorElements(fir::FirOpBuilder &builder, for (int64_t i = 0; i < len; ++i) { mask.push_back(len - 1 - i); } - auto undefVec{builder.create<fir::UndefOp>(loc, v.getType())}; - return builder.create<mlir::vector::ShuffleOp>(loc, v, undefVec, mask); + auto undefVec{fir::UndefOp::create(builder, loc, v.getType())}; + return mlir::vector::ShuffleOp::create(builder, loc, v, undefVec, mask); } static mlir::NamedAttribute getAlignmentAttr(fir::FirOpBuilder &builder, @@ -1871,8 +1877,8 @@ fir::ExtendedValue PPCIntrinsicLibrary::genVecLdNoCallGrp( const auto triple{fir::getTargetTriple(builder.getModule())}; // Need to get align 1. - auto result{builder.create<fir::LoadOp>(loc, mlirTy, addr, - getAlignmentAttr(builder, 1))}; + auto result{fir::LoadOp::create(builder, loc, mlirTy, addr, + getAlignmentAttr(builder, 1))}; if ((vop == VecOp::Xl && isBEVecElemOrderOnLE()) || (vop == VecOp::Xlbe && triple.isLittleEndian())) return builder.createConvert( @@ -1965,13 +1971,13 @@ PPCIntrinsicLibrary::genVecLdCallGrp(mlir::Type resultType, mlir::FunctionType::get(context, {addr.getType()}, {intrinResTy})}; auto funcOp{builder.createFunction(loc, fname, funcType)}; auto result{ - builder.create<fir::CallOp>(loc, funcOp, parsedArgs).getResult(0)}; + fir::CallOp::create(builder, loc, funcOp, parsedArgs).getResult(0)}; if (vop == VecOp::Lxvp) return result; if (intrinResTy != mlirTy) - result = builder.create<mlir::vector::BitCastOp>(loc, mlirTy, result); + result = mlir::vector::BitCastOp::create(builder, loc, mlirTy, result); if (vop != VecOp::Xld2 && vop != VecOp::Xlw4 && isBEVecElemOrderOnLE()) return builder.createConvert( @@ -1998,13 +2004,13 @@ PPCIntrinsicLibrary::genVecLvsGrp(mlir::Type resultType, // Convert arg0 to i64 type if needed auto i64ty{mlir::IntegerType::get(context, 64)}; if (arg0.getType() != i64ty) - arg0 = builder.create<fir::ConvertOp>(loc, i64ty, arg0); + arg0 = fir::ConvertOp::create(builder, loc, i64ty, arg0); // offset is modulo 16, so shift left 56 bits and then right 56 bits to clear // upper 56 bit while preserving sign auto shiftVal{builder.createIntegerConstant(loc, i64ty, 56)}; - auto offset{builder.create<mlir::arith::ShLIOp>(loc, arg0, shiftVal)}; - auto offset2{builder.create<mlir::arith::ShRSIOp>(loc, offset, shiftVal)}; + auto offset{mlir::arith::ShLIOp::create(builder, loc, arg0, shiftVal)}; + auto offset2{mlir::arith::ShRSIOp::create(builder, loc, offset, shiftVal)}; // Add the offsetArg to %addr of arg1 auto addr{addOffsetToAddress(builder, loc, arg1, offset2)}; @@ -2024,7 +2030,7 @@ PPCIntrinsicLibrary::genVecLvsGrp(mlir::Type resultType, auto funcType{mlir::FunctionType::get(context, {addr.getType()}, {mlirTy})}; auto funcOp{builder.createFunction(loc, fname, funcType)}; auto result{ - builder.create<fir::CallOp>(loc, funcOp, parsedArgs).getResult(0)}; + fir::CallOp::create(builder, loc, funcOp, parsedArgs).getResult(0)}; if (isNativeVecElemOrderOnLE()) return builder.createConvert( @@ -2061,19 +2067,19 @@ PPCIntrinsicLibrary::genVecNmaddMsub(mlir::Type resultType, std::get<1>(fmaMap[width]))}; if (vop == VecOp::Nmadd) { // vec_nmadd(arg1, arg2, arg3) = -fma(arg1, arg2, arg3) - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; // We need to convert fir.vector to MLIR vector to use fneg and then back // to fir.vector to store. auto vCall{builder.createConvert(loc, vTypeInfo.toMlirVectorType(context), callOp.getResult(0))}; - auto neg{builder.create<mlir::arith::NegFOp>(loc, vCall)}; + auto neg{mlir::arith::NegFOp::create(builder, loc, vCall)}; return builder.createConvert(loc, vTypeInfo.toFirVectorType(), neg); } else if (vop == VecOp::Msub) { // vec_msub(arg1, arg2, arg3) = fma(arg1, arg2, -arg3) - newArgs[2] = builder.create<mlir::arith::NegFOp>(loc, newArgs[2]); + newArgs[2] = mlir::arith::NegFOp::create(builder, loc, newArgs[2]); - auto callOp{builder.create<fir::CallOp>(loc, funcOp, newArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, newArgs)}; return callOp.getResult(0); } llvm_unreachable("Invalid vector operation for generator"); @@ -2104,10 +2110,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto mMask{builder.createConvert(loc, mlirMaskTy, argBases[2])}; if (mlirTy != vi32Ty) { - mArg0 = - builder.create<mlir::LLVM::BitcastOp>(loc, vi32Ty, mArg0).getResult(); - mArg1 = - builder.create<mlir::LLVM::BitcastOp>(loc, vi32Ty, mArg1).getResult(); + mArg0 = mlir::LLVM::BitcastOp::create(builder, loc, vi32Ty, mArg0) + .getResult(); + mArg1 = mlir::LLVM::BitcastOp::create(builder, loc, vi32Ty, mArg1) + .getResult(); } auto funcOp{builder.createFunction( @@ -2122,23 +2128,23 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto v8Ty{mlir::VectorType::get(16, i8Ty)}; auto negOne{builder.createMinusOneInteger(loc, i8Ty)}; auto vNegOne{ - builder.create<mlir::vector::BroadcastOp>(loc, v8Ty, negOne)}; + mlir::vector::BroadcastOp::create(builder, loc, v8Ty, negOne)}; - mMask = builder.create<mlir::arith::XOrIOp>(loc, mMask, vNegOne); + mMask = mlir::arith::XOrIOp::create(builder, loc, mMask, vNegOne); newArgs = {mArg1, mArg0, mMask}; } else { newArgs = {mArg0, mArg1, mMask}; } - auto res{builder.create<fir::CallOp>(loc, funcOp, newArgs).getResult(0)}; + auto res{fir::CallOp::create(builder, loc, funcOp, newArgs).getResult(0)}; if (res.getType() != argTypes[0]) { // fir.call llvm.ppc.altivec.vperm returns !fir.vector<i4:32> // convert the result back to the original type res = builder.createConvert(loc, vi32Ty, res); if (mlirTy != vi32Ty) - res = - builder.create<mlir::LLVM::BitcastOp>(loc, mlirTy, res).getResult(); + res = mlir::LLVM::BitcastOp::create(builder, loc, mlirTy, res) + .getResult(); } return builder.createConvert(loc, resultType, res); } @@ -2151,10 +2157,10 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, auto constInt{constIntOp.getInt()}; // arg1, arg2, and result type share same VecTypeInfo if (vecTyInfo.isFloat()) { - mArg0 = - builder.create<mlir::LLVM::BitcastOp>(loc, vf64Ty, mArg0).getResult(); - mArg1 = - builder.create<mlir::LLVM::BitcastOp>(loc, vf64Ty, mArg1).getResult(); + mArg0 = mlir::LLVM::BitcastOp::create(builder, loc, vf64Ty, mArg0) + .getResult(); + mArg1 = mlir::LLVM::BitcastOp::create(builder, loc, vf64Ty, mArg1) + .getResult(); } llvm::SmallVector<int64_t, 2> nMask; // native vector element order mask @@ -2183,9 +2189,9 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, llvm::SmallVector<int64_t, 2> mask = (isBEVecElemOrderOnLE()) ? rMask : nMask; - auto res{builder.create<mlir::vector::ShuffleOp>(loc, mArg0, mArg1, mask)}; + auto res{mlir::vector::ShuffleOp::create(builder, loc, mArg0, mArg1, mask)}; if (res.getType() != mlirTy) { - auto cast{builder.create<mlir::LLVM::BitcastOp>(loc, mlirTy, res)}; + auto cast{mlir::LLVM::BitcastOp::create(builder, loc, mlirTy, res)}; return builder.createConvert(loc, resultType, cast); } return builder.createConvert(loc, resultType, res); @@ -2212,22 +2218,23 @@ PPCIntrinsicLibrary::genVecSel(mlir::Type resultType, // construct a constant <16 x i8> vector with value -1 for bitcast auto bcVecTy{mlir::VectorType::get(16, i8Ty)}; - auto vNegOne{builder.create<mlir::vector::BroadcastOp>(loc, bcVecTy, negOne)}; + auto vNegOne{ + mlir::vector::BroadcastOp::create(builder, loc, bcVecTy, negOne)}; // bitcast arguments to bcVecTy - auto arg1{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[0])}; - auto arg2{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[1])}; - auto arg3{builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, vargs[2])}; + auto arg1{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[0])}; + auto arg2{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[1])}; + auto arg3{mlir::vector::BitCastOp::create(builder, loc, bcVecTy, vargs[2])}; // vec_sel(arg1, arg2, arg3) = // (arg2 and arg3) or (arg1 and (arg3 xor vector(-1,...))) - auto comp{builder.create<mlir::arith::XOrIOp>(loc, arg3, vNegOne)}; - auto a1AndComp{builder.create<mlir::arith::AndIOp>(loc, arg1, comp)}; - auto a1OrA2{builder.create<mlir::arith::AndIOp>(loc, arg2, arg3)}; - auto res{builder.create<mlir::arith::OrIOp>(loc, a1AndComp, a1OrA2)}; + auto comp{mlir::arith::XOrIOp::create(builder, loc, arg3, vNegOne)}; + auto a1AndComp{mlir::arith::AndIOp::create(builder, loc, arg1, comp)}; + auto a1OrA2{mlir::arith::AndIOp::create(builder, loc, arg2, arg3)}; + auto res{mlir::arith::OrIOp::create(builder, loc, a1AndComp, a1OrA2)}; auto bcRes{ - builder.create<mlir::vector::BitCastOp>(loc, vargs[0].getType(), res)}; + mlir::vector::BitCastOp::create(builder, loc, vargs[0].getType(), res)}; return builder.createConvert(loc, vecTyInfos[0].toFirVectorType(), bcRes); } @@ -2264,14 +2271,14 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto vecVal{builder.createIntegerConstant( loc, getConvertedElementType(context, vecTyInfoArgs[0].eleTy), width)}; auto mask{ - builder.create<mlir::vector::BroadcastOp>(loc, mlirTyArgs[1], vecVal)}; - auto shft{builder.create<mlir::arith::RemUIOp>(loc, mlirVecArgs[1], mask)}; + mlir::vector::BroadcastOp::create(builder, loc, mlirTyArgs[1], vecVal)}; + auto shft{mlir::arith::RemUIOp::create(builder, loc, mlirVecArgs[1], mask)}; mlir::Value res{nullptr}; if (vop == VecOp::Sr) - res = builder.create<mlir::arith::ShRUIOp>(loc, mlirVecArgs[0], shft); + res = mlir::arith::ShRUIOp::create(builder, loc, mlirVecArgs[0], shft); else if (vop == VecOp::Sl) - res = builder.create<mlir::arith::ShLIOp>(loc, mlirVecArgs[0], shft); + res = mlir::arith::ShLIOp::create(builder, loc, mlirVecArgs[0], shft); shftRes = builder.createConvert(loc, argTypes[0], res); } else if (vop == VecOp::Sll || vop == VecOp::Slo || vop == VecOp::Srl || @@ -2281,11 +2288,11 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, // Bitcast to vector<4xi32> auto bcVecTy{mlir::VectorType::get(4, builder.getIntegerType(32))}; if (mlirTyArgs[0] != bcVecTy) - mlirVecArgs[0] = - builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, mlirVecArgs[0]); + mlirVecArgs[0] = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, + mlirVecArgs[0]); if (mlirTyArgs[1] != bcVecTy) - mlirVecArgs[1] = - builder.create<mlir::vector::BitCastOp>(loc, bcVecTy, mlirVecArgs[1]); + mlirVecArgs[1] = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, + mlirVecArgs[1]); llvm::StringRef funcName; switch (vop) { @@ -2307,13 +2314,13 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto funcTy{genFuncType<Ty::IntegerVector<4>, Ty::IntegerVector<4>, Ty::IntegerVector<4>>(context, builder)}; mlir::func::FuncOp funcOp{builder.createFunction(loc, funcName, funcTy)}; - auto callOp{builder.create<fir::CallOp>(loc, funcOp, mlirVecArgs)}; + auto callOp{fir::CallOp::create(builder, loc, funcOp, mlirVecArgs)}; // If the result vector type is different from the original type, need // to convert to mlir vector, bitcast and then convert back to fir vector. if (callOp.getResult(0).getType() != argTypes[0]) { auto res = builder.createConvert(loc, bcVecTy, callOp.getResult(0)); - res = builder.create<mlir::vector::BitCastOp>(loc, mlirTyArgs[0], res); + res = mlir::vector::BitCastOp::create(builder, loc, mlirTyArgs[0], res); shftRes = builder.createConvert(loc, argTypes[0], res); } else { shftRes = callOp.getResult(0); @@ -2329,10 +2336,10 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, auto vi8Ty{mlir::VectorType::get(16, builder.getIntegerType(8))}; if (mlirTyArgs[0] != vi8Ty) { mlirVecArgs[0] = - builder.create<mlir::LLVM::BitcastOp>(loc, vi8Ty, mlirVecArgs[0]) + mlir::LLVM::BitcastOp::create(builder, loc, vi8Ty, mlirVecArgs[0]) .getResult(); mlirVecArgs[1] = - builder.create<mlir::LLVM::BitcastOp>(loc, vi8Ty, mlirVecArgs[1]) + mlir::LLVM::BitcastOp::create(builder, loc, vi8Ty, mlirVecArgs[1]) .getResult(); } @@ -2347,19 +2354,19 @@ PPCIntrinsicLibrary::genVecShift(mlir::Type resultType, if (triple.isLittleEndian()) { for (int i = 16; i < 32; ++i) mask.push_back(i - shiftVal); - shftRes = builder.create<mlir::vector::ShuffleOp>(loc, mlirVecArgs[1], - mlirVecArgs[0], mask); + shftRes = mlir::vector::ShuffleOp::create(builder, loc, mlirVecArgs[1], + mlirVecArgs[0], mask); } else { for (int i = 0; i < 16; ++i) mask.push_back(i + shiftVal); - shftRes = builder.create<mlir::vector::ShuffleOp>(loc, mlirVecArgs[0], - mlirVecArgs[1], mask); + shftRes = mlir::vector::ShuffleOp::create(builder, loc, mlirVecArgs[0], + mlirVecArgs[1], mask); } // Bitcast to the original type if (shftRes.getType() != mlirTyArgs[0]) shftRes = - builder.create<mlir::LLVM::BitcastOp>(loc, mlirTyArgs[0], shftRes); + mlir::LLVM::BitcastOp::create(builder, loc, mlirTyArgs[0], shftRes); return builder.createConvert(loc, resultType, shftRes); } else @@ -2384,8 +2391,9 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, auto vecTyInfo{getVecTypeFromFir(argBases[0])}; auto extractOp{genVecExtract(resultType, args)}; - splatOp = builder.create<mlir::vector::SplatOp>( - loc, *(extractOp.getUnboxed()), vecTyInfo.toMlirVectorType(context)); + splatOp = + mlir::vector::SplatOp::create(builder, loc, *(extractOp.getUnboxed()), + vecTyInfo.toMlirVectorType(context)); retTy = vecTyInfo.toFirVectorType(); break; } @@ -2393,8 +2401,8 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, assert(args.size() == 1); auto vecTyInfo{getVecTypeFromEle(argBases[0])}; - splatOp = builder.create<mlir::vector::SplatOp>( - loc, argBases[0], vecTyInfo.toMlirVectorType(context)); + splatOp = mlir::vector::SplatOp::create( + builder, loc, argBases[0], vecTyInfo.toMlirVectorType(context)); retTy = vecTyInfo.toFirVectorType(); break; } @@ -2404,8 +2412,8 @@ PPCIntrinsicLibrary::genVecSplat(mlir::Type resultType, auto intOp{builder.createConvert(loc, eleTy, argBases[0])}; // the intrinsic always returns vector(integer(4)) - splatOp = builder.create<mlir::vector::SplatOp>( - loc, intOp, mlir::VectorType::get(4, eleTy)); + splatOp = mlir::vector::SplatOp::create(builder, loc, intOp, + mlir::VectorType::get(4, eleTy)); retTy = fir::VectorType::get(4, eleTy); break; } @@ -2433,14 +2441,14 @@ PPCIntrinsicLibrary::genVecXlds(mlir::Type resultType, auto i64Ty{mlir::IntegerType::get(builder.getContext(), 64)}; auto i64VecTy{mlir::VectorType::get(2, i64Ty)}; auto i64RefTy{builder.getRefType(i64Ty)}; - auto addrConv{builder.create<fir::ConvertOp>(loc, i64RefTy, addr)}; + auto addrConv{fir::ConvertOp::create(builder, loc, i64RefTy, addr)}; - auto addrVal{builder.create<fir::LoadOp>(loc, addrConv)}; - auto splatRes{builder.create<mlir::vector::SplatOp>(loc, addrVal, i64VecTy)}; + auto addrVal{fir::LoadOp::create(builder, loc, addrConv)}; + auto splatRes{mlir::vector::SplatOp::create(builder, loc, addrVal, i64VecTy)}; mlir::Value result{nullptr}; if (mlirTy != splatRes.getType()) { - result = builder.create<mlir::vector::BitCastOp>(loc, mlirTy, splatRes); + result = mlir::vector::BitCastOp::create(builder, loc, mlirTy, splatRes); } else result = splatRes; @@ -2790,7 +2798,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { if (i == 0 && HandlerOp == MMAHandlerOp::FirstArgIsResult) { // First argument is passed in as an address. We need to load // the content to match the LLVM interface. - v = builder.create<fir::LoadOp>(loc, v); + v = fir::LoadOp::create(builder, loc, v); } auto vType{v.getType()}; mlir::Type targetType{intrFuncType.getInput(j)}; @@ -2801,7 +2809,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { auto len{mlir::dyn_cast<fir::VectorType>(vType).getLen()}; mlir::VectorType mlirType = mlir::VectorType::get(len, eleTy); auto v0{builder.createConvert(loc, mlirType, v)}; - auto v1{builder.create<mlir::vector::BitCastOp>(loc, targetType, v0)}; + auto v1{mlir::vector::BitCastOp::create(builder, loc, targetType, v0)}; intrArgs.push_back(v1); } else if (mlir::isa<mlir::IntegerType>(targetType) && mlir::isa<mlir::IntegerType>(vType)) { @@ -2817,7 +2825,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { intrArgs.push_back(v); } } - auto callSt{builder.create<fir::CallOp>(loc, funcOp, intrArgs)}; + auto callSt{fir::CallOp::create(builder, loc, funcOp, intrArgs)}; if (HandlerOp == MMAHandlerOp::SubToFunc || HandlerOp == MMAHandlerOp::SubToFuncReverseArgOnLE || HandlerOp == MMAHandlerOp::FirstArgIsResult) { @@ -2826,10 +2834,11 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value destPtr{fir::getBase(args[0])}; mlir::Type callResultPtrType{builder.getRefType(callResult.getType())}; if (destPtr.getType() != callResultPtrType) { - destPtr = builder.create<fir::ConvertOp>(loc, callResultPtrType, destPtr); + destPtr = + fir::ConvertOp::create(builder, loc, callResultPtrType, destPtr); } // Copy the result. - builder.create<fir::StoreOp>(loc, callResult, destPtr); + fir::StoreOp::create(builder, loc, callResult, destPtr); } } @@ -2896,7 +2905,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { if (vop == VecOp::Stxvp) { biArgs.push_back(argBases[0]); biArgs.push_back(addr); - builder.create<fir::CallOp>(loc, funcOp, biArgs); + fir::CallOp::create(builder, loc, funcOp, biArgs); return; } @@ -2906,7 +2915,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value newArg1{nullptr}; if (stTy != arg1TyInfo.toMlirVectorType(context)) - newArg1 = builder.create<mlir::vector::BitCastOp>(loc, stTy, cnv); + newArg1 = mlir::vector::BitCastOp::create(builder, loc, stTy, cnv); else newArg1 = cnv; @@ -2917,7 +2926,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef<fir::ExtendedValue> args) { biArgs.push_back(newArg1); biArgs.push_back(addr); - builder.create<fir::CallOp>(loc, funcOp, biArgs); + fir::CallOp::create(builder, loc, funcOp, biArgs); } // VEC_XST, VEC_XST_BE, VEC_STXV, VEC_XSTD2, VEC_XSTW4 @@ -2966,7 +2975,7 @@ void PPCIntrinsicLibrary::genVecXStore( mlir::Type srcTy{nullptr}; if (numElem != arg1TyInfo.len) { - cnv = builder.create<mlir::vector::BitCastOp>(loc, mlirVecTy, cnv); + cnv = mlir::vector::BitCastOp::create(builder, loc, mlirVecTy, cnv); srcTy = firVecTy; } else { srcTy = arg1TyInfo.toFirVectorType(); @@ -2989,9 +2998,9 @@ void PPCIntrinsicLibrary::genVecXStore( default: assert(false && "Invalid vector operation for generator"); } - builder.create<fir::StoreOp>(loc, mlir::TypeRange{}, - mlir::ValueRange{src, trg}, - getAlignmentAttr(builder, 1)); + fir::StoreOp::create(builder, loc, mlir::TypeRange{}, + mlir::ValueRange{src, trg}, + getAlignmentAttr(builder, 1)); } } // namespace fir diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp index cd5f1f6..cc9f828 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -30,7 +30,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder, mlir::dyn_cast<fir::ClassType>(fir::dyn_cast_ptrEleTy(from.getType())); mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy()); declaredTypeDesc = - builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(derivedType)); + fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(derivedType)); } else { declaredTypeDesc = builder.createNullConstant(loc); } @@ -38,7 +38,7 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder, builder, loc, fTy, to, from, declaredTypeDesc, hasStat, errMsg, sourceFile, sourceLine)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genAllocatableApplyMold(fir::FirOpBuilder &builder, @@ -52,7 +52,7 @@ void fir::runtime::genAllocatableApplyMold(fir::FirOpBuilder &builder, builder.createIntegerConstant(loc, fTy.getInput(2), rank); llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, mold, rankVal)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAllocatableSetBounds(fir::FirOpBuilder &builder, @@ -66,7 +66,7 @@ void fir::runtime::genAllocatableSetBounds(fir::FirOpBuilder &builder, mlir::FunctionType fTy{func.getFunctionType()}; llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, dimIndex, lowerBound, upperBound)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAllocatableAllocate(fir::FirOpBuilder &builder, @@ -84,10 +84,10 @@ void fir::runtime::genAllocatableAllocate(fir::FirOpBuilder &builder, hasStat = builder.createBool(loc, false); if (!errMsg) { mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); - errMsg = builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + errMsg = fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); } llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, asyncObject, hasStat, errMsg, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index 0d56cd2..8c9825e 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -50,7 +50,7 @@ mlir::Value fir::runtime::genInitArrayConstructorVector( auto args = fir::runtime::createArguments(builder, loc, funcType, cookie, toBox, useValueLengthParameters, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return cookie; } @@ -63,7 +63,7 @@ void fir::runtime::genPushArrayConstructorValue( mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, arrayConstructorVector, fromBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genPushArrayConstructorSimpleScalar( @@ -75,5 +75,5 @@ void fir::runtime::genPushArrayConstructorSimpleScalar( mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments( builder, loc, funcType, arrayConstructorVector, fromAddress); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Assign.cpp b/flang/lib/Optimizer/Builder/Runtime/Assign.cpp index 62f03f7..336dbdc 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Assign.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Assign.cpp @@ -22,7 +22,7 @@ void fir::runtime::genAssign(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignPolymorphic(fir::FirOpBuilder &builder, @@ -36,7 +36,7 @@ void fir::runtime::genAssignPolymorphic(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignExplicitLengthCharacter(fir::FirOpBuilder &builder, @@ -52,7 +52,7 @@ void fir::runtime::genAssignExplicitLengthCharacter(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genAssignTemporary(fir::FirOpBuilder &builder, @@ -66,7 +66,7 @@ void fir::runtime::genAssignTemporary(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genCopyInAssign(fir::FirOpBuilder &builder, @@ -79,7 +79,7 @@ void fir::runtime::genCopyInAssign(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genCopyOutAssign(fir::FirOpBuilder &builder, @@ -93,5 +93,5 @@ void fir::runtime::genCopyOutAssign(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp b/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp index 62a0652..a6ee986 100644 --- a/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp @@ -30,7 +30,7 @@ void fir::runtime::cuda::genSyncGlobalDescriptor(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, hostPtr, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } void fir::runtime::cuda::genDescriptorCheckSection(fir::FirOpBuilder &builder, @@ -45,7 +45,7 @@ void fir::runtime::cuda::genDescriptorCheckSection(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::cuda::genSetAllocatorIndex(fir::FirOpBuilder &builder, @@ -60,5 +60,5 @@ void fir::runtime::cuda::genSetAllocatorIndex(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, desc, index, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Character.cpp b/flang/lib/Optimizer/Builder/Runtime/Character.cpp index b168199..57fb0cc 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Character.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Character.cpp @@ -34,7 +34,7 @@ static void genCharacterSearch(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, string1Box, string2Box, backBox, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Helper function to recover the KIND from the FIR type. @@ -72,7 +72,7 @@ static void genAdjust(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, stringBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, adjustFunc, args); + fir::CallOp::create(builder, loc, adjustFunc, args); } void fir::runtime::genAdjustL(fir::FirOpBuilder &builder, mlir::Location loc, @@ -114,9 +114,9 @@ fir::runtime::genCharCompare(fir::FirOpBuilder &builder, mlir::Location loc, auto fTy = beginFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, lhsBuff, rhsBuff, lhsLen, rhsLen); - auto tri = builder.create<fir::CallOp>(loc, beginFunc, args).getResult(0); + auto tri = fir::CallOp::create(builder, loc, beginFunc, args).getResult(0); auto zero = builder.createIntegerConstant(loc, tri.getType(), 0); - return builder.create<mlir::arith::CmpIOp>(loc, cmp, tri, zero); + return mlir::arith::CmpIOp::create(builder, loc, cmp, tri, zero); } mlir::Value fir::runtime::genCharCompare(fir::FirOpBuilder &builder, @@ -130,8 +130,8 @@ mlir::Value fir::runtime::genCharCompare(fir::FirOpBuilder &builder, if (fir::isa_ref_type(base.getType())) return base; auto mem = - builder.create<fir::AllocaOp>(loc, base.getType(), /*pinned=*/false); - builder.create<fir::StoreOp>(loc, base, mem); + fir::AllocaOp::create(builder, loc, base.getType(), /*pinned=*/false); + fir::StoreOp::create(builder, loc, base, mem); return mem; }; auto lhsBuffer = allocateIfNotInMemory(fir::getBase(lhs)); @@ -165,7 +165,7 @@ mlir::Value fir::runtime::genIndex(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, substringBase, substringLen, back); - return builder.create<fir::CallOp>(loc, indexFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, indexFunc, args).getResult(0); } void fir::runtime::genIndexDescriptor(fir::FirOpBuilder &builder, @@ -189,7 +189,7 @@ void fir::runtime::genRepeat(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, stringBox, ncopies, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, repeatFunc, args); + fir::CallOp::create(builder, loc, repeatFunc, args); } void fir::runtime::genTrim(fir::FirOpBuilder &builder, mlir::Location loc, @@ -202,7 +202,7 @@ void fir::runtime::genTrim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, stringBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, trimFunc, args); + fir::CallOp::create(builder, loc, trimFunc, args); } void fir::runtime::genScanDescriptor(fir::FirOpBuilder &builder, @@ -237,7 +237,7 @@ mlir::Value fir::runtime::genScan(fir::FirOpBuilder &builder, auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, setBase, setLen, back); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genVerifyDescriptor(fir::FirOpBuilder &builder, @@ -274,5 +274,5 @@ mlir::Value fir::runtime::genVerify(fir::FirOpBuilder &builder, auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, stringBase, stringLen, setBase, setLen, back); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Command.cpp b/flang/lib/Optimizer/Builder/Runtime/Command.cpp index 35aa529..e65e2b6d 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Command.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Command.cpp @@ -30,7 +30,7 @@ mlir::Value fir::runtime::genCommandArgumentCount(fir::FirOpBuilder &builder, mlir::Location loc) { auto argumentCountFunc = fir::runtime::getRuntimeFunc<mkRTKey(ArgumentCount)>(loc, builder); - return builder.create<fir::CallOp>(loc, argumentCountFunc).getResult(0); + return fir::CallOp::create(builder, loc, argumentCountFunc).getResult(0); } mlir::Value fir::runtime::genGetCommand(fir::FirOpBuilder &builder, @@ -46,7 +46,7 @@ mlir::Value fir::runtime::genGetCommand(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, command, length, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder, @@ -54,7 +54,7 @@ mlir::Value fir::runtime::genGetPID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetPID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genGetCommandArgument( @@ -69,7 +69,7 @@ mlir::Value fir::runtime::genGetCommandArgument( llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, number, value, length, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetEnvVariable(fir::FirOpBuilder &builder, @@ -87,7 +87,7 @@ mlir::Value fir::runtime::genGetEnvVariable(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, name, value, length, trimName, errmsg, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetCwd(fir::FirOpBuilder &builder, @@ -100,7 +100,7 @@ mlir::Value fir::runtime::genGetCwd(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, cwd, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genHostnm(fir::FirOpBuilder &builder, @@ -113,7 +113,7 @@ mlir::Value fir::runtime::genHostnm(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, res, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPerror(fir::FirOpBuilder &builder, mlir::Location loc, @@ -123,7 +123,7 @@ void fir::runtime::genPerror(fir::FirOpBuilder &builder, mlir::Location loc, mlir::FunctionType runtimeFuncTy = runtimeFunc.getFunctionType(); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, string); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } mlir::Value fir::runtime::genPutEnv(fir::FirOpBuilder &builder, @@ -137,7 +137,7 @@ mlir::Value fir::runtime::genPutEnv(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(1)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, str, strLength, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genUnlink(fir::FirOpBuilder &builder, @@ -151,5 +151,5 @@ mlir::Value fir::runtime::genUnlink(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, runtimeFuncTy.getInput(1)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, path, pathLength, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Derived.cpp b/flang/lib/Optimizer/Builder/Runtime/Derived.cpp index 25b4151..1b0457b 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Derived.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Derived.cpp @@ -26,7 +26,7 @@ void fir::runtime::genDerivedTypeInitialize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeInitializeClone(fir::FirOpBuilder &builder, @@ -41,7 +41,7 @@ void fir::runtime::genDerivedTypeInitializeClone(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, newBox, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeDestroy(fir::FirOpBuilder &builder, @@ -49,7 +49,7 @@ void fir::runtime::genDerivedTypeDestroy(fir::FirOpBuilder &builder, auto func = fir::runtime::getRuntimeFunc<mkRTKey(Destroy)>(loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeFinalize(fir::FirOpBuilder &builder, @@ -61,7 +61,7 @@ void fir::runtime::genDerivedTypeFinalize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, box, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDerivedTypeDestroyWithoutFinalization( @@ -70,7 +70,7 @@ void fir::runtime::genDerivedTypeDestroyWithoutFinalization( loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, @@ -78,7 +78,7 @@ void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, fir::RecordType derivedType, unsigned rank) { mlir::Value typeDesc = - builder.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(derivedType)); + fir::TypeDescOp::create(builder, loc, mlir::TypeAttr::get(derivedType)); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(PointerNullifyDerived)>(loc, builder); @@ -90,7 +90,7 @@ void fir::runtime::genNullifyDerivedType(fir::FirOpBuilder &builder, mlir::Value c0 = builder.createIntegerConstant(loc, inputTypes[3], 0); args.push_back(rankCst); args.push_back(c0); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } mlir::Value fir::runtime::genSameTypeAs(fir::FirOpBuilder &builder, @@ -100,7 +100,7 @@ mlir::Value fir::runtime::genSameTypeAs(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(SameTypeAs)>(loc, builder); auto fTy = sameTypeAsFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, a, b); - return builder.create<fir::CallOp>(loc, sameTypeAsFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sameTypeAsFunc, args).getResult(0); } mlir::Value fir::runtime::genExtendsTypeOf(fir::FirOpBuilder &builder, @@ -110,5 +110,6 @@ mlir::Value fir::runtime::genExtendsTypeOf(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(ExtendsTypeOf)>(loc, builder); auto fTy = extendsTypeOfFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, a, mold); - return builder.create<fir::CallOp>(loc, extendsTypeOfFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, extendsTypeOfFunc, args) + .getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp b/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp index bf5fd6a..fa3d00e 100755 --- a/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp @@ -44,7 +44,7 @@ mlir::Value fir::runtime::genEnvironmentDefaults( mlir::IntegerAttr one = builder.getIntegerAttr(idxTy, 1); std::string itemListName = envDefaultListPtrName + ".items"; auto listBuilder = [&](fir::FirOpBuilder &builder) { - mlir::Value list = builder.create<fir::UndefOp>(loc, itemListTy); + mlir::Value list = fir::UndefOp::create(builder, loc, itemListTy); llvm::SmallVector<mlir::Attribute, 2> idx = {mlir::Attribute{}, mlir::Attribute{}}; auto insertStringField = [&](const std::string &s, @@ -52,8 +52,8 @@ mlir::Value fir::runtime::genEnvironmentDefaults( mlir::Value stringAddress = fir::getBase( fir::factory::createStringLiteral(builder, loc, s + '\0')); mlir::Value addr = builder.createConvert(loc, charRefTy, stringAddress); - return builder.create<fir::InsertValueOp>(loc, itemListTy, list, addr, - builder.getArrayAttr(idx)); + return fir::InsertValueOp::create(builder, loc, itemListTy, list, addr, + builder.getArrayAttr(idx)); }; size_t n = 0; @@ -65,7 +65,7 @@ mlir::Value fir::runtime::genEnvironmentDefaults( list = insertStringField(def.defaultValue, idx); ++n; } - builder.create<fir::HasValueOp>(loc, list); + fir::HasValueOp::create(builder, loc, list); }; builder.createGlobalConstant(loc, itemListTy, itemListName, listBuilder, linkOnce); @@ -73,27 +73,27 @@ mlir::Value fir::runtime::genEnvironmentDefaults( // Define the EnviornmentDefaultList object. auto envDefaultListBuilder = [&](fir::FirOpBuilder &builder) { mlir::Value envDefaultList = - builder.create<fir::UndefOp>(loc, envDefaultListTy); + fir::UndefOp::create(builder, loc, envDefaultListTy); mlir::Value numItems = builder.createIntegerConstant(loc, intTy, envDefaults.size()); - envDefaultList = builder.create<fir::InsertValueOp>( - loc, envDefaultListTy, envDefaultList, numItems, - builder.getArrayAttr(zero)); + envDefaultList = fir::InsertValueOp::create(builder, loc, envDefaultListTy, + envDefaultList, numItems, + builder.getArrayAttr(zero)); fir::GlobalOp itemList = builder.getNamedGlobal(itemListName); assert(itemList && "missing environment default list"); - mlir::Value listAddr = builder.create<fir::AddrOfOp>( - loc, itemList.resultType(), itemList.getSymbol()); - envDefaultList = builder.create<fir::InsertValueOp>( - loc, envDefaultListTy, envDefaultList, listAddr, - builder.getArrayAttr(one)); - builder.create<fir::HasValueOp>(loc, envDefaultList); + mlir::Value listAddr = fir::AddrOfOp::create( + builder, loc, itemList.resultType(), itemList.getSymbol()); + envDefaultList = fir::InsertValueOp::create(builder, loc, envDefaultListTy, + envDefaultList, listAddr, + builder.getArrayAttr(one)); + fir::HasValueOp::create(builder, loc, envDefaultList); }; fir::GlobalOp envDefaultList = builder.createGlobalConstant( loc, envDefaultListTy, envDefaultListPtrName + ".list", envDefaultListBuilder, linkOnce); // Define the pointer to the list used by the runtime. - mlir::Value addr = builder.create<fir::AddrOfOp>( - loc, envDefaultList.resultType(), envDefaultList.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, envDefaultList.resultType(), envDefaultList.getSymbol()); return addr; } diff --git a/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp b/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp index 0f66315..0256644 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp @@ -18,21 +18,21 @@ mlir::Value fir::runtime::genMapExcept(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(MapException)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } void fir::runtime::genFeclearexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feclearexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } void fir::runtime::genFeraiseexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feraiseexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } mlir::Value fir::runtime::genFetestexcept(fir::FirOpBuilder &builder, @@ -40,28 +40,28 @@ mlir::Value fir::runtime::genFetestexcept(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fetestexcept)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } void fir::runtime::genFedisableexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fedisableexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } void fir::runtime::genFeenableexcept(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(feenableexcept)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, excepts); + fir::CallOp::create(builder, loc, func, excepts); } mlir::Value fir::runtime::genFegetexcept(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(fegetexcept)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } mlir::Value fir::runtime::genSupportHalting(fir::FirOpBuilder &builder, @@ -69,33 +69,33 @@ mlir::Value fir::runtime::genSupportHalting(fir::FirOpBuilder &builder, mlir::Value excepts) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(SupportHalting)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func, excepts).getResult(0); + return fir::CallOp::create(builder, loc, func, excepts).getResult(0); } mlir::Value fir::runtime::genGetUnderflowMode(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetUnderflowMode)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } void fir::runtime::genSetUnderflowMode(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value flag) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(SetUnderflowMode)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, flag); + fir::CallOp::create(builder, loc, func, flag); } mlir::Value fir::runtime::genGetModesTypeSize(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetModesTypeSize)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } mlir::Value fir::runtime::genGetStatusTypeSize(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(GetStatusTypeSize)>(loc, builder)}; - return builder.create<fir::CallOp>(loc, func).getResult(0); + return fir::CallOp::create(builder, loc, func).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Execute.cpp b/flang/lib/Optimizer/Builder/Runtime/Execute.cpp index 71ee399..2f85fb4 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Execute.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Execute.cpp @@ -40,5 +40,5 @@ void fir::runtime::genExecuteCommandLine(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, command, wait, exitstat, cmdstat, cmdmsg, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp b/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp index 718c353..5e3f022 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp @@ -26,7 +26,7 @@ mlir::Value fir::runtime::genLboundDim(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, lboundFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, lboundFunc, args).getResult(0); } void fir::runtime::genLbound(fir::FirOpBuilder &builder, mlir::Location loc, @@ -40,7 +40,7 @@ void fir::runtime::genLbound(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultAddr, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Ubound` runtime routine. Calls to UBOUND with a DIM @@ -57,7 +57,7 @@ void fir::runtime::genUbound(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, uboundFunc, args); + fir::CallOp::create(builder, loc, uboundFunc, args); } /// Generate call to `Size` runtime routine. This routine is a version when @@ -73,7 +73,7 @@ mlir::Value fir::runtime::genSizeDim(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, sizeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sizeFunc, args).getResult(0); } /// Generate call to `Size` runtime routine. This routine is a version when @@ -88,7 +88,7 @@ mlir::Value fir::runtime::genSize(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, array, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, sizeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, sizeFunc, args).getResult(0); } /// Generate call to `IsContiguous` runtime routine. @@ -99,7 +99,7 @@ mlir::Value fir::runtime::genIsContiguous(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsContiguous)>(loc, builder); auto fTy = isContiguousFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, array); - return builder.create<fir::CallOp>(loc, isContiguousFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, isContiguousFunc, args).getResult(0); } /// Generate call to `IsContiguousUpTo` runtime routine. @@ -111,7 +111,7 @@ mlir::Value fir::runtime::genIsContiguousUpTo(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsContiguousUpTo)>(loc, builder); auto fTy = isContiguousFunc.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, array, dim); - return builder.create<fir::CallOp>(loc, isContiguousFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, isContiguousFunc, args).getResult(0); } void fir::runtime::genShape(fir::FirOpBuilder &builder, mlir::Location loc, @@ -125,5 +125,5 @@ void fir::runtime::genShape(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultAddr, array, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp index 773d640..4b4954a 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp @@ -52,14 +52,15 @@ mlir::Value fir::runtime::genAssociated(fir::FirOpBuilder &builder, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), pointer, target); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } mlir::Value fir::runtime::genCpuTime(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey(CpuTime)>(loc, builder); - return builder.create<fir::CallOp>(loc, func, std::nullopt).getResult(0); + return fir::CallOp::create(builder, loc, func, mlir::ValueRange{}) + .getResult(0); } void fir::runtime::genDateAndTime(fir::FirOpBuilder &builder, @@ -102,7 +103,7 @@ void fir::runtime::genDateAndTime(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, dateBuffer, dateLen, timeBuffer, timeLen, zoneBuffer, zoneLen, sourceFile, sourceLine, values); - builder.create<fir::CallOp>(loc, callee, args); + fir::CallOp::create(builder, loc, callee, args); } void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc, @@ -116,7 +117,7 @@ void fir::runtime::genEtime(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, runtimeFuncTy, values, time, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } void fir::runtime::genFree(fir::FirOpBuilder &builder, mlir::Location loc, @@ -124,8 +125,8 @@ void fir::runtime::genFree(fir::FirOpBuilder &builder, mlir::Location loc, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(Free)>(loc, builder); mlir::Type intPtrTy = builder.getIntPtrType(); - builder.create<fir::CallOp>(loc, runtimeFunc, - builder.createConvert(loc, intPtrTy, ptr)); + fir::CallOp::create(builder, loc, runtimeFunc, + builder.createConvert(loc, intPtrTy, ptr)); } mlir::Value fir::runtime::genFseek(fir::FirOpBuilder &builder, @@ -139,7 +140,7 @@ mlir::Value fir::runtime::genFseek(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, unit, offset, whence, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); ; } @@ -149,7 +150,7 @@ mlir::Value fir::runtime::genFtell(fir::FirOpBuilder &builder, mlir::FunctionType runtimeFuncTy = runtimeFunc.getFunctionType(); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, unit); - return builder.create<fir::CallOp>(loc, runtimeFunc, args).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc, args).getResult(0); } mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder, @@ -157,7 +158,7 @@ mlir::Value fir::runtime::genGetGID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetGID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder, @@ -165,7 +166,7 @@ mlir::Value fir::runtime::genGetUID(fir::FirOpBuilder &builder, auto runtimeFunc = fir::runtime::getRuntimeFunc<mkRTKey(GetUID)>(loc, builder); - return builder.create<fir::CallOp>(loc, runtimeFunc).getResult(0); + return fir::CallOp::create(builder, loc, runtimeFunc).getResult(0); } mlir::Value fir::runtime::genMalloc(fir::FirOpBuilder &builder, @@ -186,7 +187,7 @@ void fir::runtime::genRandomInit(fir::FirOpBuilder &builder, mlir::Location loc, fir::runtime::getRuntimeFunc<mkRTKey(RandomInit)>(loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, func.getFunctionType(), repeatable, imageDistinct); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genRandomNumber(fir::FirOpBuilder &builder, @@ -206,7 +207,7 @@ void fir::runtime::genRandomNumber(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, harvest, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, @@ -223,7 +224,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, if (staticArgCount == 0) { func = fir::runtime::getRuntimeFunc<mkRTKey(RandomSeedDefaultPut)>(loc, builder); - builder.create<fir::CallOp>(loc, func); + fir::CallOp::create(builder, loc, func); return; } mlir::FunctionType funcTy; @@ -238,7 +239,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcTy.getInput(4)); args = fir::runtime::createArguments(builder, loc, funcTy, size, put, get, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return; } if (sizeIsPresent) { @@ -255,7 +256,7 @@ void fir::runtime::genRandomSeed(fir::FirOpBuilder &builder, mlir::Location loc, sourceLine = fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2)); args = fir::runtime::createArguments(builder, loc, funcTy, argBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate rename runtime call @@ -273,14 +274,15 @@ void fir::runtime::genRename(fir::FirOpBuilder &builder, mlir::Location loc, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, runtimeFuncTy, path1, path2, status, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, runtimeFunc, args); + fir::CallOp::create(builder, loc, runtimeFunc, args); } /// generate runtime call to time intrinsic mlir::Value fir::runtime::genTime(fir::FirOpBuilder &builder, mlir::Location loc) { auto func = fir::runtime::getRuntimeFunc<mkRTKey(time)>(loc, builder); - return builder.create<fir::CallOp>(loc, func, std::nullopt).getResult(0); + return fir::CallOp::create(builder, loc, func, mlir::ValueRange{}) + .getResult(0); } /// generate runtime call to transfer intrinsic with no size argument @@ -296,7 +298,7 @@ void fir::runtime::genTransfer(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, fTy, resultBox, sourceBox, moldBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate runtime call to transfer intrinsic with size argument @@ -313,7 +315,7 @@ void fir::runtime::genTransferSize(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, moldBox, sourceFile, sourceLine, size); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// generate system_clock runtime call/s @@ -330,11 +332,12 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, mlir::dyn_cast<fir::HeapType>(type)) { // Check for a disassociated pointer or an unallocated allocatable. assert(!isOptionalArg && "invalid optional argument"); - ifOp = builder.create<fir::IfOp>(loc, builder.genIsNotNullAddr(loc, arg), - /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, builder.genIsNotNullAddr(loc, arg), + /*withElseRegion=*/false); } else if (isOptionalArg) { - ifOp = builder.create<fir::IfOp>( - loc, builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), arg), + ifOp = fir::IfOp::create( + builder, loc, + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), arg), /*withElseRegion=*/false); } if (ifOp) @@ -346,11 +349,11 @@ void fir::runtime::genSystemClock(fir::FirOpBuilder &builder, integerKind = intType.getWidth() / 8; mlir::Value kind = builder.createIntegerConstant(loc, kindTy, integerKind); mlir::Value res = - builder.create<fir::CallOp>(loc, func, mlir::ValueRange{kind}) + fir::CallOp::create(builder, loc, func, mlir::ValueRange{kind}) .getResult(0); mlir::Value castRes = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(type), res); - builder.create<fir::StoreOp>(loc, castRes, arg); + fir::StoreOp::create(builder, loc, castRes, arg); if (ifOp) builder.setInsertionPointAfter(ifOp); }; @@ -371,24 +374,24 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value status) { assert(mlir::isa<mlir::IntegerType>(number.getType())); mlir::Type int64 = builder.getIntegerType(64); - number = builder.create<fir::ConvertOp>(loc, int64, number); + number = fir::ConvertOp::create(builder, loc, int64, number); mlir::Type handlerUnwrappedTy = fir::unwrapRefType(handler.getType()); if (mlir::isa_and_nonnull<mlir::IntegerType>(handlerUnwrappedTy)) { // pass the integer as a function pointer like one would to signal(2) - handler = builder.create<fir::LoadOp>(loc, handler); + handler = fir::LoadOp::create(builder, loc, handler); mlir::Type fnPtrTy = fir::LLVMPointerType::get( mlir::FunctionType::get(handler.getContext(), {}, {})); - handler = builder.create<fir::ConvertOp>(loc, fnPtrTy, handler); + handler = fir::ConvertOp::create(builder, loc, fnPtrTy, handler); } else { assert(mlir::isa<fir::BoxProcType>(handler.getType())); - handler = builder.create<fir::BoxAddrOp>(loc, handler); + handler = fir::BoxAddrOp::create(builder, loc, handler); } mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(Signal)>(loc, builder)}; mlir::Value stat = - builder.create<fir::CallOp>(loc, func, mlir::ValueRange{number, handler}) + fir::CallOp::create(builder, loc, func, mlir::ValueRange{number, handler}) ->getResult(0); // return status code via status argument (if present) @@ -396,12 +399,12 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, assert(mlir::isa<mlir::IntegerType>(fir::unwrapRefType(status.getType()))); // status might be dynamically optional, so test if it is present mlir::Value isPresent = - builder.create<IsPresentOp>(loc, builder.getI1Type(), status); + IsPresentOp::create(builder, loc, builder.getI1Type(), status); builder.genIfOp(loc, /*results=*/{}, isPresent, /*withElseRegion=*/false) .genThen([&]() { - stat = builder.create<fir::ConvertOp>( - loc, fir::unwrapRefType(status.getType()), stat); - builder.create<fir::StoreOp>(loc, stat, status); + stat = fir::ConvertOp::create( + builder, loc, fir::unwrapRefType(status.getType()), stat); + fir::StoreOp::create(builder, loc, stat, status); }) .end(); } @@ -410,10 +413,10 @@ void fir::runtime::genSignal(fir::FirOpBuilder &builder, mlir::Location loc, void fir::runtime::genSleep(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value seconds) { mlir::Type int64 = builder.getIntegerType(64); - seconds = builder.create<fir::ConvertOp>(loc, int64, seconds); + seconds = fir::ConvertOp::create(builder, loc, int64, seconds); mlir::func::FuncOp func{ fir::runtime::getRuntimeFunc<mkRTKey(Sleep)>(loc, builder)}; - builder.create<fir::CallOp>(loc, func, seconds); + fir::CallOp::create(builder, loc, func, seconds); } /// generate chdir runtime call @@ -423,5 +426,5 @@ mlir::Value fir::runtime::genChdir(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(Chdir)>(loc, builder)}; llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(builder, loc, func.getFunctionType(), name); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Main.cpp b/flang/lib/Optimizer/Builder/Runtime/Main.cpp index 9737448..d35f687 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Main.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Main.cpp @@ -62,17 +62,17 @@ void fir::runtime::genMain( llvm::SmallVector<mlir::Value, 4> args(block->getArguments()); args.push_back(env); - builder.create<fir::CallOp>(loc, startFn, args); + fir::CallOp::create(builder, loc, startFn, args); if (initCuda) { auto initFn = builder.createFunction( loc, RTNAME_STRING(CUFInit), mlir::FunctionType::get(context, {}, {})); - builder.create<fir::CallOp>(loc, initFn); + fir::CallOp::create(builder, loc, initFn); } - builder.create<fir::CallOp>(loc, qqMainFn); - builder.create<fir::CallOp>(loc, stopFn); + fir::CallOp::create(builder, loc, qqMainFn); + fir::CallOp::create(builder, loc, stopFn); mlir::Value ret = builder.createIntegerConstant(loc, argcTy, 0); - builder.create<mlir::func::ReturnOp>(loc, ret); + mlir::func::ReturnOp::create(builder, loc, ret); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp index 4ff7c86..62d5e50 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp @@ -317,7 +317,7 @@ mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Fraction intrinsic runtime routine. @@ -340,7 +340,7 @@ mlir::Value fir::runtime::genFraction(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Mod intrinsic runtime routine. @@ -370,7 +370,7 @@ mlir::Value fir::runtime::genMod(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, funcTy, a, p, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Modulo intrinsic runtime routine. @@ -403,7 +403,7 @@ mlir::Value fir::runtime::genModulo(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, funcTy, a, p, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Nearest intrinsic or a "Next" intrinsic module procedure. @@ -427,7 +427,7 @@ mlir::Value fir::runtime::genNearest(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, valueUp); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to RRSpacing intrinsic runtime routine. @@ -451,7 +451,7 @@ mlir::Value fir::runtime::genRRSpacing(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to ErfcScaled intrinsic runtime routine. @@ -475,7 +475,7 @@ mlir::Value fir::runtime::genErfcScaled(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Scale intrinsic runtime routine. @@ -499,7 +499,7 @@ mlir::Value fir::runtime::genScale(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_char_kind intrinsic runtime routine. @@ -519,7 +519,7 @@ mlir::Value fir::runtime::genSelectedCharKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, name, length); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_int_kind intrinsic runtime routine. @@ -540,7 +540,7 @@ mlir::Value fir::runtime::genSelectedIntKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, x, xKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_logical_kind intrinsic runtime routine. @@ -561,7 +561,7 @@ mlir::Value fir::runtime::genSelectedLogicalKind(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, sourceFile, sourceLine, x, xKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Selected_real_kind intrinsic runtime routine. @@ -593,7 +593,7 @@ mlir::Value fir::runtime::genSelectedRealKind(fir::FirOpBuilder &builder, sourceLine, precision, pKind, range, rKind, radix, dKind); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Set_exponent intrinsic runtime routine. @@ -617,7 +617,7 @@ mlir::Value fir::runtime::genSetExponent(fir::FirOpBuilder &builder, auto funcTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to Spacing intrinsic runtime routine. @@ -649,6 +649,6 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder, llvm::SmallVector<mlir::Value> args = { builder.createConvert(loc, funcTy.getInput(0), x)}; - mlir::Value res = builder.create<fir::CallOp>(loc, func, args).getResult(0); + mlir::Value res = fir::CallOp::create(builder, loc, func, args).getResult(0); return builder.createConvert(loc, fltTy, res); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp b/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp index 160c651..c03ff58 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Pointer.cpp @@ -23,5 +23,5 @@ void fir::runtime::genPointerAssociateScalar(fir::FirOpBuilder &builder, mlir::FunctionType fTy{func.getFunctionType()}; llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, desc, target)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp index e5d0fb0..e5cf963 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Ragged.cpp @@ -34,25 +34,25 @@ void fir::runtime::genRaggedArrayAllocate(mlir::Location loc, auto eleTy = fir::unwrapSequenceType(fir::unwrapRefType(header.getType())); auto ptrTy = builder.getRefType(mlir::cast<mlir::TupleType>(eleTy).getType(1)); - auto ptr = builder.create<fir::CoordinateOp>(loc, ptrTy, header, one); - auto heap = builder.create<fir::LoadOp>(loc, ptr); + auto ptr = fir::CoordinateOp::create(builder, loc, ptrTy, header, one); + auto heap = fir::LoadOp::create(builder, loc, ptr); auto cmp = builder.genIsNullAddr(loc, heap); builder.genIfThen(loc, cmp) .genThen([&]() { auto asHeadersVal = builder.createIntegerConstant(loc, i1Ty, asHeaders); auto rankVal = builder.createIntegerConstant(loc, i64Ty, rank); - auto buff = builder.create<fir::AllocMemOp>(loc, extentTy); + auto buff = fir::AllocMemOp::create(builder, loc, extentTy); // Convert all the extents to i64 and pack them in a buffer on the heap. for (auto i : llvm::enumerate(extents)) { auto offset = builder.createIntegerConstant(loc, i32Ty, i.index()); auto addr = - builder.create<fir::CoordinateOp>(loc, refTy, buff, offset); + fir::CoordinateOp::create(builder, loc, refTy, buff, offset); auto castVal = builder.createConvert(loc, i64Ty, i.value()); - builder.create<fir::StoreOp>(loc, castVal, addr); + fir::StoreOp::create(builder, loc, castVal, addr); } auto args = fir::runtime::createArguments( builder, loc, fTy, header, asHeadersVal, rankVal, eleSize, buff); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); }) .end(); } @@ -64,5 +64,5 @@ void fir::runtime::genRaggedArrayDeallocate(mlir::Location loc, loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, header); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp index f778b96..157d435 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp @@ -1155,7 +1155,7 @@ mlir::Value genSpecial2Args(FN func, fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); auto args = fir::runtime::createArguments(builder, loc, fTy, maskBox, sourceFile, sourceLine, dim); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate calls to reduction intrinsics such as All and Any. @@ -1171,7 +1171,7 @@ static void genReduction2Args(FN func, fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, maskBox, dim, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxval and Minval. @@ -1189,7 +1189,7 @@ static void genReduction3Args(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, dim, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxloc and Minloc. @@ -1206,7 +1206,7 @@ static void genReduction4Args(FN func, fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, kind, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate calls to reduction intrinsics such as Maxloc and Minloc. @@ -1223,7 +1223,7 @@ genReduction5Args(FN func, fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, kind, dim, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `AllDim` runtime routine. @@ -1296,7 +1296,7 @@ void fir::runtime::genCountDim(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(5)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, maskBox, dim, kind, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Findloc` intrinsic runtime routine. This is the version @@ -1313,7 +1313,7 @@ void fir::runtime::genFindloc(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, valBox, kind, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `FindlocDim` intrinsic runtime routine. This is the version @@ -1331,7 +1331,7 @@ void fir::runtime::genFindlocDim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, valBox, kind, dim, sourceFile, sourceLine, maskBox, back); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Maxloc` intrinsic runtime routine. This is the version @@ -1392,7 +1392,7 @@ mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `MaxvalDim` intrinsic runtime routine. This is the version @@ -1417,7 +1417,7 @@ void fir::runtime::genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Minloc` intrinsic runtime routine. This is the version @@ -1476,7 +1476,7 @@ void fir::runtime::genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Minval` intrinsic runtime routine. This is the version @@ -1504,7 +1504,7 @@ mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `Norm2Dim` intrinsic runtime routine. This is the version @@ -1527,7 +1527,7 @@ void fir::runtime::genNorm2Dim(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, dim, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Norm2` intrinsic runtime routine. This is the version @@ -1558,7 +1558,7 @@ mlir::Value fir::runtime::genNorm2(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `Parity` intrinsic runtime routine. This routine is @@ -1604,7 +1604,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, dim, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1613,7 +1613,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `DotProduct` intrinsic runtime routine. @@ -1645,7 +1645,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, vectorABox, vectorBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1653,7 +1653,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, vectorABox, vectorBBox, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } /// Generate call to `SumDim` intrinsic runtime routine. This is the version /// that handles any rank array with the dim argument specified. @@ -1688,7 +1688,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine, dim, maskBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); return resultBox; } @@ -1697,7 +1697,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } // The IAll, IAny and IParity intrinsics have essentially the same @@ -1733,7 +1733,7 @@ mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments( \ builder, loc, fTy, arrayBox, sourceFile, sourceLine, dim, maskBox); \ \ - return builder.create<fir::CallOp>(loc, func, args).getResult(0); \ + return fir::CallOp::create(builder, loc, func, args).getResult(0); \ } /// Generate call to `IAllDim` intrinsic runtime routine. This is the version @@ -1819,11 +1819,12 @@ void fir::runtime::genReduce(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(2), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(2), operation); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `Reduce` intrinsic runtime routine. This is the version @@ -1864,11 +1865,12 @@ mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder, auto sourceFile = fir::factory::locationToFilename(builder, loc); auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(1), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(1), operation); auto args = fir::runtime::createArguments(builder, loc, fTy, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genReduceDim(fir::FirOpBuilder &builder, mlir::Location loc, @@ -1912,9 +1914,10 @@ void fir::runtime::genReduceDim(fir::FirOpBuilder &builder, mlir::Location loc, auto sourceLine = fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); - auto opAddr = builder.create<fir::BoxAddrOp>(loc, fTy.getInput(2), operation); + auto opAddr = + fir::BoxAddrOp::create(builder, loc, fTy.getInput(2), operation); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, opAddr, sourceFile, sourceLine, dim, maskBox, identity, ordered); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp index 411181c..5629371 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp @@ -19,13 +19,13 @@ void fir::runtime::genExit(fir::FirOpBuilder &builder, mlir::Location loc, auto exitFunc = fir::runtime::getRuntimeFunc<mkRTKey(Exit)>(loc, builder); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, exitFunc.getFunctionType(), status); - builder.create<fir::CallOp>(loc, exitFunc, args); + fir::CallOp::create(builder, loc, exitFunc, args); } void fir::runtime::genAbort(fir::FirOpBuilder &builder, mlir::Location loc) { mlir::func::FuncOp abortFunc = fir::runtime::getRuntimeFunc<mkRTKey(Abort)>(loc, builder); - builder.create<fir::CallOp>(loc, abortFunc, std::nullopt); + fir::CallOp::create(builder, loc, abortFunc, mlir::ValueRange{}); } void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder, @@ -41,5 +41,5 @@ void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder, mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc); llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( builder, loc, funcTy, msgVal, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, crashFunc, args); + fir::CallOp::create(builder, loc, crashFunc, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Support.cpp b/flang/lib/Optimizer/Builder/Runtime/Support.cpp index b5e9ddb..d0d48ad 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Support.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Support.cpp @@ -42,7 +42,7 @@ void fir::runtime::genCopyAndUpdateDescriptor(fir::FirOpBuilder &builder, func.setArgAttr(0, noCapture, unitAttr); func.setArgAttr(1, noCapture, unitAttr); } - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } mlir::Value fir::runtime::genIsAssumedSize(fir::FirOpBuilder &builder, @@ -52,5 +52,5 @@ mlir::Value fir::runtime::genIsAssumedSize(fir::FirOpBuilder &builder, fir::runtime::getRuntimeFunc<mkRTKey(IsAssumedSize)>(loc, builder); auto fTy = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, fTy, box); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } diff --git a/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp b/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp index 732152c..effd712 100644 --- a/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp @@ -23,7 +23,7 @@ mlir::Value fir::runtime::genCreateValueStack(mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcType.getInput(1)); auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPushValue(mlir::Location loc, fir::FirOpBuilder &builder, @@ -33,7 +33,7 @@ void fir::runtime::genPushValue(mlir::Location loc, fir::FirOpBuilder &builder, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, boxValue); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genValueAt(mlir::Location loc, fir::FirOpBuilder &builder, @@ -44,7 +44,7 @@ void fir::runtime::genValueAt(mlir::Location loc, fir::FirOpBuilder &builder, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, i, retValueBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDestroyValueStack(mlir::Location loc, @@ -54,7 +54,7 @@ void fir::runtime::genDestroyValueStack(mlir::Location loc, fir::runtime::getRuntimeFunc<mkRTKey(DestroyValueStack)>(loc, builder); mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } mlir::Value fir::runtime::genCreateDescriptorStack(mlir::Location loc, @@ -68,7 +68,7 @@ mlir::Value fir::runtime::genCreateDescriptorStack(mlir::Location loc, fir::factory::locationToLineNo(builder, loc, funcType.getInput(1)); auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile, sourceLine); - return builder.create<fir::CallOp>(loc, func, args).getResult(0); + return fir::CallOp::create(builder, loc, func, args).getResult(0); } void fir::runtime::genPushDescriptor(mlir::Location loc, @@ -80,7 +80,7 @@ void fir::runtime::genPushDescriptor(mlir::Location loc, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, boxDescriptor); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDescriptorAt(mlir::Location loc, @@ -92,7 +92,7 @@ void fir::runtime::genDescriptorAt(mlir::Location loc, mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr, i, retDescriptorBox); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } void fir::runtime::genDestroyDescriptorStack(mlir::Location loc, @@ -103,5 +103,5 @@ void fir::runtime::genDestroyDescriptorStack(mlir::Location loc, builder); mlir::FunctionType funcType = func.getFunctionType(); auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp index 47744b0..6251def 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp @@ -170,7 +170,7 @@ void fir::runtime::genBesselJn(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, x, bn2, bn2_1, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselJn` intrinsic. This is used when `x == 0.0`. @@ -196,7 +196,7 @@ void fir::runtime::genBesselJnX0(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselYn` intrinsic. @@ -225,7 +225,7 @@ void fir::runtime::genBesselYn(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, x, bn1, bn1_1, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to `BesselYn` intrinsic. This is used when `x == 0.0`. @@ -251,7 +251,7 @@ void fir::runtime::genBesselYnX0(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, n1, n2, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Cshift intrinsic @@ -266,7 +266,7 @@ void fir::runtime::genCshift(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, dimBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, cshiftFunc, args); + fir::CallOp::create(builder, loc, cshiftFunc, args); } /// Generate call to the vector version of the Cshift intrinsic @@ -282,7 +282,7 @@ void fir::runtime::genCshiftVector(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); auto args = fir::runtime::createArguments( builder, loc, fTy, resultBox, arrayBox, shiftBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, cshiftFunc, args); + fir::CallOp::create(builder, loc, cshiftFunc, args); } /// Generate call to Eoshift intrinsic @@ -299,7 +299,7 @@ void fir::runtime::genEoshift(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, boundBox, dimBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, eoshiftFunc, args); + fir::CallOp::create(builder, loc, eoshiftFunc, args); } /// Generate call to the vector version of the Eoshift intrinsic @@ -318,7 +318,7 @@ void fir::runtime::genEoshiftVector(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, shiftBox, boundBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, eoshiftFunc, args); + fir::CallOp::create(builder, loc, eoshiftFunc, args); } /// Define ForcedMatmul<ACAT><AKIND><BCAT><BKIND> models. @@ -388,7 +388,7 @@ void fir::runtime::genMatmul(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, matrixABox, matrixBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Define ForcedMatmulTranspose<ACAT><AKIND><BCAT><BKIND> models. @@ -440,7 +440,7 @@ void fir::runtime::genMatmulTranspose(fir::FirOpBuilder &builder, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, matrixABox, matrixBBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Pack intrinsic runtime routine. @@ -455,7 +455,7 @@ void fir::runtime::genPack(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, maskBox, vectorBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, packFunc, args); + fir::CallOp::create(builder, loc, packFunc, args); } /// Generate call to Reshape intrinsic runtime routine. @@ -471,7 +471,7 @@ void fir::runtime::genReshape(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, shapeBox, padBox, orderBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to ShallowCopy[Direct] runtime routine. @@ -491,7 +491,7 @@ void fir::runtime::genShallowCopy(fir::FirOpBuilder &builder, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, arrayBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, packFunc, args); + fir::CallOp::create(builder, loc, packFunc, args); } /// Generate call to Spread intrinsic runtime routine. @@ -506,7 +506,7 @@ void fir::runtime::genSpread(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, dim, ncopies, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Transpose intrinsic runtime routine. @@ -519,7 +519,7 @@ void fir::runtime::genTranspose(fir::FirOpBuilder &builder, mlir::Location loc, fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, sourceBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } /// Generate call to Unpack intrinsic runtime routine. @@ -534,5 +534,5 @@ void fir::runtime::genUnpack(fir::FirOpBuilder &builder, mlir::Location loc, auto args = fir::runtime::createArguments(builder, loc, fTy, resultBox, vectorBox, maskBox, fieldBox, sourceFile, sourceLine); - builder.create<fir::CallOp>(loc, unpackFunc, args); + fir::CallOp::create(builder, loc, unpackFunc, args); } diff --git a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp index 9d2e983..4c648df 100644 --- a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp +++ b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp @@ -28,7 +28,7 @@ fir::factory::Counter::Counter(mlir::Location loc, fir::FirOpBuilder &builder, one = builder.createIntegerConstant(loc, type, 1); if (canCountThroughLoops) { index = builder.createTemporary(loc, type); - builder.create<fir::StoreOp>(loc, initialValue, index); + fir::StoreOp::create(builder, loc, initialValue, index); } else { index = initialValue; } @@ -38,21 +38,21 @@ mlir::Value fir::factory::Counter::getAndIncrementIndex(mlir::Location loc, fir::FirOpBuilder &builder) { if (canCountThroughLoops) { - mlir::Value indexValue = builder.create<fir::LoadOp>(loc, index); + mlir::Value indexValue = fir::LoadOp::create(builder, loc, index); mlir::Value newValue = - builder.create<mlir::arith::AddIOp>(loc, indexValue, one); - builder.create<fir::StoreOp>(loc, newValue, index); + mlir::arith::AddIOp::create(builder, loc, indexValue, one); + fir::StoreOp::create(builder, loc, newValue, index); return indexValue; } mlir::Value indexValue = index; - index = builder.create<mlir::arith::AddIOp>(loc, indexValue, one); + index = mlir::arith::AddIOp::create(builder, loc, indexValue, one); return indexValue; } void fir::factory::Counter::reset(mlir::Location loc, fir::FirOpBuilder &builder) { if (canCountThroughLoops) - builder.create<fir::StoreOp>(loc, initialValue, index); + fir::StoreOp::create(builder, loc, initialValue, index); else index = initialValue; } @@ -103,7 +103,7 @@ void fir::factory::HomogeneousScalarStack::pushValue(mlir::Location loc, // below should not get hit but is added as a remainder/safety. if (!entity.hasIntrinsicType()) TODO(loc, "creating inlined temporary stack for derived types"); - builder.create<hlfir::AssignOp>(loc, value, tempElement); + hlfir::AssignOp::create(builder, loc, value, tempElement); } void fir::factory::HomogeneousScalarStack::resetFetchPosition( @@ -125,14 +125,14 @@ void fir::factory::HomogeneousScalarStack::destroy(mlir::Location loc, if (allocateOnHeap) { auto declare = temp.getDefiningOp<hlfir::DeclareOp>(); assert(declare && "temp must have been declared"); - builder.create<fir::FreeMemOp>(loc, declare.getMemref()); + fir::FreeMemOp::create(builder, loc, declare.getMemref()); } } hlfir::Entity fir::factory::HomogeneousScalarStack::moveStackAsArrayExpr( mlir::Location loc, fir::FirOpBuilder &builder) { mlir::Value mustFree = builder.createBool(loc, allocateOnHeap); - auto hlfirExpr = builder.create<hlfir::AsExprOp>(loc, temp, mustFree); + auto hlfirExpr = hlfir::AsExprOp::create(builder, loc, temp, mustFree); return hlfir::Entity{hlfirExpr}; } @@ -147,14 +147,14 @@ fir::factory::SimpleCopy::SimpleCopy(mlir::Location loc, // Use hlfir.as_expr and hlfir.associate to create a copy and leave // bufferization deals with how best to make the copy. if (source.isVariable()) - source = hlfir::Entity{builder.create<hlfir::AsExprOp>(loc, source)}; + source = hlfir::Entity{hlfir::AsExprOp::create(builder, loc, source)}; copy = hlfir::genAssociateExpr(loc, builder, source, source.getFortranElementType(), tempName); } void fir::factory::SimpleCopy::destroy(mlir::Location loc, fir::FirOpBuilder &builder) { - builder.create<hlfir::EndAssociateOp>(loc, copy); + hlfir::EndAssociateOp::create(builder, loc, copy); } //===----------------------------------------------------------------------===// @@ -279,7 +279,7 @@ mlir::Value fir::factory::AnyVariableStack::fetch(mlir::Location loc, mlir::Value indexValue = counter.getAndIncrementIndex(loc, builder); fir::runtime::genDescriptorAt(loc, builder, opaquePtr, indexValue, retValueBox); - hlfir::Entity retBox{builder.create<fir::LoadOp>(loc, retValueBox)}; + hlfir::Entity retBox{fir::LoadOp::create(builder, loc, retValueBox)}; // The runtime always tracks variable as address, but the form of the variable // that was saved may be different (raw address, fir.boxchar), ensure // the returned variable has the same form of the one that was saved. @@ -326,7 +326,7 @@ void fir::factory::AnyVectorSubscriptStack::pushShape( hlfir::getFortranElementOrSequenceType(*boxType)); mlir::Value null = builder.createNullConstant(loc, refType); mlir::Value descriptor = - builder.create<fir::EmboxOp>(loc, *boxType, null, shape); + fir::EmboxOp::create(builder, loc, *boxType, null, shape); shapeTemp->pushValue(loc, builder, descriptor); return; } @@ -372,7 +372,7 @@ void fir::factory::AnyAddressStack::pushValue(mlir::Location loc, mlir::Value cast = variable; if (auto boxProcType = llvm::dyn_cast<fir::BoxProcType>(variable.getType())) { cast = - builder.create<fir::BoxAddrOp>(loc, boxProcType.getEleTy(), variable); + fir::BoxAddrOp::create(builder, loc, boxProcType.getEleTy(), variable); } cast = builder.createConvert(loc, builder.getIntPtrType(), cast); static_cast<AnyValueStack *>(this)->pushValue(loc, builder, cast); @@ -383,7 +383,7 @@ mlir::Value fir::factory::AnyAddressStack::fetch(mlir::Location loc, mlir::Value addr = static_cast<AnyValueStack *>(this)->fetch(loc, builder); if (auto boxProcType = llvm::dyn_cast<fir::BoxProcType>(addressType)) { mlir::Value cast = builder.createConvert(loc, boxProcType.getEleTy(), addr); - return builder.create<fir::EmboxProcOp>(loc, boxProcType, cast); + return fir::EmboxProcOp::create(builder, loc, boxProcType, cast); } return builder.createConvert(loc, addressType, addr); } diff --git a/flang/lib/Optimizer/CodeGen/CMakeLists.txt b/flang/lib/Optimizer/CodeGen/CMakeLists.txt index 16c7944a..d5ea3c7 100644 --- a/flang/lib/Optimizer/CodeGen/CMakeLists.txt +++ b/flang/lib/Optimizer/CodeGen/CMakeLists.txt @@ -37,6 +37,7 @@ add_flang_library(FIRCodeGen MLIRComplexToROCDLLibraryCalls MLIRComplexToStandard MLIRGPUDialect + MLIRIndexToLLVM MLIRMathToFuncs MLIRMathToLLVM MLIRMathToLibm diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index d879382..609ba27 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -37,6 +37,7 @@ #include "mlir/Conversion/ComplexToStandard/ComplexToStandard.h" #include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h" #include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h" +#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h" #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Conversion/MathToFuncs/MathToFuncs.h" #include "mlir/Conversion/MathToLLVM/MathToLLVM.h" @@ -4224,6 +4225,7 @@ public: if (!isAMDGCN) mlir::populateMathToLibmConversionPatterns(pattern); mlir::populateComplexToLLVMConversionPatterns(typeConverter, pattern); + mlir::index::populateIndexToLLVMConversionPatterns(typeConverter, pattern); mlir::populateVectorToLLVMConversionPatterns(typeConverter, pattern); // Flang specific overloads for OpenMP operations, to allow for special diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp index 03cc92e..c5cf01e 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp @@ -405,7 +405,7 @@ void OrderedAssignmentRewriter::pre(hlfir::ForallMaskOp forallMaskOp) { mlir::Location loc = forallMaskOp.getLoc(); mlir::Value mask = generateYieldedScalarValue(forallMaskOp.getMaskRegion(), builder.getI1Type()); - auto ifOp = builder.create<fir::IfOp>(loc, std::nullopt, mask, false); + auto ifOp = builder.create<fir::IfOp>(loc, mlir::TypeRange{}, mask, false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); constructStack.push_back(ifOp); } @@ -530,7 +530,7 @@ void OrderedAssignmentRewriter::generateMaskIfOp(mlir::Value cdt) { mlir::Location loc = cdt.getLoc(); cdt = hlfir::loadTrivialScalar(loc, builder, hlfir::Entity{cdt}); cdt = builder.createConvert(loc, builder.getI1Type(), cdt); - auto ifOp = builder.create<fir::IfOp>(cdt.getLoc(), std::nullopt, cdt, + auto ifOp = builder.create<fir::IfOp>(cdt.getLoc(), mlir::TypeRange{}, cdt, /*withElseRegion=*/false); constructStack.push_back(ifOp.getOperation()); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp index 59e2eeb..391cfe3 100644 --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -137,9 +137,9 @@ public: auto buffer = saveResult.getMemref(); mlir::Value arg = buffer; if (mustEmboxResult(result.getType(), shouldBoxResult)) - arg = rewriter.create<fir::EmboxOp>( - loc, argType, buffer, saveResult.getShape(), /*slice*/ mlir::Value{}, - saveResult.getTypeparams()); + arg = fir::EmboxOp::create(rewriter, loc, argType, buffer, + saveResult.getShape(), /*slice*/ mlir::Value{}, + saveResult.getTypeparams()); llvm::SmallVector<mlir::Type> newResultTypes; bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType()); @@ -155,8 +155,8 @@ public: if (!isResultBuiltinCPtr) newOperands.emplace_back(arg); newOperands.append(op.getOperands().begin(), op.getOperands().end()); - newOp = rewriter.create<fir::CallOp>(loc, *op.getCallee(), - newResultTypes, newOperands); + newOp = fir::CallOp::create(rewriter, loc, *op.getCallee(), + newResultTypes, newOperands); } else { // Indirect calls. llvm::SmallVector<mlir::Type> newInputTypes; @@ -169,13 +169,13 @@ public: llvm::SmallVector<mlir::Value> newOperands; newOperands.push_back( - rewriter.create<fir::ConvertOp>(loc, newFuncTy, op.getOperand(0))); + fir::ConvertOp::create(rewriter, loc, newFuncTy, op.getOperand(0))); if (!isResultBuiltinCPtr) newOperands.push_back(arg); newOperands.append(op.getOperands().begin() + 1, op.getOperands().end()); - newOp = rewriter.create<fir::CallOp>(loc, mlir::SymbolRefAttr{}, - newResultTypes, newOperands); + newOp = fir::CallOp::create(rewriter, loc, mlir::SymbolRefAttr{}, + newResultTypes, newOperands); } } @@ -191,8 +191,8 @@ public: passArgPos = rewriter.getI32IntegerAttr(*op.getPassArgPos() + passArgShift); // TODO: propagate argument and result attributes (need to be shifted). - newOp = rewriter.create<fir::DispatchOp>( - loc, newResultTypes, rewriter.getStringAttr(op.getMethod()), + newOp = fir::DispatchOp::create( + rewriter, loc, newResultTypes, rewriter.getStringAttr(op.getMethod()), op.getOperands()[0], newOperands, passArgPos, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr, op.getProcedureAttrsAttr()); @@ -280,7 +280,7 @@ processReturnLikeOp(OpTy ret, mlir::Value newArg, // register pass, this is possible for fir.box results, or fir.record // with no length parameters. Simply store the result in the result // storage. at the return point. - rewriter.create<fir::StoreOp>(loc, resultValue, newArg); + fir::StoreOp::create(rewriter, loc, resultValue, newArg); rewriter.replaceOpWithNewOp<OpTy>(ret); } // Delete result old local storage if unused. @@ -337,8 +337,8 @@ public: newFuncTy = getCPtrFunctionType(oldFuncTy); else newFuncTy = getNewFunctionType(oldFuncTy, shouldBoxResult); - auto newAddrOf = rewriter.create<fir::AddrOfOp>(addrOf.getLoc(), newFuncTy, - addrOf.getSymbol()); + auto newAddrOf = fir::AddrOfOp::create(rewriter, addrOf.getLoc(), newFuncTy, + 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 @@ -397,7 +397,7 @@ public: if (mustEmboxResult(resultType, shouldBoxResult)) { auto bufferType = fir::ReferenceType::get(resultType); rewriter.setInsertionPointToStart(&func.front()); - newArg = rewriter.create<fir::BoxAddrOp>(loc, bufferType, newArg); + newArg = fir::BoxAddrOp::create(rewriter, loc, bufferType, newArg); } patterns.insert<ReturnOpConversion>(context, newArg); target.addDynamicallyLegalOp<mlir::func::ReturnOp>( diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp index b27c1b2..85403ad 100644 --- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp +++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp @@ -48,12 +48,21 @@ static llvm::cl::opt<bool> llvm::cl::Hidden, llvm::cl::desc("Add TBAA tags to local allocations.")); +// Engineering option to triage TBAA tags attachment for accesses +// of allocatable entities. +static llvm::cl::opt<unsigned> localAllocsThreshold( + "local-alloc-tbaa-threshold", llvm::cl::init(0), llvm::cl::ReallyHidden, + llvm::cl::desc("If present, stops generating TBAA tags for accesses of " + "local allocations after N accesses in a module")); + namespace { /// Shared state per-module class PassState { public: - PassState(mlir::DominanceInfo &domInfo) : domInfo(domInfo) {} + PassState(mlir::DominanceInfo &domInfo, + std::optional<unsigned> localAllocsThreshold) + : domInfo(domInfo), localAllocsThreshold(localAllocsThreshold) {} /// memoised call to fir::AliasAnalysis::getSource inline const fir::AliasAnalysis::Source &getSource(mlir::Value value) { if (!analysisCache.contains(value)) @@ -84,6 +93,11 @@ public: // (e.g. !fir.ref<!fir.type<Derived{f:!fir.box<!fir.heap<f32>>}>>). bool typeReferencesDescriptor(mlir::Type type); + // Returns true if we can attach a TBAA tag to an access of an allocatable + // entities. It checks if localAllocsThreshold allows the next tag + // attachment. + bool attachLocalAllocTag(); + private: mlir::DominanceInfo &domInfo; fir::AliasAnalysis analysis; @@ -103,6 +117,8 @@ private: // Local pass cache for derived types that contain descriptor // member(s), to avoid the cost of isRecordWithDescriptorMember(). llvm::DenseSet<mlir::Type> typesContainingDescriptors; + + std::optional<unsigned> localAllocsThreshold; }; // Process fir.dummy_scope operations in the given func: @@ -169,6 +185,19 @@ bool PassState::typeReferencesDescriptor(mlir::Type type) { return false; } +bool PassState::attachLocalAllocTag() { + if (!localAllocsThreshold) + return true; + if (*localAllocsThreshold == 0) { + LLVM_DEBUG(llvm::dbgs().indent(2) + << "WARN: not assigning TBAA tag for an allocated entity access " + "due to the threshold\n"); + return false; + } + --*localAllocsThreshold; + return true; +} + class AddAliasTagsPass : public fir::impl::AddAliasTagsBase<AddAliasTagsPass> { public: void runOnOperation() override; @@ -335,16 +364,16 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op, LLVM_DEBUG(llvm::dbgs().indent(2) << "WARN: unknown defining op for SourceKind::Allocate " << *op << "\n"); - } else if (source.isPointer()) { + } else if (source.isPointer() && state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to allocation at " << *op << "\n"); tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag(); - } else if (name) { + } else if (name && state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to allocation " << name << " at " << *op << "\n"); tag = state.getFuncTreeWithScope(func, scopeOp) .allocatedDataTree.getTag(*name); - } else { + } else if (state.attachLocalAllocTag()) { LLVM_DEBUG(llvm::dbgs().indent(2) << "WARN: couldn't find a name for allocation " << *op << "\n"); @@ -372,7 +401,9 @@ void AddAliasTagsPass::runOnOperation() { // thinks the pass operates on), then the real work of the pass is done in // runOnAliasInterface auto &domInfo = getAnalysis<mlir::DominanceInfo>(); - PassState state(domInfo); + PassState state(domInfo, localAllocsThreshold.getPosition() + ? std::optional<unsigned>(localAllocsThreshold) + : std::nullopt); mlir::ModuleOp mod = getOperation(); mod.walk( diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp index d45f855..f1c66a5 100644 --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -60,9 +60,10 @@ public: if (!maybeExpandedMap) return failure(); - auto coorOp = rewriter.create<fir::CoordinateOp>( - op.getLoc(), fir::ReferenceType::get(op.getResult().getType()), - adaptor.getMemref(), *maybeExpandedMap); + auto coorOp = fir::CoordinateOp::create( + rewriter, op.getLoc(), + fir::ReferenceType::get(op.getResult().getType()), adaptor.getMemref(), + *maybeExpandedMap); rewriter.replaceOpWithNewOp<fir::LoadOp>(op, coorOp.getResult()); return success(); @@ -83,8 +84,9 @@ public: if (!maybeExpandedMap) return failure(); - auto coorOp = rewriter.create<fir::CoordinateOp>( - op.getLoc(), fir::ReferenceType::get(op.getValueToStore().getType()), + auto coorOp = fir::CoordinateOp::create( + rewriter, op.getLoc(), + fir::ReferenceType::get(op.getValueToStore().getType()), adaptor.getMemref(), *maybeExpandedMap); rewriter.replaceOpWithNewOp<fir::StoreOp>(op, adaptor.getValue(), coorOp.getResult()); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index ef82e400..b032767 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -366,8 +366,9 @@ static mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) { static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeOp shape, SmallVectorImpl<mlir::Value> &indexArgs, mlir::PatternRewriter &rewriter) { - auto one = rewriter.create<mlir::arith::ConstantOp>( - acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); + auto one = mlir::arith::ConstantOp::create(rewriter, acoOp.getLoc(), + rewriter.getIndexType(), + rewriter.getIndexAttr(1)); auto extents = shape.getExtents(); for (auto i = extents.begin(); i < extents.end(); i++) { indexArgs.push_back(one); @@ -379,8 +380,9 @@ static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeOp shape, static void populateIndexArgs(fir::ArrayCoorOp acoOp, fir::ShapeShiftOp shape, SmallVectorImpl<mlir::Value> &indexArgs, mlir::PatternRewriter &rewriter) { - auto one = rewriter.create<mlir::arith::ConstantOp>( - acoOp.getLoc(), rewriter.getIndexType(), rewriter.getIndexAttr(1)); + auto one = mlir::arith::ConstantOp::create(rewriter, acoOp.getLoc(), + rewriter.getIndexType(), + rewriter.getIndexAttr(1)); auto extents = shape.getPairs(); for (auto i = extents.begin(); i < extents.end();) { indexArgs.push_back(*i++); @@ -422,13 +424,13 @@ createAffineOps(mlir::Value arrayRef, mlir::PatternRewriter &rewriter) { populateIndexArgs(acoOp, indexArgs, rewriter); - auto affineApply = rewriter.create<affine::AffineApplyOp>( - acoOp.getLoc(), affineMap, indexArgs); + auto affineApply = affine::AffineApplyOp::create(rewriter, acoOp.getLoc(), + affineMap, indexArgs); auto arrayElementType = coordinateArrayElement(acoOp); auto newType = mlir::MemRefType::get({mlir::ShapedType::kDynamic}, arrayElementType); - auto arrayConvert = rewriter.create<fir::ConvertOp>(acoOp.getLoc(), newType, - acoOp.getMemref()); + auto arrayConvert = fir::ConvertOp::create(rewriter, acoOp.getLoc(), newType, + acoOp.getMemref()); return std::make_pair(affineApply, arrayConvert); } @@ -495,7 +497,7 @@ public: affineFor.getRegionIterArgs()); if (!results.empty()) { rewriter.setInsertionPointToEnd(affineFor.getBody()); - rewriter.create<affine::AffineYieldOp>(resultOp->getLoc(), results); + affine::AffineYieldOp::create(rewriter, resultOp->getLoc(), results); } rewriter.finalizeOpModification(affineFor.getOperation()); @@ -525,8 +527,8 @@ private: std::pair<affine::AffineForOp, mlir::Value> positiveConstantStep(fir::DoLoopOp op, int64_t step, mlir::PatternRewriter &rewriter) const { - auto affineFor = rewriter.create<affine::AffineForOp>( - op.getLoc(), ValueRange(op.getLowerBound()), + auto affineFor = affine::AffineForOp::create( + rewriter, op.getLoc(), ValueRange(op.getLowerBound()), mlir::AffineMap::get(0, 1, mlir::getAffineSymbolExpr(0, op.getContext())), ValueRange(op.getUpperBound()), @@ -543,24 +545,24 @@ private: auto step = mlir::getAffineSymbolExpr(2, op.getContext()); mlir::AffineMap upperBoundMap = mlir::AffineMap::get( 0, 3, (upperBound - lowerBound + step).floorDiv(step)); - auto genericUpperBound = rewriter.create<affine::AffineApplyOp>( - op.getLoc(), upperBoundMap, + auto genericUpperBound = affine::AffineApplyOp::create( + rewriter, op.getLoc(), upperBoundMap, ValueRange({op.getLowerBound(), op.getUpperBound(), op.getStep()})); auto actualIndexMap = mlir::AffineMap::get( 1, 2, (lowerBound + mlir::getAffineDimExpr(0, op.getContext())) * mlir::getAffineSymbolExpr(1, op.getContext())); - auto affineFor = rewriter.create<affine::AffineForOp>( - op.getLoc(), ValueRange(), + auto affineFor = affine::AffineForOp::create( + rewriter, op.getLoc(), ValueRange(), AffineMap::getConstantMap(0, op.getContext()), genericUpperBound.getResult(), mlir::AffineMap::get(0, 1, 1 + mlir::getAffineSymbolExpr(0, op.getContext())), 1, op.getIterOperands()); rewriter.setInsertionPointToStart(affineFor.getBody()); - auto actualIndex = rewriter.create<affine::AffineApplyOp>( - op.getLoc(), actualIndexMap, + auto actualIndex = affine::AffineApplyOp::create( + rewriter, op.getLoc(), actualIndexMap, ValueRange( {affineFor.getInductionVar(), op.getLowerBound(), op.getStep()})); return std::make_pair(affineFor, actualIndex.getResult()); @@ -588,8 +590,8 @@ public: << "AffineIfConversion: couldn't calculate affine condition\n";); return failure(); } - auto affineIf = rewriter.create<affine::AffineIfOp>( - op.getLoc(), affineCondition.getIntegerSet(), + auto affineIf = affine::AffineIfOp::create( + rewriter, op.getLoc(), affineCondition.getIntegerSet(), affineCondition.getAffineArgs(), !op.getElseRegion().empty()); rewriter.startOpModification(affineIf); affineIf.getThenBlock()->getOperations().splice( diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp index 8544d17..247ba95 100644 --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -856,7 +856,7 @@ static bool getAdjustedExtents(mlir::Location loc, auto idxTy = rewriter.getIndexType(); if (isAssumedSize(result)) { // Use slice information to compute the extent of the column. - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); mlir::Value size = one; if (mlir::Value sliceArg = arrLoad.getSlice()) { if (auto sliceOp = @@ -896,14 +896,14 @@ static mlir::Value getOrReadExtentsAndShapeOp( mlir::cast<SequenceType>(dyn_cast_ptrOrBoxEleTy(boxTy)).getDimension(); auto idxTy = rewriter.getIndexType(); for (decltype(rank) dim = 0; dim < rank; ++dim) { - auto dimVal = rewriter.create<mlir::arith::ConstantIndexOp>(loc, dim); - auto dimInfo = rewriter.create<BoxDimsOp>(loc, idxTy, idxTy, idxTy, - arrLoad.getMemref(), dimVal); + auto dimVal = mlir::arith::ConstantIndexOp::create(rewriter, loc, dim); + auto dimInfo = BoxDimsOp::create(rewriter, loc, idxTy, idxTy, idxTy, + arrLoad.getMemref(), dimVal); result.emplace_back(dimInfo.getResult(1)); } if (!arrLoad.getShape()) { auto shapeType = ShapeType::get(rewriter.getContext(), rank); - return rewriter.create<ShapeOp>(loc, shapeType, result); + return ShapeOp::create(rewriter, loc, shapeType, result); } auto shiftOp = arrLoad.getShape().getDefiningOp<ShiftOp>(); auto shapeShiftType = ShapeShiftType::get(rewriter.getContext(), rank); @@ -912,8 +912,8 @@ static mlir::Value getOrReadExtentsAndShapeOp( shapeShiftOperands.push_back(lb); shapeShiftOperands.push_back(extent); } - return rewriter.create<ShapeShiftOp>(loc, shapeShiftType, - shapeShiftOperands); + return ShapeShiftOp::create(rewriter, loc, shapeShiftType, + shapeShiftOperands); } copyUsingSlice = getAdjustedExtents(loc, rewriter, arrLoad, result, arrLoad.getShape()); @@ -952,13 +952,13 @@ static mlir::Value genCoorOp(mlir::PatternRewriter &rewriter, auto module = load->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); auto typeparams = getTypeParamsIfRawData(loc, builder, load, alloc.getType()); - mlir::Value result = rewriter.create<ArrayCoorOp>( - loc, eleTy, alloc, shape, slice, + mlir::Value result = ArrayCoorOp::create( + rewriter, loc, eleTy, alloc, shape, slice, llvm::ArrayRef<mlir::Value>{originated}.take_front(dimension), typeparams); if (dimension < originated.size()) - result = rewriter.create<fir::CoordinateOp>( - loc, resTy, result, + result = fir::CoordinateOp::create( + rewriter, loc, resTy, result, llvm::ArrayRef<mlir::Value>{originated}.drop_front(dimension)); return result; } @@ -971,13 +971,13 @@ static mlir::Value getCharacterLen(mlir::Location loc, FirOpBuilder &builder, // The loaded array is an emboxed value. Get the CHARACTER length from // the box value. auto eleSzInBytes = - builder.create<BoxEleSizeOp>(loc, charLenTy, load.getMemref()); + BoxEleSizeOp::create(builder, loc, charLenTy, load.getMemref()); auto kindSize = builder.getKindMap().getCharacterBitsize(charTy.getFKind()); auto kindByteSize = builder.createIntegerConstant(loc, charLenTy, kindSize / 8); - return builder.create<mlir::arith::DivSIOp>(loc, eleSzInBytes, - kindByteSize); + return mlir::arith::DivSIOp::create(builder, loc, eleSzInBytes, + kindByteSize); } // The loaded array is a (set of) unboxed values. If the CHARACTER's // length is not a constant, it must be provided as a type parameter to @@ -1003,11 +1003,11 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter, auto idxTy = rewriter.getIndexType(); // Build loop nest from column to row. for (auto sh : llvm::reverse(extents)) { - auto ubi = rewriter.create<ConvertOp>(loc, idxTy, sh); - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); - auto ub = rewriter.create<mlir::arith::SubIOp>(loc, idxTy, ubi, one); - auto loop = rewriter.create<DoLoopOp>(loc, zero, ub, one); + auto ubi = ConvertOp::create(rewriter, loc, idxTy, sh); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); + auto ub = mlir::arith::SubIOp::create(rewriter, loc, idxTy, ubi, one); + auto loop = DoLoopOp::create(rewriter, loc, zero, ub, one); rewriter.setInsertionPointToStart(loop.getBody()); indices.push_back(loop.getInductionVar()); } @@ -1015,13 +1015,13 @@ void genArrayCopy(mlir::Location loc, mlir::PatternRewriter &rewriter, std::reverse(indices.begin(), indices.end()); auto module = arrLoad->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); - auto fromAddr = rewriter.create<ArrayCoorOp>( - loc, getEleTy(src.getType()), src, shapeOp, + auto fromAddr = ArrayCoorOp::create( + rewriter, loc, getEleTy(src.getType()), src, shapeOp, CopyIn && copyUsingSlice ? sliceOp : mlir::Value{}, factory::originateIndices(loc, rewriter, src.getType(), shapeOp, indices), getTypeParamsIfRawData(loc, builder, arrLoad, src.getType())); - auto toAddr = rewriter.create<ArrayCoorOp>( - loc, getEleTy(dst.getType()), dst, shapeOp, + auto toAddr = ArrayCoorOp::create( + rewriter, loc, getEleTy(dst.getType()), dst, shapeOp, !CopyIn && copyUsingSlice ? sliceOp : mlir::Value{}, factory::originateIndices(loc, rewriter, dst.getType(), shapeOp, indices), getTypeParamsIfRawData(loc, builder, arrLoad, dst.getType())); @@ -1093,15 +1093,16 @@ allocateArrayTemp(mlir::Location loc, mlir::PatternRewriter &rewriter, findNonconstantExtents(baseType, extents); llvm::SmallVector<mlir::Value> typeParams = genArrayLoadTypeParameters(loc, rewriter, load); - mlir::Value allocmem = rewriter.create<AllocMemOp>( - loc, dyn_cast_ptrOrBoxEleTy(baseType), typeParams, nonconstantExtents); + mlir::Value allocmem = + AllocMemOp::create(rewriter, loc, dyn_cast_ptrOrBoxEleTy(baseType), + typeParams, nonconstantExtents); mlir::Type eleType = fir::unwrapSequenceType(fir::unwrapPassByRefType(baseType)); if (fir::isRecordWithAllocatableMember(eleType)) { // The allocatable component descriptors need to be set to a clean // deallocated status before anything is done with them. - mlir::Value box = rewriter.create<fir::EmboxOp>( - loc, fir::BoxType::get(allocmem.getType()), allocmem, shape, + mlir::Value box = fir::EmboxOp::create( + rewriter, loc, fir::BoxType::get(allocmem.getType()), allocmem, shape, /*slice=*/mlir::Value{}, typeParams); auto module = load->getParentOfType<mlir::ModuleOp>(); FirOpBuilder builder(rewriter, module); @@ -1111,12 +1112,12 @@ allocateArrayTemp(mlir::Location loc, mlir::PatternRewriter &rewriter, auto cleanup = [=](mlir::PatternRewriter &r) { FirOpBuilder builder(r, module); runtime::genDerivedTypeDestroy(builder, loc, box); - r.create<FreeMemOp>(loc, allocmem); + FreeMemOp::create(r, loc, allocmem); }; return {allocmem, cleanup}; } auto cleanup = [=](mlir::PatternRewriter &r) { - r.create<FreeMemOp>(loc, allocmem); + FreeMemOp::create(r, loc, allocmem); }; return {allocmem, cleanup}; } @@ -1257,7 +1258,7 @@ public: if (auto inEleTy = dyn_cast_ptrEleTy(input.getType())) { emitFatalError(loc, "array_update on references not supported"); } else { - rewriter.create<fir::StoreOp>(loc, input, coor); + fir::StoreOp::create(rewriter, loc, input, coor); } }; auto lhsEltRefType = toRefType(update.getMerge().getType()); @@ -1368,7 +1369,7 @@ public: auto *op = amend.getOperation(); rewriter.setInsertionPoint(op); auto loc = amend.getLoc(); - auto undef = rewriter.create<UndefOp>(loc, amend.getType()); + auto undef = UndefOp::create(rewriter, loc, amend.getType()); rewriter.replaceOp(amend, undef.getResult()); return mlir::success(); } diff --git a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp index 6af1cb9..4c7b228 100644 --- a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp @@ -88,8 +88,8 @@ public: (fir::isPolymorphicType(oldBoxType) || (newEleType != oldBoxType.unwrapInnerType())) && !fir::isPolymorphicType(newBoxType)) { - newDtype = builder.create<fir::TypeDescOp>( - loc, mlir::TypeAttr::get(newDerivedType)); + newDtype = fir::TypeDescOp::create(builder, loc, + mlir::TypeAttr::get(newDerivedType)); } else { newDtype = builder.createNullConstant(loc); } @@ -103,7 +103,7 @@ public: rebox.getBox(), newDtype, newAttribute, lowerBoundModifier); - mlir::Value descValue = builder.create<fir::LoadOp>(loc, tempDesc); + mlir::Value descValue = fir::LoadOp::create(builder, loc, tempDesc); mlir::Value castDesc = builder.createConvert(loc, newBoxType, descValue); rewriter.replaceOp(rebox, castDesc); return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp b/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp index 2dd6950..baa8e59 100644 --- a/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp +++ b/flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp @@ -68,25 +68,26 @@ struct CUFAddConstructor // Symbol reference to CUFRegisterAllocator. builder.setInsertionPointToEnd(mod.getBody()); - auto registerFuncOp = builder.create<mlir::LLVM::LLVMFuncOp>( - loc, RTNAME_STRING(CUFRegisterAllocator), funcTy); + auto registerFuncOp = mlir::LLVM::LLVMFuncOp::create( + builder, loc, RTNAME_STRING(CUFRegisterAllocator), funcTy); registerFuncOp.setVisibility(mlir::SymbolTable::Visibility::Private); auto cufRegisterAllocatorRef = mlir::SymbolRefAttr::get( mod.getContext(), RTNAME_STRING(CUFRegisterAllocator)); builder.setInsertionPointToEnd(mod.getBody()); // Create the constructor function that call CUFRegisterAllocator. - auto func = builder.create<mlir::LLVM::LLVMFuncOp>(loc, cudaFortranCtorName, - funcTy); + auto func = mlir::LLVM::LLVMFuncOp::create(builder, loc, + cudaFortranCtorName, funcTy); func.setLinkage(mlir::LLVM::Linkage::Internal); builder.setInsertionPointToStart(func.addEntryBlock(builder)); - builder.create<mlir::LLVM::CallOp>(loc, funcTy, cufRegisterAllocatorRef); + mlir::LLVM::CallOp::create(builder, loc, funcTy, cufRegisterAllocatorRef); auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(cudaDeviceModuleName); if (gpuMod) { auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(ctx); - auto registeredMod = builder.create<cuf::RegisterModuleOp>( - loc, llvmPtrTy, mlir::SymbolRefAttr::get(ctx, gpuMod.getName())); + auto registeredMod = cuf::RegisterModuleOp::create( + builder, loc, llvmPtrTy, + mlir::SymbolRefAttr::get(ctx, gpuMod.getName())); fir::LLVMTypeConverter typeConverter(mod, /*applyTBAA=*/false, /*forceUnifiedTBAATree=*/false, *dl); @@ -96,7 +97,8 @@ struct CUFAddConstructor auto kernelName = mlir::SymbolRefAttr::get( builder.getStringAttr(cudaDeviceModuleName), {mlir::SymbolRefAttr::get(builder.getContext(), func.getName())}); - builder.create<cuf::RegisterKernelOp>(loc, kernelName, registeredMod); + cuf::RegisterKernelOp::create(builder, loc, kernelName, + registeredMod); } } @@ -140,19 +142,19 @@ struct CUFAddConstructor auto sizeVal = builder.createIntegerConstant(loc, idxTy, *size); // Global variable address - mlir::Value addr = builder.create<fir::AddrOfOp>( - loc, globalOp.resultType(), globalOp.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, globalOp.resultType(), globalOp.getSymbol()); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, registeredMod, addr, gblName, sizeVal)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); } break; default: break; } } } - builder.create<mlir::LLVM::ReturnOp>(loc, mlir::ValueRange{}); + mlir::LLVM::ReturnOp::create(builder, loc, mlir::ValueRange{}); // Create the llvm.global_ctor with the function. // TODO: We might want to have a utility that retrieve it if already @@ -165,8 +167,8 @@ struct CUFAddConstructor llvm::SmallVector<mlir::Attribute> data; priorities.push_back(0); data.push_back(mlir::LLVM::ZeroAttr::get(mod.getContext())); - builder.create<mlir::LLVM::GlobalCtorsOp>( - mod.getLoc(), builder.getArrayAttr(funcs), + mlir::LLVM::GlobalCtorsOp::create( + builder, mod.getLoc(), builder.getArrayAttr(funcs), builder.getI32ArrayAttr(priorities), builder.getArrayAttr(data)); } }; diff --git a/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp b/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp index f6381ef..5e910f7 100644 --- a/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp +++ b/flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp @@ -93,10 +93,11 @@ struct CUFComputeSharedMemoryOffsetsAndSize mlir::Value dynSize = builder.createIntegerConstant(loc, idxTy, tySize); for (auto extent : sharedOp.getShape()) - dynSize = builder.create<mlir::arith::MulIOp>(loc, dynSize, extent); + dynSize = + mlir::arith::MulIOp::create(builder, loc, dynSize, extent); if (crtDynOffset) - crtDynOffset = - builder.create<mlir::arith::AddIOp>(loc, crtDynOffset, dynSize); + crtDynOffset = mlir::arith::AddIOp::create(builder, loc, + crtDynOffset, dynSize); else crtDynOffset = dynSize; @@ -142,9 +143,9 @@ struct CUFComputeSharedMemoryOffsetsAndSize fir::GlobalOp::getDataAttrAttrName(globalOpName), cuf::DataAttributeAttr::get(gpuMod.getContext(), cuf::DataAttribute::Shared))); - auto sharedMem = builder.create<fir::GlobalOp>( - funcOp.getLoc(), sharedMemGlobalName, false, false, sharedMemType, - init, linkage, attrs); + auto sharedMem = fir::GlobalOp::create( + builder, funcOp.getLoc(), sharedMemGlobalName, false, false, + sharedMemType, init, linkage, attrs); sharedMem.setAlignment(alignment); } } diff --git a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp index fe69ffa8..a40ed95 100644 --- a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp @@ -46,27 +46,28 @@ static mlir::Value createKernelArgArray(mlir::Location loc, auto structTy = mlir::LLVM::LLVMStructType::getLiteral(ctx, structTypes); auto ptrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext()); mlir::Type i32Ty = rewriter.getI32Type(); - auto zero = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); - auto one = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 1)); + auto zero = mlir::LLVM::ConstantOp::create(rewriter, loc, i32Ty, + rewriter.getIntegerAttr(i32Ty, 0)); + auto one = mlir::LLVM::ConstantOp::create(rewriter, loc, i32Ty, + rewriter.getIntegerAttr(i32Ty, 1)); mlir::Value argStruct = - rewriter.create<mlir::LLVM::AllocaOp>(loc, ptrTy, structTy, one); - auto size = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, structTypes.size())); + mlir::LLVM::AllocaOp::create(rewriter, loc, ptrTy, structTy, one); + auto size = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, structTypes.size())); mlir::Value argArray = - rewriter.create<mlir::LLVM::AllocaOp>(loc, ptrTy, ptrTy, size); + mlir::LLVM::AllocaOp::create(rewriter, loc, ptrTy, ptrTy, size); for (auto [i, arg] : llvm::enumerate(operands)) { - auto indice = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, i)); - mlir::Value structMember = rewriter.create<LLVM::GEPOp>( - loc, ptrTy, structTy, argStruct, - mlir::ArrayRef<mlir::Value>({zero, indice})); - rewriter.create<LLVM::StoreOp>(loc, arg, structMember); - mlir::Value arrayMember = rewriter.create<LLVM::GEPOp>( - loc, ptrTy, ptrTy, argArray, mlir::ArrayRef<mlir::Value>({indice})); - rewriter.create<LLVM::StoreOp>(loc, structMember, arrayMember); + auto indice = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, i)); + mlir::Value structMember = + LLVM::GEPOp::create(rewriter, loc, ptrTy, structTy, argStruct, + mlir::ArrayRef<mlir::Value>({zero, indice})); + LLVM::StoreOp::create(rewriter, loc, arg, structMember); + mlir::Value arrayMember = + LLVM::GEPOp::create(rewriter, loc, ptrTy, ptrTy, argArray, + mlir::ArrayRef<mlir::Value>({indice})); + LLVM::StoreOp::create(rewriter, loc, structMember, arrayMember); } return argArray; } @@ -94,8 +95,8 @@ struct GPULaunchKernelConversion mlir::Value dynamicMemorySize = op.getDynamicSharedMemorySize(); mlir::Type i32Ty = rewriter.getI32Type(); if (!dynamicMemorySize) - dynamicMemorySize = rewriter.create<mlir::LLVM::ConstantOp>( - loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); + dynamicMemorySize = mlir::LLVM::ConstantOp::create( + rewriter, loc, i32Ty, rewriter.getIntegerAttr(i32Ty, 0)); mlir::Value kernelArgs = createKernelArgArray(loc, adaptor.getKernelOperands(), rewriter); @@ -108,17 +109,17 @@ struct GPULaunchKernelConversion if (!funcOp) return mlir::failure(); kernelPtr = - rewriter.create<LLVM::AddressOfOp>(loc, ptrTy, funcOp.getName()); + LLVM::AddressOfOp::create(rewriter, loc, ptrTy, funcOp.getName()); } else { kernelPtr = - rewriter.create<LLVM::AddressOfOp>(loc, ptrTy, kernel.getName()); + LLVM::AddressOfOp::create(rewriter, loc, ptrTy, kernel.getName()); } auto llvmIntPtrType = mlir::IntegerType::get( ctx, this->getTypeConverter()->getPointerBitwidth(0)); auto voidTy = mlir::LLVM::LLVMVoidType::get(ctx); - mlir::Value nullPtr = rewriter.create<LLVM::ZeroOp>(loc, ptrTy); + mlir::Value nullPtr = LLVM::ZeroOp::create(rewriter, loc, ptrTy); if (op.hasClusterSize()) { auto funcOp = mod.lookupSymbol<mlir::LLVM::LLVMFuncOp>( @@ -134,8 +135,8 @@ struct GPULaunchKernelConversion if (!funcOp) { mlir::OpBuilder::InsertionGuard insertGuard(rewriter); rewriter.setInsertionPointToStart(mod.getBody()); - auto launchKernelFuncOp = rewriter.create<mlir::LLVM::LLVMFuncOp>( - loc, RTNAME_STRING(CUFLaunchClusterKernel), funcTy); + auto launchKernelFuncOp = mlir::LLVM::LLVMFuncOp::create( + rewriter, loc, RTNAME_STRING(CUFLaunchClusterKernel), funcTy); launchKernelFuncOp.setVisibility( mlir::SymbolTable::Visibility::Private); } @@ -148,8 +149,8 @@ struct GPULaunchKernelConversion stream = adaptor.getAsyncDependencies().front(); } - rewriter.create<mlir::LLVM::CallOp>( - loc, funcTy, cufLaunchClusterKernel, + mlir::LLVM::CallOp::create( + rewriter, loc, funcTy, cufLaunchClusterKernel, mlir::ValueRange{kernelPtr, adaptor.getClusterSizeX(), adaptor.getClusterSizeY(), adaptor.getClusterSizeZ(), adaptor.getGridSizeX(), adaptor.getGridSizeY(), @@ -178,7 +179,7 @@ struct GPULaunchKernelConversion mlir::OpBuilder::InsertionGuard insertGuard(rewriter); rewriter.setInsertionPointToStart(mod.getBody()); auto launchKernelFuncOp = - rewriter.create<mlir::LLVM::LLVMFuncOp>(loc, fctName, funcTy); + mlir::LLVM::LLVMFuncOp::create(rewriter, loc, fctName, funcTy); launchKernelFuncOp.setVisibility( mlir::SymbolTable::Visibility::Private); } @@ -191,8 +192,8 @@ struct GPULaunchKernelConversion stream = adaptor.getAsyncDependencies().front(); } - rewriter.create<mlir::LLVM::CallOp>( - loc, funcTy, cufLaunchKernel, + mlir::LLVM::CallOp::create( + rewriter, loc, funcTy, cufLaunchKernel, mlir::ValueRange{kernelPtr, adaptor.getGridSizeX(), adaptor.getGridSizeY(), adaptor.getGridSizeZ(), adaptor.getBlockSizeX(), adaptor.getBlockSizeY(), @@ -222,11 +223,11 @@ static mlir::Value createAddressOfOp(mlir::ConversionPatternRewriter &rewriter, auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get( rewriter.getContext(), mlir::NVVM::NVVMMemorySpace::kSharedMemorySpace); if (auto g = gpuMod.lookupSymbol<fir::GlobalOp>(sharedGlobalName)) - return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy, - g.getSymName()); + return mlir::LLVM::AddressOfOp::create(rewriter, loc, llvmPtrTy, + g.getSymName()); if (auto g = gpuMod.lookupSymbol<mlir::LLVM::GlobalOp>(sharedGlobalName)) - return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy, - g.getSymName()); + return mlir::LLVM::AddressOfOp::create(rewriter, loc, llvmPtrTy, + g.getSymName()); return {}; } @@ -255,13 +256,13 @@ struct CUFSharedMemoryOpConversion if (!sharedGlobalAddr) mlir::emitError(loc, "Could not find the shared global operation\n"); - auto castPtr = rewriter.create<mlir::LLVM::AddrSpaceCastOp>( - loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), + auto castPtr = mlir::LLVM::AddrSpaceCastOp::create( + rewriter, loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), sharedGlobalAddr); mlir::Type baseType = castPtr->getResultTypes().front(); llvm::SmallVector<mlir::LLVM::GEPArg> gepArgs = {op.getOffset()}; - mlir::Value shmemPtr = rewriter.create<mlir::LLVM::GEPOp>( - loc, baseType, rewriter.getI8Type(), castPtr, gepArgs); + mlir::Value shmemPtr = mlir::LLVM::GEPOp::create( + rewriter, loc, baseType, rewriter.getI8Type(), castPtr, gepArgs); rewriter.replaceOp(op, {shmemPtr}); return mlir::success(); } diff --git a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp index 750569c..cd7d330 100644 --- a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp @@ -89,7 +89,7 @@ static mlir::Value createConvertOp(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Type toTy, mlir::Value val) { if (val.getType() != toTy) - return rewriter.create<fir::ConvertOp>(loc, toTy, val); + return fir::ConvertOp::create(rewriter, loc, toTy, val); return val; } @@ -118,7 +118,7 @@ static mlir::LogicalResult convertOpToCall(OpTy op, errmsg = op.getErrmsg(); } else { mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); - errmsg = builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + errmsg = fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); } llvm::SmallVector<mlir::Value> args; if constexpr (std::is_same_v<OpTy, cuf::AllocateOp>) { @@ -148,7 +148,7 @@ static mlir::LogicalResult convertOpToCall(OpTy op, fir::runtime::createArguments(builder, loc, fTy, op.getBox(), hasStat, errmsg, sourceFile, sourceLine); } - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); rewriter.replaceOp(op, callOp); return mlir::success(); } @@ -301,10 +301,11 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { if (inDeviceContext(op.getOperation())) { // In device context just replace the cuf.alloc operation with a fir.alloc // the cuf.free will be removed. - auto allocaOp = rewriter.create<fir::AllocaOp>( - loc, op.getInType(), op.getUniqName() ? *op.getUniqName() : "", - op.getBindcName() ? *op.getBindcName() : "", op.getTypeparams(), - op.getShape()); + auto allocaOp = + fir::AllocaOp::create(rewriter, loc, op.getInType(), + op.getUniqName() ? *op.getUniqName() : "", + op.getBindcName() ? *op.getBindcName() : "", + op.getTypeparams(), op.getShape()); allocaOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); rewriter.replaceOp(op, allocaOp); return mlir::success(); @@ -338,14 +339,15 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { assert(!op.getShape().empty() && "expect shape with dynamic arrays"); nbElem = builder.loadIfRef(loc, op.getShape()[0]); for (unsigned i = 1; i < op.getShape().size(); ++i) { - nbElem = rewriter.create<mlir::arith::MulIOp>( - loc, nbElem, builder.loadIfRef(loc, op.getShape()[i])); + nbElem = mlir::arith::MulIOp::create( + rewriter, loc, nbElem, + builder.loadIfRef(loc, op.getShape()[i])); } } else { nbElem = builder.createIntegerConstant(loc, builder.getIndexType(), seqTy.getConstantArraySize()); } - bytes = rewriter.create<mlir::arith::MulIOp>(loc, nbElem, width); + bytes = mlir::arith::MulIOp::create(rewriter, loc, nbElem, width); } else if (fir::isa_derived(op.getInType())) { mlir::Type structTy = typeConverter->convertType(op.getInType()); std::size_t structSize = dl->getTypeSizeInBits(structTy) / 8; @@ -363,7 +365,7 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { loc, builder.getI32Type(), getMemType(op.getDataAttr())); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, bytes, memTy, sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); auto convOp = builder.createConvert(loc, op.getResult().getType(), callOp.getResult(0)); @@ -386,7 +388,7 @@ struct CUFAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> { llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, sizeInBytes, sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); auto convOp = builder.createConvert(loc, op.getResult().getType(), callOp.getResult(0)); @@ -414,8 +416,9 @@ struct CUFDeviceAddressOpConversion op.getHostSymbol().getRootReference().getValue())) { auto mod = op->getParentOfType<mlir::ModuleOp>(); mlir::Location loc = op.getLoc(); - auto hostAddr = rewriter.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(global.getType()), op.getHostSymbol()); + auto hostAddr = fir::AddrOfOp::create( + rewriter, loc, fir::ReferenceType::get(global.getType()), + op.getHostSymbol()); fir::FirOpBuilder builder(rewriter, mod); mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc<mkRTKey(CUFGetDeviceAddress)>(loc, @@ -428,7 +431,7 @@ struct CUFDeviceAddressOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, conv, sourceFile, sourceLine)}; - auto call = rewriter.create<fir::CallOp>(loc, callee, args); + auto call = fir::CallOp::create(rewriter, loc, callee, args); mlir::Value addr = createConvertOp(rewriter, loc, hostAddr.getType(), call->getResult(0)); rewriter.replaceOp(op, addr.getDefiningOp()); @@ -456,8 +459,8 @@ struct DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> { addrOfOp.getSymbol().getRootReference().getValue())) { if (cuf::isRegisteredDeviceGlobal(global)) { rewriter.setInsertionPointAfter(addrOfOp); - mlir::Value devAddr = rewriter.create<cuf::DeviceAddressOp>( - op.getLoc(), addrOfOp.getType(), addrOfOp.getSymbol()); + mlir::Value devAddr = cuf::DeviceAddressOp::create( + rewriter, op.getLoc(), addrOfOp.getType(), addrOfOp.getSymbol()); rewriter.startOpModification(op); op.getMemrefMutable().assign(devAddr); rewriter.finalizeOpModification(op); @@ -502,7 +505,7 @@ struct CUFFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> { loc, builder.getI32Type(), getMemType(op.getDataAttr())); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, op.getDevptr(), memTy, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -515,7 +518,7 @@ struct CUFFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> { fir::factory::locationToLineNo(builder, loc, fTy.getInput(2)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, op.getDevptr(), sourceFile, sourceLine)}; - auto callOp = builder.create<fir::CallOp>(loc, func, args); + auto callOp = fir::CallOp::create(builder, loc, func, args); callOp->setAttr(cuf::getDataAttrName(), op.getDataAttrAttr()); rewriter.eraseOp(op); return mlir::success(); @@ -558,18 +561,18 @@ static mlir::Value emboxSrc(mlir::PatternRewriter &rewriter, srcTy = fir::LogicalType::get(rewriter.getContext(), 4); src = createConvertOp(rewriter, loc, srcTy, src); addr = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, addr); + fir::StoreOp::create(builder, loc, src, addr); } else { if (dstEleTy && fir::isa_trivial(dstEleTy) && srcTy != dstEleTy) { // Use dstEleTy and convert to avoid assign mismatch. addr = builder.createTemporary(loc, dstEleTy); - auto conv = builder.create<fir::ConvertOp>(loc, dstEleTy, src); - builder.create<fir::StoreOp>(loc, conv, addr); + auto conv = fir::ConvertOp::create(builder, loc, dstEleTy, src); + fir::StoreOp::create(builder, loc, conv, addr); srcTy = dstEleTy; } else { // Put constant in memory if it is not. addr = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, addr); + fir::StoreOp::create(builder, loc, src, addr); } } } else { @@ -582,7 +585,7 @@ static mlir::Value emboxSrc(mlir::PatternRewriter &rewriter, /*slice=*/nullptr, lenParams, /*tdesc=*/nullptr); mlir::Value src = builder.createTemporary(loc, box.getType()); - builder.create<fir::StoreOp>(loc, box, src); + fir::StoreOp::create(builder, loc, box, src); return src; } @@ -601,7 +604,7 @@ static mlir::Value emboxDst(mlir::PatternRewriter &rewriter, /*slice=*/nullptr, lenParams, /*tdesc=*/nullptr); mlir::Value dst = builder.createTemporary(loc, dstBox.getType()); - builder.create<fir::StoreOp>(loc, dstBox, dst); + fir::StoreOp::create(builder, loc, dstBox, dst); return dst; } @@ -660,7 +663,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -679,12 +682,12 @@ struct CUFDataTransferOpConversion extents.push_back(i.value()); } - nbElement = rewriter.create<fir::ConvertOp>(loc, i64Ty, extents[0]); + nbElement = fir::ConvertOp::create(rewriter, loc, i64Ty, extents[0]); for (unsigned i = 1; i < extents.size(); ++i) { auto operand = - rewriter.create<fir::ConvertOp>(loc, i64Ty, extents[i]); + fir::ConvertOp::create(rewriter, loc, i64Ty, extents[i]); nbElement = - rewriter.create<mlir::arith::MulIOp>(loc, nbElement, operand); + mlir::arith::MulIOp::create(rewriter, loc, nbElement, operand); } } else { if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(dstTy)) @@ -699,12 +702,11 @@ struct CUFDataTransferOpConversion } else { width = computeWidth(loc, dstTy, kindMap); } - mlir::Value widthValue = rewriter.create<mlir::arith::ConstantOp>( - loc, i64Ty, rewriter.getIntegerAttr(i64Ty, width)); - mlir::Value bytes = - nbElement - ? rewriter.create<mlir::arith::MulIOp>(loc, nbElement, widthValue) - : widthValue; + mlir::Value widthValue = mlir::arith::ConstantOp::create( + rewriter, loc, i64Ty, rewriter.getIntegerAttr(i64Ty, width)); + mlir::Value bytes = nbElement ? mlir::arith::MulIOp::create( + rewriter, loc, nbElement, widthValue) + : widthValue; mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey(CUFDataTransferPtrPtr)>(loc, @@ -719,13 +721,13 @@ struct CUFDataTransferOpConversion // Materialize the src if constant. if (matchPattern(src.getDefiningOp(), mlir::m_Constant())) { mlir::Value temp = builder.createTemporary(loc, srcTy); - builder.create<fir::StoreOp>(loc, src, temp); + fir::StoreOp::create(builder, loc, src, temp); src = temp; } llvm::SmallVector<mlir::Value> args{ fir::runtime::createArguments(builder, loc, fTy, dst, src, bytes, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); return mlir::success(); } @@ -734,7 +736,7 @@ struct CUFDataTransferOpConversion if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp())) { // Materialize the box to memory to be able to call the runtime. mlir::Value box = builder.createTemporary(loc, val.getType()); - builder.create<fir::StoreOp>(loc, val, box); + fir::StoreOp::create(builder, loc, val, box); return box; } return val; @@ -768,7 +770,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); } else { // Transfer from a descriptor. @@ -784,7 +786,7 @@ struct CUFDataTransferOpConversion fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments( builder, loc, fTy, dst, src, modeValue, sourceFile, sourceLine)}; - builder.create<fir::CallOp>(loc, func, args); + fir::CallOp::create(builder, loc, func, args); rewriter.eraseOp(op); } return mlir::success(); @@ -810,20 +812,21 @@ public: mlir::PatternRewriter &rewriter) const override { mlir::Location loc = op.getLoc(); auto idxTy = mlir::IndexType::get(op.getContext()); - mlir::Value zero = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getIntegerType(32), rewriter.getI32IntegerAttr(0)); + mlir::Value zero = mlir::arith::ConstantOp::create( + rewriter, loc, rewriter.getIntegerType(32), + rewriter.getI32IntegerAttr(0)); auto gridSizeX = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridX()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridX()); auto gridSizeY = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridY()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridY()); auto gridSizeZ = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getGridZ()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getGridZ()); auto blockSizeX = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockX()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockX()); auto blockSizeY = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockY()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockY()); auto blockSizeZ = - rewriter.create<mlir::arith::IndexCastOp>(loc, idxTy, op.getBlockZ()); + mlir::arith::IndexCastOp::create(rewriter, loc, idxTy, op.getBlockZ()); auto kernelName = mlir::SymbolRefAttr::get( rewriter.getStringAttr(cudaDeviceModuleName), {mlir::SymbolRefAttr::get( @@ -835,12 +838,12 @@ public: op.getCallee().getLeafReference())) { if (auto clusterDimsAttr = funcOp->getAttrOfType<cuf::ClusterDimsAttr>( cuf::getClusterDimsAttrName())) { - clusterDimX = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getX().getInt()); - clusterDimY = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getY().getInt()); - clusterDimZ = rewriter.create<mlir::arith::ConstantIndexOp>( - loc, clusterDimsAttr.getZ().getInt()); + clusterDimX = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getX().getInt()); + clusterDimY = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getY().getInt()); + clusterDimZ = mlir::arith::ConstantIndexOp::create( + rewriter, loc, clusterDimsAttr.getZ().getInt()); } procAttr = funcOp->getAttrOfType<cuf::ProcAttributeAttr>(cuf::getProcAttrName()); @@ -870,8 +873,9 @@ public: args.push_back(arg); } mlir::Value dynamicShmemSize = op.getBytes() ? op.getBytes() : zero; - auto gpuLaunchOp = rewriter.create<mlir::gpu::LaunchFuncOp>( - loc, kernelName, mlir::gpu::KernelDim3{gridSizeX, gridSizeY, gridSizeZ}, + auto gpuLaunchOp = mlir::gpu::LaunchFuncOp::create( + rewriter, loc, kernelName, + mlir::gpu::KernelDim3{gridSizeX, gridSizeY, gridSizeZ}, mlir::gpu::KernelDim3{blockSizeX, blockSizeY, blockSizeZ}, dynamicShmemSize, args); if (clusterDimX && clusterDimY && clusterDimZ) { @@ -883,7 +887,7 @@ public: mlir::OpBuilder::InsertionGuard guard(rewriter); rewriter.setInsertionPoint(gpuLaunchOp); mlir::Value stream = - rewriter.create<cuf::StreamCastOp>(loc, op.getStream()); + cuf::StreamCastOp::create(rewriter, loc, op.getStream()); gpuLaunchOp.getAsyncDependenciesMutable().append(stream); } if (procAttr) @@ -916,8 +920,9 @@ struct CUFSyncDescriptorOpConversion if (!globalOp) return mlir::failure(); - auto hostAddr = builder.create<fir::AddrOfOp>( - loc, fir::ReferenceType::get(globalOp.getType()), op.getGlobalName()); + auto hostAddr = fir::AddrOfOp::create( + builder, loc, fir::ReferenceType::get(globalOp.getType()), + op.getGlobalName()); fir::runtime::cuda::genSyncGlobalDescriptor(builder, loc, hostAddr); op.erase(); return mlir::success(); diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp index aee7e8c..13da38e 100644 --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -48,12 +48,13 @@ public: << "running character conversion on " << conv << '\n'); // Establish a loop that executes count iterations. - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); auto idxTy = rewriter.getIndexType(); - auto castCnt = rewriter.create<fir::ConvertOp>(loc, idxTy, conv.getCount()); - auto countm1 = rewriter.create<mlir::arith::SubIOp>(loc, castCnt, one); - auto loop = rewriter.create<fir::DoLoopOp>(loc, zero, countm1, one); + auto castCnt = + fir::ConvertOp::create(rewriter, loc, idxTy, conv.getCount()); + auto countm1 = mlir::arith::SubIOp::create(rewriter, loc, castCnt, one); + auto loop = fir::DoLoopOp::create(rewriter, loc, zero, countm1, one); auto insPt = rewriter.saveInsertionPoint(); rewriter.setInsertionPointToStart(loop.getBody()); @@ -75,21 +76,22 @@ public: auto toTy = rewriter.getIntegerType(toBits); auto toPtrTy = pointerType(toBits); auto fromPtr = - rewriter.create<fir::ConvertOp>(loc, fromPtrTy, conv.getFrom()); - auto toPtr = rewriter.create<fir::ConvertOp>(loc, toPtrTy, conv.getTo()); + fir::ConvertOp::create(rewriter, loc, fromPtrTy, conv.getFrom()); + auto toPtr = fir::ConvertOp::create(rewriter, loc, toPtrTy, conv.getTo()); auto getEleTy = [&](unsigned bits) { return fir::ReferenceType::get(rewriter.getIntegerType(bits)); }; - auto fromi = rewriter.create<fir::CoordinateOp>( - loc, getEleTy(fromBits), fromPtr, - mlir::ValueRange{loop.getInductionVar()}); - auto toi = rewriter.create<fir::CoordinateOp>( - loc, getEleTy(toBits), toPtr, mlir::ValueRange{loop.getInductionVar()}); - auto load = rewriter.create<fir::LoadOp>(loc, fromi); + auto fromi = + fir::CoordinateOp::create(rewriter, loc, getEleTy(fromBits), fromPtr, + mlir::ValueRange{loop.getInductionVar()}); + auto toi = + fir::CoordinateOp::create(rewriter, loc, getEleTy(toBits), toPtr, + mlir::ValueRange{loop.getInductionVar()}); + auto load = fir::LoadOp::create(rewriter, loc, fromi); mlir::Value icast = (fromBits >= toBits) - ? rewriter.create<fir::ConvertOp>(loc, toTy, load).getResult() - : rewriter.create<mlir::arith::ExtUIOp>(loc, toTy, load) + ? fir::ConvertOp::create(rewriter, loc, toTy, load).getResult() + : mlir::arith::ExtUIOp::create(rewriter, loc, toTy, load) .getResult(); rewriter.replaceOpWithNewOp<fir::StoreOp>(conv, icast, toi); rewriter.restoreInsertionPoint(insPt); diff --git a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp index 239a7cd..afafbd8 100644 --- a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp +++ b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp @@ -111,11 +111,11 @@ public: builder.insert(cln); mlir::Value val = builder.createConvert(loc, varTy, cln->getResult(0)); - builder.create<fir::HasValueOp>(loc, val); + fir::HasValueOp::create(builder, loc, val); }, builder.createInternalLinkage()); - mlir::Value addr = builder.create<fir::AddrOfOp>(loc, global.resultType(), - global.getSymbol()); + mlir::Value addr = fir::AddrOfOp::create( + builder, loc, global.resultType(), global.getSymbol()); newOperands.push_back(addr); needUpdate = true; } @@ -125,11 +125,11 @@ public: llvm::SmallVector<mlir::Type> newResultTypes; newResultTypes.append(callOp.getResultTypes().begin(), callOp.getResultTypes().end()); - fir::CallOp newOp = builder.create<fir::CallOp>( - loc, - callOp.getCallee().has_value() ? callOp.getCallee().value() - : mlir::SymbolRefAttr{}, - newResultTypes, newOperands); + fir::CallOp newOp = fir::CallOp::create(builder, loc, + callOp.getCallee().has_value() + ? callOp.getCallee().value() + : mlir::SymbolRefAttr{}, + newResultTypes, newOperands); // Copy all the attributes from the old to new op. newOp->setAttrs(callOp->getAttrs()); rewriter.replaceOp(callOp, newOp); diff --git a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp index 3d35803..e466aed 100644 --- a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp +++ b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp @@ -83,17 +83,17 @@ public: // Initalization block rewriter.setInsertionPointToEnd(initBlock); - auto diff = rewriter.create<mlir::arith::SubIOp>(loc, high, low); - auto distance = rewriter.create<mlir::arith::AddIOp>(loc, diff, step); + auto diff = mlir::arith::SubIOp::create(rewriter, loc, high, low); + auto distance = mlir::arith::AddIOp::create(rewriter, loc, diff, step); mlir::Value iters = - rewriter.create<mlir::arith::DivSIOp>(loc, distance, step); + mlir::arith::DivSIOp::create(rewriter, loc, distance, step); if (forceLoopToExecuteOnce) { - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto cond = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, iters, zero); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); - iters = rewriter.create<mlir::arith::SelectOp>(loc, cond, one, iters); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto cond = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, iters, zero); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); + iters = mlir::arith::SelectOp::create(rewriter, loc, cond, one, iters); } llvm::SmallVector<mlir::Value> loopOperands; @@ -102,20 +102,20 @@ public: loopOperands.append(operands.begin(), operands.end()); loopOperands.push_back(iters); - rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopOperands); + mlir::cf::BranchOp::create(rewriter, loc, conditionalBlock, loopOperands); // Last loop block auto *terminator = lastBlock->getTerminator(); rewriter.setInsertionPointToEnd(lastBlock); auto iv = conditionalBlock->getArgument(0); mlir::Value steppedIndex = - rewriter.create<mlir::arith::AddIOp>(loc, iv, step, iofAttr); + mlir::arith::AddIOp::create(rewriter, loc, iv, step, iofAttr); assert(steppedIndex && "must be a Value"); auto lastArg = conditionalBlock->getNumArguments() - 1; auto itersLeft = conditionalBlock->getArgument(lastArg); - auto one = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(rewriter, loc, 1); mlir::Value itersMinusOne = - rewriter.create<mlir::arith::SubIOp>(loc, itersLeft, one); + mlir::arith::SubIOp::create(rewriter, loc, itersLeft, one); llvm::SmallVector<mlir::Value> loopCarried; loopCarried.push_back(steppedIndex); @@ -123,8 +123,8 @@ public: : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); loopCarried.push_back(itersMinusOne); - auto backEdge = - rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopCarried); + auto backEdge = mlir::cf::BranchOp::create(rewriter, loc, conditionalBlock, + loopCarried); rewriter.eraseOp(terminator); // Copy loop annotations from the do loop to the loop back edge. @@ -133,13 +133,13 @@ public: // Conditional block rewriter.setInsertionPointToEnd(conditionalBlock); - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto comparison = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sgt, itersLeft, zero); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto comparison = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sgt, itersLeft, zero); - rewriter.create<mlir::cf::CondBranchOp>( - loc, comparison, firstBlock, llvm::ArrayRef<mlir::Value>(), endBlock, - llvm::ArrayRef<mlir::Value>()); + mlir::cf::CondBranchOp::create(rewriter, loc, comparison, firstBlock, + llvm::ArrayRef<mlir::Value>(), endBlock, + llvm::ArrayRef<mlir::Value>()); // The result of the loop operation is the values of the condition block // arguments except the induction variable on the last iteration. @@ -180,7 +180,7 @@ public: continueBlock = rewriter.createBlock( remainingOpsBlock, ifOp.getResultTypes(), llvm::SmallVector<mlir::Location>(ifOp.getNumResults(), loc)); - rewriter.create<mlir::cf::BranchOp>(loc, remainingOpsBlock); + mlir::cf::BranchOp::create(rewriter, loc, remainingOpsBlock); } // Move blocks from the "then" region to the region containing 'fir.if', @@ -190,8 +190,8 @@ public: auto *ifOpTerminator = ifOpRegion.back().getTerminator(); auto ifOpTerminatorOperands = ifOpTerminator->getOperands(); rewriter.setInsertionPointToEnd(&ifOpRegion.back()); - rewriter.create<mlir::cf::BranchOp>(loc, continueBlock, - ifOpTerminatorOperands); + mlir::cf::BranchOp::create(rewriter, loc, continueBlock, + ifOpTerminatorOperands); rewriter.eraseOp(ifOpTerminator); rewriter.inlineRegionBefore(ifOpRegion, continueBlock); @@ -205,16 +205,17 @@ public: auto *otherwiseTerm = otherwiseRegion.back().getTerminator(); auto otherwiseTermOperands = otherwiseTerm->getOperands(); rewriter.setInsertionPointToEnd(&otherwiseRegion.back()); - rewriter.create<mlir::cf::BranchOp>(loc, continueBlock, - otherwiseTermOperands); + mlir::cf::BranchOp::create(rewriter, loc, continueBlock, + otherwiseTermOperands); rewriter.eraseOp(otherwiseTerm); rewriter.inlineRegionBefore(otherwiseRegion, continueBlock); } rewriter.setInsertionPointToEnd(condBlock); - auto branchOp = rewriter.create<mlir::cf::CondBranchOp>( - loc, ifOp.getCondition(), ifOpBlock, llvm::ArrayRef<mlir::Value>(), - otherwiseBlock, llvm::ArrayRef<mlir::Value>()); + auto branchOp = mlir::cf::CondBranchOp::create( + rewriter, loc, ifOp.getCondition(), ifOpBlock, + llvm::ArrayRef<mlir::Value>(), otherwiseBlock, + llvm::ArrayRef<mlir::Value>()); llvm::ArrayRef<int32_t> weights = ifOp.getWeights(); if (!weights.empty()) branchOp.setWeights(weights); @@ -269,7 +270,7 @@ public: rewriter.setInsertionPointToEnd(lastBodyBlock); auto step = whileOp.getStep(); mlir::Value stepped = - rewriter.create<mlir::arith::AddIOp>(loc, iv, step, iofAttr); + mlir::arith::AddIOp::create(rewriter, loc, iv, step, iofAttr); assert(stepped && "must be a Value"); llvm::SmallVector<mlir::Value> loopCarried; @@ -278,7 +279,7 @@ public: ? std::next(terminator->operand_begin()) : terminator->operand_begin(); loopCarried.append(begin, terminator->operand_end()); - rewriter.create<mlir::cf::BranchOp>(loc, conditionBlock, loopCarried); + mlir::cf::BranchOp::create(rewriter, loc, conditionBlock, loopCarried); rewriter.eraseOp(terminator); // Compute loop bounds before branching to the condition. @@ -293,31 +294,31 @@ public: destOperands.push_back(lowerBound); auto iterOperands = whileOp.getIterOperands(); destOperands.append(iterOperands.begin(), iterOperands.end()); - rewriter.create<mlir::cf::BranchOp>(loc, conditionBlock, destOperands); + mlir::cf::BranchOp::create(rewriter, loc, conditionBlock, destOperands); // With the body block done, we can fill in the condition block. rewriter.setInsertionPointToEnd(conditionBlock); // The comparison depends on the sign of the step value. We fully expect // this expression to be folded by the optimizer or LLVM. This expression // is written this way so that `step == 0` always returns `false`. - auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0); - auto compl0 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::slt, zero, step); - auto compl1 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, iv, upperBound); - auto compl2 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::slt, step, zero); - auto compl3 = rewriter.create<mlir::arith::CmpIOp>( - loc, arith::CmpIPredicate::sle, upperBound, iv); - auto cmp0 = rewriter.create<mlir::arith::AndIOp>(loc, compl0, compl1); - auto cmp1 = rewriter.create<mlir::arith::AndIOp>(loc, compl2, compl3); - auto cmp2 = rewriter.create<mlir::arith::OrIOp>(loc, cmp0, cmp1); + auto zero = mlir::arith::ConstantIndexOp::create(rewriter, loc, 0); + auto compl0 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::slt, zero, step); + auto compl1 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, iv, upperBound); + auto compl2 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::slt, step, zero); + auto compl3 = mlir::arith::CmpIOp::create( + rewriter, loc, arith::CmpIPredicate::sle, upperBound, iv); + auto cmp0 = mlir::arith::AndIOp::create(rewriter, loc, compl0, compl1); + auto cmp1 = mlir::arith::AndIOp::create(rewriter, loc, compl2, compl3); + auto cmp2 = mlir::arith::OrIOp::create(rewriter, loc, cmp0, cmp1); // Remember to AND in the early-exit bool. auto comparison = - rewriter.create<mlir::arith::AndIOp>(loc, iterateVar, cmp2); - rewriter.create<mlir::cf::CondBranchOp>( - loc, comparison, firstBodyBlock, llvm::ArrayRef<mlir::Value>(), - endBlock, llvm::ArrayRef<mlir::Value>()); + mlir::arith::AndIOp::create(rewriter, loc, iterateVar, cmp2); + mlir::cf::CondBranchOp::create(rewriter, loc, comparison, firstBodyBlock, + llvm::ArrayRef<mlir::Value>(), endBlock, + llvm::ArrayRef<mlir::Value>()); // 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.getFinalValue() diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp index abad500..5dcb54e 100644 --- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp +++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp @@ -103,13 +103,14 @@ mlir::LLVM::DILocalVariableAttr DebugTypeGenerator::generateArtificialVariable( mlir::Type type = val.getType(); if (!mlir::isa<mlir::IntegerType>(type) || !type.isSignlessInteger()) { type = builder.getIntegerType(64); - val = builder.create<fir::ConvertOp>(declOp.getLoc(), type, val); + val = fir::ConvertOp::create(builder, declOp.getLoc(), type, val); } mlir::LLVM::DITypeAttr Ty = convertType(type, fileAttr, scope, declOp); auto lvAttr = mlir::LLVM::DILocalVariableAttr::get( context, scope, name, fileAttr, /*line=*/0, /*argNo=*/0, /*alignInBits=*/0, Ty, mlir::LLVM::DIFlags::Artificial); - builder.create<mlir::LLVM::DbgValueOp>(declOp.getLoc(), val, lvAttr, nullptr); + mlir::LLVM::DbgValueOp::create(builder, declOp.getLoc(), val, lvAttr, + nullptr); return lvAttr; } diff --git a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp index f06ad2d..d7d1865 100644 --- a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp +++ b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp @@ -49,13 +49,13 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> { // must be a positive value. // For easier conversion, we calculate the trip count and use a canonical // induction variable. - auto diff = rewriter.create<arith::SubIOp>(loc, high, low); - auto distance = rewriter.create<arith::AddIOp>(loc, diff, step); - auto tripCount = rewriter.create<arith::DivSIOp>(loc, distance, step); - auto zero = rewriter.create<arith::ConstantIndexOp>(loc, 0); - auto one = rewriter.create<arith::ConstantIndexOp>(loc, 1); + auto diff = arith::SubIOp::create(rewriter, loc, high, low); + auto distance = arith::AddIOp::create(rewriter, loc, diff, step); + auto tripCount = arith::DivSIOp::create(rewriter, loc, distance, step); + auto zero = arith::ConstantIndexOp::create(rewriter, loc, 0); + auto one = arith::ConstantIndexOp::create(rewriter, loc, 1); auto scfForOp = - rewriter.create<scf::ForOp>(loc, zero, tripCount, one, iterArgs); + scf::ForOp::create(rewriter, loc, zero, tripCount, one, iterArgs); auto &loopOps = doLoopOp.getBody()->getOperations(); auto resultOp = cast<fir::ResultOp>(doLoopOp.getBody()->getTerminator()); @@ -68,12 +68,12 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> { rewriter.setInsertionPointToStart(loweredBody); Value iv = - rewriter.create<arith::MulIOp>(loc, scfForOp.getInductionVar(), step); - iv = rewriter.create<arith::AddIOp>(loc, low, iv); + arith::MulIOp::create(rewriter, loc, scfForOp.getInductionVar(), step); + iv = arith::AddIOp::create(rewriter, loc, low, iv); if (!results.empty()) { rewriter.setInsertionPointToEnd(loweredBody); - rewriter.create<scf::YieldOp>(resultOp->getLoc(), results); + scf::YieldOp::create(rewriter, resultOp->getLoc(), results); } doLoopOp.getInductionVar().replaceAllUsesWith(iv); rewriter.replaceAllUsesWith(doLoopOp.getRegionIterArgs(), diff --git a/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp b/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp index 7ea3b9c..699be12 100644 --- a/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp +++ b/flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp @@ -91,8 +91,8 @@ void GenRuntimeCallsForTestPass::runOnOperation() { // Generate the wrapper function body that consists of a call and return. builder.setInsertionPointToStart(callerFunc.addEntryBlock()); mlir::Block::BlockArgListType args = callerFunc.front().getArguments(); - auto callOp = builder.create<fir::CallOp>(loc, funcOp, args); - builder.create<mlir::func::ReturnOp>(loc, callOp.getResults()); + auto callOp = fir::CallOp::create(builder, loc, funcOp, args); + mlir::func::ReturnOp::create(builder, loc, callOp.getResults()); newFuncs.push_back(callerFunc.getOperation()); builder.restoreInsertionPoint(insertPt); diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp index 056bdf6..0095159 100644 --- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp +++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp @@ -285,7 +285,7 @@ static mlir::Value getIndex(fir::FirOpBuilder &builder, mlir::Operation *op, // index_0 = index - lb; if (lb.getType() != index.getType()) lb = builder.createConvert(coop.getLoc(), index.getType(), lb); - return builder.create<mlir::arith::SubIOp>(coop.getLoc(), index, lb); + return mlir::arith::SubIOp::create(builder, coop.getLoc(), index, lb); } void LoopVersioningPass::runOnOperation() { @@ -483,26 +483,26 @@ void LoopVersioningPass::runOnOperation() { unsigned ndims = arg.rank; for (unsigned i = 0; i < ndims; i++) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - arg.dims[i] = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, - arg.arg, dimIdx); + arg.dims[i] = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + arg.arg, dimIdx); } // We only care about lowest order dimension, here. mlir::Value elemSize = builder.createIntegerConstant(loc, idxTy, arg.size); - mlir::Value cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, arg.dims[0].getResult(2), - elemSize); + mlir::Value cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, + arg.dims[0].getResult(2), elemSize); if (!allCompares) { allCompares = cmp; } else { allCompares = - builder.create<mlir::arith::AndIOp>(loc, cmp, allCompares); + mlir::arith::AndIOp::create(builder, loc, cmp, allCompares); } } auto ifOp = - builder.create<fir::IfOp>(loc, op.op->getResultTypes(), allCompares, - /*withElse=*/true); + fir::IfOp::create(builder, loc, op.op->getResultTypes(), allCompares, + /*withElse=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); LLVM_DEBUG(llvm::dbgs() << "Creating cloned loop\n"); @@ -515,8 +515,8 @@ void LoopVersioningPass::runOnOperation() { mlir::Type arrTy = fir::SequenceType::get(newShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); mlir::Type refArrTy = builder.getRefType(arrTy); - auto carg = builder.create<fir::ConvertOp>(loc, boxArrTy, arg.arg); - auto caddr = builder.create<fir::BoxAddrOp>(loc, refArrTy, carg); + auto carg = fir::ConvertOp::create(builder, loc, boxArrTy, arg.arg); + auto caddr = fir::BoxAddrOp::create(builder, loc, refArrTy, carg); auto insPt = builder.saveInsertionPoint(); // Use caddr instead of arg. clonedLoop->walk([&](mlir::Operation *coop) { @@ -540,9 +540,9 @@ void LoopVersioningPass::runOnOperation() { mlir::Value scale = builder.createConvert(loc, idxTy, arg.dims[i].getResult(2)); curIndex = - builder.create<mlir::arith::MulIOp>(loc, scale, curIndex); - totalIndex = (totalIndex) ? builder.create<mlir::arith::AddIOp>( - loc, curIndex, totalIndex) + mlir::arith::MulIOp::create(builder, loc, scale, curIndex); + totalIndex = (totalIndex) ? mlir::arith::AddIOp::create( + builder, loc, curIndex, totalIndex) : curIndex; } // This is the lowest dimension - which doesn't need scaling @@ -554,16 +554,16 @@ void LoopVersioningPass::runOnOperation() { unsigned bits = llvm::Log2_32(arg.size); mlir::Value elemShift = builder.createIntegerConstant(loc, idxTy, bits); - totalIndex = builder.create<mlir::arith::AddIOp>( - loc, - builder.create<mlir::arith::ShRSIOp>(loc, totalIndex, - elemShift), + totalIndex = mlir::arith::AddIOp::create( + builder, loc, + mlir::arith::ShRSIOp::create(builder, loc, totalIndex, + elemShift), finalIndex); } else { totalIndex = finalIndex; } - auto newOp = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(elementType), caddr, + auto newOp = fir::CoordinateOp::create( + builder, loc, builder.getRefType(elementType), caddr, mlir::ValueRange{totalIndex}); LLVM_DEBUG(newOp->dump()); coop->getResult(0).replaceAllUsesWith(newOp->getResult(0)); @@ -582,7 +582,7 @@ void LoopVersioningPass::runOnOperation() { mlir::ResultRange results = clonedLoop->getResults(); bool hasResults = (results.size() > 0); if (hasResults) - builder.create<fir::ResultOp>(loc, results); + fir::ResultOp::create(builder, loc, results); // Add the original loop in the else-side of the if operation. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); @@ -591,7 +591,7 @@ void LoopVersioningPass::runOnOperation() { builder.insert(op.op); // Rely on "cloned loop has results, so original loop also has results". if (hasResults) { - builder.create<fir::ResultOp>(loc, op.op->getResults()); + fir::ResultOp::create(builder, loc, op.op->getResults()); } else { // Use an assert to check this. assert(op.op->getResults().size() == 0 && diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp index 3f308a8..9904089 100644 --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -68,9 +68,9 @@ static mlir::Value genAllocmem(mlir::OpBuilder &builder, fir::AllocaOp alloca, }; llvm::StringRef uniqName = unpackName(alloca.getUniqName()); llvm::StringRef bindcName = unpackName(alloca.getBindcName()); - auto heap = builder.create<fir::AllocMemOp>(alloca.getLoc(), varTy, uniqName, - bindcName, alloca.getTypeparams(), - alloca.getShape()); + auto heap = fir::AllocMemOp::create(builder, alloca.getLoc(), varTy, uniqName, + bindcName, alloca.getTypeparams(), + alloca.getShape()); LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: replaced " << alloca << " with " << heap << '\n'); return heap; @@ -78,7 +78,7 @@ static mlir::Value genAllocmem(mlir::OpBuilder &builder, fir::AllocaOp alloca, static void genFreemem(mlir::Location loc, mlir::OpBuilder &builder, mlir::Value allocmem) { - [[maybe_unused]] auto free = builder.create<fir::FreeMemOp>(loc, allocmem); + [[maybe_unused]] auto free = fir::FreeMemOp::create(builder, loc, allocmem); LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: add free " << free << " for " << allocmem << '\n'); } diff --git a/flang/lib/Optimizer/Transforms/MemoryUtils.cpp b/flang/lib/Optimizer/Transforms/MemoryUtils.cpp index 1f8edf8..789111c 100644 --- a/flang/lib/Optimizer/Transforms/MemoryUtils.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryUtils.cpp @@ -200,30 +200,30 @@ void AllocaReplaceImpl::genIndirectDeallocation( // and access it indirectly in the entry points that do not dominate. rewriter.setInsertionPointToStart(&owningRegion.front()); mlir::Type heapType = fir::HeapType::get(alloca.getInType()); - mlir::Value ptrVar = rewriter.create<fir::AllocaOp>(loc, heapType); - mlir::Value nullPtr = rewriter.create<fir::ZeroOp>(loc, heapType); - rewriter.create<fir::StoreOp>(loc, nullPtr, ptrVar); + mlir::Value ptrVar = fir::AllocaOp::create(rewriter, loc, heapType); + mlir::Value nullPtr = fir::ZeroOp::create(rewriter, loc, heapType); + fir::StoreOp::create(rewriter, loc, nullPtr, ptrVar); // TODO: introducing a pointer compare op in FIR would help // generating less IR here. mlir::Type intPtrTy = fir::getIntPtrType(rewriter); - mlir::Value c0 = rewriter.create<mlir::arith::ConstantOp>( - loc, intPtrTy, rewriter.getIntegerAttr(intPtrTy, 0)); + mlir::Value c0 = mlir::arith::ConstantOp::create( + rewriter, loc, intPtrTy, rewriter.getIntegerAttr(intPtrTy, 0)); // Store new storage address right after its creation. rewriter.restoreInsertionPoint(replacementInsertPoint); mlir::Value castReplacement = fir::factory::createConvert(rewriter, loc, heapType, replacement); - rewriter.create<fir::StoreOp>(loc, castReplacement, ptrVar); + fir::StoreOp::create(rewriter, loc, castReplacement, ptrVar); // Generate conditional deallocation at every deallocation point. auto genConditionalDealloc = [&](mlir::Location loc) { - mlir::Value ptrVal = rewriter.create<fir::LoadOp>(loc, ptrVar); + mlir::Value ptrVal = fir::LoadOp::create(rewriter, loc, ptrVar); mlir::Value ptrToInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, ptrVal); - mlir::Value isAllocated = rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, ptrToInt, c0); - auto ifOp = rewriter.create<fir::IfOp>(loc, std::nullopt, isAllocated, - /*withElseRegion=*/false); + fir::ConvertOp::create(rewriter, loc, intPtrTy, ptrVal); + mlir::Value isAllocated = mlir::arith::CmpIOp::create( + rewriter, loc, mlir::arith::CmpIPredicate::ne, ptrToInt, c0); + auto ifOp = fir::IfOp::create(rewriter, loc, mlir::TypeRange{}, isAllocated, + /*withElseRegion=*/false); rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front()); mlir::Value cast = fir::factory::createConvert( rewriter, loc, replacement.getType(), ptrVal); diff --git a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp index 57eae1f..2c6601d 100644 --- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp @@ -183,49 +183,51 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> { mlir::Type tdescType = fir::TypeDescType::get(mlir::NoneType::get(rewriter.getContext())); mlir::Value boxDesc = - rewriter.create<fir::BoxTypeDescOp>(loc, tdescType, passedObject); - boxDesc = rewriter.create<fir::ConvertOp>( - loc, fir::ReferenceType::get(typeDescTy), boxDesc); + fir::BoxTypeDescOp::create(rewriter, loc, tdescType, passedObject); + boxDesc = fir::ConvertOp::create( + rewriter, loc, fir::ReferenceType::get(typeDescTy), boxDesc); // Load the bindings descriptor. auto bindingsCompName = Fortran::semantics::bindingDescCompName; fir::RecordType typeDescRecTy = mlir::cast<fir::RecordType>(typeDescTy); - mlir::Value field = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, bindingsCompName, typeDescRecTy, mlir::ValueRange{}); + mlir::Value field = + fir::FieldIndexOp::create(rewriter, loc, fieldTy, bindingsCompName, + typeDescRecTy, mlir::ValueRange{}); mlir::Type coorTy = fir::ReferenceType::get(typeDescRecTy.getType(bindingsCompName)); mlir::Value bindingBoxAddr = - rewriter.create<fir::CoordinateOp>(loc, coorTy, boxDesc, field); - mlir::Value bindingBox = rewriter.create<fir::LoadOp>(loc, bindingBoxAddr); + fir::CoordinateOp::create(rewriter, loc, coorTy, boxDesc, field); + mlir::Value bindingBox = fir::LoadOp::create(rewriter, loc, bindingBoxAddr); // Load the correct binding. - mlir::Value bindings = rewriter.create<fir::BoxAddrOp>(loc, bindingBox); + mlir::Value bindings = fir::BoxAddrOp::create(rewriter, loc, bindingBox); fir::RecordType bindingTy = fir::unwrapIfDerived( mlir::cast<fir::BaseBoxType>(bindingBox.getType())); mlir::Type bindingAddrTy = fir::ReferenceType::get(bindingTy); - mlir::Value bindingIdxVal = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getIndexType(), rewriter.getIndexAttr(bindingIdx)); - mlir::Value bindingAddr = rewriter.create<fir::CoordinateOp>( - loc, bindingAddrTy, bindings, bindingIdxVal); + mlir::Value bindingIdxVal = + mlir::arith::ConstantOp::create(rewriter, loc, rewriter.getIndexType(), + rewriter.getIndexAttr(bindingIdx)); + mlir::Value bindingAddr = fir::CoordinateOp::create( + rewriter, loc, bindingAddrTy, bindings, bindingIdxVal); // Get the function pointer. auto procCompName = Fortran::semantics::procCompName; - mlir::Value procField = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); + mlir::Value procField = fir::FieldIndexOp::create( + rewriter, loc, fieldTy, procCompName, bindingTy, mlir::ValueRange{}); fir::RecordType procTy = mlir::cast<fir::RecordType>(bindingTy.getType(procCompName)); mlir::Type procRefTy = fir::ReferenceType::get(procTy); - mlir::Value procRef = rewriter.create<fir::CoordinateOp>( - loc, procRefTy, bindingAddr, procField); + mlir::Value procRef = fir::CoordinateOp::create(rewriter, loc, procRefTy, + bindingAddr, procField); auto addressFieldName = Fortran::lower::builtin::cptrFieldName; - mlir::Value addressField = rewriter.create<fir::FieldIndexOp>( - loc, fieldTy, addressFieldName, procTy, mlir::ValueRange{}); + mlir::Value addressField = fir::FieldIndexOp::create( + rewriter, loc, fieldTy, addressFieldName, procTy, mlir::ValueRange{}); mlir::Type addressTy = procTy.getType(addressFieldName); mlir::Type addressRefTy = fir::ReferenceType::get(addressTy); - mlir::Value addressRef = rewriter.create<fir::CoordinateOp>( - loc, addressRefTy, procRef, addressField); - mlir::Value address = rewriter.create<fir::LoadOp>(loc, addressRef); + mlir::Value addressRef = fir::CoordinateOp::create( + rewriter, loc, addressRefTy, procRef, addressField); + mlir::Value address = fir::LoadOp::create(rewriter, loc, addressRef); // Get the function type. llvm::SmallVector<mlir::Type> argTypes; @@ -237,7 +239,7 @@ struct DispatchOpConv : public OpConversionPattern<fir::DispatchOp> { mlir::Type funTy = mlir::FunctionType::get(rewriter.getContext(), argTypes, resTypes); - mlir::Value funcPtr = rewriter.create<fir::ConvertOp>(loc, funTy, address); + mlir::Value funcPtr = fir::ConvertOp::create(rewriter, loc, funTy, address); // Make the call. llvm::SmallVector<mlir::Value> args{funcPtr}; @@ -398,12 +400,13 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( if (code == 0) return mlir::emitError(loc) << "type code unavailable for " << a.getType(); - mlir::Value typeCode = rewriter.create<mlir::arith::ConstantOp>( - loc, rewriter.getI8IntegerAttr(code)); - mlir::Value selectorTypeCode = rewriter.create<fir::BoxTypeCodeOp>( - loc, rewriter.getI8Type(), selector); - cmp = rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, selectorTypeCode, typeCode); + mlir::Value typeCode = mlir::arith::ConstantOp::create( + rewriter, loc, rewriter.getI8IntegerAttr(code)); + mlir::Value selectorTypeCode = fir::BoxTypeCodeOp::create( + rewriter, loc, rewriter.getI8Type(), selector); + cmp = mlir::arith::CmpIOp::create(rewriter, loc, + mlir::arith::CmpIPredicate::eq, + selectorTypeCode, typeCode); } else { // Flang inline the kind parameter in the type descriptor so we can // directly check if the type descriptor addresses are identical for @@ -418,16 +421,16 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( } else if (auto a = mlir::dyn_cast<fir::SubclassAttr>(attr)) { // Retrieve the type descriptor from the type guard statement record type. assert(mlir::isa<fir::RecordType>(a.getType()) && "expect fir.record type"); - mlir::Value typeDescAddr = - rewriter.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(a.getType())); + mlir::Value typeDescAddr = fir::TypeDescOp::create( + rewriter, loc, mlir::TypeAttr::get(a.getType())); mlir::Type refNoneType = ReferenceType::get(rewriter.getNoneType()); mlir::Value typeDesc = - rewriter.create<ConvertOp>(loc, refNoneType, typeDescAddr); + ConvertOp::create(rewriter, loc, refNoneType, typeDescAddr); // Prepare the selector descriptor for the runtime call. mlir::Type descNoneTy = fir::BoxType::get(rewriter.getNoneType()); mlir::Value descSelector = - rewriter.create<ConvertOp>(loc, descNoneTy, selector); + ConvertOp::create(rewriter, loc, descNoneTy, selector); // Generate runtime call. llvm::StringRef fctName = RTNAME_STRING(ClassIs); @@ -455,10 +458,10 @@ llvm::LogicalResult SelectTypeConv::genTypeLadderStep( rewriter.createBlock(dest->getParent(), mlir::Region::iterator(dest)); rewriter.setInsertionPointToEnd(thisBlock); if (destOps.has_value()) - rewriter.create<mlir::cf::CondBranchOp>(loc, cmp, dest, destOps.value(), - newBlock, std::nullopt); + mlir::cf::CondBranchOp::create(rewriter, loc, cmp, dest, destOps.value(), + newBlock, mlir::ValueRange{}); else - rewriter.create<mlir::cf::CondBranchOp>(loc, cmp, dest, newBlock); + mlir::cf::CondBranchOp::create(rewriter, loc, cmp, dest, newBlock); rewriter.setInsertionPointToEnd(newBlock); return mlir::success(); } @@ -470,16 +473,17 @@ SelectTypeConv::genTypeDescCompare(mlir::Location loc, mlir::Value selector, mlir::PatternRewriter &rewriter) const { assert(mlir::isa<fir::RecordType>(ty) && "expect fir.record type"); mlir::Value typeDescAddr = - rewriter.create<fir::TypeDescOp>(loc, mlir::TypeAttr::get(ty)); - mlir::Value selectorTdescAddr = rewriter.create<fir::BoxTypeDescOp>( - loc, typeDescAddr.getType(), selector); + fir::TypeDescOp::create(rewriter, loc, mlir::TypeAttr::get(ty)); + mlir::Value selectorTdescAddr = fir::BoxTypeDescOp::create( + rewriter, loc, typeDescAddr.getType(), selector); auto intPtrTy = rewriter.getIndexType(); auto typeDescInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, typeDescAddr); + fir::ConvertOp::create(rewriter, loc, intPtrTy, typeDescAddr); auto selectorTdescInt = - rewriter.create<fir::ConvertOp>(loc, intPtrTy, selectorTdescAddr); - return rewriter.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, typeDescInt, selectorTdescInt); + fir::ConvertOp::create(rewriter, loc, intPtrTy, selectorTdescAddr); + return mlir::arith::CmpIOp::create(rewriter, loc, + mlir::arith::CmpIPredicate::eq, + typeDescInt, selectorTdescInt); } llvm::SmallSet<llvm::StringRef, 4> diff --git a/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp b/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp index 506c8e6..c6aec96 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp @@ -88,18 +88,18 @@ mlir::LogicalResult IsContiguousBoxCoversion::matchAndRewrite( // The scalar cases are supposed to be optimized by the canonicalization. if (rank == 1 || (op.getInnermost() && rank > 0)) { mlir::Type idxTy = builder.getIndexType(); - auto eleSize = builder.create<fir::BoxEleSizeOp>(loc, idxTy, box); + auto eleSize = fir::BoxEleSizeOp::create(builder, loc, idxTy, box); mlir::Value zero = fir::factory::createZeroValue(builder, loc, idxTy); auto dimInfo = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, zero); + fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, zero); mlir::Value stride = dimInfo.getByteStride(); - mlir::Value pred1 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, eleSize, stride); + mlir::Value pred1 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, eleSize, stride); mlir::Value extent = dimInfo.getExtent(); - mlir::Value pred2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); + mlir::Value pred2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); mlir::Value result = - builder.create<mlir::arith::OrIOp>(loc, pred1, pred2); + mlir::arith::OrIOp::create(builder, loc, pred1, pred2); result = builder.createConvert(loc, op.getType(), result); rewriter.replaceOp(op, result); return mlir::success(); @@ -192,7 +192,7 @@ public: // TODO Should this be a heap allocation instead? For now, we allocate // on the stack for each loop iteration. mlir::Value localAlloc = - rewriter.create<fir::AllocaOp>(loop.getLoc(), localizer.getType()); + fir::AllocaOp::create(rewriter, loop.getLoc(), localizer.getType()); auto cloneLocalizerRegion = [&](mlir::Region ®ion, mlir::ValueRange regionArgs, @@ -258,10 +258,10 @@ public: for (auto [lb, ub, st, iv] : llvm::zip_equal(loop.getLowerBound(), loop.getUpperBound(), loop.getStep(), *loop.getLoopInductionVars())) { - innermostUnorderdLoop = rewriter.create<fir::DoLoopOp>( - doConcurentOp.getLoc(), lb, ub, st, + innermostUnorderdLoop = fir::DoLoopOp::create( + rewriter, doConcurentOp.getLoc(), lb, ub, st, /*unordred=*/true, /*finalCountValue=*/false, - /*iterArgs=*/std::nullopt, loop.getReduceVars(), + /*iterArgs=*/mlir::ValueRange{}, loop.getReduceVars(), loop.getReduceAttrsAttr()); ivArgs.push_back(innermostUnorderdLoop.getInductionVar()); rewriter.setInsertionPointToStart(innermostUnorderdLoop.getBody()); diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index 4d25a02..49a085e 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -284,7 +284,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, fir::SequenceType::getUnknownExtent()); mlir::Type arrTy = fir::SequenceType::get(flatShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); - mlir::Value array = builder.create<fir::ConvertOp>(loc, boxArrTy, arg); + mlir::Value array = fir::ConvertOp::create(builder, loc, boxArrTy, arg); mlir::Type resultType = funcOp.getResultTypes()[0]; mlir::Value init = initVal(builder, loc, resultType); @@ -299,11 +299,11 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // should be able to optimize the redundancy. for (unsigned i = 0; i < rank; ++i) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array, dimIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array, + dimIdx); mlir::Value len = dims.getResult(1); // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); bounds.push_back(loopCount); } // Create a loop nest consisting of OP operations. @@ -316,9 +316,9 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, for (unsigned i = rank; 0 < i; --i) { mlir::Value step = one; mlir::Value loopCount = bounds[i - 1]; - auto loop = builder.create<OP>(loc, zeroIdx, loopCount, step, - unorderedOrInitialLoopCond, - /*finalCountValue=*/false, init); + auto loop = OP::create(builder, loc, zeroIdx, loopCount, step, + unorderedOrInitialLoopCond, + /*finalCountValue=*/false, init); init = loop.getRegionIterArgs()[resultIndex]; indices.push_back(loop.getInductionVar()); // Set insertion point to the loop body so that the next loop @@ -332,8 +332,8 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // We are in the innermost loop: generate the reduction body. mlir::Type eleRefTy = builder.getRefType(elementType); mlir::Value addr = - builder.create<fir::CoordinateOp>(loc, eleRefTy, array, indices); - mlir::Value elem = builder.create<fir::LoadOp>(loc, addr); + fir::CoordinateOp::create(builder, loc, eleRefTy, array, indices); + mlir::Value elem = fir::LoadOp::create(builder, loc, addr); mlir::Value reductionVal = genBody(builder, loc, elementType, elem, init); // Generate vector with condition to continue while loop at [0] and result // from current loop at [1] for IterWhileOp loops, just result at [0] for @@ -344,7 +344,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, // to return the updated value of the reduction to the enclosing // loops. for (unsigned i = 0; i < rank; ++i) { - auto result = builder.create<fir::ResultOp>(loc, results); + auto result = fir::ResultOp::create(builder, loc, results); // Proceed to the outer loop. auto loop = mlir::cast<OP>(result->getParentOp()); results = loop.getResults(); @@ -354,7 +354,7 @@ genReductionLoop(fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp, } // End of loop nest. The insertion point is after the outermost loop. // Return the reduction value from the function. - builder.create<mlir::func::ReturnOp>(loc, results[resultIndex]); + mlir::func::ReturnOp::create(builder, loc, results[resultIndex]); } static llvm::SmallVector<mlir::Value> nopLoopCond(fir::FirOpBuilder &builder, @@ -394,9 +394,9 @@ static void genRuntimeSumBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { if (mlir::isa<mlir::FloatType>(elementType)) - return builder.create<mlir::arith::AddFOp>(loc, elem1, elem2); + return mlir::arith::AddFOp::create(builder, loc, elem1, elem2); if (mlir::isa<mlir::IntegerType>(elementType)) - return builder.create<mlir::arith::AddIOp>(loc, elem1, elem2); + return mlir::arith::AddIOp::create(builder, loc, elem1, elem2); llvm_unreachable("unsupported type"); return {}; @@ -436,12 +436,12 @@ static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, // This libm function may not work properly for F128 arguments // on targets where long double is not F128. It is an LLVM issue, // but we just use normal select here to resolve all the cases. - auto compare = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2); - return builder.create<mlir::arith::SelectOp>(loc, compare, elem1, elem2); + auto compare = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, elem1, elem2); + return mlir::arith::SelectOp::create(builder, loc, compare, elem1, elem2); } if (mlir::isa<mlir::IntegerType>(elementType)) - return builder.create<mlir::arith::MaxSIOp>(loc, elem1, elem2); + return mlir::arith::MaxSIOp::create(builder, loc, elem1, elem2); llvm_unreachable("unsupported type"); return {}; @@ -472,11 +472,11 @@ static void genRuntimeCountBody(fir::FirOpBuilder &builder, auto zero64 = builder.createIntegerConstant(loc, builder.getI64Type(), 0); auto one64 = builder.createIntegerConstant(loc, builder.getI64Type(), 1); - auto compare = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, elem1, zero32); + auto compare = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, elem1, zero32); auto select = - builder.create<mlir::arith::SelectOp>(loc, compare, zero64, one64); - return builder.create<mlir::arith::AddIOp>(loc, select, elem2); + mlir::arith::SelectOp::create(builder, loc, compare, zero64, one64); + return mlir::arith::AddIOp::create(builder, loc, select, elem2); }; // Count always gets I32 for elementType as it converts logical input to @@ -501,14 +501,14 @@ static void genRuntimeAnyBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { auto zero = builder.createIntegerConstant(loc, elementType, 0); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, elem1, zero); + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, elem1, zero); }; auto continueCond = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Value reductionVal) { auto one1 = builder.createIntegerConstant(loc, builder.getI1Type(), 1); - auto eor = builder.create<mlir::arith::XOrIOp>(loc, reductionVal, one1); + auto eor = mlir::arith::XOrIOp::create(builder, loc, reductionVal, one1); llvm::SmallVector<mlir::Value> results = {eor, reductionVal}; return results; }; @@ -534,8 +534,8 @@ static void genRuntimeAllBody(fir::FirOpBuilder &builder, mlir::Type elementType, mlir::Value elem1, mlir::Value elem2) -> mlir::Value { auto zero = builder.createIntegerConstant(loc, elementType, 0); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, elem1, zero); + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, elem1, zero); }; auto continueCond = [](fir::FirOpBuilder builder, mlir::Location loc, @@ -577,13 +577,13 @@ void fir::genMinMaxlocReductionLoop( fir::SequenceType::getUnknownExtent()); mlir::Type arrTy = fir::SequenceType::get(flatShape, elementType); mlir::Type boxArrTy = fir::BoxType::get(arrTy); - array = builder.create<fir::ConvertOp>(loc, boxArrTy, array); + array = fir::ConvertOp::create(builder, loc, boxArrTy, array); mlir::Type resultElemType = hlfir::getFortranElementType(resultArr.getType()); mlir::Value flagSet = builder.createIntegerConstant(loc, resultElemType, 1); mlir::Value zero = builder.createIntegerConstant(loc, resultElemType, 0); mlir::Value flagRef = builder.createTemporary(loc, resultElemType); - builder.create<fir::StoreOp>(loc, zero, flagRef); + fir::StoreOp::create(builder, loc, zero, flagRef); mlir::Value init = initVal(builder, loc, elementType); llvm::SmallVector<mlir::Value, Fortran::common::maxRank> bounds; @@ -597,11 +597,11 @@ void fir::genMinMaxlocReductionLoop( // should be able to optimize the redundancy. for (unsigned i = 0; i < rank; ++i) { mlir::Value dimIdx = builder.createIntegerConstant(loc, idxTy, i); - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array, dimIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array, + dimIdx); mlir::Value len = dims.getResult(1); // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); bounds.push_back(loopCount); } // Create a loop nest consisting of OP operations. @@ -615,8 +615,8 @@ void fir::genMinMaxlocReductionLoop( mlir::Value step = one; mlir::Value loopCount = bounds[i - 1]; auto loop = - builder.create<fir::DoLoopOp>(loc, zeroIdx, loopCount, step, false, - /*finalCountValue=*/false, init); + fir::DoLoopOp::create(builder, loc, zeroIdx, loopCount, step, false, + /*finalCountValue=*/false, init); init = loop.getRegionIterArgs()[0]; indices.push_back(loop.getInductionVar()); // Set insertion point to the loop body so that the next loop @@ -634,7 +634,7 @@ void fir::genMinMaxlocReductionLoop( // to return the updated value of the reduction to the enclosing // loops. for (unsigned i = 0; i < rank; ++i) { - auto result = builder.create<fir::ResultOp>(loc, reductionVal); + auto result = fir::ResultOp::create(builder, loc, reductionVal); // Proceed to the outer loop. auto loop = mlir::cast<fir::DoLoopOp>(result->getParentOp()); reductionVal = loop.getResult(0); @@ -646,7 +646,7 @@ void fir::genMinMaxlocReductionLoop( if (maskMayBeLogicalScalar) { if (fir::IfOp ifOp = mlir::dyn_cast<fir::IfOp>(builder.getBlock()->getParentOp())) { - builder.create<fir::ResultOp>(loc, reductionVal); + fir::ResultOp::create(builder, loc, reductionVal); builder.setInsertionPointAfter(ifOp); // Redefine flagSet to escape scope of ifOp flagSet = builder.createIntegerConstant(loc, resultElemType, 1); @@ -689,10 +689,11 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Value returnValue = builder.createIntegerConstant(loc, resultElemTy, 0); mlir::Value resultArrSize = builder.createIntegerConstant(loc, idxTy, rank); - mlir::Value resultArrInit = builder.create<fir::AllocMemOp>(loc, resultTy); - mlir::Value resultArrShape = builder.create<fir::ShapeOp>(loc, resultArrSize); - mlir::Value resultArr = builder.create<fir::EmboxOp>( - loc, resultBoxTy, resultArrInit, resultArrShape); + mlir::Value resultArrInit = fir::AllocMemOp::create(builder, loc, resultTy); + mlir::Value resultArrShape = + fir::ShapeOp::create(builder, loc, resultArrSize); + mlir::Value resultArr = fir::EmboxOp::create(builder, loc, resultBoxTy, + resultArrInit, resultArrShape); mlir::Type resultRefTy = builder.getRefType(resultElemTy); @@ -701,14 +702,14 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, fir::SequenceType::getUnknownExtent()); mlir::Type maskTy = fir::SequenceType::get(flatShape, maskElemType); mlir::Type boxMaskTy = fir::BoxType::get(maskTy); - mask = builder.create<fir::ConvertOp>(loc, boxMaskTy, mask); + mask = fir::ConvertOp::create(builder, loc, boxMaskTy, mask); } for (unsigned int i = 0; i < rank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxTy, i); mlir::Value resultElemAddr = - builder.create<fir::CoordinateOp>(loc, resultRefTy, resultArr, index); - builder.create<fir::StoreOp>(loc, returnValue, resultElemAddr); + fir::CoordinateOp::create(builder, loc, resultRefTy, resultArr, index); + fir::StoreOp::create(builder, loc, returnValue, resultElemAddr); } auto genBodyOp = @@ -720,29 +721,30 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (maskRank > 0) { mlir::Type logicalRef = builder.getRefType(maskElemType); mlir::Value maskAddr = - builder.create<fir::CoordinateOp>(loc, logicalRef, mask, indices); - mlir::Value maskElem = builder.create<fir::LoadOp>(loc, maskAddr); + fir::CoordinateOp::create(builder, loc, logicalRef, mask, indices); + mlir::Value maskElem = fir::LoadOp::create(builder, loc, maskAddr); // fir::IfOp requires argument to be I1 - won't accept logical or any // other Integer. mlir::Type ifCompatType = builder.getI1Type(); mlir::Value ifCompatElem = - builder.create<fir::ConvertOp>(loc, ifCompatType, maskElem); + fir::ConvertOp::create(builder, loc, ifCompatType, maskElem); llvm::SmallVector<mlir::Type> resultsTy = {elementType, elementType}; - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, ifCompatElem, - /*withElseRegion=*/true); + fir::IfOp ifOp = + fir::IfOp::create(builder, loc, elementType, ifCompatElem, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } // Set flag that mask was true at some point mlir::Value flagSet = builder.createIntegerConstant( loc, mlir::cast<fir::ReferenceType>(flagRef.getType()).getEleTy(), 1); - mlir::Value isFirst = builder.create<fir::LoadOp>(loc, flagRef); + mlir::Value isFirst = fir::LoadOp::create(builder, loc, flagRef); mlir::Type eleRefTy = builder.getRefType(elementType); mlir::Value addr = - builder.create<fir::CoordinateOp>(loc, eleRefTy, array, indices); - mlir::Value elem = builder.create<fir::LoadOp>(loc, addr); + fir::CoordinateOp::create(builder, loc, eleRefTy, array, indices); + mlir::Value elem = fir::LoadOp::create(builder, loc, addr); mlir::Value cmp; if (mlir::isa<mlir::FloatType>(elementType)) { @@ -750,38 +752,37 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, // is not NaN. A OGL/OLT condition will usually work for this unless all // the values are Nan or Inf. This follows the same logic as // NumericCompare for Minloc/Maxlox in extrema.cpp. - cmp = builder.create<mlir::arith::CmpFOp>( - loc, - isMax ? mlir::arith::CmpFPredicate::OGT - : mlir::arith::CmpFPredicate::OLT, - elem, reduction); - - mlir::Value cmpNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, reduction, reduction); - mlir::Value cmpNan2 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); - cmpNan = builder.create<mlir::arith::AndIOp>(loc, cmpNan, cmpNan2); - cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, cmpNan); + cmp = mlir::arith::CmpFOp::create(builder, loc, + isMax ? mlir::arith::CmpFPredicate::OGT + : mlir::arith::CmpFPredicate::OLT, + elem, reduction); + + mlir::Value cmpNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, reduction, reduction); + mlir::Value cmpNan2 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, elem, elem); + cmpNan = mlir::arith::AndIOp::create(builder, loc, cmpNan, cmpNan2); + cmp = mlir::arith::OrIOp::create(builder, loc, cmp, cmpNan); } else if (mlir::isa<mlir::IntegerType>(elementType)) { - cmp = builder.create<mlir::arith::CmpIOp>( - loc, - isMax ? mlir::arith::CmpIPredicate::sgt - : mlir::arith::CmpIPredicate::slt, - elem, reduction); + cmp = mlir::arith::CmpIOp::create(builder, loc, + isMax ? mlir::arith::CmpIPredicate::sgt + : mlir::arith::CmpIPredicate::slt, + elem, reduction); } else { llvm_unreachable("unsupported type"); } // The condition used for the loop is isFirst || <the condition above>. - isFirst = builder.create<fir::ConvertOp>(loc, cmp.getType(), isFirst); - isFirst = builder.create<mlir::arith::XOrIOp>( - loc, isFirst, builder.createIntegerConstant(loc, cmp.getType(), 1)); - cmp = builder.create<mlir::arith::OrIOp>(loc, cmp, isFirst); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, cmp, - /*withElseRegion*/ true); + isFirst = fir::ConvertOp::create(builder, loc, cmp.getType(), isFirst); + isFirst = mlir::arith::XOrIOp::create( + builder, loc, isFirst, + builder.createIntegerConstant(loc, cmp.getType(), 1)); + cmp = mlir::arith::OrIOp::create(builder, loc, cmp, isFirst); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, elementType, cmp, + /*withElseRegion*/ true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::StoreOp>(loc, flagSet, flagRef); + fir::StoreOp::create(builder, loc, flagSet, flagRef); mlir::Type resultElemTy = hlfir::getFortranElementType(resultArr.getType()); mlir::Type returnRefTy = builder.getRefType(resultElemTy); mlir::IndexType idxTy = builder.getIndexType(); @@ -790,17 +791,17 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, for (unsigned int i = 0; i < rank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxTy, i); - mlir::Value resultElemAddr = - builder.create<fir::CoordinateOp>(loc, returnRefTy, resultArr, index); + mlir::Value resultElemAddr = fir::CoordinateOp::create( + builder, loc, returnRefTy, resultArr, index); mlir::Value convert = - builder.create<fir::ConvertOp>(loc, resultElemTy, indices[i]); + fir::ConvertOp::create(builder, loc, resultElemTy, indices[i]); mlir::Value fortranIndex = - builder.create<mlir::arith::AddIOp>(loc, convert, one); - builder.create<fir::StoreOp>(loc, fortranIndex, resultElemAddr); + mlir::arith::AddIOp::create(builder, loc, convert, one); + fir::StoreOp::create(builder, loc, fortranIndex, resultElemAddr); } - builder.create<fir::ResultOp>(loc, elem); + fir::ResultOp::create(builder, loc, elem); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, reduction); + fir::ResultOp::create(builder, loc, reduction); builder.setInsertionPointAfter(ifOp); mlir::Value reductionVal = ifOp.getResult(0); @@ -808,9 +809,9 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (maskRank > 0) { fir::IfOp ifOp = mlir::dyn_cast<fir::IfOp>(builder.getBlock()->getParentOp()); - builder.create<fir::ResultOp>(loc, reductionVal); + fir::ResultOp::create(builder, loc, reductionVal); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, reduction); + fir::ResultOp::create(builder, loc, reduction); reductionVal = ifOp.getResult(0); builder.setInsertionPointAfter(ifOp); } @@ -825,12 +826,12 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, mlir::Type logical = maskElemType; mlir::Type logicalRefTy = builder.getRefType(logical); mlir::Value condAddr = - builder.create<fir::BoxAddrOp>(loc, logicalRefTy, mask); - mlir::Value cond = builder.create<fir::LoadOp>(loc, condAddr); - mlir::Value condI1 = builder.create<fir::ConvertOp>(loc, i1Type, cond); + fir::BoxAddrOp::create(builder, loc, logicalRefTy, mask); + mlir::Value cond = fir::LoadOp::create(builder, loc, condAddr); + mlir::Value condI1 = fir::ConvertOp::create(builder, loc, i1Type, cond); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, condI1, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, elementType, condI1, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value basicValue; @@ -839,7 +840,7 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, } else { basicValue = builder.createRealConstant(loc, elementType, 0); } - builder.create<fir::ResultOp>(loc, basicValue); + fir::ResultOp::create(builder, loc, basicValue); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } @@ -847,8 +848,8 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, const mlir::Type &resultElemType, mlir::Value resultArr, mlir::Value index) { mlir::Type resultRefTy = builder.getRefType(resultElemType); - return builder.create<fir::CoordinateOp>(loc, resultRefTy, resultArr, - index); + return fir::CoordinateOp::create(builder, loc, resultRefTy, resultArr, + index); }; genMinMaxlocReductionLoop(builder, funcOp.front().getArgument(1), init, @@ -859,25 +860,26 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder, if (isDim) { mlir::Type resultBoxTy = fir::BoxType::get(fir::HeapType::get(resultElemTy)); - mlir::Value outputArr = builder.create<fir::ConvertOp>( - loc, builder.getRefType(resultBoxTy), funcOp.front().getArgument(0)); - mlir::Value resultArrScalar = builder.create<fir::ConvertOp>( - loc, fir::HeapType::get(resultElemTy), resultArrInit); + mlir::Value outputArr = + fir::ConvertOp::create(builder, loc, builder.getRefType(resultBoxTy), + funcOp.front().getArgument(0)); + mlir::Value resultArrScalar = fir::ConvertOp::create( + builder, loc, fir::HeapType::get(resultElemTy), resultArrInit); mlir::Value resultBox = - builder.create<fir::EmboxOp>(loc, resultBoxTy, resultArrScalar); - builder.create<fir::StoreOp>(loc, resultBox, outputArr); + fir::EmboxOp::create(builder, loc, resultBoxTy, resultArrScalar); + fir::StoreOp::create(builder, loc, resultBox, outputArr); } else { fir::SequenceType::Shape resultShape(1, rank); mlir::Type outputArrTy = fir::SequenceType::get(resultShape, resultElemTy); mlir::Type outputHeapTy = fir::HeapType::get(outputArrTy); mlir::Type outputBoxTy = fir::BoxType::get(outputHeapTy); mlir::Type outputRefTy = builder.getRefType(outputBoxTy); - mlir::Value outputArr = builder.create<fir::ConvertOp>( - loc, outputRefTy, funcOp.front().getArgument(0)); - builder.create<fir::StoreOp>(loc, resultArr, outputArr); + mlir::Value outputArr = fir::ConvertOp::create( + builder, loc, outputRefTy, funcOp.front().getArgument(0)); + fir::StoreOp::create(builder, loc, resultArr, outputArr); } - builder.create<mlir::func::ReturnOp>(loc); + mlir::func::ReturnOp::create(builder, loc); } /// Generate function type for the simplified version of RTNAME(DotProduct) @@ -929,10 +931,10 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, fir::SequenceType::Shape flatShape = {fir::SequenceType::getUnknownExtent()}; mlir::Type arrTy1 = fir::SequenceType::get(flatShape, arg1ElementTy); mlir::Type boxArrTy1 = fir::BoxType::get(arrTy1); - mlir::Value array1 = builder.create<fir::ConvertOp>(loc, boxArrTy1, arg1); + mlir::Value array1 = fir::ConvertOp::create(builder, loc, boxArrTy1, arg1); mlir::Type arrTy2 = fir::SequenceType::get(flatShape, arg2ElementTy); mlir::Type boxArrTy2 = fir::BoxType::get(arrTy2); - mlir::Value array2 = builder.create<fir::ConvertOp>(loc, boxArrTy2, arg2); + mlir::Value array2 = fir::ConvertOp::create(builder, loc, boxArrTy2, arg2); // This version takes the loop trip count from the first argument. // If the first argument's box has unknown (at compilation time) // extent, then it may be better to take the extent from the second @@ -941,17 +943,17 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, // function and some analysis at the call site to choose which version // is more profitable to call. // Note that we can assume that both arguments have the same extent. - auto dims = - builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, array1, zeroIdx); + auto dims = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, array1, + zeroIdx); mlir::Value len = dims.getResult(1); mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); mlir::Value step = one; // We use C indexing here, so len-1 as loopcount - mlir::Value loopCount = builder.create<mlir::arith::SubIOp>(loc, len, one); - auto loop = builder.create<fir::DoLoopOp>(loc, zeroIdx, loopCount, step, - /*unordered=*/false, - /*finalCountValue=*/false, zero); + mlir::Value loopCount = mlir::arith::SubIOp::create(builder, loc, len, one); + auto loop = fir::DoLoopOp::create(builder, loc, zeroIdx, loopCount, step, + /*unordered=*/false, + /*finalCountValue=*/false, zero); mlir::Value sumVal = loop.getRegionIterArgs()[0]; // Begin loop code @@ -961,33 +963,35 @@ static void genRuntimeDotBody(fir::FirOpBuilder &builder, mlir::Type eleRef1Ty = builder.getRefType(arg1ElementTy); mlir::Value index = loop.getInductionVar(); mlir::Value addr1 = - builder.create<fir::CoordinateOp>(loc, eleRef1Ty, array1, index); - mlir::Value elem1 = builder.create<fir::LoadOp>(loc, addr1); + fir::CoordinateOp::create(builder, loc, eleRef1Ty, array1, index); + mlir::Value elem1 = fir::LoadOp::create(builder, loc, addr1); // Convert to the result type. - elem1 = builder.create<fir::ConvertOp>(loc, resultElementType, elem1); + elem1 = fir::ConvertOp::create(builder, loc, resultElementType, elem1); mlir::Type eleRef2Ty = builder.getRefType(arg2ElementTy); mlir::Value addr2 = - builder.create<fir::CoordinateOp>(loc, eleRef2Ty, array2, index); - mlir::Value elem2 = builder.create<fir::LoadOp>(loc, addr2); + fir::CoordinateOp::create(builder, loc, eleRef2Ty, array2, index); + mlir::Value elem2 = fir::LoadOp::create(builder, loc, addr2); // Convert to the result type. - elem2 = builder.create<fir::ConvertOp>(loc, resultElementType, elem2); + elem2 = fir::ConvertOp::create(builder, loc, resultElementType, elem2); if (mlir::isa<mlir::FloatType>(resultElementType)) - sumVal = builder.create<mlir::arith::AddFOp>( - loc, builder.create<mlir::arith::MulFOp>(loc, elem1, elem2), sumVal); + sumVal = mlir::arith::AddFOp::create( + builder, loc, mlir::arith::MulFOp::create(builder, loc, elem1, elem2), + sumVal); else if (mlir::isa<mlir::IntegerType>(resultElementType)) - sumVal = builder.create<mlir::arith::AddIOp>( - loc, builder.create<mlir::arith::MulIOp>(loc, elem1, elem2), sumVal); + sumVal = mlir::arith::AddIOp::create( + builder, loc, mlir::arith::MulIOp::create(builder, loc, elem1, elem2), + sumVal); else llvm_unreachable("unsupported type"); - builder.create<fir::ResultOp>(loc, sumVal); + fir::ResultOp::create(builder, loc, sumVal); // End of loop. builder.restoreInsertionPoint(loopEndPt); mlir::Value resultVal = loop.getResult(0); - builder.create<mlir::func::ReturnOp>(loc, resultVal); + mlir::func::ReturnOp::create(builder, loc, resultVal); } mlir::func::FuncOp SimplifyIntrinsicsPass::getOrCreateFunction( @@ -1229,8 +1233,8 @@ void SimplifyIntrinsicsPass::simplifyMinMaxlocReduction( mlir::func::FuncOp newFunc = getOrCreateFunction(builder, funcName, typeGenerator, bodyGenerator); - builder.create<fir::CallOp>(loc, newFunc, - mlir::ValueRange{args[0], args[1], mask}); + fir::CallOp::create(builder, loc, newFunc, + mlir::ValueRange{args[0], args[1], mask}); call->dropAllReferences(); call->erase(); } @@ -1259,7 +1263,7 @@ void SimplifyIntrinsicsPass::simplifyReductionBody( mlir::func::FuncOp newFunc = getOrCreateFunction(builder, funcName, typeGenerator, bodyGenerator); auto newCall = - builder.create<fir::CallOp>(loc, newFunc, mlir::ValueRange{args[0]}); + fir::CallOp::create(builder, loc, newFunc, mlir::ValueRange{args[0]}); call->replaceAllUsesWith(newCall.getResults()); call->dropAllReferences(); call->erase(); @@ -1344,8 +1348,8 @@ void SimplifyIntrinsicsPass::runOnOperation() { mlir::func::FuncOp newFunc = getOrCreateFunction( builder, typedFuncName, typeGenerator, bodyGenerator); - auto newCall = builder.create<fir::CallOp>(loc, newFunc, - mlir::ValueRange{v1, v2}); + auto newCall = fir::CallOp::create(builder, loc, newFunc, + mlir::ValueRange{v1, v2}); call->replaceAllUsesWith(newCall.getResults()); call->dropAllReferences(); call->erase(); diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp index bc8a949..0d13129 100644 --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -569,7 +569,7 @@ static mlir::Value convertAllocationType(mlir::PatternRewriter &rewriter, auto insertionPoint = rewriter.saveInsertionPoint(); rewriter.setInsertionPointAfter(stack.getDefiningOp()); mlir::Value conv = - rewriter.create<fir::ConvertOp>(loc, firHeapTy, stack).getResult(); + fir::ConvertOp::create(rewriter, loc, firHeapTy, stack).getResult(); rewriter.restoreInsertionPoint(insertionPoint); return conv; } @@ -758,9 +758,9 @@ AllocMemConversion::insertAlloca(fir::AllocMemOp &oldAlloc, llvm::StringRef uniqName = unpackName(oldAlloc.getUniqName()); llvm::StringRef bindcName = unpackName(oldAlloc.getBindcName()); - auto alloca = rewriter.create<fir::AllocaOp>(loc, varTy, uniqName, bindcName, - oldAlloc.getTypeparams(), - oldAlloc.getShape()); + auto alloca = + fir::AllocaOp::create(rewriter, loc, varTy, uniqName, bindcName, + oldAlloc.getTypeparams(), oldAlloc.getShape()); if (emitLifetimeMarkers) insertLifetimeMarkers(oldAlloc, alloca, rewriter); |