[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.
This commit is contained in:
@@ -235,8 +235,7 @@ class LLVM_MemOpPatterns {
|
||||
}];
|
||||
code setInvariantGroupCode = [{
|
||||
if ($invariantGroup) {
|
||||
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(),
|
||||
std::nullopt);
|
||||
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), {});
|
||||
inst->setMetadata(llvm::LLVMContext::MD_invariant_group, metadata);
|
||||
}
|
||||
}];
|
||||
|
||||
@@ -425,7 +425,7 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
|
||||
auto *inst = builder.CreateLoad($_resultType, $addr, $volatile_);
|
||||
$res = inst;
|
||||
if ($invariant) {
|
||||
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), std::nullopt);
|
||||
llvm::MDNode *metadata = llvm::MDNode::get(inst->getContext(), {});
|
||||
inst->setMetadata(llvm::LLVMContext::MD_invariant_load, metadata);
|
||||
}
|
||||
if ($dereferenceable)
|
||||
|
||||
@@ -88,7 +88,7 @@ struct constant_op_binder {
|
||||
|
||||
// Fold the constant to an attribute.
|
||||
SmallVector<OpFoldResult, 1> foldedOp;
|
||||
LogicalResult result = op->fold(/*operands=*/std::nullopt, foldedOp);
|
||||
LogicalResult result = op->fold(/*operands=*/{}, foldedOp);
|
||||
(void)result;
|
||||
assert(succeeded(result) && "expected ConstantLike op to be foldable");
|
||||
|
||||
|
||||
@@ -810,8 +810,7 @@ public:
|
||||
RewritePatternSet &add(ConstructorArg &&arg, ConstructorArgs &&...args) {
|
||||
// The following expands a call to emplace_back for each of the pattern
|
||||
// types 'Ts'.
|
||||
(addImpl<Ts>(/*debugLabels=*/std::nullopt,
|
||||
std::forward<ConstructorArg>(arg),
|
||||
(addImpl<Ts>(/*debugLabels=*/{}, std::forward<ConstructorArg>(arg),
|
||||
std::forward<ConstructorArgs>(args)...),
|
||||
...);
|
||||
return *this;
|
||||
@@ -894,7 +893,7 @@ public:
|
||||
RewritePatternSet &insert(ConstructorArg &&arg, ConstructorArgs &&...args) {
|
||||
// The following expands a call to emplace_back for each of the pattern
|
||||
// types 'Ts'.
|
||||
(addImpl<Ts>(/*debugLabels=*/std::nullopt, arg, args...), ...);
|
||||
(addImpl<Ts>(/*debugLabels=*/{}, arg, args...), ...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -903,8 +903,8 @@ public:
|
||||
ArrayRef<VariableDecl *> results,
|
||||
const CompoundStmt *body,
|
||||
Type resultType) {
|
||||
return createImpl(ctx, name, inputs, /*nativeInputTypes=*/std::nullopt,
|
||||
results, /*codeBlock=*/std::nullopt, body, resultType);
|
||||
return createImpl(ctx, name, inputs, /*nativeInputTypes=*/{}, results,
|
||||
/*codeBlock=*/std::nullopt, body, resultType);
|
||||
}
|
||||
|
||||
/// Return the name of the constraint.
|
||||
|
||||
@@ -309,7 +309,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
|
||||
return;
|
||||
assert(type.getNumInputs() == argAttrs.size());
|
||||
call_interface_impl::addArgAndResultAttrs(
|
||||
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
|
||||
builder, state, argAttrs, /*resultAttrs=*/{},
|
||||
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
|
||||
}
|
||||
|
||||
|
||||
@@ -601,7 +601,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
|
||||
return;
|
||||
assert(type.getNumInputs() == argAttrs.size());
|
||||
call_interface_impl::addArgAndResultAttrs(
|
||||
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
|
||||
builder, state, argAttrs, /*resultAttrs=*/{},
|
||||
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
|
||||
return;
|
||||
assert(type.getNumInputs() == argAttrs.size());
|
||||
call_interface_impl::addArgAndResultAttrs(
|
||||
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
|
||||
builder, state, argAttrs, /*resultAttrs=*/{},
|
||||
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
|
||||
}
|
||||
|
||||
|
||||
@@ -2774,7 +2774,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
|
||||
assert(llvm::cast<LLVMFunctionType>(type).getNumParams() == argAttrs.size() &&
|
||||
"expected as many argument attribute lists as arguments");
|
||||
call_interface_impl::addArgAndResultAttrs(
|
||||
builder, result, argAttrs, /*resultAttrs=*/std::nullopt,
|
||||
builder, result, argAttrs, /*resultAttrs=*/{},
|
||||
getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name));
|
||||
}
|
||||
|
||||
|
||||
@@ -1303,7 +1303,7 @@ void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name,
|
||||
return;
|
||||
assert(type.getNumInputs() == argAttrs.size());
|
||||
call_interface_impl::addArgAndResultAttrs(
|
||||
builder, state, argAttrs, /*resultAttrs=*/std::nullopt,
|
||||
builder, state, argAttrs, /*resultAttrs=*/{},
|
||||
getArgAttrsAttrName(state.name), getResAttrsAttrName(state.name));
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ Tester::Interestingness Tester::isInteresting(StringRef testCase) const {
|
||||
|
||||
std::string errMsg;
|
||||
int result = llvm::sys::ExecuteAndWait(
|
||||
testScript, testerArgs, /*Env=*/std::nullopt, /*Redirects=*/std::nullopt,
|
||||
testScript, testerArgs, /*Env=*/std::nullopt, /*Redirects=*/{},
|
||||
/*SecondsToWait=*/0, /*MemoryLimit=*/0, &errMsg);
|
||||
|
||||
if (result < 0)
|
||||
|
||||
@@ -206,7 +206,7 @@ void LoopAnnotationConversion::convertLocation(FusedLoc location) {
|
||||
|
||||
llvm::MDNode *LoopAnnotationConversion::convert() {
|
||||
// Reserve operand 0 for loop id self reference.
|
||||
auto dummy = llvm::MDNode::getTemporary(ctx, std::nullopt);
|
||||
auto dummy = llvm::MDNode::getTemporary(ctx, {});
|
||||
metadataNodes.push_back(dummy.get());
|
||||
|
||||
if (FusedLoc startLoc = attr.getStartLoc())
|
||||
|
||||
@@ -1922,7 +1922,7 @@ ModuleTranslation::getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr) {
|
||||
if (!scopeInserted)
|
||||
return scopeIt->second;
|
||||
llvm::LLVMContext &ctx = llvmModule->getContext();
|
||||
auto dummy = llvm::MDNode::getTemporary(ctx, std::nullopt);
|
||||
auto dummy = llvm::MDNode::getTemporary(ctx, {});
|
||||
// Convert the domain metadata node if necessary.
|
||||
auto [domainIt, insertedDomain] = aliasDomainMetadataMapping.try_emplace(
|
||||
aliasScopeAttr.getDomain(), nullptr);
|
||||
|
||||
@@ -985,8 +985,7 @@ ast::Decl *Parser::createODSNativePDLLConstraintDecl(
|
||||
// Build the native constraint.
|
||||
auto *constraintDecl = ast::UserConstraintDecl::createNative(
|
||||
ctx, ast::Name::create(ctx, name, loc), paramVar,
|
||||
/*results=*/std::nullopt, codeBlock, ast::TupleType::get(ctx),
|
||||
nativeType);
|
||||
/*results=*/{}, codeBlock, ast::TupleType::get(ctx), nativeType);
|
||||
constraintDecl->setDocComment(ctx, docString);
|
||||
curDeclScope->add(constraintDecl);
|
||||
return constraintDecl;
|
||||
@@ -1782,7 +1781,7 @@ Parser::parseConstraint(std::optional<SMRange> &typeConstraint,
|
||||
|
||||
FailureOr<ast::ConstraintRef> Parser::parseArgOrResultConstraint() {
|
||||
std::optional<SMRange> typeConstraint;
|
||||
return parseConstraint(typeConstraint, /*existingConstraints=*/std::nullopt,
|
||||
return parseConstraint(typeConstraint, /*existingConstraints=*/{},
|
||||
/*allowInlineTypeConstraints=*/false);
|
||||
}
|
||||
|
||||
@@ -2995,8 +2994,8 @@ LogicalResult Parser::validateOperationOperandsOrResults(
|
||||
// Otherwise, create dummy values for each of the entries so that we
|
||||
// adhere to the ODS signature.
|
||||
for (unsigned i = 0, e = odsValues.size(); i < e; ++i) {
|
||||
values.push_back(ast::RangeExpr::create(
|
||||
ctx, loc, /*elements=*/std::nullopt, rangeTy));
|
||||
values.push_back(
|
||||
ast::RangeExpr::create(ctx, loc, /*elements=*/{}, rangeTy));
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ static Operation *createOp(MLIRContext *context, Location loc,
|
||||
unsigned int numRegions = 0) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(loc, OperationName(operationName, context), {}, {},
|
||||
std::nullopt, OpaqueProperties(nullptr),
|
||||
std::nullopt, numRegions);
|
||||
std::nullopt, OpaqueProperties(nullptr), {},
|
||||
numRegions);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -22,9 +22,9 @@ static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
|
||||
ArrayRef<Type> resultTypes = {},
|
||||
unsigned int numRegions = 0) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(
|
||||
UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes,
|
||||
operands, std::nullopt, nullptr, std::nullopt, numRegions);
|
||||
return Operation::create(UnknownLoc::get(context),
|
||||
OperationName("foo.bar", context), resultTypes,
|
||||
operands, std::nullopt, nullptr, {}, numRegions);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -33,7 +33,7 @@ TEST(OperandStorageTest, NonResizable) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *useOp =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value operand = useOp->getResult(0);
|
||||
|
||||
// Create a non-resizable operation with one operand.
|
||||
@@ -57,7 +57,7 @@ TEST(OperandStorageTest, Resizable) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *useOp =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value operand = useOp->getResult(0);
|
||||
|
||||
// Create a resizable operation with one operand.
|
||||
@@ -85,7 +85,7 @@ TEST(OperandStorageTest, RangeReplace) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *useOp =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value operand = useOp->getResult(0);
|
||||
|
||||
// Create a resizable operation with one operand.
|
||||
@@ -121,7 +121,7 @@ TEST(OperandStorageTest, MutableRange) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *useOp =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value operand = useOp->getResult(0);
|
||||
|
||||
// Create a resizable operation with one operand.
|
||||
@@ -158,8 +158,7 @@ TEST(OperandStorageTest, RangeErase) {
|
||||
Builder builder(&context);
|
||||
|
||||
Type type = builder.getNoneType();
|
||||
Operation *useOp =
|
||||
createOp(&context, /*operands=*/std::nullopt, {type, type});
|
||||
Operation *useOp = createOp(&context, /*operands=*/{}, {type, type});
|
||||
Value operand1 = useOp->getResult(0);
|
||||
Value operand2 = useOp->getResult(1);
|
||||
|
||||
@@ -189,8 +188,8 @@ TEST(OperationOrderTest, OrderIsAlwaysValid) {
|
||||
MLIRContext context;
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *containerOp = createOp(&context, /*operands=*/std::nullopt,
|
||||
/*resultTypes=*/std::nullopt,
|
||||
Operation *containerOp = createOp(&context, /*operands=*/{},
|
||||
/*resultTypes=*/{},
|
||||
/*numRegions=*/1);
|
||||
Region ®ion = containerOp->getRegion(0);
|
||||
Block *block = new Block();
|
||||
@@ -237,7 +236,7 @@ TEST(OperationFormatPrintTest, CanPrintNameAsPrefix) {
|
||||
Operation *op = Operation::create(
|
||||
NameLoc::get(StringAttr::get(&context, "my_named_loc")),
|
||||
OperationName("t.op", &context), builder.getIntegerType(16), {},
|
||||
std::nullopt, nullptr, std::nullopt, 0);
|
||||
std::nullopt, nullptr, {}, 0);
|
||||
|
||||
std::string str;
|
||||
OpPrintingFlags flags;
|
||||
|
||||
@@ -20,9 +20,9 @@ static Operation *createOp(MLIRContext *context, ArrayRef<Value> operands = {},
|
||||
ArrayRef<Type> resultTypes = {},
|
||||
unsigned int numRegions = 0) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(
|
||||
UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes,
|
||||
operands, std::nullopt, nullptr, std::nullopt, numRegions);
|
||||
return Operation::create(UnknownLoc::get(context),
|
||||
OperationName("foo.bar", context), resultTypes,
|
||||
operands, std::nullopt, nullptr, {}, numRegions);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -32,7 +32,7 @@ TEST(ValueTest, getNumUses) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *op0 =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
|
||||
Value v0 = op0->getResult(0);
|
||||
EXPECT_EQ(v0.getNumUses(), (unsigned)0);
|
||||
@@ -53,7 +53,7 @@ TEST(ValueTest, hasNUses) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *op0 =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value v0 = op0->getResult(0);
|
||||
EXPECT_TRUE(v0.hasNUses(0));
|
||||
EXPECT_FALSE(v0.hasNUses(1));
|
||||
@@ -77,7 +77,7 @@ TEST(ValueTest, hasNUsesOrMore) {
|
||||
Builder builder(&context);
|
||||
|
||||
Operation *op0 =
|
||||
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
|
||||
createOp(&context, /*operands=*/{}, builder.getIntegerType(16));
|
||||
Value v0 = op0->getResult(0);
|
||||
EXPECT_TRUE(v0.hasNUsesOrMore(0));
|
||||
EXPECT_FALSE(v0.hasNUsesOrMore(1));
|
||||
|
||||
@@ -13,9 +13,9 @@ using namespace mlir;
|
||||
|
||||
static Operation *createOp(MLIRContext *context) {
|
||||
context->allowUnregisteredDialects();
|
||||
return Operation::create(
|
||||
UnknownLoc::get(context), OperationName("foo.bar", context), {}, {},
|
||||
std::nullopt, /*properties=*/nullptr, std::nullopt, 0);
|
||||
return Operation::create(UnknownLoc::get(context),
|
||||
OperationName("foo.bar", context), {}, {},
|
||||
std::nullopt, /*properties=*/nullptr, {}, 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Reference in New Issue
Block a user