Skip to content

Commit 0a81ace

Browse files
[mlir] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
1 parent bb83dc1 commit 0a81ace

File tree

244 files changed

+1211
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+1211
-1122
lines changed

mlir/examples/toy/Ch1/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch1/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch2/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch2/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch3/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch3/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch4/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch4/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch5/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch5/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch6/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class VarDeclExprAST : public ExprAST {
129129

130130
/// Expression class for a return operator.
131131
class ReturnExprAST : public ExprAST {
132-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
132+
std::optional<std::unique_ptr<ExprAST>> expr;
133133

134134
public:
135-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
135+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
136136
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
137137

138-
llvm::Optional<ExprAST *> getExpr() {
138+
std::optional<ExprAST *> getExpr() {
139139
if (expr.has_value())
140140
return expr->get();
141141
return std::nullopt;

mlir/examples/toy/Ch6/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parser {
6767
lexer.consume(tok_return);
6868

6969
// return takes an optional argument
70-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
70+
std::optional<std::unique_ptr<ExprAST>> expr;
7171
if (lexer.getCurToken() != ';') {
7272
expr = parseExpression();
7373
if (!expr)

mlir/examples/toy/Ch7/include/toy/AST.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ class VarDeclExprAST : public ExprAST {
149149

150150
/// Expression class for a return operator.
151151
class ReturnExprAST : public ExprAST {
152-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
152+
std::optional<std::unique_ptr<ExprAST>> expr;
153153

154154
public:
155-
ReturnExprAST(Location loc, llvm::Optional<std::unique_ptr<ExprAST>> expr)
155+
ReturnExprAST(Location loc, std::optional<std::unique_ptr<ExprAST>> expr)
156156
: ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {}
157157

158-
llvm::Optional<ExprAST *> getExpr() {
158+
std::optional<ExprAST *> getExpr() {
159159
if (expr.has_value())
160160
return expr->get();
161161
return std::nullopt;

mlir/examples/toy/Ch7/include/toy/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Parser {
8282
lexer.consume(tok_return);
8383

8484
// return takes an optional argument
85-
llvm::Optional<std::unique_ptr<ExprAST>> expr;
85+
std::optional<std::unique_ptr<ExprAST>> expr;
8686
if (lexer.getCurToken() != ';') {
8787
expr = parseExpression();
8888
if (!expr)

mlir/examples/toy/Ch7/mlir/MLIRGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class MLIRGenImpl {
271271
}
272272

273273
/// Return the numeric member index of the given struct access expression.
274-
llvm::Optional<size_t> getMemberIndex(BinaryExprAST &accessOp) {
274+
std::optional<size_t> getMemberIndex(BinaryExprAST &accessOp) {
275275
assert(accessOp.getOp() == '.' && "expected access operation");
276276

277277
// Lookup the struct node for the LHS.
@@ -313,7 +313,7 @@ class MLIRGenImpl {
313313

314314
// If this is an access operation, handle it immediately.
315315
if (binop.getOp() == '.') {
316-
llvm::Optional<size_t> accessIndex = getMemberIndex(binop);
316+
std::optional<size_t> accessIndex = getMemberIndex(binop);
317317
if (!accessIndex) {
318318
emitError(location, "invalid access into struct expression");
319319
return nullptr;

mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ConstantValue {
8383

8484
private:
8585
/// The constant value.
86-
Optional<Attribute> constant;
86+
std::optional<Attribute> constant;
8787
/// A dialect instance that can be used to materialize the constant.
8888
Dialect *dialect = nullptr;
8989
};

mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class DeadCodeAnalysis : public DataFlowAnalysis {
221221

222222
/// Get the constant values of the operands of the operation. Returns none if
223223
/// any of the operand lattices are uninitialized.
224-
Optional<SmallVector<Attribute>> getOperandValues(Operation *op);
224+
std::optional<SmallVector<Attribute>> getOperandValues(Operation *op);
225225

226226
/// The top-level operation the analysis is running on. This is used to detect
227227
/// if a callable is outside the scope of the analysis and thus must be

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ class IntegerRelation {
362362
///
363363
/// Returns an integer sample point if one exists, or an empty Optional
364364
/// otherwise. The returned value also includes values of local ids.
365-
Optional<SmallVector<MPInt, 8>> findIntegerSample() const;
365+
std::optional<SmallVector<MPInt, 8>> findIntegerSample() const;
366366

367367
/// Compute an overapproximation of the number of integer points in the
368368
/// relation. Symbol vars currently not supported. If the computed
369369
/// overapproximation is infinite, an empty optional is returned.
370-
Optional<MPInt> computeVolume() const;
370+
std::optional<MPInt> computeVolume() const;
371371

372372
/// Returns true if the given point satisfies the constraints, or false
373373
/// otherwise. Takes the values of all vars including locals.
@@ -377,9 +377,9 @@ class IntegerRelation {
377377
}
378378
/// Given the values of non-local vars, return a satisfying assignment to the
379379
/// local if one exists, or an empty optional otherwise.
380-
Optional<SmallVector<MPInt, 8>>
380+
std::optional<SmallVector<MPInt, 8>>
381381
containsPointNoLocal(ArrayRef<MPInt> point) const;
382-
Optional<SmallVector<MPInt, 8>>
382+
std::optional<SmallVector<MPInt, 8>>
383383
containsPointNoLocal(ArrayRef<int64_t> point) const {
384384
return containsPointNoLocal(getMPIntVec(point));
385385
}
@@ -473,20 +473,20 @@ class IntegerRelation {
473473
/// equality). Ex: if the lower bound is [(s0 + s2 - 1) floordiv 32] for a
474474
/// system with three symbolic variables, *lb = [1, 0, 1], lbDivisor = 32. See
475475
/// comments at function definition for examples.
476-
Optional<MPInt> getConstantBoundOnDimSize(
476+
std::optional<MPInt> getConstantBoundOnDimSize(
477477
unsigned pos, SmallVectorImpl<MPInt> *lb = nullptr,
478478
MPInt *boundFloorDivisor = nullptr, SmallVectorImpl<MPInt> *ub = nullptr,
479479
unsigned *minLbPos = nullptr, unsigned *minUbPos = nullptr) const;
480480
/// The same, but casts to int64_t. This is unsafe and will assert-fail if the
481481
/// value does not fit in an int64_t.
482-
Optional<int64_t> getConstantBoundOnDimSize64(
482+
std::optional<int64_t> getConstantBoundOnDimSize64(
483483
unsigned pos, SmallVectorImpl<int64_t> *lb = nullptr,
484484
int64_t *boundFloorDivisor = nullptr,
485485
SmallVectorImpl<int64_t> *ub = nullptr, unsigned *minLbPos = nullptr,
486486
unsigned *minUbPos = nullptr) const {
487487
SmallVector<MPInt, 8> ubMPInt, lbMPInt;
488488
MPInt boundFloorDivisorMPInt;
489-
Optional<MPInt> result = getConstantBoundOnDimSize(
489+
std::optional<MPInt> result = getConstantBoundOnDimSize(
490490
pos, &lbMPInt, &boundFloorDivisorMPInt, &ubMPInt, minLbPos, minUbPos);
491491
if (lb)
492492
*lb = getInt64Vec(lbMPInt);
@@ -499,10 +499,11 @@ class IntegerRelation {
499499

500500
/// Returns the constant bound for the pos^th variable if there is one;
501501
/// std::nullopt otherwise.
502-
Optional<MPInt> getConstantBound(BoundType type, unsigned pos) const;
502+
std::optional<MPInt> getConstantBound(BoundType type, unsigned pos) const;
503503
/// The same, but casts to int64_t. This is unsafe and will assert-fail if the
504504
/// value does not fit in an int64_t.
505-
Optional<int64_t> getConstantBound64(BoundType type, unsigned pos) const {
505+
std::optional<int64_t> getConstantBound64(BoundType type,
506+
unsigned pos) const {
506507
return llvm::transformOptional(getConstantBound(type, pos), int64FromMPInt);
507508
}
508509

@@ -683,11 +684,11 @@ class IntegerRelation {
683684
/// Returns the constant lower bound bound if isLower is true, and the upper
684685
/// bound if isLower is false.
685686
template <bool isLower>
686-
Optional<MPInt> computeConstantLowerOrUpperBound(unsigned pos);
687+
std::optional<MPInt> computeConstantLowerOrUpperBound(unsigned pos);
687688
/// The same, but casts to int64_t. This is unsafe and will assert-fail if the
688689
/// value does not fit in an int64_t.
689690
template <bool isLower>
690-
Optional<int64_t> computeConstantLowerOrUpperBound64(unsigned pos) {
691+
std::optional<int64_t> computeConstantLowerOrUpperBound64(unsigned pos) {
691692
return computeConstantLowerOrUpperBound<isLower>(pos).map(int64FromMPInt);
692693
}
693694

mlir/include/mlir/Analysis/Presburger/PWMAFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ class PWMAFunction {
176176
PresburgerSet getDomain() const;
177177

178178
/// Return the output of the function at the given point.
179-
Optional<SmallVector<MPInt, 8>> valueAt(ArrayRef<MPInt> point) const;
180-
Optional<SmallVector<MPInt, 8>> valueAt(ArrayRef<int64_t> point) const {
179+
std::optional<SmallVector<MPInt, 8>> valueAt(ArrayRef<MPInt> point) const;
180+
std::optional<SmallVector<MPInt, 8>> valueAt(ArrayRef<int64_t> point) const {
181181
return valueAt(getMPIntVec(point));
182182
}
183183

mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class PresburgerRelation {
121121
/// This currently just sums up the overapproximations of the volumes of the
122122
/// disjuncts, so the approximation might be far from the true volume in the
123123
/// case when there is a lot of overlap between disjuncts.
124-
Optional<MPInt> computeVolume() const;
124+
std::optional<MPInt> computeVolume() const;
125125

126126
/// Simplifies the representation of a PresburgerRelation.
127127
///

mlir/include/mlir/Analysis/Presburger/Simplex.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class SimplexBase {
264264
/// Returns an empty optional if no pivot is possible, which happens only when
265265
/// the column unknown is a variable and no constraint has a non-zero
266266
/// coefficient for it.
267-
Optional<unsigned> findAnyPivotRow(unsigned col);
267+
std::optional<unsigned> findAnyPivotRow(unsigned col);
268268

269269
/// Swap the row with the column in the tableau's data structures but not the
270270
/// tableau itself. This is used by pivot.
@@ -523,11 +523,11 @@ class LexSimplex : public LexSimplexBase {
523523

524524
/// Get a constraint row that is violated, if one exists.
525525
/// Otherwise, return an empty optional.
526-
Optional<unsigned> maybeGetViolatedRow() const;
526+
std::optional<unsigned> maybeGetViolatedRow() const;
527527

528528
/// Get a row corresponding to a var that has a non-integral sample value, if
529529
/// one exists. Otherwise, return an empty optional.
530-
Optional<unsigned> maybeGetNonIntegralVarRow() const;
530+
std::optional<unsigned> maybeGetNonIntegralVarRow() const;
531531
};
532532

533533
/// Represents the result of a symbolic lexicographic minimization computation.
@@ -634,11 +634,11 @@ class SymbolicLexSimplex : public LexSimplexBase {
634634
LogicalResult doNonBranchingPivots();
635635

636636
/// Get a row that is always violated in the current domain, if one exists.
637-
Optional<unsigned> maybeGetAlwaysViolatedRow();
637+
std::optional<unsigned> maybeGetAlwaysViolatedRow();
638638

639639
/// Get a row corresponding to a variable with non-integral sample value, if
640640
/// one exists.
641-
Optional<unsigned> maybeGetNonIntegralVarRow();
641+
std::optional<unsigned> maybeGetNonIntegralVarRow();
642642

643643
/// Given a row that has a non-integer sample value, cut away this fractional
644644
/// sample value witahout removing any integer points, i.e., the integer
@@ -782,7 +782,7 @@ class Simplex : public SimplexBase {
782782

783783
/// Returns an integer sample point if one exists, or std::nullopt
784784
/// otherwise. This should only be called for bounded sets.
785-
Optional<SmallVector<MPInt, 8>> findIntegerSample();
785+
std::optional<SmallVector<MPInt, 8>> findIntegerSample();
786786

787787
enum class IneqType { Redundant, Cut, Separate };
788788

@@ -806,11 +806,11 @@ class Simplex : public SimplexBase {
806806

807807
/// Returns the current sample point if it is integral. Otherwise, returns
808808
/// std::nullopt.
809-
Optional<SmallVector<MPInt, 8>> getSamplePointIfIntegral() const;
809+
std::optional<SmallVector<MPInt, 8>> getSamplePointIfIntegral() const;
810810

811811
/// Returns the current sample point, which may contain non-integer (rational)
812812
/// coordinates. Returns an empty optional when the tableau is empty.
813-
Optional<SmallVector<Fraction, 8>> getRationalSample() const;
813+
std::optional<SmallVector<Fraction, 8>> getRationalSample() const;
814814

815815
private:
816816
friend class GBRSimplex;
@@ -829,7 +829,7 @@ class Simplex : public SimplexBase {
829829
///
830830
/// Returns a (row, col) pair denoting a pivot, or an empty Optional if
831831
/// no valid pivot exists.
832-
Optional<Pivot> findPivot(int row, Direction direction) const;
832+
std::optional<Pivot> findPivot(int row, Direction direction) const;
833833

834834
/// Find a row that can be used to pivot the column in the specified
835835
/// direction. If skipRow is not null, then this row is excluded
@@ -839,8 +839,8 @@ class Simplex : public SimplexBase {
839839
///
840840
/// Returns the row to pivot to, or an empty Optional if the column
841841
/// is unbounded in the specified direction.
842-
Optional<unsigned> findPivotRow(Optional<unsigned> skipRow,
843-
Direction direction, unsigned col) const;
842+
std::optional<unsigned> findPivotRow(std::optional<unsigned> skipRow,
843+
Direction direction, unsigned col) const;
844844

845845
/// Undo the addition of the last constraint while preserving tableau
846846
/// consistency.

0 commit comments

Comments
 (0)