diff options
author | Victor Hernandez <vhernandez@apple.com> | 2009-10-26 23:43:48 +0000 |
---|---|---|
committer | Victor Hernandez <vhernandez@apple.com> | 2009-10-26 23:43:48 +0000 |
commit | de5ad42aa16287671b8e39173f8e0d39b8f35a73 (patch) | |
tree | 4b5bb9c47e42d2dc31877f0a8d5786927266b0c2 /llvm/lib/Transforms/Scalar | |
parent | 7a484dd6a9a900c1c25794a0d555e40e417f693b (diff) | |
download | bcm5719-llvm-de5ad42aa16287671b8e39173f8e0d39b8f35a73.tar.gz bcm5719-llvm-de5ad42aa16287671b8e39173f8e0d39b8f35a73.zip |
Remove FreeInst.
Remove LowerAllocations pass.
Update some more passes to treate free calls just like they were treating FreeInst.
llvm-svn: 85176
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 57 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 1 |
3 files changed, 5 insertions, 60 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index f55d8b2accb..c10d236cda6 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -89,7 +89,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { Instruction *Inst = BBI++; // If we find a store or a free, get its memory dependence. - if (!isa<StoreInst>(Inst) && !isa<FreeInst>(Inst) && !isFreeCall(Inst)) + if (!isa<StoreInst>(Inst) && !isFreeCall(Inst)) continue; // Don't molest volatile stores or do queries that will return "clobber". @@ -104,7 +104,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { if (InstDep.isNonLocal()) continue; // Handle frees whose dependencies are non-trivial. - if (isa<FreeInst>(Inst) || isFreeCall(Inst)) { + if (isFreeCall(Inst)) { MadeChange |= handleFreeWithNonTrivialDependency(Inst, InstDep); continue; } @@ -176,8 +176,7 @@ bool DSE::handleFreeWithNonTrivialDependency(Instruction *F, MemDepResult Dep) { Value *DepPointer = Dependency->getPointerOperand()->getUnderlyingObject(); // Check for aliasing. - Value* FreeVal = isa<FreeInst>(F) ? F->getOperand(0) : F->getOperand(1); - if (AA.alias(FreeVal, 1, DepPointer, 1) != + if (AA.alias(F->getOperand(1), 1, DepPointer, 1) != AliasAnalysis::MustAlias) return false; diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 7c0d22359fd..fa84bb5c493 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -285,7 +285,6 @@ namespace { Instruction *visitPHINode(PHINode &PN); Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP); Instruction *visitAllocaInst(AllocaInst &AI); - Instruction *visitFreeInst(FreeInst &FI); Instruction *visitFree(Instruction &FI); Instruction *visitLoadInst(LoadInst &LI); Instruction *visitStoreInst(StoreInst &SI); @@ -11328,56 +11327,6 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) { return 0; } -Instruction *InstCombiner::visitFreeInst(FreeInst &FI) { - Value *Op = FI.getOperand(0); - - // free undef -> unreachable. - if (isa<UndefValue>(Op)) { - // Insert a new store to null because we cannot modify the CFG here. - new StoreInst(ConstantInt::getTrue(*Context), - UndefValue::get(Type::getInt1PtrTy(*Context)), &FI); - return EraseInstFromFunction(FI); - } - - // If we have 'free null' delete the instruction. This can happen in stl code - // when lots of inlining happens. - if (isa<ConstantPointerNull>(Op)) - return EraseInstFromFunction(FI); - - // Change free <ty>* (cast <ty2>* X to <ty>*) into free <ty2>* X - if (BitCastInst *CI = dyn_cast<BitCastInst>(Op)) { - FI.setOperand(0, CI->getOperand(0)); - return &FI; - } - - // Change free (gep X, 0,0,0,0) into free(X) - if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) { - if (GEPI->hasAllZeroIndices()) { - Worklist.Add(GEPI); - FI.setOperand(0, GEPI->getOperand(0)); - return &FI; - } - } - - if (isMalloc(Op)) { - if (CallInst* CI = extractMallocCallFromBitCast(Op)) { - if (Op->hasOneUse() && CI->hasOneUse()) { - EraseInstFromFunction(FI); - EraseInstFromFunction(*CI); - return EraseInstFromFunction(*cast<Instruction>(Op)); - } - } else { - // Op is a call to malloc - if (Op->hasOneUse()) { - EraseInstFromFunction(FI); - return EraseInstFromFunction(*cast<Instruction>(Op)); - } - } - } - - return 0; -} - Instruction *InstCombiner::visitFree(Instruction &FI) { Value *Op = FI.getOperand(1); @@ -11394,9 +11343,8 @@ Instruction *InstCombiner::visitFree(Instruction &FI) { if (isa<ConstantPointerNull>(Op)) return EraseInstFromFunction(FI); - // FIXME: Bring back free (gep X, 0,0,0,0) into free(X) transform - - if (isMalloc(Op)) { + // If we have a malloc call whose only use is a free call, delete both. + if (isMalloc(Op)) if (CallInst* CI = extractMallocCallFromBitCast(Op)) { if (Op->hasOneUse() && CI->hasOneUse()) { EraseInstFromFunction(FI); @@ -11410,7 +11358,6 @@ Instruction *InstCombiner::visitFree(Instruction &FI) { return EraseInstFromFunction(*cast<Instruction>(Op)); } } - } return 0; } diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 1bb5f4ae7fd..4c561217f89 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -416,7 +416,6 @@ private: void visitAllocaInst (Instruction &I) { markOverdefined(&I); } void visitVANextInst (Instruction &I) { markOverdefined(&I); } void visitVAArgInst (Instruction &I) { markOverdefined(&I); } - void visitFreeInst (Instruction &I) { /*returns void*/ } void visitInstruction(Instruction &I) { // If a new instruction is added to LLVM that we don't handle... |