Skip to content

[mlir][NFC] update mlir/Dialect create APIs (30/n) #150643

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 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RootOrderingTest : public ::testing::Test {
builder.setInsertionPointToStart(&block);
for (int i = 0; i < 4; ++i)
// Ops will be deleted when `block` is destroyed.
v[i] = builder.create<ConstantIntOp>(builder.getUnknownLoc(), i, 32);
v[i] = ConstantIntOp::create(builder, builder.getUnknownLoc(), i, 32);
}

/// Checks that optimal branching on graph has the given cost and
Expand Down
126 changes: 63 additions & 63 deletions mlir/unittests/Dialect/OpenACC/OpenACCOpsTest.cpp

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,68 +119,68 @@ class SCFLoopLikeTest : public ::testing::Test {

TEST_F(SCFLoopLikeTest, queryUnidimensionalLooplikes) {
OwningOpRef<arith::ConstantIndexOp> lb =
b.create<arith::ConstantIndexOp>(loc, 0);
arith::ConstantIndexOp::create(b, loc, 0);
OwningOpRef<arith::ConstantIndexOp> ub =
b.create<arith::ConstantIndexOp>(loc, 10);
arith::ConstantIndexOp::create(b, loc, 10);
OwningOpRef<arith::ConstantIndexOp> step =
b.create<arith::ConstantIndexOp>(loc, 2);
arith::ConstantIndexOp::create(b, loc, 2);

OwningOpRef<scf::ForOp> forOp =
b.create<scf::ForOp>(loc, lb.get(), ub.get(), step.get());
scf::ForOp::create(b, loc, lb.get(), ub.get(), step.get());
checkUnidimensional(forOp.get());

OwningOpRef<scf::ForallOp> forallOp = b.create<scf::ForallOp>(
loc, ArrayRef<OpFoldResult>(lb->getResult()),
OwningOpRef<scf::ForallOp> forallOp = scf::ForallOp::create(
b, loc, ArrayRef<OpFoldResult>(lb->getResult()),
ArrayRef<OpFoldResult>(ub->getResult()),
ArrayRef<OpFoldResult>(step->getResult()), ValueRange(), std::nullopt);
checkUnidimensional(forallOp.get());

OwningOpRef<scf::ParallelOp> parallelOp = b.create<scf::ParallelOp>(
loc, ValueRange(lb->getResult()), ValueRange(ub->getResult()),
OwningOpRef<scf::ParallelOp> parallelOp = scf::ParallelOp::create(
b, loc, ValueRange(lb->getResult()), ValueRange(ub->getResult()),
ValueRange(step->getResult()), ValueRange());
checkUnidimensional(parallelOp.get());
}

TEST_F(SCFLoopLikeTest, queryMultidimensionalLooplikes) {
OwningOpRef<arith::ConstantIndexOp> lb =
b.create<arith::ConstantIndexOp>(loc, 0);
arith::ConstantIndexOp::create(b, loc, 0);
OwningOpRef<arith::ConstantIndexOp> ub =
b.create<arith::ConstantIndexOp>(loc, 10);
arith::ConstantIndexOp::create(b, loc, 10);
OwningOpRef<arith::ConstantIndexOp> step =
b.create<arith::ConstantIndexOp>(loc, 2);
arith::ConstantIndexOp::create(b, loc, 2);

OwningOpRef<scf::ForallOp> forallOp = b.create<scf::ForallOp>(
loc, ArrayRef<OpFoldResult>({lb->getResult(), lb->getResult()}),
OwningOpRef<scf::ForallOp> forallOp = scf::ForallOp::create(
b, loc, ArrayRef<OpFoldResult>({lb->getResult(), lb->getResult()}),
ArrayRef<OpFoldResult>({ub->getResult(), ub->getResult()}),
ArrayRef<OpFoldResult>({step->getResult(), step->getResult()}),
ValueRange(), std::nullopt);
checkMultidimensional(forallOp.get());

OwningOpRef<scf::ParallelOp> parallelOp = b.create<scf::ParallelOp>(
loc, ValueRange({lb->getResult(), lb->getResult()}),
OwningOpRef<scf::ParallelOp> parallelOp = scf::ParallelOp::create(
b, loc, ValueRange({lb->getResult(), lb->getResult()}),
ValueRange({ub->getResult(), ub->getResult()}),
ValueRange({step->getResult(), step->getResult()}), ValueRange());
checkMultidimensional(parallelOp.get());
}

TEST_F(SCFLoopLikeTest, testForallNormalize) {
OwningOpRef<arith::ConstantIndexOp> lb =
b.create<arith::ConstantIndexOp>(loc, 1);
arith::ConstantIndexOp::create(b, loc, 1);
OwningOpRef<arith::ConstantIndexOp> ub =
b.create<arith::ConstantIndexOp>(loc, 10);
arith::ConstantIndexOp::create(b, loc, 10);
OwningOpRef<arith::ConstantIndexOp> step =
b.create<arith::ConstantIndexOp>(loc, 3);
arith::ConstantIndexOp::create(b, loc, 3);

scf::ForallOp forallOp = b.create<scf::ForallOp>(
loc, ArrayRef<OpFoldResult>({lb->getResult(), lb->getResult()}),
scf::ForallOp forallOp = scf::ForallOp::create(
b, loc, ArrayRef<OpFoldResult>({lb->getResult(), lb->getResult()}),
ArrayRef<OpFoldResult>({ub->getResult(), ub->getResult()}),
ArrayRef<OpFoldResult>({step->getResult(), step->getResult()}),
ValueRange(), std::nullopt);
// Create a user of the induction variable. Bitcast is chosen for simplicity
// since it is unary.
b.setInsertionPointToStart(forallOp.getBody());
b.create<arith::BitcastOp>(UnknownLoc::get(&context), b.getF64Type(),
forallOp.getInductionVar(0));
arith::BitcastOp::create(b, UnknownLoc::get(&context), b.getF64Type(),
forallOp.getInductionVar(0));
IRRewriter rewriter(b);
FailureOr<scf::ForallOp> maybeNormalizedForallOp =
normalizeForallOp(rewriter, forallOp);
Expand Down
36 changes: 18 additions & 18 deletions mlir/unittests/Dialect/SMT/QuantifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ TEST(QuantifierTest, ExistsBuilderWithPattern) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ExistsOp> existsOp = builder.create<ExistsOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ExistsOp> existsOp = ExistsOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
std::nullopt,
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
Expand Down Expand Up @@ -57,10 +57,10 @@ TEST(QuantifierTest, ExistsBuilderNoPattern) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ExistsOp> existsOp = builder.create<ExistsOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ExistsOp> existsOp = ExistsOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
ArrayRef<StringRef>{"a", "b"}, nullptr, /*weight=*/0, /*noPattern=*/true);

Expand All @@ -82,10 +82,10 @@ TEST(QuantifierTest, ExistsBuilderDefault) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ExistsOp> existsOp = builder.create<ExistsOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ExistsOp> existsOp = ExistsOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
ArrayRef<StringRef>{"a", "b"});

Expand All @@ -111,10 +111,10 @@ TEST(QuantifierTest, ForallBuilderWithPattern) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ForallOp> forallOp = builder.create<ForallOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ForallOp> forallOp = ForallOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
ArrayRef<StringRef>{"a", "b"},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
Expand Down Expand Up @@ -142,10 +142,10 @@ TEST(QuantifierTest, ForallBuilderNoPattern) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ForallOp> forallOp = builder.create<ForallOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ForallOp> forallOp = ForallOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
ArrayRef<StringRef>{"a", "b"}, nullptr, /*weight=*/0, /*noPattern=*/true);

Expand All @@ -167,10 +167,10 @@ TEST(QuantifierTest, ForallBuilderDefault) {
OpBuilder builder(&context);
auto boolTy = BoolType::get(&context);

OwningOpRef<ForallOp> forallOp = builder.create<ForallOp>(
loc, TypeRange{boolTy, boolTy},
OwningOpRef<ForallOp> forallOp = ForallOp::create(
builder, loc, TypeRange{boolTy, boolTy},
[](OpBuilder &builder, Location loc, ValueRange boundVars) {
return builder.create<AndOp>(loc, boundVars);
return AndOp::create(builder, loc, boundVars);
},
std::nullopt);

Expand Down
12 changes: 6 additions & 6 deletions mlir/unittests/Dialect/SPIRV/SerializationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class SerializationTest : public ::testing::Test {
spirv::GlobalVariableOp addGlobalVar(Type type, llvm::StringRef name) {
OpBuilder builder(module->getRegion());
auto ptrType = spirv::PointerType::get(type, spirv::StorageClass::Uniform);
return builder.create<spirv::GlobalVariableOp>(
UnknownLoc::get(&context), TypeAttr::get(ptrType),
return spirv::GlobalVariableOp::create(
builder, UnknownLoc::get(&context), TypeAttr::get(ptrType),
builder.getStringAttr(name), nullptr);
}

Expand All @@ -82,14 +82,14 @@ class SerializationTest : public ::testing::Test {
auto loc = UnknownLoc::get(&context);

if (auto intType = dyn_cast<IntegerType>(type)) {
return builder.create<spirv::ConstantOp>(
loc, type, builder.getIntegerAttr(type, val));
return spirv::ConstantOp::create(builder, loc, type,
builder.getIntegerAttr(type, val));
}
if (auto vectorType = dyn_cast<VectorType>(type)) {
Type elemType = vectorType.getElementType();
if (auto intType = dyn_cast<IntegerType>(elemType)) {
return builder.create<spirv::ConstantOp>(
loc, type,
return spirv::ConstantOp::create(
builder, loc, type,
DenseElementsAttr::get(vectorType,
IntegerAttr::get(elemType, val).getValue()));
}
Expand Down
8 changes: 4 additions & 4 deletions mlir/unittests/IR/IRMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ TEST(IRMapping, TypedValue) {
Block block;
builder.setInsertionPointToEnd(&block);

Value i64Val = builder.create<test::TestOpConstant>(
loc, builder.getI64Type(), builder.getI64IntegerAttr(0));
Value f64Val = builder.create<test::TestOpConstant>(
loc, builder.getF64Type(), builder.getF64FloatAttr(0.0));
Value i64Val = test::TestOpConstant::create(
builder, loc, builder.getI64Type(), builder.getI64IntegerAttr(0));
Value f64Val = test::TestOpConstant::create(
builder, loc, builder.getF64Type(), builder.getF64FloatAttr(0.0));

IRMapping mapping;
mapping.map(i64Val, f64Val);
Expand Down
18 changes: 9 additions & 9 deletions mlir/unittests/IR/InterfaceAttachmentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ TEST(InterfaceAttachment, Operation) {

// Initially, the operation doesn't have the interface.
OwningOpRef<ModuleOp> moduleOp =
builder.create<ModuleOp>(UnknownLoc::get(&context));
ModuleOp::create(builder, UnknownLoc::get(&context));
ASSERT_FALSE(isa<TestExternalOpInterface>(moduleOp->getOperation()));

// We can attach an external interface and now the operaiton has it.
Expand All @@ -317,8 +317,8 @@ TEST(InterfaceAttachment, Operation) {

// Default implementation can be overridden.
OwningOpRef<UnrealizedConversionCastOp> castOp =
builder.create<UnrealizedConversionCastOp>(UnknownLoc::get(&context),
TypeRange(), ValueRange());
UnrealizedConversionCastOp::create(builder, UnknownLoc::get(&context),
TypeRange(), ValueRange());
ASSERT_FALSE(isa<TestExternalOpInterface>(castOp->getOperation()));
UnrealizedConversionCastOp::attachInterface<TestExternalOpOverridingModel>(
context);
Expand Down Expand Up @@ -368,11 +368,11 @@ TEST(InterfaceAttachment, OperationDelayedContextConstruct) {
OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context));
OpBuilder builder(module->getBody(), module->getBody()->begin());
auto opJ =
builder.create<test::OpJ>(builder.getUnknownLoc(), builder.getI32Type());
test::OpJ::create(builder, builder.getUnknownLoc(), builder.getI32Type());
auto opH =
builder.create<test::OpH>(builder.getUnknownLoc(), opJ.getResult());
test::OpH::create(builder, builder.getUnknownLoc(), opJ.getResult());
auto opI =
builder.create<test::OpI>(builder.getUnknownLoc(), opJ.getResult());
test::OpI::create(builder, builder.getUnknownLoc(), opJ.getResult());

EXPECT_TRUE(isa<TestExternalOpInterface>(module->getOperation()));
EXPECT_TRUE(isa<TestExternalOpInterface>(opJ.getOperation()));
Expand All @@ -399,11 +399,11 @@ TEST(InterfaceAttachment, OperationDelayedContextAppend) {
OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context));
OpBuilder builder(module->getBody(), module->getBody()->begin());
auto opJ =
builder.create<test::OpJ>(builder.getUnknownLoc(), builder.getI32Type());
test::OpJ::create(builder, builder.getUnknownLoc(), builder.getI32Type());
auto opH =
builder.create<test::OpH>(builder.getUnknownLoc(), opJ.getResult());
test::OpH::create(builder, builder.getUnknownLoc(), opJ.getResult());
auto opI =
builder.create<test::OpI>(builder.getUnknownLoc(), opJ.getResult());
test::OpI::create(builder, builder.getUnknownLoc(), opJ.getResult());

EXPECT_FALSE(isa<TestExternalOpInterface>(module->getOperation()));
EXPECT_FALSE(isa<TestExternalOpInterface>(opJ.getOperation()));
Expand Down
16 changes: 8 additions & 8 deletions mlir/unittests/IR/InterfaceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ TEST(InterfaceTest, OpInterfaceDenseMapKey) {

OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context));
OpBuilder builder(module->getBody(), module->getBody()->begin());
auto op1 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
builder.getI32Type());
auto op2 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
builder.getI32Type());
auto op3 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
builder.getI32Type());
auto op1 = test::SideEffectOp::create(builder, builder.getUnknownLoc(),
builder.getI32Type());
auto op2 = test::SideEffectOp::create(builder, builder.getUnknownLoc(),
builder.getI32Type());
auto op3 = test::SideEffectOp::create(builder, builder.getUnknownLoc(),
builder.getI32Type());
DenseSet<MemoryEffectOpInterface> opSet;
opSet.insert(op1);
opSet.insert(op2);
Expand Down Expand Up @@ -64,8 +64,8 @@ TEST(InterfaceTest, TestCustomClassOf) {
context.loadDialect<test::TestDialect>();

OpBuilder builder(&context);
auto op = builder.create<TestOpOptionallyImplementingInterface>(
builder.getUnknownLoc(), /*implementsInterface=*/true);
auto op = TestOpOptionallyImplementingInterface::create(
builder, builder.getUnknownLoc(), /*implementsInterface=*/true);
EXPECT_TRUE(isa<TestOptionallyImplementedOpInterface>(*op));
op.setImplementsInterface(false);
EXPECT_FALSE(isa<TestOptionallyImplementedOpInterface>(*op));
Expand Down
12 changes: 6 additions & 6 deletions mlir/unittests/IR/OperationSupportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ TEST(OperandStorageTest, PopulateDefaultAttrs) {
auto req1 = b.getI32IntegerAttr(10);
auto req2 = b.getI32IntegerAttr(60);
// Verify default attributes populated post op creation.
Operation *op = b.create<test::OpAttrMatch1>(b.getUnknownLoc(), req1, nullptr,
nullptr, req2);
Operation *op = test::OpAttrMatch1::create(b, b.getUnknownLoc(), req1,
nullptr, nullptr, req2);
auto opt = op->getInherentAttr("default_valued_attr");
EXPECT_NE(opt, nullptr) << *op;

Expand Down Expand Up @@ -343,11 +343,11 @@ TEST(OperationEquivalenceTest, HashWorksWithFlags) {

// Check ignore properties.
auto req1 = b.getI32IntegerAttr(10);
Operation *opWithProperty1 = b.create<test::OpAttrMatch1>(
b.getUnknownLoc(), req1, nullptr, nullptr, req1);
Operation *opWithProperty1 = test::OpAttrMatch1::create(
b, b.getUnknownLoc(), req1, nullptr, nullptr, req1);
auto req2 = b.getI32IntegerAttr(60);
Operation *opWithProperty2 = b.create<test::OpAttrMatch1>(
b.getUnknownLoc(), req2, nullptr, nullptr, req2);
Operation *opWithProperty2 = test::OpAttrMatch1::create(
b, b.getUnknownLoc(), req2, nullptr, nullptr, req2);
EXPECT_EQ(getHash(opWithProperty1, OperationEquivalence::IgnoreProperties),
getHash(opWithProperty2, OperationEquivalence::IgnoreProperties));
EXPECT_NE(getHash(opWithProperty1, OperationEquivalence::None),
Expand Down
Loading
Loading