summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-10-26 23:43:48 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-10-26 23:43:48 +0000
commit046e78ce55a7c3d82b7b6758d2d77f2d99f970bf (patch)
tree1dad2445d3c6c08dc6d901e27806df980a7f855a /lib/Analysis
parentdda9583e5194c08ddd409f3e1c211e17acd6d5b8 (diff)
downloadllvm-046e78ce55a7c3d82b7b6758d2d77f2d99f970bf.tar.gz
llvm-046e78ce55a7c3d82b7b6758d2d77f2d99f970bf.tar.bz2
llvm-046e78ce55a7c3d82b7b6758d2d77f2d99f970bf.tar.xz
Remove FreeInst.
Remove LowerAllocations pass. Update some more passes to treate free calls just like they were treating FreeInst. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85176 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/AliasSetTracker.cpp33
-rw-r--r--lib/Analysis/CaptureTracking.cpp7
-rw-r--r--lib/Analysis/IPA/Andersens.cpp3
-rw-r--r--lib/Analysis/IPA/GlobalsModRef.cpp4
-rw-r--r--lib/Analysis/InlineCost.cpp4
-rw-r--r--lib/Analysis/InstCount.cpp4
-rw-r--r--lib/Analysis/MallocHelper.cpp9
-rw-r--r--lib/Analysis/MemoryDependenceAnalysis.cpp13
8 files changed, 36 insertions, 41 deletions
diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp
index 081f47854a..5b1b7d1814 100644
--- a/lib/Analysis/AliasSetTracker.cpp
+++ b/lib/Analysis/AliasSetTracker.cpp
@@ -13,6 +13,7 @@
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/MallocHelper.h"
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/Pass.h"
@@ -296,12 +297,6 @@ bool AliasSetTracker::add(StoreInst *SI) {
return NewPtr;
}
-bool AliasSetTracker::add(FreeInst *FI) {
- bool NewPtr;
- addPointer(FI->getOperand(0), ~0, AliasSet::Mods, NewPtr);
- return NewPtr;
-}
-
bool AliasSetTracker::add(VAArgInst *VAAI) {
bool NewPtr;
addPointer(VAAI->getOperand(0), ~0, AliasSet::ModRef, NewPtr);
@@ -310,6 +305,13 @@ bool AliasSetTracker::add(VAArgInst *VAAI) {
bool AliasSetTracker::add(CallSite CS) {
+ Instruction* Inst = CS.getInstruction();
+ if (isFreeCall(Inst)) {
+ bool NewPtr;
+ addPointer(Inst->getOperand(1), ~0, AliasSet::Mods, NewPtr);
+ return NewPtr;
+ }
+
if (isa<DbgInfoIntrinsic>(CS.getInstruction()))
return true; // Ignore DbgInfo Intrinsics.
if (AA.doesNotAccessMemory(CS))
@@ -337,8 +339,6 @@ bool AliasSetTracker::add(Instruction *I) {
return add(CI);
else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
return add(II);
- else if (FreeInst *FI = dyn_cast<FreeInst>(I))
- return add(FI);
else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return add(VAAI);
return true;
@@ -427,13 +427,6 @@ bool AliasSetTracker::remove(StoreInst *SI) {
return true;
}
-bool AliasSetTracker::remove(FreeInst *FI) {
- AliasSet *AS = findAliasSetForPointer(FI->getOperand(0), ~0);
- if (!AS) return false;
- remove(*AS);
- return true;
-}
-
bool AliasSetTracker::remove(VAArgInst *VAAI) {
AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0), ~0);
if (!AS) return false;
@@ -442,6 +435,14 @@ bool AliasSetTracker::remove(VAArgInst *VAAI) {
}
bool AliasSetTracker::remove(CallSite CS) {
+ Instruction* Inst = CS.getInstruction();
+ if (isFreeCall(Inst)) {
+ AliasSet *AS = findAliasSetForPointer(Inst->getOperand(1), ~0);
+ if (!AS) return false;
+ remove(*AS);
+ return true;
+ }
+
if (AA.doesNotAccessMemory(CS))
return false; // doesn't alias anything
@@ -459,8 +460,6 @@ bool AliasSetTracker::remove(Instruction *I) {
return remove(SI);
else if (CallInst *CI = dyn_cast<CallInst>(I))
return remove(CI);
- else if (FreeInst *FI = dyn_cast<FreeInst>(I))
- return remove(FI);
else if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
return remove(VAAI);
return true;
diff --git a/lib/Analysis/CaptureTracking.cpp b/lib/Analysis/CaptureTracking.cpp
index b30ac719ae..649b760b70 100644
--- a/lib/Analysis/CaptureTracking.cpp
+++ b/lib/Analysis/CaptureTracking.cpp
@@ -17,6 +17,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/CaptureTracking.h"
+#include "llvm/Analysis/MallocHelper.h"
#include "llvm/Instructions.h"
#include "llvm/Value.h"
#include "llvm/ADT/SmallSet.h"
@@ -48,6 +49,9 @@ bool llvm::PointerMayBeCaptured(const Value *V, bool ReturnCaptures) {
switch (I->getOpcode()) {
case Instruction::Call:
+ if (isFreeCall(I))
+ // Freeing a pointer does not cause it to be captured.
+ break;
case Instruction::Invoke: {
CallSite CS = CallSite::get(I);
// Not captured if the callee is readonly, doesn't return a copy through
@@ -73,9 +77,6 @@ bool llvm::PointerMayBeCaptured(const Value *V, bool ReturnCaptures) {
// captured.
break;
}
- case Instruction::Free:
- // Freeing a pointer does not cause it to be captured.
- break;
case Instruction::Load:
// Loading from a pointer does not cause it to be captured.
break;
diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp
index 637234251e..78ec06f21c 100644
--- a/lib/Analysis/IPA/Andersens.cpp
+++ b/lib/Analysis/IPA/Andersens.cpp
@@ -1016,7 +1016,7 @@ 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)) {
+ } else if (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
@@ -1156,7 +1156,6 @@ void Andersens::visitInstruction(Instruction &I) {
case Instruction::Switch:
case Instruction::Unwind:
case Instruction::Unreachable:
- case Instruction::Free:
case Instruction::ICmp:
case Instruction::FCmp:
return;
diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp
index 01090f11cb..011b0ef6e1 100644
--- a/lib/Analysis/IPA/GlobalsModRef.cpp
+++ b/lib/Analysis/IPA/GlobalsModRef.cpp
@@ -238,7 +238,7 @@ 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)) {
+ } else if (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
@@ -437,7 +437,7 @@ 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)) ||
isFreeCall(&cast<Instruction>(*II))) {
FunctionEffect |= ModRef;
}
diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp
index 4f010b658e..febdd9101c 100644
--- a/lib/Analysis/InlineCost.cpp
+++ b/lib/Analysis/InlineCost.cpp
@@ -130,10 +130,6 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
NumInsts += InlineConstants::CallPenalty;
}
- // These, too, are calls.
- if (isa<FreeInst>(II))
- NumInsts += InlineConstants::CallPenalty;
-
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (!AI->isStaticAlloca())
this->usesDynamicAlloca = true;
diff --git a/lib/Analysis/InstCount.cpp b/lib/Analysis/InstCount.cpp
index c4f3b68211..a4b041f02a 100644
--- a/lib/Analysis/InstCount.cpp
+++ b/lib/Analysis/InstCount.cpp
@@ -74,11 +74,11 @@ FunctionPass *llvm::createInstCountPass() { return new InstCount(); }
bool InstCount::runOnFunction(Function &F) {
unsigned StartMemInsts =
NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
- NumInvokeInst + NumAllocaInst + NumFreeInst;
+ NumInvokeInst + NumAllocaInst;
visit(F);
unsigned EndMemInsts =
NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
- NumInvokeInst + NumAllocaInst + NumFreeInst;
+ NumInvokeInst + NumAllocaInst;
TotalMemInst += EndMemInsts-StartMemInsts;
return false;
}
diff --git a/lib/Analysis/MallocHelper.cpp b/lib/Analysis/MallocHelper.cpp
index 511de9d6a5..70afa88ac6 100644
--- a/lib/Analysis/MallocHelper.cpp
+++ b/lib/Analysis/MallocHelper.cpp
@@ -1,4 +1,4 @@
-//===-- MallocHelper.cpp - Functions to identify malloc calls -------------===//
+//===-- MallocFreeHelper.cpp - Identify calls to malloc and free builtins -===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,7 +8,8 @@
//===----------------------------------------------------------------------===//
//
// This family of functions identifies calls to malloc, bitcasts of malloc
-// calls, and the types and array sizes associated with them.
+// calls, and the types and array sizes associated with them. It also
+// identifies calls to the free builtin.
//
//===----------------------------------------------------------------------===//
@@ -264,6 +265,10 @@ Value* llvm::getMallocArraySize(CallInst* CI, LLVMContext &Context,
return BO->getOperand(0);
}
+//===----------------------------------------------------------------------===//
+// free Call Utility Functions.
+//
+
/// 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);
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp
index ce7674003f..7b3fe64a4a 100644
--- a/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -113,10 +113,9 @@ getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
} else if (VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
Pointer = V->getOperand(0);
PointerSize = AA->getTypeStoreSize(V->getType());
- } else if (FreeInst *F = dyn_cast<FreeInst>(Inst)) {
- Pointer = F->getPointerOperand();
-
- // FreeInsts erase the entire structure
+ } else if (isFreeCall(Inst)) {
+ Pointer = Inst->getOperand(1);
+ // calls to free() erase the entire structure
PointerSize = ~0ULL;
} else if (isFreeCall(Inst)) {
Pointer = Inst->getOperand(0);
@@ -319,7 +318,7 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
MemSize = AA->getTypeStoreSize(LI->getType());
}
} else if (isFreeCall(QueryInst)) {
- MemPtr = QueryInst->getOperand(0);
+ MemPtr = QueryInst->getOperand(1);
// calls to free() erase the entire structure, not just a field.
MemSize = ~0UL;
} else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
@@ -327,10 +326,6 @@ MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
bool isReadOnly = AA->onlyReadsMemory(QueryCS);
LocalCache = getCallSiteDependencyFrom(QueryCS, isReadOnly, ScanPos,
QueryParent);
- } else if (FreeInst *FI = dyn_cast<FreeInst>(QueryInst)) {
- MemPtr = FI->getPointerOperand();
- // FreeInsts erase the entire structure, not just a field.
- MemSize = ~0UL;
} else {
// Non-memory instruction.
LocalCache = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos));