[mlir] Migrate away from TypeRange(std::nullopt) (NFC) (#145246)

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.

One of the uses of std::nullopt is in a the constructors for
TypeRange.  This patch takes care of the migration where we need
TypeRange() to facilitate perfect forwarding.  Note that {} would be
ambiguous for perfecting forwarding to work.
This commit is contained in:
Kazu Hirata
2025-06-22 19:09:31 -07:00
committed by GitHub
parent a17b5bce8c
commit 6023ba2bf7
3 changed files with 4 additions and 4 deletions

View File

@@ -245,7 +245,7 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
Location terminatorLoc = terminator.getLoc();
terminator.erase();
builder.setInsertionPointToEnd(innermostForOp.getBody());
builder.create<gpu::TerminatorOp>(terminatorLoc, std::nullopt);
builder.create<gpu::TerminatorOp>(terminatorLoc, TypeRange());
launchOp.getBody().front().getOperations().splice(
launchOp.getBody().front().begin(),
innermostForOp.getBody()->getOperations());

View File

@@ -839,7 +839,7 @@ public:
ConversionPatternRewriter &rewriter) const override {
if (callOp.getNumResults() == 0) {
auto newOp = rewriter.replaceOpWithNewOp<LLVM::CallOp>(
callOp, std::nullopt, adaptor.getOperands(), callOp->getAttrs());
callOp, TypeRange(), adaptor.getOperands(), callOp->getAttrs());
newOp.getProperties().operandSegmentSizes = {
static_cast<int32_t>(adaptor.getOperands().size()), 0};
newOp.getProperties().op_bundle_sizes = rewriter.getDenseI32ArrayAttr({});

View File

@@ -1008,7 +1008,7 @@ struct TestPassthroughInvalidOp : public ConversionPattern {
op->getOperand(it.index()).getType(), range)
.getResult());
}
rewriter.replaceOpWithNewOp<TestValidOp>(op, std::nullopt, flattened,
rewriter.replaceOpWithNewOp<TestValidOp>(op, TypeRange(), flattened,
std::nullopt);
return success();
}
@@ -1024,7 +1024,7 @@ struct TestDropAndReplaceInvalidOp : public ConversionPattern {
LogicalResult
matchAndRewrite(Operation *op, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const final {
rewriter.replaceOpWithNewOp<TestValidOp>(op, std::nullopt, ValueRange(),
rewriter.replaceOpWithNewOp<TestValidOp>(op, TypeRange(), ValueRange(),
std::nullopt);
return success();
}