diff --git a/flang/lib/Optimizer/Builder/CUFCommon.cpp b/flang/lib/Optimizer/Builder/CUFCommon.cpp index dcbf4991907bf..cf7588f275d22 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(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(addrOfOp.getSymbol())) { if (cuf::isRegisteredDeviceGlobal(globalOp)) { - builder.create(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 61428ac490a46..a096099a04fe8 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(loc, charTy); - builder.create(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(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(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(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( - 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(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(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(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(loc, buff.getType()); - builder.create(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(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(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(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(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( - 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( - 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( - loc, mlir::arith::CmpIPredicate::slt, a, b); - return builder.create(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(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(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(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(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(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(loc, box.getLen(), castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, box.getLen(), castBounds[0]); } else { substringLen = - builder.create(loc, castBounds[1], castBounds[0]); + mlir::arith::SubIOp::create(builder, loc, castBounds[1], castBounds[0]); } - substringLen = builder.create(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( - loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); + auto cdt = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, substringLen, zero); substringLen = - builder.create(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(loc, len, one); + mlir::Value lastChar = mlir::arith::SubIOp::create(builder, loc, len, one); auto iterWhile = - builder.create(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(loc, codeAddr); - auto isBlank = builder.create( - 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 results = {isBlank, index}; - builder.create(loc, results); + fir::ResultOp::create(builder, loc, results); builder.restoreInsertionPoint(insPt); // Compute length after iteration (zero if all blanks) mlir::Value newLen = - builder.create(loc, iterWhile.getResult(1), one); - auto result = builder.create( - 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(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(loc, charType); + auto undef = fir::UndefOp::create(builder, loc, charType); auto zero = builder.getIntegerAttr(builder.getIndexType(), 0); - return builder.create(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(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(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(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(tuple.getType()); - mlir::Value addr = builder.create( - 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(addr.getType())) - return builder.create(loc, addrTy.getEleTy(), addr); + return fir::BoxAddrOp::create(builder, loc, addrTy.getEleTy(), addr); return addr; }(); - mlir::Value len = builder.create( - 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(loc, tupleType.getType(1)); - mlir::Value tuple = builder.create(loc, tupleType); - tuple = builder.create( - 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( - 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( - loc, mlir::arith::CmpIPredicate::uge, biggestLen, currLen); - biggestLen = builder.create(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(loc, resultCmp, currBuf, - resultBuf); - resultLen = builder.create(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(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(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(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 69f97dd654ce0..61de9880774ac 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(loc, cplxTy); + mlir::Value und = fir::UndefOp::create(builder, loc, cplxTy); return insert(insert(und, real), imag); } diff --git a/flang/lib/Optimizer/Builder/DoLoopHelper.cpp b/flang/lib/Optimizer/Builder/DoLoopHelper.cpp index 4b12e281b5153..0ec91d5883b92 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(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(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 5b1dbc4435d6c..eaad54eb9eec2 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 typeParams, fir::FortranVariableFlagsAttr fortranAttrs) { auto nameAttr = mlir::StringAttr::get(builder.getContext(), name); - return builder.create(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(val.getType()).getTypeList() == mlir::cast(toTy).getTypeList()) && "incompatible record types"); - return builder.create(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(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(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(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 getFromBox(mlir::Location loc, } else if (auto charTy = mlir::dyn_cast(eleTy)) { if (charTy.hasDynamicLen()) { auto idxTy = builder.getIndexType(); - auto eleSz = builder.create(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(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(loc, stringLitOp); + fir::HasValueOp::create(builder, loc, stringLitOp); }, builder.createLinkOnceLinkage()); - auto addr = builder.create(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(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(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(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( - 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( - loc, rFieldRefType, fir::getBase(rhs), rField); - mlir::Value field = builder.create( - 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( - loc, fieldRefType, fir::getBase(lhs), field); + mlir::Value toCoor = fir::CoordinateOp::create(builder, loc, fieldRefType, + fir::getBase(lhs), field); std::optional outerLoop; if (auto sequenceType = mlir::dyn_cast(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(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(loc, elementRefType, toCoor, - indices); - fromCoor = builder.create(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(fieldEleTy)) { assert(mlir::isa( mlir::cast(fieldEleTy).getEleTy()) && "allocatable members require deep copy"); - auto fromPointerValue = builder.create(loc, fromCoor); + auto fromPointerValue = fir::LoadOp::create(builder, loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); - builder.create(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(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(loc, upper, lower); + auto diff = mlir::arith::SubIOp::create(builder, loc, upper, lower); auto one = builder.createIntegerConstant(loc, idxTy, 1); - auto size = builder.create(loc, diff, one); - auto cmp = builder.create( - loc, mlir::arith::CmpIPredicate::sgt, size, zero); - return builder.create(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(memref.getType())) - return builder.create(loc, idxTy, memref); + return fir::BoxCharLenOp::create(builder, loc, idxTy, memref); if (mlir::isa(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(definingOp)) if (auto intAttr = mlir::dyn_cast(cst.getValue())) return intAttr.getInt() > 0 ? value : zero; - mlir::Value valueIsGreater = builder.create( - loc, mlir::arith::CmpIPredicate::sgt, value, zero); - return builder.create(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 - + 1` case. - auto diff = builder.create(loc, type, ub, lb); - auto rawExtent = builder.create(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( - 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(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( - loc, fieldIndexType, cptrFieldName, recTy, + mlir::Value cptrFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, cptrFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - auto cptrCoord = builder.create( - 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(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( - 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(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(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(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(loc, boxEleTy)}; - return builder.create(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 fir::factory::updateRuntimeExtentsForEmptyArrays( mlir::Type type = extent.getType(); mlir::Value zero = createZeroValue(builder, loc, type); zeroes.push_back(zero); - mlir::Value isZero = builder.create( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); - isEmpty = builder.create(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 newExtents; for (auto [zero, extent] : llvm::zip_equal(zeroes, extents)) { newExtents.push_back( - builder.create(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(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(loc, ptrTy, alloc.getResult()); - builder.create(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(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 fb6f0dbf719fb..c3948f2caf67b 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(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(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(boxChar.getType()).getEleTy()); - auto unboxed = builder.create( - 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()) @@ -278,8 +278,9 @@ hlfir::genDeclare(mlir::Location loc, fir::FirOpBuilder &builder, box.nonDeferredLenParams().end()); }, [](const auto &) {}); - auto declareOp = builder.create( - 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(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(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(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(loc, baseAddr); + baseAddr = fir::LoadOp::create(builder, loc, baseAddr); // Get raw address. if (mlir::isa(var.getType())) baseAddr = genUnboxChar(loc, builder, var.getBase()).getAddr(); if (mlir::isa(baseAddr.getType())) - baseAddr = builder.create(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(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(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(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(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 lenParams; genLengthParameters(loc, builder, entity, lenParams); if (mlir::isa(entity.getType())) - return hlfir::Entity{builder.create( - 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(loc, lbIdx, one); + auto shift = mlir::arith::SubIOp::create(builder, loc, lbIdx, one); mlir::Value index = - builder.create(loc, oneBasedIdx, shift); + mlir::arith::AddIOp::create(builder, loc, oneBasedIdx, shift); indices.push_back(index); } - designate = builder.create(loc, resultType, entity, - indices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + indices, lenParams); } else { - designate = builder.create(loc, resultType, entity, - oneBasedIndices, lenParams); + designate = hlfir::DesignateOp::create(builder, loc, resultType, entity, + oneBasedIndices, lenParams); } return mlir::cast(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(loc, lb, extent); - return builder.create(loc, add, one); + auto add = mlir::arith::AddIOp::create(builder, loc, lb, extent); + return mlir::arith::SubIOp::create(builder, loc, add, one); } llvm::SmallVector> @@ -557,8 +557,8 @@ static mlir::Value computeVariableExtent(mlir::Location loc, assert(mlir::isa(variable.getType()) && "array variable with dynamic extent must be boxed"); mlir::Value dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create(loc, idxTy, idxTy, idxTy, - variable, dimVal); + auto dimInfo = fir::BoxDimsOp::create(builder, loc, idxTy, idxTy, idxTy, + variable, dimVal); return dimInfo.getExtent(); } llvm::SmallVector getVariableExtents(mlir::Location loc, @@ -608,14 +608,14 @@ mlir::Value hlfir::genShape(mlir::Location loc, fir::FirOpBuilder &builder, return shape; if (mlir::isa(shape.getType())) if (auto s = shape.getDefiningOp()) - return builder.create(loc, s.getExtents()); + return fir::ShapeOp::create(builder, loc, s.getExtents()); } if (mlir::isa(entity.getType())) - return builder.create(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(loc, - getVariableExtents(loc, builder, entity)); + return fir::ShapeOp::create(builder, loc, + getVariableExtents(loc, builder, entity)); } llvm::SmallVector @@ -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(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(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(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(loc, entity)}; + hlfir::Entity boxLoad{fir::LoadOp::create(builder, loc, entity)}; if (entity.isScalar()) { if (!entity.isPolymorphic() && !entity.hasLengthParameters()) - return hlfir::Entity{builder.create(loc, boxLoad)}; + return hlfir::Entity{fir::BoxAddrOp::create(builder, loc, boxLoad)}; mlir::Type elementType = boxLoad.getFortranElementType(); if (auto charType = mlir::dyn_cast(elementType)) { - mlir::Value base = builder.create(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(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(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( - 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(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(loc, 1); + auto one = mlir::arith::ConstantIndexOp::create(builder, loc, 1); mlir::Type indexType = builder.getIndexType(); if (emitWorkshareLoop) { - auto wslw = builder.create(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(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(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(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 hlfir::genLoopNestWithReductions( bool isUnordered) { assert(!extents.empty() && "must have at least one extent"); // Build loop nest from column to row. - auto one = builder.create(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 hlfir::genLoopNestWithReductions( // of its parent loop. fir::DoLoopOp doLoop; if (!parentLoop) { - doLoop = builder.create(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(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(loc, doLoop.getResults()); + fir::ResultOp::create(builder, loc, doLoop.getResults()); } } @@ -1044,7 +1043,7 @@ llvm::SmallVector hlfir::genLoopNestWithReductions( genBody(loc, builder, oneBasedIndices, parentLoop.getRegionIterArgs()); builder.setInsertionPointToEnd(parentLoop.getBody()); if (!reductionValues.empty()) - builder.create(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(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( - 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(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(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 absentValues; for (mlir::Type resTy : ifOp->getResultTypes()) { if (fir::isa_ref_type(resTy) || fir::isa_box_type(resTy)) - absentValues.emplace_back(builder.create(loc, resTy)); + absentValues.emplace_back(fir::AbsentOp::create(builder, loc, resTy)); else - absentValues.emplace_back(builder.create(loc, resTy)); + absentValues.emplace_back(fir::ZeroOp::create(builder, loc, resTy)); } - builder.create(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( - 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(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 typeParams, fir::FortranVariableFlagsAttr attrs) -> mlir::Value { auto declareOp = - builder.create(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(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( - 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(loc, shapeShiftType, lbAndExtents); - auto declareOp = builder.create( - 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(declareOp.getOperation()); @@ -1536,8 +1535,8 @@ std::pair hlfir::computeEvaluateOpInNewTemp( extents, typeParams); mlir::Value innerMemory = evalInMem.getMemory(); temp = builder.createConvert(loc, innerMemory.getType(), temp); - auto declareOp = builder.create( - 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(loc, extents[dim - 1]); + fir::ShapeOp::create(builder, loc, extents[dim - 1]); // The result type is one of: // !fir.box/class> @@ -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( - 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 d77a656158a37..323d2fe1ac16f 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -1110,7 +1110,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, // was just created from user functions with the same name. funcOp->setAttr(fir::FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr()); - auto libCall = builder.create(loc, funcOp, args); + auto libCall = fir::CallOp::create(builder, loc, funcOp, args); // TODO: ensure 'strictfp' setting on the call for "precise/strict" // FP mode. Set appropriate Fast-Math Flags otherwise. // TODO: we should also mark as many libm function as possible @@ -1124,7 +1124,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type soughtFuncType = funcOp.getFunctionType(); if (soughtFuncType == libFuncType) { - libCall = builder.create(loc, funcOp, args); + libCall = fir::CallOp::create(builder, loc, funcOp, args); } else { // A function with the same name might have been declared // before (e.g. with an explicit interface and a binding label). @@ -1138,13 +1138,13 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::Twine("' may lead to undefined behavior."))); mlir::SymbolRefAttr funcSymbolAttr = builder.getSymbolRefAttr(libFuncName); mlir::Value funcPointer = - builder.create(loc, soughtFuncType, funcSymbolAttr); + fir::AddrOfOp::create(builder, loc, soughtFuncType, funcSymbolAttr); funcPointer = builder.createConvert(loc, libFuncType, funcPointer); llvm::SmallVector operands{funcPointer}; operands.append(args.begin(), args.end()); - libCall = builder.create(loc, mlir::SymbolRefAttr{}, - libFuncType.getResults(), operands); + libCall = fir::CallOp::create(builder, loc, mlir::SymbolRefAttr{}, + libFuncType.getResults(), operands); } LLVM_DEBUG(libCall.dump(); llvm::dbgs() << "\n"); @@ -1220,7 +1220,7 @@ mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc, LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - result = builder.create(loc, args); + result = T::create(builder, loc, args); } LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n"); return result; @@ -1258,12 +1258,12 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc, // the argument types for an operation if constexpr (T::template hasTrait< mlir::OpTrait::SameOperandsAndResultType>()) { - result = builder.create(loc, args); + result = T::create(builder, loc, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } else { auto complexTy = mlir::cast(mathLibFuncType.getInput(0)); auto realTy = complexTy.getElementType(); - result = builder.create(loc, realTy, args); + result = T::create(builder, loc, realTy, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } @@ -2461,7 +2461,7 @@ IntrinsicLibrary::outlineInWrapper(GeneratorType generator, nameOS << '.' << fmfString; } mlir::func::FuncOp wrapper = getWrapper(generator, funcName, funcType); - return builder.create(loc, wrapper, args).getResult(0); + return fir::CallOp::create(builder, loc, wrapper, args).getResult(0); } template @@ -2477,7 +2477,7 @@ fir::ExtendedValue IntrinsicLibrary::outlineInExtendedWrapper( mlirArgs.emplace_back(toValue(extendedVal, builder, loc)); mlir::FunctionType funcType = getFunctionType(resultType, mlirArgs, builder); mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); - auto call = builder.create(loc, wrapper, mlirArgs); + auto call = fir::CallOp::create(builder, loc, wrapper, mlirArgs); if (resultType) return toExtendedValue(call.getResult(0), builder, loc); // Subroutine calls @@ -2595,9 +2595,9 @@ IntrinsicLibrary::readAndAddCleanUp(fir::MutableBoxValue resultMutableBox, return box; }, [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { - auto load = builder.create(loc, resultType, tempAddr); + auto load = fir::LoadOp::create(builder, loc, resultType, tempAddr); // Temp can be freed right away since it was loaded. - builder.create(loc, tempAddr); + fir::FreeMemOp::create(builder, loc, tempAddr); return load; }, [&](const fir::CharBoxValue &box) -> fir::ExtendedValue { @@ -2650,9 +2650,9 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, // So, implement abs here without branching. mlir::Value shift = builder.createIntegerConstant(loc, intType, intType.getWidth() - 1); - auto mask = builder.create(loc, arg, shift); - auto xored = builder.create(loc, arg, mask); - return builder.create(loc, xored, mask); + auto mask = mlir::arith::ShRSIOp::create(builder, loc, arg, shift); + auto xored = mlir::arith::XOrIOp::create(builder, loc, arg, mask); + return mlir::arith::SubIOp::create(builder, loc, xored, mask); } llvm_unreachable("unexpected type in ABS argument"); } @@ -2671,7 +2671,7 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ADJUSTL & ADJUSTR @@ -2824,7 +2824,7 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); } // ATAND, ATAN2D @@ -2838,8 +2838,8 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, // atand = atan * 180/pi if (args.size() == 2) { - atan = builder.create(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2849,7 +2849,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } // ATANPI, ATAN2PI @@ -2863,8 +2863,8 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, // atanpi = atan / pi if (args.size() == 2) { - atan = builder.create(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2874,7 +2874,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, @@ -2882,8 +2882,8 @@ static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, mlir::Value arg1) { auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); arg0 = builder.createConvert(loc, llvmPointerType, arg0); - return builder.create( - loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); + return mlir::LLVM::AtomicRMWOp::create(builder, loc, binOp, arg0, arg1, + mlir::LLVM::AtomicOrdering::seq_cst); } mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, @@ -2941,11 +2941,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, auto bitCastFloat = [&](mlir::Value arg) -> mlir::Value { if (mlir::isa(arg.getType())) - return builder.create(loc, builder.getI32Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI32Type(), + arg); if (mlir::isa(arg.getType())) - return builder.create(loc, builder.getI64Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI64Type(), + arg); return arg; }; @@ -2958,11 +2958,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, } auto address = - builder.create(loc, llvmPtrTy, arg0) + mlir::UnrealizedConversionCastOp::create(builder, loc, llvmPtrTy, arg0) .getResult(0); - auto cmpxchg = builder.create( - loc, address, arg1, arg2, successOrdering, failureOrdering); - return builder.create(loc, cmpxchg, 1); + auto cmpxchg = mlir::LLVM::AtomicCmpXchgOp::create( + builder, loc, address, arg1, arg2, successOrdering, failureOrdering); + return mlir::LLVM::ExtractValueOp::create(builder, loc, cmpxchg, 1); } mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, @@ -3038,31 +3038,31 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::isa(ptrTy))) { mlir::Value pointerBoxProc = fir::isBoxProcAddressType(ptrTy) - ? builder.create(loc, fir::getBase(args[0])) + ? fir::LoadOp::create(builder, loc, fir::getBase(args[0])) : fir::getBase(args[0]); mlir::Value pointerTarget = - builder.create(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(loc, target); + target = fir::LoadOp::create(builder, loc, target); if (mlir::isa(target.getType())) - target = builder.create(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( - 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( - 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(loc, sameTarget, notNull); + return mlir::arith::AndIOp::create(builder, loc, sameTarget, notNull); } auto *pointer = args[0].match([&](const fir::MutableBoxValue &x) { return &x; }, @@ -3075,7 +3075,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::Value targetBox = builder.createBox(loc, target); mlir::Value pointerBoxRef = fir::factory::getMutableIRBox(builder, loc, *pointer); - auto pointerBox = builder.create(loc, pointerBoxRef); + auto pointerBox = fir::LoadOp::create(builder, loc, pointerBoxRef); return fir::runtime::genAssociated(builder, loc, pointerBox, targetBox); } @@ -3106,12 +3106,12 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselJnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3123,7 +3123,7 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_JN(n2) and BESSEL_JN(n2 - 1) since they // are the anchors of the recursion. - mlir::Value n2_1 = builder.create(loc, n2, one); + mlir::Value n2_1 = mlir::arith::SubIOp::create(builder, loc, n2, one); mlir::Value bn2 = genRuntimeCall("bessel_jn", resultType, {n2, x}); mlir::Value bn2_1 = genRuntimeCall("bessel_jn", resultType, {n2_1, x}); fir::runtime::genBesselJn(builder, loc, resultBox, n1, n2, x, bn2, bn2_1); @@ -3191,12 +3191,12 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselYnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3208,7 +3208,7 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_YN(n1) and BESSEL_YN(n1 + 1) since they // are the anchors of the recursion. - mlir::Value n1_1 = builder.create(loc, n1, one); + mlir::Value n1_1 = mlir::arith::AddIOp::create(builder, loc, n1, one); mlir::Value bn1 = genRuntimeCall("bessel_yn", resultType, {n1, x}); mlir::Value bn1_1 = genRuntimeCall("bessel_yn", resultType, {n1_1, x}); fir::runtime::genBesselYn(builder, loc, resultBox, n1, n2, x, bn1, bn1_1); @@ -3280,12 +3280,12 @@ IntrinsicLibrary::genBitwiseCompare(mlir::Type resultType, if (arg0Ty.isUnsignedInteger()) arg0 = builder.createConvert(loc, signlessType, arg0); else if (bits0 < widest) - arg0 = builder.create(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(loc, signlessType, arg1); - return builder.create(loc, pred, arg0, arg1); + arg1 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg1); + return mlir::arith::CmpIOp::create(builder, loc, pred, arg0, arg1); } // BTEST @@ -3304,9 +3304,9 @@ mlir::Value IntrinsicLibrary::genBtest(mlir::Type resultType, word = builder.createConvert(loc, signlessType, word); mlir::Value shiftCount = builder.createConvert(loc, signlessType, args[1]); mlir::Value shifted = - builder.create(loc, word, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, word, shiftCount); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); - mlir::Value bit = builder.create(loc, shifted, one); + mlir::Value bit = mlir::arith::AndIOp::create(builder, loc, shifted, one); return builder.createConvert(loc, resultType, bit); } @@ -3317,11 +3317,11 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder, mlir::Value addr{nullptr}; if (isFunc) { auto funcTy = mlir::cast(argValue.getType()).getEleTy(); - addr = builder.create(loc, funcTy, argValue); + addr = fir::BoxAddrOp::create(builder, loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf(); - addr = builder.create(loc, box->getMemTy(), - fir::getBase(*box)); + addr = fir::BoxAddrOp::create(builder, loc, box->getMemTy(), + fir::getBase(*box)); } return addr; } @@ -3331,7 +3331,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type resultType, llvm::ArrayRef args, bool isFunc = false, bool isDevLoc = false) { assert(args.size() == 1); - mlir::Value res = builder.create(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Value resAddr; if (isDevLoc) resAddr = fir::factory::genCDevPtrAddr(builder, loc, res, resultType); @@ -3342,7 +3342,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value argAddrVal = builder.createConvert( loc, fir::unwrapRefType(resAddr.getType()), argAddr); - builder.create(loc, argAddrVal, resAddr); + fir::StoreOp::create(builder, loc, argAddrVal, resAddr); return res; } @@ -3355,8 +3355,8 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtrVal1 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr1); mlir::Value zero = builder.createIntegerConstant(loc, cPtrVal1.getType(), 0); - mlir::Value res = builder.create( - loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); + mlir::Value res = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); if (isStaticallyPresent(args[1])) { mlir::Type i1Ty = builder.getI1Type(); @@ -3365,15 +3365,16 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, res = builder .genIfOp(loc, {i1Ty}, isDynamicallyAbsent, /*withElseRegion=*/true) - .genThen([&]() { builder.create(loc, res); }) + .genThen([&]() { fir::ResultOp::create(builder, loc, res); }) .genElse([&]() { mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); - mlir::Value cmpVal = builder.create( - 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(loc, res, cmpVal); - builder.create(loc, newRes); + mlir::arith::AndIOp::create(builder, loc, res, cmpVal); + fir::ResultOp::create(builder, loc, newRes); }) .getResults()[0]; } @@ -3428,9 +3429,9 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef 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( - loc, builder.getRefType(shapeElementType), shape, index); - mlir::Value load = builder.create(loc, var); + mlir::Value var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(shapeElementType), shape, index); + mlir::Value load = fir::LoadOp::create(builder, loc, var); extents.push_back(builder.createConvert(loc, idxType, load)); } } @@ -3474,8 +3475,8 @@ void IntrinsicLibrary::genCFProcPointer( mlir::Value cptrCast = builder.createConvert(loc, boxProcType.getEleTy(), cptr); mlir::Value cptrBox = - builder.create(loc, boxProcType, cptrCast); - builder.create(loc, cptrBox, fptr); + fir::EmboxProcOp::create(builder, loc, boxProcType, cptrCast); + fir::StoreOp::create(builder, loc, cptrBox, fptr); } // C_FUNLOC @@ -3505,7 +3506,7 @@ IntrinsicLibrary::genCPtrCompare(mlir::Type resultType, mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); mlir::Value cmp = - builder.create(loc, pred, cPtrVal1, cPtrVal2); + mlir::arith::CmpIOp::create(builder, loc, pred, cPtrVal1, cPtrVal2); return builder.createConvert(loc, resultType, cmp); } @@ -3604,7 +3605,7 @@ mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType, mlir::Value cplx = args[0]; auto imag = fir::factory::Complex{builder, loc}.extractComplexPart( cplx, /*isImagPart=*/true); - auto negImag = builder.create(loc, imag); + auto negImag = mlir::arith::NegFOp::create(builder, loc, imag); return fir::factory::Complex{builder, loc}.insertComplexPart( cplx, negImag, /*isImagPart=*/true); } @@ -3620,7 +3621,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3635,7 +3636,7 @@ mlir::Value IntrinsicLibrary::genCospi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3696,7 +3697,7 @@ void IntrinsicLibrary::genCpuTime(llvm::ArrayRef args) { mlir::Value res1 = fir::runtime::genCpuTime(builder, loc); mlir::Value res2 = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg->getType()), res1); - builder.create(loc, res2, *arg); + fir::StoreOp::create(builder, loc, res2, *arg); } // CSHIFT @@ -3723,7 +3724,7 @@ IntrinsicLibrary::genCshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar CSHIFT argument"); - auto shift = builder.create(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genCshiftVector(builder, loc, resultIrBox, array, shift); } else { @@ -3749,9 +3750,9 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, assert(args.size() == 1); mlir::Type resTy = fir::SequenceType::get(extent, resultType); mlir::Value arg = fir::getBase(args[0]); - mlir::Value res = builder.create(loc, resTy); + mlir::Value res = fir::AllocaOp::create(builder, loc, resTy); if (mlir::isa(arg.getType())) - arg = builder.create(loc, arg); + arg = fir::BoxAddrOp::create(builder, loc, arg); mlir::Type refResTy = fir::ReferenceType::get(resTy); mlir::FunctionType ftype = mlir::FunctionType::get(arg.getContext(), {refResTy, refResTy}, {}); @@ -3759,7 +3760,7 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, llvm::SmallVector funcArgs; funcArgs.push_back(res); funcArgs.push_back(arg); - builder.create(loc, funcOp, funcArgs); + fir::CallOp::create(builder, loc, funcOp, funcArgs); mlir::Value ext = builder.createIntegerConstant(loc, builder.getIndexType(), extent); return fir::ArrayBoxValue(res, {ext}); @@ -3775,8 +3776,8 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef args) { mlir::Value values = fir::getBase(args[3]); if (!values) - values = builder.create( - loc, fir::BoxType::get(builder.getNoneType())); + values = fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())); fir::runtime::genDateAndTime(builder, loc, charArgs[0], charArgs[1], charArgs[2], values); @@ -3788,17 +3789,17 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, assert(args.size() == 2); if (mlir::isa(resultType)) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto diff = builder.create(loc, args[0], args[1]); - auto cmp = builder.create( - loc, mlir::arith::CmpIPredicate::sgt, diff, zero); - return builder.create(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(loc, args[0], args[1]); - auto cmp = builder.create( - loc, mlir::arith::CmpFPredicate::OGT, diff, zero); - return builder.create(loc, cmp, diff, zero); + auto diff = mlir::arith::SubFOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } // DOT_PRODUCT @@ -3816,12 +3817,13 @@ IntrinsicLibrary::genDotProduct(mlir::Type resultType, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, result); - return builder.create(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(loc, fir::BoxType::get(eleTy)); + auto resultBox = + fir::AbsentOp::create(builder, loc, fir::BoxType::get(eleTy)); return fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, resultBox); } @@ -3833,7 +3835,7 @@ mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType, "Result must be double precision in DPROD"); mlir::Value a = builder.createConvert(loc, resultType, args[0]); mlir::Value b = builder.createConvert(loc, resultType, args[1]); - return builder.create(loc, a, b); + return mlir::arith::MulFOp::create(builder, loc, a, b); } // DSHIFTL @@ -3856,14 +3858,14 @@ mlir::Value IntrinsicLibrary::genDshiftl(mlir::Type resultType, // Per the standard, the value of DSHIFTL(I, J, SHIFT) is equal to // IOR (SHIFTL(I, SHIFT), SHIFTR(J, BIT_SIZE(J) - SHIFT)) - mlir::Value diff = builder.create(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, shift}; mlir::Value lft = genShift(signlessType, lArgs); mlir::Value rArgs[2]{j, diff}; mlir::Value rgt = genShift(signlessType, rArgs); - mlir::Value result = builder.create(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3889,14 +3891,14 @@ mlir::Value IntrinsicLibrary::genDshiftr(mlir::Type resultType, // Per the standard, the value of DSHIFTR(I, J, SHIFT) is equal to // IOR (SHIFTL(I, BIT_SIZE(I) - SHIFT), SHIFTR(J, SHIFT)) - mlir::Value diff = builder.create(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, diff}; mlir::Value lft = genShift(signlessType, lArgs); mlir::Value rArgs[2]{j, shift}; mlir::Value rgt = genShift(signlessType, rArgs); - mlir::Value result = builder.create(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3924,8 +3926,8 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle optional BOUNDARY argument mlir::Value boundary = isStaticallyAbsent(args[2]) - ? builder.create( - loc, fir::BoxType::get(builder.getNoneType())) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())) : builder.createBox(loc, args[2]); if (arrayRank == 1) { @@ -3933,7 +3935,7 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar EOSHIFT SHIFT argument"); - auto shift = builder.create(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genEoshiftVector(builder, loc, resultIrBox, array, shift, boundary); } else { @@ -3981,14 +3983,15 @@ void IntrinsicLibrary::genExecuteCommandLine( .genIfOp(loc, {i1Ty}, waitIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto waitLoad = builder.create(loc, waitAddr); + auto waitLoad = + fir::LoadOp::create(builder, loc, waitAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, waitLoad); - builder.create(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -3996,15 +3999,15 @@ void IntrinsicLibrary::genExecuteCommandLine( mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdstatBox = isStaticallyPresent(cmdstat) ? fir::getBase(cmdstat) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdmsgBox = isStaticallyPresent(cmdmsg) ? fir::getBase(cmdmsg) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); } @@ -4025,7 +4028,7 @@ IntrinsicLibrary::genEtime(std::optional resultType, auto timeAddr = builder.createTemporary(loc, *resultType); auto timeBox = builder.createBox(loc, timeAddr); fir::runtime::genEtime(builder, loc, values, timeBox); - return builder.create(loc, timeAddr); + return fir::LoadOp::create(builder, loc, timeAddr); } else { // subroutine form mlir::Value time = fir::getBase(args[1]); @@ -4098,8 +4101,8 @@ IntrinsicLibrary::genFindloc(mlir::Type resultType, // Handle optional mask argument auto mask = isStaticallyAbsent(args[3]) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); // Handle optional kind argument @@ -4288,15 +4291,15 @@ void IntrinsicLibrary::genGetCommand(llvm::ArrayRef args) { mlir::Value commandBox = isStaticallyPresent(command) ? fir::getBase(command) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommand(builder, loc, commandBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4355,15 +4358,15 @@ void IntrinsicLibrary::genGetCommandArgument( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommandArgument( builder, loc, number, valBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4408,13 +4411,14 @@ void IntrinsicLibrary::genGetEnvironmentVariable( .genIfOp(loc, {i1Ty}, trimNameIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto trimLoad = builder.create(loc, trimNameAddr); + auto trimLoad = + fir::LoadOp::create(builder, loc, trimNameAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, trimLoad); - builder.create(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -4423,15 +4427,15 @@ void IntrinsicLibrary::genGetEnvironmentVariable( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetEnvVariable(builder, loc, name, valBox, lenBox, trim, errBox); if (isStaticallyPresent(status)) { @@ -4516,8 +4520,8 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -4531,10 +4535,10 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); - return builder.create(loc, result); + return fir::LoadOp::create(builder, loc, result); } - auto resultBox = builder.create( - loc, fir::BoxType::get(builder.getI1Type())); + auto resultBox = fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())); return func(builder, loc, array, mask, resultBox); } // Handle Product/Sum cases that have an array result. @@ -4581,8 +4585,8 @@ mlir::Value IntrinsicLibrary::genIbclr(mlir::Type resultType, mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value bit = builder.create(loc, one, pos); - mlir::Value mask = builder.create(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(loc, resultType, args[0], mask); } @@ -4610,18 +4614,18 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast(resultType).getWidth()); mlir::Value shiftCount = - builder.create(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(loc, ones, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); mlir::Value res1 = builder.createUnsigned( loc, signlessType, word, pos); - mlir::Value res2 = builder.create(loc, res1, mask); - mlir::Value lenIsZero = builder.create( - 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(loc, lenIsZero, zero, res2); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, zero, res2); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -4640,7 +4644,7 @@ mlir::Value IntrinsicLibrary::genIbset(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value mask = builder.create(loc, one, pos); + mlir::Value mask = mlir::arith::ShLIOp::create(builder, loc, one, pos); return builder.createUnsigned(loc, resultType, args[0], mask); } @@ -4674,13 +4678,13 @@ IntrinsicLibrary::genIchar(mlir::Type resultType, fir::CharacterType::get(builder.getContext(), eleType.getFKind(), 1); mlir::Type toTy = builder.getRefType(charType); mlir::Value cast = builder.createConvert(loc, toTy, buffer); - charVal = builder.create(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(loc, resultType, code); + return mlir::arith::ExtUIOp::create(builder, loc, resultType, code); } // llvm floating point class intrinsic test values @@ -4710,7 +4714,7 @@ mlir::Value IntrinsicLibrary::genIsFPClass(mlir::Type resultType, assert(args.size() == 1); mlir::Type i1Ty = builder.getI1Type(); mlir::Value isfpclass = - builder.create(loc, i1Ty, args[0], fpclass); + mlir::LLVM::IsFPClass::create(builder, loc, i1Ty, args[0], fpclass); return builder.createConvert(loc, resultType, isfpclass); } @@ -4725,7 +4729,7 @@ mlir::Value IntrinsicLibrary::genQNan(mlir::Type resultType) { void IntrinsicLibrary::genRaiseExcept(int excepts, mlir::Value cond) { fir::IfOp ifOp; if (cond) { - ifOp = builder.create(loc, cond, /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, cond, /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } mlir::Type i32Ty = builder.getIntegerType(32); @@ -4746,11 +4750,11 @@ getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec, mlir::dyn_cast(fir::unwrapPassByRefType(rec.getType())); assert(index < recType.getTypeList().size() && "not enough components"); auto [fieldName, fieldTy] = recType.getTypeList()[index]; - mlir::Value field = builder.create( - loc, fir::FieldType::get(recType.getContext()), fieldName, recType, - fir::getTypeParams(rec)); - return {builder.create(loc, builder.getRefType(fieldTy), - rec, field), + mlir::Value field = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(recType.getContext()), fieldName, + recType, fir::getTypeParams(rec)); + return {fir::CoordinateOp::create(builder, loc, builder.getRefType(fieldTy), + rec, field), fieldTy}; } @@ -4763,9 +4767,9 @@ IntrinsicLibrary::genIeeeTypeCompare(mlir::Type resultType, assert(args.size() == 2); auto [leftRef, fieldTy] = getFieldRef(builder, loc, args[0]); auto [rightRef, ignore] = getFieldRef(builder, loc, args[1]); - mlir::Value left = builder.create(loc, fieldTy, leftRef); - mlir::Value right = builder.create(loc, fieldTy, rightRef); - return builder.create(loc, pred, left, right); + mlir::Value left = fir::LoadOp::create(builder, loc, fieldTy, leftRef); + mlir::Value right = fir::LoadOp::create(builder, loc, fieldTy, rightRef); + return mlir::arith::CmpIOp::create(builder, loc, pred, left, right); } // IEEE_CLASS @@ -4796,7 +4800,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, const unsigned intWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(intWidth); mlir::Value intVal = - builder.create(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); llvm::StringRef tableName = RTNAME_STRING(IeeeClassTable); uint64_t highSignificandSize = (realType.getWidth() == 80) + 1; @@ -4806,8 +4810,8 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, return builder.createIntegerConstant(loc, intType, k); }; auto createIntegerConstantAPI = [&](const llvm::APInt &apInt) { - return builder.create( - loc, intType, builder.getIntegerAttr(intType, apInt)); + return mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr(intType, apInt)); }; auto getMasksAndShifts = [&](uint64_t totalSize, uint64_t exponentSize, uint64_t significandSize, @@ -4854,50 +4858,52 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, // [s] sign bit int pos = 3 + highSignificandSize; - mlir::Value index = builder.create( - loc, builder.create(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(loc, intVal, exponentMask); + mlir::arith::AndIOp::create(builder, loc, intVal, exponentMask); mlir::Value zero = createIntegerConstant(0); - index = builder.create( - loc, index, - builder.create( - loc, - builder.create( - 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( - loc, index, - builder.create( - loc, - builder.create( - 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( - loc, index, - builder.create( - loc, - builder.create( - loc, mlir::arith::CmpIPredicate::ne, - builder.create(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( - loc, index, - builder.create( - loc, - builder.create(loc, intVal, - highSignificandShift), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, + highSignificandShift), createIntegerConstant((1 << highSignificandSize) - 1))); int tableSize = 1 << (4 + highSignificandSize); @@ -5025,10 +5031,10 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, mlir::RankedTensorType::get(tableSize, int8Ty), values)); } - return builder.create( - loc, builder.getRefType(resultType), - builder.create(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(resultType), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), index); } @@ -5055,34 +5061,36 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType, // Args have the same type. if (xRealType == yRealType) - return builder.create(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(loc, xIntType, xRealVal); + mlir::arith::BitcastOp::create(builder, loc, xIntType, xRealVal); mlir::Value yIntVal = - builder.create(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( - loc, yIntVal, + mlir::Value ySign = mlir::arith::ShRUIOp::create( + builder, loc, yIntVal, builder.createIntegerConstant(loc, yIntType, yRealType.getWidth() - 1)); - mlir::Value xAbs = builder.create( - loc, builder.create(loc, xIntVal, xOne), xOne); - mlir::Value xSign = builder.create( - loc, - builder.create(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( - loc, xOne, + mlir::arith::ShLIOp::create( + builder, loc, xOne, builder.createIntegerConstant(loc, xIntType, xRealType.getWidth() - 1))); - return builder.create( - loc, xRealType, builder.create(loc, xAbs, xSign)); + return mlir::arith::BitcastOp::create( + builder, loc, xRealType, + mlir::arith::OrIOp::create(builder, loc, xAbs, xSign)); } // IEEE_GET_FLAG @@ -5096,16 +5104,16 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef 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(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(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create( - loc, resultTy, - builder.create(loc, mlir::arith::CmpIPredicate::ne, - excepts, zero)); - builder.create(loc, logicalResult, flagValue); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + excepts, zero)); + fir::StoreOp::create(builder, loc, logicalResult, flagValue); } // IEEE_GET_HALTING_MODE @@ -5120,17 +5128,17 @@ void IntrinsicLibrary::genIeeeGetHaltingMode( mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value haltSet = fir::runtime::genFegetexcept(builder, loc); - mlir::Value intResult = builder.create( - loc, haltSet, + mlir::Value intResult = mlir::arith::AndIOp::create( + builder, loc, haltSet, fir::runtime::genMapExcept( - builder, loc, builder.create(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create( - loc, resultTy, - builder.create(loc, mlir::arith::CmpIPredicate::ne, - intResult, zero)); - builder.create(loc, logicalResult, halting); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + intResult, zero)); + fir::StoreOp::create(builder, loc, logicalResult, halting); } // IEEE_GET_MODES, IEEE_SET_MODES @@ -5155,34 +5163,34 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // allotment. Allocate data space from the heap. auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]), 1); - addr = builder.create( - loc, builder.create(loc, fieldRef)); + addr = fir::BoxAddrOp::create(builder, loc, + fir::LoadOp::create(builder, loc, fieldRef)); mlir::Type heapTy = addr.getType(); - mlir::Value allocated = builder.create( - 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(loc, heapTy, allocated, - /*withElseRegion=*/true); + auto ifOp = fir::IfOp::create(builder, loc, heapTy, allocated, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create(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(loc, extractSequenceType(heapTy), - /*typeparams=*/mlir::ValueRange(), - byteSize); - mlir::Value shape = builder.create(loc, byteSize); - builder.create( - loc, builder.create(loc, fieldTy, addr, shape), fieldRef); - builder.create(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(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(loc, ptrTy, getBase(args[0])); + addr = fir::ConvertOp::create(builder, loc, ptrTy, getBase(args[0])); } llvm::StringRef func = isModes ? (isGet ? "fegetmode" : "fesetmode") : (isGet ? "fegetenv" : "fesetenv"); @@ -5193,11 +5201,11 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // Check that an explicit ieee_[get|set]_rounding_mode call radix value is 2. static void checkRadix(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value radix, std::string procName) { - mlir::Value notTwo = builder.create( - 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(loc, notTwo, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, notTwo, + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError(builder, loc, procName + " radix argument must be 2"); @@ -5215,9 +5223,9 @@ void IntrinsicLibrary::genIeeeGetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_get_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mode = builder.createConvert(loc, fieldTy, mode); - builder.create(loc, mode, fieldRef); + fir::StoreOp::create(builder, loc, mode, fieldRef); } // IEEE_GET_UNDERFLOW_MODE @@ -5242,44 +5250,45 @@ mlir::Value IntrinsicLibrary::genIeeeInt(mlir::Type resultType, mlir::FloatType realType = mlir::cast(args[0].getType()); mlir::Value realResult = genIeeeRint(realType, {args[0], args[1]}); int intWidth = mlir::cast(resultType).getWidth(); - mlir::Value intLBound = builder.create( - 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( - 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(loc, realType, intLBound); - mlir::Value realUBound = builder.create(loc, realLBound); - mlir::Value aGreaterThanLBound = builder.create( - loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); - mlir::Value aLessThanUBound = builder.create( - loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); - mlir::Value resultIsValid = builder.create( - 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(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( - 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(loc, resultType, realResult); - builder.create(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(loc, aGreaterThanLBound, - intUBound, intLBound); - builder.create(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, aGreaterThanLBound, + intUBound, intLBound); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); } @@ -5334,7 +5343,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(realType.getWidth()); mlir::Value intVal = - builder.create(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Type i1Ty = builder.getI1Type(); int exponentBias, significandSize, nonSignificandSize; @@ -5381,72 +5390,72 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, llvm_unreachable("unknown real type"); } - mlir::Value isZero = builder.create( - 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(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( - 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(loc, resultType, result); - builder.create(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(loc, intVal, one); + mlir::arith::ShLIOp::create(builder, loc, intVal, one); mlir::Value isFinite = genIsFPClass(i1Ty, args, finiteTest); - auto innerIfOp = builder.create(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(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( - loc, shiftLeftOne, + mlir::Value biasedExponent = mlir::arith::ShRUIOp::create( + builder, loc, shiftLeftOne, builder.createIntegerConstant(loc, intType, significandSize + 1)); - result = builder.create( - loc, biasedExponent, + result = mlir::arith::SubIOp::create( + builder, loc, biasedExponent, builder.createIntegerConstant(loc, intType, exponentBias)); - result = builder.create(loc, resultType, result); - builder.create(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( - loc, intVal, + mlir::Value significand = mlir::arith::ShLIOp::create( + builder, loc, intVal, builder.createIntegerConstant(loc, intType, nonSignificandSize)); mlir::Value ctlz = - builder.create(loc, significand); + mlir::math::CountLeadingZerosOp::create(builder, loc, significand); mlir::Type i32Ty = builder.getI32Type(); - result = builder.create( - loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), - builder.create(loc, i32Ty, ctlz)); - result = builder.create(loc, resultType, result); - builder.create(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(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(loc, shiftLeftOne, one); - result = builder.create(loc, resultType, result); - builder.create(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(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -5480,8 +5489,8 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, mlir::Value x1, y1; // X or ABS(X), Y or ABS(Y) if constexpr (isMag) { mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - x1 = builder.create(loc, x, zero); - y1 = builder.create(loc, y, zero); + x1 = mlir::math::CopySignOp::create(builder, loc, x, zero); + y1 = mlir::math::CopySignOp::create(builder, loc, y, zero); } else { x1 = x; y1 = y; @@ -5492,56 +5501,56 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, // X1 < Y1 -- MAX result is Y; MIN result is X. pred = mlir::arith::CmpFPredicate::OLT; - cmp = builder.create(loc, pred, x1, y1); - auto ifOp1 = builder.create(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(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(loc, pred, x1, y1); - auto ifOp2 = builder.create(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(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(loc, pred, x1, y1); - auto ifOp3 = builder.create(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(loc, resultIsX, x, y); - builder.create(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(loc, pred, x, x); - resultIsY = builder.create(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( - loc, resultIsX, x, - builder.create(loc, resultIsY, y, - genQNan(resultType))); - mlir::Value hasSNaNOp = builder.create( - 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(loc, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointAfter(ifOp3); - builder.create(loc, ifOp3.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp3.getResult(0)); builder.setInsertionPointAfter(ifOp2); - builder.create(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5554,13 +5563,13 @@ IntrinsicLibrary::genIeeeQuietCompare(mlir::Type resultType, llvm::ArrayRef args) { // Compare X and Y with special case treatment of NaN operands. assert(args.size() == 2); - mlir::Value hasSNaNOp = builder.create( - 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(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(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_REAL @@ -5612,14 +5621,14 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, // If the argument is an sNaN, raise an invalid exception and return a qNaN. // Otherwise return the argument. auto processSnan = [&](mlir::Value x) { - fir::IfOp ifOp = builder.create(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(loc, genQNan(resultType)); + fir::ResultOp::create(builder, loc, genQNan(resultType)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create(loc, x); + fir::ResultOp::create(builder, loc, x); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); }; @@ -5635,7 +5644,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, a = builder.createConvert(loc, f32Ty, a); aType = f32Ty; } - r = builder.create(loc, resultType, a); + r = fir::ConvertOp::create(builder, loc, resultType, a); mlir::IntegerType aIntType = mlir::dyn_cast(aType); mlir::FloatType aFloatType = mlir::dyn_cast(aType); @@ -5647,142 +5656,144 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, return aIntType ? r : processSnan(r); // A possibly inexact conversion result may need to be rounded up or down. - mlir::Value b = builder.create(loc, aType, r); + mlir::Value b = fir::ConvertOp::create(builder, loc, aType, r); mlir::Value aEqB; if (aIntType) - aEqB = builder.create( - loc, mlir::arith::CmpIPredicate::eq, a, b); + aEqB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, a, b); else - aEqB = builder.create( - 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(loc, resultType, aEqB, - /*withElseRegion=*/true); + fir::IfOp ifOp1 = fir::IfOp::create(builder, loc, resultType, aEqB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); - builder.create(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(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( - loc, mlir::arith::CmpIPredicate::slt, a, zero); - aIsPositive = builder.create( - 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( - loc, mlir::arith::CmpFPredicate::OLT, a, zero); - aIsPositive = builder.create( - 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(loc, resultIntType, r); + mlir::arith::BitcastOp::create(builder, loc, resultIntType, r); mlir::Value one = builder.createIntegerConstant(loc, resultIntType, 1); - mlir::Value rIsOdd = builder.create( - loc, i1Ty, builder.create(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( - 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( - 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(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( - loc, mlir::arith::CmpIPredicate::slt, a, b); + aLtB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); else - aLtB = builder.create( - 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(loc, resultCast, one); + mlir::arith::AddIOp::create(builder, loc, resultCast, one); mlir::Value downResult = - builder.create(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(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(loc, roundToZeroBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsPositive); roundAway = - builder.create(loc, roundAwayBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsNegative); mlir::Value roundDown = match(_FORTRAN_RUNTIME_IEEE_DOWN); mustAdjust = - builder.create(loc, roundToNearest, roundToZero); - mustAdjust = builder.create(loc, mustAdjust, roundAway); - mustAdjust = builder.create(loc, mustAdjust, roundDown); - adjustIfOp = builder.create(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( - loc, resultType, - builder.create(loc, aIsNegative, upResult, - downResult)); - builder.create(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(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create(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(loc, roundToZeroBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsNegative); roundAway = - builder.create(loc, roundAwayBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsPositive); mlir::Value roundUp = match(_FORTRAN_RUNTIME_IEEE_UP); mustAdjust = - builder.create(loc, roundToNearest, roundToZero); - mustAdjust = builder.create(loc, mustAdjust, roundAway); - mustAdjust = builder.create(loc, mustAdjust, roundUp); - adjustIfOp = builder.create(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( - loc, resultType, - builder.create(loc, aIsPositive, upResult, - downResult)); - builder.create(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(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create(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( - 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( - loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), + fir::IfOp exceptIfOp2 = fir::IfOp::create( + builder, loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp2.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | @@ -5790,7 +5801,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, builder.setInsertionPointToStart(&exceptIfOp2.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointAfter(exceptIfOp1); - builder.create(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5806,19 +5817,19 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType, mlir::Value y = args[1]; if (mlir::dyn_cast(resultType).getWidth() < 32) { mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext()); - x = builder.create(loc, f32Ty, x); - y = builder.create(loc, f32Ty, y); + x = fir::ConvertOp::create(builder, loc, f32Ty, x); + y = fir::ConvertOp::create(builder, loc, f32Ty, y); } else { - x = builder.create(loc, resultType, x); - y = builder.create(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( - 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(loc, resultType, result); + return fir::ConvertOp::create(builder, loc, resultType, result); } // IEEE_RINT @@ -5834,19 +5845,19 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType, mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); mlir::Value mode; if (isStaticallyPresent(args[1])) { - mode = builder.create(loc, getRound).getResult(0); + mode = fir::CallOp::create(builder, loc, getRound).getResult(0); genIeeeSetRoundingMode({args[1]}); } if (mlir::cast(resultType).getWidth() == 16) - a = builder.create( - loc, mlir::Float32Type::get(builder.getContext()), a); - mlir::Value result = builder.create( - 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(loc, setRound, mode); + fir::CallOp::create(builder, loc, setRound, mode); } else { - mlir::Value inexact = builder.create( - loc, mlir::arith::CmpFPredicate::ONE, args[0], result); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], result); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); } return result; @@ -5862,18 +5873,19 @@ void IntrinsicLibrary::genIeeeSetFlagOrHaltingMode( mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value except = fir::runtime::genMapExcept( - builder, loc, builder.create(loc, i32Ty, field)); - auto ifOp = builder.create( - loc, builder.create(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(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(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointAfter(ifOp); } @@ -5890,7 +5902,7 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_set_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); - mlir::Value mode = builder.create(loc, fieldRef); + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); static_assert( _FORTRAN_RUNTIME_IEEE_TO_ZERO >= 0 && _FORTRAN_RUNTIME_IEEE_TO_ZERO <= 3 && @@ -5898,28 +5910,28 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( _FORTRAN_RUNTIME_IEEE_NEAREST <= 3 && _FORTRAN_RUNTIME_IEEE_UP >= 0 && _FORTRAN_RUNTIME_IEEE_UP <= 3 && _FORTRAN_RUNTIME_IEEE_DOWN >= 0 && _FORTRAN_RUNTIME_IEEE_DOWN <= 3 && "unexpected rounding mode mapping"); - mlir::Value mask = builder.create( - 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( - loc, mlir::arith::CmpIPredicate::eq, - builder.create(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(loc, modeIsSupported, mode, - nearest); - mode = builder.create( - loc, setRound.getFunctionType().getInput(0), mode); - builder.create(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 args) { assert(args.size() == 1); - mlir::Value gradual = builder.create(loc, builder.getI1Type(), - getBase(args[0])); + mlir::Value gradual = fir::ConvertOp::create( + builder, loc, builder.getI1Type(), getBase(args[0])); fir::runtime::genSetUnderflowMode(builder, loc, {gradual}); } @@ -5933,9 +5945,9 @@ IntrinsicLibrary::genIeeeSignalingCompare(mlir::Type resultType, assert(args.size() == 2); mlir::Value hasNaNOp = genIeeeUnordered(mlir::Type{}, args); mlir::Value res = - builder.create(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(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_SIGNBIT @@ -5954,9 +5966,9 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType, } mlir::Type intType = builder.getIntegerType(bitWidth); mlir::Value intVal = - builder.create(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(loc, intVal, shift); + mlir::Value sign = mlir::arith::ShRUIOp::create(builder, loc, intVal, shift); return builder.createConvert(loc, resultType, sign); } @@ -5969,21 +5981,21 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value flag = builder.create(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( - loc, mlir::arith::CmpIPredicate::ne, - builder.create(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(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(loc, builder.createBool(loc, true)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, true)); // TargetCharacteristics information for the nonstandard ieee_denorm flag // is not available here. So use a runtime check restricted to possibly @@ -6007,17 +6019,17 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, } } if (mayBeSupported) { - mlir::Value isDenorm = builder.create( - 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( - loc, isDenorm, + mlir::Value result = mlir::arith::AndIOp::create( + builder, loc, isDenorm, fir::runtime::genSupportHalting( - builder, loc, builder.create(loc, i32Ty, flag))); - builder.create(loc, result); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, flag))); + fir::ResultOp::create(builder, loc, result); } else { - builder.create(loc, builder.createBool(loc, false)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, false)); } builder.setInsertionPointAfter(ifOp); return builder.createConvert(loc, resultType, ifOp.getResult(0)); @@ -6032,11 +6044,11 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportHalting( assert(args.size() == 1); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); return builder.createConvert( loc, resultType, fir::runtime::genSupportHalting( - builder, loc, builder.create(loc, i32Ty, field))); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); } // IEEE_SUPPORT_ROUNDING @@ -6053,16 +6065,16 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportRounding( // 4 - to nearest, ties away from zero [not supported] assert(args.size() == 1 || args.size() == 2); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value mode = builder.create(loc, fieldRef); - mlir::Value lbOk = builder.create( - 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( - 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(loc, lbOk, ubOk)); + loc, resultType, mlir::arith::AndIOp::create(builder, loc, lbOk, ubOk)); } // IEEE_SUPPORT_STANDARD @@ -6086,15 +6098,15 @@ IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType, // If there is no result type return an i1 result. assert(args.size() == 2); if (args[0].getType() == args[1].getType()) { - mlir::Value res = builder.create( - 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(loc, xIsNan, yIsNan); + mlir::Value res = mlir::arith::OrIOp::create(builder, loc, xIsNan, yIsNan); return builder.createConvert(loc, resultType, res); } @@ -6219,22 +6231,22 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType, mlir::Value which; if (args.size() == 2) { // user call auto [index, ignore] = getFieldRef(builder, loc, args[1]); - which = builder.create(loc, index); + which = fir::LoadOp::create(builder, loc, index); } else { // compiler generated call which = args[0]; } - mlir::Value bits = builder.create( - loc, - builder.create( - loc, builder.getRefType(valueTy), - builder.create(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( - 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(loc, realType, bits); + return mlir::arith::BitcastOp::create(builder, loc, realType, bits); } // IEOR @@ -6276,13 +6288,14 @@ IntrinsicLibrary::genIndex(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value backOpt = isStaticallyAbsent(args, 2) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) - : makeRefThenEmbox(fir::getBase(args[2])); + mlir::Value backOpt = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : makeRefThenEmbox(fir::getBase(args[2])); mlir::Value kindVal = isStaticallyAbsent(args, 3) ? builder.createIntegerConstant( loc, builder.getIndexType(), @@ -6331,8 +6344,8 @@ mlir::Value IntrinsicLibrary::genIsIostatValue(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 1); - return builder.create( - loc, mlir::arith::CmpIPredicate::eq, args[0], + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, args[0], builder.createIntegerConstant(loc, args[0].getType(), value)); } @@ -6359,16 +6372,16 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - auto left = builder.create(loc, word, absShift); - auto right = builder.create(loc, word, absShift); - auto shiftIsLarge = builder.create( - loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); - auto shiftIsNegative = builder.create( - 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(loc, shiftIsNegative, right, left); + mlir::arith::SelectOp::create(builder, loc, shiftIsNegative, right, left); mlir::Value result = - builder.create(loc, shiftIsLarge, zero, sel); + mlir::arith::SelectOp::create(builder, loc, shiftIsLarge, zero, sel); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6409,42 +6422,42 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value absShift = genAbs(signlessType, {shift}); - auto elseSize = builder.create(loc, size, absShift); - auto shiftIsZero = builder.create( - loc, mlir::arith::CmpIPredicate::eq, shift, zero); - auto shiftEqualsSize = builder.create( - 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(loc, shiftIsZero, shiftEqualsSize); - auto shiftIsPositive = builder.create( - loc, mlir::arith::CmpIPredicate::sgt, shift, zero); - auto leftSize = builder.create(loc, shiftIsPositive, - absShift, elseSize); - auto rightSize = builder.create(loc, shiftIsPositive, - elseSize, absShift); - auto hasUnchanged = builder.create( - loc, mlir::arith::CmpIPredicate::ne, size, bitSize); - auto unchangedTmp1 = builder.create(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(loc, unchangedTmp1, size); - auto unchanged = builder.create(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(loc, bitSize, leftSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, leftSize); auto leftMask = - builder.create(loc, ones, leftMaskShift); - auto leftTmp = builder.create(loc, word, rightSize); - auto left = builder.create(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(loc, bitSize, rightSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, rightSize); auto rightMask = - builder.create(loc, ones, rightMaskShift); - auto rightTmp = builder.create(loc, word, rightMask); - auto right = builder.create(loc, rightTmp, leftSize); - auto resTmp = builder.create(loc, unchanged, left); - auto res = builder.create(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(loc, shiftIsNop, word, res); + mlir::arith::SelectOp::create(builder, loc, shiftIsNop, word, res); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6456,7 +6469,7 @@ mlir::Value IntrinsicLibrary::genLeadz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create(loc, args); + mlir::math::CountLeadingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -6524,18 +6537,18 @@ IntrinsicLibrary::genLoc(mlir::Type resultType, // created when preparing the argument cases, but the box can be safely be // used for all those cases and the address will be null if absent. mlir::Value isPresent = - builder.create(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(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - builder.create(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } @@ -6568,12 +6581,12 @@ mlir::Value IntrinsicLibrary::genMask(mlir::Type resultType, // non-deterministic result. Other compilers don't produce a consistent result // in this case either, so we choose the most efficient implementation. mlir::Value shift = - builder.create(loc, bitSize, bitsToSet); - mlir::Value shifted = builder.create(loc, ones, shift); - mlir::Value isZero = builder.create( - 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(loc, isZero, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, isZero, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6591,8 +6604,8 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); mlir::Type retTy = mlir::LLVM::LLVMStructType::getLiteral(context, {resultType, i1Ty}); @@ -6601,10 +6614,10 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, .create(loc, retTy, args[0], arg1, mlir::NVVM::MatchSyncKind::all) .getResult(); - auto value = builder.create(loc, match, 0); - auto pred = builder.create(loc, match, 1); - auto conv = builder.create(loc, resultType, pred); - builder.create(loc, conv, args[2]); + auto value = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 0); + auto pred = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 1); + auto conv = mlir::LLVM::ZExtOp::create(builder, loc, resultType, pred); + fir::StoreOp::create(builder, loc, conv, args[2]); return value; } @@ -6614,14 +6627,14 @@ mlir::Value IntrinsicLibrary::genVoteSync(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 2); mlir::Value arg1 = - builder.create(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(loc, resTy, args[0], arg1, kind) + mlir::NVVM::VoteSyncOp::create(builder, loc, resTy, args[0], arg1, kind) .getResult(); - return builder.create(loc, resultType, voteRes); + return fir::ConvertOp::create(builder, loc, resultType, voteRes); } // MATCH_ANY_SYNC @@ -6633,8 +6646,8 @@ IntrinsicLibrary::genMatchAnySync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); return builder .create(loc, resultType, args[0], arg1, @@ -6718,10 +6731,10 @@ IntrinsicLibrary::genMerge(mlir::Type, mlir::Value other) -> mlir::Value { mlir::Type otherType = other.getType(); if (mlir::isa(otherType)) - return builder.create(loc, otherType, polymorphic, - /*shape*/ mlir::Value{}, - /*slice=*/mlir::Value{}); - return builder.create(loc, otherType, polymorphic); + return fir::ReboxOp::create(builder, loc, otherType, polymorphic, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + return fir::BoxAddrOp::create(builder, loc, otherType, polymorphic); }; if (fir::isPolymorphicType(tsource.getType()) && !fir::isPolymorphicType(fsource.getType())) { @@ -6737,8 +6750,8 @@ IntrinsicLibrary::genMerge(mlir::Type, // fulfill mlir::SelectOp constraint that the MLIR types must be the same. fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); } - auto rslt = builder.create(loc, mask, tsourceCast, - fsourceCast); + auto rslt = mlir::arith::SelectOp::create(builder, loc, mask, tsourceCast, + fsourceCast); if (isCharRslt) { // Need a CharBoxValue for character results const fir::CharBoxValue *charBox = args[0].getCharBox(); @@ -6779,7 +6792,7 @@ mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, args[0], args[1]); } if (mlir::isa(resultType)) - return builder.create(loc, args[0], args[1]); + return mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); // Use runtime. return builder.createConvert( @@ -6809,19 +6822,19 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, } if (mlir::isa(resultType)) { auto remainder = - builder.create(loc, args[0], args[1]); - auto argXor = builder.create(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( - loc, mlir::arith::CmpIPredicate::slt, argXor, zero); - auto remainderIsNotZero = builder.create( - loc, mlir::arith::CmpIPredicate::ne, remainder, zero); - auto mustAddP = builder.create(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(loc, remainder, args[1]); - return builder.create(loc, mustAddP, remPlusP, - remainder); + mlir::arith::AddIOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } auto fastMathFlags = builder.getFastMathFlags(); @@ -6834,21 +6847,21 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, loc, resultType, fir::runtime::genModulo(builder, loc, args[0], args[1])); - auto remainder = builder.create(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( - loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); - auto aLessThanZero = builder.create( - loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); - auto pLessThanZero = builder.create( - 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(loc, aLessThanZero, pLessThanZero); - auto mustAddP = builder.create(loc, remainderIsNotZero, - argSignDifferent); - auto remPlusP = builder.create(loc, remainder, args[1]); - return builder.create(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 args) { @@ -6863,7 +6876,7 @@ void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef args) { mlir::Value errBox = isStaticallyPresent(errMsg) ? fir::getBase(errMsg) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); const fir::MutableBoxValue *fromBox = from.getBoxOf(); const fir::MutableBoxValue *toBox = to.getBoxOf(); @@ -6920,33 +6933,34 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef args) { mlir::Type toType{fir::dyn_cast_ptrEleTy(toAddr.getType())}; assert(toType.getIntOrFloatBitWidth() == fromType.getIntOrFloatBitWidth() && "mismatched mvbits types"); - auto to = builder.create(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(signlessType).getWidth()); - auto shiftCount = builder.create(loc, bitSize, len); - auto mask = builder.create(loc, ones, shiftCount); - auto unchangedTmp1 = builder.create(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(loc, unchangedTmp1, ones); - auto unchanged = builder.create(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(loc, from, frompos); + auto frombitsTmp1 = mlir::arith::ShRUIOp::create(builder, loc, from, frompos); auto frombitsTmp2 = - builder.create(loc, frombitsTmp1, mask); - auto frombits = builder.create(loc, frombitsTmp2, topos); - auto resTmp = builder.create(loc, unchanged, frombits); - auto lenIsZero = builder.create( - 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(loc, lenIsZero, to, resTmp); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, to, resTmp); if (toType.isUnsignedInteger()) res = builder.createConvert(loc, toType, res); - builder.create(loc, res, toAddr); + fir::StoreOp::create(builder, loc, res, toAddr); } // NEAREST, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP @@ -6988,7 +7002,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, // If isNan(Y), set X to a qNaN that will propagate to the resultIsX result. mlir::Value qNan = genQNan(xType); mlir::Value isFPClass = genIsFPClass(i1Ty, args[1], nanTest); - x = builder.create(loc, isFPClass, qNan, x); + x = mlir::arith::SelectOp::create(builder, loc, isFPClass, qNan, x); } mlir::Value resultIsX = genIsFPClass(i1Ty, x, nanTest); mlir::Type intType = builder.getIntegerType(xBitWidth); @@ -6999,15 +7013,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if constexpr (proc == NearestProc::Nearest) { // Arg S must not be zero. fir::IfOp ifOp = - builder.create(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( - loc, mlir::arith::CmpIPredicate::ne, sSign, one); + valueUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, sSign, one); } else if constexpr (proc == NearestProc::NextAfter) { // Convert X and Y to a common type to allow comparison. Direct conversions // between kinds 2, 3, 10, and 16 are not all supported. These conversions @@ -7028,58 +7042,58 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if (xBitWidth > 32 && xBitWidth > yBitWidth) y = builder.createConvert(loc, xType, y); } - resultIsX = builder.create( - loc, resultIsX, - builder.create( - loc, mlir::arith::CmpFPredicate::OEQ, x1, y)); - valueUp = builder.create( - 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( - 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( - loc, resultIsX, - builder.create( - 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(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(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( - 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(loc, resultType, resultIsMinSubnormal, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultType, resultIsMinSubnormal, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value minPositiveSubnormal = - builder.create(loc, resultType, one); - mlir::Value minNegativeSubnormal = builder.create( - loc, resultType, - builder.create( - 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( - 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(loc, result); + fir::ResultOp::create(builder, loc, result); // Result is (X + minPositiveSubnormal) or (X - minPositiveSubnormal). builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); @@ -7105,15 +7119,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, genRuntimeCall("feraiseexcept", i32Ty, excepts); genRuntimeCall("feenableexcept", i32Ty, mask); } - builder.create(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(loc, intType, x); - mlir::Value add = builder.create(loc, intX, one); - mlir::Value sub = builder.create(loc, intX, one); - result = builder.create( - loc, resultType, - builder.create(loc, magnitudeUp, add, sub)); + mlir::Value intX = mlir::arith::BitcastOp::create(builder, loc, intType, x); + mlir::Value add = mlir::arith::AddIOp::create(builder, loc, intX, one); + mlir::Value sub = mlir::arith::SubIOp::create(builder, loc, intX, one); + result = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, magnitudeUp, add, sub)); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) { genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | @@ -7123,11 +7137,11 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, _FORTRAN_RUNTIME_IEEE_INEXACT, genIsFPClass(i1Ty, result, subnormalTest)); } - builder.create(loc, result); + fir::ResultOp::create(builder, loc, result); } builder.setInsertionPointAfter(innerIfOp); - builder.create(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -7209,7 +7223,7 @@ IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef args) { mlir::Value boxStorage = builder.createTemporary(loc, boxType); mlir::Value box = fir::factory::createUnallocatedBox( builder, loc, boxType, mold->nonDeferredLenParams()); - builder.create(loc, box, boxStorage); + fir::StoreOp::create(builder, loc, box, boxStorage); return fir::MutableBoxValue(boxStorage, mold->nonDeferredLenParams(), {}); } @@ -7218,7 +7232,7 @@ template mlir::Value IntrinsicLibrary::genNVVMTime(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 0 && "expect no arguments"); - return builder.create(loc, resultType).getResult(); + return OpTy::create(builder, loc, resultType).getResult(); } // PACK @@ -7235,10 +7249,11 @@ IntrinsicLibrary::genPack(mlir::Type resultType, mlir::Value mask = builder.createBox(loc, args[1]); // Handle optional vector argument - mlir::Value vector = isStaticallyAbsent(args, 2) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value vector = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 1); @@ -7298,7 +7313,7 @@ void IntrinsicLibrary::genPerror(llvm::ArrayRef args) { fir::ExtendedValue str = args[0]; const auto *box = str.getBoxOf(); mlir::Value addr = - builder.create(loc, box->getMemTy(), fir::getBase(*box)); + fir::BoxAddrOp::create(builder, loc, box->getMemTy(), fir::getBase(*box)); fir::runtime::genPerror(builder, loc, addr); } @@ -7307,7 +7322,7 @@ mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 1); - mlir::Value count = builder.create(loc, args); + mlir::Value count = mlir::math::CtPopOp::create(builder, loc, args); return builder.createConvert(loc, resultType, count); } @@ -7320,7 +7335,7 @@ mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, mlir::Value count = genPopcnt(resultType, args); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - return builder.create(loc, count, one); + return mlir::arith::AndIOp::create(builder, loc, count, one); } // PRESENT @@ -7328,8 +7343,8 @@ fir::ExtendedValue IntrinsicLibrary::genPresent(mlir::Type, llvm::ArrayRef args) { assert(args.size() == 1); - return builder.create(loc, builder.getI1Type(), - fir::getBase(args[0])); + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(args[0])); } // PRODUCT @@ -7394,7 +7409,7 @@ void IntrinsicLibrary::genRandomSeed(llvm::ArrayRef args) { auto getDesc = [&](int i) { return isStaticallyPresent(args[i]) ? fir::getBase(args[i]) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); }; mlir::Value size = getDesc(0); mlir::Value put = getDesc(1); @@ -7438,13 +7453,13 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, bool absentDim = isStaticallyAbsent(args[2]); auto mask = isStaticallyAbsent(args[3]) - ? builder.create( - 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(loc, fir::ReferenceType::get(eleTy)) + ? fir::AbsentOp::create(builder, loc, fir::ReferenceType::get(eleTy)) : fir::getBase(args[4]); mlir::Value ordered = isStaticallyAbsent(args[5]) @@ -7460,7 +7475,7 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, ordered, result, argByRef); if (fir::isa_derived(eleTy)) return result; - return builder.create(loc, result); + return fir::LoadOp::create(builder, loc, result); } if (fir::isa_char(eleTy)) { auto charTy = mlir::dyn_cast_or_null(resultType); @@ -7510,7 +7525,7 @@ IntrinsicLibrary::genRename(std::optional resultType, auto statusAddr = builder.createTemporary(loc, *resultType); auto statusBox = builder.createBox(loc, statusAddr); fir::runtime::genRename(builder, loc, path1, path2, statusBox); - return builder.create(loc, statusAddr); + return fir::LoadOp::create(builder, loc, statusAddr); } else { // code-gen for the procedure form of RENAME mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); @@ -7518,7 +7533,7 @@ IntrinsicLibrary::genRename(std::optional resultType, mlir::Value statusBox = isStaticallyPresent(status) ? fir::getBase(status) - : builder.create(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genRename(builder, loc, path1, path2, statusBox); return {}; } @@ -7563,16 +7578,18 @@ IntrinsicLibrary::genReshape(mlir::Type resultType, TODO(loc, "intrinsic: reshape requires computing rank of result"); // Handle optional pad argument - mlir::Value pad = isStaticallyAbsent(args[2]) - ? builder.create( - 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( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[3]); + mlir::Value order = + isStaticallyAbsent(args[3]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[3]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type type = builder.getVarLenSeqTy(resultType, resultRank); @@ -7643,26 +7660,27 @@ mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType, // If X is finite and result is infinite, signal IEEE_OVERFLOW // If X is finite and scale(result, -I) != X, signal IEEE_UNDERFLOW fir::IfOp outerIfOp = - builder.create(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(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( - 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(loc, mlir::arith::CmpFPredicate::ONE, - args[0], reverseResult)); + mlir::arith::CmpFOp::create(builder, loc, mlir::arith::CmpFPredicate::ONE, + args[0], reverseResult)); builder.setInsertionPointAfter(outerIfOp); return result; } @@ -7714,13 +7732,14 @@ IntrinsicLibrary::genScan(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create(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( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -7761,7 +7780,7 @@ IntrinsicLibrary::genSecond(std::optional resultType, genCpuTime(subroutineArgs); if (resultType) - return builder.create(loc, fir::getBase(result)); + return fir::LoadOp::create(builder, loc, fir::getBase(result)); return {}; } @@ -7808,22 +7827,22 @@ IntrinsicLibrary::genSelectedRealKind(mlir::Type resultType, // Handle optional precision(P) argument mlir::Value precision = isStaticallyAbsent(args[0]) - ? builder.create( - 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( - 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( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[2]); return builder.createConvert( @@ -7861,9 +7880,9 @@ createBoxForRuntimeBoundInquiry(mlir::Location loc, fir::FirOpBuilder &builder, // shape information. mlir::Value localShape = builder.createShape(loc, array); mlir::Value oldBox = boxValue.getAddr(); - return builder.create(loc, oldBox.getType(), oldBox, - localShape, - /*slice=*/mlir::Value{}); + return fir::ReboxOp::create(builder, loc, oldBox.getType(), oldBox, + localShape, + /*slice=*/mlir::Value{}); }, [&](const auto &) -> mlir::Value { // This is a pointer/allocatable, or an entity not yet tracked with a @@ -7909,7 +7928,7 @@ genBoundInquiry(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value resultBase = builder.createConvert(loc, baseType, resultStorage); mlir::Value rankValue = - builder.create(loc, builder.getIndexType(), arrayBox); + fir::BoxRankOp::create(builder, loc, builder.getIndexType(), arrayBox); return fir::ArrayBoxValue{resultBase, {rankValue}}; } // Result extent is a compile time constant in the other cases. @@ -7939,9 +7958,9 @@ IntrinsicLibrary::genShape(mlir::Type resultType, mlir::Value extent = fir::factory::readExtent(builder, loc, array, dim); extent = builder.createConvert(loc, extentType, extent); auto index = builder.createIntegerConstant(loc, indexType, dim); - auto shapeAddr = builder.create(loc, shapeAddrType, - shapeArray, index); - builder.create(loc, extent, shapeAddr); + auto shapeAddr = fir::CoordinateOp::create(builder, loc, shapeAddrType, + shapeArray, index); + fir::StoreOp::create(builder, loc, extent, shapeAddr); } mlir::Value shapeArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -7967,18 +7986,18 @@ mlir::Value IntrinsicLibrary::genShift(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value tooSmall = builder.create( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); - mlir::Value tooLarge = builder.create( - 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(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(loc, word, shift); + mlir::Value shifted = Shift::create(builder, loc, word, shift); mlir::Value result = - builder.create(loc, outOfBounds, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, outOfBounds, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -7993,8 +8012,8 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value bitSize = builder.createIntegerConstant(loc, signlessType, bits); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value shiftGeBitSize = builder.create( - loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); + mlir::Value shiftGeBitSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); // Lowering of mlir::arith::ShRSIOp is using `ashr`. `ashr` is undefined when // the shift amount is equal to the element size. @@ -8006,13 +8025,13 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value valueIsNeg = builder.create( - 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(loc, valueIsNeg, minusOne, zero); - mlir::Value shifted = builder.create(loc, word, shift); - mlir::Value result = builder.create( - loc, shiftGeBitSize, specialRes, shifted); + mlir::arith::SelectOp::create(builder, loc, valueIsNeg, minusOne, zero); + mlir::Value shifted = mlir::arith::ShRSIOp::create(builder, loc, word, shift); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, shiftGeBitSize, specialRes, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -8037,10 +8056,10 @@ mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, if (mlir::isa(resultType)) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto neg = builder.create(loc, zero, abs); - auto cmp = builder.create( - loc, mlir::arith::CmpIPredicate::slt, args[1], zero); - return builder.create(loc, cmp, neg, abs); + auto neg = mlir::arith::SubIOp::create(builder, loc, zero, abs); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, args[1], zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, neg, abs); } return genRuntimeCall("sign", resultType, args); } @@ -8056,7 +8075,7 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); } @@ -8100,14 +8119,14 @@ IntrinsicLibrary::genSize(mlir::Type resultType, .genThen([&]() { mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, array)); - builder.create(loc, size); + fir::ResultOp::create(builder, loc, size); }) .genElse([&]() { - mlir::Value dimValue = builder.create(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(loc, size); + fir::ResultOp::create(builder, loc, size); }) .getResults()[0]; } @@ -8118,12 +8137,13 @@ IntrinsicLibrary::genSizeOf(mlir::Type resultType, llvm::ArrayRef args) { assert(args.size() == 1); mlir::Value box = fir::getBase(args[0]); - mlir::Value eleSize = builder.create(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(loc, eleSize, arraySize); + return mlir::arith::MulIOp::create(builder, loc, eleSize, arraySize); } // TAND @@ -8137,7 +8157,7 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); } @@ -8147,81 +8167,83 @@ mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); - mlir::Value threadIdX = builder.create(loc, i32Ty); - mlir::Value threadIdY = builder.create(loc, i32Ty); - mlir::Value threadIdZ = builder.create(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(loc, i32Ty); - mlir::Value blockIdY = builder.create(loc, i32Ty); - mlir::Value blockIdZ = builder.create(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(loc, i32Ty); - mlir::Value blockDimY = builder.create(loc, i32Ty); - mlir::Value blockDimZ = builder.create(loc, i32Ty); - mlir::Value gridDimX = builder.create(loc, i32Ty); - mlir::Value gridDimY = builder.create(loc, i32Ty); - mlir::Value gridDimZ = builder.create(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(loc, blockDimZ, gridDimZ); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, gridDimZ); mlir::Value resY = - builder.create(loc, blockDimY, gridDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimY, gridDimY); mlir::Value resX = - builder.create(loc, blockDimX, gridDimX); - mlir::Value resZY = builder.create(loc, resZ, resY); - mlir::Value size = builder.create(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(loc, blockIdZ, gridDimY); - mlir::Value r2 = builder.create(loc, r1, gridDimX); - mlir::Value r3 = builder.create(loc, blockIdY, gridDimX); - mlir::Value r2r3 = builder.create(loc, r2, r3); - mlir::Value tmp = builder.create(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(loc, blockDimX, blockDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimX, blockDimY); mlir::Value bXbYbZ = - builder.create(loc, bXbY, blockDimZ); + mlir::arith::MulIOp::create(builder, loc, bXbY, blockDimZ); mlir::Value tZbY = - builder.create(loc, threadIdZ, blockDimY); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); mlir::Value tZbYbX = - builder.create(loc, tZbY, blockDimX); + mlir::arith::MulIOp::create(builder, loc, tZbY, blockDimX); mlir::Value tYbX = - builder.create(loc, threadIdY, blockDimX); - mlir::Value rank = builder.create(loc, tmp, bXbYbZ); - rank = builder.create(loc, rank, tZbYbX); - rank = builder.create(loc, rank, tYbX); - rank = builder.create(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(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( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create(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( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8232,50 +8254,50 @@ IntrinsicLibrary::genThisThreadBlock(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create(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(loc, i32Ty); - mlir::Value blockDimY = builder.create(loc, i32Ty); - mlir::Value blockDimZ = builder.create(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(loc, blockDimZ, blockDimY); - size = builder.create(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(loc, i32Ty); - mlir::Value threadIdY = builder.create(loc, i32Ty); - mlir::Value threadIdZ = builder.create(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(loc, threadIdZ, blockDimY); - mlir::Value r2 = builder.create(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(loc, threadIdY, blockDimX); - mlir::Value r2r3 = builder.create(loc, r2, r3); - mlir::Value rank = builder.create(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(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( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create(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( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8285,7 +8307,7 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // coalesced_group%size = 32 @@ -8293,28 +8315,28 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create(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(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(loc, threadIdX, mask); - mlir::Value rank = builder.create(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( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8324,7 +8346,7 @@ mlir::Value IntrinsicLibrary::genTrailz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create(loc, args); + mlir::math::CountTrailingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -8352,10 +8374,10 @@ static mlir::Value computeLBOUND(fir::FirOpBuilder &builder, mlir::Location loc, zero = builder.createConvert(loc, extent.getType(), zero); // Note: for assumed size, the extent is -1, and the lower bound should // be returned. It is important to test extent == 0 and not extent > 0. - auto dimIsEmpty = builder.create( - 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(loc, dimIsEmpty, one, lb); + return mlir::arith::SelectOp::create(builder, loc, dimIsEmpty, one, lb); } // LBOUND @@ -8391,8 +8413,8 @@ IntrinsicLibrary::genLbound(mlir::Type resultType, lb = builder.createConvert(loc, lbType, lb); auto index = builder.createIntegerConstant(loc, indexType, dim); auto lbAddr = - builder.create(loc, lbAddrType, lbArray, index); - builder.create(loc, lb, lbAddr); + fir::CoordinateOp::create(builder, loc, lbAddrType, lbArray, index); + fir::StoreOp::create(builder, loc, lb, lbAddr); } mlir::Value lbArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -8431,8 +8453,8 @@ IntrinsicLibrary::genUbound(mlir::Type resultType, mlir::Value lbound = fir::getBase(genLbound(resultType, args)); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - mlir::Value ubound = builder.create(loc, lbound, one); - return builder.create(loc, ubound, extent); + mlir::Value ubound = mlir::arith::SubIOp::create(builder, loc, lbound, one); + return mlir::arith::AddIOp::create(builder, loc, ubound, extent); } // Handle calls to UBOUND without the DIM argument, which return an array int kindPos = args.size() == 2 ? 1 : 2; @@ -8526,9 +8548,9 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType, box = builder.createBox(loc, args[0], /*isPolymorphic=*/args[0].isPolymorphic()); - mlir::Value eleSize = builder.create(loc, kindTy, box); + mlir::Value eleSize = fir::BoxEleSizeOp::create(builder, loc, kindTy, box); mlir::Value c8 = builder.createIntegerConstant(loc, kindTy, 8); - return builder.create(loc, eleSize, c8); + return mlir::arith::MulIOp::create(builder, loc, eleSize, c8); } // SUM @@ -8541,7 +8563,7 @@ IntrinsicLibrary::genSum(mlir::Type resultType, // SYNCTHREADS void IntrinsicLibrary::genSyncThreads(llvm::ArrayRef args) { - builder.create(loc); + mlir::NVVM::Barrier0Op::create(builder, loc); } // SYNCTHREADS_AND @@ -8553,7 +8575,7 @@ IntrinsicLibrary::genSyncThreadsAnd(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_COUNT @@ -8565,7 +8587,7 @@ IntrinsicLibrary::genSyncThreadsCount(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_OR @@ -8577,7 +8599,7 @@ IntrinsicLibrary::genSyncThreadsOr(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCWARP @@ -8589,7 +8611,7 @@ void IntrinsicLibrary::genSyncWarp(llvm::ArrayRef args) { mlir::FunctionType::get(builder.getContext(), {mask.getType()}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector argsList{mask}; - builder.create(loc, funcOp, argsList); + fir::CallOp::create(builder, loc, funcOp, argsList); } // SYSTEM @@ -8615,25 +8637,26 @@ IntrinsicLibrary::genSystem(std::optional resultType, mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create(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(loc, tempValue, temp); + fir::StoreOp::create(builder, loc, tempValue, temp); mlir::Value cmdstatBox = builder.createBox(loc, temp); mlir::Value cmdmsgBox = - builder.create(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(loc, exitstatBox); - return builder.create(loc, fir::getBase(exitstatAddr)); + mlir::Value exitstatAddr = + fir::BoxAddrOp::create(builder, loc, exitstatBox); + return fir::LoadOp::create(builder, loc, fir::getBase(exitstatAddr)); } return {}; } @@ -8729,7 +8752,7 @@ void IntrinsicLibrary::genThreadFence(llvm::ArrayRef args) { mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector noArgs; - builder.create(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_BLOCK @@ -8740,7 +8763,7 @@ void IntrinsicLibrary::genThreadFenceBlock( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector noArgs; - builder.create(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_SYSTEM @@ -8751,7 +8774,7 @@ void IntrinsicLibrary::genThreadFenceSystem( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector noArgs; - builder.create(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // TIME @@ -8803,29 +8826,30 @@ static mlir::Value createExtremumCompare(mlir::Location loc, // Return the number if one of the inputs is NaN and the other is // a number. auto leftIsResult = - builder.create(loc, orderedCmp, left, right); - auto rightIsNan = builder.create( - 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(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(loc, orderedCmp, left, right); - auto leftIsNan = builder.create( - loc, mlir::arith::CmpFPredicate::UNE, left, left); - result = builder.create(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(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(loc, unorderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, unorderedCmp, left, right); } else { // TODO: ieeeMinNum/ieeeMaxNum static_assert(behavior == ExtremumBehavior::IeeeMinMaxNum, @@ -8839,8 +8863,8 @@ static mlir::Value createExtremumCompare(mlir::Location loc, left = builder.createConvert(loc, signlessType, left); right = builder.createConvert(loc, signlessType, right); } - result = - builder.create(loc, integerPredicate, left, right); + result = mlir::arith::CmpIOp::create(builder, loc, integerPredicate, left, + right); } else if (fir::isa_char(type) || fir::isa_char(fir::unwrapRefType(type))) { // TODO: ! character min and max is tricky because the result // length is the length of the longest argument! @@ -8961,13 +8985,14 @@ IntrinsicLibrary::genVerify(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create(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( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -9007,8 +9032,8 @@ IntrinsicLibrary::genExtremumloc(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); // Handle optional kind argument @@ -9090,8 +9115,8 @@ IntrinsicLibrary::genExtremumVal(FN func, FD funcDim, FC funcChar, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -9155,7 +9180,7 @@ mlir::Value IntrinsicLibrary::genExtremum(mlir::Type, for (auto arg : args.drop_front()) { mlir::Value mask = createExtremumCompare(loc, builder, result, arg); - result = builder.create(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 93abedc43936d..50c945df5b465 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(loc, extents); + shape = fir::ShapeOp::create(builder, loc, extents); } else { llvm::SmallVector 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(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(loc, boxType, cleanedAddr, shape, - emptySlice, cleanedLengths, tdesc); + return fir::EmboxOp::create(builder, loc, boxType, cleanedAddr, shape, + emptySlice, cleanedLengths, tdesc); } //===----------------------------------------------------------------------===// @@ -106,7 +106,7 @@ class MutablePropertyReader { bool forceIRBoxRead = false) : builder{builder}, loc{loc}, box{box} { if (forceIRBoxRead || !box.isDescribedByVariables()) - irBox = builder.create(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 @@ class MutablePropertyReader { auto memrefTy = box.getBoxTy().getEleTy(); if (!fir::isa_ref_type(memrefTy)) memrefTy = builder.getRefType(memrefTy); - return builder.create(loc, memrefTy, irBox); + return fir::BoxAddrOp::create(builder, loc, memrefTy, irBox); } auto addrVar = box.getMutableProperties().addr; - return builder.create(loc, addrVar); + return fir::LoadOp::create(builder, loc, addrVar); } /// Return {lbound, extent} values read from the MutableBoxValue given /// the dimension. @@ -125,13 +125,14 @@ class MutablePropertyReader { auto idxTy = builder.getIndexType(); if (irBox) { auto dimVal = builder.createIntegerConstant(loc, idxTy, dim); - auto dimInfo = builder.create(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(loc, mutableProperties.lbounds[dim]); - auto ext = builder.create(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 @@ class MutablePropertyReader { const auto &deferred = box.getMutableProperties().deferredParams; if (deferred.empty()) fir::emitFatalError(loc, "allocatable entity has no length property"); - return builder.create(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 @@ class MutablePropertyWriter { /// 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(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 @@ class MutablePropertyWriter { if (box.isDescribedByVariables()) { auto addrVar = box.getMutableProperties().addr; auto nullTy = fir::dyn_cast_ptrEleTy(addrVar.getType()); - builder.create(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 @@ class MutablePropertyWriter { auto deallocatedBox = fir::factory::createUnallocatedBox( builder, loc, box.getBoxTy(), box.nonDeferredLenParams(), typeSourceBox, allocator); - builder.create(loc, deallocatedBox, box.getAddr()); + fir::StoreOp::create(builder, loc, deallocatedBox, box.getAddr()); } } @@ -286,7 +287,7 @@ class MutablePropertyWriter { const bool valueTypeIsVolatile = fir::isa_volatile_type(fir::unwrapRefType(box.getAddr().getType())); irBox = builder.createVolatileCast(loc, valueTypeIsVolatile, irBox); - builder.create(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 @@ class MutablePropertyWriter { mlir::ValueRange lengths) { auto castAndStore = [&](mlir::Value val, mlir::Value addr) { auto type = fir::dyn_cast_ptrEleTy(addr.getType()); - builder.create(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( - 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(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(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(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( - 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(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 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(loc, shiftType, newLbounds); + shift = fir::ShiftOp::create(builder, loc, shiftType, newLbounds); } auto reboxed = - builder.create(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(loc, idxTy, ubi, lbi); + auto diff = mlir::arith::SubIOp::create(builder, loc, idxTy, ubi, lbi); extents.emplace_back( - builder.create(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(loc, arr.getMemTy(), - arr.getAddr()); + auto rawAddr = fir::BoxAddrOp::create(builder, loc, arr.getMemTy(), + arr.getAddr()); llvm::SmallVector lenParams; if (arr.isCharacter()) { lenParams.emplace_back( @@ -678,10 +679,10 @@ void fir::factory::associateMutableBoxWithRemap( shapeArgs.push_back(ext); } auto shape = - builder.create(loc, shapeType, shapeArgs); + fir::ShapeShiftOp::create(builder, loc, shapeType, shapeArgs); auto reboxed = - builder.create(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( - loc, box.getBaseTy(), allocName, lengths, extents); + auto newStorage = fir::AllocMemOp::create(builder, loc, box.getBaseTy(), + allocName, lengths, extents); if (mlir::isa(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 safeExtents; for (mlir::Value extent : extents) safeExtents.push_back(fir::factory::genMaxWithZero(builder, loc, extent)); - auto heap = builder.create(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(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( - loc, mlir::arith::CmpIPredicate::ne, castPrevious, required); - mustReallocate = builder.create( - 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 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(loc, heap); + fir::ResultOp::create(builder, loc, heap); }) .genElse([&]() { if (storageHandler) storageHandler(getExtValForStorage(addr)); - builder.create(loc, addr); + fir::ResultOp::create(builder, loc, addr); }); ifOp.end(); auto newAddr = ifOp.getResults()[0]; - builder.create( - 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(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(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(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(loc, boxTy, nullAddr, shape, - /*emptySlice=*/mlir::Value{}, - fir::factory::elideLengthsAlreadyInType( - boxTy.unwrapInnerType(), typeParams), - polymorphicMold); - builder.create(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 db12c84496b10..03952da95b11e 100644 --- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp @@ -1091,7 +1091,7 @@ void PPCIntrinsicLibrary::genMtfsf(llvm::ArrayRef args) { builder.getContext(), builder); funcOp = builder.createFunction(loc, "llvm.ppc.mtfsf", libFuncType); } - builder.create(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(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(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(loc, newVecTy, zeroVal)}; - auto zeroSubVarg1{builder.create(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(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(loc, vargs[0], vargs[1]); + r = mlir::arith::AddIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create(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(loc, vargs[0], vargs[1]); + r = mlir::arith::MulIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create(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(loc, vargs[0], vargs[1]); + r = mlir::arith::SubIOp::create(builder, loc, vargs[0], vargs[1]); else if (isFloat) - r = builder.create(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(vecTyInfo.eleTy).getWidth()}; auto ftype{builder.getIntegerType(wd)}; auto bcVecTy{mlir::VectorType::get(vecTyInfo.len, ftype)}; - arg1 = builder.create(loc, bcVecTy, vargs[0]); - arg2 = builder.create(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(loc, arg1, arg2); + r = mlir::arith::AndIOp::create(builder, loc, arg1, arg2); else if (vop == VecOp::Xor) - r = builder.create(loc, arg1, arg2); + r = mlir::arith::XOrIOp::create(builder, loc, arg1, arg2); if (isFloat) - r = builder.create(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(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(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( - loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; + auto vNegOne{mlir::vector::BroadcastOp::create( + builder, loc, vecTyInfo.toMlirVectorType(context), negOneVal)}; - auto callOp{builder.create(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(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(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(loc, vtype, arg).getResult(); + arg = mlir::LLVM::BitcastOp::create(builder, loc, vtype, arg).getResult(); llvm::SmallVector mask{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}; - arg = builder.create(loc, arg, arg, mask); + arg = mlir::vector::ShuffleOp::create(builder, loc, arg, arg, mask); if (ty != vtype) - arg = builder.create(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(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(loc, ty, vArg1) - : builder.create(loc, ty, vArg1)}; + ? mlir::LLVM::UIToFPOp::create(builder, loc, ty, vArg1) + : mlir::LLVM::SIToFPOp::create(builder, loc, ty, vArg1)}; // construct vector<1./(1< auto constInt{mlir::dyn_cast_or_null( @@ -1595,11 +1596,11 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType, assert(constInt && "expected integer constant argument"); double f{1.0 / (1 << constInt.getInt())}; llvm::SmallVector vals{f, f}; - auto constOp{builder.create( - loc, ty, builder.getF64VectorAttr(vals))}; + auto constOp{mlir::arith::ConstantOp::create( + builder, loc, ty, builder.getF64VectorAttr(vals))}; - auto mulOp{builder.create( - 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(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<4>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; - auto callOp{builder.create(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<8>>(context, builder)}; auto funcOp{builder.createFunction(loc, fname, ftype)}; newArgs[0] = - builder.create(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(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(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( loc, builder.getIndexType(), uremOp); - return builder.create(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(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( loc, builder.getIndexType(), uremOp); mlir::Value res = - builder.create(loc, argBases[0], varg1, index); - return builder.create(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 &mergeMask = (isBEVecElemOrderOnLE()) ? rMask : mMask; - auto callOp{builder.create(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> - auto resAddr{builder.create(loc, arrRefTy, baseAddr)}; + auto resAddr{fir::ConvertOp::create(builder, loc, arrRefTy, baseAddr)}; - return builder.create(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(loc, v.getType())}; - return builder.create(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(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(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(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(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(loc, arg0, shiftVal)}; - auto offset2{builder.create(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(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(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(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(loc, newArgs[2]); + newArgs[2] = mlir::arith::NegFOp::create(builder, loc, newArgs[2]); - auto callOp{builder.create(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(loc, vi32Ty, mArg0).getResult(); - mArg1 = - builder.create(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(loc, v8Ty, negOne)}; + mlir::vector::BroadcastOp::create(builder, loc, v8Ty, negOne)}; - mMask = builder.create(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(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 // convert the result back to the original type res = builder.createConvert(loc, vi32Ty, res); if (mlirTy != vi32Ty) - res = - builder.create(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(loc, vf64Ty, mArg0).getResult(); - mArg1 = - builder.create(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 nMask; // native vector element order mask @@ -2188,9 +2189,9 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType, llvm::SmallVector mask = (isBEVecElemOrderOnLE()) ? rMask : nMask; - auto res{builder.create(loc, mArg0, mArg1, mask)}; + auto res{mlir::vector::ShuffleOp::create(builder, loc, mArg0, mArg1, mask)}; if (res.getType() != mlirTy) { - auto cast{builder.create(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(loc, bcVecTy, negOne)}; + auto vNegOne{ + mlir::vector::BroadcastOp::create(builder, loc, bcVecTy, negOne)}; // bitcast arguments to bcVecTy - auto arg1{builder.create(loc, bcVecTy, vargs[0])}; - auto arg2{builder.create(loc, bcVecTy, vargs[1])}; - auto arg3{builder.create(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(loc, arg3, vNegOne)}; - auto a1AndComp{builder.create(loc, arg1, comp)}; - auto a1OrA2{builder.create(loc, arg2, arg3)}; - auto res{builder.create(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(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(loc, mlirTyArgs[1], vecVal)}; - auto shft{builder.create(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(loc, mlirVecArgs[0], shft); + res = mlir::arith::ShRUIOp::create(builder, loc, mlirVecArgs[0], shft); else if (vop == VecOp::Sl) - res = builder.create(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(loc, bcVecTy, mlirVecArgs[0]); + mlirVecArgs[0] = mlir::vector::BitCastOp::create(builder, loc, bcVecTy, + mlirVecArgs[0]); if (mlirTyArgs[1] != bcVecTy) - mlirVecArgs[1] = - builder.create(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>>(context, builder)}; mlir::func::FuncOp funcOp{builder.createFunction(loc, funcName, funcTy)}; - auto callOp{builder.create(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(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(loc, vi8Ty, mlirVecArgs[0]) + mlir::LLVM::BitcastOp::create(builder, loc, vi8Ty, mlirVecArgs[0]) .getResult(); mlirVecArgs[1] = - builder.create(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(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(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(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( - 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( - 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( - 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(loc, i64RefTy, addr)}; + auto addrConv{fir::ConvertOp::create(builder, loc, i64RefTy, addr)}; - auto addrVal{builder.create(loc, addrConv)}; - auto splatRes{builder.create(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(loc, mlirTy, splatRes); + result = mlir::vector::BitCastOp::create(builder, loc, mlirTy, splatRes); } else result = splatRes; @@ -2795,7 +2798,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef 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(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 args) { auto len{mlir::dyn_cast(vType).getLen()}; mlir::VectorType mlirType = mlir::VectorType::get(len, eleTy); auto v0{builder.createConvert(loc, mlirType, v)}; - auto v1{builder.create(loc, targetType, v0)}; + auto v1{mlir::vector::BitCastOp::create(builder, loc, targetType, v0)}; intrArgs.push_back(v1); } else if (mlir::isa(targetType) && mlir::isa(vType)) { @@ -2822,7 +2825,7 @@ void PPCIntrinsicLibrary::genMmaIntr(llvm::ArrayRef args) { intrArgs.push_back(v); } } - auto callSt{builder.create(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 args) { mlir::Value destPtr{fir::getBase(args[0])}; mlir::Type callResultPtrType{builder.getRefType(callResult.getType())}; if (destPtr.getType() != callResultPtrType) { - destPtr = builder.create(loc, callResultPtrType, destPtr); + destPtr = + fir::ConvertOp::create(builder, loc, callResultPtrType, destPtr); } // Copy the result. - builder.create(loc, callResult, destPtr); + fir::StoreOp::create(builder, loc, callResult, destPtr); } } @@ -2901,7 +2905,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef args) { if (vop == VecOp::Stxvp) { biArgs.push_back(argBases[0]); biArgs.push_back(addr); - builder.create(loc, funcOp, biArgs); + fir::CallOp::create(builder, loc, funcOp, biArgs); return; } @@ -2911,7 +2915,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef args) { mlir::Value newArg1{nullptr}; if (stTy != arg1TyInfo.toMlirVectorType(context)) - newArg1 = builder.create(loc, stTy, cnv); + newArg1 = mlir::vector::BitCastOp::create(builder, loc, stTy, cnv); else newArg1 = cnv; @@ -2922,7 +2926,7 @@ void PPCIntrinsicLibrary::genVecStore(llvm::ArrayRef args) { biArgs.push_back(newArg1); biArgs.push_back(addr); - builder.create(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(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(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/TemporaryStorage.cpp b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp index 9d2e9837a3df8..4c648df18b328 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(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(loc, index); + mlir::Value indexValue = fir::LoadOp::create(builder, loc, index); mlir::Value newValue = - builder.create(loc, indexValue, one); - builder.create(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(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(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(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(); assert(declare && "temp must have been declared"); - builder.create(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(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(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(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(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(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(variable.getType())) { cast = - builder.create(loc, boxProcType.getEleTy(), variable); + fir::BoxAddrOp::create(builder, loc, boxProcType.getEleTy(), variable); } cast = builder.createConvert(loc, builder.getIntPtrType(), cast); static_cast(this)->pushValue(loc, builder, cast); @@ -383,7 +383,7 @@ mlir::Value fir::factory::AnyAddressStack::fetch(mlir::Location loc, mlir::Value addr = static_cast(this)->fetch(loc, builder); if (auto boxProcType = llvm::dyn_cast(addressType)) { mlir::Value cast = builder.createConvert(loc, boxProcType.getEleTy(), addr); - return builder.create(loc, boxProcType, cast); + return fir::EmboxProcOp::create(builder, loc, boxProcType, cast); } return builder.createConvert(loc, addressType, addr); }