Skip to content

Commit dec93ae

Browse files
[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.
1 parent 2ac293f commit dec93ae

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct AssertOpLowering : public ConvertOpToLLVMPattern<cf::AssertOp> {
7979
abortFunc = rewriter.create<LLVM::LLVMFuncOp>(rewriter.getUnknownLoc(),
8080
"abort", abortFuncTy);
8181
}
82-
rewriter.create<LLVM::CallOp>(loc, abortFunc, std::nullopt);
82+
rewriter.create<LLVM::CallOp>(loc, abortFunc, ValueRange());
8383
rewriter.create<LLVM::UnreachableOp>(loc);
8484
} else {
8585
rewriter.create<LLVM::BrOp>(loc, ValueRange(), continuationBlock);

mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,8 +1616,8 @@ struct MemRefReshapeOpLowering
16161616

16171617
// Hook up the cond exit to the remainder.
16181618
rewriter.setInsertionPointToEnd(condBlock);
1619-
rewriter.create<LLVM::CondBrOp>(loc, pred, bodyBlock, std::nullopt,
1620-
remainder, std::nullopt);
1619+
rewriter.create<LLVM::CondBrOp>(loc, pred, bodyBlock, ValueRange(),
1620+
remainder, ValueRange());
16211621

16221622
// Reset position to beginning of new remainder block.
16231623
rewriter.setInsertionPointToStart(remainder);

mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ LogicalResult ReinterpretCastPattern::matchAndRewrite(
928928
}();
929929

930930
rewriter.replaceOpWithNewOp<spirv::InBoundsPtrAccessChainOp>(
931-
op, src, offsetValue, std::nullopt);
931+
op, src, offsetValue, ValueRange());
932932
return success();
933933
}
934934

mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ struct WhileOpConversion final : SCFToSPIRVPattern<scf::WhileOp> {
421421

422422
rewriter.setInsertionPointToEnd(&beforeBlock);
423423
rewriter.replaceOpWithNewOp<spirv::BranchConditionalOp>(
424-
cond, conditionVal, &afterBlock, condArgs, &mergeBlock, std::nullopt);
424+
cond, conditionVal, &afterBlock, condArgs, &mergeBlock, ValueRange());
425425

426426
// Convert the scf.yield op to a branch back to the header block.
427427
rewriter.setInsertionPointToEnd(&afterBlock);

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,7 +2742,7 @@ buildAffineLoopFromConstants(OpBuilder &builder, Location loc, int64_t lb,
27422742
int64_t ub, int64_t step,
27432743
AffineForOp::BodyBuilderFn bodyBuilderFn) {
27442744
return builder.create<AffineForOp>(loc, lb, ub, step,
2745-
/*iterArgs=*/std::nullopt, bodyBuilderFn);
2745+
/*iterArgs=*/ValueRange(), bodyBuilderFn);
27462746
}
27472747

27482748
/// 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,
27572757
ubConst.value(), step, bodyBuilderFn);
27582758
return builder.create<AffineForOp>(loc, lb, builder.getDimIdentityMap(), ub,
27592759
builder.getDimIdentityMap(), step,
2760-
/*iterArgs=*/std::nullopt, bodyBuilderFn);
2760+
/*iterArgs=*/ValueRange(), bodyBuilderFn);
27612761
}
27622762

27632763
void mlir::affine::buildAffineLoopNest(

mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,14 @@ func::FuncOp mlir::bufferization::buildDeallocationLibraryFunction(
460460
Value toRetainSize = builder.create<memref::DimOp>(loc, toRetainMemref, c0);
461461

462462
builder.create<scf::ForOp>(
463-
loc, c0, toRetainSize, c1, std::nullopt,
463+
loc, c0, toRetainSize, c1, ValueRange(),
464464
[&](OpBuilder &builder, Location loc, Value i, ValueRange iterArgs) {
465465
builder.create<memref::StoreOp>(loc, falseValue, retainCondsMemref, i);
466466
builder.create<scf::YieldOp>(loc);
467467
});
468468

469469
builder.create<scf::ForOp>(
470-
loc, c0, toDeallocSize, c1, std::nullopt,
470+
loc, c0, toDeallocSize, c1, ValueRange(),
471471
[&](OpBuilder &builder, Location loc, Value outerIter,
472472
ValueRange iterArgs) {
473473
Value toDealloc =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ struct MergeNestedParallelLoops : public OpRewritePattern<ParallelOp> {
31943194
auto newSteps = concatValues(op.getStep(), innerOp.getStep());
31953195

31963196
rewriter.replaceOpWithNewOp<ParallelOp>(op, newLowerBounds, newUpperBounds,
3197-
newSteps, std::nullopt,
3197+
newSteps, ValueRange(),
31983198
bodyBuilder);
31993199
return success();
32003200
}

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ struct OutRewriter : public OpRewritePattern<OutOp> {
15371537

15381538
// For each element in the source tensor, output the element.
15391539
rewriter.create<ForeachOp>(
1540-
loc, src, std::nullopt,
1540+
loc, src, ValueRange(),
15411541
[&](OpBuilder &builder, Location loc, ValueRange dcvs, Value v,
15421542
ValueRange reduc) {
15431543
for (Dimension d = 0; d < dimRank; d++) {

0 commit comments

Comments
 (0)