diff options
| author | Torok Edwin <edwintorok@gmail.com> | 2010-08-04 11:42:45 +0000 |
|---|---|---|
| committer | Torok Edwin <edwintorok@gmail.com> | 2010-08-04 11:42:45 +0000 |
| commit | bfc17d0157015447489cb2e5aff3c379b217e7cd (patch) | |
| tree | 6d793740c016b8faac6ef27c77c19b738256f8da /llvm/lib | |
| parent | 94ab4902601bd4a5144dbdb0516c35a421cb48e2 (diff) | |
| download | bcm5719-llvm-bfc17d0157015447489cb2e5aff3c379b217e7cd.tar.gz bcm5719-llvm-bfc17d0157015447489cb2e5aff3c379b217e7cd.zip | |
Add a missing function.
llvm-svn: 110195
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/PointerTracking.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/PointerTracking.cpp b/llvm/lib/Analysis/PointerTracking.cpp index 142066e42ba..03d3059fdbb 100644 --- a/llvm/lib/Analysis/PointerTracking.cpp +++ b/llvm/lib/Analysis/PointerTracking.cpp @@ -144,6 +144,55 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P, return SE->getCouldNotCompute(); } +Value *PointerTracking::computeAllocationCountValue(Value *P, const Type *&Ty) const +{ + Value *V = P->stripPointerCasts(); + if (AllocaInst *AI = dyn_cast<AllocaInst>(V)) { + Ty = AI->getAllocatedType(); + // arraySize elements of type Ty. + return AI->getArraySize(); + } + + if (CallInst *CI = extractMallocCall(V)) { + Ty = getMallocAllocatedType(CI); + if (!Ty) + return 0; + Value *arraySize = getMallocArraySize(CI, TD); + if (!arraySize) { + Ty = Type::getInt8Ty(P->getContext()); + return CI->getArgOperand(0); + } + // arraySize elements of type Ty. + return arraySize; + } + + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { + if (GV->hasDefinitiveInitializer()) { + Constant *C = GV->getInitializer(); + if (const ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { + Ty = ATy->getElementType(); + return ConstantInt::get(Type::getInt32Ty(P->getContext()), + ATy->getNumElements()); + } + } + Ty = cast<PointerType>(GV->getType())->getElementType(); + return ConstantInt::get(Type::getInt32Ty(P->getContext()), 1); + //TODO: implement more tracking for globals + } + + if (CallInst *CI = dyn_cast<CallInst>(V)) { + CallSite CS(CI); + Function *F = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts()); + if (F == reallocFunc) { + Ty = Type::getInt8Ty(P->getContext()); + // realloc allocates arg1 bytes. + return CS.getArgument(1); + } + } + + return 0; +} + // Calculates the number of elements of type Ty allocated for P. const SCEV *PointerTracking::computeAllocationCountForType(Value *P, const Type *Ty) |

