[BOLT] Use std::optional instead of llvm::Optional (NFC)
authorKazu Hirata <kazu@google.com>
Tue, 3 Jan 2023 02:40:21 +0000 (18:40 -0800)
committerKazu Hirata <kazu@google.com>
Tue, 3 Jan 2023 02:40:21 +0000 (18:40 -0800)
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

bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Passes/DataflowAnalysis.h
bolt/include/bolt/Passes/ReachingDefOrUse.h
bolt/lib/Passes/ShrinkWrapping.cpp
bolt/lib/Passes/ValidateInternalCalls.cpp
bolt/lib/Rewrite/MachORewriteInstance.cpp
bolt/lib/Rewrite/RewriteInstance.cpp

index 2d60ac5..32ad4da 100644 (file)
@@ -42,6 +42,7 @@
 #include <functional>
 #include <list>
 #include <map>
+#include <optional>
 #include <set>
 #include <string>
 #include <system_error>
@@ -650,11 +651,11 @@ public:
 
   /// Address of the code/function that is executed before any other code in
   /// the binary.
-  Optional<uint64_t> StartFunctionAddress;
+  std::optional<uint64_t> StartFunctionAddress;
 
   /// Address of the code/function that is going to be executed right before
   /// the execution of the binary is completed.
-  Optional<uint64_t> FiniFunctionAddress;
+  std::optional<uint64_t> FiniFunctionAddress;
 
   /// Page alignment used for code layout.
   uint64_t PageAlign{HugePageSize};
index 1f9087e..7104443 100644 (file)
@@ -12,6 +12,7 @@
 #include "bolt/Core/BinaryContext.h"
 #include "bolt/Core/BinaryFunction.h"
 #include "llvm/Support/Errc.h"
+#include <optional>
 #include <queue>
 
 namespace llvm {
@@ -152,7 +153,7 @@ class DataflowAnalysis {
     return *static_cast<const Derived *>(this);
   }
 
-  mutable Optional<unsigned> AnnotationIndex;
+  mutable std::optional<unsigned> AnnotationIndex;
 
 protected:
   const BinaryContext &BC;
index 0d5fb2b..f38d1a3 100644 (file)
 
 #include "bolt/Passes/DataflowAnalysis.h"
 #include "bolt/Passes/RegAnalysis.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Timer.h"
+#include <optional>
 
 namespace opts {
 extern llvm::cl::opt<bool> TimeOpts;
@@ -34,7 +34,7 @@ class ReachingDefOrUse
 
 public:
   ReachingDefOrUse(const RegAnalysis &RA, BinaryFunction &BF,
-                   Optional<MCPhysReg> TrackingReg = std::nullopt,
+                   std::optional<MCPhysReg> TrackingReg = std::nullopt,
                    MCPlusBuilder::AllocatorIdTy AllocId = 0)
       : InstrsDataflowAnalysis<ReachingDefOrUse<Def>, !Def>(BF, AllocId),
         RA(RA), TrackingReg(TrackingReg) {}
@@ -65,7 +65,7 @@ protected:
 
   /// If set, limit the dataflow to only track instructions affecting this
   /// register. Otherwise the analysis can be too permissive.
-  Optional<MCPhysReg> TrackingReg;
+  std::optional<MCPhysReg> TrackingReg;
 
   void preflight() {
     // Populate our universe of tracked expressions with all instructions
index ffc5189..5f013a7 100644 (file)
@@ -16,6 +16,7 @@
 #include "bolt/Passes/MCF.h"
 #include "bolt/Utils/CommandLineOpts.h"
 #include <numeric>
+#include <optional>
 #include <stack>
 
 #define DEBUG_TYPE "shrinkwrapping"
@@ -1465,7 +1466,7 @@ class PredictiveStackPointerTracking
   decltype(ShrinkWrapping::Todo) &TodoMap;
   DataflowInfoManager &Info;
 
-  Optional<unsigned> AnnotationIndex;
+  std::optional<unsigned> AnnotationIndex;
 
 protected:
   void compNextAux(const MCInst &Point,
index ba7e791..22dadf4 100644 (file)
@@ -16,6 +16,7 @@
 #include "bolt/Passes/FrameAnalysis.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/MC/MCInstPrinter.h"
+#include <optional>
 #include <queue>
 
 #define DEBUG_TYPE "bolt-internalcalls"
@@ -43,7 +44,7 @@ class StackPointerTrackingForInternalCalls
   friend class DataflowAnalysis<StackPointerTrackingForInternalCalls,
                                 std::pair<int, int>>;
 
-  Optional<unsigned> AnnotationIndex;
+  std::optional<unsigned> AnnotationIndex;
 
 protected:
   // We change the starting state to only consider the first block as an
index d4882f0..cdc064c 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include <memory>
+#include <optional>
 
 namespace opts {
 
@@ -197,9 +198,9 @@ std::vector<DataInCodeRegion> readDataInCode(const MachOObjectFile &O) {
   return DataInCode;
 }
 
-Optional<uint64_t> readStartAddress(const MachOObjectFile &O) {
-  Optional<uint64_t> StartOffset;
-  Optional<uint64_t> TextVMAddr;
+std::optional<uint64_t> readStartAddress(const MachOObjectFile &O) {
+  std::optional<uint64_t> StartOffset;
+  std::optional<uint64_t> TextVMAddr;
   for (const object::MachOObjectFile::LoadCommandInfo &LC : O.load_commands()) {
     switch (LC.C.cmd) {
     case MachO::LC_MAIN: {
@@ -228,7 +229,7 @@ Optional<uint64_t> readStartAddress(const MachOObjectFile &O) {
     }
   }
   return (TextVMAddr && StartOffset)
-             ? Optional<uint64_t>(*TextVMAddr + *StartOffset)
+             ? std::optional<uint64_t>(*TextVMAddr + *StartOffset)
              : std::nullopt;
 }
 
index cb931cc..aaf423e 100644 (file)
@@ -58,6 +58,7 @@
 #include <algorithm>
 #include <fstream>
 #include <memory>
+#include <optional>
 #include <system_error>
 
 #undef  DEBUG_TYPE
@@ -2790,9 +2791,10 @@ void RewriteInstance::selectFunctionsToProcess() {
     if (opts::Lite) {
       // Forcibly include functions specified in the -function-order file.
       if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
-        Optional<StringRef> Match = Function.forEachName([&](StringRef Name) {
-          return ReorderFunctionsUserSet.contains(Name);
-        });
+        std::optional<StringRef> Match =
+            Function.forEachName([&](StringRef Name) {
+              return ReorderFunctionsUserSet.contains(Name);
+            });
         if (Match.has_value())
           return true;
       }
@@ -4779,7 +4781,7 @@ void RewriteInstance::updateELFSymbolTable(
     assert(SymbolName && "cannot get symbol name");
 
     auto updateSymbolValue = [&](const StringRef Name,
-                                 Optional<uint64_t> Value = std::nullopt) {
+                                 std::optional<uint64_t> Value = std::nullopt) {
       NewSymbol.st_value = Value ? *Value : getNewValueForSymbol(Name);
       NewSymbol.st_shndx = ELF::SHN_ABS;
       outs() << "BOLT-INFO: setting " << Name << " to 0x"