[llvm] r274957 - [CFLAA] Simplify CFLGraphBuilder. NFC.

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 19:48:56 PDT 2016


Author: gbiv
Date: Fri Jul  8 21:48:56 2016
New Revision: 274957

URL: http://llvm.org/viewvc/llvm-project?rev=274957&view=rev
Log:
[CFLAA] Simplify CFLGraphBuilder. NFC.

This removes a few fields from the graph builder by making us compute
things (that we'd always compute anyway) more eagerly.

Patch by Jia Chen.

Differential Revision: http://reviews.llvm.org/D22009

Modified:
    llvm/trunk/lib/Analysis/CFLSteensAliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/CFLSteensAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFLSteensAliasAnalysis.cpp?rev=274957&r1=274956&r2=274957&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFLSteensAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/CFLSteensAliasAnalysis.cpp Fri Jul  8 21:48:56 2016
@@ -118,8 +118,6 @@ class GetEdgesVisitor : public InstVisit
 
   CFLGraph &Graph;
   SmallVectorImpl<Value *> &ReturnValues;
-  SmallPtrSetImpl<Value *> &Externals;
-  SmallPtrSetImpl<Value *> &Escapes;
   SmallVectorImpl<InstantiatedRelation> &InstantiatedRelations;
   SmallVectorImpl<InstantiatedAttr> &InstantiatedAttrs;
 
@@ -131,12 +129,16 @@ class GetEdgesVisitor : public InstVisit
   }
 
   void addNode(Value *Val) {
+    assert(Val != nullptr);
     if (!Graph.addNode(Val))
       return;
 
-    if (isa<GlobalValue>(Val))
-      Externals.insert(Val);
-    else if (auto CExpr = dyn_cast<ConstantExpr>(Val))
+    if (isa<GlobalValue>(Val)) {
+      Graph.addAttr(Val, getGlobalOrArgAttrFromValue(*Val));
+      // Currently we do not attempt to be smart on globals
+      InstantiatedAttrs.push_back(
+          InstantiatedAttr{InstantiatedValue{Val, 1}, getAttrUnknown()});
+    } else if (auto CExpr = dyn_cast<ConstantExpr>(Val))
       if (hasUsefulEdges(CExpr))
         visitConstantExpr(CExpr);
   }
@@ -147,6 +149,7 @@ class GetEdgesVisitor : public InstVisit
   }
 
   void addEdge(Value *From, Value *To, EdgeType Type) {
+    assert(From != nullptr && To != nullptr);
     if (!From->getType()->isPointerTy() || !To->getType()->isPointerTy())
       return;
     addNode(From);
@@ -158,12 +161,9 @@ class GetEdgesVisitor : public InstVisit
 public:
   GetEdgesVisitor(CFLSteensAAResult &AA, const TargetLibraryInfo &TLI,
                   CFLGraph &Graph, SmallVectorImpl<Value *> &ReturnValues,
-                  SmallPtrSetImpl<Value *> &Externals,
-                  SmallPtrSetImpl<Value *> &Escapes,
                   SmallVectorImpl<InstantiatedRelation> &InstantiatedRelations,
                   SmallVectorImpl<InstantiatedAttr> &InstantiatedAttrs)
       : AA(AA), TLI(TLI), Graph(Graph), ReturnValues(ReturnValues),
-        Externals(Externals), Escapes(Escapes),
         InstantiatedRelations(InstantiatedRelations),
         InstantiatedAttrs(InstantiatedAttrs) {}
 
@@ -334,13 +334,22 @@ public:
     // anything, too (unless the result is marked noalias).
     if (!CS.onlyReadsMemory())
       for (Value *V : CS.args()) {
-        if (V->getType()->isPointerTy())
-          Escapes.insert(V);
+        if (V->getType()->isPointerTy()) {
+          // The argument itself escapes.
+          addNodeWithAttr(V, getAttrEscaped());
+          // The fate of argument memory is unknown. Note that since AliasAttrs
+          // is transitive with respect to dereference, we only need to specify
+          // it for the first-level memory.
+          InstantiatedAttrs.push_back(
+              InstantiatedAttr{InstantiatedValue{V, 1}, getAttrUnknown()});
+        }
       }
 
     if (Inst->getType()->isPointerTy()) {
       auto *Fn = CS.getCalledFunction();
       if (Fn == nullptr || !Fn->doesNotAlias(0))
+        // No need to call addNodeWithAttr() since we've added Inst at the
+        // beginning of this function and we know it is not a global.
         Graph.addAttr(Inst, getAttrUnknown());
     }
   }
