Make Escape Analysis work for any pointer.
authorOwen Anderson <resistor@mac.com>
Sun, 12 Oct 2008 07:33:29 +0000 (07:33 +0000)
committerOwen Anderson <resistor@mac.com>
Sun, 12 Oct 2008 07:33:29 +0000 (07:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57412 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/EscapeAnalysis.h
lib/Analysis/EscapeAnalysis.cpp

index 0befb31f4e72b4c5845379e6059693d223b6d60f..03012a828cb469a632b5d47f73f8279463305974 100644 (file)
@@ -50,8 +50,9 @@ public:
   //===---------------------------------------------------------------------
   // Client API
 
-  /// escapes - returns true if the AllocationInst can escape.
-  bool escapes(AllocationInst* A);
+  /// escapes - returns true if the value, which must have a pointer type,
+  /// can escape.
+  bool escapes(Value* A);
 };
 
 } // end llvm namespace
index 69dde4d7fdfcf125666c027cebe5a74599a80d99..43bad29fb7ddc81901c7fd2e12ed06086c02cea3 100644 (file)
@@ -98,18 +98,22 @@ bool EscapeAnalysis::runOnFunction(Function& F) {
 /// escape point.
 /// FIXME: Once we've discovered a path, it would be a good idea to memoize it,
 /// and all of its subpaths, to amortize the cost of future queries.
-bool EscapeAnalysis::escapes(AllocationInst* A) {
-  std::vector<Instruction*> worklist;
+bool EscapeAnalysis::escapes(Value* A) {
+  assert(isa<PointerType>(A->getType()) && 
+         "Can't do escape analysis on non-pointer types!");
+  
+  std::vector<Value*> worklist;
   worklist.push_back(A);
   
-  SmallPtrSet<Instruction*, 8> visited;
+  SmallPtrSet<Value*, 8> visited;
   visited.insert(A);
   while (!worklist.empty()) {
-    Instruction* curr = worklist.back();
+    Value* curr = worklist.back();
     worklist.pop_back();
     
-    if (EscapePoints.count(curr))
-      return true;
+    if (Instruction* I = dyn_cast<Instruction>(curr))
+      if (EscapePoints.count(I))
+        return true;
     
     if (StoreInst* S = dyn_cast<StoreInst>(curr)) {
       // We know this must be an instruction, because constant gep's would