Skip to content

Commit a16eb90

Browse files
committed
[mlir][NFC] update mlir/Dialect create APIs (26/n)
See llvm#147168 for more info.
1 parent b7e332d commit a16eb90

File tree

8 files changed

+176
-170
lines changed

8 files changed

+176
-170
lines changed

mlir/lib/IR/BuiltinDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void ModuleOp::build(OpBuilder &builder, OperationState &state,
132132
/// Construct a module from the given context.
133133
ModuleOp ModuleOp::create(Location loc, std::optional<StringRef> name) {
134134
OpBuilder builder(loc->getContext());
135-
return builder.create<ModuleOp>(loc, name);
135+
return ModuleOp::create(builder, loc, name);
136136
}
137137

138138
DataLayoutSpecInterface ModuleOp::getDataLayoutSpec() {

mlir/lib/Query/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static Operation *extractFunction(std::vector<Operation *> &ops,
7777
clonedOp->result_end());
7878
}
7979
// Add return operation
80-
builder.create<func::ReturnOp>(loc, clonedVals);
80+
func::ReturnOp::create(builder, loc, clonedVals);
8181

8282
// Remove unused function arguments
8383
size_t currentIndex = 0;

mlir/lib/Target/LLVMIR/LLVMImportInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
3737
return failure();
3838

3939
Type resultType = moduleImport.convertType(inst->getType());
40-
auto op = builder.create<::mlir::LLVM::CallIntrinsicOp>(
41-
moduleImport.translateLoc(inst->getDebugLoc()),
40+
auto op = ::mlir::LLVM::CallIntrinsicOp::create(
41+
builder, moduleImport.translateLoc(inst->getDebugLoc()),
4242
isa<LLVMVoidType>(resultType) ? TypeRange{} : TypeRange{resultType},
4343
StringAttr::get(builder.getContext(), intrinName),
4444
ValueRange{mlirOperands}, FastmathFlagsAttr{});

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 71 additions & 70 deletions
Large diffs are not rendered by default.

mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,38 @@ static inline spirv::Opcode extractOpcode(uint32_t word) {
4242
Value spirv::Deserializer::getValue(uint32_t id) {
4343
if (auto constInfo = getConstant(id)) {
4444
// Materialize a `spirv.Constant` op at every use site.
45-
return opBuilder.create<spirv::ConstantOp>(unknownLoc, constInfo->second,
46-
constInfo->first);
45+
return spirv::ConstantOp::create(opBuilder, unknownLoc, constInfo->second,
46+
constInfo->first);
4747
}
4848
if (std::optional<std::pair<Attribute, Type>> constCompositeReplicateInfo =
4949
getConstantCompositeReplicate(id)) {
50-
return opBuilder.create<spirv::EXTConstantCompositeReplicateOp>(
51-
unknownLoc, constCompositeReplicateInfo->second,
50+
return spirv::EXTConstantCompositeReplicateOp::create(
51+
opBuilder, unknownLoc, constCompositeReplicateInfo->second,
5252
constCompositeReplicateInfo->first);
5353
}
5454
if (auto varOp = getGlobalVariable(id)) {
55-
auto addressOfOp = opBuilder.create<spirv::AddressOfOp>(
56-
unknownLoc, varOp.getType(), SymbolRefAttr::get(varOp.getOperation()));
55+
auto addressOfOp =
56+
spirv::AddressOfOp::create(opBuilder, unknownLoc, varOp.getType(),
57+
SymbolRefAttr::get(varOp.getOperation()));
5758
return addressOfOp.getPointer();
5859
}
5960
if (auto constOp = getSpecConstant(id)) {
60-
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
61-
unknownLoc, constOp.getDefaultValue().getType(),
61+
auto referenceOfOp = spirv::ReferenceOfOp::create(
62+
opBuilder, unknownLoc, constOp.getDefaultValue().getType(),
6263
SymbolRefAttr::get(constOp.getOperation()));
6364
return referenceOfOp.getReference();
6465
}
6566
if (SpecConstantCompositeOp specConstCompositeOp =
6667
getSpecConstantComposite(id)) {
67-
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
68-
unknownLoc, specConstCompositeOp.getType(),
68+
auto referenceOfOp = spirv::ReferenceOfOp::create(
69+
opBuilder, unknownLoc, specConstCompositeOp.getType(),
6970
SymbolRefAttr::get(specConstCompositeOp.getOperation()));
7071
return referenceOfOp.getReference();
7172
}
7273
if (auto specConstCompositeReplicateOp =
7374
getSpecConstantCompositeReplicate(id)) {
74-
auto referenceOfOp = opBuilder.create<spirv::ReferenceOfOp>(
75-
unknownLoc, specConstCompositeReplicateOp.getType(),
75+
auto referenceOfOp = spirv::ReferenceOfOp::create(
76+
opBuilder, unknownLoc, specConstCompositeReplicateOp.getType(),
7677
SymbolRefAttr::get(specConstCompositeReplicateOp.getOperation()));
7778
return referenceOfOp.getReference();
7879
}
@@ -83,7 +84,7 @@ Value spirv::Deserializer::getValue(uint32_t id) {
8384
specConstOperationInfo->enclosedOpOperands);
8485
}
8586
if (auto undef = getUndefType(id)) {
86-
return opBuilder.create<spirv::UndefOp>(unknownLoc, undef);
87+
return spirv::UndefOp::create(opBuilder, unknownLoc, undef);
8788
}
8889
return valueMap.lookup(id);
8990
}
@@ -387,8 +388,9 @@ Deserializer::processOp<spirv::EntryPointOp>(ArrayRef<uint32_t> words) {
387388
interface.push_back(SymbolRefAttr::get(arg.getOperation()));
388389
wordIndex++;
389390
}
390-
opBuilder.create<spirv::EntryPointOp>(
391-
unknownLoc, execModel, SymbolRefAttr::get(opBuilder.getContext(), fnName),
391+
spirv::EntryPointOp::create(
392+
opBuilder, unknownLoc, execModel,
393+
SymbolRefAttr::get(opBuilder.getContext(), fnName),
392394
opBuilder.getArrayAttr(interface));
393395
return success();
394396
}
@@ -420,9 +422,10 @@ Deserializer::processOp<spirv::ExecutionModeOp>(ArrayRef<uint32_t> words) {
420422
attrListElems.push_back(opBuilder.getI32IntegerAttr(words[wordIndex++]));
421423
}
422424
auto values = opBuilder.getArrayAttr(attrListElems);
423-
opBuilder.create<spirv::ExecutionModeOp>(
424-
unknownLoc, SymbolRefAttr::get(opBuilder.getContext(), fn.getName()),
425-
execMode, values);
425+
spirv::ExecutionModeOp::create(
426+
opBuilder, unknownLoc,
427+
SymbolRefAttr::get(opBuilder.getContext(), fn.getName()), execMode,
428+
values);
426429
return success();
427430
}
428431

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

462-
auto opFunctionCall = opBuilder.create<spirv::FunctionCallOp>(
463-
unknownLoc, resultType,
465+
auto opFunctionCall = spirv::FunctionCallOp::create(
466+
opBuilder, unknownLoc, resultType,
464467
SymbolRefAttr::get(opBuilder.getContext(), functionName), arguments);
465468

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

538541
Location loc = createFileLineColLoc(opBuilder);
539-
opBuilder.create<spirv::CopyMemoryOp>(loc, resultTypes, operands, attributes);
542+
spirv::CopyMemoryOp::create(opBuilder, loc, resultTypes, operands,
543+
attributes);
540544

541545
return success();
542546
}
@@ -567,8 +571,8 @@ LogicalResult Deserializer::processOp<spirv::GenericCastToPtrExplicitOp>(
567571
operands.push_back(arg);
568572

569573
Location loc = createFileLineColLoc(opBuilder);
570-
Operation *op = opBuilder.create<spirv::GenericCastToPtrExplicitOp>(
571-
loc, resultTypes, operands);
574+
Operation *op = spirv::GenericCastToPtrExplicitOp::create(
575+
opBuilder, loc, resultTypes, operands);
572576
valueMap[valueID] = op->getResult(0);
573577
return success();
574578
}

mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ spirv::Deserializer::processFunction(ArrayRef<uint32_t> operands) {
518518
}
519519

520520
std::string fnName = getFunctionSymbol(fnID);
521-
auto funcOp = opBuilder.create<spirv::FuncOp>(
522-
unknownLoc, fnName, functionType, fnControl.value());
521+
auto funcOp = spirv::FuncOp::create(opBuilder, unknownLoc, fnName,
522+
functionType, fnControl.value());
523523
// Processing other function attributes.
524524
if (decorations.count(fnID)) {
525525
for (auto attr : decorations[fnID].getAttrs()) {
@@ -714,8 +714,8 @@ spirv::SpecConstantOp
714714
spirv::Deserializer::createSpecConstant(Location loc, uint32_t resultID,
715715
TypedAttr defaultValue) {
716716
auto symName = opBuilder.getStringAttr(getSpecConstantSymbol(resultID));
717-
auto op = opBuilder.create<spirv::SpecConstantOp>(unknownLoc, symName,
718-
defaultValue);
717+
auto op = spirv::SpecConstantOp::create(opBuilder, unknownLoc, symName,
718+
defaultValue);
719719
if (decorations.count(resultID)) {
720720
for (auto attr : decorations[resultID].getAttrs())
721721
op->setAttr(attr.getName(), attr.getValue());
@@ -790,9 +790,9 @@ spirv::Deserializer::processGlobalVariable(ArrayRef<uint32_t> operands) {
790790
<< wordIndex << " of " << operands.size() << " processed";
791791
}
792792
auto loc = createFileLineColLoc(opBuilder);
793-
auto varOp = opBuilder.create<spirv::GlobalVariableOp>(
794-
loc, TypeAttr::get(type), opBuilder.getStringAttr(variableName),
795-
initializer);
793+
auto varOp = spirv::GlobalVariableOp::create(
794+
opBuilder, loc, TypeAttr::get(type),
795+
opBuilder.getStringAttr(variableName), initializer);
796796

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

1640-
auto op = opBuilder.create<spirv::SpecConstantCompositeOp>(
1641-
unknownLoc, TypeAttr::get(resultType), symName,
1640+
auto op = spirv::SpecConstantCompositeOp::create(
1641+
opBuilder, unknownLoc, TypeAttr::get(resultType), symName,
16421642
opBuilder.getArrayAttr(elements));
16431643
specConstCompositeMap[resultID] = op;
16441644

@@ -1671,8 +1671,8 @@ LogicalResult spirv::Deserializer::processSpecConstantCompositeReplicateEXT(
16711671
auto symName = opBuilder.getStringAttr(getSpecConstantSymbol(resultID));
16721672
spirv::SpecConstantOp constituentSpecConstantOp =
16731673
getSpecConstant(operands[2]);
1674-
auto op = opBuilder.create<spirv::EXTSpecConstantCompositeReplicateOp>(
1675-
unknownLoc, TypeAttr::get(resultType), symName,
1674+
auto op = spirv::EXTSpecConstantCompositeReplicateOp::create(
1675+
opBuilder, unknownLoc, TypeAttr::get(resultType), symName,
16761676
SymbolRefAttr::get(constituentSpecConstantOp));
16771677

16781678
specConstCompositeReplicateMap[resultID] = op;
@@ -1747,7 +1747,7 @@ Value spirv::Deserializer::materializeSpecConstantOperation(
17471747

17481748
auto loc = createFileLineColLoc(opBuilder);
17491749
auto specConstOperationOp =
1750-
opBuilder.create<spirv::SpecConstantOperationOp>(loc, resultType);
1750+
spirv::SpecConstantOperationOp::create(opBuilder, loc, resultType);
17511751

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

1763-
opBuilder.create<spirv::YieldOp>(loc, block.front().getResult(0));
1763+
spirv::YieldOp::create(opBuilder, loc, block.front().getResult(0));
17641764
return specConstOperationOp.getResult();
17651765
}
17661766

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

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

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

20402040
auto control = static_cast<spirv::SelectionControl>(selectionControl);
2041-
auto selectionOp = builder.create<spirv::SelectionOp>(location, control);
2041+
auto selectionOp = spirv::SelectionOp::create(builder, location, control);
20422042
selectionOp.addMergeBlock(builder);
20432043

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

20522052
auto control = static_cast<spirv::LoopControl>(loopControl);
2053-
auto loopOp = builder.create<spirv::LoopOp>(location, control);
2053+
auto loopOp = spirv::LoopOp::create(builder, location, control);
20542054
loopOp.addEntryAndMergeBlock(builder);
20552055

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

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

22702270
if (isLoop)
2271-
newOp = builder.create<spirv::LoopOp>(
2272-
location, TypeRange(ValueRange(outsideUses)),
2273-
static_cast<spirv::LoopControl>(control));
2271+
newOp = spirv::LoopOp::create(builder, location,
2272+
TypeRange(ValueRange(outsideUses)),
2273+
static_cast<spirv::LoopControl>(control));
22742274
else
2275-
newOp = builder.create<spirv::SelectionOp>(
2276-
location, TypeRange(ValueRange(outsideUses)),
2275+
newOp = spirv::SelectionOp::create(
2276+
builder, location, TypeRange(ValueRange(outsideUses)),
22772277
static_cast<spirv::SelectionControl>(control));
22782278

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

24542454
if (auto branchOp = dyn_cast<spirv::BranchOp>(op)) {
24552455
// Replace the previous branch op with a new one with block arguments.
2456-
opBuilder.create<spirv::BranchOp>(branchOp.getLoc(), branchOp.getTarget(),
2457-
blockArgs);
2456+
spirv::BranchOp::create(opBuilder, branchOp.getLoc(),
2457+
branchOp.getTarget(), blockArgs);
24582458
branchOp.erase();
24592459
} else if (auto branchCondOp = dyn_cast<spirv::BranchConditionalOp>(op)) {
24602460
assert((branchCondOp.getTrueBlock() == target ||
24612461
branchCondOp.getFalseBlock() == target) &&
24622462
"expected target to be either the true or false target");
24632463
if (target == branchCondOp.getTrueTarget())
2464-
opBuilder.create<spirv::BranchConditionalOp>(
2465-
branchCondOp.getLoc(), branchCondOp.getCondition(), blockArgs,
2466-
branchCondOp.getFalseBlockArguments(),
2464+
spirv::BranchConditionalOp::create(
2465+
opBuilder, branchCondOp.getLoc(), branchCondOp.getCondition(),
2466+
blockArgs, branchCondOp.getFalseBlockArguments(),
24672467
branchCondOp.getBranchWeightsAttr(), branchCondOp.getTrueTarget(),
24682468
branchCondOp.getFalseTarget());
24692469
else
2470-
opBuilder.create<spirv::BranchConditionalOp>(
2471-
branchCondOp.getLoc(), branchCondOp.getCondition(),
2470+
spirv::BranchConditionalOp::create(
2471+
opBuilder, branchCondOp.getLoc(), branchCondOp.getCondition(),
24722472
branchCondOp.getTrueBlockArguments(), blockArgs,
24732473
branchCondOp.getBranchWeightsAttr(), branchCondOp.getTrueBlock(),
24742474
branchCondOp.getFalseBlock());
@@ -2528,7 +2528,7 @@ LogicalResult spirv::Deserializer::splitConditionalBlocks() {
25282528
if (!llvm::hasSingleElement(*block) || splitHeaderMergeBlock) {
25292529
Block *newBlock = block->splitBlock(terminator);
25302530
OpBuilder builder(block, block->end());
2531-
builder.create<spirv::BranchOp>(block->getParent()->getLoc(), newBlock);
2531+
spirv::BranchOp::create(builder, block->getParent()->getLoc(), newBlock);
25322532

25332533
// After splitting we need to update the map to use the new block as a
25342534
// header.

0 commit comments

Comments
 (0)