Skip to content

Commit 63f30d7

Browse files
[mlir] Migrate away from {TypeRange,ValueRange}(std::nullopt) (NFC) (#145445)
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch migrates away from TypeRagne(std::nullopt) and ValueRange(std::nullopt).
1 parent 6dad1e8 commit 63f30d7

File tree

17 files changed

+44
-56
lines changed

17 files changed

+44
-56
lines changed

mlir/include/mlir/Dialect/Affine/IR/AffineOps.td

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,16 @@ def AffineForOp : Affine_Op<"for",
243243
let regions = (region SizedRegion<1>:$region);
244244

245245
let skipDefaultBuilders = 1;
246-
let builders = [
247-
OpBuilder<(ins "int64_t":$lowerBound, "int64_t":$upperBound,
248-
CArg<"int64_t", "1">:$step, CArg<"ValueRange", "std::nullopt">:$iterArgs,
249-
CArg<"function_ref<void(OpBuilder &, Location, Value, ValueRange)>",
250-
"nullptr">:$bodyBuilder)>,
251-
OpBuilder<(ins "ValueRange":$lbOperands, "AffineMap":$lbMap,
252-
"ValueRange":$ubOperands, "AffineMap":$ubMap, CArg<"int64_t", "1">:$step,
253-
CArg<"ValueRange", "std::nullopt">:$iterArgs,
254-
CArg<"function_ref<void(OpBuilder &, Location, Value, ValueRange)>",
255-
"nullptr">:$bodyBuilder)>
256-
];
246+
let builders =
247+
[OpBuilder<(ins "int64_t":$lowerBound, "int64_t":$upperBound,
248+
CArg<"int64_t", "1">:$step, CArg<"ValueRange", "{}">:$iterArgs,
249+
CArg<"function_ref<void(OpBuilder &, Location, Value, ValueRange)>",
250+
"nullptr">:$bodyBuilder)>,
251+
OpBuilder<(ins "ValueRange":$lbOperands, "AffineMap":$lbMap,
252+
"ValueRange":$ubOperands, "AffineMap":$ubMap,
253+
CArg<"int64_t", "1">:$step, CArg<"ValueRange", "{}">:$iterArgs,
254+
CArg<"function_ref<void(OpBuilder &, Location, Value, ValueRange)>",
255+
"nullptr">:$bodyBuilder)>];
257256

258257
let extraClassDeclaration = [{
259258
/// Defining the function type we use for building the body of affine.for.
@@ -920,9 +919,7 @@ def AffineYieldOp : Affine_Op<"yield", [Pure, Terminator, ReturnLike,
920919

921920
let arguments = (ins Variadic<AnyType>:$operands);
922921

923-
let builders = [
924-
OpBuilder<(ins), [{ build($_builder, $_state, std::nullopt); }]>
925-
];
922+
let builders = [OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>];
926923

927924
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
928925
let hasVerifier = 1;

mlir/include/mlir/Dialect/Async/IR/AsyncOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def Async_ReturnOp : Async_Op<"return",
288288

289289
let arguments = (ins Variadic<AnyType>:$operands);
290290

291-
let builders = [OpBuilder<(ins), [{build($_builder, $_state, std::nullopt);}]>];
291+
let builders = [OpBuilder<(ins), [{build($_builder, $_state, {});}]>];
292292

293293
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
294294
let hasVerifier = 1;

mlir/include/mlir/Dialect/Func/IR/FuncOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def ReturnOp : Func_Op<"return", [Pure, HasParent<"FuncOp">,
385385
let arguments = (ins Variadic<AnyType>:$operands);
386386

387387
let builders = [OpBuilder<(ins), [{
388-
build($_builder, $_state, std::nullopt);
388+
build($_builder, $_state, {});
389389
}]>];
390390

391391
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";

mlir/include/mlir/Dialect/MLProgram/IR/MLProgramOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def MLProgram_OutputOp : MLProgram_Op<"output", [
462462
let arguments = (ins Variadic<AnyType>:$operands);
463463

464464
let builders = [OpBuilder<(ins), [{
465-
build($_builder, $_state, std::nullopt);
465+
build($_builder, $_state, {});
466466
}]>];
467467

468468
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
@@ -488,7 +488,7 @@ def MLProgram_ReturnOp : MLProgram_Op<"return", [
488488
let arguments = (ins Variadic<AnyType>:$operands);
489489

490490
let builders = [OpBuilder<(ins), [{
491-
build($_builder, $_state, std::nullopt);
491+
build($_builder, $_state, {});
492492
}]>];
493493

494494
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";

mlir/include/mlir/Dialect/SCF/IR/SCFOps.td

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,10 @@ def ForOp : SCF_Op<"for",
248248
let regions = (region SizedRegion<1>:$region);
249249

250250
let skipDefaultBuilders = 1;
251-
let builders = [
252-
OpBuilder<(ins "Value":$lowerBound, "Value":$upperBound, "Value":$step,
253-
CArg<"ValueRange", "std::nullopt">:$initArgs,
251+
let builders = [OpBuilder<(ins "Value":$lowerBound, "Value":$upperBound,
252+
"Value":$step, CArg<"ValueRange", "{}">:$initArgs,
254253
CArg<"function_ref<void(OpBuilder &, Location, Value, ValueRange)>",
255-
"nullptr">)>
256-
];
254+
"nullptr">)>];
257255

258256
let extraClassDeclaration = [{
259257
using BodyBuilderFn =

mlir/include/mlir/Dialect/SMT/IR/SMTOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def YieldOp : SMTOp<"yield", [
227227
let arguments = (ins Variadic<AnyType>:$values);
228228
let assemblyFormat = "($values^ `:` qualified(type($values)))? attr-dict";
229229
let builders = [OpBuilder<(ins), [{
230-
build($_builder, $_state, std::nullopt);
230+
build($_builder, $_state, {});
231231
}]>];
232232
}
233233

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,7 @@ def Shape_YieldOp : Shape_Op<"yield",
678678

679679
let arguments = (ins Variadic<AnyType>:$operands);
680680

681-
let builders = [OpBuilder<(ins),
682-
[{ build($_builder, $_state, std::nullopt); }]>
683-
];
681+
let builders = [OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>];
684682

685683
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
686684
let hasVerifier = 1;

mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ lowerAsEntryFunction(gpu::GPUFuncOp funcOp, const TypeConverter &typeConverter,
251251
}
252252
auto newFuncOp = rewriter.create<spirv::FuncOp>(
253253
funcOp.getLoc(), funcOp.getName(),
254-
rewriter.getFunctionType(signatureConverter.getConvertedTypes(),
255-
std::nullopt));
254+
rewriter.getFunctionType(signatureConverter.getConvertedTypes(), {}));
256255
for (const auto &namedAttr : funcOp->getAttrs()) {
257256
if (namedAttr.getName() == funcOp.getFunctionTypeAttrName() ||
258257
namedAttr.getName() == SymbolTable::getSymbolAttrName())

mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ SymbolRefAttr PatternLowering::generateRewriter(
636636
builder.setInsertionPointToEnd(rewriterModule.getBody());
637637
auto rewriterFunc = builder.create<pdl_interp::FuncOp>(
638638
pattern.getLoc(), "pdl_generated_rewriter",
639-
builder.getFunctionType(std::nullopt, std::nullopt));
639+
builder.getFunctionType({}, {}));
640640
rewriterSymbolTable.insert(rewriterFunc);
641641

642642
// Generate the rewriter function body.
@@ -703,7 +703,7 @@ SymbolRefAttr PatternLowering::generateRewriter(
703703
// Update the signature of the rewrite function.
704704
rewriterFunc.setType(builder.getFunctionType(
705705
llvm::to_vector<8>(rewriterFunc.front().getArgumentTypes()),
706-
/*results=*/std::nullopt));
706+
/*results=*/{}));
707707

708708
builder.create<pdl_interp::FinalizeOp>(rewriter.getLoc());
709709
return SymbolRefAttr::get(
@@ -990,7 +990,7 @@ void PDLToPDLInterpPass::runOnOperation() {
990990
auto matcherFunc = builder.create<pdl_interp::FuncOp>(
991991
module.getLoc(), pdl_interp::PDLInterpDialect::getMatcherFunctionName(),
992992
builder.getFunctionType(builder.getType<pdl::OperationType>(),
993-
/*results=*/std::nullopt),
993+
/*results=*/{}),
994994
/*attrs=*/std::nullopt);
995995

996996
// Create a nested module to hold the functions invoked for rewriting the IR

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ void WarpExecuteOnLane0Op::build(OpBuilder &builder, OperationState &result,
23022302
TypeRange resultTypes, Value laneId,
23032303
int64_t warpSize) {
23042304
build(builder, result, resultTypes, laneId, warpSize,
2305-
/*operands=*/std::nullopt, /*argTypes=*/std::nullopt);
2305+
/*operands=*/{}, /*argTypes=*/{});
23062306
}
23072307

23082308
void WarpExecuteOnLane0Op::build(OpBuilder &builder, OperationState &result,

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ LoopNest mlir::scf::buildLoopNest(
769769
ValueRange steps,
770770
function_ref<void(OpBuilder &, Location, ValueRange)> bodyBuilder) {
771771
// Delegate to the main function by wrapping the body builder.
772-
return buildLoopNest(builder, loc, lbs, ubs, steps, std::nullopt,
772+
return buildLoopNest(builder, loc, lbs, ubs, steps, {},
773773
[&bodyBuilder](OpBuilder &nestedBuilder,
774774
Location nestedLoc, ValueRange ivs,
775775
ValueRange) -> ValueVector {

mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ LogicalResult ProcessInterfaceVarABI::matchAndRewrite(
282282

283283
// Creates a new function with the update signature.
284284
rewriter.modifyOpInPlace(funcOp, [&] {
285-
funcOp.setType(rewriter.getFunctionType(
286-
signatureConverter.getConvertedTypes(), std::nullopt));
285+
funcOp.setType(
286+
rewriter.getFunctionType(signatureConverter.getConvertedTypes(), {}));
287287
});
288288
return success();
289289
}

mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ static Operation *createOp(MLIRContext *context, Location loc,
2323
StringRef operationName,
2424
unsigned int numRegions = 0) {
2525
context->allowUnregisteredDialects();
26-
return Operation::create(loc, OperationName(operationName, context),
27-
std::nullopt, std::nullopt, std::nullopt,
28-
OpaqueProperties(nullptr), std::nullopt, numRegions);
26+
return Operation::create(loc, OperationName(operationName, context), {}, {},
27+
std::nullopt, OpaqueProperties(nullptr),
28+
std::nullopt, numRegions);
2929
}
3030

3131
namespace {

mlir/unittests/IR/OperationSupportTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TEST(OperandStorageTest, NonResizable) {
4444
EXPECT_EQ(user->getNumOperands(), 1u);
4545

4646
// Removing is okay.
47-
user->setOperands(std::nullopt);
47+
user->setOperands({});
4848
EXPECT_EQ(user->getNumOperands(), 0u);
4949

5050
// Destroy the operations.
@@ -68,7 +68,7 @@ TEST(OperandStorageTest, Resizable) {
6868
EXPECT_EQ(user->getNumOperands(), 1u);
6969

7070
// Removing is okay.
71-
user->setOperands(std::nullopt);
71+
user->setOperands({});
7272
EXPECT_EQ(user->getNumOperands(), 0u);
7373

7474
// Adding more operands is okay.
@@ -236,7 +236,7 @@ TEST(OperationFormatPrintTest, CanPrintNameAsPrefix) {
236236
context.allowUnregisteredDialects();
237237
Operation *op = Operation::create(
238238
NameLoc::get(StringAttr::get(&context, "my_named_loc")),
239-
OperationName("t.op", &context), builder.getIntegerType(16), std::nullopt,
239+
OperationName("t.op", &context), builder.getIntegerType(16), {},
240240
std::nullopt, nullptr, std::nullopt, 0);
241241

242242
std::string str;

mlir/unittests/Pass/AnalysisManagerTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
6363

6464
// Create a function and a module.
6565
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
66-
func::FuncOp func1 =
67-
func::FuncOp::create(builder.getUnknownLoc(), "foo",
68-
builder.getFunctionType(std::nullopt, std::nullopt));
66+
func::FuncOp func1 = func::FuncOp::create(builder.getUnknownLoc(), "foo",
67+
builder.getFunctionType({}, {}));
6968
func1.setPrivate();
7069
module->push_back(func1);
7170

@@ -94,9 +93,8 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
9493

9594
// Create a function and a module.
9695
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
97-
func::FuncOp func1 =
98-
func::FuncOp::create(builder.getUnknownLoc(), "foo",
99-
builder.getFunctionType(std::nullopt, std::nullopt));
96+
func::FuncOp func1 = func::FuncOp::create(builder.getUnknownLoc(), "foo",
97+
builder.getFunctionType({}, {}));
10098
func1.setPrivate();
10199
module->push_back(func1);
102100

mlir/unittests/Pass/PassManagerTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
6363
// Create a module with 2 functions.
6464
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
6565
for (StringRef name : {"secret", "not_secret"}) {
66-
auto func = func::FuncOp::create(
67-
builder.getUnknownLoc(), name,
68-
builder.getFunctionType(std::nullopt, std::nullopt));
66+
auto func = func::FuncOp::create(builder.getUnknownLoc(), name,
67+
builder.getFunctionType({}, {}));
6968
func.setPrivate();
7069
module->push_back(func);
7170
}
@@ -125,9 +124,8 @@ TEST(PassManagerTest, ExecutionAction) {
125124

126125
// Create a module with 2 functions.
127126
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
128-
auto f =
129-
func::FuncOp::create(builder.getUnknownLoc(), "process_me_once",
130-
builder.getFunctionType(std::nullopt, std::nullopt));
127+
auto f = func::FuncOp::create(builder.getUnknownLoc(), "process_me_once",
128+
builder.getFunctionType({}, {}));
131129
f.setPrivate();
132130
module->push_back(f);
133131

mlir/unittests/Transforms/DialectConversion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ using namespace mlir;
1414
static Operation *createOp(MLIRContext *context) {
1515
context->allowUnregisteredDialects();
1616
return Operation::create(
17-
UnknownLoc::get(context), OperationName("foo.bar", context), std::nullopt,
18-
std::nullopt, std::nullopt, /*properties=*/nullptr, std::nullopt, 0);
17+
UnknownLoc::get(context), OperationName("foo.bar", context), {}, {},
18+
std::nullopt, /*properties=*/nullptr, std::nullopt, 0);
1919
}
2020

2121
namespace {

0 commit comments

Comments
 (0)