aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Optimizer')
-rw-r--r--flang/lib/Optimizer/Builder/CUFCommon.cpp8
-rw-r--r--flang/lib/Optimizer/Builder/Character.cpp155
-rw-r--r--flang/lib/Optimizer/Builder/Complex.cpp2
-rw-r--r--flang/lib/Optimizer/Builder/DoLoopHelper.cpp4
-rw-r--r--flang/lib/Optimizer/Builder/FIRBuilder.cpp145
-rw-r--r--flang/lib/Optimizer/Builder/HLFIRTools.cpp181
-rw-r--r--flang/lib/Optimizer/Builder/IntrinsicCall.cpp1765
-rw-r--r--flang/lib/Optimizer/Builder/MutableBox.cpp128
-rw-r--r--flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp250
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp12
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp6
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Assign.cpp12
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/CUDA/Descriptor.cpp6
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Character.cpp22
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Command.cpp20
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Derived.cpp19
-rwxr-xr-xflang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp32
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Exceptions.cpp24
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Execute.cpp2
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Inquiry.cpp16
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp75
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Main.cpp10
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Numeric.cpp28
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Pointer.cpp2
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Ragged.cpp14
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Reduction.cpp57
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Stop.cpp6
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Support.cpp4
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp16
-rw-r--r--flang/lib/Optimizer/Builder/Runtime/Transformational.cpp32
-rw-r--r--flang/lib/Optimizer/Builder/TemporaryStorage.cpp30
-rw-r--r--flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp14
-rw-r--r--flang/lib/Optimizer/CodeGen/CodeGen.cpp477
-rw-r--r--flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp50
-rw-r--r--flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp39
-rw-r--r--flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp34
-rw-r--r--flang/lib/Optimizer/Dialect/FIRDialect.cpp2
-rw-r--r--flang/lib/Optimizer/Dialect/FIROps.cpp20
-rw-r--r--flang/lib/Optimizer/Dialect/Support/FIRContext.cpp51
-rw-r--r--flang/lib/Optimizer/Dialect/Support/KindMapping.cpp1
-rw-r--r--flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp6
-rw-r--r--flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp10
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp65
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp128
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRAssign.cpp2
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopyIn.cpp34
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp4
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp19
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp18
-rw-r--r--flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp244
-rw-r--r--flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp69
-rw-r--r--flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp23
-rw-r--r--flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp2
-rw-r--r--flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp14
-rw-r--r--flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp26
-rw-r--r--flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp131
-rw-r--r--flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp8
-rw-r--r--flang/lib/Optimizer/Support/CMakeLists.txt9
-rw-r--r--flang/lib/Optimizer/Transforms/AbstractResult.cpp28
-rw-r--r--flang/lib/Optimizer/Transforms/AddAliasTags.cpp41
-rw-r--r--flang/lib/Optimizer/Transforms/AffineDemotion.cpp12
-rw-r--r--flang/lib/Optimizer/Transforms/AffinePromotion.cpp40
-rw-r--r--flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp63
-rw-r--r--flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp6
-rw-r--r--flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp30
-rw-r--r--flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp13
-rw-r--r--flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp75
-rw-r--r--flang/lib/Optimizer/Transforms/CUFOpConversion.cpp123
-rw-r--r--flang/lib/Optimizer/Transforms/CharacterConversion.cpp32
-rw-r--r--flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp16
-rw-r--r--flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp95
-rw-r--r--flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp5
-rw-r--r--flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp58
-rw-r--r--flang/lib/Optimizer/Transforms/FIRToSCF.cpp61
-rw-r--r--flang/lib/Optimizer/Transforms/GenRuntimeCallsForTest.cpp4
-rw-r--r--flang/lib/Optimizer/Transforms/LoopVersioning.cpp44
-rw-r--r--flang/lib/Optimizer/Transforms/MemoryAllocation.cpp8
-rw-r--r--flang/lib/Optimizer/Transforms/MemoryUtils.cpp24
-rw-r--r--flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp88
-rw-r--r--flang/lib/Optimizer/Transforms/SimplifyFIROperations.cpp20
-rw-r--r--flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp256
-rw-r--r--flang/lib/Optimizer/Transforms/StackArrays.cpp8
82 files changed, 3041 insertions, 2692 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 5b1dbc44..eaad54e 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -406,10 +406,10 @@ mlir::Value fir::FirOpBuilder::genTempDeclareOp(
llvm::ArrayRef<mlir::Value> typeParams,
fir::FortranVariableFlagsAttr fortranAttrs) {
auto nameAttr = mlir::StringAttr::get(builder.getContext(), name);
- return builder.create<fir::DeclareOp>(loc, memref.getType(), memref, shape,
- typeParams,
- /*dummy_scope=*/nullptr, nameAttr,
- fortranAttrs, cuf::DataAttributeAttr{});
+ return fir::DeclareOp::create(builder, loc, memref.getType(), memref, shape,
+ typeParams,
+ /*dummy_scope=*/nullptr, nameAttr, fortranAttrs,
+ cuf::DataAttributeAttr{});
}
mlir::Value fir::FirOpBuilder::genStackSave(mlir::Location loc) {
@@ -585,7 +585,7 @@ mlir::Value fir::factory::createConvert(mlir::OpBuilder &builder,
mlir::cast<fir::RecordType>(val.getType()).getTypeList() ==
mlir::cast<fir::RecordType>(toTy).getTypeList()) &&
"incompatible record types");
- return builder.create<fir::ConvertOp>(loc, toTy, val);
+ return fir::ConvertOp::create(builder, loc, toTy, val);
}
return val;
}
@@ -824,7 +824,7 @@ genNullPointerComparison(fir::FirOpBuilder &builder, mlir::Location loc,
auto intPtrTy = builder.getIntPtrType();
auto ptrToInt = builder.createConvert(loc, intPtrTy, addr);
auto c0 = builder.createIntegerConstant(loc, intPtrTy, 0);
- return builder.create<mlir::arith::CmpIOp>(loc, condition, ptrToInt, c0);
+ return mlir::arith::CmpIOp::create(builder, loc, condition, ptrToInt, c0);
}
mlir::Value fir::FirOpBuilder::genIsNotNullAddr(mlir::Location loc,
@@ -1028,8 +1028,8 @@ fir::factory::readExtents(fir::FirOpBuilder &builder, mlir::Location loc,
auto idxTy = builder.getIndexType();
for (decltype(rank) dim = 0; dim < rank; ++dim) {
auto dimVal = builder.createIntegerConstant(loc, idxTy, dim);
- auto dimInfo = builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy,
- box.getAddr(), dimVal);
+ auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy,
+ box.getAddr(), dimVal);
result.emplace_back(dimInfo.getResult(1));
}
return result;
@@ -1061,7 +1061,7 @@ fir::ExtendedValue fir::factory::readBoxValue(fir::FirOpBuilder &builder,
assert(!box.hasAssumedRank() &&
"cannot read unlimited polymorphic or assumed rank fir.box");
auto addr =
- builder.create<fir::BoxAddrOp>(loc, box.getMemTy(), box.getAddr());
+ fir::BoxAddrOp::create(builder, loc, box.getMemTy(), box.getAddr());
if (box.isCharacter()) {
auto len = fir::factory::readCharLen(builder, loc, box);
if (box.rank() == 0)
@@ -1139,13 +1139,13 @@ static llvm::SmallVector<mlir::Value> getFromBox(mlir::Location loc,
} else if (auto charTy = mlir::dyn_cast<fir::CharacterType>(eleTy)) {
if (charTy.hasDynamicLen()) {
auto idxTy = builder.getIndexType();
- auto eleSz = builder.create<fir::BoxEleSizeOp>(loc, idxTy, boxVal);
+ auto eleSz = fir::BoxEleSizeOp::create(builder, loc, idxTy, boxVal);
auto kindBytes =
builder.getKindMap().getCharacterBitsize(charTy.getFKind()) / 8;
mlir::Value charSz =
builder.createIntegerConstant(loc, idxTy, kindBytes);
mlir::Value len =
- builder.create<mlir::arith::DivSIOp>(loc, eleSz, charSz);
+ mlir::arith::DivSIOp::create(builder, loc, eleSz, charSz);
return {len};
}
}
@@ -1237,11 +1237,11 @@ fir::ExtendedValue fir::factory::createStringLiteral(fir::FirOpBuilder &builder,
loc, type, globalName,
[&](fir::FirOpBuilder &builder) {
auto stringLitOp = builder.createStringLitOp(loc, str);
- builder.create<fir::HasValueOp>(loc, stringLitOp);
+ fir::HasValueOp::create(builder, loc, stringLitOp);
},
builder.createLinkOnceLinkage());
- auto addr = builder.create<fir::AddrOfOp>(loc, global.resultType(),
- global.getSymbol());
+ auto addr = fir::AddrOfOp::create(builder, loc, global.resultType(),
+ global.getSymbol());
auto len = builder.createIntegerConstant(
loc, builder.getCharacterLengthType(), str.size());
return fir::CharBoxValue{addr, len};
@@ -1255,7 +1255,7 @@ fir::factory::createExtents(fir::FirOpBuilder &builder, mlir::Location loc,
for (auto ext : seqTy.getShape())
extents.emplace_back(
ext == fir::SequenceType::getUnknownExtent()
- ? builder.create<fir::UndefOp>(loc, idxTy).getResult()
+ ? fir::UndefOp::create(builder, loc, idxTy).getResult()
: builder.createIntegerConstant(loc, idxTy, ext));
return extents;
}
@@ -1396,11 +1396,11 @@ void fir::factory::genScalarAssignment(fir::FirOpBuilder &builder,
assert(!fir::hasDynamicSize(type));
auto rhsVal = fir::getBase(rhs);
if (fir::isa_ref_type(rhsVal.getType()))
- rhsVal = builder.create<fir::LoadOp>(loc, rhsVal);
+ rhsVal = fir::LoadOp::create(builder, loc, rhsVal);
mlir::Value lhsAddr = fir::getBase(lhs);
rhsVal = builder.createConvert(loc, fir::unwrapRefType(lhsAddr.getType()),
rhsVal);
- builder.create<fir::StoreOp>(loc, rhsVal, lhsAddr);
+ fir::StoreOp::create(builder, loc, rhsVal, lhsAddr);
}
}
@@ -1421,16 +1421,18 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
auto &[lFieldName, lFieldTy] = lhsPair;
auto &[rFieldName, rFieldTy] = rhsPair;
assert(!fir::hasDynamicSize(lFieldTy) && !fir::hasDynamicSize(rFieldTy));
- mlir::Value rField = builder.create<fir::FieldIndexOp>(
- loc, fieldIndexType, rFieldName, rhsType, fir::getTypeParams(rhs));
+ mlir::Value rField =
+ fir::FieldIndexOp::create(builder, loc, fieldIndexType, rFieldName,
+ rhsType, fir::getTypeParams(rhs));
auto rFieldRefType = builder.getRefType(rFieldTy);
- mlir::Value fromCoor = builder.create<fir::CoordinateOp>(
- loc, rFieldRefType, fir::getBase(rhs), rField);
- mlir::Value field = builder.create<fir::FieldIndexOp>(
- loc, fieldIndexType, lFieldName, lhsType, fir::getTypeParams(lhs));
+ mlir::Value fromCoor = fir::CoordinateOp::create(
+ builder, loc, rFieldRefType, fir::getBase(rhs), rField);
+ mlir::Value field =
+ fir::FieldIndexOp::create(builder, loc, fieldIndexType, lFieldName,
+ lhsType, fir::getTypeParams(lhs));
auto fieldRefType = builder.getRefType(lFieldTy);
- mlir::Value toCoor = builder.create<fir::CoordinateOp>(
- loc, fieldRefType, fir::getBase(lhs), field);
+ mlir::Value toCoor = fir::CoordinateOp::create(builder, loc, fieldRefType,
+ fir::getBase(lhs), field);
std::optional<fir::DoLoopOp> outerLoop;
if (auto sequenceType = mlir::dyn_cast<fir::SequenceType>(lFieldTy)) {
// Create loops to assign array components elements by elements.
@@ -1444,7 +1446,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
for (auto extent : llvm::reverse(sequenceType.getShape())) {
// TODO: add zero size test !
mlir::Value ub = builder.createIntegerConstant(loc, idxTy, extent - 1);
- auto loop = builder.create<fir::DoLoopOp>(loc, zero, ub, one);
+ auto loop = fir::DoLoopOp::create(builder, loc, zero, ub, one);
if (!outerLoop)
outerLoop = loop;
indices.push_back(loop.getInductionVar());
@@ -1453,19 +1455,19 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder,
// Set indices in column-major order.
std::reverse(indices.begin(), indices.end());
auto elementRefType = builder.getRefType(sequenceType.getEleTy());
- toCoor = builder.create<fir::CoordinateOp>(loc, elementRefType, toCoor,
- indices);
- fromCoor = builder.create<fir::CoordinateOp>(loc, elementRefType,
- fromCoor, indices);
+ toCoor = fir::CoordinateOp::create(builder, loc, elementRefType, toCoor,
+ indices);
+ fromCoor = fir::CoordinateOp::create(builder, loc, elementRefType,
+ fromCoor, indices);
}
if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy);
mlir::isa<fir::BaseBoxType>(fieldEleTy)) {
assert(mlir::isa<fir::PointerType>(
mlir::cast<fir::BaseBoxType>(fieldEleTy).getEleTy()) &&
"allocatable members require deep copy");
- auto fromPointerValue = builder.create<fir::LoadOp>(loc, fromCoor);
+ auto fromPointerValue = fir::LoadOp::create(builder, loc, fromCoor);
auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue);
- builder.create<fir::StoreOp>(loc, castTo, toCoor);
+ fir::StoreOp::create(builder, loc, castTo, toCoor);
} else {
auto from =
fir::factory::componentToExtendedValue(builder, loc, fromCoor);
@@ -1543,7 +1545,7 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder,
// runtime interface, but assume the fir.box is unchanged.
// TODO: does this holds true with polymorphic entities ?
auto toMutableBox = builder.createTemporary(loc, to.getType());
- builder.create<fir::StoreOp>(loc, to, toMutableBox);
+ fir::StoreOp::create(builder, loc, to, toMutableBox);
if (isTemporaryLHS)
fir::runtime::genAssignTemporary(builder, loc, toMutableBox, from);
else
@@ -1588,12 +1590,12 @@ mlir::Value fir::factory::genLenOfCharacter(
auto idxTy = builder.getIndexType();
auto zero = builder.createIntegerConstant(loc, idxTy, 0);
auto saturatedDiff = [&](mlir::Value lower, mlir::Value upper) {
- auto diff = builder.create<mlir::arith::SubIOp>(loc, upper, lower);
+ auto diff = mlir::arith::SubIOp::create(builder, loc, upper, lower);
auto one = builder.createIntegerConstant(loc, idxTy, 1);
- auto size = builder.create<mlir::arith::AddIOp>(loc, diff, one);
- auto cmp = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::sgt, size, zero);
- return builder.create<mlir::arith::SelectOp>(loc, cmp, size, zero);
+ auto size = mlir::arith::AddIOp::create(builder, loc, diff, one);
+ auto cmp = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::sgt, size, zero);
+ return mlir::arith::SelectOp::create(builder, loc, cmp, size, zero);
};
if (substring.size() == 2) {
auto upper = builder.createConvert(loc, idxTy, substring.back());
@@ -1615,7 +1617,7 @@ mlir::Value fir::factory::genLenOfCharacter(
}
if (fir::isa_box_type(memref.getType())) {
if (mlir::isa<fir::BoxCharType>(memref.getType()))
- return builder.create<fir::BoxCharLenOp>(loc, idxTy, memref);
+ return fir::BoxCharLenOp::create(builder, loc, idxTy, memref);
if (mlir::isa<fir::BoxType>(memref.getType()))
return CharacterExprHelper(builder, loc).readLengthFromBox(memref);
fir::emitFatalError(loc, "memref has wrong type");
@@ -1684,10 +1686,10 @@ mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder,
if (auto cst = mlir::dyn_cast<mlir::arith::ConstantOp>(definingOp))
if (auto intAttr = mlir::dyn_cast<mlir::IntegerAttr>(cst.getValue()))
return intAttr.getInt() > 0 ? value : zero;
- mlir::Value valueIsGreater = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::sgt, value, zero);
- return builder.create<mlir::arith::SelectOp>(loc, valueIsGreater, value,
- zero);
+ mlir::Value valueIsGreater = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::sgt, value, zero);
+ return mlir::arith::SelectOp::create(builder, loc, valueIsGreater, value,
+ zero);
}
mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder,
@@ -1703,8 +1705,8 @@ mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder,
mlir::Value one) {
mlir::Type type = lb.getType();
// Let the folder deal with the common `ub - <const> + 1` case.
- auto diff = builder.create<mlir::arith::SubIOp>(loc, type, ub, lb);
- auto rawExtent = builder.create<mlir::arith::AddIOp>(loc, type, diff, one);
+ auto diff = mlir::arith::SubIOp::create(builder, loc, type, ub, lb);
+ auto rawExtent = mlir::arith::AddIOp::create(builder, loc, type, diff, one);
return fir::factory::genMaxWithZero(builder, loc, rawExtent, zero);
}
mlir::Value fir::factory::computeExtent(fir::FirOpBuilder &builder,
@@ -1724,8 +1726,8 @@ genCPtrOrCFunptrFieldIndex(fir::FirOpBuilder &builder, mlir::Location loc,
auto addrFieldName = recTy.getTypeList()[0].first;
mlir::Type addrFieldTy = recTy.getTypeList()[0].second;
auto fieldIndexType = fir::FieldType::get(cptrTy.getContext());
- mlir::Value addrFieldIndex = builder.create<fir::FieldIndexOp>(
- loc, fieldIndexType, addrFieldName, recTy,
+ mlir::Value addrFieldIndex = fir::FieldIndexOp::create(
+ builder, loc, fieldIndexType, addrFieldName, recTy,
/*typeParams=*/mlir::ValueRange{});
return {addrFieldIndex, addrFieldTy};
}
@@ -1736,8 +1738,8 @@ mlir::Value fir::factory::genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder,
mlir::Type ty) {
auto [addrFieldIndex, addrFieldTy] =
genCPtrOrCFunptrFieldIndex(builder, loc, ty);
- return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy),
- cPtr, addrFieldIndex);
+ return fir::CoordinateOp::create(
+ builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex);
}
mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder,
@@ -1748,15 +1750,15 @@ mlir::Value fir::factory::genCDevPtrAddr(fir::FirOpBuilder &builder,
auto cptrFieldName = recTy.getTypeList()[0].first;
mlir::Type cptrFieldTy = recTy.getTypeList()[0].second;
auto fieldIndexType = fir::FieldType::get(ty.getContext());
- mlir::Value cptrFieldIndex = builder.create<fir::FieldIndexOp>(
- loc, fieldIndexType, cptrFieldName, recTy,
+ mlir::Value cptrFieldIndex = fir::FieldIndexOp::create(
+ builder, loc, fieldIndexType, cptrFieldName, recTy,
/*typeParams=*/mlir::ValueRange{});
- auto cptrCoord = builder.create<fir::CoordinateOp>(
- loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex);
+ auto cptrCoord = fir::CoordinateOp::create(
+ builder, loc, builder.getRefType(cptrFieldTy), cDevPtr, cptrFieldIndex);
auto [addrFieldIndex, addrFieldTy] =
genCPtrOrCFunptrFieldIndex(builder, loc, cptrFieldTy);
- return builder.create<fir::CoordinateOp>(loc, builder.getRefType(addrFieldTy),
- cptrCoord, addrFieldIndex);
+ return fir::CoordinateOp::create(
+ builder, loc, builder.getRefType(addrFieldTy), cptrCoord, addrFieldIndex);
}
mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
@@ -1769,13 +1771,13 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy);
mlir::Value cPtrCoor;
if (fir::isa_ref_type(cPtr.getType())) {
- cPtrCoor = builder.create<fir::CoordinateOp>(
- loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex);
+ cPtrCoor = fir::CoordinateOp::create(
+ builder, loc, builder.getRefType(addrFieldTy), cPtr, addrFieldIndex);
} else {
auto arrayAttr = builder.getArrayAttr(
{builder.getIntegerAttr(builder.getIndexType(), 0)});
- cPtrCoor = builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr,
- arrayAttr);
+ cPtrCoor = fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr,
+ arrayAttr);
}
return genCPtrOrCFunptrValue(builder, loc, cPtrCoor);
}
@@ -1783,13 +1785,14 @@ mlir::Value fir::factory::genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
if (fir::isa_ref_type(cPtr.getType())) {
mlir::Value cPtrAddr =
fir::factory::genCPtrOrCFunptrAddr(builder, loc, cPtr, cPtrTy);
- return builder.create<fir::LoadOp>(loc, cPtrAddr);
+ return fir::LoadOp::create(builder, loc, cPtrAddr);
}
auto [addrFieldIndex, addrFieldTy] =
genCPtrOrCFunptrFieldIndex(builder, loc, cPtrTy);
auto arrayAttr =
builder.getArrayAttr({builder.getIntegerAttr(builder.getIndexType(), 0)});
- return builder.create<fir::ExtractValueOp>(loc, addrFieldTy, cPtr, arrayAttr);
+ return fir::ExtractValueOp::create(builder, loc, addrFieldTy, cPtr,
+ arrayAttr);
}
fir::BoxValue fir::factory::createBoxValue(fir::FirOpBuilder &builder,
@@ -1837,8 +1840,8 @@ mlir::Value fir::factory::createNullBoxProc(fir::FirOpBuilder &builder,
if (!boxTy)
fir::emitFatalError(loc, "Procedure pointer must be of BoxProcType");
auto boxEleTy{fir::unwrapRefType(boxTy.getEleTy())};
- mlir::Value initVal{builder.create<fir::ZeroOp>(loc, boxEleTy)};
- return builder.create<fir::EmboxProcOp>(loc, boxTy, initVal);
+ mlir::Value initVal{fir::ZeroOp::create(builder, loc, boxEleTy)};
+ return fir::EmboxProcOp::create(builder, loc, boxTy, initVal);
}
void fir::factory::setInternalLinkage(mlir::func::FuncOp func) {
@@ -1897,15 +1900,15 @@ llvm::SmallVector<mlir::Value> fir::factory::updateRuntimeExtentsForEmptyArrays(
mlir::Type type = extent.getType();
mlir::Value zero = createZeroValue(builder, loc, type);
zeroes.push_back(zero);
- mlir::Value isZero = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::eq, extent, zero);
- isEmpty = builder.create<mlir::arith::OrIOp>(loc, isEmpty, isZero);
+ mlir::Value isZero = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero);
+ isEmpty = mlir::arith::OrIOp::create(builder, loc, isEmpty, isZero);
}
llvm::SmallVector<mlir::Value> newExtents;
for (auto [zero, extent] : llvm::zip_equal(zeroes, extents)) {
newExtents.push_back(
- builder.create<mlir::arith::SelectOp>(loc, isEmpty, zero, extent));
+ mlir::arith::SelectOp::create(builder, loc, isEmpty, zero, extent));
}
return newExtents;
}
@@ -1926,7 +1929,7 @@ void fir::factory::genDimInfoFromBox(
for (unsigned i = 0; i < rank; ++i) {
mlir::Value dim = builder.createIntegerConstant(loc, idxTy, i);
auto dimInfo =
- builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim);
+ fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, box, dim);
if (lbounds)
lbounds->push_back(dimInfo.getLowerBound());
if (extents)
@@ -1943,12 +1946,12 @@ mlir::Value fir::factory::genLifetimeStart(mlir::OpBuilder &builder,
mlir::Type ptrTy = mlir::LLVM::LLVMPointerType::get(
alloc.getContext(), getAllocaAddressSpace(dl));
mlir::Value cast =
- builder.create<fir::ConvertOp>(loc, ptrTy, alloc.getResult());
- builder.create<mlir::LLVM::LifetimeStartOp>(loc, size, cast);
+ fir::ConvertOp::create(builder, loc, ptrTy, alloc.getResult());
+ mlir::LLVM::LifetimeStartOp::create(builder, loc, size, cast);
return cast;
}
void fir::factory::genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc,
mlir::Value cast, int64_t size) {
- builder.create<mlir::LLVM::LifetimeEndOp>(loc, size, cast);
+ mlir::LLVM::LifetimeEndOp::create(builder, loc, size, cast);
}
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..e62ed48 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -246,6 +246,7 @@ static constexpr IntrinsicHandler handlers[]{
{"abs", &I::genAbs},
{"achar", &I::genChar},
{"acosd", &I::genAcosd},
+ {"acospi", &I::genAcospi},
{"adjustl",
&I::genAdjustRtCall<fir::runtime::genAdjustL>,
{{{"string", asAddr}}},
@@ -278,6 +279,7 @@ static constexpr IntrinsicHandler handlers[]{
{{{"mask", asValue}, {"pred", asValue}}},
/*isElemental=*/false},
{"asind", &I::genAsind},
+ {"asinpi", &I::genAsinpi},
{"associated",
&I::genAssociated,
{{{"pointer", asInquired}, {"target", asInquired}}},
@@ -369,7 +371,8 @@ static constexpr IntrinsicHandler handlers[]{
&I::genCFPointer,
{{{"cptr", asValue},
{"fptr", asInquired},
- {"shape", asAddr, handleDynamicOptional}}},
+ {"shape", asAddr, handleDynamicOptional},
+ {"lower", asAddr, handleDynamicOptional}}},
/*isElemental=*/false},
{"c_f_procpointer",
&I::genCFProcPointer,
@@ -901,6 +904,7 @@ static constexpr IntrinsicHandler handlers[]{
{{{"number", asValue}, {"handler", asAddr}, {"status", asAddr}}},
/*isElemental=*/false},
{"sind", &I::genSind},
+ {"sinpi", &I::genSinpi},
{"size",
&I::genSize,
{{{"array", asBox},
@@ -941,6 +945,7 @@ static constexpr IntrinsicHandler handlers[]{
{{{"count", asAddr}, {"count_rate", asAddr}, {"count_max", asAddr}}},
/*isElemental=*/false},
{"tand", &I::genTand},
+ {"tanpi", &I::genTanpi},
{"this_grid", &I::genThisGrid, {}, /*isElemental=*/false},
{"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false},
{"this_warp", &I::genThisWarp, {}, /*isElemental=*/false},
@@ -1110,7 +1115,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 +1129,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 +1143,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 +1225,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 +1263,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 +2466,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 +2482,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 +2600,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 +2655,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 +2676,22 @@ 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);
+}
+
+// ACOSPI
+mlir::Value IntrinsicLibrary::genAcospi(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ mlir::Value acos = getRuntimeCallGenerator("acos", ftype)(builder, loc, args);
+ llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi);
+ mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
+ return mlir::arith::MulFOp::create(builder, loc, acos, factor);
}
// ADJUSTL & ADJUSTR
@@ -2824,7 +2844,22 @@ 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);
+}
+
+// ASINPI
+mlir::Value IntrinsicLibrary::genAsinpi(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ mlir::Value asin = getRuntimeCallGenerator("asin", ftype)(builder, loc, args);
+ llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi);
+ mlir::Value dfactor =
+ builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi);
+ mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
+ return mlir::arith::MulFOp::create(builder, loc, asin, factor);
}
// ATAND, ATAN2D
@@ -2838,8 +2873,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 +2884,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 +2898,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 +2909,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 +2917,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 +2976,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 +2993,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 +3073,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 +3110,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 +3141,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 +3158,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 +3226,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 +3243,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 +3315,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 +3339,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 +3352,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 +3366,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 +3377,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 +3390,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 +3400,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];
}
@@ -3403,7 +3439,7 @@ IntrinsicLibrary::genCDevLoc(mlir::Type resultType,
// C_F_POINTER
void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) {
- assert(args.size() == 3);
+ assert(args.size() == 4);
// Handle CPTR argument
// Get the value of the C address or the result of a reference to C_LOC.
mlir::Value cPtr = fir::getBase(args[0]);
@@ -3418,9 +3454,12 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) {
mlir::Value addr =
builder.createConvert(loc, fPtr->getMemTy(), cPtrAddrVal);
mlir::SmallVector<mlir::Value> extents;
+ mlir::SmallVector<mlir::Value> lbounds;
if (box.hasRank()) {
assert(isStaticallyPresent(args[2]) &&
"FPTR argument must be an array if SHAPE argument exists");
+
+ // Handle and unpack SHAPE argument
mlir::Value shape = fir::getBase(args[2]);
int arrayRank = box.rank();
mlir::Type shapeElementType =
@@ -3428,22 +3467,36 @@ 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));
}
+
+ // Handle and unpack LOWER argument if present
+ if (isStaticallyPresent(args[3])) {
+ mlir::Value lower = fir::getBase(args[3]);
+ mlir::Type lowerElementType =
+ fir::unwrapSequenceType(fir::unwrapPassByRefType(lower.getType()));
+ 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(lowerElementType), lower, index);
+ mlir::Value load = builder.create<fir::LoadOp>(loc, var);
+ lbounds.push_back(builder.createConvert(loc, idxType, load));
+ }
+ }
}
if (box.isCharacter()) {
mlir::Value len = box.nonDeferredLenParams()[0];
if (box.hasRank())
- return fir::CharArrayBoxValue{addr, len, extents};
+ return fir::CharArrayBoxValue{addr, len, extents, lbounds};
return fir::CharBoxValue{addr, len};
}
if (box.isDerivedWithLenParameters())
TODO(loc, "get length parameters of derived type");
if (box.hasRank())
- return fir::ArrayBoxValue{addr, extents};
+ return fir::ArrayBoxValue{addr, extents, lbounds};
return addr;
};
@@ -3474,8 +3527,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 +3558,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 +3657,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 +3673,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 +3688,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 +3749,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 +3776,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 +3802,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 +3812,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 +3828,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 +3841,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 +3869,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 +3887,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 +3910,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 +3943,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 +3978,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 +3987,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 +4035,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 +4051,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 +4080,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 +4153,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 +4343,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 +4410,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 +4463,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 +4479,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 +4572,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 +4587,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 +4637,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 +4666,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 +4696,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 +4730,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 +4766,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 +4781,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 +4802,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 +4819,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 +4852,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 +4862,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 +4910,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 +5083,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 +5113,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 +5156,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 +5180,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 +5215,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 +5253,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 +5275,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 +5302,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 +5395,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 +5442,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 +5541,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 +5553,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 +5615,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 +5673,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 +5696,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 +5708,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 +5853,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 +5869,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 +5897,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 +5925,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 +5954,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 +5962,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 +5997,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 +6018,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 +6033,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 +6071,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 +6096,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 +6117,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 +6150,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 +6283,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 +6340,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 +6396,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 +6424,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 +6474,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 +6521,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 +6589,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 +6633,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 +6656,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 +6666,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 +6679,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 +6698,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 +6783,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 +6802,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 +6844,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 +6874,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 +6899,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 +6928,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 +6985,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 +7054,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 +7065,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 +7094,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 +7171,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 +7189,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 +7275,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 +7284,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 +7301,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 +7365,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 +7374,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 +7387,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 +7395,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 +7461,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 +7505,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 +7527,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 +7577,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 +7585,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 +7630,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 +7712,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 +7784,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 +7832,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 +7879,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 +7932,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 +7980,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 +8010,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 +8038,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 +8064,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 +8077,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 +8108,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,6 +8127,21 @@ 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 = mlir::arith::MulFOp::create(builder, loc, args[0], factor);
+ return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
+}
+
+// SINPI
+mlir::Value IntrinsicLibrary::genSinpi(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ 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);
return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
}
@@ -8100,14 +8186,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 +8204,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,6 +8224,21 @@ 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 = mlir::arith::MulFOp::create(builder, loc, args[0], factor);
+ return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
+}
+
+// TANPI
+mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::MLIRContext *context = builder.getContext();
+ mlir::FunctionType ftype =
+ mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
+ llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
+ 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);
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
}
@@ -8147,81 +8249,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 +8336,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 +8389,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 +8397,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 +8428,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 +8456,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 +8495,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 +8535,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 +8630,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 +8645,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 +8657,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 +8669,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 +8681,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 +8693,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 +8719,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 +8834,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 +8845,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 +8856,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 +8908,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 +8945,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 +9067,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 +9114,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 +9197,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 +9262,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 db12c84..03952da9 100644
--- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
@@ -1091,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
@@ -1118,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)
@@ -1128,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()) {
@@ -1159,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));
}
@@ -1189,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: {
@@ -1217,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;
}
@@ -1342,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);
}
@@ -1473,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;
}
@@ -1487,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;
@@ -1519,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");
@@ -1535,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;
}
@@ -1576,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) {
@@ -1585,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>(
@@ -1595,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);
}
@@ -1613,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);
}
@@ -1629,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()) {
@@ -1638,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)};
@@ -1662,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
@@ -1681,14 +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);
mlir::Value index = builder.createOrFold<mlir::index::CastUOp>(
loc, builder.getIndexType(), uremOp);
- return builder.create<mlir::vector::ExtractOp>(loc, varg0, index);
+ return mlir::vector::ExtractOp::create(builder, loc, varg0, index);
}
// VEC_INSERT
@@ -1704,7 +1705,7 @@ 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);
@@ -1712,8 +1713,8 @@ PPCIntrinsicLibrary::genVecInsert(mlir::Type resultType,
mlir::Value index = builder.createOrFold<mlir::index::CastUOp>(
loc, builder.getIndexType(), uremOp);
mlir::Value res =
- builder.create<mlir::vector::InsertOp>(loc, argBases[0], varg1, index);
- return builder.create<fir::ConvertOp>(loc, vecTyInfo.toFirVectorType(), res);
+ mlir::vector::InsertOp::create(builder, loc, argBases[0], varg1, index);
+ return fir::ConvertOp::create(builder, loc, vecTyInfo.toFirVectorType(), res);
}
// VEC_MERGEH, VEC_MERGEL
@@ -1799,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);
}
@@ -1812,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,
@@ -1826,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,
@@ -1876,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(
@@ -1970,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(
@@ -2003,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)};
@@ -2029,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(
@@ -2066,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");
@@ -2109,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(
@@ -2127,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);
}
@@ -2156,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
@@ -2188,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);
@@ -2217,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);
}
@@ -2269,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 ||
@@ -2286,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) {
@@ -2312,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);
@@ -2334,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();
}
@@ -2352,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
@@ -2389,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;
}
@@ -2398,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;
}
@@ -2409,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;
}
@@ -2438,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;
@@ -2795,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)};
@@ -2806,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)) {
@@ -2822,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) {
@@ -2831,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);
}
}
@@ -2901,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;
}
@@ -2911,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;
@@ -2922,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
@@ -2971,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();
@@ -2994,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 04703f7..4b4954a 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp
@@ -52,14 +52,14 @@ 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, mlir::ValueRange{})
+ return fir::CallOp::create(builder, loc, func, mlir::ValueRange{})
.getResult(0);
}
@@ -103,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,
@@ -117,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,
@@ -125,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,
@@ -140,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);
;
}
@@ -150,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,
@@ -158,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,
@@ -166,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,
@@ -187,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,
@@ -207,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,
@@ -224,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;
@@ -239,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) {
@@ -256,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
@@ -274,14 +274,14 @@ 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, mlir::ValueRange{})
+ return fir::CallOp::create(builder, loc, func, mlir::ValueRange{})
.getResult(0);
}
@@ -298,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
@@ -315,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
@@ -332,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)
@@ -348,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);
};
@@ -373,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)
@@ -398,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();
}
@@ -412,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
@@ -425,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 9b5e43b..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, mlir::ValueRange{});
+ 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/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index 69bdb48..61d6d2ae 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -180,8 +180,8 @@ public:
mlir::ValueRange inputs,
mlir::Location loc) {
assert(inputs.size() == 1);
- return builder.create<ConvertOp>(loc, unwrapRefType(type.getEleTy()),
- inputs[0]);
+ return ConvertOp::create(builder, loc, unwrapRefType(type.getEleTy()),
+ inputs[0]);
}
void setLocation(mlir::Location location) { loc = location; }
@@ -282,17 +282,17 @@ public:
// 32 bytes.
fir::SequenceType::Extent thunkSize = triple.getTrampolineSize();
mlir::Type buffTy = SequenceType::get({thunkSize}, i8Ty);
- auto buffer = builder.create<AllocaOp>(loc, buffTy);
+ auto buffer = AllocaOp::create(builder, loc, buffTy);
mlir::Value closure =
builder.createConvert(loc, i8Ptr, embox.getHost());
mlir::Value tramp = builder.createConvert(loc, i8Ptr, buffer);
mlir::Value func =
builder.createConvert(loc, i8Ptr, embox.getFunc());
- builder.create<fir::CallOp>(
- loc, factory::getLlvmInitTrampoline(builder),
+ fir::CallOp::create(
+ builder, loc, factory::getLlvmInitTrampoline(builder),
llvm::ArrayRef<mlir::Value>{tramp, func, closure});
- auto adjustCall = builder.create<fir::CallOp>(
- loc, factory::getLlvmAdjustTrampoline(builder),
+ auto adjustCall = fir::CallOp::create(
+ builder, loc, factory::getLlvmAdjustTrampoline(builder),
llvm::ArrayRef<mlir::Value>{tramp});
rewriter.replaceOpWithNewOp<ConvertOp>(embox, toTy,
adjustCall.getResult(0));
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 609ba27..1362a9f2 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -92,7 +92,7 @@ genConstantIndex(mlir::Location loc, mlir::Type ity,
mlir::ConversionPatternRewriter &rewriter,
std::int64_t offset) {
auto cattr = rewriter.getI64IntegerAttr(offset);
- return rewriter.create<mlir::LLVM::ConstantOp>(loc, ity, cattr);
+ return mlir::LLVM::ConstantOp::create(rewriter, loc, ity, cattr);
}
static mlir::Block *createBlock(mlir::ConversionPatternRewriter &rewriter,
@@ -148,27 +148,30 @@ mlir::Value replaceWithAddrOfOrASCast(mlir::ConversionPatternRewriter &rewriter,
mlir::Operation *replaceOp = nullptr) {
if (mlir::isa<mlir::LLVM::LLVMPointerType>(type)) {
if (globalAS != programAS) {
- auto llvmAddrOp = rewriter.create<mlir::LLVM::AddressOfOp>(
- loc, getLlvmPtrType(rewriter.getContext(), globalAS), symName);
+ auto llvmAddrOp = mlir::LLVM::AddressOfOp::create(
+ rewriter, loc, getLlvmPtrType(rewriter.getContext(), globalAS),
+ symName);
if (replaceOp)
return rewriter.replaceOpWithNewOp<mlir::LLVM::AddrSpaceCastOp>(
replaceOp, ::getLlvmPtrType(rewriter.getContext(), programAS),
llvmAddrOp);
- return rewriter.create<mlir::LLVM::AddrSpaceCastOp>(
- loc, getLlvmPtrType(rewriter.getContext(), programAS), llvmAddrOp);
+ return mlir::LLVM::AddrSpaceCastOp::create(
+ rewriter, loc, getLlvmPtrType(rewriter.getContext(), programAS),
+ llvmAddrOp);
}
if (replaceOp)
return rewriter.replaceOpWithNewOp<mlir::LLVM::AddressOfOp>(
replaceOp, getLlvmPtrType(rewriter.getContext(), globalAS), symName);
- return rewriter.create<mlir::LLVM::AddressOfOp>(
- loc, getLlvmPtrType(rewriter.getContext(), globalAS), symName);
+ return mlir::LLVM::AddressOfOp::create(
+ rewriter, loc, getLlvmPtrType(rewriter.getContext(), globalAS),
+ symName);
}
if (replaceOp)
return rewriter.replaceOpWithNewOp<mlir::LLVM::AddressOfOp>(replaceOp, type,
symName);
- return rewriter.create<mlir::LLVM::AddressOfOp>(loc, type, symName);
+ return mlir::LLVM::AddressOfOp::create(rewriter, loc, type, symName);
}
/// Lower `fir.address_of` operation to `llvm.address_of` operation.
@@ -250,8 +253,8 @@ public:
if (auto varAttr =
mlir::dyn_cast_or_null<mlir::LLVM::DILocalVariableAttr>(
fusedLoc.getMetadata())) {
- rewriter.create<mlir::LLVM::DbgDeclareOp>(memRef.getLoc(), memRef,
- varAttr, nullptr);
+ mlir::LLVM::DbgDeclareOp::create(rewriter, memRef.getLoc(), memRef,
+ varAttr, nullptr);
}
}
rewriter.replaceOp(declareOp, memRef);
@@ -294,8 +297,8 @@ struct AllocaOpConversion : public fir::FIROpConversion<fir::AllocaOp> {
emitError(loc, "did not find allocation function");
mlir::NamedAttribute attr = rewriter.getNamedAttr(
"callee", mlir::SymbolRefAttr::get(memSizeFn));
- auto call = rewriter.create<mlir::LLVM::CallOp>(
- loc, ity, lenParams,
+ auto call = mlir::LLVM::CallOp::create(
+ rewriter, loc, ity, lenParams,
addLLVMOpBundleAttrs(rewriter, {attr}, lenParams.size()));
size = call.getResult();
llvmObjectType = ::getI8Type(alloc.getContext());
@@ -339,9 +342,9 @@ struct AllocaOpConversion : public fir::FIROpConversion<fir::AllocaOp> {
// pointers! Only propagate pinned and bindc_name to help debugging, but
// this should have no functional purpose (and passing the operand segment
// attribute like before is certainly bad).
- auto llvmAlloc = rewriter.create<mlir::LLVM::AllocaOp>(
- loc, ::getLlvmPtrType(alloc.getContext(), allocaAs), llvmObjectType,
- size);
+ auto llvmAlloc = mlir::LLVM::AllocaOp::create(
+ rewriter, loc, ::getLlvmPtrType(alloc.getContext(), allocaAs),
+ llvmObjectType, size);
if (alloc.getPinned())
llvmAlloc->setDiscardableAttr(alloc.getPinnedAttrName(),
alloc.getPinnedAttr());
@@ -401,8 +404,8 @@ struct BoxCharLenOpConversion : public fir::FIROpConversion<fir::BoxCharLenOp> {
mlir::Type returnValTy = boxCharLen.getResult().getType();
constexpr int boxcharLenIdx = 1;
- auto len = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, boxChar,
- boxcharLenIdx);
+ auto len = mlir::LLVM::ExtractValueOp::create(rewriter, loc, boxChar,
+ boxcharLenIdx);
mlir::Value lenAfterCast = integerCast(loc, rewriter, returnValTy, len);
rewriter.replaceOp(boxCharLen, lenAfterCast);
@@ -597,9 +600,9 @@ struct StringLitOpConversion : public fir::FIROpConversion<fir::StringLitOp> {
unsigned bits = lowerTy().characterBitsize(charTy);
mlir::Type intTy = rewriter.getIntegerType(bits);
mlir::Location loc = constop.getLoc();
- mlir::Value cst = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
+ mlir::Value cst = mlir::LLVM::UndefOp::create(rewriter, loc, ty);
if (auto arr = mlir::dyn_cast<mlir::DenseElementsAttr>(attr)) {
- cst = rewriter.create<mlir::LLVM::ConstantOp>(loc, ty, arr);
+ cst = mlir::LLVM::ConstantOp::create(rewriter, loc, ty, arr);
} else if (auto arr = mlir::dyn_cast<mlir::ArrayAttr>(attr)) {
for (auto a : llvm::enumerate(arr.getValue())) {
// convert each character to a precise bitsize
@@ -608,9 +611,9 @@ struct StringLitOpConversion : public fir::FIROpConversion<fir::StringLitOp> {
mlir::cast<mlir::IntegerAttr>(a.value()).getValue().zextOrTrunc(
bits));
auto elemCst =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, intTy, elemAttr);
- cst = rewriter.create<mlir::LLVM::InsertValueOp>(loc, cst, elemCst,
- a.index());
+ mlir::LLVM::ConstantOp::create(rewriter, loc, intTy, elemAttr);
+ cst = mlir::LLVM::InsertValueOp::create(rewriter, loc, cst, elemCst,
+ a.index());
}
} else {
return mlir::failure();
@@ -706,14 +709,14 @@ struct CmpcOpConversion : public fir::FIROpConversion<fir::CmpcOp> {
mlir::arith::convertArithFastMathFlagsToLLVM(cmp.getFastmath());
mlir::LLVM::FCmpPredicate pred =
static_cast<mlir::LLVM::FCmpPredicate>(cmp.getPredicate());
- auto rcp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, resTy, pred,
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, operands[0], 0),
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, operands[1], 0), fmf);
- auto icp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, resTy, pred,
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, operands[0], 1),
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, operands[1], 1), fmf);
+ auto rcp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, resTy, pred,
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, operands[0], 0),
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, operands[1], 0), fmf);
+ auto icp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, resTy, pred,
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, operands[0], 1),
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, operands[1], 1), fmf);
llvm::SmallVector<mlir::Value, 2> cp = {rcp, icp};
switch (cmp.getPredicate()) {
case mlir::arith::CmpFPredicate::OEQ: // .EQ.
@@ -778,16 +781,16 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
"incompatible record types");
auto toStTy = mlir::cast<mlir::LLVM::LLVMStructType>(toTy);
- mlir::Value val = rewriter.create<mlir::LLVM::UndefOp>(loc, toStTy);
+ mlir::Value val = mlir::LLVM::UndefOp::create(rewriter, loc, toStTy);
auto indexTypeMap = toStTy.getSubelementIndexMap();
assert(indexTypeMap.has_value() && "invalid record type");
for (auto [attr, type] : indexTypeMap.value()) {
int64_t index = mlir::cast<mlir::IntegerAttr>(attr).getInt();
auto extVal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, op0, index);
- val =
- rewriter.create<mlir::LLVM::InsertValueOp>(loc, val, extVal, index);
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, op0, index);
+ val = mlir::LLVM::InsertValueOp::create(rewriter, loc, val, extVal,
+ index);
}
rewriter.replaceOp(convert, val);
@@ -831,8 +834,8 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
// Compare the input with zero.
mlir::Value zero = genConstantIndex(loc, fromTy, rewriter, 0);
- auto isTrue = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::ne, op0, zero);
+ auto isTrue = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::ne, op0, zero);
// Zero extend the i1 isTrue result to the required type (unless it is i1
// itself).
@@ -859,23 +862,24 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
return {};
}
if (fromBits > toBits)
- return rewriter.create<mlir::LLVM::FPTruncOp>(loc, toTy, val);
- return rewriter.create<mlir::LLVM::FPExtOp>(loc, toTy, val);
+ return mlir::LLVM::FPTruncOp::create(rewriter, loc, toTy, val);
+ return mlir::LLVM::FPExtOp::create(rewriter, loc, toTy, val);
};
// Complex to complex conversion.
if (fir::isa_complex(fromFirTy) && fir::isa_complex(toFirTy)) {
// Special case: handle the conversion of a complex such that both the
// real and imaginary parts are converted together.
auto ty = convertType(getComplexEleTy(convert.getValue().getType()));
- auto rp = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, op0, 0);
- auto ip = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, op0, 1);
+ auto rp = mlir::LLVM::ExtractValueOp::create(rewriter, loc, op0, 0);
+ auto ip = mlir::LLVM::ExtractValueOp::create(rewriter, loc, op0, 1);
auto nt = convertType(getComplexEleTy(convert.getRes().getType()));
auto fromBits = mlir::LLVM::getPrimitiveTypeSizeInBits(ty);
auto toBits = mlir::LLVM::getPrimitiveTypeSizeInBits(nt);
auto rc = convertFpToFp(rp, fromBits, toBits, nt);
auto ic = convertFpToFp(ip, fromBits, toBits, nt);
- auto un = rewriter.create<mlir::LLVM::UndefOp>(loc, toTy);
- auto i1 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, un, rc, 0);
+ auto un = mlir::LLVM::UndefOp::create(rewriter, loc, toTy);
+ llvm::SmallVector<int64_t> pos{0};
+ auto i1 = mlir::LLVM::InsertValueOp::create(rewriter, loc, un, rc, pos);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(convert, i1, ic,
1);
return mlir::success();
@@ -1023,7 +1027,7 @@ struct EmboxCharOpConversion : public fir::FIROpConversion<fir::EmboxCharOp> {
mlir::Location loc = emboxChar.getLoc();
mlir::Type llvmStructTy = convertType(emboxChar.getType());
- auto llvmStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmStructTy);
+ auto llvmStruct = mlir::LLVM::UndefOp::create(rewriter, loc, llvmStructTy);
mlir::Type lenTy =
mlir::cast<mlir::LLVM::LLVMStructType>(llvmStructTy).getBody()[1];
@@ -1033,10 +1037,11 @@ struct EmboxCharOpConversion : public fir::FIROpConversion<fir::EmboxCharOp> {
mlir::cast<mlir::LLVM::LLVMStructType>(llvmStructTy).getBody()[0];
if (addrTy != charBuffer.getType())
charBuffer =
- rewriter.create<mlir::LLVM::BitcastOp>(loc, addrTy, charBuffer);
+ mlir::LLVM::BitcastOp::create(rewriter, loc, addrTy, charBuffer);
- auto insertBufferOp = rewriter.create<mlir::LLVM::InsertValueOp>(
- loc, llvmStruct, charBuffer, 0);
+ llvm::SmallVector<int64_t> pos{0};
+ auto insertBufferOp = mlir::LLVM::InsertValueOp::create(
+ rewriter, loc, llvmStruct, charBuffer, pos);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
emboxChar, insertBufferOp, lenAfterCast, 1);
@@ -1059,8 +1064,8 @@ getMallocInModule(ModuleOp mod, fir::AllocMemOp op,
return mlir::SymbolRefAttr::get(userMalloc);
mlir::OpBuilder moduleBuilder(mod.getBodyRegion());
- auto mallocDecl = moduleBuilder.create<mlir::LLVM::LLVMFuncOp>(
- op.getLoc(), mallocName,
+ auto mallocDecl = mlir::LLVM::LLVMFuncOp::create(
+ moduleBuilder, op.getLoc(), mallocName,
mlir::LLVM::LLVMFunctionType::get(getLlvmPtrType(op.getContext()),
indexType,
/*isVarArg=*/false));
@@ -1120,19 +1125,19 @@ struct AllocMemOpConversion : public fir::FIROpConversion<fir::AllocMemOp> {
TODO(loc, "fir.allocmem codegen of derived type with length parameters");
mlir::Value size = genTypeSizeInBytes(loc, ity, rewriter, llvmObjectTy);
if (auto scaleSize = genAllocationScaleSize(heap, ity, rewriter))
- size = rewriter.create<mlir::LLVM::MulOp>(loc, ity, size, scaleSize);
+ size = mlir::LLVM::MulOp::create(rewriter, loc, ity, size, scaleSize);
for (mlir::Value opnd : adaptor.getOperands())
- size = rewriter.create<mlir::LLVM::MulOp>(
- loc, ity, size, integerCast(loc, rewriter, ity, opnd));
+ size = mlir::LLVM::MulOp::create(rewriter, loc, ity, size,
+ integerCast(loc, rewriter, ity, opnd));
// As the return value of malloc(0) is implementation defined, allocate one
// byte to ensure the allocation status being true. This behavior aligns to
// what the runtime has.
mlir::Value zero = genConstantIndex(loc, ity, rewriter, 0);
mlir::Value one = genConstantIndex(loc, ity, rewriter, 1);
- mlir::Value cmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sgt, size, zero);
- size = rewriter.create<mlir::LLVM::SelectOp>(loc, cmp, size, one);
+ mlir::Value cmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::sgt, size, zero);
+ size = mlir::LLVM::SelectOp::create(rewriter, loc, cmp, size, one);
auto mallocTyWidth = lowerTy().getIndexTypeBitwidth();
auto mallocTy =
@@ -1173,8 +1178,8 @@ getFreeInModule(ModuleOp mod, fir::FreeMemOp op,
// Create llvm declaration for free.
mlir::OpBuilder moduleBuilder(mod.getBodyRegion());
auto voidType = mlir::LLVM::LLVMVoidType::get(op.getContext());
- auto freeDecl = moduleBuilder.create<mlir::LLVM::LLVMFuncOp>(
- rewriter.getUnknownLoc(), freeName,
+ auto freeDecl = mlir::LLVM::LLVMFuncOp::create(
+ moduleBuilder, rewriter.getUnknownLoc(), freeName,
mlir::LLVM::LLVMFunctionType::get(voidType,
getLlvmPtrType(op.getContext()),
/*isVarArg=*/false));
@@ -1209,8 +1214,9 @@ struct FreeMemOpConversion : public fir::FIROpConversion<fir::FreeMemOp> {
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Location loc = freemem.getLoc();
freemem->setAttr("callee", getFree(freemem, rewriter));
- rewriter.create<mlir::LLVM::CallOp>(
- loc, mlir::TypeRange{}, mlir::ValueRange{adaptor.getHeapref()},
+ mlir::LLVM::CallOp::create(
+ rewriter, loc, mlir::TypeRange{},
+ mlir::ValueRange{adaptor.getHeapref()},
addLLVMOpBundleAttrs(rewriter, freemem->getAttrs(), 1));
rewriter.eraseOp(freemem);
return mlir::success();
@@ -1265,38 +1271,39 @@ static mlir::Value genSourceFile(mlir::Location loc, mlir::ModuleOp mod,
std::string globalName = fir::factory::uniqueCGIdent("cl", fn);
if (auto g = mod.lookupSymbol<fir::GlobalOp>(globalName)) {
- return rewriter.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, g.getName());
+ return mlir::LLVM::AddressOfOp::create(rewriter, loc, ptrTy, g.getName());
} else if (auto g = mod.lookupSymbol<mlir::LLVM::GlobalOp>(globalName)) {
- return rewriter.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, g.getName());
+ return mlir::LLVM::AddressOfOp::create(rewriter, loc, ptrTy, g.getName());
}
auto crtInsPt = rewriter.saveInsertionPoint();
rewriter.setInsertionPoint(mod.getBody(), mod.getBody()->end());
auto arrayTy = mlir::LLVM::LLVMArrayType::get(
mlir::IntegerType::get(rewriter.getContext(), 8), fn.size());
- mlir::LLVM::GlobalOp globalOp = rewriter.create<mlir::LLVM::GlobalOp>(
- loc, arrayTy, /*constant=*/true, mlir::LLVM::Linkage::Linkonce,
- globalName, mlir::Attribute());
+ mlir::LLVM::GlobalOp globalOp = mlir::LLVM::GlobalOp::create(
+ rewriter, loc, arrayTy, /*constant=*/true,
+ mlir::LLVM::Linkage::Linkonce, globalName, mlir::Attribute());
mlir::Region &region = globalOp.getInitializerRegion();
mlir::Block *block = rewriter.createBlock(&region);
rewriter.setInsertionPoint(block, block->begin());
- mlir::Value constValue = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, arrayTy, rewriter.getStringAttr(fn));
- rewriter.create<mlir::LLVM::ReturnOp>(loc, constValue);
+ mlir::Value constValue = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, arrayTy, rewriter.getStringAttr(fn));
+ mlir::LLVM::ReturnOp::create(rewriter, loc, constValue);
rewriter.restoreInsertionPoint(crtInsPt);
- return rewriter.create<mlir::LLVM::AddressOfOp>(loc, ptrTy,
- globalOp.getName());
+ return mlir::LLVM::AddressOfOp::create(rewriter, loc, ptrTy,
+ globalOp.getName());
}
- return rewriter.create<mlir::LLVM::ZeroOp>(loc, ptrTy);
+ return mlir::LLVM::ZeroOp::create(rewriter, loc, ptrTy);
}
static mlir::Value genSourceLine(mlir::Location loc,
mlir::ConversionPatternRewriter &rewriter) {
if (auto flc = mlir::dyn_cast<mlir::FileLineColLoc>(loc))
- return rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI32Type(),
- flc.getLine());
- return rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI32Type(), 0);
+ return mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI32Type(),
+ flc.getLine());
+ return mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI32Type(),
+ 0);
}
static mlir::Value
@@ -1373,7 +1380,7 @@ getTypeDescriptor(ModOpTy mod, mlir::ConversionPatternRewriter &rewriter,
if (options.ignoreMissingTypeDescriptors ||
fir::NameUniquer::belongsToModule(
name, Fortran::semantics::typeInfoBuiltinModule))
- return rewriter.create<mlir::LLVM::ZeroOp>(loc, llvmPtrTy);
+ return mlir::LLVM::ZeroOp::create(rewriter, loc, llvmPtrTy);
if (!options.skipExternalRttiDefinition)
fir::emitFatalError(loc,
@@ -1386,12 +1393,12 @@ getTypeDescriptor(ModOpTy mod, mlir::ConversionPatternRewriter &rewriter,
// option. Generate the object declaration now.
auto insertPt = rewriter.saveInsertionPoint();
rewriter.setInsertionPoint(mod.getBody(), mod.getBody()->end());
- mlir::LLVM::GlobalOp global = rewriter.create<mlir::LLVM::GlobalOp>(
- loc, llvmPtrTy, /*constant=*/true, mlir::LLVM::Linkage::External, name,
- mlir::Attribute());
+ mlir::LLVM::GlobalOp global = mlir::LLVM::GlobalOp::create(
+ rewriter, loc, llvmPtrTy, /*constant=*/true,
+ mlir::LLVM::Linkage::External, name, mlir::Attribute());
rewriter.restoreInsertionPoint(insertPt);
- return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy,
- global.getSymName());
+ return mlir::LLVM::AddressOfOp::create(rewriter, loc, llvmPtrTy,
+ global.getSymName());
}
/// Common base class for embox to descriptor conversion.
@@ -1422,7 +1429,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
assert(!lenParams.empty());
auto len64 = fir::FIROpConversion<OP>::integerCast(loc, rewriter, i64Ty,
lenParams.back());
- return rewriter.create<mlir::LLVM::MulOp>(loc, i64Ty, size, len64);
+ return mlir::LLVM::MulOp::create(rewriter, loc, i64Ty, size, len64);
}
// Get the element size and CFI type code of the boxed value.
@@ -1437,7 +1444,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
return getSizeAndTypeCode(loc, rewriter, seqTy.getEleTy(), lenParams);
if (mlir::isa<mlir::NoneType>(
boxEleTy)) // unlimited polymorphic or assumed type
- return {rewriter.create<mlir::LLVM::ConstantOp>(loc, i64Ty, 0),
+ return {mlir::LLVM::ConstantOp::create(rewriter, loc, i64Ty, 0),
this->genConstantOffset(loc, rewriter, CFI_type_other)};
mlir::Value typeCodeVal = this->genConstantOffset(
loc, rewriter,
@@ -1473,8 +1480,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
if (!bitcast)
value = this->integerCast(loc, rewriter, fldTy, value);
// bitcast are no-ops with LLVM opaque pointers.
- return rewriter.create<mlir::LLVM::InsertValueOp>(loc, dest, value,
- fldIndexes);
+ return mlir::LLVM::InsertValueOp::create(rewriter, loc, dest, value,
+ fldIndexes);
}
inline mlir::Value
@@ -1518,7 +1525,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
bool isUnlimitedPolymorphic = fir::isUnlimitedPolymorphicType(boxTy);
bool useInputType = fir::isPolymorphicType(boxTy) || isUnlimitedPolymorphic;
mlir::Value descriptor =
- rewriter.create<mlir::LLVM::UndefOp>(loc, llvmBoxTy);
+ mlir::LLVM::UndefOp::create(rewriter, loc, llvmBoxTy);
descriptor =
insertField(rewriter, loc, descriptor, {kElemLenPosInBox}, eleSize);
descriptor = insertField(rewriter, loc, descriptor, {kVersionPosInBox},
@@ -1539,16 +1546,16 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
auto maskAttr = mlir::IntegerAttr::get(
rewriter.getIntegerType(8, /*isSigned=*/false),
llvm::APInt(8, (uint64_t)_CFI_ADDENDUM_FLAG, /*isSigned=*/false));
- mlir::LLVM::ConstantOp mask = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, rewriter.getI8Type(), maskAttr);
- extraField = rewriter.create<mlir::LLVM::OrOp>(loc, extraField, mask);
+ mlir::LLVM::ConstantOp mask = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, rewriter.getI8Type(), maskAttr);
+ extraField = mlir::LLVM::OrOp::create(rewriter, loc, extraField, mask);
} else {
auto maskAttr = mlir::IntegerAttr::get(
rewriter.getIntegerType(8, /*isSigned=*/false),
llvm::APInt(8, (uint64_t)~_CFI_ADDENDUM_FLAG, /*isSigned=*/true));
- mlir::LLVM::ConstantOp mask = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, rewriter.getI8Type(), maskAttr);
- extraField = rewriter.create<mlir::LLVM::AndOp>(loc, extraField, mask);
+ mlir::LLVM::ConstantOp mask = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, rewriter.getI8Type(), maskAttr);
+ extraField = mlir::LLVM::AndOp::create(rewriter, loc, extraField, mask);
}
// Extra field value is provided so just use it.
descriptor =
@@ -1575,8 +1582,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
} else {
// Unlimited polymorphic type descriptor with no record type. Set
// type descriptor address to a clean state.
- typeDesc = rewriter.create<mlir::LLVM::ZeroOp>(
- loc, ::getLlvmPtrType(mod.getContext()));
+ typeDesc = mlir::LLVM::ZeroOp::create(
+ rewriter, loc, ::getLlvmPtrType(mod.getContext()));
}
} else {
typeDesc = getTypeDescriptor(
@@ -1756,13 +1763,14 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
mlir::Value cast =
this->integerCast(loc, rewriter, outterOffsetTy, *substringOffset);
- gepArgs[0] = rewriter.create<mlir::LLVM::AddOp>(
- loc, outterOffsetTy, llvm::cast<mlir::Value>(gepArgs[0]), cast);
+ gepArgs[0] = mlir::LLVM::AddOp::create(
+ rewriter, loc, outterOffsetTy, llvm::cast<mlir::Value>(gepArgs[0]),
+ cast);
}
}
mlir::Type llvmPtrTy = ::getLlvmPtrType(resultTy.getContext());
- return rewriter.create<mlir::LLVM::GEPOp>(
- loc, llvmPtrTy, llvmBaseObjectType, base, gepArgs);
+ return mlir::LLVM::GEPOp::create(rewriter, loc, llvmPtrTy,
+ llvmBaseObjectType, base, gepArgs);
}
template <typename BOX>
@@ -1809,7 +1817,8 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
storage = this->genAllocaAndAddrCastWithType(loc, llvmBoxTy, defaultAlign,
rewriter);
}
- auto storeOp = rewriter.create<mlir::LLVM::StoreOp>(loc, boxValue, storage);
+ auto storeOp =
+ mlir::LLVM::StoreOp::create(rewriter, loc, boxValue, storage);
this->attachTBAATag(storeOp, boxTy, boxTy, nullptr);
return storage;
}
@@ -1823,14 +1832,14 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
ub = this->integerCast(loc, rewriter, type, ub);
step = this->integerCast(loc, rewriter, type, step);
zero = this->integerCast(loc, rewriter, type, zero);
- mlir::Value extent = rewriter.create<mlir::LLVM::SubOp>(loc, type, ub, lb);
- extent = rewriter.create<mlir::LLVM::AddOp>(loc, type, extent, step);
- extent = rewriter.create<mlir::LLVM::SDivOp>(loc, type, extent, step);
+ mlir::Value extent = mlir::LLVM::SubOp::create(rewriter, loc, type, ub, lb);
+ extent = mlir::LLVM::AddOp::create(rewriter, loc, type, extent, step);
+ extent = mlir::LLVM::SDivOp::create(rewriter, loc, type, extent, step);
// If the resulting extent is negative (`ub-lb` and `step` have different
// signs), zero must be returned instead.
- auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sgt, extent, zero);
- return rewriter.create<mlir::LLVM::SelectOp>(loc, cmp, extent, zero);
+ auto cmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::sgt, extent, zero);
+ return mlir::LLVM::SelectOp::create(rewriter, loc, cmp, extent, zero);
}
};
@@ -2005,14 +2014,14 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
mlir::Value adj = one;
if (hasShift)
adj = integerCast(loc, rewriter, i64Ty, operands[shiftOffset]);
- auto ao = rewriter.create<mlir::LLVM::SubOp>(loc, i64Ty, off, adj);
+ auto ao = mlir::LLVM::SubOp::create(rewriter, loc, i64Ty, off, adj);
if (constRows > 0) {
cstInteriorIndices.push_back(ao);
} else {
auto dimOff =
- rewriter.create<mlir::LLVM::MulOp>(loc, i64Ty, ao, prevPtrOff);
- ptrOffset =
- rewriter.create<mlir::LLVM::AddOp>(loc, i64Ty, dimOff, ptrOffset);
+ mlir::LLVM::MulOp::create(rewriter, loc, i64Ty, ao, prevPtrOff);
+ ptrOffset = mlir::LLVM::AddOp::create(rewriter, loc, i64Ty, dimOff,
+ ptrOffset);
}
if (mlir::isa_and_nonnull<fir::UndefOp>(
xbox.getSlice()[3 * di + 1].getDefiningOp())) {
@@ -2042,10 +2051,10 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
if (hasShift && !(hasSlice || hasSubcomp || hasSubstr) &&
(isaPointerOrAllocatable || !normalizedLowerBound(xbox))) {
lb = integerCast(loc, rewriter, i64Ty, operands[shiftOffset]);
- auto extentIsEmpty = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, extent, zero);
- lb = rewriter.create<mlir::LLVM::SelectOp>(loc, extentIsEmpty, one,
- lb);
+ auto extentIsEmpty = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::eq, extent, zero);
+ lb = mlir::LLVM::SelectOp::create(rewriter, loc, extentIsEmpty, one,
+ lb);
}
dest = insertLowerBound(rewriter, loc, dest, descIdx, lb);
@@ -2057,18 +2066,18 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
mlir::Value sliceStep =
integerCast(loc, rewriter, i64Ty, operands[sliceOffset + 2]);
step =
- rewriter.create<mlir::LLVM::MulOp>(loc, i64Ty, step, sliceStep);
+ mlir::LLVM::MulOp::create(rewriter, loc, i64Ty, step, sliceStep);
}
dest = insertStride(rewriter, loc, dest, descIdx, step);
++descIdx;
}
// compute the stride and offset for the next natural dimension
- prevDimByteStride = rewriter.create<mlir::LLVM::MulOp>(
- loc, i64Ty, prevDimByteStride, outerExtent);
+ prevDimByteStride = mlir::LLVM::MulOp::create(
+ rewriter, loc, i64Ty, prevDimByteStride, outerExtent);
if (constRows == 0)
- prevPtrOff = rewriter.create<mlir::LLVM::MulOp>(loc, i64Ty, prevPtrOff,
- outerExtent);
+ prevPtrOff = mlir::LLVM::MulOp::create(rewriter, loc, i64Ty, prevPtrOff,
+ outerExtent);
else
--constRows;
@@ -2153,7 +2162,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
"character target in global op must have constant length");
mlir::Value width =
genConstantIndex(loc, idxTy, rewriter, charTy.getFKind());
- len = rewriter.create<mlir::LLVM::SDivOp>(loc, idxTy, len, width);
+ len = mlir::LLVM::SDivOp::create(rewriter, loc, idxTy, len, width);
}
lenParams.emplace_back(len);
}
@@ -2214,9 +2223,10 @@ private:
mlir::Value lb = one;
if (!lbounds.empty()) {
lb = integerCast(loc, rewriter, lowerTy().indexType(), lbounds[dim]);
- auto extentIsEmpty = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, extent, zero);
- lb = rewriter.create<mlir::LLVM::SelectOp>(loc, extentIsEmpty, one, lb);
+ auto extentIsEmpty = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::eq, extent, zero);
+ lb =
+ mlir::LLVM::SelectOp::create(rewriter, loc, extentIsEmpty, one, lb);
};
dest = insertLowerBound(rewriter, loc, dest, dim, lb);
dest = insertExtent(rewriter, loc, dest, dim, extent);
@@ -2284,9 +2294,9 @@ private:
? integerCast(loc, rewriter, idxTy, operands[shiftOps])
: one;
mlir::Value diff =
- rewriter.create<mlir::LLVM::SubOp>(loc, idxTy, sliceLb, sliceOrigin);
+ mlir::LLVM::SubOp::create(rewriter, loc, idxTy, sliceLb, sliceOrigin);
mlir::Value offset =
- rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, diff, inputStride);
+ mlir::LLVM::MulOp::create(rewriter, loc, idxTy, diff, inputStride);
// Strides from the fir.box are in bytes.
base = genGEP(loc, byteTy, rewriter, base, offset);
// Apply upper bound and step if this is a triplet. Otherwise, the
@@ -2304,7 +2314,7 @@ private:
slicedExtents.emplace_back(extent);
// stride = step*input_stride
mlir::Value stride =
- rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, step, inputStride);
+ mlir::LLVM::MulOp::create(rewriter, loc, idxTy, step, inputStride);
slicedStrides.emplace_back(stride);
}
}
@@ -2348,7 +2358,7 @@ private:
newExtents.emplace_back(extent);
newStrides.emplace_back(stride);
// nextStride = extent * stride;
- stride = rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, extent, stride);
+ stride = mlir::LLVM::MulOp::create(rewriter, loc, idxTy, extent, stride);
}
return finalizeRebox(rebox, adaptor, destBoxTy, dest, base, reboxShifts,
newExtents, newStrides, rewriter);
@@ -2536,8 +2546,8 @@ struct InsertOnRangeOpConversion
mlir::Value insertVal = adaptor.getVal();
while (subscripts != uBounds) {
- lastOp = rewriter.create<mlir::LLVM::InsertValueOp>(
- loc, lastOp, insertVal, subscripts);
+ lastOp = mlir::LLVM::InsertValueOp::create(rewriter, loc, lastOp,
+ insertVal, subscripts);
incrementSubscripts(dims, subscripts);
}
@@ -2606,15 +2616,16 @@ struct XArrayCoorOpConversion
if (normalSlice)
step = integerCast(loc, rewriter, idxTy, operands[sliceOffset + 2]);
}
- auto idx = rewriter.create<mlir::LLVM::SubOp>(loc, idxTy, index, lb, nsw);
+ auto idx =
+ mlir::LLVM::SubOp::create(rewriter, loc, idxTy, index, lb, nsw);
mlir::Value diff =
- rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, idx, step, nsw);
+ mlir::LLVM::MulOp::create(rewriter, loc, idxTy, idx, step, nsw);
if (normalSlice) {
mlir::Value sliceLb =
integerCast(loc, rewriter, idxTy, operands[sliceOffset]);
auto adj =
- rewriter.create<mlir::LLVM::SubOp>(loc, idxTy, sliceLb, lb, nsw);
- diff = rewriter.create<mlir::LLVM::AddOp>(loc, idxTy, diff, adj, nsw);
+ mlir::LLVM::SubOp::create(rewriter, loc, idxTy, sliceLb, lb, nsw);
+ diff = mlir::LLVM::AddOp::create(rewriter, loc, idxTy, diff, adj, nsw);
}
// Update the offset given the stride and the zero based index `diff`
// that was just computed.
@@ -2623,20 +2634,20 @@ struct XArrayCoorOpConversion
mlir::Value stride =
getStrideFromBox(loc, baseBoxTyPair, operands[0], i, rewriter);
auto sc =
- rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, diff, stride, nsw);
+ mlir::LLVM::MulOp::create(rewriter, loc, idxTy, diff, stride, nsw);
offset =
- rewriter.create<mlir::LLVM::AddOp>(loc, idxTy, sc, offset, nsw);
+ mlir::LLVM::AddOp::create(rewriter, loc, idxTy, sc, offset, nsw);
} else {
// Use stride computed at last iteration.
auto sc =
- rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, diff, prevExt, nsw);
+ mlir::LLVM::MulOp::create(rewriter, loc, idxTy, diff, prevExt, nsw);
offset =
- rewriter.create<mlir::LLVM::AddOp>(loc, idxTy, sc, offset, nsw);
+ mlir::LLVM::AddOp::create(rewriter, loc, idxTy, sc, offset, nsw);
// Compute next stride assuming contiguity of the base array
// (in element number).
auto nextExt = integerCast(loc, rewriter, idxTy, operands[shapeOffset]);
- prevExt = rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, prevExt,
- nextExt, nsw);
+ prevExt = mlir::LLVM::MulOp::create(rewriter, loc, idxTy, prevExt,
+ nextExt, nsw);
}
}
@@ -2648,8 +2659,8 @@ struct XArrayCoorOpConversion
mlir::Value base =
getBaseAddrFromBox(loc, baseBoxTyPair, operands[0], rewriter);
llvm::SmallVector<mlir::LLVM::GEPArg> args{offset};
- auto addr = rewriter.create<mlir::LLVM::GEPOp>(loc, llvmPtrTy, byteTy,
- base, args);
+ auto addr = mlir::LLVM::GEPOp::create(rewriter, loc, llvmPtrTy, byteTy,
+ base, args);
if (coor.getSubcomponent().empty()) {
rewriter.replaceOp(coor, addr);
return mlir::success();
@@ -2696,8 +2707,8 @@ struct XArrayCoorOpConversion
assert(coor.getLenParams().size() == 1);
auto length = integerCast(loc, rewriter, idxTy,
operands[coor.getLenParamsOperandIndex()]);
- offset = rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, offset,
- length, nsw);
+ offset = mlir::LLVM::MulOp::create(rewriter, loc, idxTy, offset,
+ length, nsw);
} else {
TODO(loc, "compute size of derived type with type parameters");
}
@@ -2912,13 +2923,14 @@ private:
for (unsigned dim = 0; dim < arrayDim && it != end; ++dim, ++it) {
mlir::Value stride =
getStrideFromBox(loc, boxTyPair, operands[0], dim, rewriter);
- auto sc = rewriter.create<mlir::LLVM::MulOp>(
- loc, idxTy, operands[nextIndexValue + dim], stride, nsw);
- off = rewriter.create<mlir::LLVM::AddOp>(loc, idxTy, sc, off, nsw);
+ auto sc = mlir::LLVM::MulOp::create(rewriter, loc, idxTy,
+ operands[nextIndexValue + dim],
+ stride, nsw);
+ off = mlir::LLVM::AddOp::create(rewriter, loc, idxTy, sc, off, nsw);
}
nextIndexValue += arrayDim;
- resultAddr = rewriter.create<mlir::LLVM::GEPOp>(
- loc, llvmPtrTy, byteTy, resultAddr,
+ resultAddr = mlir::LLVM::GEPOp::create(
+ rewriter, loc, llvmPtrTy, byteTy, resultAddr,
llvm::ArrayRef<mlir::LLVM::GEPArg>{off});
cpnTy = arrTy.getEleTy();
} else if (auto recTy = mlir::dyn_cast<fir::RecordType>(cpnTy)) {
@@ -2930,8 +2942,8 @@ private:
++it;
cpnTy = recTy.getType(fieldIndex);
auto llvmRecTy = lowerTy().convertType(recTy);
- resultAddr = rewriter.create<mlir::LLVM::GEPOp>(
- loc, llvmPtrTy, llvmRecTy, resultAddr,
+ resultAddr = mlir::LLVM::GEPOp::create(
+ rewriter, loc, llvmPtrTy, llvmRecTy, resultAddr,
llvm::ArrayRef<mlir::LLVM::GEPArg>{0, fieldIndex});
} else {
fir::emitFatalError(loc, "unexpected type in coordinate_of");
@@ -3184,9 +3196,10 @@ struct GlobalOpConversion : public fir::FIROpConversion<fir::GlobalOp> {
auto isConst = global.getConstant().has_value();
mlir::SymbolRefAttr comdat;
llvm::ArrayRef<mlir::NamedAttribute> attrs;
- auto g = rewriter.create<mlir::LLVM::GlobalOp>(
- loc, tyAttr, isConst, linkage, global.getSymName(), initAttr, 0,
- getGlobalAddressSpace(rewriter), false, false, comdat, attrs, dbgExprs);
+ auto g = mlir::LLVM::GlobalOp::create(
+ rewriter, loc, tyAttr, isConst, linkage, global.getSymName(), initAttr,
+ 0, getGlobalAddressSpace(rewriter), false, false, comdat, attrs,
+ dbgExprs);
if (global.getAlignment() && *global.getAlignment() > 0)
g.setAlignment(*global.getAlignment());
@@ -3276,15 +3289,15 @@ private:
module.lookupSymbol<mlir::LLVM::ComdatOp>(comdatName);
if (!comdatOp) {
comdatOp =
- rewriter.create<mlir::LLVM::ComdatOp>(module.getLoc(), comdatName);
+ mlir::LLVM::ComdatOp::create(rewriter, module.getLoc(), comdatName);
}
if (auto select = comdatOp.lookupSymbol<mlir::LLVM::ComdatSelectorOp>(
global.getSymName()))
return;
mlir::OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPointToEnd(&comdatOp.getBody().back());
- auto selectorOp = rewriter.create<mlir::LLVM::ComdatSelectorOp>(
- comdatOp.getLoc(), global.getSymName(),
+ auto selectorOp = mlir::LLVM::ComdatSelectorOp::create(
+ rewriter, comdatOp.getLoc(), global.getSymName(),
mlir::LLVM::comdat::Comdat::Any);
global.setComdatAttr(mlir::SymbolRefAttr::get(
rewriter.getContext(), comdatName,
@@ -3331,8 +3344,8 @@ struct LoadOpConversion : public fir::FIROpConversion<fir::LoadOp> {
TypePair boxTypePair{boxTy, llvmLoadTy};
mlir::Value boxSize =
computeBoxSize(loc, boxTypePair, inputBoxStorage, rewriter);
- auto memcpy = rewriter.create<mlir::LLVM::MemcpyOp>(
- loc, newBoxStorage, inputBoxStorage, boxSize, isVolatile);
+ auto memcpy = mlir::LLVM::MemcpyOp::create(
+ rewriter, loc, newBoxStorage, inputBoxStorage, boxSize, isVolatile);
if (std::optional<mlir::ArrayAttr> optionalTag = load.getTbaa())
memcpy.setTBAATags(*optionalTag);
@@ -3340,8 +3353,9 @@ struct LoadOpConversion : public fir::FIROpConversion<fir::LoadOp> {
attachTBAATag(memcpy, boxTy, boxTy, nullptr);
rewriter.replaceOp(load, newBoxStorage);
} else {
- mlir::LLVM::LoadOp loadOp = rewriter.create<mlir::LLVM::LoadOp>(
- load.getLoc(), llvmLoadTy, adaptor.getOperands(), load->getAttrs());
+ mlir::LLVM::LoadOp loadOp =
+ mlir::LLVM::LoadOp::create(rewriter, load.getLoc(), llvmLoadTy,
+ adaptor.getOperands(), load->getAttrs());
loadOp.setVolatile_(isVolatile);
if (std::optional<mlir::ArrayAttr> optionalTag = load.getTbaa())
loadOp.setTBAATags(*optionalTag);
@@ -3396,10 +3410,10 @@ static void genCondBrOp(mlir::Location loc, mlir::Value cmp, mlir::Block *dest,
mlir::ConversionPatternRewriter &rewriter,
mlir::Block *newBlock) {
if (destOps)
- rewriter.create<mlir::LLVM::CondBrOp>(loc, cmp, dest, *destOps, newBlock,
- mlir::ValueRange());
+ mlir::LLVM::CondBrOp::create(rewriter, loc, cmp, dest, *destOps, newBlock,
+ mlir::ValueRange());
else
- rewriter.create<mlir::LLVM::CondBrOp>(loc, cmp, dest, newBlock);
+ mlir::LLVM::CondBrOp::create(rewriter, loc, cmp, dest, newBlock);
}
template <typename A, typename B>
@@ -3466,36 +3480,39 @@ struct SelectCaseOpConversion : public fir::FIROpConversion<fir::SelectCaseOp> {
mlir::Attribute attr = cases[t];
assert(mlir::isa<mlir::UnitAttr>(attr) || cmpOps.has_value());
if (mlir::isa<fir::PointIntervalAttr>(attr)) {
- auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, selector, cmpOps->front());
+ auto cmp = mlir::LLVM::ICmpOp::create(rewriter, loc,
+ mlir::LLVM::ICmpPredicate::eq,
+ selector, cmpOps->front());
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
if (mlir::isa<fir::LowerBoundAttr>(attr)) {
- auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sle, cmpOps->front(), selector);
+ auto cmp = mlir::LLVM::ICmpOp::create(rewriter, loc,
+ mlir::LLVM::ICmpPredicate::sle,
+ cmpOps->front(), selector);
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
if (mlir::isa<fir::UpperBoundAttr>(attr)) {
- auto cmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sle, selector, cmpOps->front());
+ auto cmp = mlir::LLVM::ICmpOp::create(rewriter, loc,
+ mlir::LLVM::ICmpPredicate::sle,
+ selector, cmpOps->front());
genCaseLadderStep(loc, cmp, dest, destOps, rewriter);
continue;
}
if (mlir::isa<fir::ClosedIntervalAttr>(attr)) {
mlir::Value caseArg0 = *cmpOps->begin();
- auto cmp0 = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sle, caseArg0, selector);
+ auto cmp0 = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::sle, caseArg0, selector);
auto *thisBlock = rewriter.getInsertionBlock();
auto *newBlock1 = createBlock(rewriter, dest);
auto *newBlock2 = createBlock(rewriter, dest);
rewriter.setInsertionPointToEnd(thisBlock);
- rewriter.create<mlir::LLVM::CondBrOp>(loc, cmp0, newBlock1, newBlock2);
+ mlir::LLVM::CondBrOp::create(rewriter, loc, cmp0, newBlock1, newBlock2);
rewriter.setInsertionPointToEnd(newBlock1);
mlir::Value caseArg1 = *(cmpOps->begin() + 1);
- auto cmp1 = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::sle, selector, caseArg1);
+ auto cmp1 = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::sle, selector, caseArg1);
genCondBrOp(loc, cmp1, dest, destOps, rewriter, newBlock2);
rewriter.setInsertionPointToEnd(newBlock2);
continue;
@@ -3581,8 +3598,8 @@ selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering, OP select,
// LLVM::SwitchOp takes a i32 type for the selector.
if (select.getSelector().getType() != rewriter.getI32Type())
- selector = rewriter.create<mlir::LLVM::TruncOp>(loc, rewriter.getI32Type(),
- selector);
+ selector = mlir::LLVM::TruncOp::create(rewriter, loc, rewriter.getI32Type(),
+ selector);
rewriter.replaceOpWithNewOp<mlir::LLVM::SwitchOp>(
select, selector,
@@ -3654,11 +3671,11 @@ struct StoreOpConversion : public fir::FIROpConversion<fir::StoreOp> {
TypePair boxTypePair{boxTy, llvmBoxTy};
mlir::Value boxSize =
computeBoxSize(loc, boxTypePair, llvmValue, rewriter);
- newOp = rewriter.create<mlir::LLVM::MemcpyOp>(loc, llvmMemref, llvmValue,
- boxSize, isVolatile);
+ newOp = mlir::LLVM::MemcpyOp::create(rewriter, loc, llvmMemref, llvmValue,
+ boxSize, isVolatile);
} else {
mlir::LLVM::StoreOp storeOp =
- rewriter.create<mlir::LLVM::StoreOp>(loc, llvmValue, llvmMemref);
+ mlir::LLVM::StoreOp::create(rewriter, loc, llvmValue, llvmMemref);
if (isVolatile)
storeOp.setVolatile_(true);
@@ -3697,11 +3714,11 @@ struct CopyOpConversion : public fir::FIROpConversion<fir::CopyOp> {
mlir::LLVM::AliasAnalysisOpInterface newOp;
if (copy.getNoOverlap())
- newOp = rewriter.create<mlir::LLVM::MemcpyOp>(
- loc, llvmDestination, llvmSource, copySize, isVolatile);
+ newOp = mlir::LLVM::MemcpyOp::create(rewriter, loc, llvmDestination,
+ llvmSource, copySize, isVolatile);
else
- newOp = rewriter.create<mlir::LLVM::MemmoveOp>(
- loc, llvmDestination, llvmSource, copySize, isVolatile);
+ newOp = mlir::LLVM::MemmoveOp::create(rewriter, loc, llvmDestination,
+ llvmSource, copySize, isVolatile);
// TODO: propagate TBAA once FirAliasTagOpInterface added to CopyOp.
attachTBAATag(newOp, copyTy, copyTy, nullptr);
@@ -3725,9 +3742,9 @@ struct UnboxCharOpConversion : public fir::FIROpConversion<fir::UnboxCharOp> {
mlir::Location loc = unboxchar.getLoc();
mlir::Value ptrToBuffer =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, tuple, 0);
+ mlir::LLVM::ExtractValueOp::create(rewriter, loc, tuple, 0);
- auto len = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, tuple, 1);
+ auto len = mlir::LLVM::ExtractValueOp::create(rewriter, loc, tuple, 1);
mlir::Value lenAfterCast = integerCast(loc, rewriter, lenTy, len);
rewriter.replaceOp(unboxchar,
@@ -3817,11 +3834,11 @@ struct IsPresentOpConversion : public fir::FIROpConversion<fir::IsPresentOp> {
mlir::cast<mlir::LLVM::LLVMStructType>(ptr.getType());
assert(!structTy.isOpaque() && !structTy.getBody().empty());
- ptr = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, ptr, 0);
+ ptr = mlir::LLVM::ExtractValueOp::create(rewriter, loc, ptr, 0);
}
mlir::LLVM::ConstantOp c0 =
genConstantIndex(isPresent.getLoc(), idxTy, rewriter, 0);
- auto addr = rewriter.create<mlir::LLVM::PtrToIntOp>(loc, idxTy, ptr);
+ auto addr = mlir::LLVM::PtrToIntOp::create(rewriter, loc, idxTy, ptr);
rewriter.replaceOpWithNewOp<mlir::LLVM::ICmpOp>(
isPresent, mlir::LLVM::ICmpPredicate::ne, addr, c0);
@@ -3866,15 +3883,16 @@ complexSum(OPTY sumop, mlir::ValueRange opnds,
auto loc = sumop.getLoc();
mlir::Type eleTy = lowering.convertType(getComplexEleTy(sumop.getType()));
mlir::Type ty = lowering.convertType(sumop.getType());
- auto x0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 0);
- auto y0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 1);
- auto x1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 0);
- auto y1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 1);
- auto rx = rewriter.create<LLVMOP>(loc, eleTy, x0, x1, fmf);
- auto ry = rewriter.create<LLVMOP>(loc, eleTy, y0, y1, fmf);
- auto r0 = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
- auto r1 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, r0, rx, 0);
- return rewriter.create<mlir::LLVM::InsertValueOp>(loc, r1, ry, 1);
+ auto x0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 0);
+ auto y0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 1);
+ auto x1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 0);
+ auto y1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 1);
+ auto rx = LLVMOP::create(rewriter, loc, eleTy, x0, x1, fmf);
+ auto ry = LLVMOP::create(rewriter, loc, eleTy, y0, y1, fmf);
+ auto r0 = mlir::LLVM::UndefOp::create(rewriter, loc, ty);
+ llvm::SmallVector<int64_t> pos{0};
+ auto r1 = mlir::LLVM::InsertValueOp::create(rewriter, loc, r0, rx, pos);
+ return mlir::LLVM::InsertValueOp::create(rewriter, loc, r1, ry, 1);
}
} // namespace
@@ -3925,19 +3943,20 @@ struct MulcOpConversion : public fir::FIROpConversion<fir::MulcOp> {
auto loc = mulc.getLoc();
mlir::Type eleTy = convertType(getComplexEleTy(mulc.getType()));
mlir::Type ty = convertType(mulc.getType());
- auto x0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 0);
- auto y0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 1);
- auto x1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 0);
- auto y1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 1);
- auto xx = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, x0, x1, fmf);
- auto yx = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, y0, x1, fmf);
- auto xy = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, x0, y1, fmf);
- auto ri = rewriter.create<mlir::LLVM::FAddOp>(loc, eleTy, xy, yx, fmf);
- auto yy = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, y0, y1, fmf);
- auto rr = rewriter.create<mlir::LLVM::FSubOp>(loc, eleTy, xx, yy, fmf);
- auto ra = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
- auto r1 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, ra, rr, 0);
- auto r0 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, r1, ri, 1);
+ auto x0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 0);
+ auto y0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 1);
+ auto x1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 0);
+ auto y1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 1);
+ auto xx = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, x0, x1, fmf);
+ auto yx = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, y0, x1, fmf);
+ auto xy = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, x0, y1, fmf);
+ auto ri = mlir::LLVM::FAddOp::create(rewriter, loc, eleTy, xy, yx, fmf);
+ auto yy = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, y0, y1, fmf);
+ auto rr = mlir::LLVM::FSubOp::create(rewriter, loc, eleTy, xx, yy, fmf);
+ auto ra = mlir::LLVM::UndefOp::create(rewriter, loc, ty);
+ llvm::SmallVector<int64_t> pos{0};
+ auto r1 = mlir::LLVM::InsertValueOp::create(rewriter, loc, ra, rr, pos);
+ auto r0 = mlir::LLVM::InsertValueOp::create(rewriter, loc, r1, ri, 1);
rewriter.replaceOp(mulc, r0.getResult());
return mlir::success();
}
@@ -3960,24 +3979,25 @@ struct DivcOpConversion : public fir::FIROpConversion<fir::DivcOp> {
auto loc = divc.getLoc();
mlir::Type eleTy = convertType(getComplexEleTy(divc.getType()));
mlir::Type ty = convertType(divc.getType());
- auto x0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 0);
- auto y0 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, a, 1);
- auto x1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 0);
- auto y1 = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, b, 1);
- auto xx = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, x0, x1, fmf);
- auto x1x1 = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, x1, x1, fmf);
- auto yx = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, y0, x1, fmf);
- auto xy = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, x0, y1, fmf);
- auto yy = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, y0, y1, fmf);
- auto y1y1 = rewriter.create<mlir::LLVM::FMulOp>(loc, eleTy, y1, y1, fmf);
- auto d = rewriter.create<mlir::LLVM::FAddOp>(loc, eleTy, x1x1, y1y1, fmf);
- auto rrn = rewriter.create<mlir::LLVM::FAddOp>(loc, eleTy, xx, yy, fmf);
- auto rin = rewriter.create<mlir::LLVM::FSubOp>(loc, eleTy, yx, xy, fmf);
- auto rr = rewriter.create<mlir::LLVM::FDivOp>(loc, eleTy, rrn, d, fmf);
- auto ri = rewriter.create<mlir::LLVM::FDivOp>(loc, eleTy, rin, d, fmf);
- auto ra = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
- auto r1 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, ra, rr, 0);
- auto r0 = rewriter.create<mlir::LLVM::InsertValueOp>(loc, r1, ri, 1);
+ auto x0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 0);
+ auto y0 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, a, 1);
+ auto x1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 0);
+ auto y1 = mlir::LLVM::ExtractValueOp::create(rewriter, loc, b, 1);
+ auto xx = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, x0, x1, fmf);
+ auto x1x1 = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, x1, x1, fmf);
+ auto yx = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, y0, x1, fmf);
+ auto xy = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, x0, y1, fmf);
+ auto yy = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, y0, y1, fmf);
+ auto y1y1 = mlir::LLVM::FMulOp::create(rewriter, loc, eleTy, y1, y1, fmf);
+ auto d = mlir::LLVM::FAddOp::create(rewriter, loc, eleTy, x1x1, y1y1, fmf);
+ auto rrn = mlir::LLVM::FAddOp::create(rewriter, loc, eleTy, xx, yy, fmf);
+ auto rin = mlir::LLVM::FSubOp::create(rewriter, loc, eleTy, yx, xy, fmf);
+ auto rr = mlir::LLVM::FDivOp::create(rewriter, loc, eleTy, rrn, d, fmf);
+ auto ri = mlir::LLVM::FDivOp::create(rewriter, loc, eleTy, rin, d, fmf);
+ auto ra = mlir::LLVM::UndefOp::create(rewriter, loc, ty);
+ llvm::SmallVector<int64_t> pos{0};
+ auto r1 = mlir::LLVM::InsertValueOp::create(rewriter, loc, ra, rr, pos);
+ auto r0 = mlir::LLVM::InsertValueOp::create(rewriter, loc, r1, ri, 1);
rewriter.replaceOp(divc, r0.getResult());
return mlir::success();
}
@@ -3995,11 +4015,12 @@ struct NegcOpConversion : public fir::FIROpConversion<fir::NegcOp> {
auto eleTy = convertType(getComplexEleTy(neg.getType()));
auto loc = neg.getLoc();
mlir::Value o0 = adaptor.getOperands()[0];
- auto rp = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, o0, 0);
- auto ip = rewriter.create<mlir::LLVM::ExtractValueOp>(loc, o0, 1);
- auto nrp = rewriter.create<mlir::LLVM::FNegOp>(loc, eleTy, rp);
- auto nip = rewriter.create<mlir::LLVM::FNegOp>(loc, eleTy, ip);
- auto r = rewriter.create<mlir::LLVM::InsertValueOp>(loc, o0, nrp, 0);
+ auto rp = mlir::LLVM::ExtractValueOp::create(rewriter, loc, o0, 0);
+ auto ip = mlir::LLVM::ExtractValueOp::create(rewriter, loc, o0, 1);
+ auto nrp = mlir::LLVM::FNegOp::create(rewriter, loc, eleTy, rp);
+ auto nip = mlir::LLVM::FNegOp::create(rewriter, loc, eleTy, ip);
+ llvm::SmallVector<int64_t> pos{0};
+ auto r = mlir::LLVM::InsertValueOp::create(rewriter, loc, o0, nrp, pos);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(neg, r, nip, 1);
return mlir::success();
}
diff --git a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
index 75a54fd..c52be56 100644
--- a/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
+++ b/flang/lib/Optimizer/CodeGen/FIROpPatterns.cpp
@@ -48,7 +48,7 @@ mlir::LLVM::ConstantOp ConvertFIRToLLVMPattern::genI32Constant(
int value) const {
mlir::Type i32Ty = rewriter.getI32Type();
mlir::IntegerAttr attr = rewriter.getI32IntegerAttr(value);
- return rewriter.create<mlir::LLVM::ConstantOp>(loc, i32Ty, attr);
+ return mlir::LLVM::ConstantOp::create(rewriter, loc, i32Ty, attr);
}
mlir::LLVM::ConstantOp ConvertFIRToLLVMPattern::genConstantOffset(
@@ -56,7 +56,7 @@ mlir::LLVM::ConstantOp ConvertFIRToLLVMPattern::genConstantOffset(
int offset) const {
mlir::Type ity = lowerTy().offsetType();
mlir::IntegerAttr cattr = rewriter.getI32IntegerAttr(offset);
- return rewriter.create<mlir::LLVM::ConstantOp>(loc, ity, cattr);
+ return mlir::LLVM::ConstantOp::create(rewriter, loc, ity, cattr);
}
/// Perform an extension or truncation as needed on an integer value. Lowering
@@ -80,9 +80,9 @@ mlir::Value ConvertFIRToLLVMPattern::integerCast(
return rewriter.createOrFold<mlir::LLVM::SExtOp>(loc, ty, val);
} else {
if (toSize < fromSize)
- return rewriter.create<mlir::LLVM::TruncOp>(loc, ty, val);
+ return mlir::LLVM::TruncOp::create(rewriter, loc, ty, val);
if (toSize > fromSize)
- return rewriter.create<mlir::LLVM::SExtOp>(loc, ty, val);
+ return mlir::LLVM::SExtOp::create(rewriter, loc, ty, val);
}
return val;
}
@@ -100,16 +100,16 @@ mlir::Value ConvertFIRToLLVMPattern::getValueFromBox(
mlir::ConversionPatternRewriter &rewriter, int boxValue) const {
if (mlir::isa<mlir::LLVM::LLVMPointerType>(box.getType())) {
auto pty = getLlvmPtrType(resultTy.getContext());
- auto p = rewriter.create<mlir::LLVM::GEPOp>(
- loc, pty, boxTy.llvm, box,
+ auto p = mlir::LLVM::GEPOp::create(
+ rewriter, loc, pty, boxTy.llvm, box,
llvm::ArrayRef<mlir::LLVM::GEPArg>{0, boxValue});
auto fldTy = getBoxEleTy(boxTy.llvm, {boxValue});
- auto loadOp = rewriter.create<mlir::LLVM::LoadOp>(loc, fldTy, p);
+ auto loadOp = mlir::LLVM::LoadOp::create(rewriter, loc, fldTy, p);
auto castOp = integerCast(loc, rewriter, resultTy, loadOp);
attachTBAATag(loadOp, boxTy.fir, nullptr, p);
return castOp;
}
- return rewriter.create<mlir::LLVM::ExtractValueOp>(loc, box, boxValue);
+ return mlir::LLVM::ExtractValueOp::create(rewriter, loc, box, boxValue);
}
/// Method to construct code sequence to get the triple for dimension `dim`
@@ -147,7 +147,7 @@ mlir::Value ConvertFIRToLLVMPattern::loadDimFieldFromBox(
"in memory");
mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0,
static_cast<int>(kDimsPosInBox), dim, off);
- auto loadOp = rewriter.create<mlir::LLVM::LoadOp>(loc, ty, p);
+ auto loadOp = mlir::LLVM::LoadOp::create(rewriter, loc, ty, p);
attachTBAATag(loadOp, boxTy.fir, nullptr, p);
return loadOp;
}
@@ -158,12 +158,13 @@ mlir::Value ConvertFIRToLLVMPattern::getDimFieldFromBox(
if (mlir::isa<mlir::LLVM::LLVMPointerType>(box.getType())) {
mlir::LLVM::GEPOp p = genGEP(loc, boxTy.llvm, rewriter, box, 0,
static_cast<int>(kDimsPosInBox), dim, off);
- auto loadOp = rewriter.create<mlir::LLVM::LoadOp>(loc, ty, p);
+ auto loadOp = mlir::LLVM::LoadOp::create(rewriter, loc, ty, p);
attachTBAATag(loadOp, boxTy.fir, nullptr, p);
return loadOp;
}
- return rewriter.create<mlir::LLVM::ExtractValueOp>(
- loc, box, llvm::ArrayRef<std::int64_t>{kDimsPosInBox, dim, off});
+ return mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, box,
+ llvm::ArrayRef<std::int64_t>{kDimsPosInBox, dim, off});
}
mlir::Value ConvertFIRToLLVMPattern::getStrideFromBox(
@@ -251,10 +252,10 @@ mlir::Value ConvertFIRToLLVMPattern::genBoxAttributeCheck(
getValueFromBox(loc, boxTy, box, attrTy, rewriter, kAttributePosInBox);
mlir::LLVM::ConstantOp attrMask = genConstantOffset(loc, rewriter, maskValue);
auto maskRes =
- rewriter.create<mlir::LLVM::AndOp>(loc, attrTy, attribute, attrMask);
+ mlir::LLVM::AndOp::create(rewriter, loc, attrTy, attribute, attrMask);
mlir::LLVM::ConstantOp c0 = genConstantOffset(loc, rewriter, 0);
- return rewriter.create<mlir::LLVM::ICmpOp>(loc, mlir::LLVM::ICmpPredicate::ne,
- maskRes, c0);
+ return mlir::LLVM::ICmpOp::create(rewriter, loc,
+ mlir::LLVM::ICmpPredicate::ne, maskRes, c0);
}
mlir::Value ConvertFIRToLLVMPattern::computeBoxSize(
@@ -281,10 +282,10 @@ mlir::Value ConvertFIRToLLVMPattern::computeBoxSize(
firBoxType.getBoxTypeWithNewShape(1)))) &&
"descriptor layout requires adding padding for dim field");
mlir::Value sizePerDim = genConstantOffset(loc, rewriter, sizePerDimCst);
- mlir::Value dimsSize = rewriter.create<mlir::LLVM::MulOp>(
- loc, sizePerDim.getType(), sizePerDim, rank);
- mlir::Value size = rewriter.create<mlir::LLVM::AddOp>(
- loc, scalarBoxSize.getType(), scalarBoxSize, dimsSize);
+ mlir::Value dimsSize = mlir::LLVM::MulOp::create(
+ rewriter, loc, sizePerDim.getType(), sizePerDim, rank);
+ mlir::Value size = mlir::LLVM::AddOp::create(
+ rewriter, loc, scalarBoxSize.getType(), scalarBoxSize, dimsSize);
return size;
}
@@ -324,9 +325,9 @@ mlir::Value ConvertFIRToLLVMPattern::genAllocaAndAddrCastWithType(
unsigned allocaAs = getAllocaAddressSpace(rewriter);
unsigned programAs = getProgramAddressSpace(rewriter);
- mlir::Value al = rewriter.create<mlir::LLVM::AllocaOp>(
- loc, ::getLlvmPtrType(llvmObjectTy.getContext(), allocaAs), llvmObjectTy,
- size, alignment);
+ mlir::Value al = mlir::LLVM::AllocaOp::create(
+ rewriter, loc, ::getLlvmPtrType(llvmObjectTy.getContext(), allocaAs),
+ llvmObjectTy, size, alignment);
// if our allocation address space, is not the same as the program address
// space, then we must emit a cast to the program address space before use.
@@ -334,8 +335,9 @@ mlir::Value ConvertFIRToLLVMPattern::genAllocaAndAddrCastWithType(
// the numeric value 5 (private), and the program address space is 0
// (generic).
if (allocaAs != programAs) {
- al = rewriter.create<mlir::LLVM::AddrSpaceCastOp>(
- loc, ::getLlvmPtrType(llvmObjectTy.getContext(), programAs), al);
+ al = mlir::LLVM::AddrSpaceCastOp::create(
+ rewriter, loc, ::getLlvmPtrType(llvmObjectTy.getContext(), programAs),
+ al);
}
rewriter.restoreInsertionPoint(thisPt);
diff --git a/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp b/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp
index d2cf85b..ac432c7 100644
--- a/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp
+++ b/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp
@@ -152,20 +152,20 @@ PackArrayConversion::matchAndRewrite(fir::PackArrayOp op,
// For now we have to always check if the box is present.
auto isPresent =
- builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), box);
+ fir::IsPresentOp::create(builder, loc, builder.getI1Type(), box);
- fir::IfOp ifOp = builder.create<fir::IfOp>(loc, boxType, isPresent,
- /*withElseRegion=*/true);
+ fir::IfOp ifOp = fir::IfOp::create(builder, loc, boxType, isPresent,
+ /*withElseRegion=*/true);
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
// The box is present.
auto newBox = genRepackedBox(builder, loc, op);
if (mlir::failed(newBox))
return newBox;
- builder.create<fir::ResultOp>(loc, *newBox);
+ fir::ResultOp::create(builder, loc, *newBox);
// The box is not present. Return original box.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
- builder.create<fir::ResultOp>(loc, box);
+ fir::ResultOp::create(builder, loc, box);
rewriter.replaceOp(op, ifOp.getResult(0));
return mlir::success();
@@ -199,8 +199,8 @@ mlir::Value PackArrayConversion::allocateTempBuffer(
// We need to reset the CFI_attribute_allocatable before
// returning the temporary box to avoid any mishandling
// of the temporary box in Fortran runtime.
- base = builder.create<fir::BoxAddrOp>(loc, fir::boxMemRefType(tempBoxType),
- base);
+ base = fir::BoxAddrOp::create(builder, loc, fir::boxMemRefType(tempBoxType),
+ base);
ptrType = base.getType();
}
@@ -262,23 +262,24 @@ PackArrayConversion::genRepackedBox(fir::FirOpBuilder &builder,
}
// Create a temporay iff the original is not contigous and is not empty.
- auto isNotContiguous = builder.genNot(
- loc, builder.create<fir::IsContiguousBoxOp>(loc, box, op.getInnermost()));
+ auto isNotContiguous =
+ builder.genNot(loc, fir::IsContiguousBoxOp::create(builder, loc, box,
+ op.getInnermost()));
auto dataAddr =
- builder.create<fir::BoxAddrOp>(loc, fir::boxMemRefType(boxType), box);
+ fir::BoxAddrOp::create(builder, loc, fir::boxMemRefType(boxType), box);
auto isNotEmpty =
- builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), dataAddr);
+ fir::IsPresentOp::create(builder, loc, builder.getI1Type(), dataAddr);
auto doPack =
- builder.create<mlir::arith::AndIOp>(loc, isNotContiguous, isNotEmpty);
+ mlir::arith::AndIOp::create(builder, loc, isNotContiguous, isNotEmpty);
fir::IfOp ifOp =
- builder.create<fir::IfOp>(loc, boxType, doPack, /*withElseRegion=*/true);
+ fir::IfOp::create(builder, loc, boxType, doPack, /*withElseRegion=*/true);
// Assume that the repacking is unlikely.
ifOp.setUnlikelyIfWeights();
// Return original box.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
- builder.create<fir::ResultOp>(loc, box);
+ fir::ResultOp::create(builder, loc, box);
// Create a new box.
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
@@ -308,7 +309,7 @@ PackArrayConversion::genRepackedBox(fir::FirOpBuilder &builder,
if (!op.getNoCopy())
fir::runtime::genShallowCopy(builder, loc, tempBox, box,
/*resultIsAllocated=*/true);
- builder.create<fir::ResultOp>(loc, tempBox);
+ fir::ResultOp::create(builder, loc, tempBox);
return ifOp.getResult(0);
}
@@ -330,15 +331,15 @@ UnpackArrayConversion::matchAndRewrite(fir::UnpackArrayOp op,
// For now we have to always check if the box is present.
auto isPresent =
- builder.create<fir::IsPresentOp>(loc, predicateType, originalBox);
+ fir::IsPresentOp::create(builder, loc, predicateType, originalBox);
builder.genIfThen(loc, isPresent).genThen([&]() {
mlir::Type addrType =
fir::HeapType::get(fir::extractSequenceType(tempBox.getType()));
mlir::Value tempAddr =
- builder.create<fir::BoxAddrOp>(loc, addrType, tempBox);
+ fir::BoxAddrOp::create(builder, loc, addrType, tempBox);
mlir::Value originalAddr =
- builder.create<fir::BoxAddrOp>(loc, addrType, originalBox);
+ fir::BoxAddrOp::create(builder, loc, addrType, originalBox);
auto isNotSame = builder.genPtrCompare(loc, mlir::arith::CmpIPredicate::ne,
tempAddr, originalAddr);
@@ -356,7 +357,7 @@ UnpackArrayConversion::matchAndRewrite(fir::UnpackArrayOp op,
// to the runtime that uses heap memory, even when the stack
// attribute is set on fir.pack_array.
if (!op.getStack() || !canAllocateTempOnStack(originalBox))
- builder.create<fir::FreeMemOp>(loc, tempAddr);
+ fir::FreeMemOp::create(builder, loc, tempAddr);
})
.getIfOp()
.setUnlikelyIfWeights();
diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index b60ac11..1b1d43c 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -103,13 +103,14 @@ public:
auto idxTy = rewriter.getIndexType();
for (auto ext : seqTy.getShape()) {
auto iAttr = rewriter.getIndexAttr(ext);
- auto extVal = rewriter.create<mlir::arith::ConstantOp>(loc, idxTy, iAttr);
+ auto extVal =
+ mlir::arith::ConstantOp::create(rewriter, loc, idxTy, iAttr);
shapeOpers.push_back(extVal);
}
- auto xbox = rewriter.create<fir::cg::XEmboxOp>(
- loc, embox.getType(), embox.getMemref(), shapeOpers, mlir::ValueRange{},
+ auto xbox = fir::cg::XEmboxOp::create(
+ rewriter, loc, embox.getType(), embox.getMemref(), shapeOpers,
mlir::ValueRange{}, mlir::ValueRange{}, mlir::ValueRange{},
- embox.getTypeparams(), embox.getSourceBox(),
+ mlir::ValueRange{}, embox.getTypeparams(), embox.getSourceBox(),
embox.getAllocatorIdxAttr());
LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
rewriter.replaceOp(embox, xbox.getOperation()->getResults());
@@ -143,10 +144,11 @@ public:
substrOpers.assign(sliceOp.getSubstr().begin(),
sliceOp.getSubstr().end());
}
- auto xbox = rewriter.create<fir::cg::XEmboxOp>(
- loc, embox.getType(), embox.getMemref(), shapeOpers, shiftOpers,
- sliceOpers, subcompOpers, substrOpers, embox.getTypeparams(),
- embox.getSourceBox(), embox.getAllocatorIdxAttr());
+ auto xbox = fir::cg::XEmboxOp::create(
+ rewriter, loc, embox.getType(), embox.getMemref(), shapeOpers,
+ shiftOpers, sliceOpers, subcompOpers, substrOpers,
+ embox.getTypeparams(), embox.getSourceBox(),
+ embox.getAllocatorIdxAttr());
LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
rewriter.replaceOp(embox, xbox.getOperation()->getResults());
return mlir::success();
@@ -201,8 +203,8 @@ public:
sliceOp.getSubstr().end());
}
- auto xRebox = rewriter.create<fir::cg::XReboxOp>(
- loc, rebox.getType(), rebox.getBox(), shapeOpers, shiftOpers,
+ auto xRebox = fir::cg::XReboxOp::create(
+ rewriter, loc, rebox.getType(), rebox.getBox(), shapeOpers, shiftOpers,
sliceOpers, subcompOpers, substrOpers);
LLVM_DEBUG(llvm::dbgs()
<< "rewriting " << rebox << " to " << xRebox << '\n');
@@ -259,9 +261,9 @@ public:
"Don't allow substring operations on array_coor. This "
"restriction may be lifted in the future.");
}
- auto xArrCoor = rewriter.create<fir::cg::XArrayCoorOp>(
- loc, arrCoor.getType(), arrCoor.getMemref(), shapeOpers, shiftOpers,
- sliceOpers, subcompOpers, arrCoor.getIndices(),
+ auto xArrCoor = fir::cg::XArrayCoorOp::create(
+ rewriter, loc, arrCoor.getType(), arrCoor.getMemref(), shapeOpers,
+ shiftOpers, sliceOpers, subcompOpers, arrCoor.getIndices(),
arrCoor.getTypeparams());
LLVM_DEBUG(llvm::dbgs()
<< "rewriting " << arrCoor << " to " << xArrCoor << '\n');
@@ -301,9 +303,9 @@ public:
return mlir::failure();
}
// FIXME: Add FortranAttrs and CudaAttrs
- auto xDeclOp = rewriter.create<fir::cg::XDeclareOp>(
- loc, declareOp.getType(), declareOp.getMemref(), shapeOpers, shiftOpers,
- declareOp.getTypeparams(), declareOp.getDummyScope(),
+ auto xDeclOp = fir::cg::XDeclareOp::create(
+ rewriter, loc, declareOp.getType(), declareOp.getMemref(), shapeOpers,
+ shiftOpers, declareOp.getTypeparams(), declareOp.getDummyScope(),
declareOp.getUniqName());
LLVM_DEBUG(llvm::dbgs()
<< "rewriting " << declareOp << " to " << xDeclOp << '\n');
diff --git a/flang/lib/Optimizer/Dialect/FIRDialect.cpp b/flang/lib/Optimizer/Dialect/FIRDialect.cpp
index 4b1dada..12f1baf3 100644
--- a/flang/lib/Optimizer/Dialect/FIRDialect.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRDialect.cpp
@@ -56,7 +56,7 @@ struct FIRInlinerInterface : public mlir::DialectInlinerInterface {
mlir::Value input,
mlir::Type resultType,
mlir::Location loc) const final {
- return builder.create<fir::ConvertOp>(loc, resultType, input);
+ return fir::ConvertOp::create(builder, loc, resultType, input);
}
};
} // namespace
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index cf20d84..01975f3 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -782,8 +782,8 @@ private:
return nullptr;
mlir::OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPoint(shapeShiftOp);
- return rewriter.create<fir::ShapeOp>(shapeShiftOp.getLoc(),
- shapeShiftOp.getExtents());
+ return fir::ShapeOp::create(rewriter, shapeShiftOp.getLoc(),
+ shapeShiftOp.getExtents());
}
static std::optional<IndicesVectorTy>
@@ -797,19 +797,19 @@ private:
rewriter.setInsertionPoint(op);
mlir::Location loc = op->getLoc();
mlir::Type idxTy = rewriter.getIndexType();
- mlir::Value one = rewriter.create<mlir::arith::ConstantOp>(
- loc, idxTy, rewriter.getIndexAttr(1));
+ mlir::Value one = mlir::arith::ConstantOp::create(
+ rewriter, loc, idxTy, rewriter.getIndexAttr(1));
rewriter.restoreInsertionPoint(savedIP);
auto nsw = mlir::arith::IntegerOverflowFlags::nsw;
IndicesVectorTy shiftedIndices;
for (auto [lb, idx] : llvm::zip(lbs, indices)) {
- mlir::Value extLb = rewriter.create<fir::ConvertOp>(loc, idxTy, lb);
- mlir::Value extIdx = rewriter.create<fir::ConvertOp>(loc, idxTy, idx);
+ mlir::Value extLb = fir::ConvertOp::create(rewriter, loc, idxTy, lb);
+ mlir::Value extIdx = fir::ConvertOp::create(rewriter, loc, idxTy, idx);
mlir::Value add =
- rewriter.create<mlir::arith::AddIOp>(loc, extIdx, extLb, nsw);
+ mlir::arith::AddIOp::create(rewriter, loc, extIdx, extLb, nsw);
mlir::Value sub =
- rewriter.create<mlir::arith::SubIOp>(loc, add, one, nsw);
+ mlir::arith::SubIOp::create(rewriter, loc, add, one, nsw);
shiftedIndices.push_back(sub);
}
@@ -4711,7 +4711,7 @@ mlir::func::FuncOp fir::createFuncOp(mlir::Location loc, mlir::ModuleOp module,
return f;
mlir::OpBuilder modBuilder(module.getBodyRegion());
modBuilder.setInsertionPointToEnd(module.getBody());
- auto result = modBuilder.create<mlir::func::FuncOp>(loc, name, type, attrs);
+ auto result = mlir::func::FuncOp::create(modBuilder, loc, name, type, attrs);
result.setVisibility(mlir::SymbolTable::Visibility::Private);
return result;
}
@@ -4731,7 +4731,7 @@ fir::GlobalOp fir::createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
if (auto g = module.lookupSymbol<fir::GlobalOp>(name))
return g;
mlir::OpBuilder modBuilder(module.getBodyRegion());
- auto result = modBuilder.create<fir::GlobalOp>(loc, name, type, attrs);
+ auto result = fir::GlobalOp::create(modBuilder, loc, name, type, attrs);
result.setVisibility(mlir::SymbolTable::Visibility::Private);
return result;
}
diff --git a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
index 01c0be6..c2e0afe1 100644
--- a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
+++ b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
@@ -88,6 +88,57 @@ void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu) {
mod->setAttr(tuneCpuName, mlir::StringAttr::get(ctx, cpu));
}
+static constexpr const char *atomicIgnoreDenormalModeName =
+ "fir.atomic_ignore_denormal_mode";
+
+void fir::setAtomicIgnoreDenormalMode(mlir::ModuleOp mod, bool value) {
+ if (value) {
+ auto *ctx = mod.getContext();
+ mod->setAttr(atomicIgnoreDenormalModeName, mlir::UnitAttr::get(ctx));
+ } else {
+ if (mod->hasAttr(atomicIgnoreDenormalModeName))
+ mod->removeAttr(atomicIgnoreDenormalModeName);
+ }
+}
+
+bool fir::getAtomicIgnoreDenormalMode(mlir::ModuleOp mod) {
+ return mod->hasAttr(atomicIgnoreDenormalModeName);
+}
+
+static constexpr const char *atomicFineGrainedMemoryName =
+ "fir.atomic_fine_grained_memory";
+
+void fir::setAtomicFineGrainedMemory(mlir::ModuleOp mod, bool value) {
+ if (value) {
+ auto *ctx = mod.getContext();
+ mod->setAttr(atomicFineGrainedMemoryName, mlir::UnitAttr::get(ctx));
+ } else {
+ if (mod->hasAttr(atomicFineGrainedMemoryName))
+ mod->removeAttr(atomicFineGrainedMemoryName);
+ }
+}
+
+bool fir::getAtomicFineGrainedMemory(mlir::ModuleOp mod) {
+ return mod->hasAttr(atomicFineGrainedMemoryName);
+}
+
+static constexpr const char *atomicRemoteMemoryName =
+ "fir.atomic_remote_memory";
+
+void fir::setAtomicRemoteMemory(mlir::ModuleOp mod, bool value) {
+ if (value) {
+ auto *ctx = mod.getContext();
+ mod->setAttr(atomicRemoteMemoryName, mlir::UnitAttr::get(ctx));
+ } else {
+ if (mod->hasAttr(atomicRemoteMemoryName))
+ mod->removeAttr(atomicRemoteMemoryName);
+ }
+}
+
+bool fir::getAtomicRemoteMemory(mlir::ModuleOp mod) {
+ return mod->hasAttr(atomicRemoteMemoryName);
+}
+
llvm::StringRef fir::getTuneCPU(mlir::ModuleOp mod) {
if (auto attr = mod->getAttrOfType<mlir::StringAttr>(tuneCpuName))
return attr.getValue();
diff --git a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
index 30c6030..6cf8adb 100644
--- a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
+++ b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
@@ -12,6 +12,7 @@
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/CommandLine.h"
/// Allow the user to set the FIR intrinsic type kind value to LLVM type
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
index cb77aef..1b1abef 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp
@@ -201,13 +201,13 @@ mlir::Value hlfir::genExprShape(mlir::OpBuilder &builder,
for (std::int64_t extent : expr.getShape()) {
if (extent == hlfir::ExprType::getUnknownExtent())
return {};
- extents.emplace_back(builder.create<mlir::arith::ConstantOp>(
- loc, indexTy, builder.getIntegerAttr(indexTy, extent)));
+ extents.emplace_back(mlir::arith::ConstantOp::create(
+ builder, loc, indexTy, builder.getIntegerAttr(indexTy, extent)));
}
fir::ShapeType shapeTy =
fir::ShapeType::get(builder.getContext(), expr.getRank());
- fir::ShapeOp shape = builder.create<fir::ShapeOp>(loc, shapeTy, extents);
+ fir::ShapeOp shape = fir::ShapeOp::create(builder, loc, shapeTy, extents);
return shape.getResult();
}
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
index df6ce12..ed102db 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
@@ -257,7 +257,7 @@ updateDeclaredInputTypeWithVolatility(mlir::Type inputType, mlir::Value memref,
llvm::TypeSwitch<mlir::Type>(inputType)
.Case<fir::ReferenceType, fir::BoxType, fir::ClassType>(updateType);
memref =
- builder.create<fir::VolatileCastOp>(memref.getLoc(), inputType, memref);
+ fir::VolatileCastOp::create(builder, memref.getLoc(), inputType, memref);
return std::make_pair(inputType, memref);
}
@@ -1293,8 +1293,8 @@ hlfir::MatmulOp::canonicalize(MatmulOp matmulOp,
if (isOtherwiseUnused(transposeOp)) {
mlir::Location loc = matmulOp.getLoc();
mlir::Type resultTy = matmulOp.getResult().getType();
- auto matmulTransposeOp = rewriter.create<hlfir::MatmulTransposeOp>(
- loc, resultTy, transposeOp.getArray(), matmulOp.getRhs(),
+ auto matmulTransposeOp = hlfir::MatmulTransposeOp::create(
+ rewriter, loc, resultTy, transposeOp.getArray(), matmulOp.getRhs(),
matmulOp.getFastmathAttr());
// we don't need to remove any hlfir.destroy because it will be needed for
@@ -2271,8 +2271,8 @@ hlfir::GetLengthOp::canonicalize(GetLengthOp getLength,
return mlir::failure();
mlir::Type indexTy = rewriter.getIndexType();
- auto cstLen = rewriter.create<mlir::arith::ConstantOp>(
- loc, indexTy, mlir::IntegerAttr::get(indexTy, charTy.getLen()));
+ auto cstLen = mlir::arith::ConstantOp::create(
+ rewriter, loc, indexTy, mlir::IntegerAttr::get(indexTy, charTy.getLen()));
rewriter.replaceOp(getLength, cstLen);
return mlir::success();
}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
index 00ca673..9109f2b 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
@@ -53,13 +53,13 @@ static mlir::Value packageBufferizedExpr(mlir::Location loc,
auto tupleType = mlir::TupleType::get(
builder.getContext(),
mlir::TypeRange{storage.getType(), mustFree.getType()});
- auto undef = builder.create<fir::UndefOp>(loc, tupleType);
- auto insert = builder.create<fir::InsertValueOp>(
- loc, tupleType, undef, mustFree,
+ auto undef = fir::UndefOp::create(builder, loc, tupleType);
+ auto insert = fir::InsertValueOp::create(
+ builder, loc, tupleType, undef, mustFree,
builder.getArrayAttr(
{builder.getIntegerAttr(builder.getIndexType(), 1)}));
- return builder.create<fir::InsertValueOp>(
- loc, tupleType, insert, storage,
+ return fir::InsertValueOp::create(
+ builder, loc, tupleType, insert, storage,
builder.getArrayAttr(
{builder.getIntegerAttr(builder.getIndexType(), 0)}));
}
@@ -117,8 +117,8 @@ createArrayTemp(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();
};
@@ -137,9 +137,9 @@ static mlir::Value copyInTempAndPackage(mlir::Location loc,
hlfir::Entity source) {
auto [temp, cleanup] = hlfir::createTempFromMold(loc, builder, source);
assert(!temp.isAllocatable() && "expect temp to already be allocated");
- builder.create<hlfir::AssignOp>(loc, source, temp, /*realloc=*/false,
- /*keep_lhs_length_if_realloc=*/false,
- /*temporary_lhs=*/true);
+ hlfir::AssignOp::create(builder, loc, source, temp, /*realloc=*/false,
+ /*keep_lhs_length_if_realloc=*/false,
+ /*temporary_lhs=*/true);
return packageBufferizedExpr(loc, builder, temp, cleanup);
}
@@ -210,11 +210,11 @@ struct ApplyOpConversion : public mlir::OpConversionPattern<hlfir::ApplyOp> {
mlir::Location loc = apply->getLoc();
hlfir::Entity bufferizedExpr = getBufferizedExprStorage(adaptor.getExpr());
mlir::Type resultType = hlfir::getVariableElementType(bufferizedExpr);
- mlir::Value result = rewriter.create<hlfir::DesignateOp>(
- loc, resultType, bufferizedExpr, adaptor.getIndices(),
+ mlir::Value result = hlfir::DesignateOp::create(
+ rewriter, loc, resultType, bufferizedExpr, adaptor.getIndices(),
adaptor.getTypeparams());
if (fir::isa_trivial(apply.getType())) {
- result = rewriter.create<fir::LoadOp>(loc, result);
+ result = fir::LoadOp::create(rewriter, loc, result);
} else {
fir::FirOpBuilder builder(rewriter, apply.getOperation());
result =
@@ -297,15 +297,15 @@ struct SetLengthOpConversion
llvm::SmallVector<mlir::Value, 1> lenParams{adaptor.getLength()};
auto alloca = builder.createTemporary(loc, charType, tmpName,
/*shape=*/{}, lenParams);
- auto declareOp = builder.create<hlfir::DeclareOp>(
- loc, alloca, tmpName, /*shape=*/mlir::Value{}, lenParams,
+ auto declareOp = hlfir::DeclareOp::create(
+ builder, loc, alloca, tmpName, /*shape=*/mlir::Value{}, lenParams,
/*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{});
hlfir::Entity temp{declareOp.getBase()};
// Assign string value to the created temp.
- builder.create<hlfir::AssignOp>(loc, string, temp,
- /*realloc=*/false,
- /*keep_lhs_length_if_realloc=*/false,
- /*temporary_lhs=*/true);
+ hlfir::AssignOp::create(builder, loc, string, temp,
+ /*realloc=*/false,
+ /*keep_lhs_length_if_realloc=*/false,
+ /*temporary_lhs=*/true);
mlir::Value bufferizedExpr =
packageBufferizedExpr(loc, builder, temp, false);
rewriter.replaceOp(setLength, bufferizedExpr);
@@ -445,7 +445,8 @@ struct AssociateOpConversion
!mlir::isa<fir::BaseBoxType>(assocType)) ||
((mlir::isa<fir::BoxCharType>(sourceVar.getType()) &&
!mlir::isa<fir::BoxCharType>(assocType)))) {
- sourceVar = builder.create<fir::BoxAddrOp>(loc, assocType, sourceVar);
+ sourceVar =
+ fir::BoxAddrOp::create(builder, loc, assocType, sourceVar);
} else {
sourceVar = builder.createConvert(loc, assocType, sourceVar);
}
@@ -511,7 +512,7 @@ struct AssociateOpConversion
name = *associate.getUniqName();
auto temp =
builder.createTemporary(loc, bufferizedExpr.getType(), name, attrs);
- builder.create<fir::StoreOp>(loc, bufferizedExpr, temp);
+ fir::StoreOp::create(builder, loc, bufferizedExpr, temp);
mlir::Value mustFree = builder.createBool(loc, false);
replaceWith(temp, temp, mustFree);
return mlir::success();
@@ -544,10 +545,10 @@ static void genBufferDestruction(mlir::Location loc, fir::FirOpBuilder &builder,
if (mustFinalize && !mlir::isa<fir::BaseBoxType>(var.getType()))
fir::emitFatalError(loc, "non-finalizable variable");
- addr = builder.create<fir::BoxAddrOp>(loc, heapType, var);
+ addr = fir::BoxAddrOp::create(builder, loc, heapType, var);
} else {
if (!mlir::isa<fir::HeapType>(var.getType()))
- addr = builder.create<fir::ConvertOp>(loc, heapType, var);
+ addr = fir::ConvertOp::create(builder, loc, heapType, var);
if (mustFinalize || deallocComponents) {
// Embox the raw pointer using proper shape and type params
@@ -577,7 +578,7 @@ static void genBufferDestruction(mlir::Location loc, fir::FirOpBuilder &builder,
fir::runtime::genDerivedTypeDestroyWithoutFinalization(builder, loc, var);
if (doFree)
- builder.create<fir::FreeMemOp>(loc, addr);
+ fir::FreeMemOp::create(builder, loc, addr);
};
bool deallocComponents = hlfir::mayHaveAllocatableComponent(var.getType());
@@ -657,7 +658,7 @@ struct NoReassocOpConversion
fir::FirOpBuilder builder(rewriter, noreassoc.getOperation());
mlir::Value bufferizedExpr = getBufferizedExprStorage(adaptor.getVal());
mlir::Value result =
- builder.create<hlfir::NoReassocOp>(loc, bufferizedExpr);
+ hlfir::NoReassocOp::create(builder, loc, bufferizedExpr);
if (!fir::isa_trivial(bufferizedExpr.getType())) {
// NoReassocOp should not be needed on the mustFree path.
@@ -775,13 +776,13 @@ struct ElementalOpConversion
if (asExpr && asExpr.isMove() && mlir::isa<fir::RecordType>(elemType) &&
hlfir::mayHaveAllocatableComponent(elemType) &&
wasCreatedInCurrentBlock(elementValue, builder)) {
- auto load = builder.create<fir::LoadOp>(loc, asExpr.getVar());
- builder.create<fir::StoreOp>(loc, load, tempElement);
+ auto load = fir::LoadOp::create(builder, loc, asExpr.getVar());
+ fir::StoreOp::create(builder, loc, load, tempElement);
} else {
- builder.create<hlfir::AssignOp>(loc, elementValue, tempElement,
- /*realloc=*/false,
- /*keep_lhs_length_if_realloc=*/false,
- /*temporary_lhs=*/true);
+ hlfir::AssignOp::create(builder, loc, elementValue, tempElement,
+ /*realloc=*/false,
+ /*keep_lhs_length_if_realloc=*/false,
+ /*temporary_lhs=*/true);
// hlfir.yield_element implicitly marks the end-of-life its operand if
// it is an expression created in the hlfir.elemental (since it is its
@@ -792,7 +793,7 @@ struct ElementalOpConversion
// loop, this will ensure the buffer properly deallocated.
if (mlir::isa<hlfir::ExprType>(elementValue.getType()) &&
wasCreatedInCurrentBlock(elementValue, builder))
- builder.create<hlfir::DestroyOp>(loc, elementValue);
+ hlfir::DestroyOp::create(builder, loc, elementValue);
}
builder.restoreInsertionPoint(insPt);
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
index 33f687d..2e27324 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
@@ -82,8 +82,8 @@ public:
rhsType = fir::LogicalType::get(builder.getContext(), 4);
rhsVal = builder.createConvert(loc, rhsType, rhsVal);
}
- mlir::Value temp = builder.create<fir::AllocaOp>(loc, rhsType);
- builder.create<fir::StoreOp>(loc, rhsVal, temp);
+ mlir::Value temp = fir::AllocaOp::create(builder, loc, rhsType);
+ fir::StoreOp::create(builder, loc, rhsVal, temp);
rhsExv = temp;
}
return fir::getBase(builder.createBox(loc, rhsExv));
@@ -136,7 +136,7 @@ public:
// reallocate and modify "toMutableBox" even if it is taking it by
// reference.
auto toMutableBox = builder.createTemporary(loc, to.getType());
- builder.create<fir::StoreOp>(loc, to, toMutableBox);
+ fir::StoreOp::create(builder, loc, to, toMutableBox);
if (assignOp.isTemporaryLHS())
fir::runtime::genAssignTemporary(builder, loc, toMutableBox, from);
else
@@ -182,7 +182,7 @@ public:
.genIfOp(loc, {resultAddrType}, isContiguous,
/*withElseRegion=*/true)
.genThen(
- [&]() { builder.create<fir::ResultOp>(loc, inputVariable); })
+ [&]() { fir::ResultOp::create(builder, loc, inputVariable); })
.genElse([&] {
// Create temporary on the heap. Note that the runtime is used and
// that is desired: since the data copy happens under a runtime
@@ -191,17 +191,17 @@ public:
// compilation time on these loops.
mlir::Value temp = copyInOp.getTempBox();
fir::runtime::genCopyInAssign(builder, loc, temp, inputVariable);
- mlir::Value copy = builder.create<fir::LoadOp>(loc, temp);
+ mlir::Value copy = fir::LoadOp::create(builder, loc, temp);
// Get rid of allocatable flag in the fir.box.
if (mlir::cast<fir::BaseBoxType>(resultAddrType).isAssumedRank())
- copy = builder.create<fir::ReboxAssumedRankOp>(
- loc, resultAddrType, copy,
+ copy = fir::ReboxAssumedRankOp::create(
+ builder, loc, resultAddrType, copy,
fir::LowerBoundModifierAttribute::Preserve);
else
- copy = builder.create<fir::ReboxOp>(loc, resultAddrType, copy,
- /*shape=*/mlir::Value{},
- /*slice=*/mlir::Value{});
- builder.create<fir::ResultOp>(loc, copy);
+ copy = fir::ReboxOp::create(builder, loc, resultAddrType, copy,
+ /*shape=*/mlir::Value{},
+ /*slice=*/mlir::Value{});
+ fir::ResultOp::create(builder, loc, copy);
})
.getResults()[0];
return {addr, builder.genNot(loc, isContiguous)};
@@ -218,14 +218,14 @@ public:
/*withElseRegion=*/true)
.genThen([&]() {
CopyInResult res = genNonOptionalCopyIn(loc, builder, copyInOp);
- builder.create<fir::ResultOp>(
- loc, mlir::ValueRange{res.addr, res.wasCopied});
+ fir::ResultOp::create(builder, loc,
+ mlir::ValueRange{res.addr, res.wasCopied});
})
.genElse([&] {
mlir::Value absent =
- builder.create<fir::AbsentOp>(loc, resultAddrType);
- builder.create<fir::ResultOp>(
- loc, mlir::ValueRange{absent, isPresent});
+ fir::AbsentOp::create(builder, loc, resultAddrType);
+ fir::ResultOp::create(builder, loc,
+ mlir::ValueRange{absent, isPresent});
})
.getResults();
return {res[0], res[1]};
@@ -269,12 +269,12 @@ public:
// CopyOutAssign() guarantees that there will be no finalization for
// the LHS even if it is of a derived type with finalization.
varMutableBox = builder.createTemporary(loc, var.getType());
- builder.create<fir::StoreOp>(loc, var, varMutableBox);
+ fir::StoreOp::create(builder, loc, var, varMutableBox);
} else {
// Even when there is no need to copy back the data (e.g., the dummy
// argument was intent(in), CopyOutAssign is called to
// destroy/deallocate the temporary.
- varMutableBox = builder.create<fir::ZeroOp>(loc, temp.getType());
+ varMutableBox = fir::ZeroOp::create(builder, loc, temp.getType());
}
fir::runtime::genCopyOutAssign(builder, loc, varMutableBox,
copyOutOp.getTemp());
@@ -302,8 +302,8 @@ public:
fir::FortranVariableFlagsAttr::get(rewriter.getContext(), *attrs);
if (auto attr = declareOp.getDataAttr())
dataAttr = cuf::DataAttributeAttr::get(rewriter.getContext(), *attr);
- auto firDeclareOp = rewriter.create<fir::DeclareOp>(
- loc, memref.getType(), memref, declareOp.getShape(),
+ auto firDeclareOp = fir::DeclareOp::create(
+ rewriter, loc, memref.getType(), memref, declareOp.getShape(),
declareOp.getTypeparams(), declareOp.getDummyScope(),
declareOp.getUniqName(), fortranAttrs, dataAttr);
@@ -328,15 +328,15 @@ public:
mlir::dyn_cast<fir::BaseBoxType>(firBase.getType())) {
// Rebox so that lower bounds and attributes are correct.
if (baseBoxType.isAssumedRank())
- return builder.create<fir::ReboxAssumedRankOp>(
- loc, hlfirBaseType, firBase,
+ return fir::ReboxAssumedRankOp::create(
+ builder, loc, hlfirBaseType, firBase,
fir::LowerBoundModifierAttribute::SetToOnes);
if (!fir::extractSequenceType(baseBoxType.getEleTy()) &&
baseBoxType == hlfirBaseType)
return firBase;
- return builder.create<fir::ReboxOp>(loc, hlfirBaseType, firBase,
- declareOp.getShape(),
- /*slice=*/mlir::Value{});
+ return fir::ReboxOp::create(builder, loc, hlfirBaseType, firBase,
+ declareOp.getShape(),
+ /*slice=*/mlir::Value{});
} else {
llvm::SmallVector<mlir::Value> typeParams;
auto maybeCharType = mlir::dyn_cast<fir::CharacterType>(
@@ -344,9 +344,9 @@ public:
if (!maybeCharType || maybeCharType.hasDynamicLen())
typeParams.append(declareOp.getTypeparams().begin(),
declareOp.getTypeparams().end());
- return builder.create<fir::EmboxOp>(
- loc, hlfirBaseType, firBase, declareOp.getShape(),
- /*slice=*/mlir::Value{}, typeParams);
+ return fir::EmboxOp::create(builder, loc, hlfirBaseType, firBase,
+ declareOp.getShape(),
+ /*slice=*/mlir::Value{}, typeParams);
}
};
if (!mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation())
@@ -367,26 +367,26 @@ public:
// preserve the optional aspect: the hlfir fir.box should be null if
// the entity is absent so that later fir.is_present on the hlfir base
// are valid.
- mlir::Value isPresent =
- builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), firBase);
- hlfirBase = builder
- .genIfOp(loc, {hlfirBaseType}, isPresent,
- /*withElseRegion=*/true)
- .genThen([&] {
- builder.create<fir::ResultOp>(loc, genHlfirBox());
- })
- .genElse([&]() {
- mlir::Value absent =
- builder.create<fir::AbsentOp>(loc, hlfirBaseType);
- builder.create<fir::ResultOp>(loc, absent);
- })
- .getResults()[0];
+ mlir::Value isPresent = fir::IsPresentOp::create(
+ builder, loc, builder.getI1Type(), firBase);
+ hlfirBase =
+ builder
+ .genIfOp(loc, {hlfirBaseType}, isPresent,
+ /*withElseRegion=*/true)
+ .genThen(
+ [&] { fir::ResultOp::create(builder, loc, genHlfirBox()); })
+ .genElse([&]() {
+ mlir::Value absent =
+ fir::AbsentOp::create(builder, loc, hlfirBaseType);
+ fir::ResultOp::create(builder, loc, absent);
+ })
+ .getResults()[0];
}
} else if (mlir::isa<fir::BoxCharType>(hlfirBaseType)) {
assert(declareOp.getTypeparams().size() == 1 &&
"must contain character length");
- hlfirBase = rewriter.create<fir::EmboxCharOp>(
- loc, hlfirBaseType, firBase, declareOp.getTypeparams()[0]);
+ hlfirBase = fir::EmboxCharOp::create(
+ rewriter, loc, hlfirBaseType, firBase, declareOp.getTypeparams()[0]);
} else {
if (hlfirBaseType != firBase.getType()) {
declareOp.emitOpError()
@@ -426,9 +426,9 @@ class DesignateOpConversion
const bool isVolatile = fir::isa_volatile_type(originalDesignateType);
mlir::Type arrayCoorType = fir::ReferenceType::get(baseEleTy, isVolatile);
- base = builder.create<fir::ArrayCoorOp>(
- loc, arrayCoorType, base, shape,
- /*slice=*/mlir::Value{}, firstElementIndices, firBaseTypeParameters);
+ base = fir::ArrayCoorOp::create(builder, loc, arrayCoorType, base, shape,
+ /*slice=*/mlir::Value{},
+ firstElementIndices, firBaseTypeParameters);
return base;
}
@@ -461,8 +461,8 @@ public:
mlir::Type baseRecordType = baseEntity.getFortranElementType();
if (fir::isRecordWithTypeParameters(baseRecordType))
TODO(loc, "hlfir.designate with a parametrized derived type base");
- fieldIndex = builder.create<fir::FieldIndexOp>(
- loc, fir::FieldType::get(builder.getContext()),
+ fieldIndex = fir::FieldIndexOp::create(
+ builder, loc, fir::FieldType::get(builder.getContext()),
designate.getComponent().value(), baseRecordType,
/*typeParams=*/mlir::ValueRange{});
if (baseEntity.isScalar()) {
@@ -475,7 +475,8 @@ public:
designate.getComponent().value());
mlir::Type coorTy = fir::ReferenceType::get(componentType, isVolatile);
- base = builder.create<fir::CoordinateOp>(loc, coorTy, base, fieldIndex);
+ base =
+ fir::CoordinateOp::create(builder, loc, coorTy, base, fieldIndex);
if (mlir::isa<fir::BaseBoxType>(componentType)) {
auto variableInterface = mlir::cast<fir::FortranVariableOpInterface>(
designate.getOperation());
@@ -532,12 +533,12 @@ public:
mlir::Value iIdx = builder.createConvert(loc, idxTy, i);
mlir::Value lbIdx = builder.createConvert(loc, idxTy, lb);
sliceFields.emplace_back(
- builder.create<mlir::arith::SubIOp>(loc, iIdx, lbIdx));
+ mlir::arith::SubIOp::create(builder, loc, iIdx, lbIdx));
}
}
} else if (!isScalarDesignator) {
// Otherwise, this is an array section with triplets.
- auto undef = builder.create<fir::UndefOp>(loc, idxTy);
+ auto undef = fir::UndefOp::create(builder, loc, idxTy);
unsigned i = 0;
for (auto isTriplet : designate.getIsTriplet()) {
triples.push_back(subscripts[i++]);
@@ -558,7 +559,7 @@ public:
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
substring[0] = builder.createConvert(loc, idxTy, substring[0]);
substring[0] =
- builder.create<mlir::arith::SubIOp>(loc, substring[0], one);
+ mlir::arith::SubIOp::create(builder, loc, substring[0], one);
substring.push_back(designate.getTypeparams()[0]);
}
if (designate.getComplexPart()) {
@@ -570,7 +571,7 @@ public:
mlir::Value slice;
if (!triples.empty())
slice =
- builder.create<fir::SliceOp>(loc, triples, sliceFields, substring);
+ fir::SliceOp::create(builder, loc, triples, sliceFields, substring);
else
assert(sliceFields.empty() && substring.empty());
@@ -580,11 +581,11 @@ public:
mlir::Value resultBox;
if (mlir::isa<fir::BaseBoxType>(base.getType())) {
resultBox =
- builder.create<fir::ReboxOp>(loc, resultType, base, shape, slice);
+ fir::ReboxOp::create(builder, loc, resultType, base, shape, slice);
} else {
resultBox =
- builder.create<fir::EmboxOp>(loc, resultType, base, shape, slice,
- firBaseTypeParameters, sourceBox);
+ fir::EmboxOp::create(builder, loc, resultType, base, shape, slice,
+ firBaseTypeParameters, sourceBox);
}
rewriter.replaceOp(designate, resultBox);
return mlir::success();
@@ -623,15 +624,16 @@ public:
*designate.getComplexPart());
auto coorTy = fir::ReferenceType::get(resultEleTy, isVolatile);
- base = builder.create<fir::CoordinateOp>(loc, coorTy, base, index);
+ base = fir::CoordinateOp::create(builder, loc, coorTy, base, index);
}
// Cast/embox the computed scalar address if needed.
if (mlir::isa<fir::BoxCharType>(designateResultType)) {
assert(designate.getTypeparams().size() == 1 &&
"must have character length");
- auto emboxChar = builder.create<fir::EmboxCharOp>(
- loc, designateResultType, base, designate.getTypeparams()[0]);
+ auto emboxChar =
+ fir::EmboxCharOp::create(builder, loc, designateResultType, base,
+ designate.getTypeparams()[0]);
rewriter.replaceOp(designate, emboxChar.getResult());
} else {
@@ -679,7 +681,7 @@ public:
// and the output will be monomorphic, the base address can be extracted
// from the fir.class.
if (mlir::isa<fir::BaseBoxType>(baseAddr.getType()))
- baseAddr = rewriter.create<fir::BoxAddrOp>(loc, baseAddr);
+ baseAddr = fir::BoxAddrOp::create(rewriter, loc, baseAddr);
rewriter.replaceOpWithNewOp<fir::ConvertOp>(parentComponent, resultType,
baseAddr);
return mlir::success();
@@ -697,8 +699,8 @@ public:
fir::BoxType::get(base.getElementOrSequenceType());
assert(!base.hasLengthParameters() &&
"base must be a box if it has any type parameters");
- baseAddr = rewriter.create<fir::EmboxOp>(
- loc, baseBoxType, baseAddr, parentComponent.getShape(),
+ baseAddr = fir::EmboxOp::create(
+ rewriter, loc, baseBoxType, baseAddr, parentComponent.getShape(),
/*slice=*/mlir::Value{}, /*typeParams=*/mlir::ValueRange{});
}
rewriter.replaceOpWithNewOp<fir::ReboxOp>(parentComponent, resultType,
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRAssign.cpp b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRAssign.cpp
index 6c4a07b..86d3974 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRAssign.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRAssign.cpp
@@ -126,7 +126,7 @@ public:
rhsArrayElement = hlfir::loadTrivialScalar(loc, builder, rhsArrayElement);
auto lhsArrayElement =
hlfir::getElementAt(loc, builder, lhs, loopNest.oneBasedIndices);
- builder.create<hlfir::AssignOp>(loc, rhsArrayElement, lhsArrayElement);
+ hlfir::AssignOp::create(builder, loc, rhsArrayElement, lhsArrayElement);
rewriter.eraseOp(assign);
return mlir::success();
}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopyIn.cpp b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopyIn.cpp
index 7e8acc5..e1df01e 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopyIn.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopyIn.cpp
@@ -82,7 +82,7 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
hlfir::getFortranElementOrSequenceType(inputVariable.getType());
fir::BoxType resultBoxType = fir::BoxType::get(sequenceType);
mlir::Value isContiguous =
- builder.create<fir::IsContiguousBoxOp>(loc, inputVariable);
+ fir::IsContiguousBoxOp::create(builder, loc, inputVariable);
mlir::Operation::result_range results =
builder
.genIfOp(loc, {resultBoxType, builder.getI1Type()}, isContiguous,
@@ -90,12 +90,13 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
.genThen([&]() {
mlir::Value result = inputVariable;
if (fir::isPointerType(inputVariable.getType())) {
- result = builder.create<fir::ReboxOp>(
- loc, resultBoxType, inputVariable, mlir::Value{},
- mlir::Value{});
+ result = fir::ReboxOp::create(builder, loc, resultBoxType,
+ inputVariable, mlir::Value{},
+ mlir::Value{});
}
- builder.create<fir::ResultOp>(
- loc, mlir::ValueRange{result, builder.createBool(loc, false)});
+ fir::ResultOp::create(
+ builder, loc,
+ mlir::ValueRange{result, builder.createBool(loc, false)});
})
.genElse([&] {
mlir::Value shape = hlfir::genShape(loc, builder, inputVariable);
@@ -106,9 +107,9 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
mlir::Value alloc = builder.createHeapTemporary(
loc, sequenceType, tmpName, extents, lenParams);
- auto declareOp = builder.create<hlfir::DeclareOp>(
- loc, alloc, tmpName, shape, lenParams,
- /*dummy_scope=*/nullptr);
+ auto declareOp = hlfir::DeclareOp::create(builder, loc, alloc,
+ tmpName, shape, lenParams,
+ /*dummy_scope=*/nullptr);
hlfir::Entity temp{declareOp.getBase()};
hlfir::LoopNest loopNest =
hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true,
@@ -120,7 +121,7 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
elem = hlfir::loadTrivialScalar(loc, builder, elem);
hlfir::Entity tempElem = hlfir::getElementAt(
loc, builder, temp, loopNest.oneBasedIndices);
- builder.create<hlfir::AssignOp>(loc, elem, tempElem);
+ hlfir::AssignOp::create(builder, loc, elem, tempElem);
builder.setInsertionPointAfter(loopNest.outerOp);
mlir::Value result;
@@ -132,12 +133,13 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
fir::ReferenceType refTy =
fir::ReferenceType::get(temp.getElementOrSequenceType());
mlir::Value refVal = builder.createConvert(loc, refTy, temp);
- result = builder.create<fir::EmboxOp>(loc, resultBoxType, refVal,
- shape);
+ result = fir::EmboxOp::create(builder, loc, resultBoxType, refVal,
+ shape);
}
- builder.create<fir::ResultOp>(
- loc, mlir::ValueRange{result, builder.createBool(loc, true)});
+ fir::ResultOp::create(
+ builder, loc,
+ mlir::ValueRange{result, builder.createBool(loc, true)});
})
.getResults();
@@ -145,8 +147,8 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
mlir::OpResult needsCleanup = results[1];
// Prepare the corresponding copyOut to free the temporary if it is required
- auto alloca = builder.create<fir::AllocaOp>(loc, resultBox.getType());
- auto store = builder.create<fir::StoreOp>(loc, resultBox, alloca);
+ auto alloca = fir::AllocaOp::create(builder, loc, resultBox.getType());
+ auto store = fir::StoreOp::create(builder, loc, resultBox, alloca);
rewriter.startOpModification(copyOut);
copyOut->setOperand(0, store.getMemref());
copyOut->setOperand(1, needsCleanup);
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
index 31e5bc1..3c29d68 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
@@ -169,8 +169,8 @@ protected:
}
if (resultEntity->isVariable()) {
- hlfir::AsExprOp asExpr = builder.create<hlfir::AsExprOp>(
- loc, *resultEntity, builder.createBool(loc, mustBeFreed));
+ hlfir::AsExprOp asExpr = hlfir::AsExprOp::create(
+ builder, loc, *resultEntity, builder.createBool(loc, mustBeFreed));
resultEntity = hlfir::EntityWithAttributes{asExpr.getResult()};
}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
index c5cf01e..123e5e7 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
@@ -377,7 +377,7 @@ void OrderedAssignmentRewriter::pre(hlfir::ForallOp forallOp) {
} else {
step = generateYieldedScalarValue(forallOp.getStepRegion(), idxTy);
}
- auto doLoop = builder.create<fir::DoLoopOp>(loc, lb, ub, step);
+ auto doLoop = fir::DoLoopOp::create(builder, loc, lb, ub, step);
builder.setInsertionPointToStart(doLoop.getBody());
mlir::Value oldIndex = forallOp.getForallIndexValue();
mlir::Value newIndex =
@@ -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, mlir::TypeRange{}, mask, false);
+ auto ifOp = fir::IfOp::create(builder, loc, mlir::TypeRange{}, mask, false);
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
constructStack.push_back(ifOp);
}
@@ -431,11 +431,11 @@ convertToMoldType(mlir::Location loc, fir::FirOpBuilder &builder,
if (input.isVariable() && mold.isValue()) {
if (fir::isa_trivial(mold.getType())) {
// fir.ref<T> to T.
- mlir::Value load = builder.create<fir::LoadOp>(loc, input);
+ mlir::Value load = fir::LoadOp::create(builder, loc, input);
return hlfir::Entity{builder.createConvert(loc, mold.getType(), load)};
}
// fir.ref<T> to hlfir.expr<T>.
- mlir::Value asExpr = builder.create<hlfir::AsExprOp>(loc, input);
+ mlir::Value asExpr = hlfir::AsExprOp::create(builder, loc, input);
if (asExpr.getType() != mold.getType())
TODO(loc, "hlfir.expr conversion");
cleanups.emplace_back([=]() { b->create<hlfir::DestroyOp>(loc, asExpr); });
@@ -517,7 +517,7 @@ void OrderedAssignmentRewriter::pre(hlfir::RegionAssignOp regionAssignOp) {
} else {
// TODO: preserve allocatable assignment aspects for forall once
// they are conveyed in hlfir.region_assign.
- builder.create<hlfir::AssignOp>(loc, rhsEntity, lhsEntity);
+ hlfir::AssignOp::create(builder, loc, rhsEntity, lhsEntity);
}
generateCleanupIfAny(loweredLhs.elementalCleanup);
if (loweredLhs.vectorSubscriptLoopNest)
@@ -530,8 +530,8 @@ 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(), mlir::TypeRange{}, cdt,
- /*withElseRegion=*/false);
+ auto ifOp = fir::IfOp::create(builder, cdt.getLoc(), mlir::TypeRange{}, cdt,
+ /*withElseRegion=*/false);
constructStack.push_back(ifOp.getOperation());
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
}
@@ -604,7 +604,7 @@ void OrderedAssignmentRewriter::enterElsewhere(hlfir::ElseWhereOp elseWhereOp) {
if (ifOp.getElseRegion().empty()) {
mlir::Location loc = elseWhereOp.getLoc();
builder.createBlock(&ifOp.getElseRegion());
- auto end = builder.create<fir::ResultOp>(loc);
+ auto end = fir::ResultOp::create(builder, loc);
builder.setInsertionPoint(end);
} else {
builder.setInsertionPoint(&ifOp.getElseRegion().back().back());
@@ -1150,7 +1150,8 @@ computeLoopNestIterationNumber(mlir::Location loc, fir::FirOpBuilder &builder,
if (!loopExtent)
loopExtent = extent;
else
- loopExtent = builder.create<mlir::arith::MulIOp>(loc, loopExtent, extent);
+ loopExtent =
+ mlir::arith::MulIOp::create(builder, loc, loopExtent, extent);
}
assert(loopExtent && "loopNest must not be empty");
return loopExtent;
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
index abcbf14..2712bfb 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
@@ -727,8 +727,8 @@ llvm::LogicalResult ElementalAssignBufferization::matchAndRewrite(
// Assign the element value to the array element for this iteration.
auto arrayElement =
hlfir::getElementAt(loc, builder, lhs, loopNest.oneBasedIndices);
- builder.create<hlfir::AssignOp>(
- loc, elementValue, arrayElement, /*realloc=*/false,
+ hlfir::AssignOp::create(
+ builder, loc, elementValue, arrayElement, /*realloc=*/false,
/*keep_lhs_length_if_realloc=*/false, match->assign.getTemporaryLhs());
rewriter.eraseOp(match->assign);
@@ -793,7 +793,7 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite(
// optimized.
mlir::Value n = extents[0];
for (size_t i = 1; i < extents.size(); ++i)
- n = builder.create<mlir::arith::MulIOp>(loc, n, extents[i]);
+ n = mlir::arith::MulIOp::create(builder, loc, n, extents[i]);
llvm::SmallVector<mlir::Value> flatExtents = {n};
mlir::Type flatArrayType;
@@ -801,8 +801,8 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite(
if (mlir::isa<fir::BoxType>(lhs.getType())) {
shape = builder.genShape(loc, flatExtents);
flatArrayType = fir::BoxType::get(fir::SequenceType::get(eleTy, 1));
- flatArray = builder.create<fir::ReboxOp>(loc, flatArrayType, flatArray,
- shape, /*slice=*/mlir::Value{});
+ flatArray = fir::ReboxOp::create(builder, loc, flatArrayType, flatArray,
+ shape, /*slice=*/mlir::Value{});
} else {
// Array references must have fixed shape, when used in assignments.
auto seqTy =
@@ -822,9 +822,9 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite(
builder.setInsertionPointToStart(loopNest.body);
mlir::Value arrayElement =
- builder.create<hlfir::DesignateOp>(loc, fir::ReferenceType::get(eleTy),
- flatArray, loopNest.oneBasedIndices);
- builder.create<hlfir::AssignOp>(loc, rhs, arrayElement);
+ hlfir::DesignateOp::create(builder, loc, fir::ReferenceType::get(eleTy),
+ flatArray, loopNest.oneBasedIndices);
+ hlfir::AssignOp::create(builder, loc, rhs, arrayElement);
} else {
hlfir::LoopNest loopNest =
hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true,
@@ -832,7 +832,7 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite(
builder.setInsertionPointToStart(loopNest.body);
auto arrayElement =
hlfir::getElementAt(loc, builder, lhs, loopNest.oneBasedIndices);
- builder.create<hlfir::AssignOp>(loc, rhs, arrayElement);
+ hlfir::AssignOp::create(builder, loc, rhs, arrayElement);
}
rewriter.eraseOp(assign);
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
index 7958239..b27c3a8 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
@@ -60,22 +60,22 @@ public:
v2 = castToProductType(v2, resultType);
mlir::Value result;
if (mlir::isa<mlir::FloatType>(resultType)) {
- result = builder.create<mlir::arith::AddFOp>(
- loc, acc, builder.create<mlir::arith::MulFOp>(loc, v1, v2));
+ result = mlir::arith::AddFOp::create(
+ builder, loc, acc, mlir::arith::MulFOp::create(builder, loc, v1, v2));
} else if (mlir::isa<mlir::ComplexType>(resultType)) {
if constexpr (CONJ)
result = fir::IntrinsicLibrary{builder, loc}.genConjg(resultType, v1);
else
result = v1;
- result = builder.create<fir::AddcOp>(
- loc, acc, builder.create<fir::MulcOp>(loc, result, v2));
+ result = fir::AddcOp::create(
+ builder, loc, acc, fir::MulcOp::create(builder, loc, result, v2));
} else if (mlir::isa<mlir::IntegerType>(resultType)) {
- result = builder.create<mlir::arith::AddIOp>(
- loc, acc, builder.create<mlir::arith::MulIOp>(loc, v1, v2));
+ result = mlir::arith::AddIOp::create(
+ builder, loc, acc, mlir::arith::MulIOp::create(builder, loc, v1, v2));
} else if (mlir::isa<fir::LogicalType>(resultType)) {
- result = builder.create<mlir::arith::OrIOp>(
- loc, acc, builder.create<mlir::arith::AndIOp>(loc, v1, v2));
+ result = mlir::arith::OrIOp::create(
+ builder, loc, acc, mlir::arith::AndIOp::create(builder, loc, v1, v2));
} else {
llvm_unreachable("unsupported type");
}
@@ -168,8 +168,8 @@ private:
// transpose indices
assert(inExtents.size() == 2 && "checked in TransposeOp::validate");
- return builder.create<fir::ShapeOp>(
- loc, mlir::ValueRange{inExtents[1], inExtents[0]});
+ return fir::ShapeOp::create(builder, loc,
+ mlir::ValueRange{inExtents[1], inExtents[0]});
}
};
@@ -385,23 +385,22 @@ genMinMaxComparison(mlir::Location loc, 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/Maxloc in extrema.cpp.
- mlir::Value cmp = builder.create<mlir::arith::CmpFOp>(
- loc,
- IS_MAX ? 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);
- return builder.create<mlir::arith::OrIOp>(loc, cmp, cmpNan);
+ mlir::Value cmp =
+ mlir::arith::CmpFOp::create(builder, loc,
+ IS_MAX ? 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);
+ return mlir::arith::OrIOp::create(builder, loc, cmp, cmpNan);
} else if (mlir::isa<mlir::IntegerType>(reduction.getType())) {
- return builder.create<mlir::arith::CmpIOp>(
- loc,
- IS_MAX ? mlir::arith::CmpIPredicate::sgt
- : mlir::arith::CmpIPredicate::slt,
- elem, reduction);
+ return mlir::arith::CmpIOp::create(builder, loc,
+ IS_MAX ? mlir::arith::CmpIPredicate::sgt
+ : mlir::arith::CmpIPredicate::slt,
+ elem, reduction);
}
llvm_unreachable("unsupported type");
}
@@ -415,9 +414,9 @@ genIsNotEmptyArrayExtents(mlir::Location loc, fir::FirOpBuilder &builder,
for (auto extent : extents) {
mlir::Value zero =
fir::factory::createZeroValue(builder, loc, extent.getType());
- mlir::Value cmp = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::ne, extent, zero);
- isNotEmpty = builder.create<mlir::arith::AndIOp>(loc, isNotEmpty, cmp);
+ mlir::Value cmp = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::ne, extent, zero);
+ isNotEmpty = mlir::arith::AndIOp::create(builder, loc, isNotEmpty, cmp);
}
return isNotEmpty;
}
@@ -581,8 +580,8 @@ MinMaxlocAsElementalConverter<T>::genReductionInitValues(
llvm::SmallVector<mlir::Type> ifTypes(getNumCoors(),
getResultElementType());
ifTypes.push_back(getSourceElementType());
- ifOp = builder.create<fir::IfOp>(loc, ifTypes, isNotEmpty,
- /*withElseRegion=*/true);
+ ifOp = fir::IfOp::create(builder, loc, ifTypes, isNotEmpty,
+ /*withElseRegion=*/true);
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
mlir::Value one =
builder.createIntegerConstant(loc, getResultElementType(), 1);
@@ -590,7 +589,7 @@ MinMaxlocAsElementalConverter<T>::genReductionInitValues(
mlir::Value minMaxFirst =
hlfir::loadElementAt(loc, builder, hlfir::Entity{getSource()}, indices);
results.push_back(minMaxFirst);
- builder.create<fir::ResultOp>(loc, results);
+ fir::ResultOp::create(builder, loc, results);
// In the 'else' block use default init values.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
@@ -607,7 +606,7 @@ MinMaxlocAsElementalConverter<T>::genReductionInitValues(
result.push_back(minMaxInit);
if (ifOp) {
- builder.create<fir::ResultOp>(loc, result);
+ fir::ResultOp::create(builder, loc, result);
builder.setInsertionPointAfter(ifOp);
result = ifOp.getResults();
} else if (useIsFirst()) {
@@ -635,7 +634,7 @@ MinMaxlocAsElementalConverter<T>::reduceOneElement(
// If isFirst is true, then do the reduction update regardless
// of the FP comparison.
cmp =
- builder.create<mlir::arith::OrIOp>(loc, cmp, getIsFirst(currentValue));
+ mlir::arith::OrIOp::create(builder, loc, cmp, getIsFirst(currentValue));
}
llvm::SmallVector<mlir::Value> newIndices;
@@ -654,12 +653,12 @@ MinMaxlocAsElementalConverter<T>::reduceOneElement(
mlir::Value newCoor = builder.createConvert(
loc, currentCoor.getType(), oneBasedIndices[coorIdx + dim - 1]);
mlir::Value update =
- builder.create<mlir::arith::SelectOp>(loc, cmp, newCoor, currentCoor);
+ mlir::arith::SelectOp::create(builder, loc, cmp, newCoor, currentCoor);
newIndices.push_back(update);
}
- mlir::Value newMinMax = builder.create<mlir::arith::SelectOp>(
- loc, cmp, elementValue, getCurrentMinMax(currentValue));
+ mlir::Value newMinMax = mlir::arith::SelectOp::create(
+ builder, loc, cmp, elementValue, getCurrentMinMax(currentValue));
newIndices.push_back(newMinMax);
if (useIsFirst()) {
@@ -711,10 +710,10 @@ hlfir::Entity MinMaxlocAsElementalConverter<T>::genFinalResult(
mlir::Value idx = builder.createIntegerConstant(loc, indexType, i + 1);
mlir::Value resultElement =
hlfir::getElementAt(loc, builder, hlfir::Entity{tempArray}, {idx});
- builder.create<hlfir::AssignOp>(loc, coor, resultElement);
+ hlfir::AssignOp::create(builder, loc, coor, resultElement);
}
- mlir::Value tempExpr = builder.create<hlfir::AsExprOp>(
- loc, tempArray, builder.createBool(loc, false));
+ mlir::Value tempExpr = hlfir::AsExprOp::create(
+ builder, loc, tempArray, builder.createBool(loc, false));
return hlfir::Entity{tempExpr};
}
@@ -792,10 +791,10 @@ private:
mlir::Value cmp =
genMinMaxComparison<isMax>(loc, builder, elementValue, currentMinMax);
if (useIsFirst())
- cmp = builder.create<mlir::arith::OrIOp>(loc, cmp,
- getIsFirst(currentValue));
- mlir::Value newMinMax = builder.create<mlir::arith::SelectOp>(
- loc, cmp, elementValue, currentMinMax);
+ cmp = mlir::arith::OrIOp::create(builder, loc, cmp,
+ getIsFirst(currentValue));
+ mlir::Value newMinMax = mlir::arith::SelectOp::create(
+ builder, loc, cmp, elementValue, currentMinMax);
result.push_back(newMinMax);
if (useIsFirst())
result.push_back(builder.createBool(loc, false));
@@ -867,13 +866,13 @@ MinMaxvalAsElementalConverter<T>::genReductionInitValues(
loc, builder, this->isTotalReduction(), this->getConstDim(),
this->getSourceRank(), oneBasedIndices);
- ifOp =
- builder.create<fir::IfOp>(loc, this->getResultElementType(), isNotEmpty,
- /*withElseRegion=*/true);
+ ifOp = fir::IfOp::create(builder, loc, this->getResultElementType(),
+ isNotEmpty,
+ /*withElseRegion=*/true);
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
mlir::Value minMaxFirst = hlfir::loadElementAt(
loc, builder, hlfir::Entity{this->getSource()}, indices);
- builder.create<fir::ResultOp>(loc, minMaxFirst);
+ fir::ResultOp::create(builder, loc, minMaxFirst);
// In the 'else' block use default init values.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
@@ -884,7 +883,7 @@ MinMaxvalAsElementalConverter<T>::genReductionInitValues(
result.push_back(init);
if (ifOp) {
- builder.create<fir::ResultOp>(loc, result);
+ fir::ResultOp::create(builder, loc, result);
builder.setInsertionPointAfter(ifOp);
result = ifOp.getResults();
} else if (useIsFirst()) {
@@ -992,9 +991,9 @@ private:
mlir::Value mask =
builder.createConvert(loc, builder.getI1Type(), elementValue);
if constexpr (isAll)
- return {builder.create<mlir::arith::AndIOp>(loc, mask, currentValue[0])};
+ return {mlir::arith::AndIOp::create(builder, loc, mask, currentValue[0])};
else
- return {builder.create<mlir::arith::OrIOp>(loc, mask, currentValue[0])};
+ return {mlir::arith::OrIOp::create(builder, loc, mask, currentValue[0])};
}
virtual hlfir::Entity genFinalResult(
@@ -1034,9 +1033,9 @@ private:
mlir::Value one =
builder.createIntegerConstant(loc, getResultElementType(), 1);
mlir::Value add1 =
- builder.create<mlir::arith::AddIOp>(loc, currentValue[0], one);
- return {builder.create<mlir::arith::SelectOp>(loc, cond, add1,
- currentValue[0])};
+ mlir::arith::AddIOp::create(builder, loc, currentValue[0], one);
+ return {mlir::arith::SelectOp::create(builder, loc, cond, add1,
+ currentValue[0])};
}
};
@@ -1068,7 +1067,7 @@ mlir::LogicalResult ReductionAsElementalConverter::convert() {
// MASK represented by a box might be dynamically optional,
// so we have to check for its presence before accessing it.
isPresentPred =
- builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), mask);
+ fir::IsPresentOp::create(builder, loc, builder.getI1Type(), mask);
}
if (hlfir::Entity{mask}.isScalar())
@@ -1119,20 +1118,20 @@ mlir::LogicalResult ReductionAsElementalConverter::convert() {
// to address the proper mask element.
maskValue = genMaskValue(mask, isPresentPred, indices);
}
- mlir::Value isUnmasked =
- builder.create<fir::ConvertOp>(loc, builder.getI1Type(), maskValue);
- ifOp = builder.create<fir::IfOp>(loc, reductionTypes, isUnmasked,
- /*withElseRegion=*/true);
+ mlir::Value isUnmasked = fir::ConvertOp::create(
+ builder, loc, builder.getI1Type(), maskValue);
+ ifOp = fir::IfOp::create(builder, loc, reductionTypes, isUnmasked,
+ /*withElseRegion=*/true);
// In the 'else' block return the current reduction value.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
- builder.create<fir::ResultOp>(loc, reductionValues);
+ fir::ResultOp::create(builder, loc, reductionValues);
// In the 'then' block do the actual addition.
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
}
reductionValues = reduceOneElement(reductionValues, array, indices);
if (ifOp) {
- builder.create<fir::ResultOp>(loc, reductionValues);
+ fir::ResultOp::create(builder, loc, reductionValues);
builder.setInsertionPointAfter(ifOp);
reductionValues = ifOp.getResults();
}
@@ -1177,7 +1176,7 @@ ReductionAsElementalConverter::genResultShapeForPartialReduction(
mlir::Value dimExtent = inExtents[dimVal - 1];
inExtents.erase(inExtents.begin() + dimVal - 1);
- return {builder.create<fir::ShapeOp>(loc, inExtents), dimExtent};
+ return {fir::ShapeOp::create(builder, loc, inExtents), dimExtent};
}
mlir::Value SumAsElementalConverter::genScalarAdd(mlir::Value value1,
@@ -1185,11 +1184,11 @@ mlir::Value SumAsElementalConverter::genScalarAdd(mlir::Value value1,
mlir::Type ty = value1.getType();
assert(ty == value2.getType() && "reduction values' types do not match");
if (mlir::isa<mlir::FloatType>(ty))
- return builder.create<mlir::arith::AddFOp>(loc, value1, value2);
+ return mlir::arith::AddFOp::create(builder, loc, value1, value2);
else if (mlir::isa<mlir::ComplexType>(ty))
- return builder.create<fir::AddcOp>(loc, value1, value2);
+ return fir::AddcOp::create(builder, loc, value1, value2);
else if (mlir::isa<mlir::IntegerType>(ty))
- return builder.create<mlir::arith::AddIOp>(loc, value1, value2);
+ return mlir::arith::AddIOp::create(builder, loc, value1, value2);
llvm_unreachable("unsupported SUM reduction type");
}
@@ -1201,14 +1200,14 @@ mlir::Value ReductionAsElementalConverter::genMaskValue(
mlir::Type maskType =
hlfir::getFortranElementType(fir::unwrapPassByRefType(mask.getType()));
if (isPresentPred) {
- ifOp = builder.create<fir::IfOp>(loc, maskType, isPresentPred,
- /*withElseRegion=*/true);
+ ifOp = fir::IfOp::create(builder, loc, maskType, isPresentPred,
+ /*withElseRegion=*/true);
// Use 'true', if the mask is not present.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
mlir::Value trueValue = builder.createBool(loc, true);
trueValue = builder.createConvert(loc, maskType, trueValue);
- builder.create<fir::ResultOp>(loc, trueValue);
+ fir::ResultOp::create(builder, loc, trueValue);
// Load the mask value, if the mask is present.
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
@@ -1219,7 +1218,7 @@ mlir::Value ReductionAsElementalConverter::genMaskValue(
if (mlir::isa<fir::BaseBoxType>(mask.getType())) {
// MASK may be a boxed scalar.
mlir::Value addr = hlfir::genVariableRawAddress(loc, builder, maskVar);
- mask = builder.create<fir::LoadOp>(loc, hlfir::Entity{addr});
+ mask = fir::LoadOp::create(builder, loc, hlfir::Entity{addr});
} else {
mask = hlfir::loadTrivialScalar(loc, builder, maskVar);
}
@@ -1233,7 +1232,7 @@ mlir::Value ReductionAsElementalConverter::genMaskValue(
if (!isPresentPred)
return mask;
- builder.create<fir::ResultOp>(loc, mask);
+ fir::ResultOp::create(builder, loc, mask);
return ifOp.getResult(0);
}
@@ -1335,9 +1334,9 @@ private:
// which extent value we use.
mlir::Value zero = builder.createIntegerConstant(loc, calcType, 0);
mlir::Value one = builder.createIntegerConstant(loc, calcType, 1);
- mlir::Value isZero = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::eq, extent, zero);
- extent = builder.create<mlir::arith::SelectOp>(loc, isZero, one, extent);
+ mlir::Value isZero = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero);
+ extent = mlir::arith::SelectOp::create(builder, loc, isZero, one, extent);
shiftVal = fir::IntrinsicLibrary{builder, loc}.genModulo(
calcType, {shiftVal, extent});
return builder.createConvert(loc, calcType, shiftVal);
@@ -1408,17 +1407,17 @@ private:
// Such index computation allows for further loop vectorization
// in LLVM.
mlir::Value wrapBound =
- builder.create<mlir::arith::SubIOp>(loc, shiftDimExtent, shiftVal);
+ mlir::arith::SubIOp::create(builder, loc, shiftDimExtent, shiftVal);
mlir::Value adjustedShiftVal =
- builder.create<mlir::arith::SubIOp>(loc, shiftVal, shiftDimExtent);
+ mlir::arith::SubIOp::create(builder, loc, shiftVal, shiftDimExtent);
mlir::Value index =
builder.createConvert(loc, calcType, inputIndices[dimVal - 1]);
- mlir::Value wrapCheck = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::sle, index, wrapBound);
- mlir::Value actualShift = builder.create<mlir::arith::SelectOp>(
- loc, wrapCheck, shiftVal, adjustedShiftVal);
+ mlir::Value wrapCheck = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::sle, index, wrapBound);
+ mlir::Value actualShift = mlir::arith::SelectOp::create(
+ builder, loc, wrapCheck, shiftVal, adjustedShiftVal);
mlir::Value newIndex =
- builder.create<mlir::arith::AddIOp>(loc, index, actualShift);
+ mlir::arith::AddIOp::create(builder, loc, index, actualShift);
newIndex = builder.createConvert(loc, builder.getIndexType(), newIndex);
indices[dimVal - 1] = newIndex;
hlfir::Entity element = hlfir::getElementAt(loc, builder, array, indices);
@@ -1484,9 +1483,9 @@ private:
normalizeShiftValue(loc, builder, shiftVal, shiftDimExtent, calcType);
}
- hlfir::EvaluateInMemoryOp evalOp =
- builder.create<hlfir::EvaluateInMemoryOp>(
- loc, mlir::cast<hlfir::ExprType>(cshift.getType()), arrayShape);
+ hlfir::EvaluateInMemoryOp evalOp = hlfir::EvaluateInMemoryOp::create(
+ builder, loc, mlir::cast<hlfir::ExprType>(cshift.getType()),
+ arrayShape);
builder.setInsertionPointToStart(&evalOp.getBody().front());
mlir::Value resultArray = evalOp.getMemory();
@@ -1550,13 +1549,14 @@ private:
srcIndices[dimVal - 1] = srcIndex;
hlfir::Entity srcElementValue =
hlfir::loadElementAt(loc, builder, srcArray, srcIndices);
- mlir::Value dstIndex = builder.create<mlir::arith::AddIOp>(
- loc, srcIndex,
- builder.create<mlir::arith::SubIOp>(loc, shiftDimExtent, shiftVal));
+ mlir::Value dstIndex = mlir::arith::AddIOp::create(
+ builder, loc, srcIndex,
+ mlir::arith::SubIOp::create(builder, loc, shiftDimExtent,
+ shiftVal));
dstIndices[dimVal - 1] = dstIndex;
hlfir::Entity dstElement = hlfir::getElementAt(
loc, builder, hlfir::Entity{resultArray}, dstIndices);
- builder.create<hlfir::AssignOp>(loc, srcElementValue, dstElement);
+ hlfir::AssignOp::create(builder, loc, srcElementValue, dstElement);
return {};
};
@@ -1576,20 +1576,20 @@ private:
assert(index.size() == 1 && "expected single loop");
mlir::Value dstIndex = builder.createConvert(loc, calcType, index[0]);
mlir::Value srcIndex =
- builder.create<mlir::arith::AddIOp>(loc, dstIndex, shiftVal);
+ mlir::arith::AddIOp::create(builder, loc, dstIndex, shiftVal);
srcIndices[dimVal - 1] = srcIndex;
hlfir::Entity srcElementValue =
hlfir::loadElementAt(loc, builder, srcArray, srcIndices);
dstIndices[dimVal - 1] = dstIndex;
hlfir::Entity dstElement = hlfir::getElementAt(
loc, builder, hlfir::Entity{resultArray}, dstIndices);
- builder.create<hlfir::AssignOp>(loc, srcElementValue, dstElement);
+ hlfir::AssignOp::create(builder, loc, srcElementValue, dstElement);
return {};
};
// Generate the second loop.
mlir::Value bound =
- builder.create<mlir::arith::SubIOp>(loc, shiftDimExtent, shiftVal);
+ mlir::arith::SubIOp::create(builder, loc, shiftDimExtent, shiftVal);
hlfir::genLoopNestWithReductions(loc, builder, {bound},
/*reductionInits=*/{}, genAssign2,
/*isUnordered=*/true);
@@ -1625,11 +1625,12 @@ private:
if (dimVal == 1 && mlir::isa<fir::BaseBoxType>(array.getType())) {
mlir::Type indexType = builder.getIndexType();
elemSize =
- builder.create<fir::BoxEleSizeOp>(loc, indexType, array.getBase());
+ fir::BoxEleSizeOp::create(builder, loc, indexType, array.getBase());
mlir::Value dimIdx =
builder.createIntegerConstant(loc, indexType, dimVal - 1);
- auto boxDim = builder.create<fir::BoxDimsOp>(
- loc, indexType, indexType, indexType, array.getBase(), dimIdx);
+ auto boxDim =
+ fir::BoxDimsOp::create(builder, loc, indexType, indexType,
+ indexType, array.getBase(), dimIdx);
stride = boxDim.getByteStride();
}
@@ -1639,8 +1640,8 @@ private:
return {};
}
- mlir::Value isContiguous = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::eq, elemSize, stride);
+ mlir::Value isContiguous = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::eq, elemSize, stride);
builder.genIfOp(loc, {}, isContiguous, /*withElseRegion=*/true)
.genThen([&]() {
genDimensionShift(loc, builder, shiftVal, /*exposeContiguity=*/true,
@@ -1710,9 +1711,9 @@ public:
// Generate hlfir.eval_in_mem to mimic the MATMUL implementation
// from Fortran runtime. The implementation needs to operate
// with the result array as an in-memory object.
- hlfir::EvaluateInMemoryOp evalOp =
- builder.create<hlfir::EvaluateInMemoryOp>(
- loc, mlir::cast<hlfir::ExprType>(matmul.getType()), resultShape);
+ hlfir::EvaluateInMemoryOp evalOp = hlfir::EvaluateInMemoryOp::create(
+ builder, loc, mlir::cast<hlfir::ExprType>(matmul.getType()),
+ resultShape);
builder.setInsertionPointToStart(&evalOp.getBody().front());
// Embox the raw array pointer to simplify designating it.
@@ -1813,7 +1814,7 @@ private:
llvm::SmallVector<mlir::Value> innerProductExtent =
fir::factory::deduceOptimalExtents({innerProduct1Extent},
{innerProduct2Extent});
- return {builder.create<fir::ShapeOp>(loc, newExtents),
+ return {fir::ShapeOp::create(builder, loc, newExtents),
innerProductExtent[0]};
}
@@ -1853,7 +1854,7 @@ private:
-> llvm::SmallVector<mlir::Value, 0> {
hlfir::Entity resultElement =
hlfir::getElementAt(loc, builder, result, oneBasedIndices);
- builder.create<hlfir::AssignOp>(loc, initValue, resultElement);
+ hlfir::AssignOp::create(builder, loc, initValue, resultElement);
return {};
};
@@ -1887,7 +1888,7 @@ private:
mlir::Value productValue =
ProductFactory{loc, builder}.genAccumulateProduct(
resultElementValue, lhsElementValue, rhsElementValue);
- builder.create<hlfir::AssignOp>(loc, productValue, resultElement);
+ hlfir::AssignOp::create(builder, loc, productValue, resultElement);
return {};
};
@@ -1924,7 +1925,7 @@ private:
mlir::Value productValue =
ProductFactory{loc, builder}.genAccumulateProduct(
resultElementValue, lhsElementValue, rhsElementValue);
- builder.create<hlfir::AssignOp>(loc, productValue, resultElement);
+ hlfir::AssignOp::create(builder, loc, productValue, resultElement);
return {};
};
hlfir::genLoopNestWithReductions(
@@ -1956,7 +1957,7 @@ private:
mlir::Value productValue =
ProductFactory{loc, builder}.genAccumulateProduct(
resultElementValue, lhsElementValue, rhsElementValue);
- builder.create<hlfir::AssignOp>(loc, productValue, resultElement);
+ hlfir::AssignOp::create(builder, loc, productValue, resultElement);
return {};
};
hlfir::genLoopNestWithReductions(
@@ -2172,7 +2173,7 @@ public:
resultExtents.push_back(hlfir::loadElementAt(
loc, builder, shape,
builder.createIntegerConstant(loc, indexType, idx + 1)));
- auto resultShape = builder.create<fir::ShapeOp>(loc, resultExtents);
+ auto resultShape = fir::ShapeOp::create(builder, loc, resultExtents);
auto genKernel = [&](mlir::Location loc, fir::FirOpBuilder &builder,
mlir::ValueRange inputIndices) -> hlfir::Entity {
@@ -2181,10 +2182,11 @@ public:
fir::IfOp ifOp;
if (pad) {
// PAD is present. Check if this element comes from the PAD array.
- mlir::Value isInsideArray = builder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::ult, linearIndex, arraySize);
- ifOp = builder.create<fir::IfOp>(loc, elementType, isInsideArray,
- /*withElseRegion=*/true);
+ mlir::Value isInsideArray = mlir::arith::CmpIOp::create(
+ builder, loc, mlir::arith::CmpIPredicate::ult, linearIndex,
+ arraySize);
+ ifOp = fir::IfOp::create(builder, loc, elementType, isInsideArray,
+ /*withElseRegion=*/true);
// In the 'else' block, return an element from the PAD.
builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
@@ -2196,13 +2198,13 @@ public:
// Subtract the ARRAY size from the zero-based linear index
// to get the zero-based linear index into PAD.
mlir::Value padLinearIndex =
- builder.create<mlir::arith::SubIOp>(loc, linearIndex, arraySize);
+ mlir::arith::SubIOp::create(builder, loc, linearIndex, arraySize);
llvm::SmallVector<mlir::Value, Fortran::common::maxRank> padIndices =
delinearizeIndex(loc, builder, padExtents, padLinearIndex,
/*wrapAround=*/true);
mlir::Value padElement =
hlfir::loadElementAt(loc, builder, hlfir::Entity{pad}, padIndices);
- builder.create<fir::ResultOp>(loc, padElement);
+ fir::ResultOp::create(builder, loc, padElement);
// In the 'then' block, return an element from the ARRAY.
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
@@ -2215,7 +2217,7 @@ public:
hlfir::loadElementAt(loc, builder, array, arrayIndices);
if (ifOp) {
- builder.create<fir::ResultOp>(loc, arrayElement);
+ fir::ResultOp::create(builder, loc, arrayElement);
builder.setInsertionPointAfter(ifOp);
arrayElement = ifOp.getResult(0);
}
@@ -2252,12 +2254,12 @@ private:
mlir::Value linearIndex = zero;
std::size_t idx = 0;
for (auto index : llvm::reverse(indices)) {
- mlir::Value tmp = builder.create<mlir::arith::SubIOp>(
- loc, builder.createConvert(loc, indexType, index), one);
- tmp = builder.create<mlir::arith::AddIOp>(loc, linearIndex, tmp);
+ mlir::Value tmp = mlir::arith::SubIOp::create(
+ builder, loc, builder.createConvert(loc, indexType, index), one);
+ tmp = mlir::arith::AddIOp::create(builder, loc, linearIndex, tmp);
if (idx + 1 < rank)
- tmp = builder.create<mlir::arith::MulIOp>(
- loc, tmp,
+ tmp = mlir::arith::MulIOp::create(
+ builder, loc, tmp,
builder.createConvert(loc, indexType, extents[rank - idx - 2]));
linearIndex = tmp;
@@ -2297,12 +2299,12 @@ private:
mlir::Value currentIndex = linearIndex;
if (dim != extents.size() - 1 || wrapAround)
currentIndex =
- builder.create<mlir::arith::RemUIOp>(loc, linearIndex, extent);
+ mlir::arith::RemUIOp::create(builder, loc, linearIndex, extent);
// The result of the last division is unused, so it will be DCEd.
linearIndex =
- builder.create<mlir::arith::DivUIOp>(loc, linearIndex, extent);
+ mlir::arith::DivUIOp::create(builder, loc, linearIndex, extent);
indices.push_back(
- builder.create<mlir::arith::AddIOp>(loc, currentIndex, one));
+ mlir::arith::AddIOp::create(builder, loc, currentIndex, one));
}
return indices;
}
@@ -2314,8 +2316,8 @@ private:
mlir::Type indexType = builder.getIndexType();
mlir::Value size = builder.createIntegerConstant(loc, indexType, 1);
for (auto extent : extents)
- size = builder.create<mlir::arith::MulIOp>(
- loc, size, builder.createConvert(loc, indexType, extent));
+ size = mlir::arith::MulIOp::create(
+ builder, loc, size, builder.createConvert(loc, indexType, extent));
return size;
}
};
diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
index 8b40c64..e5fd19d 100644
--- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
@@ -244,15 +244,16 @@ generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
mlir::Value cummulativeExtent = one;
for (auto extent : shapeOp.getExtents()) {
mlir::Value upperbound =
- builder.create<mlir::arith::SubIOp>(loc, extent, one);
+ mlir::arith::SubIOp::create(builder, loc, extent, one);
mlir::Value stride = one;
if (strideIncludeLowerExtent) {
stride = cummulativeExtent;
- cummulativeExtent = builder.create<mlir::arith::MulIOp>(
- loc, cummulativeExtent, extent);
+ cummulativeExtent = mlir::arith::MulIOp::create(
+ builder, loc, cummulativeExtent, extent);
}
- auto accBound = builder.create<mlir::acc::DataBoundsOp>(
- loc, mlir::acc::DataBoundsType::get(builder.getContext()),
+ auto accBound = mlir::acc::DataBoundsOp::create(
+ builder, loc,
+ mlir::acc::DataBoundsType::get(builder.getContext()),
/*lowerbound=*/zero, /*upperbound=*/upperbound,
/*extent=*/extent, /*stride=*/stride, /*strideInBytes=*/false,
/*startIdx=*/one);
@@ -269,17 +270,18 @@ generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
} else {
mlir::Value extent = val;
mlir::Value upperbound =
- builder.create<mlir::arith::SubIOp>(loc, extent, one);
- upperbound = builder.create<mlir::arith::AddIOp>(loc, lowerbound,
- upperbound);
+ mlir::arith::SubIOp::create(builder, loc, extent, one);
+ upperbound = mlir::arith::AddIOp::create(builder, loc, lowerbound,
+ upperbound);
mlir::Value stride = one;
if (strideIncludeLowerExtent) {
stride = cummulativeExtent;
- cummulativeExtent = builder.create<mlir::arith::MulIOp>(
- loc, cummulativeExtent, extent);
+ cummulativeExtent = mlir::arith::MulIOp::create(
+ builder, loc, cummulativeExtent, extent);
}
- auto accBound = builder.create<mlir::acc::DataBoundsOp>(
- loc, mlir::acc::DataBoundsType::get(builder.getContext()),
+ auto accBound = mlir::acc::DataBoundsOp::create(
+ builder, loc,
+ mlir::acc::DataBoundsType::get(builder.getContext()),
/*lowerbound=*/zero, /*upperbound=*/upperbound,
/*extent=*/extent, /*stride=*/stride, /*strideInBytes=*/false,
/*startIdx=*/lowerbound);
@@ -531,9 +533,9 @@ static fir::ShapeOp genShapeOp(mlir::OpBuilder &builder,
llvm::SmallVector<mlir::Value> extents;
mlir::Type idxTy = builder.getIndexType();
for (auto extent : seqTy.getShape())
- extents.push_back(builder.create<mlir::arith::ConstantOp>(
- loc, idxTy, builder.getIntegerAttr(idxTy, extent)));
- return builder.create<fir::ShapeOp>(loc, extents);
+ extents.push_back(mlir::arith::ConstantOp::create(
+ builder, loc, idxTy, builder.getIntegerAttr(idxTy, extent)));
+ return fir::ShapeOp::create(builder, loc, extents);
}
template <typename Ty>
@@ -549,9 +551,10 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
fir::FirOpBuilder firBuilder(builder, mod);
auto getDeclareOpForType = [&](mlir::Type ty) -> hlfir::DeclareOp {
- auto alloca = firBuilder.create<fir::AllocaOp>(loc, ty);
- return firBuilder.create<hlfir::DeclareOp>(
- loc, alloca, varName, /*shape=*/nullptr, llvm::ArrayRef<mlir::Value>{},
+ auto alloca = fir::AllocaOp::create(firBuilder, loc, ty);
+ return hlfir::DeclareOp::create(
+ firBuilder, loc, alloca, varName, /*shape=*/nullptr,
+ llvm::ArrayRef<mlir::Value>{},
/*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{});
};
@@ -559,7 +562,7 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
auto declareOp = getDeclareOpForType(unwrappedTy);
if (initVal) {
auto convert = firBuilder.createConvert(loc, unwrappedTy, initVal);
- firBuilder.create<fir::StoreOp>(loc, convert, declareOp.getBase());
+ fir::StoreOp::create(firBuilder, loc, convert, declareOp.getBase());
}
retVal = declareOp.getBase();
} else if (auto seqTy =
@@ -567,14 +570,15 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
if (fir::isa_trivial(seqTy.getEleTy())) {
mlir::Value shape;
if (seqTy.hasDynamicExtents()) {
- shape = firBuilder.create<fir::ShapeOp>(loc, llvm::to_vector(extents));
+ shape = fir::ShapeOp::create(firBuilder, loc, llvm::to_vector(extents));
} else {
shape = genShapeOp(firBuilder, seqTy, loc);
}
- auto alloca = firBuilder.create<fir::AllocaOp>(
- loc, seqTy, /*typeparams=*/mlir::ValueRange{}, extents);
- auto declareOp = firBuilder.create<hlfir::DeclareOp>(
- loc, alloca, varName, shape, llvm::ArrayRef<mlir::Value>{},
+ auto alloca = fir::AllocaOp::create(
+ firBuilder, loc, seqTy, /*typeparams=*/mlir::ValueRange{}, extents);
+ auto declareOp = hlfir::DeclareOp::create(
+ firBuilder, loc, alloca, varName, shape,
+ llvm::ArrayRef<mlir::Value>{},
/*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{});
if (initVal) {
@@ -584,21 +588,22 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
llvm::SmallVector<mlir::Value> ivs;
if (seqTy.hasDynamicExtents()) {
- firBuilder.create<hlfir::AssignOp>(loc, initVal, declareOp.getBase());
+ hlfir::AssignOp::create(firBuilder, loc, initVal,
+ declareOp.getBase());
} else {
for (auto ext : seqTy.getShape()) {
auto lb = firBuilder.createIntegerConstant(loc, idxTy, 0);
auto ub = firBuilder.createIntegerConstant(loc, idxTy, ext - 1);
auto step = firBuilder.createIntegerConstant(loc, idxTy, 1);
- auto loop = firBuilder.create<fir::DoLoopOp>(loc, lb, ub, step,
- /*unordered=*/false);
+ auto loop = fir::DoLoopOp::create(firBuilder, loc, lb, ub, step,
+ /*unordered=*/false);
firBuilder.setInsertionPointToStart(loop.getBody());
loops.push_back(loop);
ivs.push_back(loop.getInductionVar());
}
- auto coord = firBuilder.create<fir::CoordinateOp>(
- loc, refTy, declareOp.getBase(), ivs);
- firBuilder.create<fir::StoreOp>(loc, initVal, coord);
+ auto coord = fir::CoordinateOp::create(firBuilder, loc, refTy,
+ declareOp.getBase(), ivs);
+ fir::StoreOp::create(firBuilder, loc, initVal, coord);
firBuilder.setInsertionPointAfter(loops[0]);
}
}
@@ -626,7 +631,7 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
storeDst = firBuilder.createConvert(
loc, firBuilder.getRefType(temp.getType()), retVal);
}
- builder.create<fir::StoreOp>(loc, temp, storeDst);
+ fir::StoreOp::create(builder, loc, temp, storeDst);
} else {
retVal = temp;
}
@@ -634,7 +639,7 @@ mlir::Value OpenACCMappableModel<Ty>::generatePrivateInit(
TODO(loc, "Unsupported boxed type for OpenACC private-like recipe");
}
if (initVal) {
- builder.create<hlfir::AssignOp>(loc, initVal, retVal);
+ hlfir::AssignOp::create(builder, loc, initVal, retVal);
}
}
return retVal;
diff --git a/flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp b/flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp
index 31076f6..2b3ac16 100644
--- a/flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp
+++ b/flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp
@@ -246,9 +246,9 @@ private:
genParallelOp(mlir::Location loc, mlir::ConversionPatternRewriter &rewriter,
looputils::InductionVariableInfos &ivInfos,
mlir::IRMapping &mapper) const {
- auto parallelOp = rewriter.create<mlir::omp::ParallelOp>(loc);
+ auto parallelOp = mlir::omp::ParallelOp::create(rewriter, loc);
rewriter.createBlock(&parallelOp.getRegion());
- rewriter.setInsertionPoint(rewriter.create<mlir::omp::TerminatorOp>(loc));
+ rewriter.setInsertionPoint(mlir::omp::TerminatorOp::create(rewriter, loc));
genLoopNestIndVarAllocs(rewriter, ivInfos, mapper);
return parallelOp;
@@ -319,8 +319,8 @@ private:
auto firYield =
mlir::cast<fir::YieldOp>(ompRegion.back().getTerminator());
rewriter.setInsertionPoint(firYield);
- rewriter.create<mlir::omp::YieldOp>(firYield.getLoc(),
- firYield.getOperands());
+ mlir::omp::YieldOp::create(rewriter, firYield.getLoc(),
+ firYield.getOperands());
rewriter.eraseOp(firYield);
}
};
@@ -342,8 +342,8 @@ private:
mlir::OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPointAfter(localizer);
- auto privatizer = rewriter.create<mlir::omp::PrivateClauseOp>(
- localizer.getLoc(), sym.getLeafReference().str() + ".omp",
+ auto privatizer = mlir::omp::PrivateClauseOp::create(
+ rewriter, localizer.getLoc(), sym.getLeafReference().str() + ".omp",
localizer.getTypeAttr().getValue(),
mlir::omp::DataSharingClauseType::Private);
@@ -369,8 +369,9 @@ private:
mlir::OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPointAfter(firReducer);
- auto ompReducer = rewriter.create<mlir::omp::DeclareReductionOp>(
- firReducer.getLoc(), sym.getLeafReference().str() + ".omp",
+ auto ompReducer = mlir::omp::DeclareReductionOp::create(
+ rewriter, firReducer.getLoc(),
+ sym.getLeafReference().str() + ".omp",
firReducer.getTypeAttr().getValue());
cloneFIRRegionToOMP(firReducer.getAllocRegion(),
@@ -392,7 +393,7 @@ private:
}
auto wsloopOp =
- rewriter.create<mlir::omp::WsloopOp>(loop.getLoc(), wsloopClauseOps);
+ mlir::omp::WsloopOp::create(rewriter, loop.getLoc(), wsloopClauseOps);
wsloopOp.setComposite(isComposite);
Fortran::common::openmp::EntryBlockArgs wsloopArgs;
@@ -402,7 +403,7 @@ private:
wsloopOp.getRegion());
auto loopNestOp =
- rewriter.create<mlir::omp::LoopNestOp>(loop.getLoc(), clauseOps);
+ mlir::omp::LoopNestOp::create(rewriter, loop.getLoc(), clauseOps);
// Clone the loop's body inside the loop nest construct using the
// mapped values.
@@ -410,7 +411,7 @@ private:
loopNestOp.getRegion().begin(), mapper);
rewriter.setInsertionPointToEnd(&loopNestOp.getRegion().back());
- rewriter.create<mlir::omp::YieldOp>(loop->getLoc());
+ mlir::omp::YieldOp::create(rewriter, loop->getLoc());
// `local` region arguments are transferred/cloned from the `do concurrent`
// loop to the loopnest op when the region is cloned above. Instead, these
diff --git a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
index 9554808..ae5c0ec 100644
--- a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
+++ b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
@@ -83,7 +83,7 @@ public:
for (Value res : callOp->getResults()) {
opBuilder.setInsertionPoint(callOp);
undefResults.emplace_back(
- opBuilder.create<fir::UndefOp>(res.getLoc(), res.getType()));
+ fir::UndefOp::create(opBuilder, res.getLoc(), res.getType()));
}
callOp->replaceAllUsesWith(undefResults);
}
diff --git a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
index 3009746..66593ec 100644
--- a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
+++ b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
@@ -280,7 +280,7 @@ private:
args.reduction.vars = clauseOps.reductionVars;
}
- auto wrapperOp = rewriter.create<OpTy>(loopOp.getLoc(), clauseOps);
+ auto wrapperOp = OpTy::create(rewriter, loopOp.getLoc(), clauseOps);
mlir::Block *opBlock = genEntryBlock(rewriter, args, wrapperOp.getRegion());
mlir::IRMapping mapper;
@@ -307,16 +307,16 @@ private:
Fortran::common::openmp::EntryBlockArgs parallelArgs;
parallelArgs.priv.vars = parallelClauseOps.privateVars;
- auto parallelOp = rewriter.create<mlir::omp::ParallelOp>(loopOp.getLoc(),
- parallelClauseOps);
+ auto parallelOp = mlir::omp::ParallelOp::create(rewriter, loopOp.getLoc(),
+ parallelClauseOps);
genEntryBlock(rewriter, parallelArgs, parallelOp.getRegion());
parallelOp.setComposite(true);
rewriter.setInsertionPoint(
- rewriter.create<mlir::omp::TerminatorOp>(loopOp.getLoc()));
+ mlir::omp::TerminatorOp::create(rewriter, loopOp.getLoc()));
mlir::omp::DistributeOperands distributeClauseOps;
- auto distributeOp = rewriter.create<mlir::omp::DistributeOp>(
- loopOp.getLoc(), distributeClauseOps);
+ auto distributeOp = mlir::omp::DistributeOp::create(
+ rewriter, loopOp.getLoc(), distributeClauseOps);
distributeOp.setComposite(true);
rewriter.createBlock(&distributeOp.getRegion());
@@ -326,7 +326,7 @@ private:
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
auto wsloopOp =
- rewriter.create<mlir::omp::WsloopOp>(loopOp.getLoc(), wsloopClauseOps);
+ mlir::omp::WsloopOp::create(rewriter, loopOp.getLoc(), wsloopClauseOps);
wsloopOp.setComposite(true);
genEntryBlock(rewriter, wsloopArgs, wsloopOp.getRegion());
diff --git a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
index 27a57f7..f6af684 100644
--- a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
+++ b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
@@ -160,17 +160,17 @@ static mlir::func::FuncOp createCopyFunc(mlir::Location loc, mlir::Type varType,
llvm::SmallVector<mlir::Type> argsTy = {varType, varType};
auto funcType = mlir::FunctionType::get(builder.getContext(), argsTy, {});
mlir::func::FuncOp funcOp =
- modBuilder.create<mlir::func::FuncOp>(loc, copyFuncName, funcType);
+ mlir::func::FuncOp::create(modBuilder, loc, copyFuncName, funcType);
funcOp.setVisibility(mlir::SymbolTable::Visibility::Private);
fir::factory::setInternalLinkage(funcOp);
builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), argsTy,
{loc, loc});
builder.setInsertionPointToStart(&funcOp.getRegion().back());
- Value loaded = builder.create<fir::LoadOp>(loc, funcOp.getArgument(1));
- builder.create<fir::StoreOp>(loc, loaded, funcOp.getArgument(0));
+ Value loaded = fir::LoadOp::create(builder, loc, funcOp.getArgument(1));
+ fir::StoreOp::create(builder, loc, loaded, funcOp.getArgument(0));
- builder.create<mlir::func::ReturnOp>(loc);
+ mlir::func::ReturnOp::create(builder, loc);
return funcOp;
}
@@ -234,9 +234,9 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
if (auto reloaded = rootMapping.lookupOrNull(v))
return nullptr;
Type ty = v.getType();
- Value alloc = allocaBuilder.create<fir::AllocaOp>(loc, ty);
- singleBuilder.create<fir::StoreOp>(loc, singleMapping.lookup(v), alloc);
- Value reloaded = parallelBuilder.create<fir::LoadOp>(loc, ty, alloc);
+ Value alloc = fir::AllocaOp::create(allocaBuilder, loc, ty);
+ fir::StoreOp::create(singleBuilder, loc, singleMapping.lookup(v), alloc);
+ Value reloaded = fir::LoadOp::create(parallelBuilder, loc, ty, alloc);
rootMapping.map(v, reloaded);
return alloc;
};
@@ -293,7 +293,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
allParallelized = false;
}
}
- singleBuilder.create<omp::TerminatorOp>(loc);
+ omp::TerminatorOp::create(singleBuilder, loc);
return {allParallelized, copyPrivate};
};
@@ -370,7 +370,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
SymbolRefAttr::get(funcOp));
}
omp::SingleOp singleOp =
- rootBuilder.create<omp::SingleOp>(loc, singleOperands);
+ omp::SingleOp::create(rootBuilder, loc, singleOperands);
singleOp.getRegion().push_back(singleBlock);
targetRegion.front().getOperations().splice(
singleOp->getIterator(), allocaBlock->getOperations());
@@ -386,7 +386,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
if (isLast)
wsloopOperands.nowait = rootBuilder.getUnitAttr();
auto wsloop =
- rootBuilder.create<mlir::omp::WsloopOp>(loc, wsloopOperands);
+ mlir::omp::WsloopOp::create(rootBuilder, loc, wsloopOperands);
auto clonedWslw = cast<omp::WorkshareLoopWrapperOp>(
rootBuilder.clone(*wslw, rootMapping));
wsloop.getRegion().takeBody(clonedWslw.getRegion());
@@ -465,9 +465,9 @@ LogicalResult lowerWorkshare(mlir::omp::WorkshareOp wsOp, DominanceInfo &di) {
// it because our `parallelizeRegion` function works on regions and not
// blocks.
omp::WorkshareOp newOp =
- rootBuilder.create<omp::WorkshareOp>(loc, omp::WorkshareOperands());
+ omp::WorkshareOp::create(rootBuilder, loc, omp::WorkshareOperands());
if (!wsOp.getNowait())
- rootBuilder.create<omp::BarrierOp>(loc);
+ omp::BarrierOp::create(rootBuilder, loc);
parallelizeRegion(wsOp.getRegion(), newOp.getRegion(), rootMapping, loc,
di);
@@ -505,7 +505,7 @@ LogicalResult lowerWorkshare(mlir::omp::WorkshareOp wsOp, DominanceInfo &di) {
omp::SingleOperands operands;
operands.nowait = wsOp.getNowaitAttr();
- omp::SingleOp newOp = rootBuilder.create<omp::SingleOp>(loc, operands);
+ omp::SingleOp newOp = omp::SingleOp::create(rootBuilder, loc, operands);
newOp.getRegion().getBlocks().splice(newOp.getRegion().getBlocks().begin(),
wsOp.getRegion().getBlocks());
diff --git a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp
index f052cf8..57be863 100644
--- a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp
+++ b/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp
@@ -137,41 +137,50 @@ class MapInfoFinalizationPass
!fir::factory::isOptionalArgument(descriptor.getDefiningOp()))
return descriptor;
- mlir::Value &slot = localBoxAllocas[descriptor.getDefiningOp()];
- if (slot) {
- return slot;
+ mlir::Value &alloca = localBoxAllocas[descriptor.getDefiningOp()];
+ mlir::Location loc = boxMap->getLoc();
+
+ if (!alloca) {
+ // The fir::BoxOffsetOp only works with !fir.ref<!fir.box<...>> types, as
+ // allowing it to access non-reference box operations can cause some
+ // problematic SSA IR. However, in the case of assumed shape's the type
+ // is not a !fir.ref, in these cases to retrieve the appropriate
+ // !fir.ref<!fir.box<...>> to access the data we need to map we must
+ // perform an alloca and then store to it and retrieve the data from the
+ // new alloca.
+ mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
+ mlir::Block *allocaBlock = builder.getAllocaBlock();
+ assert(allocaBlock && "No alloca block found for this top level op");
+ builder.setInsertionPointToStart(allocaBlock);
+
+ mlir::Type allocaType = descriptor.getType();
+ if (fir::isBoxAddress(allocaType))
+ allocaType = fir::unwrapRefType(allocaType);
+ alloca = fir::AllocaOp::create(builder, loc, allocaType);
+ builder.restoreInsertionPoint(insPt);
}
- // The fir::BoxOffsetOp only works with !fir.ref<!fir.box<...>> types, as
- // allowing it to access non-reference box operations can cause some
- // problematic SSA IR. However, in the case of assumed shape's the type
- // is not a !fir.ref, in these cases to retrieve the appropriate
- // !fir.ref<!fir.box<...>> to access the data we need to map we must
- // perform an alloca and then store to it and retrieve the data from the new
- // alloca.
- mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
- mlir::Block *allocaBlock = builder.getAllocaBlock();
- mlir::Location loc = boxMap->getLoc();
- assert(allocaBlock && "No alloca block found for this top level op");
- builder.setInsertionPointToStart(allocaBlock);
-
- mlir::Type allocaType = descriptor.getType();
- if (fir::isBoxAddress(allocaType))
- allocaType = fir::unwrapRefType(allocaType);
- auto alloca = builder.create<fir::AllocaOp>(loc, allocaType);
- builder.restoreInsertionPoint(insPt);
// We should only emit a store if the passed in data is present, it is
// possible a user passes in no argument to an optional parameter, in which
// case we cannot store or we'll segfault on the emitted memcpy.
+ // TODO: We currently emit a present -> load/store every time we use a
+ // mapped value that requires a local allocation, this isn't the most
+ // efficient, although, it is more correct in a lot of situations. One
+ // such situation is emitting a this series of instructions in separate
+ // segments of a branch (e.g. two target regions in separate else/if branch
+ // mapping the same function argument), however, it would be nice to be able
+ // to optimize these situations e.g. raising the load/store out of the
+ // branch if possible. But perhaps this is best left to lower level
+ // optimisation passes.
auto isPresent =
- builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), descriptor);
+ fir::IsPresentOp::create(builder, loc, builder.getI1Type(), descriptor);
builder.genIfOp(loc, {}, isPresent, false)
.genThen([&]() {
descriptor = builder.loadIfRef(loc, descriptor);
- builder.create<fir::StoreOp>(loc, descriptor, alloca);
+ fir::StoreOp::create(builder, loc, descriptor, alloca);
})
.end();
- return slot = alloca;
+ return alloca;
}
/// Function that generates a FIR operation accessing the descriptor's
@@ -183,8 +192,8 @@ class MapInfoFinalizationPass
int64_t mapType,
fir::FirOpBuilder &builder) {
mlir::Location loc = descriptor.getLoc();
- mlir::Value baseAddrAddr = builder.create<fir::BoxOffsetOp>(
- loc, descriptor, fir::BoxFieldAttr::base_addr);
+ mlir::Value baseAddrAddr = fir::BoxOffsetOp::create(
+ builder, loc, descriptor, fir::BoxFieldAttr::base_addr);
mlir::Type underlyingVarType =
llvm::cast<mlir::omp::PointerLikeType>(
@@ -195,8 +204,8 @@ class MapInfoFinalizationPass
underlyingVarType = seqType.getEleTy();
// Member of the descriptor pointing at the allocated data
- return builder.create<mlir::omp::MapInfoOp>(
- loc, baseAddrAddr.getType(), descriptor,
+ return mlir::omp::MapInfoOp::create(
+ builder, loc, baseAddrAddr.getType(), descriptor,
mlir::TypeAttr::get(underlyingVarType),
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(
@@ -293,12 +302,12 @@ class MapInfoFinalizationPass
mlir::Value boxChar = op.getVarPtr();
if (mlir::isa<fir::ReferenceType>(op.getVarPtr().getType()))
- boxChar = builder.create<fir::LoadOp>(loc, op.getVarPtr());
+ boxChar = fir::LoadOp::create(builder, loc, op.getVarPtr());
fir::BoxCharType boxCharType =
mlir::dyn_cast<fir::BoxCharType>(boxChar.getType());
- mlir::Value boxAddr = builder.create<fir::BoxOffsetOp>(
- loc, op.getVarPtr(), fir::BoxFieldAttr::base_addr);
+ mlir::Value boxAddr = fir::BoxOffsetOp::create(
+ builder, loc, op.getVarPtr(), fir::BoxFieldAttr::base_addr);
uint64_t mapTypeToImplicit = static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
@@ -310,8 +319,8 @@ class MapInfoFinalizationPass
newMembersAttr = builder.create2DI64ArrayAttr(memberIdx);
mlir::Value varPtr = op.getVarPtr();
- mlir::omp::MapInfoOp memberMapInfoOp = builder.create<mlir::omp::MapInfoOp>(
- op.getLoc(), varPtr.getType(), varPtr,
+ mlir::omp::MapInfoOp memberMapInfoOp = mlir::omp::MapInfoOp::create(
+ builder, op.getLoc(), varPtr.getType(), varPtr,
mlir::TypeAttr::get(boxCharType.getEleTy()),
builder.getIntegerAttr(builder.getIntegerType(64, /*isSigned=*/false),
mapTypeToImplicit),
@@ -324,8 +333,8 @@ class MapInfoFinalizationPass
/*mapperId=*/mlir::FlatSymbolRefAttr(), /*name=*/op.getNameAttr(),
builder.getBoolAttr(false));
- mlir::omp::MapInfoOp newMapInfoOp = builder.create<mlir::omp::MapInfoOp>(
- op.getLoc(), op.getResult().getType(), varPtr,
+ mlir::omp::MapInfoOp newMapInfoOp = mlir::omp::MapInfoOp::create(
+ builder, op.getLoc(), op.getResult().getType(), varPtr,
mlir::TypeAttr::get(
llvm::cast<mlir::omp::PointerLikeType>(varPtr.getType())
.getElementType()),
@@ -425,16 +434,15 @@ class MapInfoFinalizationPass
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS);
}
- mlir::omp::MapInfoOp newDescParentMapOp =
- builder.create<mlir::omp::MapInfoOp>(
- op->getLoc(), op.getResult().getType(), descriptor,
- mlir::TypeAttr::get(fir::unwrapRefType(descriptor.getType())),
- builder.getIntegerAttr(builder.getIntegerType(64, false),
- getDescriptorMapType(mapType, target)),
- op.getMapCaptureTypeAttr(), /*varPtrPtr=*/mlir::Value{}, newMembers,
- newMembersAttr, /*bounds=*/mlir::SmallVector<mlir::Value>{},
- /*mapperId*/ mlir::FlatSymbolRefAttr(), op.getNameAttr(),
- /*partial_map=*/builder.getBoolAttr(false));
+ mlir::omp::MapInfoOp newDescParentMapOp = mlir::omp::MapInfoOp::create(
+ builder, op->getLoc(), op.getResult().getType(), descriptor,
+ mlir::TypeAttr::get(fir::unwrapRefType(descriptor.getType())),
+ builder.getIntegerAttr(builder.getIntegerType(64, false),
+ getDescriptorMapType(mapType, target)),
+ op.getMapCaptureTypeAttr(), /*varPtrPtr=*/mlir::Value{}, newMembers,
+ newMembersAttr, /*bounds=*/mlir::SmallVector<mlir::Value>{},
+ /*mapperId*/ mlir::FlatSymbolRefAttr(), op.getNameAttr(),
+ /*partial_map=*/builder.getBoolAttr(false));
op.replaceAllUsesWith(newDescParentMapOp.getResult());
op->erase();
return newDescParentMapOp;
@@ -739,8 +747,8 @@ class MapInfoFinalizationPass
builder.setInsertionPoint(op);
fir::IntOrValue idxConst =
mlir::IntegerAttr::get(builder.getI32Type(), fieldIdx);
- auto fieldCoord = builder.create<fir::CoordinateOp>(
- op.getLoc(), builder.getRefType(memTy), op.getVarPtr(),
+ auto fieldCoord = fir::CoordinateOp::create(
+ builder, op.getLoc(), builder.getRefType(memTy), op.getVarPtr(),
llvm::SmallVector<fir::IntOrValue, 1>{idxConst});
fir::factory::AddrAndBoundsInfo info =
fir::factory::getDataOperandBaseAddr(
@@ -754,21 +762,20 @@ class MapInfoFinalizationPass
.first,
/*dataExvIsAssumedSize=*/false, op.getLoc());
- mlir::omp::MapInfoOp fieldMapOp =
- builder.create<mlir::omp::MapInfoOp>(
- op.getLoc(), fieldCoord.getResult().getType(),
- fieldCoord.getResult(),
- mlir::TypeAttr::get(
- fir::unwrapRefType(fieldCoord.getResult().getType())),
- op.getMapTypeAttr(),
- builder.getAttr<mlir::omp::VariableCaptureKindAttr>(
- mlir::omp::VariableCaptureKind::ByRef),
- /*varPtrPtr=*/mlir::Value{}, /*members=*/mlir::ValueRange{},
- /*members_index=*/mlir::ArrayAttr{}, bounds,
- /*mapperId=*/mlir::FlatSymbolRefAttr(),
- builder.getStringAttr(op.getNameAttr().strref() + "." +
- field + ".implicit_map"),
- /*partial_map=*/builder.getBoolAttr(false));
+ mlir::omp::MapInfoOp fieldMapOp = mlir::omp::MapInfoOp::create(
+ builder, op.getLoc(), fieldCoord.getResult().getType(),
+ fieldCoord.getResult(),
+ mlir::TypeAttr::get(
+ fir::unwrapRefType(fieldCoord.getResult().getType())),
+ op.getMapTypeAttr(),
+ builder.getAttr<mlir::omp::VariableCaptureKindAttr>(
+ mlir::omp::VariableCaptureKind::ByRef),
+ /*varPtrPtr=*/mlir::Value{}, /*members=*/mlir::ValueRange{},
+ /*members_index=*/mlir::ArrayAttr{}, bounds,
+ /*mapperId=*/mlir::FlatSymbolRefAttr(),
+ builder.getStringAttr(op.getNameAttr().strref() + "." + field +
+ ".implicit_map"),
+ /*partial_map=*/builder.getBoolAttr(false));
newMapOpsForFields.emplace_back(fieldMapOp);
fieldIndicies.emplace_back(fieldIdx);
}
diff --git a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
index 19566af..3a802ef 100644
--- a/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
+++ b/flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
@@ -80,9 +80,9 @@ class MapsForPrivatizedSymbolsPass
mlir::Block *allocaBlock = builder.getAllocaBlock();
assert(allocaBlock && "No allocablock found for a funcOp");
builder.setInsertionPointToStart(allocaBlock);
- auto alloca = builder.create<fir::AllocaOp>(loc, varPtr.getType());
+ auto alloca = fir::AllocaOp::create(builder, loc, varPtr.getType());
builder.restoreInsertionPoint(savedInsPoint);
- builder.create<fir::StoreOp>(loc, varPtr, alloca);
+ fir::StoreOp::create(builder, loc, varPtr, alloca);
varPtr = alloca;
}
assert(mlir::isa<omp::PointerLikeType>(varPtr.getType()) &&
@@ -94,8 +94,8 @@ class MapsForPrivatizedSymbolsPass
if (needsBoundsOps(varPtr))
genBoundsOps(builder, varPtr, boundsOps);
- return builder.create<omp::MapInfoOp>(
- loc, varPtr.getType(), varPtr,
+ return omp::MapInfoOp::create(
+ builder, loc, varPtr.getType(), varPtr,
TypeAttr::get(llvm::cast<omp::PointerLikeType>(varPtr.getType())
.getElementType()),
builder.getIntegerAttr(builder.getIntegerType(64, /*isSigned=*/false),
diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt
index 7ccdd4f..38038e1 100644
--- a/flang/lib/Optimizer/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/Support/CMakeLists.txt
@@ -1,6 +1,3 @@
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
-
add_flang_library(FIRSupport
DataLayout.cpp
InitFIR.cpp
@@ -23,12 +20,12 @@ add_flang_library(FIRSupport
${extension_libs}
MLIR_LIBS
- ${dialect_libs}
- ${extension_libs}
MLIRBuiltinToLLVMIRTranslation
+ MLIRLLVMToLLVMIRTranslation
MLIROpenACCToLLVMIRTranslation
MLIROpenMPToLLVMIRTranslation
- MLIRLLVMToLLVMIRTranslation
+ MLIRRegisterAllDialects
+ MLIRRegisterAllExtensions
MLIRTargetLLVMIRExport
MLIRTargetLLVMIRImport
)
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/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
index 3d84eaa..2fcff87 100644
--- a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
@@ -41,6 +41,23 @@ mangleExternalName(const std::pair<fir::NameUniquer::NameKind,
appendUnderscore);
}
+/// Process a symbol reference and return the updated symbol reference if
+/// needed.
+std::optional<mlir::SymbolRefAttr>
+processSymbolRef(mlir::SymbolRefAttr symRef, mlir::Operation *nestedOp,
+ const llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr>
+ &remappings) {
+ if (auto remap = remappings.find(symRef.getLeafReference());
+ remap != remappings.end()) {
+ mlir::SymbolRefAttr symAttr = mlir::FlatSymbolRefAttr(remap->second);
+ if (mlir::isa<mlir::gpu::LaunchFuncOp>(nestedOp))
+ symAttr = mlir::SymbolRefAttr::get(
+ symRef.getRootReference(), {mlir::FlatSymbolRefAttr(remap->second)});
+ return symAttr;
+ }
+ return std::nullopt;
+}
+
namespace {
class ExternalNameConversionPass
@@ -97,21 +114,40 @@ void ExternalNameConversionPass::runOnOperation() {
// Update all uses of the functions and globals that have been renamed.
op.walk([&remappings](mlir::Operation *nestedOp) {
- llvm::SmallVector<std::pair<mlir::StringAttr, mlir::SymbolRefAttr>> updates;
+ llvm::SmallVector<std::pair<mlir::StringAttr, mlir::SymbolRefAttr>>
+ symRefUpdates;
+ llvm::SmallVector<std::pair<mlir::StringAttr, mlir::ArrayAttr>>
+ arrayUpdates;
for (const mlir::NamedAttribute &attr : nestedOp->getAttrDictionary())
if (auto symRef = llvm::dyn_cast<mlir::SymbolRefAttr>(attr.getValue())) {
- if (auto remap = remappings.find(symRef.getLeafReference());
- remap != remappings.end()) {
- mlir::SymbolRefAttr symAttr = mlir::FlatSymbolRefAttr(remap->second);
- if (mlir::isa<mlir::gpu::LaunchFuncOp>(nestedOp))
- symAttr = mlir::SymbolRefAttr::get(
- symRef.getRootReference(),
- {mlir::FlatSymbolRefAttr(remap->second)});
- updates.emplace_back(std::pair<mlir::StringAttr, mlir::SymbolRefAttr>{
- attr.getName(), symAttr});
+ if (auto newSymRef = processSymbolRef(symRef, nestedOp, remappings))
+ symRefUpdates.emplace_back(
+ std::pair<mlir::StringAttr, mlir::SymbolRefAttr>{attr.getName(),
+ *newSymRef});
+ } else if (auto arrayAttr =
+ llvm::dyn_cast<mlir::ArrayAttr>(attr.getValue())) {
+ llvm::SmallVector<mlir::Attribute> symbolRefs;
+ for (auto element : arrayAttr) {
+ if (!element) {
+ symbolRefs.push_back(element);
+ continue;
+ }
+ auto symRef = llvm::dyn_cast<mlir::SymbolRefAttr>(element);
+ std::optional<mlir::SymbolRefAttr> updatedSymRef;
+ if (symRef)
+ updatedSymRef = processSymbolRef(symRef, nestedOp, remappings);
+ if (!symRef || !updatedSymRef)
+ symbolRefs.push_back(element);
+ else
+ symbolRefs.push_back(*updatedSymRef);
}
+ arrayUpdates.push_back(std::make_pair(
+ attr.getName(),
+ mlir::ArrayAttr::get(nestedOp->getContext(), symbolRefs)));
}
- for (auto update : updates)
+ for (auto update : symRefUpdates)
+ nestedOp->setAttr(update.first, update.second);
+ for (auto update : arrayUpdates)
nestedOp->setAttr(update.first, update.second);
});
}
diff --git a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp
index f06ad2d..1902757 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(),
@@ -87,13 +87,52 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> {
return success();
}
};
+
+void copyBlockAndTransformResult(PatternRewriter &rewriter, Block &srcBlock,
+ Block &dstBlock) {
+ Operation *srcTerminator = srcBlock.getTerminator();
+ auto resultOp = cast<fir::ResultOp>(srcTerminator);
+
+ dstBlock.getOperations().splice(dstBlock.begin(), srcBlock.getOperations(),
+ srcBlock.begin(), std::prev(srcBlock.end()));
+
+ if (!resultOp->getOperands().empty()) {
+ rewriter.setInsertionPointToEnd(&dstBlock);
+ scf::YieldOp::create(rewriter, resultOp->getLoc(), resultOp->getOperands());
+ }
+
+ rewriter.eraseOp(srcTerminator);
+}
+
+struct IfConversion : public OpRewritePattern<fir::IfOp> {
+ using OpRewritePattern<fir::IfOp>::OpRewritePattern;
+ LogicalResult matchAndRewrite(fir::IfOp ifOp,
+ PatternRewriter &rewriter) const override {
+ bool hasElse = !ifOp.getElseRegion().empty();
+ auto scfIfOp =
+ scf::IfOp::create(rewriter, ifOp.getLoc(), ifOp.getResultTypes(),
+ ifOp.getCondition(), hasElse);
+
+ copyBlockAndTransformResult(rewriter, ifOp.getThenRegion().front(),
+ scfIfOp.getThenRegion().front());
+
+ if (hasElse) {
+ copyBlockAndTransformResult(rewriter, ifOp.getElseRegion().front(),
+ scfIfOp.getElseRegion().front());
+ }
+
+ scfIfOp->setAttrs(ifOp->getAttrs());
+ rewriter.replaceOp(ifOp, scfIfOp);
+ return success();
+ }
+};
} // namespace
void FIRToSCFPass::runOnOperation() {
RewritePatternSet patterns(&getContext());
- patterns.add<DoLoopConversion>(patterns.getContext());
+ patterns.add<DoLoopConversion, IfConversion>(patterns.getContext());
ConversionTarget target(getContext());
- target.addIllegalOp<fir::DoLoopOp>();
+ target.addIllegalOp<fir::DoLoopOp, fir::IfOp>();
target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns))))
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 bc4fcd8..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, mlir::TypeRange{}, 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 6e45aae..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, mlir::ValueRange{});
+ 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 ad8464b..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 &region,
mlir::ValueRange regionArgs,
@@ -258,8 +258,8 @@ 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=*/mlir::ValueRange{}, loop.getReduceVars(),
loop.getReduceAttrsAttr());
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);