[PM/AA] Extract the ModRef enums from the AliasAnalysis class in
[oota-llvm.git] / lib / Analysis / IPA / GlobalsModRef.cpp
index 3e4b00e6e507bed601d0b001e49020f01c41dd92..1accb4647e7fc4a14c3f6621670a3f9907170f42 100644 (file)
@@ -71,7 +71,7 @@ struct FunctionRecord {
   bool MayReadAnyGlobal;
 
   unsigned getInfoForGlobal(const GlobalValue *GV) const {
-    unsigned Effect = MayReadAnyGlobal ? AliasAnalysis::Ref : 0;
+    unsigned Effect = MayReadAnyGlobal ? MRI_Ref : 0;
     std::map<const GlobalValue *, unsigned>::const_iterator I =
         GlobalInfo.find(GV);
     if (I != GlobalInfo.end())
@@ -168,59 +168,59 @@ public:
     AU.setPreservesAll(); // Does not transform code
   }
 
+  /// getAdjustedAnalysisPointer - This method is used when a pass implements
+  /// an analysis interface through multiple inheritance.  If needed, it
+  /// should override this to adjust the this pointer as needed for the
+  /// specified pass info.
+  void *getAdjustedAnalysisPointer(AnalysisID PI) override {
+    if (PI == &AliasAnalysis::ID)
+      return (AliasAnalysis *)this;
+    return this;
+  }
+
   //------------------------------------------------
   // Implement the AliasAnalysis API
   //
   AliasResult alias(const MemoryLocation &LocA,
                     const MemoryLocation &LocB) override;
-  ModRefResult getModRefInfo(ImmutableCallSite CS,
-                             const MemoryLocation &Loc) override;
-  ModRefResult getModRefInfo(ImmutableCallSite CS1,
-                             ImmutableCallSite CS2) override {
+  ModRefInfo getModRefInfo(ImmutableCallSite CS,
+                           const MemoryLocation &Loc) override;
+  ModRefInfo getModRefInfo(ImmutableCallSite CS1,
+                           ImmutableCallSite CS2) override {
     return AliasAnalysis::getModRefInfo(CS1, CS2);
   }
 
   /// getModRefBehavior - Return the behavior of the specified function if
   /// called from the specified call site.  The call site may be null in which
   /// case the most generic behavior of this function should be returned.
-  ModRefBehavior getModRefBehavior(const Function *F) override {
-    ModRefBehavior Min = UnknownModRefBehavior;
+  FunctionModRefBehavior getModRefBehavior(const Function *F) override {
+    FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
 
     if (FunctionRecord *FR = getFunctionInfo(F)) {
       if (FR->FunctionEffect == 0)
-        Min = DoesNotAccessMemory;
-      else if ((FR->FunctionEffect & Mod) == 0)
-        Min = OnlyReadsMemory;
+        Min = FMRB_DoesNotAccessMemory;
+      else if ((FR->FunctionEffect & MRI_Mod) == 0)
+        Min = FMRB_OnlyReadsMemory;
     }
 
-    return ModRefBehavior(AliasAnalysis::getModRefBehavior(F) & Min);
+    return FunctionModRefBehavior(AliasAnalysis::getModRefBehavior(F) & Min);
   }
 
   /// getModRefBehavior - Return the behavior of the specified function if
   /// called from the specified call site.  The call site may be null in which
   /// case the most generic behavior of this function should be returned.
-  ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
-    ModRefBehavior Min = UnknownModRefBehavior;
+  FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
+    FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
 
     if (const Function *F = CS.getCalledFunction())
       if (FunctionRecord *FR = getFunctionInfo(F)) {
         if (FR->FunctionEffect == 0)
-          Min = DoesNotAccessMemory;
-        else if ((FR->FunctionEffect & Mod) == 0)
-          Min = OnlyReadsMemory;
+          Min = FMRB_DoesNotAccessMemory;
+        else if ((FR->FunctionEffect & MRI_Mod) == 0)
+          Min = FMRB_OnlyReadsMemory;
       }
 
-    return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
-  }
-
-  /// getAdjustedAnalysisPointer - This method is used when a pass implements
-  /// an analysis interface through multiple inheritance.  If needed, it
-  /// should override this to adjust the this pointer as needed for the
-  /// specified pass info.
-  void *getAdjustedAnalysisPointer(AnalysisID PI) override {
-    if (PI == &AliasAnalysis::ID)
-      return (AliasAnalysis *)this;
-    return this;
+    return FunctionModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
   }
 
 private:
@@ -280,11 +280,11 @@ void GlobalsModRef::AnalyzeGlobals(Module &M) {
         Handles.front().I = Handles.begin();
 
         for (Function *Reader : Readers)
-          FunctionInfo[Reader].GlobalInfo[&GV] |= Ref;
+          FunctionInfo[Reader].GlobalInfo[&GV] |= MRI_Ref;
 
         if (!GV.isConstant()) // No need to keep track of writers to constants
           for (Function *Writer : Writers)
-            FunctionInfo[Writer].GlobalInfo[&GV] |= Mod;
+            FunctionInfo[Writer].GlobalInfo[&GV] |= MRI_Mod;
         ++NumNonAddrTakenGlobalVars;
 
         // If this global holds a pointer type, see if it is an indirect global.
@@ -455,13 +455,13 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
         if (F->doesNotAccessMemory()) {
           // Can't do better than that!
         } else if (F->onlyReadsMemory()) {
-          FunctionEffect |= Ref;
+          FunctionEffect |= MRI_Ref;
           if (!F->isIntrinsic())
             // This function might call back into the module and read a global -
             // consider every global as possibly being read by this function.
             FR.MayReadAnyGlobal = true;
         } else {
-          FunctionEffect |= ModRef;
+          FunctionEffect |= MRI_ModRef;
           // Can't say anything useful unless it's an intrinsic - they don't
           // read or write global variables of the kind considered here.
           KnowNothing = !F->isIntrinsic();
@@ -502,10 +502,10 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
 
     // Scan the function bodies for explicit loads or stores.
     for (auto *Node : SCC) {
-      if (FunctionEffect == ModRef)
+      if (FunctionEffect == MRI_ModRef)
         break; // The mod/ref lattice saturates here.
       for (Instruction &I : inst_range(Node->getFunction())) {
-        if (FunctionEffect == ModRef)
+        if (FunctionEffect == MRI_ModRef)
           break; // The mod/ref lattice saturates here.
 
         // We handle calls specially because the graph-relevant aspects are
@@ -514,13 +514,13 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
           if (isAllocationFn(&I, TLI) || isFreeCall(&I, TLI)) {
             // FIXME: It is completely unclear why this is necessary and not
             // handled by the above graph code.
-            FunctionEffect |= ModRef;
+            FunctionEffect |= MRI_ModRef;
           } else if (Function *Callee = CS.getCalledFunction()) {
             // The callgraph doesn't include intrinsic calls.
             if (Callee->isIntrinsic()) {
-              ModRefBehavior Behaviour =
+              FunctionModRefBehavior Behaviour =
                   AliasAnalysis::getModRefBehavior(Callee);
-              FunctionEffect |= (Behaviour & ModRef);
+              FunctionEffect |= (Behaviour & MRI_ModRef);
             }
           }
           continue;
@@ -529,13 +529,13 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
         // All non-call instructions we use the primary predicates for whether
         // thay read or write memory.
         if (I.mayReadFromMemory())
-          FunctionEffect |= Ref;
+          FunctionEffect |= MRI_Ref;
         if (I.mayWriteToMemory())
-          FunctionEffect |= Mod;
+          FunctionEffect |= MRI_Mod;
       }
     }
 
-    if ((FunctionEffect & Mod) == 0)
+    if ((FunctionEffect & MRI_Mod) == 0)
       ++NumReadMemFunctions;
     if (FunctionEffect == 0)
       ++NumNoMemFunctions;
@@ -621,9 +621,9 @@ AliasResult GlobalsModRef::alias(const MemoryLocation &LocA,
   return AliasAnalysis::alias(LocA, LocB);
 }
 
-AliasAnalysis::ModRefResult
-GlobalsModRef::getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc) {
-  unsigned Known = ModRef;
+ModRefInfo GlobalsModRef::getModRefInfo(ImmutableCallSite CS,
+                                        const MemoryLocation &Loc) {
+  unsigned Known = MRI_ModRef;
 
   // If we are asking for mod/ref info of a direct call with a pointer to a
   // global we are tracking, return information if we have it.
@@ -636,7 +636,7 @@ GlobalsModRef::getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc) {
           if (const FunctionRecord *FR = getFunctionInfo(F))
             Known = FR->getInfoForGlobal(GV);
 
-  if (Known == NoModRef)
-    return NoModRef; // No need to query other mod/ref analyses
-  return ModRefResult(Known & AliasAnalysis::getModRefInfo(CS, Loc));
+  if (Known == MRI_NoModRef)
+    return MRI_NoModRef; // No need to query other mod/ref analyses
+  return ModRefInfo(Known & AliasAnalysis::getModRefInfo(CS, Loc));
 }