Skip to content

Commit 70dce3d

Browse files
[mlir] Migrate away from std::nullopt (NFC) (#145842)
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 replaces {} with std::nullopt.
1 parent 87729bc commit 70dce3d

File tree

18 files changed

+41
-45
lines changed

18 files changed

+41
-45
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ class LLVM_MemOpPatterns {
235235
}];
236236
code setInvariantGroupCode = [{
237237
if ($invariantGroup) {
238-
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(),
239-
std::nullopt);
238+
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), {});
240239
inst->setMetadata(llvm::LLVMContext::MD_invariant_group, metadata);
241240
}
242241
}];

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
425425
auto *inst = builder.CreateLoad($_resultType, $addr, $volatile_);
426426
$res = inst;
427427
if ($invariant) {
428-
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), std::nullopt);
428+
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), {});
429429
inst->setMetadata(llvm::LLVMContext::MD_invariant_load, metadata);
430430
}
431431
if ($dereferenceable)

mlir/include/mlir/IR/Matchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct constant_op_binder {
8888

8989
// Fold the constant to an attribute.
9090
SmallVector<OpFoldResult, 1> foldedOp;
91-
LogicalResult result = op->fold(/*operands=*/std::nullopt, foldedOp);
91+
LogicalResult result = op->fold(/*operands=*/{}, foldedOp);
9292
(void)result;
9393
assert(succeeded(result) && "expected ConstantLike op to be foldable");
9494

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ class RewritePatternSet {
810810
RewritePatternSet &add(ConstructorArg &&arg, ConstructorArgs &&...args) {
811811
// The following expands a call to emplace_back for each of the pattern
812812
// types 'Ts'.
813-
(addImpl<Ts>(/*debugLabels=*/std::nullopt,
814-
std::forward<ConstructorArg>(arg),
813+
(addImpl<Ts>(/*debugLabels=*/{}, std::forward<ConstructorArg>(arg),
815814
std::forward<ConstructorArgs>(args)...),
816815
...);
817816
return *this;
@@ -894,7 +893,7 @@ class RewritePatternSet {
894893
RewritePatternSet &insert(ConstructorArg &&arg, ConstructorArgs &&...args) {
895894
// The following expands a call to emplace_back for each of the pattern
896895
// types 'Ts'.
897-
(addImpl<Ts>(/*debugLabels=*/std::nullopt, arg, args...), ...);
896+
(addImpl<Ts>(/*debugLabels=*/{}, arg, args...), ...);
898897
return *this;
899898
}
900899

mlir/include/mlir/Tools/PDLL/AST/Nodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ class UserConstraintDecl final
903903
ArrayRef<VariableDecl *> results,
904904
const CompoundStmt *body,
905905
Type resultType) {
906-
return createImpl(ctx, name, inputs, /*nativeInputTypes=*/std::nullopt,
907-
results, /*codeBlock=*/std::nullopt, body, resultType);
906+
return createImpl(ctx, name, inputs, /*nativeInputTypes=*/{}, results,
907+
/*codeBlock=*/std::nullopt, body, resultType);
908908
}
909909

910910
/// Return the name of the constraint.

mlir/lib/Dialect/Async/IR/Async.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
309309
return;
310310
assert(type.getNumInputs() == argAttrs.size());
311311
call_interface_impl::addArgAndResultAttrs(
312-
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
312+
builder, state, argAttrs, /*resultAttrs=*/{},
313313
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
314314
}
315315

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
601601
return;
602602
assert(type.getNumInputs() == argAttrs.size());
603603
call_interface_impl::addArgAndResultAttrs(
604-
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
604+
builder, state, argAttrs, /*resultAttrs=*/{},
605605
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
606606
}
607607

mlir/lib/Dialect/Func/IR/FuncOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
193193
return;
194194
assert(type.getNumInputs() == argAttrs.size());
195195
call_interface_impl::addArgAndResultAttrs(
196-
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
196+
builder, state, argAttrs, /*resultAttrs=*/{},
197197
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
198198
}
199199

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
27742774
assert(llvm::cast<LLVMFunctionType>(type).getNumParams() == argAttrs.size() &&
27752775
"expected as many argument attribute lists as arguments");
27762776
call_interface_impl::addArgAndResultAttrs(
2777-
builder, result, argAttrs, /*resultAttrs=*/std::nullopt,
2777+
builder, result, argAttrs, /*resultAttrs=*/{},
27782778
getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name));
27792779
}
27802780

mlir/lib/Dialect/Shape/IR/Shape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
13031303
return;
13041304
assert(type.getNumInputs() == argAttrs.size());
13051305
call_interface_impl::addArgAndResultAttrs(
1306-
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
1306+
builder, state, argAttrs, /*resultAttrs=*/{},
13071307
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
13081308
}
13091309

0 commit comments

Comments
 (0)