llvm.org GIT mirror llvm / e02f724
Fix PR3415 (infinite loop in EscapeAnalysis) by deleting the escape analysis pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63197 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 10 years ago
5 changed file(s) with 0 addition(s) and 220 deletion(s). Raw diff Collapse all Expand all
+0
-55
include/llvm/Analysis/EscapeAnalysis.h less more
None //===------------- EscapeAnalysis.h - Pointer escape analysis -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for the pointer escape analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_ANALYSIS_ESCAPEANALYSIS_H
14 #define LLVM_ANALYSIS_ESCAPEANALYSIS_H
15
16 #include "llvm/Pass.h"
17 #include
18
19 namespace llvm {
20
21 class Instruction;
22 class Value;
23
24 /// EscapeAnalysis - This class determines whether an allocation (a MallocInst
25 /// or an AllocaInst) can escape from the current function. It performs some
26 /// precomputation, with the rest of the work happening on-demand.
27 class EscapeAnalysis : public FunctionPass {
28 private:
29 std::set EscapePoints;
30
31 public:
32 static char ID; // Class identification, replacement for typeinfo
33
34 EscapeAnalysis() : FunctionPass(intptr_t(&ID)) {}
35
36 bool runOnFunction(Function &F);
37
38 void releaseMemory() {
39 EscapePoints.clear();
40 }
41
42 void getAnalysisUsage(AnalysisUsage &AU) const;
43
44 //===---------------------------------------------------------------------
45 // Client API
46
47 /// escapes - returns true if the value, which must have a pointer type,
48 /// can escape.
49 bool escapes(Value* A);
50 };
51
52 } // end llvm namespace
53
54 #endif
1515 #define LLVM_LINKALLPASSES_H
1616
1717 #include "llvm/Analysis/AliasSetTracker.h"
18 #include "llvm/Analysis/EscapeAnalysis.h"
1918 #include "llvm/Analysis/FindUsedTypes.h"
2019 #include "llvm/Analysis/IntervalPartition.h"
2120 #include "llvm/Analysis/LoopVR.h"
131130 (void)new llvm::FindUsedTypes();
132131 (void)new llvm::ScalarEvolution();
133132 (void)new llvm::LoopVR();
134 (void)new llvm::EscapeAnalysis();
135133 ((llvm::Function*)0)->viewCFGOnly();
136134 llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)0);
137135 X.add((llvm::Value*)0, 0); // for -print-alias-sets
1010 ConstantFolding.cpp
1111 DbgInfoPrinter.cpp
1212 DebugInfo.cpp
13 EscapeAnalysis.cpp
1413 InstCount.cpp
1514 Interval.cpp
1615 IntervalPartition.cpp
+0
-158
lib/Analysis/EscapeAnalysis.cpp less more
None //===------------- EscapeAnalysis.h - Pointer escape analysis -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the implementation of the pointer escape analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #define DEBUG_TYPE "escape-analysis"
14 #include "llvm/Analysis/EscapeAnalysis.h"
15 #include "llvm/Constants.h"
16 #include "llvm/Instructions.h"
17 #include "llvm/Module.h"
18 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/Support/InstIterator.h"
20 #include "llvm/Target/TargetData.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include
23 using namespace llvm;
24
25 char EscapeAnalysis::ID = 0;
26 static RegisterPass X("escape-analysis",
27 "Pointer Escape Analysis", true, true);
28
29
30 void EscapeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
31 AU.addRequiredTransitive();
32 AU.addRequiredTransitive();
33 AU.setPreservesAll();
34 }
35
36 /// runOnFunction - Precomputation for escape analysis. This collects all know
37 /// "escape points" in the def-use graph of the function. These are
38 /// instructions which allow their inputs to escape from the current function.
39 bool EscapeAnalysis::runOnFunction(Function& F) {
40 EscapePoints.clear();
41
42 TargetData& TD = getAnalysis();
43 AliasAnalysis& AA = getAnalysis();
44 Module* M = F.getParent();
45
46 // Walk through all instructions in the function, identifying those that
47 // may allow their inputs to escape.
48 for(inst_iterator II = inst_begin(F), IE = inst_end(F); II != IE; ++II) {
49 Instruction* I = &*II;
50
51 // The most obvious case is stores. Any store that may write to global
52 // memory or to a function argument potentially allows its input to escape.
53 if (StoreInst* S = dyn_cast(I)) {
54 const Type* StoreType = S->getOperand(0)->getType();
55 unsigned StoreSize = TD.getTypeStoreSize(StoreType);
56 Value* Pointer = S->getPointerOperand();
57
58 bool inserted = false;
59 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end();
60 AI != AE; ++AI) {
61 if (!isa(AI->getType())) continue;
62 AliasAnalysis::AliasResult R = AA.alias(Pointer, StoreSize, AI, ~0U);
63 if (R != AliasAnalysis::NoAlias) {
64 EscapePoints.insert(S);
65 inserted = true;
66 break;
67 }
68 }
69
70 if (inserted)
71 continue;
72
73 for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
74 GI != GE; ++GI) {
75 AliasAnalysis::AliasResult R = AA.alias(Pointer, StoreSize, GI, ~0U);
76 if (R != AliasAnalysis::NoAlias) {
77 EscapePoints.insert(S);
78 break;
79 }
80 }
81
82 // Calls and invokes potentially allow their parameters to escape.
83 // FIXME: This can and should be refined. Intrinsics have known escape
84 // behavior, and alias analysis may be able to tell us more about callees.
85 } else if (isa(I) || isa(I)) {
86 EscapePoints.insert(I);
87
88 // Returns allow the return value to escape. This is mostly important
89 // for malloc to alloca promotion.
90 } else if (isa(I)) {
91 EscapePoints.insert(I);
92
93 // Branching on the value of a pointer may allow the value to escape through
94 // methods not discoverable via def-use chaining.
95 } else if(isa(I) || isa(I)) {
96 EscapePoints.insert(I);
97 }
98
99 // FIXME: Are there any other possible escape points?
100 }
101
102 return false;
103 }
104
105 /// escapes - Determines whether the passed allocation can escape from the
106 /// current function. It does this by using a simple worklist algorithm to
107 /// search for a path in the def-use graph from the allocation to an
108 /// escape point.
109 /// FIXME: Once we've discovered a path, it would be a good idea to memoize it,
110 /// and all of its subpaths, to amortize the cost of future queries.
111 bool EscapeAnalysis::escapes(Value* A) {
112 assert(isa(A->getType()) &&
113 "Can't do escape analysis on non-pointer types!");
114
115 std::vector worklist;
116 worklist.push_back(A);
117
118 SmallPtrSet visited;
119 visited.insert(A);
120 while (!worklist.empty()) {
121 Value* curr = worklist.back();
122 worklist.pop_back();
123
124 if (Instruction* I = dyn_cast(curr))
125 if (EscapePoints.count(I)) {
126 BranchInst* B = dyn_cast(I);
127 if (!B) return true;
128 Value* condition = B->getCondition();
129 ICmpInst* C = dyn_cast(condition);
130 if (!C) return true;
131 Value* O1 = C->getOperand(0);
132 Value* O2 = C->getOperand(1);
133 if (isa(O1->stripPointerCasts())) {
134 if (!isa(O2)) return true;
135 } else if(isa(O2->stripPointerCasts())) {
136 if (!isa(O1)) return true;
137 } else
138 return true;
139 }
140
141 if (StoreInst* S = dyn_cast(curr)) {
142 // We know this must be an instruction, because constant gep's would
143 // have been found to alias a global, so stores to them would have
144 // been in EscapePoints.
145 if (visited.insert(cast(S->getPointerOperand())))
146 worklist.push_back(cast(S->getPointerOperand()));
147 } else {
148 for (Instruction::use_iterator UI = curr->use_begin(),
149 UE = curr->use_end(); UI != UE; ++UI)
150 if (Instruction* U = dyn_cast(UI))
151 if (visited.insert(U))
152 worklist.push_back(U);
153 }
154 }
155
156 return false;
157 }
345345
346346
347347 RelativePath="..\..\lib\Analysis\DebugInfo.cpp"
348 >
349
350
351 RelativePath="..\..\lib\Analysis\EscapeAnalysis.cpp"
352348 >
353349
354350