Skip to content

[mlir][NFC] update mlir/Dialect create APIs (22/n) #149929

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 21, 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
16 changes: 8 additions & 8 deletions mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void LoopOp::addEntryAndMergeBlock(OpBuilder &builder) {
builder.createBlock(&getBody());

// Add a spirv.mlir.merge op into the merge block.
builder.create<spirv::MergeOp>(getLoc());
spirv::MergeOp::create(builder, getLoc());
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -543,15 +543,15 @@ void SelectionOp::addMergeBlock(OpBuilder &builder) {
builder.createBlock(&getBody());

// Add a spirv.mlir.merge op into the merge block.
builder.create<spirv::MergeOp>(getLoc());
spirv::MergeOp::create(builder, getLoc());
}

SelectionOp
SelectionOp::createIfThen(Location loc, Value condition,
function_ref<void(OpBuilder &builder)> thenBody,
OpBuilder &builder) {
auto selectionOp =
builder.create<spirv::SelectionOp>(loc, spirv::SelectionControl::None);
spirv::SelectionOp::create(builder, loc, spirv::SelectionControl::None);

selectionOp.addMergeBlock(builder);
Block *mergeBlock = selectionOp.getMergeBlock();
Expand All @@ -562,17 +562,17 @@ SelectionOp::createIfThen(Location loc, Value condition,
OpBuilder::InsertionGuard guard(builder);
thenBlock = builder.createBlock(mergeBlock);
thenBody(builder);
builder.create<spirv::BranchOp>(loc, mergeBlock);
spirv::BranchOp::create(builder, loc, mergeBlock);
}

// Build the header block.
{
OpBuilder::InsertionGuard guard(builder);
builder.createBlock(thenBlock);
builder.create<spirv::BranchConditionalOp>(
loc, condition, thenBlock,
/*trueArguments=*/ArrayRef<Value>(), mergeBlock,
/*falseArguments=*/ArrayRef<Value>());
spirv::BranchConditionalOp::create(builder, loc, condition, thenBlock,
/*trueArguments=*/ArrayRef<Value>(),
mergeBlock,
/*falseArguments=*/ArrayRef<Value>());
}

return selectionOp;
Expand Down
24 changes: 12 additions & 12 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ struct IAddCarryFold final : OpRewritePattern<spirv::IAddCarryOp> {
return failure();

Value addsVal =
rewriter.create<spirv::ConstantOp>(loc, constituentType, adds);
spirv::ConstantOp::create(rewriter, loc, constituentType, adds);

Value carrysVal =
rewriter.create<spirv::ConstantOp>(loc, constituentType, carrys);
spirv::ConstantOp::create(rewriter, loc, constituentType, carrys);

// Create empty struct
Value undef = rewriter.create<spirv::UndefOp>(loc, op.getType());
Value undef = spirv::UndefOp::create(rewriter, loc, op.getType());
// Fill in adds at id 0
Value intermediate =
rewriter.create<spirv::CompositeInsertOp>(loc, addsVal, undef, 0);
spirv::CompositeInsertOp::create(rewriter, loc, addsVal, undef, 0);
// Fill in carrys at id 1
rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(op, carrysVal,
intermediate, 1);
Expand Down Expand Up @@ -260,16 +260,16 @@ struct MulExtendedFold final : OpRewritePattern<MulOp> {
return failure();

Value lowBitsVal =
rewriter.create<spirv::ConstantOp>(loc, constituentType, lowBits);
spirv::ConstantOp::create(rewriter, loc, constituentType, lowBits);

Value highBitsVal =
rewriter.create<spirv::ConstantOp>(loc, constituentType, highBits);
spirv::ConstantOp::create(rewriter, loc, constituentType, highBits);

// Create empty struct
Value undef = rewriter.create<spirv::UndefOp>(loc, op.getType());
Value undef = spirv::UndefOp::create(rewriter, loc, op.getType());
// Fill in lowBits at id 0
Value intermediate =
rewriter.create<spirv::CompositeInsertOp>(loc, lowBitsVal, undef, 0);
spirv::CompositeInsertOp::create(rewriter, loc, lowBitsVal, undef, 0);
// Fill in highBits at id 1
rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(op, highBitsVal,
intermediate, 1);
Expand Down Expand Up @@ -1309,11 +1309,11 @@ struct ConvertSelectionOpToSelect final : OpRewritePattern<spirv::SelectionOp> {
auto storeOpAttributes =
cast<spirv::StoreOp>(trueBlock->front())->getAttrs();

auto selectOp = rewriter.create<spirv::SelectOp>(
selectionOp.getLoc(), trueValue.getType(),
auto selectOp = spirv::SelectOp::create(
rewriter, selectionOp.getLoc(), trueValue.getType(),
brConditionalOp.getCondition(), trueValue, falseValue);
rewriter.create<spirv::StoreOp>(selectOp.getLoc(), ptrValue,
selectOp.getResult(), storeOpAttributes);
spirv::StoreOp::create(rewriter, selectOp.getLoc(), ptrValue,
selectOp.getResult(), storeOpAttributes);

// `spirv.mlir.selection` is not needed anymore.
rewriter.eraseOp(op);
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,12 @@ Operation *SPIRVDialect::materializeConstant(OpBuilder &builder,
Attribute value, Type type,
Location loc) {
if (auto poison = dyn_cast<ub::PoisonAttr>(value))
return builder.create<ub::PoisonOp>(loc, type, poison);
return ub::PoisonOp::create(builder, loc, type, poison);

if (!spirv::ConstantOp::isBuildableWith(type))
return nullptr;

return builder.create<spirv::ConstantOp>(loc, type, value);
return spirv::ConstantOp::create(builder, loc, type, value);
}

//===----------------------------------------------------------------------===//
Expand Down
42 changes: 21 additions & 21 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,26 +651,26 @@ spirv::ConstantOp spirv::ConstantOp::getZero(Type type, Location loc,
if (auto intType = llvm::dyn_cast<IntegerType>(type)) {
unsigned width = intType.getWidth();
if (width == 1)
return builder.create<spirv::ConstantOp>(loc, type,
builder.getBoolAttr(false));
return builder.create<spirv::ConstantOp>(
loc, type, builder.getIntegerAttr(type, APInt(width, 0)));
return spirv::ConstantOp::create(builder, loc, type,
builder.getBoolAttr(false));
return spirv::ConstantOp::create(
builder, loc, type, builder.getIntegerAttr(type, APInt(width, 0)));
}
if (auto floatType = llvm::dyn_cast<FloatType>(type)) {
return builder.create<spirv::ConstantOp>(
loc, type, builder.getFloatAttr(floatType, 0.0));
return spirv::ConstantOp::create(builder, loc, type,
builder.getFloatAttr(floatType, 0.0));
}
if (auto vectorType = llvm::dyn_cast<VectorType>(type)) {
Type elemType = vectorType.getElementType();
if (llvm::isa<IntegerType>(elemType)) {
return builder.create<spirv::ConstantOp>(
loc, type,
return spirv::ConstantOp::create(
builder, loc, type,
DenseElementsAttr::get(vectorType,
IntegerAttr::get(elemType, 0).getValue()));
}
if (llvm::isa<FloatType>(elemType)) {
return builder.create<spirv::ConstantOp>(
loc, type,
return spirv::ConstantOp::create(
builder, loc, type,
DenseFPElementsAttr::get(vectorType,
FloatAttr::get(elemType, 0.0).getValue()));
}
Expand All @@ -684,26 +684,26 @@ spirv::ConstantOp spirv::ConstantOp::getOne(Type type, Location loc,
if (auto intType = llvm::dyn_cast<IntegerType>(type)) {
unsigned width = intType.getWidth();
if (width == 1)
return builder.create<spirv::ConstantOp>(loc, type,
builder.getBoolAttr(true));
return builder.create<spirv::ConstantOp>(
loc, type, builder.getIntegerAttr(type, APInt(width, 1)));
return spirv::ConstantOp::create(builder, loc, type,
builder.getBoolAttr(true));
return spirv::ConstantOp::create(
builder, loc, type, builder.getIntegerAttr(type, APInt(width, 1)));
}
if (auto floatType = llvm::dyn_cast<FloatType>(type)) {
return builder.create<spirv::ConstantOp>(
loc, type, builder.getFloatAttr(floatType, 1.0));
return spirv::ConstantOp::create(builder, loc, type,
builder.getFloatAttr(floatType, 1.0));
}
if (auto vectorType = llvm::dyn_cast<VectorType>(type)) {
Type elemType = vectorType.getElementType();
if (llvm::isa<IntegerType>(elemType)) {
return builder.create<spirv::ConstantOp>(
loc, type,
return spirv::ConstantOp::create(
builder, loc, type,
DenseElementsAttr::get(vectorType,
IntegerAttr::get(elemType, 1).getValue()));
}
if (llvm::isa<FloatType>(elemType)) {
return builder.create<spirv::ConstantOp>(
loc, type,
return spirv::ConstantOp::create(
builder, loc, type,
DenseFPElementsAttr::get(vectorType,
FloatAttr::get(elemType, 1.0).getValue()));
}
Expand Down Expand Up @@ -1985,7 +1985,7 @@ ParseResult spirv::SpecConstantOperationOp::parse(OpAsmParser &parser,

OpBuilder builder(parser.getContext());
builder.setInsertionPointToEnd(&block);
builder.create<spirv::YieldOp>(wrappedOp->getLoc(), wrappedOp->getResult(0));
spirv::YieldOp::create(builder, wrappedOp->getLoc(), wrappedOp->getResult(0));
result.location = wrappedOp->getLoc();

result.addTypes(wrappedOp->getResult(0).getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ OwningOpRef<spirv::ModuleOp> combine(ArrayRef<spirv::ModuleOp> inputModules,
}
}

auto combinedModule = combinedModuleBuilder.create<spirv::ModuleOp>(
firstModule.getLoc(), addressingModel, memoryModel, vceTriple);
auto combinedModule =
spirv::ModuleOp::create(combinedModuleBuilder, firstModule.getLoc(),
addressingModel, memoryModel, vceTriple);
combinedModuleBuilder.setInsertionPointToStart(combinedModule.getBody());

// In some cases, a symbol in the (current state of the) combined module is
Expand Down
36 changes: 18 additions & 18 deletions mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ createGlobalVarForEntryPointArgument(OpBuilder &builder, spirv::FuncOp funcOp,
varType =
spirv::PointerType::get(varPointeeType, varPtrType.getStorageClass());

return builder.create<spirv::GlobalVariableOp>(
funcOp.getLoc(), varType, varName, abiInfo.getDescriptorSet(),
abiInfo.getBinding());
return spirv::GlobalVariableOp::create(builder, funcOp.getLoc(), varType,
varName, abiInfo.getDescriptorSet(),
abiInfo.getBinding());
}

/// Gets the global variables that need to be specified as interface variable
Expand Down Expand Up @@ -146,17 +146,17 @@ static LogicalResult lowerEntryPointABIAttr(spirv::FuncOp funcOp,
return funcOp.emitRemark("lower entry point failure: could not select "
"execution model based on 'spirv.target_env'");

builder.create<spirv::EntryPointOp>(funcOp.getLoc(), *executionModel, funcOp,
interfaceVars);
spirv::EntryPointOp::create(builder, funcOp.getLoc(), *executionModel, funcOp,
interfaceVars);

// Specifies the spirv.ExecutionModeOp.
if (DenseI32ArrayAttr workgroupSizeAttr = entryPointAttr.getWorkgroupSize()) {
std::optional<ArrayRef<spirv::Capability>> caps =
spirv::getCapabilities(spirv::ExecutionMode::LocalSize);
if (!caps || targetEnv.allows(*caps)) {
builder.create<spirv::ExecutionModeOp>(funcOp.getLoc(), funcOp,
spirv::ExecutionMode::LocalSize,
workgroupSizeAttr.asArrayRef());
spirv::ExecutionModeOp::create(builder, funcOp.getLoc(), funcOp,
spirv::ExecutionMode::LocalSize,
workgroupSizeAttr.asArrayRef());
// Erase workgroup size.
entryPointAttr = spirv::EntryPointABIAttr::get(
entryPointAttr.getContext(), DenseI32ArrayAttr(),
Expand All @@ -167,9 +167,9 @@ static LogicalResult lowerEntryPointABIAttr(spirv::FuncOp funcOp,
std::optional<ArrayRef<spirv::Capability>> caps =
spirv::getCapabilities(spirv::ExecutionMode::SubgroupSize);
if (!caps || targetEnv.allows(*caps)) {
builder.create<spirv::ExecutionModeOp>(funcOp.getLoc(), funcOp,
spirv::ExecutionMode::SubgroupSize,
*subgroupSize);
spirv::ExecutionModeOp::create(builder, funcOp.getLoc(), funcOp,
spirv::ExecutionMode::SubgroupSize,
*subgroupSize);
// Erase subgroup size.
entryPointAttr = spirv::EntryPointABIAttr::get(
entryPointAttr.getContext(), entryPointAttr.getWorkgroupSize(),
Expand All @@ -180,8 +180,8 @@ static LogicalResult lowerEntryPointABIAttr(spirv::FuncOp funcOp,
std::optional<ArrayRef<spirv::Capability>> caps =
spirv::getCapabilities(spirv::ExecutionMode::SignedZeroInfNanPreserve);
if (!caps || targetEnv.allows(*caps)) {
builder.create<spirv::ExecutionModeOp>(
funcOp.getLoc(), funcOp,
spirv::ExecutionModeOp::create(
builder, funcOp.getLoc(), funcOp,
spirv::ExecutionMode::SignedZeroInfNanPreserve, *targetWidth);
// Erase target width.
entryPointAttr = spirv::EntryPointABIAttr::get(
Expand Down Expand Up @@ -259,7 +259,7 @@ LogicalResult ProcessInterfaceVarABI::matchAndRewrite(

// Insert spirv::AddressOf and spirv::AccessChain operations.
Value replacement =
rewriter.create<spirv::AddressOfOp>(funcOp.getLoc(), var);
spirv::AddressOfOp::create(rewriter, funcOp.getLoc(), var);
// Check if the arg is a scalar or vector type. In that case, the value
// needs to be loaded into registers.
// TODO: This is loading value of the scalar into registers
Expand All @@ -269,9 +269,9 @@ LogicalResult ProcessInterfaceVarABI::matchAndRewrite(
if (cast<spirv::SPIRVType>(argType.value()).isScalarOrVector()) {
auto zero =
spirv::ConstantOp::getZero(indexType, funcOp.getLoc(), rewriter);
auto loadPtr = rewriter.create<spirv::AccessChainOp>(
funcOp.getLoc(), replacement, zero.getConstant());
replacement = rewriter.create<spirv::LoadOp>(funcOp.getLoc(), loadPtr);
auto loadPtr = spirv::AccessChainOp::create(
rewriter, funcOp.getLoc(), replacement, zero.getConstant());
replacement = spirv::LoadOp::create(rewriter, funcOp.getLoc(), loadPtr);
}
signatureConverter.remapInput(argType.index(), replacement);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ void LowerABIAttributesPass::runOnOperation() {
ValueRange inputs, Location loc) {
if (inputs.size() != 1 || !isa<spirv::PointerType>(inputs[0].getType()))
return Value();
return builder.create<spirv::BitcastOp>(loc, type, inputs[0]).getResult();
return spirv::BitcastOp::create(builder, loc, type, inputs[0]).getResult();
});

RewritePatternSet patterns(context);
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void RewriteInsertsPass::runOnOperation() {
operands.push_back(insertionOp.getObject());

OpBuilder builder(lastCompositeInsertOp);
auto compositeConstructOp = builder.create<spirv::CompositeConstructOp>(
location, compositeType, operands);
auto compositeConstructOp = spirv::CompositeConstructOp::create(
builder, location, compositeType, operands);

lastCompositeInsertOp.replaceAllUsesWith(
compositeConstructOp->getResult(0));
Expand Down
Loading
Loading