summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-10-24 04:23:03 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-10-24 04:23:03 +0000
commite297149e267e05159db4dc490493fddcb3784d95 (patch)
tree4f49152e0dfd1305070ba4ab33c516f5fe31ebab /llvm/lib/Analysis
parent46ed1f83414d1e93e5af6a8145526c0d216861c1 (diff)
downloadbcm5719-llvm-e297149e267e05159db4dc490493fddcb3784d95.tar.gz
bcm5719-llvm-e297149e267e05159db4dc490493fddcb3784d95.zip
Auto-upgrade free instructions to calls to the builtin free function.
Update all analysis passes and transforms to treat free calls just like FreeInst. Remove RaiseAllocations and all its tests since FreeInst no longer needs to be raised. llvm-svn: 84987
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/IPA/Andersens.cpp4
-rw-r--r--llvm/lib/Analysis/IPA/GlobalsModRef.cpp7
-rw-r--r--llvm/lib/Analysis/MallocHelper.cpp26
-rw-r--r--llvm/lib/Analysis/MemoryDependenceAnalysis.cpp8
4 files changed, 40 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/IPA/Andersens.cpp b/llvm/lib/Analysis/IPA/Andersens.cpp
index b5129a7d3ba..e37a9dbb7ac 100644
--- a/llvm/lib/Analysis/IPA/Andersens.cpp
+++ b/llvm/lib/Analysis/IPA/Andersens.cpp
@@ -1017,6 +1017,8 @@ bool Andersens::AnalyzeUsesOfFunction(Value *V) {
}
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(*UI)) {
if (AnalyzeUsesOfFunction(GEP)) return true;
+ } else if (isa<FreeInst>(*UI) || isFreeCall(*UI)) {
+ return false;
} else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
// Make sure that this is just the function being called, not that it is
// passing into the function.
@@ -1038,8 +1040,6 @@ bool Andersens::AnalyzeUsesOfFunction(Value *V) {
} else if (ICmpInst *ICI = dyn_cast<ICmpInst>(*UI)) {
if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
return true; // Allow comparison against null.
- } else if (isa<FreeInst>(*UI)) {
- return false;
} else {
return true;
}
diff --git a/llvm/lib/Analysis/IPA/GlobalsModRef.cpp b/llvm/lib/Analysis/IPA/GlobalsModRef.cpp
index 7949288340a..d83ea48080c 100644
--- a/llvm/lib/Analysis/IPA/GlobalsModRef.cpp
+++ b/llvm/lib/Analysis/IPA/GlobalsModRef.cpp
@@ -240,6 +240,8 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V,
} else if (BitCastInst *BCI = dyn_cast<BitCastInst>(*UI)) {
if (AnalyzeUsesOfPointer(BCI, Readers, Writers, OkayStoreDest))
return true;
+ } else if (isa<FreeInst>(*UI) || isFreeCall(*UI)) {
+ Writers.push_back(cast<Instruction>(*UI)->getParent()->getParent());
} else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
// Make sure that this is just the function being called, not that it is
// passing into the function.
@@ -261,8 +263,6 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V,
} else if (ICmpInst *ICI = dyn_cast<ICmpInst>(*UI)) {
if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
return true; // Allow comparison against null.
- } else if (FreeInst *F = dyn_cast<FreeInst>(*UI)) {
- Writers.push_back(F->getParent()->getParent());
} else {
return true;
}
@@ -439,7 +439,8 @@ void GlobalsModRef::AnalyzeCallGraph(CallGraph &CG, Module &M) {
if (cast<StoreInst>(*II).isVolatile())
// Treat volatile stores as reading memory somewhere.
FunctionEffect |= Ref;
- } else if (isMalloc(&cast<Instruction>(*II)) || isa<FreeInst>(*II)) {
+ } else if (isMalloc(&cast<Instruction>(*II)) || isa<FreeInst>(*II) ||
+ isFreeCall(&cast<Instruction>(*II))) {
FunctionEffect |= ModRef;
}
diff --git a/llvm/lib/Analysis/MallocHelper.cpp b/llvm/lib/Analysis/MallocHelper.cpp
index e7bb41eeec2..511de9d6a51 100644
--- a/llvm/lib/Analysis/MallocHelper.cpp
+++ b/llvm/lib/Analysis/MallocHelper.cpp
@@ -263,3 +263,29 @@ Value* llvm::getMallocArraySize(CallInst* CI, LLVMContext &Context,
assert(BO && "getMallocArraySize not constant but not multiplication either");
return BO->getOperand(0);
}
+
+/// isFreeCall - Returns true if the the value is a call to the builtin free()
+bool llvm::isFreeCall(const Value* I) {
+ const CallInst *CI = dyn_cast<CallInst>(I);
+ if (!CI)
+ return false;
+
+ const Module* M = CI->getParent()->getParent()->getParent();
+ Function *FreeFunc = M->getFunction("free");
+
+ if (CI->getOperand(0) != FreeFunc)
+ return false;
+
+ // Check free prototype.
+ // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
+ // attribute will exist.
+ const FunctionType *FTy = FreeFunc->getFunctionType();
+ if (FTy->getReturnType() != Type::getVoidTy(M->getContext()))
+ return false;
+ if (FTy->getNumParams() != 1)
+ return false;
+ if (FTy->param_begin()->get() != Type::getInt8PtrTy(M->getContext()))
+ return false;
+
+ return true;
+}
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index c3aa5bc9306..ce7674003fe 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -118,6 +118,10 @@ getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
// FreeInsts erase the entire structure
PointerSize = ~0ULL;
+ } else if (isFreeCall(Inst)) {
+ Pointer = Inst->getOperand(0);
+ // calls to free() erase the entire structure
+ PointerSize = ~0ULL;
} else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
// Debug intrinsics don't cause dependences.
if (isa<DbgInfoIntrinsic>(Inst)) continue;
@@ -314,6 +318,10 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
MemPtr = LI->getPointerOperand();
MemSize = AA->getTypeStoreSize(LI->getType());
}
+ } else if (isFreeCall(QueryInst)) {
+ MemPtr = QueryInst->getOperand(0);
+ // calls to free() erase the entire structure, not just a field.
+ MemSize = ~0UL;
} else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
CallSite QueryCS = CallSite::get(QueryInst);
bool isReadOnly = AA->onlyReadsMemory(QueryCS);
OpenPOWER on IntegriCloud