[Mlir-commits] [mlir] 76b1100 - [mlir] llvm::Optional::value() && => operator*/operator->

Fangrui Song llvmlistbot at llvm.org
Sat Dec 17 11:23:55 PST 2022


Author: Fangrui Song
Date: 2022-12-17T19:23:50Z
New Revision: 76b11003728dc1e37a28d69db81fb7952c7486e9

URL: https://github.com/llvm/llvm-project/commit/76b11003728dc1e37a28d69db81fb7952c7486e9
DIFF: https://github.com/llvm/llvm-project/commit/76b11003728dc1e37a28d69db81fb7952c7486e9.diff

LOG: [mlir] llvm::Optional::value() && => operator*/operator->

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.

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
index 1790f4b550a6b..0c582ed4f1008 100644
--- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
@@ -221,7 +221,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
index 1790f4b550a6b..0c582ed4f1008 100644
--- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
@@ -221,7 +221,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
index d5061d9adf0ae..8348361530026 100644
--- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
@@ -225,7 +225,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
index d5061d9adf0ae..8348361530026 100644
--- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
@@ -225,7 +225,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
index d5061d9adf0ae..8348361530026 100644
--- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
@@ -225,7 +225,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
index 93c9bd5997f71..ed367b84d817a 100644
--- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
@@ -358,7 +358,7 @@ class MLIRGenImpl {
     // '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();
     }
 

diff  --git a/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td b/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
index 6f88a77be6798..4a96d99249092 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
+++ b/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
@@ -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 :

diff  --git a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
index 4bc24aff0abc5..680ef8d00b037 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
@@ -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);
   }


        


More information about the Mlir-commits mailing list