From dec93ae45492cd84e3eec05f00ffb0fb1d35f045 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 22 Jun 2025 06:30:17 -0700 Subject: [PATCH] [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. --- mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp | 2 +- mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp | 4 ++-- mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp | 2 +- mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp | 2 +- mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 4 ++-- .../Dialect/Bufferization/Transforms/LowerDeallocations.cpp | 4 ++-- mlir/lib/Dialect/SCF/IR/SCF.cpp | 2 +- .../Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp index 3d0804fd11b6..cf416e140c85 100644 --- a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp +++ b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp @@ -79,7 +79,7 @@ struct AssertOpLowering : public ConvertOpToLLVMPattern { abortFunc = rewriter.create(rewriter.getUnknownLoc(), "abort", abortFuncTy); } - rewriter.create(loc, abortFunc, std::nullopt); + rewriter.create(loc, abortFunc, ValueRange()); rewriter.create(loc); } else { rewriter.create(loc, ValueRange(), continuationBlock); diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp index e8294a5234c4..4b7b2cc224ce 100644 --- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp +++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp @@ -1616,8 +1616,8 @@ private: // Hook up the cond exit to the remainder. rewriter.setInsertionPointToEnd(condBlock); - rewriter.create(loc, pred, bodyBlock, std::nullopt, - remainder, std::nullopt); + rewriter.create(loc, pred, bodyBlock, ValueRange(), + remainder, ValueRange()); // Reset position to beginning of new remainder block. rewriter.setInsertionPointToStart(remainder); diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp index ff5b762a969d..f8867c65fe7d 100644 --- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp @@ -928,7 +928,7 @@ LogicalResult ReinterpretCastPattern::matchAndRewrite( }(); rewriter.replaceOpWithNewOp( - op, src, offsetValue, std::nullopt); + op, src, offsetValue, ValueRange()); return success(); } diff --git a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp index baac1b374b12..a59001de299f 100644 --- a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp +++ b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp @@ -421,7 +421,7 @@ struct WhileOpConversion final : SCFToSPIRVPattern { rewriter.setInsertionPointToEnd(&beforeBlock); rewriter.replaceOpWithNewOp( - 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); diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index 3d09c6a9b2c2..48770d4f4ff7 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -2742,7 +2742,7 @@ buildAffineLoopFromConstants(OpBuilder &builder, Location loc, int64_t lb, int64_t ub, int64_t step, AffineForOp::BodyBuilderFn bodyBuilderFn) { return builder.create(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(loc, lb, builder.getDimIdentityMap(), ub, builder.getDimIdentityMap(), step, - /*iterArgs=*/std::nullopt, bodyBuilderFn); + /*iterArgs=*/ValueRange(), bodyBuilderFn); } void mlir::affine::buildAffineLoopNest( diff --git a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp index f51b125bda6e..2a17ae4f6a24 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp @@ -460,14 +460,14 @@ func::FuncOp mlir::bufferization::buildDeallocationLibraryFunction( Value toRetainSize = builder.create(loc, toRetainMemref, c0); builder.create( - loc, c0, toRetainSize, c1, std::nullopt, + loc, c0, toRetainSize, c1, ValueRange(), [&](OpBuilder &builder, Location loc, Value i, ValueRange iterArgs) { builder.create(loc, falseValue, retainCondsMemref, i); builder.create(loc); }); builder.create( - loc, c0, toDeallocSize, c1, std::nullopt, + loc, c0, toDeallocSize, c1, ValueRange(), [&](OpBuilder &builder, Location loc, Value outerIter, ValueRange iterArgs) { Value toDealloc = diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index 5a0b8a058dd6..b3271462df27 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -3194,7 +3194,7 @@ struct MergeNestedParallelLoops : public OpRewritePattern { auto newSteps = concatValues(op.getStep(), innerOp.getStep()); rewriter.replaceOpWithNewOp(op, newLowerBounds, newUpperBounds, - newSteps, std::nullopt, + newSteps, ValueRange(), bodyBuilder); return success(); } diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp index dcb023707088..093a35a3d4c9 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp @@ -1537,7 +1537,7 @@ struct OutRewriter : public OpRewritePattern { // For each element in the source tensor, output the element. rewriter.create( - loc, src, std::nullopt, + loc, src, ValueRange(), [&](OpBuilder &builder, Location loc, ValueRange dcvs, Value v, ValueRange reduc) { for (Dimension d = 0; d < dimRank; d++) {