@@ -412,8 +421,6 @@ class CFLGraphBuilder {
   SmallVector<Value *, 4> ReturnedValues;
 
   // Auxiliary structures used by the builder
-  SmallPtrSet<Value *, 8> ExternalValues;
-  SmallPtrSet<Value *, 8> EscapedValues;
   SmallVector<InstantiatedRelation, 8> InstantiatedRelations;
   SmallVector<InstantiatedAttr, 8> InstantiatedAttrs;
 
@@ -432,7 +439,10 @@ class CFLGraphBuilder {
   void addArgumentToGraph(Argument &Arg) {
     if (Arg.getType()->isPointerTy()) {
       Graph.addNode(&Arg);
-      ExternalValues.insert(&Arg);
+      Graph.addAttr(&Arg, getGlobalOrArgAttrFromValue(Arg));
+      // Pointees of a formal parameter is known to the caller
+      InstantiatedAttrs.push_back(
+          InstantiatedAttr{InstantiatedValue{&Arg, 1}, getAttrCaller()});
     }
   }
 
@@ -446,8 +456,8 @@ class CFLGraphBuilder {
     if (!hasUsefulEdges(&Inst))
       return;
 
-    GetEdgesVisitor(Analysis, TLI, Graph, ReturnedValues, ExternalValues,
-                    EscapedValues, InstantiatedRelations, InstantiatedAttrs)
+    GetEdgesVisitor(Analysis, TLI, Graph, ReturnedValues, InstantiatedRelations,
+                    InstantiatedAttrs)
         .visit(Inst);
   }
 
@@ -473,12 +483,6 @@ public:
   const SmallVector<Value *, 4> &getReturnValues() const {
     return ReturnedValues;
   }
-  const SmallPtrSet<Value *, 8> &getExternalValues() const {
-    return ExternalValues;
-  }
-  const SmallPtrSet<Value *, 8> &getEscapedValues() const {
-    return EscapedValues;
-  }
   const SmallVector<InstantiatedRelation, 8> &getInstantiatedRelations() const {
     return InstantiatedRelations;
   }
@@ -666,19 +670,6 @@ CFLSteensAAResult::FunctionInfo CFLSteen
     }
   }
 
-  // Special handling for globals and arguments
-  for (auto *External : GraphBuilder.getExternalValues()) {
-    SetBuilder.add(External);
-    auto Attr = getGlobalOrArgAttrFromValue(*External);
-    if (Attr.any()) {
-      SetBuilder.noteAttributes(External, Attr);
-      if (isa<GlobalValue>(External))
-        SetBuilder.addAttributesBelow(External, 1, getAttrUnknown());
-      else
-        SetBuilder.addAttributesBelow(External, 1, getAttrCaller());
-    }
-  }
-
   // Special handling for interprocedural aliases
   for (auto &Edge : GraphBuilder.getInstantiatedRelations()) {
     auto FromVal = Edge.From.Val;
@@ -696,13 +687,6 @@ CFLSteensAAResult::FunctionInfo CFLSteen
     SetBuilder.addAttributesBelow(Val, IPAttr.IValue.DerefLevel, IPAttr.Attr);
   }
 
-  // Special handling for opaque external functions
-  for (auto *Escape : GraphBuilder.getEscapedValues()) {
-    SetBuilder.add(Escape);
-    SetBuilder.noteAttributes(Escape, getAttrEscaped());
-    SetBuilder.addAttributesBelow(Escape, 1, getAttrUnknown());
-  }
-
   return FunctionInfo(*Fn, GraphBuilder.getReturnValues(), SetBuilder.build());
 }
 




More information about the llvm-commits mailing list