[flang-commits] [flang] c715e2f - [flang] Use value_or (NFC)

Kazu Hirata via flang-commits flang-commits at lists.llvm.org
Sat Jul 16 00:52:00 PDT 2022


Author: Kazu Hirata
Date: 2022-07-16T00:51:54-07:00
New Revision: c715e2ff92ac5943b3b483def82cadb07b0d898c

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

LOG: [flang] Use value_or (NFC)

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
    flang/lib/Optimizer/CodeGen/CodeGen.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index fbe4029ff5c0..188a9d251cdf 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -252,12 +252,10 @@ class BoxedProcedurePass : public BoxedProcedurePassBase<BoxedProcedurePass> {
             rewriter.setInsertionPoint(mem);
             auto toTy = typeConverter.convertType(unwrapRefType(ty));
             bool isPinned = mem.getPinned();
-            llvm::StringRef uniqName;
-            if (mem.getUniqName())
-              uniqName = mem.getUniqName().getValue();
-            llvm::StringRef bindcName;
-            if (mem.getBindcName())
-              bindcName = mem.getBindcName().getValue();
+            llvm::StringRef uniqName =
+                mem.getUniqName().value_or(llvm::StringRef());
+            llvm::StringRef bindcName =
+                mem.getBindcName().value_or(llvm::StringRef());
             rewriter.replaceOpWithNewOp<AllocaOp>(
                 mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams(),
                 mem.getShape());
@@ -267,12 +265,10 @@ class BoxedProcedurePass : public BoxedProcedurePassBase<BoxedProcedurePass> {
           if (typeConverter.needsConversion(ty)) {
             rewriter.setInsertionPoint(mem);
             auto toTy = typeConverter.convertType(unwrapRefType(ty));
-            llvm::StringRef uniqName;
-            if (mem.getUniqName())
-              uniqName = mem.getUniqName().getValue();
-            llvm::StringRef bindcName;
-            if (mem.getBindcName())
-              bindcName = mem.getBindcName().getValue();
+            llvm::StringRef uniqName =
+                mem.getUniqName().value_or(llvm::StringRef());
+            llvm::StringRef bindcName =
+                mem.getBindcName().value_or(llvm::StringRef());
             rewriter.replaceOpWithNewOp<AllocMemOp>(
                 mem, toTy, uniqName, bindcName, mem.getTypeparams(),
                 mem.getShape());

diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 0f61776a7215..113556c280ba 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -2679,9 +2679,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
     if (global.getType().isa<fir::BoxType>())
       tyAttr = tyAttr.cast<mlir::LLVM::LLVMPointerType>().getElementType();
     auto loc = global.getLoc();
-    mlir::Attribute initAttr;
-    if (global.getInitVal())
-      initAttr = global.getInitVal().getValue();
+    mlir::Attribute initAttr = global.getInitVal().value_or(mlir::Attribute());
     auto linkage = convertLinkage(global.getLinkName());
     auto isConst = global.getConstant().has_value();
     auto g = rewriter.create<mlir::LLVM::GlobalOp>(


        


More information about the flang-commits mailing list