[mlir] Migrate away from ValueRange(std::nullopt) (NFC) (#145210)

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 common uses of std::nullopt is in one of the constructors
for ValueRange.  This patch takes care of the migration where we need
ValueRange() to facilitate perfect forwarding.  Note that {} would be
ambiguous for perfecting forwarding to work.
This commit is contained in:
Kazu Hirata
2025-06-22 06:30:17 -07:00
committed by GitHub
parent 2ac293f5ac
commit dec93ae454
8 changed files with 11 additions and 11 deletions

View File

@@ -79,7 +79,7 @@ struct AssertOpLowering : public ConvertOpToLLVMPattern<cf::AssertOp> {
abortFunc = rewriter.create<LLVM::LLVMFuncOp>(rewriter.getUnknownLoc(),
"abort", abortFuncTy);
}
rewriter.create<LLVM::CallOp>(loc, abortFunc, std::nullopt);
rewriter.create<LLVM::CallOp>(loc, abortFunc, ValueRange());
rewriter.create<LLVM::UnreachableOp>(loc);
} else {
rewriter.create<LLVM::BrOp>(loc, ValueRange(), continuationBlock);

View File

@@ -1616,8 +1616,8 @@ private:
// Hook up the cond exit to the remainder.
rewriter.setInsertionPointToEnd(condBlock);
rewriter.create<LLVM::CondBrOp>(loc, pred, bodyBlock, std::nullopt,
remainder, std::nullopt);
rewriter.create<LLVM::CondBrOp>(loc, pred, bodyBlock, ValueRange(),
remainder, ValueRange());
// Reset position to beginning of new remainder block.
rewriter.setInsertionPointToStart(remainder);

View File

@@ -928,7 +928,7 @@ LogicalResult ReinterpretCastPattern::matchAndRewrite(
}();
rewriter.replaceOpWithNewOp<spirv::InBoundsPtrAccessChainOp>(
op, src, offsetValue, std::nullopt);
op, src, offsetValue, ValueRange());
return success();
}

View File

@@ -421,7 +421,7 @@ struct WhileOpConversion final : SCFToSPIRVPattern<scf::WhileOp> {
rewriter.setInsertionPointToEnd(&beforeBlock);
rewriter.replaceOpWithNewOp<spirv::BranchConditionalOp>(
cond, conditionVal, &afterBlock, condArgs, &mergeBlock, std::nullopt);
cond, conditionVal, &afterBlock, condArgs, &mergeBlock, ValueRange());
// Convert the scf.yield op to a branch back to the header block.
rewriter.setInsertionPointToEnd(&afterBlock);

View File

@@ -2742,7 +2742,7 @@ buildAffineLoopFromConstants(OpBuilder &builder, Location loc, int64_t lb,
int64_t ub, int64_t step,
AffineForOp::BodyBuilderFn bodyBuilderFn) {
return builder.create<AffineForOp>(loc, lb, ub, step,
/*iterArgs=*/std::nullopt, bodyBuilderFn);
/*iterArgs=*/ValueRange(), bodyBuilderFn);
}
/// Creates an affine loop from the bounds that may or may not be constants.
@@ -2757,7 +2757,7 @@ buildAffineLoopFromValues(OpBuilder &builder, Location loc, Value lb, Value ub,
ubConst.value(), step, bodyBuilderFn);
return builder.create<AffineForOp>(loc, lb, builder.getDimIdentityMap(), ub,
builder.getDimIdentityMap(), step,
/*iterArgs=*/std::nullopt, bodyBuilderFn);
/*iterArgs=*/ValueRange(), bodyBuilderFn);
}
void mlir::affine::buildAffineLoopNest(

View File

@@ -460,14 +460,14 @@ func::FuncOp mlir::bufferization::buildDeallocationLibraryFunction(
Value toRetainSize = builder.create<memref::DimOp>(loc, toRetainMemref, c0);
builder.create<scf::ForOp>(
loc, c0, toRetainSize, c1, std::nullopt,
loc, c0, toRetainSize, c1, ValueRange(),
[&](OpBuilder &builder, Location loc, Value i, ValueRange iterArgs) {
builder.create<memref::StoreOp>(loc, falseValue, retainCondsMemref, i);
builder.create<scf::YieldOp>(loc);
});
builder.create<scf::ForOp>(
loc, c0, toDeallocSize, c1, std::nullopt,
loc, c0, toDeallocSize, c1, ValueRange(),
[&](OpBuilder &builder, Location loc, Value outerIter,
ValueRange iterArgs) {
Value toDealloc =

View File

@@ -3194,7 +3194,7 @@ struct MergeNestedParallelLoops : public OpRewritePattern<ParallelOp> {
auto newSteps = concatValues(op.getStep(), innerOp.getStep());
rewriter.replaceOpWithNewOp<ParallelOp>(op, newLowerBounds, newUpperBounds,
newSteps, std::nullopt,
newSteps, ValueRange(),
bodyBuilder);
return success();
}

View File

@@ -1537,7 +1537,7 @@ struct OutRewriter : public OpRewritePattern<OutOp> {
// For each element in the source tensor, output the element.
rewriter.create<ForeachOp>(
loc, src, std::nullopt,
loc, src, ValueRange(),
[&](OpBuilder &builder, Location loc, ValueRange dcvs, Value v,
ValueRange reduc) {
for (Dimension d = 0; d < dimRank; d++) {