Skip to content

Commit 2e120d5

Browse files
kazutakahirataAnthony Tran
authored andcommitted
[mlir] Migrate away from std::nullopt (NFC) (llvm#145523)
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 migrates away from std::nullopt in favor of ArrayRef<T>() where we use perfect forwarding. Note that {} would be ambiguous for perfect forwarding to work.
1 parent 477d38c commit 2e120d5

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ void PDLToPDLInterpPass::runOnOperation() {
991991
module.getLoc(), pdl_interp::PDLInterpDialect::getMatcherFunctionName(),
992992
builder.getFunctionType(builder.getType<pdl::OperationType>(),
993993
/*results=*/{}),
994-
/*attrs=*/std::nullopt);
994+
/*attrs=*/ArrayRef<NamedAttribute>());
995995

996996
// Create a nested module to hold the functions invoked for rewriting the IR
997997
// after a successful match.

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ static Value createLinalgBodyCalculationForElementwiseOp(
310310
auto shifted =
311311
rewriter.create<arith::ShRSIOp>(loc, resultTypes, args[0], subtract)
312312
->getResults();
313-
auto truncated =
314-
rewriter.create<arith::TruncIOp>(loc, i1Ty, shifted, std::nullopt);
313+
auto truncated = rewriter.create<arith::TruncIOp>(
314+
loc, i1Ty, shifted, ArrayRef<NamedAttribute>());
315315
auto isInputOdd =
316316
rewriter.create<arith::AndIOp>(loc, i1Ty, truncated, i1one);
317317

@@ -552,20 +552,20 @@ static Value createLinalgBodyCalculationForElementwiseOp(
552552

553553
if (isa<FloatType>(srcTy) && isa<FloatType>(dstTy) && bitExtend)
554554
return rewriter.create<arith::ExtFOp>(loc, resultTypes, args,
555-
std::nullopt);
555+
ArrayRef<NamedAttribute>());
556556

557557
if (isa<FloatType>(srcTy) && isa<FloatType>(dstTy) && !bitExtend)
558558
return rewriter.create<arith::TruncFOp>(loc, resultTypes, args,
559-
std::nullopt);
559+
ArrayRef<NamedAttribute>());
560560

561561
// 1-bit integers need to be treated as signless.
562562
if (srcTy.isInteger(1) && arith::UIToFPOp::areCastCompatible(srcTy, dstTy))
563563
return rewriter.create<arith::UIToFPOp>(loc, resultTypes, args,
564-
std::nullopt);
564+
ArrayRef<NamedAttribute>());
565565

566566
if (srcTy.isInteger(1) && isa<IntegerType>(dstTy) && bitExtend)
567567
return rewriter.create<arith::ExtUIOp>(loc, resultTypes, args,
568-
std::nullopt);
568+
ArrayRef<NamedAttribute>());
569569

570570
// Unsigned integers need an unrealized cast so that they can be passed
571571
// to UIToFP.
@@ -583,7 +583,7 @@ static Value createLinalgBodyCalculationForElementwiseOp(
583583
// All other si-to-fp conversions should be handled by SIToFP.
584584
if (arith::SIToFPOp::areCastCompatible(srcTy, dstTy))
585585
return rewriter.create<arith::SIToFPOp>(loc, resultTypes, args,
586-
std::nullopt);
586+
ArrayRef<NamedAttribute>());
587587

588588
// Casting to boolean, floats need to only be checked as not-equal to zero.
589589
if (isa<FloatType>(srcTy) && dstTy.isInteger(1)) {
@@ -690,7 +690,7 @@ static Value createLinalgBodyCalculationForElementwiseOp(
690690

691691
if (isa<IntegerType>(srcTy) && isa<IntegerType>(dstTy) && bitExtend)
692692
return rewriter.create<arith::ExtSIOp>(loc, resultTypes, args,
693-
std::nullopt);
693+
ArrayRef<NamedAttribute>());
694694

695695
if (isa<IntegerType>(srcTy) && isa<IntegerType>(dstTy) && !bitExtend) {
696696
return rewriter.create<arith::TruncIOp>(loc, dstTy, args[0]);

mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ static Value getFlatMemref(OpBuilder &rewriter, Location loc, Value source,
111111
getFlatOffsetAndStrides(rewriter, loc, source, offsetsTemp);
112112
MemRefType retType = inferCastResultType(base, offset);
113113
return rewriter.create<memref::ReinterpretCastOp>(loc, retType, base, offset,
114-
std::nullopt, std::nullopt);
114+
ArrayRef<OpFoldResult>(),
115+
ArrayRef<OpFoldResult>());
115116
}
116117

117118
static bool needFlatten(Value val) {

mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ Value CodeGen::genNonInitializerVar(const ast::VariableDecl *varDecl,
350350
Value results = builder.create<pdl::TypesOp>(
351351
loc, pdl::RangeType::get(builder.getType<pdl::TypeType>()),
352352
/*types=*/ArrayAttr());
353-
return builder.create<pdl::OperationOp>(
354-
loc, opType.getName(), operands, std::nullopt, ValueRange(), results);
353+
return builder.create<pdl::OperationOp>(loc, opType.getName(), operands,
354+
ArrayRef<StringRef>(), ValueRange(),
355+
results);
355356
}
356357

357358
if (ast::RangeType rangeTy = dyn_cast<ast::RangeType>(type)) {

mlir/test/lib/Dialect/Test/TestPatterns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ struct TestPassthroughInvalidOp : public ConversionPattern {
10141014
.getResult());
10151015
}
10161016
rewriter.replaceOpWithNewOp<TestValidOp>(op, TypeRange(), flattened,
1017-
std::nullopt);
1017+
ArrayRef<NamedAttribute>());
10181018
return success();
10191019
}
10201020
};
@@ -1030,7 +1030,7 @@ struct TestDropAndReplaceInvalidOp : public ConversionPattern {
10301030
matchAndRewrite(Operation *op, ArrayRef<Value> operands,
10311031
ConversionPatternRewriter &rewriter) const final {
10321032
rewriter.replaceOpWithNewOp<TestValidOp>(op, TypeRange(), ValueRange(),
1033-
std::nullopt);
1033+
ArrayRef<NamedAttribute>());
10341034
return success();
10351035
}
10361036
};

0 commit comments

Comments
 (0)