Skip to content

[mlir][NFC] update mlir/lib create APIs (26/n) #149933

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 2 commits into from
Jul 22, 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
2 changes: 1 addition & 1 deletion mlir/lib/IR/BuiltinDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void ModuleOp::build(OpBuilder &builder, OperationState &state,
/// Construct a module from the given context.
ModuleOp ModuleOp::create(Location loc, std::optional<StringRef> name) {
OpBuilder builder(loc->getContext());
return builder.create<ModuleOp>(loc, name);
return ModuleOp::create(builder, loc, name);
}

DataLayoutSpecInterface ModuleOp::getDataLayoutSpec() {
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Query/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static Operation *extractFunction(std::vector<Operation *> &ops,
clonedOp->result_end());
}
// Add return operation
builder.create<func::ReturnOp>(loc, clonedVals);
func::ReturnOp::create(builder, loc, clonedVals);

// Remove unused function arguments
size_t currentIndex = 0;
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Target/LLVMIR/LLVMImportInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
return failure();

Type resultType = moduleImport.convertType(inst->getType());
auto op = builder.create<::mlir::LLVM::CallIntrinsicOp>(
moduleImport.translateLoc(inst->getDebugLoc()),
auto op = CallIntrinsicOp::create(
builder, moduleImport.translateLoc(inst->getDebugLoc()),
isa<LLVMVoidType>(resultType) ? TypeRange{} : TypeRange{resultType},
StringAttr::get(builder.getContext(), intrinName),
ValueRange{mlirOperands}, FastmathFlagsAttr{});
Expand Down
141 changes: 71 additions & 70 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp

Large diffs are not rendered by default.

50 changes: 27 additions & 23 deletions mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,38 @@ static inline spirv::Opcode extractOpcode(uint32_t word) {
Value spirv::Deserializer::getValue(uint32_t id) {
if (auto constInfo = getConstant(id)) {
// Materialize a `spirv.Constant` op at every use site.
return opBuilder.create<spirv::ConstantOp>(unknownLoc, constInfo->second,
constInfo->first);
return spirv::ConstantOp::create(opBuilder, unknownLoc, constInfo->second,
constInfo->first);
}
if (std::optional<std::pair<Attribute, Type>> constCompositeReplicateInfo =
getConstantCompositeReplicate(id)) {
return opBuilder.create<spirv::EXTConstantCompositeReplicateOp>(
unknownLoc, constCompositeReplicateInfo->second,
return spirv::EXTConstantCompositeReplicateOp::create(
opBuilder, unknownLoc, constCompositeReplicateInfo->second,
constCompositeReplicateInfo->first);
}
if (auto varOp = getGlobalVariable(id)) {
auto addressOfOp = opBuilder.create<spirv::AddressOfOp>(
unknownLoc, varOp.getType(), SymbolRefAttr::get(varOp.getOperation()));
auto addressOfOp =
spirv::AddressOfOp::create(opBuilder, unknownLoc, varOp.getType(),
SymbolRefAttr::get(varOp.getOperation()));
return addressOfOp.getPointer();
}
if (auto constOp = getSpecConstant(id)) {
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
unknownLoc, constOp.getDefaultValue().getType(),
auto referenceOfOp = spirv::ReferenceOfOp::create(
opBuilder, unknownLoc, constOp.getDefaultValue().getType(),
SymbolRefAttr::get(constOp.getOperation()));
return referenceOfOp.getReference();
}
if (SpecConstantCompositeOp specConstCompositeOp =
getSpecConstantComposite(id)) {
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
unknownLoc, specConstCompositeOp.getType(),
auto referenceOfOp = spirv::ReferenceOfOp::create(
opBuilder, unknownLoc, specConstCompositeOp.getType(),
SymbolRefAttr::get(specConstCompositeOp.getOperation()));
return referenceOfOp.getReference();
}
if (auto specConstCompositeReplicateOp =
getSpecConstantCompositeReplicate(id)) {
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
unknownLoc, specConstCompositeReplicateOp.getType(),
auto referenceOfOp = spirv::ReferenceOfOp::create(
opBuilder, unknownLoc, specConstCompositeReplicateOp.getType(),
SymbolRefAttr::get(specConstCompositeReplicateOp.getOperation()));
return referenceOfOp.getReference();
}
Expand All @@ -83,7 +84,7 @@ Value spirv::Deserializer::getValue(uint32_t id) {
specConstOperationInfo->enclosedOpOperands);
}
if (auto undef = getUndefType(id)) {
return opBuilder.create<spirv::UndefOp>(unknownLoc, undef);
return spirv::UndefOp::create(opBuilder, unknownLoc, undef);
}
return valueMap.lookup(id);
}
Expand Down Expand Up @@ -387,8 +388,9 @@ Deserializer::processOp<spirv::EntryPointOp>(ArrayRef<uint32_t> words) {
interface.push_back(SymbolRefAttr::get(arg.getOperation()));
wordIndex++;
}
opBuilder.create<spirv::EntryPointOp>(
unknownLoc, execModel, SymbolRefAttr::get(opBuilder.getContext(), fnName),
spirv::EntryPointOp::create(
opBuilder, unknownLoc, execModel,
SymbolRefAttr::get(opBuilder.getContext(), fnName),
opBuilder.getArrayAttr(interface));
return success();
}
Expand Down Expand Up @@ -420,9 +422,10 @@ Deserializer::processOp<spirv::ExecutionModeOp>(ArrayRef<uint32_t> words) {
attrListElems.push_back(opBuilder.getI32IntegerAttr(words[wordIndex++]));
}
auto values = opBuilder.getArrayAttr(attrListElems);
opBuilder.create<spirv::ExecutionModeOp>(
unknownLoc, SymbolRefAttr::get(opBuilder.getContext(), fn.getName()),
execMode, values);
spirv::ExecutionModeOp::create(
opBuilder, unknownLoc,
SymbolRefAttr::get(opBuilder.getContext(), fn.getName()), execMode,
values);
return success();
}

Expand Down Expand Up @@ -459,8 +462,8 @@ Deserializer::processOp<spirv::FunctionCallOp>(ArrayRef<uint32_t> operands) {
arguments.push_back(value);
}

auto opFunctionCall = opBuilder.create<spirv::FunctionCallOp>(
unknownLoc, resultType,
auto opFunctionCall = spirv::FunctionCallOp::create(
opBuilder, unknownLoc, resultType,
SymbolRefAttr::get(opBuilder.getContext(), functionName), arguments);

if (resultType)
Expand Down Expand Up @@ -536,7 +539,8 @@ Deserializer::processOp<spirv::CopyMemoryOp>(ArrayRef<uint32_t> words) {
}

Location loc = createFileLineColLoc(opBuilder);
opBuilder.create<spirv::CopyMemoryOp>(loc, resultTypes, operands, attributes);
spirv::CopyMemoryOp::create(opBuilder, loc, resultTypes, operands,
attributes);

return success();
}
Expand Down Expand Up @@ -567,8 +571,8 @@ LogicalResult Deserializer::processOp<spirv::GenericCastToPtrExplicitOp>(
operands.push_back(arg);

Location loc = createFileLineColLoc(opBuilder);
Operation *op = opBuilder.create<spirv::GenericCastToPtrExplicitOp>(
loc, resultTypes, operands);
Operation *op = spirv::GenericCastToPtrExplicitOp::create(
opBuilder, loc, resultTypes, operands);
valueMap[valueID] = op->getResult(0);
return success();
}
Expand Down
68 changes: 34 additions & 34 deletions mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ spirv::Deserializer::processFunction(ArrayRef<uint32_t> operands) {
}

std::string fnName = getFunctionSymbol(fnID);
auto funcOp = opBuilder.create<spirv::FuncOp>(
unknownLoc, fnName, functionType, fnControl.value());
auto funcOp = spirv::FuncOp::create(opBuilder, unknownLoc, fnName,
functionType, fnControl.value());
// Processing other function attributes.
if (decorations.count(fnID)) {
for (auto attr : decorations[fnID].getAttrs()) {
Expand Down Expand Up @@ -714,8 +714,8 @@ spirv::SpecConstantOp
spirv::Deserializer::createSpecConstant(Location loc, uint32_t resultID,
TypedAttr defaultValue) {
auto symName = opBuilder.getStringAttr(getSpecConstantSymbol(resultID));
auto op = opBuilder.create<spirv::SpecConstantOp>(unknownLoc, symName,
defaultValue);
auto op = spirv::SpecConstantOp::create(opBuilder, unknownLoc, symName,
defaultValue);
if (decorations.count(resultID)) {
for (auto attr : decorations[resultID].getAttrs())
op->setAttr(attr.getName(), attr.getValue());
Expand Down Expand Up @@ -790,9 +790,9 @@ spirv::Deserializer::processGlobalVariable(ArrayRef<uint32_t> operands) {
<< wordIndex << " of " << operands.size() << " processed";
}
auto loc = createFileLineColLoc(opBuilder);
auto varOp = opBuilder.create<spirv::GlobalVariableOp>(
loc, TypeAttr::get(type), opBuilder.getStringAttr(variableName),
initializer);
auto varOp = spirv::GlobalVariableOp::create(
opBuilder, loc, TypeAttr::get(type),
opBuilder.getStringAttr(variableName), initializer);

// Decorations.
if (decorations.count(variableID)) {
Expand Down Expand Up @@ -1637,8 +1637,8 @@ spirv::Deserializer::processSpecConstantComposite(ArrayRef<uint32_t> operands) {
elements.push_back(SymbolRefAttr::get(elementInfo));
}

auto op = opBuilder.create<spirv::SpecConstantCompositeOp>(
unknownLoc, TypeAttr::get(resultType), symName,
auto op = spirv::SpecConstantCompositeOp::create(
opBuilder, unknownLoc, TypeAttr::get(resultType), symName,
opBuilder.getArrayAttr(elements));
specConstCompositeMap[resultID] = op;

Expand Down Expand Up @@ -1671,8 +1671,8 @@ LogicalResult spirv::Deserializer::processSpecConstantCompositeReplicateEXT(
auto symName = opBuilder.getStringAttr(getSpecConstantSymbol(resultID));
spirv::SpecConstantOp constituentSpecConstantOp =
getSpecConstant(operands[2]);
auto op = opBuilder.create<spirv::EXTSpecConstantCompositeReplicateOp>(
unknownLoc, TypeAttr::get(resultType), symName,
auto op = spirv::EXTSpecConstantCompositeReplicateOp::create(
opBuilder, unknownLoc, TypeAttr::get(resultType), symName,
SymbolRefAttr::get(constituentSpecConstantOp));

specConstCompositeReplicateMap[resultID] = op;
Expand Down Expand Up @@ -1747,7 +1747,7 @@ Value spirv::Deserializer::materializeSpecConstantOperation(

auto loc = createFileLineColLoc(opBuilder);
auto specConstOperationOp =
opBuilder.create<spirv::SpecConstantOperationOp>(loc, resultType);
spirv::SpecConstantOperationOp::create(opBuilder, loc, resultType);

Region &body = specConstOperationOp.getBody();
// Move the new block into SpecConstantOperation's body.
Expand All @@ -1760,7 +1760,7 @@ Value spirv::Deserializer::materializeSpecConstantOperation(
OpBuilder::InsertionGuard moduleInsertionGuard(opBuilder);
opBuilder.setInsertionPointToEnd(&block);

opBuilder.create<spirv::YieldOp>(loc, block.front().getResult(0));
spirv::YieldOp::create(opBuilder, loc, block.front().getResult(0));
return specConstOperationOp.getResult();
}

Expand Down Expand Up @@ -1824,7 +1824,7 @@ LogicalResult spirv::Deserializer::processBranch(ArrayRef<uint32_t> operands) {
// The preceding instruction for the OpBranch instruction could be an
// OpLoopMerge or an OpSelectionMerge instruction, in this case they will have
// the same OpLine information.
opBuilder.create<spirv::BranchOp>(loc, target);
spirv::BranchOp::create(opBuilder, loc, target);

clearDebugLine();
return success();
Expand Down Expand Up @@ -1855,8 +1855,8 @@ spirv::Deserializer::processBranchConditional(ArrayRef<uint32_t> operands) {
// an OpSelectionMerge instruction, in this case they will have the same
// OpLine information.
auto loc = createFileLineColLoc(opBuilder);
opBuilder.create<spirv::BranchConditionalOp>(
loc, condition, trueBlock,
spirv::BranchConditionalOp::create(
opBuilder, loc, condition, trueBlock,
/*trueArguments=*/ArrayRef<Value>(), falseBlock,
/*falseArguments=*/ArrayRef<Value>(), weights);

Expand Down Expand Up @@ -2038,7 +2038,7 @@ ControlFlowStructurizer::createSelectionOp(uint32_t selectionControl) {
OpBuilder builder(&mergeBlock->front());

auto control = static_cast<spirv::SelectionControl>(selectionControl);
auto selectionOp = builder.create<spirv::SelectionOp>(location, control);
auto selectionOp = spirv::SelectionOp::create(builder, location, control);
selectionOp.addMergeBlock(builder);

return selectionOp;
Expand All @@ -2050,7 +2050,7 @@ spirv::LoopOp ControlFlowStructurizer::createLoopOp(uint32_t loopControl) {
OpBuilder builder(&mergeBlock->front());

auto control = static_cast<spirv::LoopControl>(loopControl);
auto loopOp = builder.create<spirv::LoopOp>(location, control);
auto loopOp = spirv::LoopOp::create(builder, location, control);
loopOp.addEntryAndMergeBlock(builder);

return loopOp;
Expand Down Expand Up @@ -2183,8 +2183,8 @@ LogicalResult ControlFlowStructurizer::structurize() {
// The loop entry block should have a unconditional branch jumping to the
// loop header block.
builder.setInsertionPointToEnd(&body.front());
builder.create<spirv::BranchOp>(location, mapper.lookupOrNull(headerBlock),
ArrayRef<Value>(blockArgs));
spirv::BranchOp::create(builder, location, mapper.lookupOrNull(headerBlock),
ArrayRef<Value>(blockArgs));
}

// Values defined inside the selection region that need to be yielded outside
Expand Down Expand Up @@ -2268,12 +2268,12 @@ LogicalResult ControlFlowStructurizer::structurize() {
Operation *newOp = nullptr;

if (isLoop)
newOp = builder.create<spirv::LoopOp>(
location, TypeRange(ValueRange(outsideUses)),
static_cast<spirv::LoopControl>(control));
newOp = spirv::LoopOp::create(builder, location,
TypeRange(ValueRange(outsideUses)),
static_cast<spirv::LoopControl>(control));
else
newOp = builder.create<spirv::SelectionOp>(
location, TypeRange(ValueRange(outsideUses)),
newOp = spirv::SelectionOp::create(
builder, location, TypeRange(ValueRange(outsideUses)),
static_cast<spirv::SelectionControl>(control));

newOp->getRegion(0).takeBody(body);
Expand Down Expand Up @@ -2399,7 +2399,7 @@ LogicalResult ControlFlowStructurizer::structurize() {
// but replace all ops inside with a branch to the merge block.
block->clear();
builder.setInsertionPointToEnd(block);
builder.create<spirv::BranchOp>(location, mergeBlock);
spirv::BranchOp::create(builder, location, mergeBlock);
} else {
LLVM_DEBUG(logger.startLine() << "[cf] erasing block " << block << "\n");
block->erase();
Expand Down Expand Up @@ -2453,22 +2453,22 @@ LogicalResult spirv::Deserializer::wireUpBlockArgument() {

if (auto branchOp = dyn_cast<spirv::BranchOp>(op)) {
// Replace the previous branch op with a new one with block arguments.
opBuilder.create<spirv::BranchOp>(branchOp.getLoc(), branchOp.getTarget(),
blockArgs);
spirv::BranchOp::create(opBuilder, branchOp.getLoc(),
branchOp.getTarget(), blockArgs);
branchOp.erase();
} else if (auto branchCondOp = dyn_cast<spirv::BranchConditionalOp>(op)) {
assert((branchCondOp.getTrueBlock() == target ||
branchCondOp.getFalseBlock() == target) &&
"expected target to be either the true or false target");
if (target == branchCondOp.getTrueTarget())
opBuilder.create<spirv::BranchConditionalOp>(
branchCondOp.getLoc(), branchCondOp.getCondition(), blockArgs,
branchCondOp.getFalseBlockArguments(),
spirv::BranchConditionalOp::create(
opBuilder, branchCondOp.getLoc(), branchCondOp.getCondition(),
blockArgs, branchCondOp.getFalseBlockArguments(),
branchCondOp.getBranchWeightsAttr(), branchCondOp.getTrueTarget(),
branchCondOp.getFalseTarget());
else
opBuilder.create<spirv::BranchConditionalOp>(
branchCondOp.getLoc(), branchCondOp.getCondition(),
spirv::BranchConditionalOp::create(
opBuilder, branchCondOp.getLoc(), branchCondOp.getCondition(),
branchCondOp.getTrueBlockArguments(), blockArgs,
branchCondOp.getBranchWeightsAttr(), branchCondOp.getTrueBlock(),
branchCondOp.getFalseBlock());
Expand Down Expand Up @@ -2528,7 +2528,7 @@ LogicalResult spirv::Deserializer::splitConditionalBlocks() {
if (!llvm::hasSingleElement(*block) || splitHeaderMergeBlock) {
Block *newBlock = block->splitBlock(terminator);
OpBuilder builder(block, block->end());
builder.create<spirv::BranchOp>(block->getParent()->getLoc(), newBlock);
spirv::BranchOp::create(builder, block->getParent()->getLoc(), newBlock);

// After splitting we need to update the map to use the new block as a
// header.
Expand Down
Loading