[C++11] More 'nullptr' conversion or in some cases just using a boolean check instead...
[oota-llvm.git] / include / llvm / IR / PassManager.h
index 07f20a3f31b967fb3655568a3527b4000c80605d..9575e12edb8eda1ed492fd91e0fefda02c0413a5 100644 (file)
@@ -71,8 +71,12 @@ public:
       : PreservedPassIDs(Arg.PreservedPassIDs) {}
   PreservedAnalyses(PreservedAnalyses &&Arg)
       : PreservedPassIDs(std::move(Arg.PreservedPassIDs)) {}
+  friend void swap(PreservedAnalyses &LHS, PreservedAnalyses &RHS) {
+    using std::swap;
+    swap(LHS.PreservedPassIDs, RHS.PreservedPassIDs);
+  }
   PreservedAnalyses &operator=(PreservedAnalyses RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -212,8 +216,12 @@ struct PassModel<IRUnitT, AnalysisManagerT, PassT, true>
   // refuses to generate them.
   PassModel(const PassModel &Arg) : Pass(Arg.Pass) {}
   PassModel(PassModel &&Arg) : Pass(std::move(Arg.Pass)) {}
+  friend void swap(PassModel &LHS, PassModel &RHS) {
+    using std::swap;
+    swap(LHS.Pass, RHS.Pass);
+  }
   PassModel &operator=(PassModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -234,8 +242,12 @@ struct PassModel<IRUnitT, AnalysisManagerT, PassT, false>
   // refuses to generate them.
   PassModel(const PassModel &Arg) : Pass(Arg.Pass) {}
   PassModel(PassModel &&Arg) : Pass(std::move(Arg.Pass)) {}
+  friend void swap(PassModel &LHS, PassModel &RHS) {
+    using std::swap;
+    swap(LHS.Pass, RHS.Pass);
+  }
   PassModel &operator=(PassModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -306,8 +318,12 @@ struct AnalysisResultModel<IRUnitT, PassT, ResultT, false>
   AnalysisResultModel(const AnalysisResultModel &Arg) : Result(Arg.Result) {}
   AnalysisResultModel(AnalysisResultModel &&Arg)
       : Result(std::move(Arg.Result)) {}
+  friend void swap(AnalysisResultModel &LHS, AnalysisResultModel &RHS) {
+    using std::swap;
+    swap(LHS.Result, RHS.Result);
+  }
   AnalysisResultModel &operator=(AnalysisResultModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -334,8 +350,12 @@ struct AnalysisResultModel<IRUnitT, PassT, ResultT, true>
   AnalysisResultModel(const AnalysisResultModel &Arg) : Result(Arg.Result) {}
   AnalysisResultModel(AnalysisResultModel &&Arg)
       : Result(std::move(Arg.Result)) {}
+  friend void swap(AnalysisResultModel &LHS, AnalysisResultModel &RHS) {
+    using std::swap;
+    swap(LHS.Result, RHS.Result);
+  }
   AnalysisResultModel &operator=(AnalysisResultModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -382,8 +402,12 @@ struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, true>
   // refuses to generate them.
   AnalysisPassModel(const AnalysisPassModel &Arg) : Pass(Arg.Pass) {}
   AnalysisPassModel(AnalysisPassModel &&Arg) : Pass(std::move(Arg.Pass)) {}
+  friend void swap(AnalysisPassModel &LHS, AnalysisPassModel &RHS) {
+    using std::swap;
+    swap(LHS.Pass, RHS.Pass);
+  }
   AnalysisPassModel &operator=(AnalysisPassModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -412,8 +436,12 @@ struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, false>
   // refuses to generate them.
   AnalysisPassModel(const AnalysisPassModel &Arg) : Pass(Arg.Pass) {}
   AnalysisPassModel(AnalysisPassModel &&Arg) : Pass(std::move(Arg.Pass)) {}
+  friend void swap(AnalysisPassModel &LHS, AnalysisPassModel &RHS) {
+    using std::swap;
+    swap(LHS.Pass, RHS.Pass);
+  }
   AnalysisPassModel &operator=(AnalysisPassModel RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
@@ -452,7 +480,7 @@ public:
   ///
   /// This method should only be called for a single module as there is the
   /// expectation that the lifetime of a pass is bounded to that of a module.
-  PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM = 0);
+  PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM = nullptr);
 
   template <typename ModulePassT> void addPass(ModulePassT Pass) {
     Passes.emplace_back(new ModulePassModel<ModulePassT>(std::move(Pass)));
@@ -496,7 +524,7 @@ public:
     Passes.emplace_back(new FunctionPassModel<FunctionPassT>(std::move(Pass)));
   }
 
-  PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = 0);
+  PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = nullptr);
 
   static StringRef name() { return "FunctionPassManager"; }
 
@@ -799,17 +827,17 @@ public:
   static void *ID() { return (void *)&PassID; }
 
   explicit FunctionAnalysisManagerModuleProxy(FunctionAnalysisManager &FAM)
-      : FAM(FAM) {}
+      : FAM(&FAM) {}
   // We have to explicitly define all the special member functions because MSVC
   // refuses to generate them.
   FunctionAnalysisManagerModuleProxy(
       const FunctionAnalysisManagerModuleProxy &Arg)
       : FAM(Arg.FAM) {}
   FunctionAnalysisManagerModuleProxy(FunctionAnalysisManagerModuleProxy &&Arg)
-      : FAM(Arg.FAM) {}
+      : FAM(std::move(Arg.FAM)) {}
   FunctionAnalysisManagerModuleProxy &
   operator=(FunctionAnalysisManagerModuleProxy RHS) {
-    std::swap(*this, RHS);
+    std::swap(FAM, RHS.FAM);
     return *this;
   }
 
@@ -827,7 +855,7 @@ public:
 private:
   static char PassID;
 
-  FunctionAnalysisManager &FAM;
+  FunctionAnalysisManager *FAM;
 };
 
 /// \brief The result proxy object for the
@@ -836,19 +864,19 @@ private:
 /// See its documentation for more information.
 class FunctionAnalysisManagerModuleProxy::Result {
 public:
-  explicit Result(FunctionAnalysisManager &FAM) : FAM(FAM) {}
+  explicit Result(FunctionAnalysisManager &FAM) : FAM(&FAM) {}
   // We have to explicitly define all the special member functions because MSVC
   // refuses to generate them.
   Result(const Result &Arg) : FAM(Arg.FAM) {}
-  Result(Result &&Arg) : FAM(Arg.FAM) {}
+  Result(Result &&Arg) : FAM(std::move(Arg.FAM)) {}
   Result &operator=(Result RHS) {
-    std::swap(*this, RHS);
+    std::swap(FAM, RHS.FAM);
     return *this;
   }
   ~Result();
 
   /// \brief Accessor for the \c FunctionAnalysisManager.
-  FunctionAnalysisManager &getManager() { return FAM; }
+  FunctionAnalysisManager &getManager() { return *FAM; }
 
   /// \brief Handler for invalidation of the module.
   ///
@@ -863,7 +891,7 @@ public:
   bool invalidate(Module *M, const PreservedAnalyses &PA);
 
 private:
-  FunctionAnalysisManager &FAM;
+  FunctionAnalysisManager *FAM;
 };
 
 /// \brief A function analysis which acts as a proxy for a module analysis
@@ -883,51 +911,51 @@ public:
   /// \brief Result proxy object for \c ModuleAnalysisManagerFunctionProxy.
   class Result {
   public:
-    explicit Result(const ModuleAnalysisManager &MAM) : MAM(MAM) {}
+    explicit Result(const ModuleAnalysisManager &MAM) : MAM(&MAM) {}
     // We have to explicitly define all the special member functions because
     // MSVC refuses to generate them.
     Result(const Result &Arg) : MAM(Arg.MAM) {}
-    Result(Result &&Arg) : MAM(Arg.MAM) {}
+    Result(Result &&Arg) : MAM(std::move(Arg.MAM)) {}
     Result &operator=(Result RHS) {
-      std::swap(*this, RHS);
+      std::swap(MAM, RHS.MAM);
       return *this;
     }
 
-    const ModuleAnalysisManager &getManager() const { return MAM; }
+    const ModuleAnalysisManager &getManager() const { return *MAM; }
 
     /// \brief Handle invalidation by ignoring it, this pass is immutable.
     bool invalidate(Function *) { return false; }
 
   private:
-    const ModuleAnalysisManager &MAM;
+    const ModuleAnalysisManager *MAM;
   };
 
   static void *ID() { return (void *)&PassID; }
 
   ModuleAnalysisManagerFunctionProxy(const ModuleAnalysisManager &MAM)
-      : MAM(MAM) {}
+      : MAM(&MAM) {}
   // We have to explicitly define all the special member functions because MSVC
   // refuses to generate them.
   ModuleAnalysisManagerFunctionProxy(
       const ModuleAnalysisManagerFunctionProxy &Arg)
       : MAM(Arg.MAM) {}
   ModuleAnalysisManagerFunctionProxy(ModuleAnalysisManagerFunctionProxy &&Arg)
-      : MAM(Arg.MAM) {}
+      : MAM(std::move(Arg.MAM)) {}
   ModuleAnalysisManagerFunctionProxy &
   operator=(ModuleAnalysisManagerFunctionProxy RHS) {
-    std::swap(*this, RHS);
+    std::swap(MAM, RHS.MAM);
     return *this;
   }
 
   /// \brief Run the analysis pass and create our proxy result object.
   /// Nothing to see here, it just forwards the \c MAM reference into the
   /// result.
-  Result run(Function *) { return Result(MAM); }
+  Result run(Function *) { return Result(*MAM); }
 
 private:
   static char PassID;
 
-  const ModuleAnalysisManager &MAM;
+  const ModuleAnalysisManager *MAM;
 };
 
 /// \brief Trivial adaptor that maps from a module to its functions.
@@ -948,14 +976,18 @@ public:
       : Pass(Arg.Pass) {}
   ModuleToFunctionPassAdaptor(ModuleToFunctionPassAdaptor &&Arg)
       : Pass(std::move(Arg.Pass)) {}
+  friend void swap(ModuleToFunctionPassAdaptor &LHS, ModuleToFunctionPassAdaptor &RHS) {
+    using std::swap;
+    swap(LHS.Pass, RHS.Pass);
+  }
   ModuleToFunctionPassAdaptor &operator=(ModuleToFunctionPassAdaptor RHS) {
-    std::swap(*this, RHS);
+    swap(*this, RHS);
     return *this;
   }
 
   /// \brief Runs the function pass across every function in the module.
   PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) {
-    FunctionAnalysisManager *FAM = 0;
+    FunctionAnalysisManager *FAM = nullptr;
     if (AM)
       // Setup the function analysis manager from its proxy.
       FAM = &AM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();