[mlir] llvm::Optional::value() && => operator*/operator->
authorFangrui Song <i@maskray.me>
Sat, 17 Dec 2022 19:23:50 +0000 (19:23 +0000)
committerFangrui Song <i@maskray.me>
Sat, 17 Dec 2022 19:23:50 +0000 (19:23 +0000)
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.

mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp

index 1790f4b..0c582ed 100644 (file)
@@ -221,7 +221,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index 1790f4b..0c582ed 100644 (file)
@@ -221,7 +221,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index d5061d9..8348361 100644 (file)
@@ -225,7 +225,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index d5061d9..8348361 100644 (file)
@@ -225,7 +225,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index d5061d9..8348361 100644 (file)
@@ -225,7 +225,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index 93c9bd5..ed367b8 100644 (file)
@@ -358,7 +358,7 @@ private:
     // 'return' takes an optional expression, handle that case here.
     mlir::Value expr = nullptr;
     if (ret.getExpr().has_value()) {
-      if (!(expr = mlirGen(*ret.getExpr().value())))
+      if (!(expr = mlirGen(**ret.getExpr())))
         return mlir::failure();
     }
 
index 6f88a77..4a96d99 100644 (file)
@@ -126,7 +126,7 @@ def MulSIExtendedToMulI :
 def IsScalarOrSplatOne :
     Constraint<And<[
       CPred<"succeeded(getIntOrSplatIntValue($0))">,
-      CPred<"getIntOrSplatIntValue($0).value() == 1">]>>;
+      CPred<"*getIntOrSplatIntValue($0) == 1">]>>;
 
 // mulsi_extended(x, 1) -> [x, extsi(cmpi slt, x, 0)]
 def MulSIExtendedRHSOne :
@@ -284,7 +284,7 @@ def TruncationMatchesShiftAmount :
     Constraint<And<[
       CPred<"succeeded(getIntOrSplatIntValue($2))">,
       CPred<"(getScalarOrElementWidth($0) - getScalarOrElementWidth($1)) == "
-              "getIntOrSplatIntValue($2).value()">]>>;
+              "*getIntOrSplatIntValue($2)">]>>;
 
 // trunci(shrsi(x, c)) -> trunci(shrui(x, c))
 def TruncIShrSIToTrunciShrUI :
index 4bc24af..680ef8d 100644 (file)
@@ -1172,7 +1172,7 @@ static Operation *genFor(Merger &merger, CodeGen &codegen, OpBuilder &builder,
   bool isParallel = isParallelFor(codegen, isOuter, isSparse);
 
   Operation *loop =
-      genLoopBoundary(codegen, merger, [&](MutableArrayRef<Value> reduc) {
+      *genLoopBoundary(codegen, merger, [&](MutableArrayRef<Value> reduc) {
         if (merger.isFilterLoop(idx)) {
           // extraTids/extraDims must be empty because filter loops only
           // corresponding to the one and only sparse tensor level.
@@ -1187,7 +1187,7 @@ static Operation *genFor(Merger &merger, CodeGen &codegen, OpBuilder &builder,
         }
         return codegen.loopEmitter.enterLoopOverTensorAtDim(
             builder, loc, tid, dim, reduc, isParallel, extraTids, extraDims);
-      }).value();
+      });
   assert(loop);
   return loop;
 }
@@ -1200,12 +1200,12 @@ static Operation *genWhile(Merger &merger, CodeGen &codegen, OpBuilder &builder,
                            ArrayRef<size_t> extraDims) {
 
   Operation *loop =
-      genLoopBoundary(codegen, merger, [&](MutableArrayRef<Value> reduc) {
+      *genLoopBoundary(codegen, merger, [&](MutableArrayRef<Value> reduc) {
         // Construct the while-loop with a parameter for each index.
         return codegen.loopEmitter.enterCoIterationOverTensorsAtDims(
             builder, op.getLoc(), condTids, condDims, needsUniv, reduc,
             extraTids, extraDims);
-      }).value();
+      });
   assert(loop);
   return loop;
 }
@@ -1277,7 +1277,7 @@ static scf::IfOp genIf(Merger &merger, CodeGen &codegen, OpBuilder &builder,
     Value clause;
     if (isCompressedDLT(merger.getDimLevelType(b)) ||
         isSingletonDLT(merger.getDimLevelType(b))) {
-      auto dim = merger.getDimNum(tensor, idx).value();
+      auto dim = *merger.getDimNum(tensor, idx);
       Value op1 = codegen.loopEmitter.getCoord()[tensor][dim];
       Value op2 = codegen.getLoopIdxValue(idx);
       clause = builder.create<arith::CmpIOp>(loc, arith::CmpIPredicate::eq, op1,
@@ -1486,7 +1486,7 @@ static void translateBitsToTidDimPairs(
     // Note that we generate dense indices of the output tensor
     // unconditionally, since they may not appear in the lattice, but may be
     // needed for linearized codegen.
-    auto dim = merger.getDimNum(merger.getOutTensorID(), idx).value();
+    auto dim = *merger.getDimNum(merger.getOutTensorID(), idx);
     extraTids.push_back(merger.getOutTensorID());
     extraDims.push_back(dim);
   }