Skip to content

[mlir][NFC] update LLVM create APIs (2/n) #149667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def LLVM_NoAliasScopeDeclOp
return success();
if (scopeAttrs->size() != 1)
return failure();
$_op = $_builder.create<LLVM::NoAliasScopeDeclOp>(
$_location, (*scopeAttrs)[0]);
$_op = LLVM::NoAliasScopeDeclOp::create(
$_builder, $_location, (*scopeAttrs)[0]);
}];
let assemblyFormat = "$scope attr-dict";
}
Expand Down Expand Up @@ -468,7 +468,7 @@ class LLVM_ConstrainedIntr<string mnem, int numArgs,
$_builder.getNamedAttr($_qualCppClassName::getRoundingModeAttrName(),
roundingModeAttr));
}], true : "") # [{
$res = $_builder.create<$_qualCppClassName>($_location,
$res = $_qualCppClassName::create($_builder, $_location,
$_resultType, mlirOperands, mlirAttrs);
}];
}
Expand Down Expand Up @@ -743,7 +743,7 @@ def LLVM_DbgLabelOp : LLVM_IntrOp<"dbg.label", [], [], [], 0> {
// Drop the intrinsic if the label translation fails due to cylic metadata.
if (!labelAttr)
return success();
$_op = $_builder.create<$_qualCppClassName>($_location, labelAttr);
$_op = $_qualCppClassName::create($_builder, $_location, labelAttr);
}];
let assemblyFormat = "$label attr-dict";
}
Expand Down Expand Up @@ -883,7 +883,7 @@ def LLVM_MatrixColumnMajorLoadOp : LLVM_OneResultIntrOp<"matrix.column.major.loa
$columns);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::MatrixColumnMajorLoadOp>(
$res = LLVM::MatrixColumnMajorLoadOp::create($_builder,
$_location, $_resultType, $data, $stride,
$_int_attr($isVolatile), $_int_attr($rows), $_int_attr($columns));
}];
Expand Down Expand Up @@ -917,7 +917,7 @@ def LLVM_MatrixColumnMajorStoreOp : LLVM_ZeroResultIntrOp<"matrix.column.major.s
$rows, $columns);
}];
string mlirBuilder = [{
$_op = $_builder.create<LLVM::MatrixColumnMajorStoreOp>(
$_op = LLVM::MatrixColumnMajorStoreOp::create($_builder,
$_location, $matrix, $data, $stride,
$_int_attr($isVolatile), $_int_attr($rows), $_int_attr($columns));
}];
Expand All @@ -940,7 +940,7 @@ def LLVM_MatrixMultiplyOp : LLVM_OneResultIntrOp<"matrix.multiply"> {
$rhs_columns);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::MatrixMultiplyOp>(
$res = LLVM::MatrixMultiplyOp::create($_builder,
$_location, $_resultType, $lhs, $rhs,
$_int_attr($lhs_rows), $_int_attr($lhs_columns), $_int_attr($rhs_columns));
}];
Expand All @@ -960,7 +960,7 @@ def LLVM_MatrixTransposeOp : LLVM_OneResultIntrOp<"matrix.transpose"> {
$matrix, $rows, $columns);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::MatrixTransposeOp>(
$res = LLVM::MatrixTransposeOp::create($_builder,
$_location, $_resultType, $matrix,
$_int_attr($rows), $_int_attr($columns));
}];
Expand Down Expand Up @@ -997,7 +997,7 @@ def LLVM_MaskedLoadOp : LLVM_OneResultIntrOp<"masked.load"> {
string mlirBuilder = [{
auto *intrinInst = dyn_cast<llvm::IntrinsicInst>(inst);
bool nontemporal = intrinInst->hasMetadata(llvm::LLVMContext::MD_nontemporal);
$res = $_builder.create<LLVM::MaskedLoadOp>($_location,
$res = LLVM::MaskedLoadOp::create($_builder, $_location,
$_resultType, $data, $mask, $pass_thru, $_int_attr($alignment),
nontemporal ? $_builder.getUnitAttr() : nullptr);
}];
Expand All @@ -1017,7 +1017,7 @@ def LLVM_MaskedStoreOp : LLVM_ZeroResultIntrOp<"masked.store"> {
$value, $data, llvm::Align($alignment), $mask);
}];
string mlirBuilder = [{
$_op = $_builder.create<LLVM::MaskedStoreOp>($_location,
$_op = LLVM::MaskedStoreOp::create($_builder, $_location,
$value, $data, $mask, $_int_attr($alignment));
}];
list<int> llvmArgIndices = [0, 1, 3, 2];
Expand All @@ -1040,7 +1040,7 @@ def LLVM_masked_gather : LLVM_OneResultIntrOp<"masked.gather"> {
$_resultType, $ptrs, llvm::Align($alignment), $mask, $pass_thru[0]);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::masked_gather>($_location,
$res = LLVM::masked_gather::create($_builder, $_location,
$_resultType, $ptrs, $mask, $pass_thru, $_int_attr($alignment));
}];
list<int> llvmArgIndices = [0, 2, 3, 1];
Expand All @@ -1061,7 +1061,7 @@ def LLVM_masked_scatter : LLVM_ZeroResultIntrOp<"masked.scatter"> {
$value, $ptrs, llvm::Align($alignment), $mask);
}];
string mlirBuilder = [{
$_op = $_builder.create<LLVM::masked_scatter>($_location,
$_op = LLVM::masked_scatter::create($_builder, $_location,
$value, $ptrs, $mask, $_int_attr($alignment));
}];
list<int> llvmArgIndices = [0, 1, 3, 2];
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class LLVM_IntrOpBase<Dialect dialect, string opName, string enumName,
}
SmallVector<Type> resultTypes =
}] # !if(!gt(numResults, 0), "{$_resultType};", "{};") # [{
auto op = $_builder.create<$_qualCppClassName>(
auto op = $_qualCppClassName::create($_builder,
$_location, resultTypes, mlirOperands, mlirAttrs);
}];
string baseMlirBuilderCoda = !if(!gt(numResults, 0), "$res = op;", "$_op = op;");
Expand Down
58 changes: 29 additions & 29 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LLVM_IntArithmeticOp<string mnemonic, string instName,
LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName, traits> {
let arguments = commonArgs;
string mlirBuilder = [{
$res = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
$res = $_qualCppClassName::create($_builder, $_location, $lhs, $rhs);
}];
}
class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName,
Expand All @@ -64,7 +64,7 @@ class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName,
let arguments = !con(commonArgs, iofArg);

