[llvm-commits] [llvm] r110195 - in /llvm/trunk: include/llvm/Analysis/PointerTracking.h lib/Analysis/PointerTracking.cpp
Torok Edwin
edwintorok at gmail.com
Wed Aug 4 04:42:45 PDT 2010
Author: edwin
Date: Wed Aug 4 06:42:45 2010
New Revision: 110195
URL: http://llvm.org/viewvc/llvm-project?rev=110195&view=rev
Log:
Add a missing function.
Modified:
llvm/trunk/include/llvm/Analysis/PointerTracking.h
llvm/trunk/lib/Analysis/PointerTracking.cpp
Modified: llvm/trunk/include/llvm/Analysis/PointerTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PointerTracking.h?rev=110195&r1=110194&r2=110195&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/PointerTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/PointerTracking.h Wed Aug 4 06:42:45 2010
@@ -98,6 +98,7 @@
virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
void print(raw_ostream &OS, const Module* = 0) const;
+ Value *computeAllocationCountValue(Value *P, const Type *&Ty) const;
private:
Function *FF;
TargetData *TD;
Modified: llvm/trunk/lib/Analysis/PointerTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PointerTracking.cpp?rev=110195&r1=110194&r2=110195&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/PointerTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/PointerTracking.cpp Wed Aug 4 06:42:45 2010
@@ -144,6 +144,55 @@
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)
More information about the llvm-commits
mailing list