AliasAnalysis.cpp (210299) | AliasAnalysis.cpp (212904) |
---|---|
1//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 51 unchanged lines hidden (view full) --- 60} 61 62void AliasAnalysis::copyValue(Value *From, Value *To) { 63 assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!"); 64 AA->copyValue(From, To); 65} 66 67AliasAnalysis::ModRefResult | 1//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 51 unchanged lines hidden (view full) --- 60} 61 62void AliasAnalysis::copyValue(Value *From, Value *To) { 63 assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!"); 64 AA->copyValue(From, To); 65} 66 67AliasAnalysis::ModRefResult |
68AliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { 69 // FIXME: we can do better. | 68AliasAnalysis::getModRefInfo(ImmutableCallSite CS, 69 const Value *P, unsigned Size) { 70 // Don't assert AA because BasicAA calls us in order to make use of the 71 // logic here. 72 73 ModRefBehavior MRB = getModRefBehavior(CS); 74 if (MRB == DoesNotAccessMemory) 75 return NoModRef; 76 77 ModRefResult Mask = ModRef; 78 if (MRB == OnlyReadsMemory) 79 Mask = Ref; 80 else if (MRB == AliasAnalysis::AccessesArguments) { 81 bool doesAlias = false; 82 for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); 83 AI != AE; ++AI) 84 if (!isNoAlias(*AI, ~0U, P, Size)) { 85 doesAlias = true; 86 break; 87 } 88 89 if (!doesAlias) 90 return NoModRef; 91 } 92 93 // If P points to a constant memory location, the call definitely could not 94 // modify the memory location. 95 if ((Mask & Mod) && pointsToConstantMemory(P)) 96 Mask = ModRefResult(Mask & ~Mod); 97 98 // If this is BasicAA, don't forward. 99 if (!AA) return Mask; 100 101 // Otherwise, fall back to the next AA in the chain. But we can merge 102 // in any mask we've managed to compute. 103 return ModRefResult(AA->getModRefInfo(CS, P, Size) & Mask); 104} 105 106AliasAnalysis::ModRefResult 107AliasAnalysis::getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) { 108 // Don't assert AA because BasicAA calls us in order to make use of the 109 // logic here. 110 111 // If CS1 or CS2 are readnone, they don't interact. 112 ModRefBehavior CS1B = getModRefBehavior(CS1); 113 if (CS1B == DoesNotAccessMemory) return NoModRef; 114 115 ModRefBehavior CS2B = getModRefBehavior(CS2); 116 if (CS2B == DoesNotAccessMemory) return NoModRef; 117 118 // If they both only read from memory, there is no dependence. 119 if (CS1B == OnlyReadsMemory && CS2B == OnlyReadsMemory) 120 return NoModRef; 121 122 AliasAnalysis::ModRefResult Mask = ModRef; 123 124 // If CS1 only reads memory, the only dependence on CS2 can be 125 // from CS1 reading memory written by CS2. 126 if (CS1B == OnlyReadsMemory) 127 Mask = ModRefResult(Mask & Ref); 128 129 // If CS2 only access memory through arguments, accumulate the mod/ref 130 // information from CS1's references to the memory referenced by 131 // CS2's arguments. 132 if (CS2B == AccessesArguments) { 133 AliasAnalysis::ModRefResult R = NoModRef; 134 for (ImmutableCallSite::arg_iterator 135 I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) { 136 R = ModRefResult((R | getModRefInfo(CS1, *I, UnknownSize)) & Mask); 137 if (R == Mask) 138 break; 139 } 140 return R; 141 } 142 143 // If CS1 only accesses memory through arguments, check if CS2 references 144 // any of the memory referenced by CS1's arguments. If not, return NoModRef. 145 if (CS1B == AccessesArguments) { 146 AliasAnalysis::ModRefResult R = NoModRef; 147 for (ImmutableCallSite::arg_iterator 148 I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) 149 if (getModRefInfo(CS2, *I, UnknownSize) != NoModRef) { 150 R = Mask; 151 break; 152 } 153 if (R == NoModRef) 154 return R; 155 } 156 157 // If this is BasicAA, don't forward. 158 if (!AA) return Mask; 159 160 // Otherwise, fall back to the next AA in the chain. But we can merge 161 // in any mask we've managed to compute. 162 return ModRefResult(AA->getModRefInfo(CS1, CS2) & Mask); 163} 164 165AliasAnalysis::ModRefBehavior 166AliasAnalysis::getModRefBehavior(ImmutableCallSite CS) { 167 // Don't assert AA because BasicAA calls us in order to make use of the 168 // logic here. 169 170 ModRefBehavior Min = UnknownModRefBehavior; 171 172 // Call back into the alias analysis with the other form of getModRefBehavior 173 // to see if it can give a better response. 174 if (const Function *F = CS.getCalledFunction()) 175 Min = getModRefBehavior(F); 176 177 // If this is BasicAA, don't forward. 178 if (!AA) return Min; 179 180 // Otherwise, fall back to the next AA in the chain. But we can merge 181 // in any result we've managed to compute. 182 return std::min(AA->getModRefBehavior(CS), Min); 183} 184 185AliasAnalysis::ModRefBehavior 186AliasAnalysis::getModRefBehavior(const Function *F) { |
70 assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!"); | 187 assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!"); |
71 return AA->getModRefInfo(CS1, CS2); | 188 return AA->getModRefBehavior(F); |
72} 73 74 75//===----------------------------------------------------------------------===// 76// AliasAnalysis non-virtual helper method implementation 77//===----------------------------------------------------------------------===// 78 79AliasAnalysis::ModRefResult | 189} 190 191 192//===----------------------------------------------------------------------===// 193// AliasAnalysis non-virtual helper method implementation 194//===----------------------------------------------------------------------===// 195 196AliasAnalysis::ModRefResult |
80AliasAnalysis::getModRefInfo(LoadInst *L, Value *P, unsigned Size) { 81 return alias(L->getOperand(0), getTypeStoreSize(L->getType()), 82 P, Size) ? Ref : NoModRef; | 197AliasAnalysis::getModRefInfo(const LoadInst *L, const Value *P, unsigned Size) { 198 // Be conservative in the face of volatile. 199 if (L->isVolatile()) 200 return ModRef; 201 202 // If the load address doesn't alias the given address, it doesn't read 203 // or write the specified memory. 204 if (!alias(L->getOperand(0), getTypeStoreSize(L->getType()), P, Size)) 205 return NoModRef; 206 207 // Otherwise, a load just reads. 208 return Ref; |
83} 84 85AliasAnalysis::ModRefResult | 209} 210 211AliasAnalysis::ModRefResult |
86AliasAnalysis::getModRefInfo(StoreInst *S, Value *P, unsigned Size) { 87 // If the stored address cannot alias the pointer in question, then the 88 // pointer cannot be modified by the store. | 212AliasAnalysis::getModRefInfo(const StoreInst *S, const Value *P, unsigned Size) { 213 // Be conservative in the face of volatile. 214 if (S->isVolatile()) 215 return ModRef; 216 217 // If the store address cannot alias the pointer in question, then the 218 // specified memory cannot be modified by the store. |
89 if (!alias(S->getOperand(1), 90 getTypeStoreSize(S->getOperand(0)->getType()), P, Size)) 91 return NoModRef; 92 93 // If the pointer is a pointer to constant memory, then it could not have been 94 // modified by this store. | 219 if (!alias(S->getOperand(1), 220 getTypeStoreSize(S->getOperand(0)->getType()), P, Size)) 221 return NoModRef; 222 223 // If the pointer is a pointer to constant memory, then it could not have been 224 // modified by this store. |
95 return pointsToConstantMemory(P) ? NoModRef : Mod; 96} | 225 if (pointsToConstantMemory(P)) 226 return NoModRef; |
97 | 227 |
98AliasAnalysis::ModRefBehavior 99AliasAnalysis::getModRefBehavior(CallSite CS, 100 std::vector<PointerAccessInfo> *Info) { 101 if (CS.doesNotAccessMemory()) 102 // Can't do better than this. 103 return DoesNotAccessMemory; 104 ModRefBehavior MRB = getModRefBehavior(CS.getCalledFunction(), Info); 105 if (MRB != DoesNotAccessMemory && CS.onlyReadsMemory()) 106 return OnlyReadsMemory; 107 return MRB; | 228 // Otherwise, a store just writes. 229 return Mod; |
108} 109 | 230} 231 |
110AliasAnalysis::ModRefBehavior 111AliasAnalysis::getModRefBehavior(Function *F, 112 std::vector<PointerAccessInfo> *Info) { 113 if (F) { 114 if (F->doesNotAccessMemory()) 115 // Can't do better than this. 116 return DoesNotAccessMemory; 117 if (F->onlyReadsMemory()) 118 return OnlyReadsMemory; 119 if (unsigned id = F->getIntrinsicID()) 120 return getModRefBehavior(id); 121 } 122 return UnknownModRefBehavior; 123} 124 125AliasAnalysis::ModRefBehavior AliasAnalysis::getModRefBehavior(unsigned iid) { 126#define GET_INTRINSIC_MODREF_BEHAVIOR 127#include "llvm/Intrinsics.gen" 128#undef GET_INTRINSIC_MODREF_BEHAVIOR 129} 130 | |
131AliasAnalysis::ModRefResult | 232AliasAnalysis::ModRefResult |
132AliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { 133 ModRefBehavior MRB = getModRefBehavior(CS); 134 if (MRB == DoesNotAccessMemory) | 233AliasAnalysis::getModRefInfo(const VAArgInst *V, const Value *P, unsigned Size) { 234 // If the va_arg address cannot alias the pointer in question, then the 235 // specified memory cannot be accessed by the va_arg. 236 if (!alias(V->getOperand(0), UnknownSize, P, Size)) |
135 return NoModRef; | 237 return NoModRef; |
136 137 ModRefResult Mask = ModRef; 138 if (MRB == OnlyReadsMemory) 139 Mask = Ref; 140 else if (MRB == AliasAnalysis::AccessesArguments) { 141 bool doesAlias = false; 142 for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); 143 AI != AE; ++AI) 144 if (!isNoAlias(*AI, ~0U, P, Size)) { 145 doesAlias = true; 146 break; 147 } | |
148 | 238 |
149 if (!doesAlias) 150 return NoModRef; 151 } | 239 // If the pointer is a pointer to constant memory, then it could not have been 240 // modified by this va_arg. 241 if (pointsToConstantMemory(P)) 242 return NoModRef; |
152 | 243 |
153 if (!AA) return Mask; | 244 // Otherwise, a va_arg reads and writes. 245 return ModRef; 246} |
154 | 247 |
155 // If P points to a constant memory location, the call definitely could not 156 // modify the memory location. 157 if ((Mask & Mod) && AA->pointsToConstantMemory(P)) 158 Mask = ModRefResult(Mask & ~Mod); | |
159 | 248 |
160 return ModRefResult(Mask & AA->getModRefInfo(CS, P, Size)); | 249AliasAnalysis::ModRefBehavior 250AliasAnalysis::getIntrinsicModRefBehavior(unsigned iid) { 251#define GET_INTRINSIC_MODREF_BEHAVIOR 252#include "llvm/Intrinsics.gen" 253#undef GET_INTRINSIC_MODREF_BEHAVIOR |
161} 162 163// AliasAnalysis destructor: DO NOT move this to the header file for 164// AliasAnalysis or else clients of the AliasAnalysis class may not depend on 165// the AliasAnalysis.o file in the current .a file, causing alias analysis 166// support to not be included in the tool correctly! 167// 168AliasAnalysis::~AliasAnalysis() {} --- 32 unchanged lines hidden (view full) --- 201/// instructions to consider are all of the instructions in the range of [I1,I2] 202/// INCLUSIVE. I1 and I2 must be in the same basic block. 203/// 204bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1, 205 const Instruction &I2, 206 const Value *Ptr, unsigned Size) { 207 assert(I1.getParent() == I2.getParent() && 208 "Instructions not in same basic block!"); | 254} 255 256// AliasAnalysis destructor: DO NOT move this to the header file for 257// AliasAnalysis or else clients of the AliasAnalysis class may not depend on 258// the AliasAnalysis.o file in the current .a file, causing alias analysis 259// support to not be included in the tool correctly! 260// 261AliasAnalysis::~AliasAnalysis() {} --- 32 unchanged lines hidden (view full) --- 294/// instructions to consider are all of the instructions in the range of [I1,I2] 295/// INCLUSIVE. I1 and I2 must be in the same basic block. 296/// 297bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1, 298 const Instruction &I2, 299 const Value *Ptr, unsigned Size) { 300 assert(I1.getParent() == I2.getParent() && 301 "Instructions not in same basic block!"); |
209 BasicBlock::iterator I = const_cast<Instruction*>(&I1); 210 BasicBlock::iterator E = const_cast<Instruction*>(&I2); | 302 BasicBlock::const_iterator I = &I1; 303 BasicBlock::const_iterator E = &I2; |
211 ++E; // Convert from inclusive to exclusive range. 212 213 for (; I != E; ++I) // Check every instruction in range | 304 ++E; // Convert from inclusive to exclusive range. 305 306 for (; I != E; ++I) // Check every instruction in range |
214 if (getModRefInfo(I, const_cast<Value*>(Ptr), Size) & Mod) | 307 if (getModRefInfo(I, Ptr, Size) & Mod) |
215 return true; 216 return false; 217} 218 219/// isNoAliasCall - Return true if this pointer is returned by a noalias 220/// function. 221bool llvm::isNoAliasCall(const Value *V) { 222 if (isa<CallInst>(V) || isa<InvokeInst>(V)) | 308 return true; 309 return false; 310} 311 312/// isNoAliasCall - Return true if this pointer is returned by a noalias 313/// function. 314bool llvm::isNoAliasCall(const Value *V) { 315 if (isa<CallInst>(V) || isa<InvokeInst>(V)) |
223 return CallSite(const_cast<Instruction*>(cast<Instruction>(V))) | 316 return ImmutableCallSite(cast<Instruction>(V)) |
224 .paramHasAttr(0, Attribute::NoAlias); 225 return false; 226} 227 228/// isIdentifiedObject - Return true if this pointer refers to a distinct and 229/// identifiable object. This returns true for: 230/// Global Variables and Functions (but not Global Aliases) 231/// Allocas and Mallocs --- 20 unchanged lines hidden --- | 317 .paramHasAttr(0, Attribute::NoAlias); 318 return false; 319} 320 321/// isIdentifiedObject - Return true if this pointer refers to a distinct and 322/// identifiable object. This returns true for: 323/// Global Variables and Functions (but not Global Aliases) 324/// Allocas and Mallocs --- 20 unchanged lines hidden --- |