string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
auto op = $_qualCppClassName::create($_builder, $_location, $lhs, $rhs);
moduleImport.setIntegerOverflowFlags(inst, op);
$res = op;
}];
Expand All @@ -82,7 +82,7 @@ class LLVM_IntArithmeticOpWithExactFlag<string mnemonic, string instName,
let arguments = !con(commonArgs, (ins UnitAttr:$isExact));

string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
auto op = $_qualCppClassName::create($_builder, $_location, $lhs, $rhs);
moduleImport.setExactFlag(inst, op);
$res = op;
}];
Expand All @@ -100,7 +100,7 @@ class LLVM_IntArithmeticOpWithDisjointFlag<string mnemonic, string instName,
let arguments = !con(commonArgs, (ins UnitAttr:$isDisjoint));

string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
auto op = $_qualCppClassName::create($_builder, $_location, $lhs, $rhs);
moduleImport.setDisjointFlag(inst, op);
$res = op;
}];
Expand All @@ -121,7 +121,7 @@ class LLVM_FloatArithmeticOp<string mnemonic, string instName,
ins DefaultValuedAttr<LLVM_FastmathFlagsAttr, "{}">:$fastmathFlags);
let arguments = !con(commonArgs, fmfArg);
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
auto op = $_qualCppClassName::create($_builder, $_location, $lhs, $rhs);
moduleImport.setFastmathFlagsAttr(inst, op);
$res = op;
}];
Expand All @@ -141,7 +141,7 @@ class LLVM_UnaryFloatArithmeticOp<Type type, string mnemonic,
let assemblyFormat = "$operand attr-dict `:` type($res)";
string llvmInstName = instName;
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $operand);
auto op = $_qualCppClassName::create($_builder, $_location, $operand);
moduleImport.setFastmathFlagsAttr(inst, op);
$res = op;
}];
Expand Down Expand Up @@ -193,7 +193,7 @@ def LLVM_ICmpOp : LLVM_ArithmeticCmpOp<"icmp", [Pure]> {
}];
string mlirBuilder = [{
auto *iCmpInst = cast<llvm::ICmpInst>(inst);
$res = $_builder.create<$_qualCppClassName>($_location,
$res = $_qualCppClassName::create($_builder, $_location,
convertICmpPredicateFromLLVM(iCmpInst->getPredicate()), $lhs, $rhs);
}];
// Set the $predicate index to -1 to indicate there is no matching operand
Expand All @@ -217,7 +217,7 @@ def LLVM_FCmpOp : LLVM_ArithmeticCmpOp<"fcmp", [
}];
string mlirBuilder = [{
auto *fCmpInst = cast<llvm::FCmpInst>(inst);
auto op = $_builder.create<$_qualCppClassName>(
auto op = $_qualCppClassName::create($_builder,
$_location, convertFCmpPredicateFromLLVM(fCmpInst->getPredicate()), $lhs, $rhs);
moduleImport.setFastmathFlagsAttr(inst, op);
$res = op;
Expand Down Expand Up @@ -261,7 +261,7 @@ def LLVM_AllocaOp : LLVM_Op<"alloca",
Type allocatedType =
moduleImport.convertType(allocaInst->getAllocatedType());
unsigned alignment = allocaInst->getAlign().value();
$res = $_builder.create<LLVM::AllocaOp>(
$res = LLVM::AllocaOp::create($_builder,
$_location, $_resultType, $arraySize,
alignment == 0 ? IntegerAttr() : $_builder.getI64IntegerAttr(alignment),
allocatedType, allocaInst->isUsedWithInAlloca());
Expand Down Expand Up @@ -440,7 +440,7 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
string mlirBuilder = [{
auto *loadInst = cast<llvm::LoadInst>(inst);
unsigned alignment = loadInst->getAlign().value();
$res = $_builder.create<LLVM::LoadOp>($_location, $_resultType, $addr,
$res = LLVM::LoadOp::create($_builder, $_location, $_resultType, $addr,
alignment, loadInst->isVolatile(),
loadInst->hasMetadata(llvm::LLVMContext::MD_nontemporal),
loadInst->hasMetadata(llvm::LLVMContext::MD_invariant_load),
Expand Down Expand Up @@ -518,7 +518,7 @@ def LLVM_StoreOp : LLVM_MemAccessOpBase<"store",
string mlirBuilder = [{
auto *storeInst = cast<llvm::StoreInst>(inst);
unsigned alignment = storeInst->getAlign().value();
$_op = $_builder.create<LLVM::StoreOp>($_location, $value, $addr,
$_op = LLVM::StoreOp::create($_builder, $_location, $value, $addr,
alignment, storeInst->isVolatile(),
storeInst->hasMetadata(llvm::LLVMContext::MD_nontemporal),
storeInst->hasMetadata(llvm::LLVMContext::MD_invariant_group),
Expand Down Expand Up @@ -547,7 +547,7 @@ class LLVM_CastOp<string mnemonic, string instName, Type type,
let assemblyFormat = "$arg attr-dict `:` type($arg) `to` type($res)";
string llvmInstName = instName;
string mlirBuilder = [{
$res = $_builder.create<$_qualCppClassName>(
$res = $_qualCppClassName::create($_builder,
$_location, $_resultType, $arg);
}];
}
Expand All @@ -561,7 +561,7 @@ class LLVM_CastOpWithNNegFlag<string mnemonic, string instName, Type type,
let assemblyFormat = "(`nneg` $nonNeg^)? $arg attr-dict `:` type($arg) `to` type($res)";
string llvmInstName = instName;
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>(
auto op = $_qualCppClassName::create($_builder,
$_location, $_resultType, $arg);
moduleImport.setNonNegFlag(inst, op);
$res = op;
Expand All @@ -578,7 +578,7 @@ class LLVM_CastOpWithOverflowFlag<string mnemonic, string instName, Type type,
let assemblyFormat = "$arg ($overflowFlags^)? attr-dict `:` type($arg) `to` type($res)";
string llvmInstName = instName;
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>(
auto op = $_qualCppClassName::create($_builder,
$_location, $_resultType, $arg);
moduleImport.setIntegerOverflowFlags(inst, op);
$res = op;
Expand All @@ -602,7 +602,7 @@ class LLVM_DereferenceableCastOp<string mnemonic, string instName, Type type,
}
}];
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>(
auto op = $_qualCppClassName::create($_builder,
$_location, $_resultType, $arg);
$res = op;
}];
Expand Down Expand Up @@ -725,7 +725,7 @@ def LLVM_VaArgOp : LLVM_Op<"va_arg"> {

string llvmInstName = "VAArg";
string mlirBuilder = [{
$res = $_builder.create<mlir::LLVM::VaArgOp>(
$res = mlir::LLVM::VaArgOp::create($_builder,
$_location, $_resultType, $arg);
}];
}
Expand Down Expand Up @@ -847,7 +847,7 @@ def LLVM_ExtractElementOp : LLVM_Op<"extractelement", [Pure,
$res = builder.CreateExtractElement($vector, $position);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::ExtractElementOp>(
$res = LLVM::ExtractElementOp::create($_builder,
$_location, $vector, $position);
}];
}
Expand Down Expand Up @@ -881,7 +881,7 @@ def LLVM_ExtractValueOp : LLVM_Op<"extractvalue", [Pure]> {
}];
string mlirBuilder = [{
auto *evInst = cast<llvm::ExtractValueInst>(inst);
$res = $_builder.create<LLVM::ExtractValueOp>($_location,
$res = LLVM::ExtractValueOp::create($_builder, $_location,
$container, getPositionFromIndices(evInst->getIndices()));
}];
}
Expand Down Expand Up @@ -913,7 +913,7 @@ def LLVM_InsertElementOp : LLVM_Op<"insertelement", [Pure,
$res = builder.CreateInsertElement($vector, $value, $position);
}];
string mlirBuilder = [{
$res = $_builder.create<LLVM::InsertElementOp>(
$res = LLVM::InsertElementOp::create($_builder,
$_location, $vector, $value, $position);
}];
}
Expand Down Expand Up @@ -945,7 +945,7 @@ def LLVM_InsertValueOp : LLVM_Op<
}];
string mlirBuilder = [{
auto *ivInst = cast<llvm::InsertValueInst>(inst);
$res = $_builder.create<LLVM::InsertValueOp>($_location,
$res = LLVM::InsertValueOp::create($_builder, $_location,
$container, $value, getPositionFromIndices(ivInst->getIndices()));
}];
}
Expand Down Expand Up @@ -982,7 +982,7 @@ def LLVM_ShuffleVectorOp : LLVM_Op<"shufflevector",
string mlirBuilder = [{
auto *svInst = cast<llvm::ShuffleVectorInst>(inst);
SmallVector<int32_t> mask(svInst->getShuffleMask());
$res = $_builder.create<LLVM::ShuffleVectorOp>(
$res = LLVM::ShuffleVectorOp::create($_builder,
$_location, $v1, $v2, mask);
}];
}
Expand All @@ -1003,7 +1003,7 @@ def LLVM_SelectOp
let assemblyFormat = "operands attr-dict `:` type($condition) `,` type($res)";
string llvmInstName = "Select";
string mlirBuilder = [{
auto op = $_builder.create<LLVM::SelectOp>(
auto op = LLVM::SelectOp::create($_builder,
$_location, $_resultType, $condition, $trueValue, $falseValue);
moduleImport.setFastmathFlagsAttr(inst, op);
$res = op;
Expand All @@ -1017,7 +1017,7 @@ def LLVM_FreezeOp : LLVM_Op<"freeze", [Pure, SameOperandsAndResultType]> {
string llvmInstName = "Freeze";
string llvmBuilder = "$res = builder.CreateFreeze($val);";
string mlirBuilder = [{
$res = $_builder.create<LLVM::FreezeOp>($_location, $val);
$res = LLVM::FreezeOp::create($_builder, $_location, $val);
}];
}

Expand Down Expand Up @@ -1108,7 +1108,7 @@ def LLVM_ReturnOp : LLVM_TerminatorOp<"return", [Pure, ReturnLike]> {
moduleImport.convertValues(llvmOperands);
if (failed(mlirOperands))
return failure();
$_op = $_builder.create<LLVM::ReturnOp>($_location, *mlirOperands);
$_op = LLVM::ReturnOp::create($_builder, $_location, *mlirOperands);
}];
}

Expand All @@ -1120,15 +1120,15 @@ def LLVM_ResumeOp : LLVM_TerminatorOp<"resume"> {
string llvmInstName = "Resume";
string llvmBuilder = [{ builder.CreateResume($value); }];
string mlirBuilder = [{
$_op = $_builder.create<LLVM::ResumeOp>($_location, $value);
$_op = LLVM::ResumeOp::create($_builder, $_location, $value);
}];
}
def LLVM_UnreachableOp : LLVM_TerminatorOp<"unreachable"> {
let assemblyFormat = "attr-dict";
string llvmInstName = "Unreachable";
string llvmBuilder = [{ builder.CreateUnreachable(); }];
string mlirBuilder = [{
$_op = $_builder.create<LLVM::UnreachableOp>($_location);
$_op = LLVM::UnreachableOp::create($_builder, $_location);
}];
}

Expand Down Expand Up @@ -2256,7 +2256,7 @@ def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [
string mlirBuilder = [{
auto *atomicInst = cast<llvm::AtomicRMWInst>(inst);
unsigned alignment = atomicInst->getAlign().value();
$res = $_builder.create<LLVM::AtomicRMWOp>($_location,
$res = LLVM::AtomicRMWOp::create($_builder, $_location,
convertAtomicBinOpFromLLVM(atomicInst->getOperation()), $ptr, $val,
convertAtomicOrderingFromLLVM(atomicInst->getOrdering()),
getLLVMSyncScope(atomicInst), alignment, atomicInst->isVolatile());
Expand Down Expand Up @@ -2311,7 +2311,7 @@ def LLVM_AtomicCmpXchgOp : LLVM_MemAccessOpBase<"cmpxchg", [
string mlirBuilder = [{
auto *cmpXchgInst = cast<llvm::AtomicCmpXchgInst>(inst);
unsigned alignment = cmpXchgInst->getAlign().value();
$res = $_builder.create<LLVM::AtomicCmpXchgOp>(
$res = LLVM::AtomicCmpXchgOp::create($_builder,
$_location, $ptr, $cmp, $val,
convertAtomicOrderingFromLLVM(cmpXchgInst->getSuccessOrdering()),
convertAtomicOrderingFromLLVM(cmpXchgInst->getFailureOrdering()),
Expand Down Expand Up @@ -2340,7 +2340,7 @@ def LLVM_FenceOp : LLVM_Op<"fence">, LLVM_MemOpPatterns {
}] # setSyncScopeCode;
string mlirBuilder = [{
llvm::FenceInst *fenceInst = cast<llvm::FenceInst>(inst);
$_op = $_builder.create<LLVM::FenceOp>(
$_op = LLVM::FenceOp::create($_builder,
$_location,
convertAtomicOrderingFromLLVM(fenceInst->getOrdering()),
getLLVMSyncScope(fenceInst));
Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void PtxBuilder::insertValue(Value v, PTXRegisterMod itype) {
}
for (auto [idx, t] : llvm::enumerate(stype.getBody())) {
if (itype != PTXRegisterMod::Write) {
Value extractValue = rewriter.create<LLVM::ExtractValueOp>(
interfaceOp->getLoc(), v, idx);
Value extractValue = LLVM::ExtractValueOp::create(
rewriter, interfaceOp->getLoc(), v, idx);
addValue(extractValue);
}
if (itype == PTXRegisterMod::ReadWrite) {
Expand Down Expand Up @@ -132,8 +132,8 @@ LLVM::InlineAsmOp PtxBuilder::build() {
// Replace all % with $
llvm::replace(ptxInstruction, '%', '$');

return rewriter.create<LLVM::InlineAsmOp>(
interfaceOp->getLoc(),
return LLVM::InlineAsmOp::create(
rewriter, interfaceOp->getLoc(),
/*result types=*/resultTypes,
/*operands=*/ptxOperands,
/*asm_string=*/llvm::StringRef(ptxInstruction),
Expand Down
Loading
Loading