diff options
40 files changed, 132 insertions, 402 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index c64b87f2f3..f17a950036 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -117,8 +117,8 @@ void BrainF::header(LLVMContext& C) { //brainf.end: endbb = BasicBlock::Create(C, label, brainf_func); - //free i8 *%arr - new FreeInst(ptr_arr, endbb); + //call free(i8 *%arr) + endbb->getInstList().push_back(CallInst::CreateFree(ptr_arr, endbb)); //ret void ReturnInst::Create(C, endbb); diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 89e1545843..7cb5bc371b 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -470,7 +470,6 @@ void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle); macro(UIToFPInst) \ macro(ZExtInst) \ macro(ExtractValueInst) \ - macro(FreeInst) \ macro(LoadInst) \ macro(VAArgInst) diff --git a/include/llvm/Analysis/AliasSetTracker.h b/include/llvm/Analysis/AliasSetTracker.h index 239f30f938..42a377e141 100644 --- a/include/llvm/Analysis/AliasSetTracker.h +++ b/include/llvm/Analysis/AliasSetTracker.h @@ -29,7 +29,6 @@ namespace llvm { class AliasAnalysis; class LoadInst; class StoreInst; -class FreeInst; class VAArgInst; class AliasSetTracker; class AliasSet; @@ -298,7 +297,6 @@ public: bool add(Value *Ptr, unsigned Size); // Add a location bool add(LoadInst *LI); bool add(StoreInst *SI); - bool add(FreeInst *FI); bool add(VAArgInst *VAAI); bool add(CallSite CS); // Call/Invoke instructions bool add(CallInst *CI) { return add(CallSite(CI)); } @@ -313,7 +311,6 @@ public: bool remove(Value *Ptr, unsigned Size); // Remove a location bool remove(LoadInst *LI); bool remove(StoreInst *SI); - bool remove(FreeInst *FI); bool remove(VAArgInst *VAAI); bool remove(CallSite CS); bool remove(CallInst *CI) { return remove(CallSite(CI)); } diff --git a/include/llvm/Analysis/MallocHelper.h b/include/llvm/Analysis/MallocHelper.h index be307c02ae..22cf1b58bb 100644 --- a/include/llvm/Analysis/MallocHelper.h +++ b/include/llvm/Analysis/MallocHelper.h @@ -1,4 +1,4 @@ -//===- llvm/Analysis/MallocHelper.h ---- Identify malloc calls --*- C++ -*-===// +//===- llvm/Analysis/MallocFreeHelper.h - Identify malloc/free --*- C++ -*-===// // // 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. // //===----------------------------------------------------------------------===// diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 6b84857c89..e83acba82e 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -117,7 +117,6 @@ public: static inline bool classof(const UnaryInstruction *) { return true; } static inline bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Alloca || - I->getOpcode() == Instruction::Free || I->getOpcode() == Instruction::Load || I->getOpcode() == Instruction::VAArg || I->getOpcode() == Instruction::ExtractValue || diff --git a/include/llvm/Instruction.def b/include/llvm/Instruction.def index 5c8fe3eacc..ec86b35364 100644 --- a/include/llvm/Instruction.def +++ b/include/llvm/Instruction.def @@ -128,48 +128,47 @@ HANDLE_BINARY_INST(24, Xor , BinaryOperator) // Memory operators... FIRST_MEMORY_INST(25) -HANDLE_MEMORY_INST(25, Free , FreeInst ) // Heap management instructions -HANDLE_MEMORY_INST(26, Alloca, AllocaInst) // Stack management -HANDLE_MEMORY_INST(27, Load , LoadInst ) // Memory manipulation instrs -HANDLE_MEMORY_INST(28, Store , StoreInst ) -HANDLE_MEMORY_INST(29, GetElementPtr, GetElementPtrInst) - LAST_MEMORY_INST(29) +HANDLE_MEMORY_INST(25, Alloca, AllocaInst) // Stack management +HANDLE_MEMORY_INST(26, Load , LoadInst ) // Memory manipulation instrs +HANDLE_MEMORY_INST(27, Store , StoreInst ) +HANDLE_MEMORY_INST(28, GetElementPtr, GetElementPtrInst) + LAST_MEMORY_INST(28) // Cast operators ... // NOTE: The order matters here because CastInst::isEliminableCastPair // NOTE: (see Instructions.cpp) encodes a table based on this ordering. - FIRST_CAST_INST(30) -HANDLE_CAST_INST(30, Trunc , TruncInst ) // Truncate integers -HANDLE_CAST_INST(31, ZExt , ZExtInst ) // Zero extend integers -HANDLE_CAST_INST(32, SExt , SExtInst ) // Sign extend integers -HANDLE_CAST_INST(33, FPToUI , FPToUIInst ) // floating point -> UInt -HANDLE_CAST_INST(34, FPToSI , FPToSIInst ) // floating point -> SInt -HANDLE_CAST_INST(35, UIToFP , UIToFPInst ) // UInt -> floating point -HANDLE_CAST_INST(36, SIToFP , SIToFPInst ) // SInt -> floating point -HANDLE_CAST_INST(37, FPTrunc , FPTruncInst ) // Truncate floating point -HANDLE_CAST_INST(38, FPExt , FPExtInst ) // Extend floating point -HANDLE_CAST_INST(39, PtrToInt, PtrToIntInst) // Pointer -> Integer -HANDLE_CAST_INST(40, IntToPtr, IntToPtrInst) // Integer -> Pointer -HANDLE_CAST_INST(41, BitCast , BitCastInst ) // Type cast - LAST_CAST_INST(41) + FIRST_CAST_INST(29) +HANDLE_CAST_INST(29, Trunc , TruncInst ) // Truncate integers +HANDLE_CAST_INST(30, ZExt , ZExtInst ) // Zero extend integers +HANDLE_CAST_INST(31, SExt , SExtInst ) // Sign extend integers +HANDLE_CAST_INST(32, FPToUI , FPToUIInst ) // floating point -> UInt +HANDLE_CAST_INST(33, FPToSI , FPToSIInst ) // floating point -> SInt +HANDLE_CAST_INST(34, UIToFP , UIToFPInst ) // UInt -> floating point +HANDLE_CAST_INST(35, SIToFP , SIToFPInst ) // SInt -> floating point +HANDLE_CAST_INST(36, FPTrunc , FPTruncInst ) // Truncate floating point +HANDLE_CAST_INST(37, FPExt , FPExtInst ) // Extend floating point +HANDLE_CAST_INST(38, PtrToInt, PtrToIntInst) // Pointer -> Integer +HANDLE_CAST_INST(39, IntToPtr, IntToPtrInst) // Integer -> Pointer +HANDLE_CAST_INST(40, BitCast , BitCastInst ) // Type cast + LAST_CAST_INST(40) // Other operators... - FIRST_OTHER_INST(42) -HANDLE_OTHER_INST(42, ICmp , ICmpInst ) // Integer comparison instruction -HANDLE_OTHER_INST(43, FCmp , FCmpInst ) // Floating point comparison instr. -HANDLE_OTHER_INST(44, PHI , PHINode ) // PHI node instruction -HANDLE_OTHER_INST(45, Call , CallInst ) // Call a function -HANDLE_OTHER_INST(46, Select , SelectInst ) // select instruction -HANDLE_OTHER_INST(47, UserOp1, Instruction) // May be used internally in a pass -HANDLE_OTHER_INST(48, UserOp2, Instruction) // Internal to passes only -HANDLE_OTHER_INST(49, VAArg , VAArgInst ) // vaarg instruction -HANDLE_OTHER_INST(50, ExtractElement, ExtractElementInst)// extract from vector -HANDLE_OTHER_INST(51, InsertElement, InsertElementInst) // insert into vector -HANDLE_OTHER_INST(52, ShuffleVector, ShuffleVectorInst) // shuffle two vectors. -HANDLE_OTHER_INST(53, ExtractValue, ExtractValueInst)// extract from aggregate -HANDLE_OTHER_INST(54, InsertValue, InsertValueInst) // insert into aggregate - - LAST_OTHER_INST(54) + FIRST_OTHER_INST(41) +HANDLE_OTHER_INST(41, ICmp , ICmpInst ) // Integer comparison instruction +HANDLE_OTHER_INST(42, FCmp , FCmpInst ) // Floating point comparison instr. +HANDLE_OTHER_INST(43, PHI , PHINode ) // PHI node instruction +HANDLE_OTHER_INST(44, Call , CallInst ) // Call a function +HANDLE_OTHER_INST(45, Select , SelectInst ) // select instruction +HANDLE_OTHER_INST(46, UserOp1, Instruction) // May be used internally in a pass +HANDLE_OTHER_INST(47, UserOp2, Instruction) // Internal to passes only +HANDLE_OTHER_INST(48, VAArg , VAArgInst ) // vaarg instruction +HANDLE_OTHER_INST(49, ExtractElement, ExtractElementInst)// extract from vector +HANDLE_OTHER_INST(50, InsertElement, InsertElementInst) // insert into vector +HANDLE_OTHER_INST(51, ShuffleVector, ShuffleVectorInst) // shuffle two vectors. +HANDLE_OTHER_INST(52, ExtractValue, ExtractValueInst)// extract from aggregate +HANDLE_OTHER_INST(53, InsertValue, InsertValueInst) // insert into aggregate + + LAST_OTHER_INST(53) #undef FIRST_TERM_INST #undef HANDLE_TERM_INST diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 1e2c93fe87..7cb6786aca 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -104,35 +104,6 @@ public: //===----------------------------------------------------------------------===// -// FreeInst Class -//===----------------------------------------------------------------------===// - -/// FreeInst - an instruction to deallocate memory -/// -class FreeInst : public UnaryInstruction { - void AssertOK(); -public: - explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); - FreeInst(Value *Ptr, BasicBlock *InsertAfter); - - virtual FreeInst *clone() const; - - // Accessor methods for consistency with other memory operations - Value *getPointerOperand() { return getOperand(0); } - const Value *getPointerOperand() const { return getOperand(0); } - - // Methods for support type inquiry through isa, cast, and dyn_cast: - static inline bool classof(const FreeInst *) { return true; } - static inline bool classof(const Instruction *I) { - return (I->getOpcode() == Instruction::Free); - } - static inline bool classof(const Value *V) { - return isa<Instruction>(V) && classof(cast<Instruction>(V)); - } -}; - - -//===----------------------------------------------------------------------===// // LoadInst Class //===----------------------------------------------------------------------===// diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h index bc5722e82e..28538b72b8 100644 --- a/include/llvm/LinkAllPasses.h +++ b/include/llvm/LinkAllPasses.h @@ -91,7 +91,6 @@ namespace { (void) llvm::createLoopUnswitchPass(); (void) llvm::createLoopRotatePass(); (void) llvm::createLoopIndexSplitPass(); - (void) llvm::createLowerAllocationsPass(); (void) llvm::createLowerInvokePass(); (void) llvm::createLowerSetJmpPass(); (void) llvm::createLowerSwitchPass(); diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 83df9edc0c..84bfd09b00 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -433,9 +433,6 @@ public: const Twine &Name = "") { return Insert(new AllocaInst(Ty, ArraySize), Name); } - FreeInst *CreateFree(Value *Ptr) { - return Insert(new FreeInst(Ptr)); - } // Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of // converting the string to 'bool' for the isVolatile parameter. LoadInst *CreateLoad(Value *Ptr, const char *Name) { diff --git a/include/llvm/Support/InstVisitor.h b/include/llvm/Support/InstVisitor.h index 1e34e6633d..ae35a3c281 100644 --- a/include/llvm/Support/InstVisitor.h +++ b/include/llvm/Support/InstVisitor.h @@ -166,7 +166,6 @@ public: RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);} RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);} RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(Instruction); } - RetTy visitFreeInst(FreeInst &I) { DELEGATE(Instruction); } RetTy visitLoadInst(LoadInst &I) { DELEGATE(Instruction); } RetTy visitStoreInst(StoreInst &I) { DELEGATE(Instruction); } RetTy visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction); } diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index c5378994fd..f700c49d55 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -225,15 +225,6 @@ extern const PassInfo *const LoopSimplifyID; //===----------------------------------------------------------------------===// // -// LowerAllocations - Turn free instructions into @free calls. -// -// AU.addRequiredID(LowerAllocationsID); -// -Pass *createLowerAllocationsPass(); -extern const PassInfo *const LowerAllocationsID; - -//===----------------------------------------------------------------------===// -// // TailCallElimination - This pass eliminates call instructions to the current // function which occur immediately before return instructions. // 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)); diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index f6cea8887c..4fb7ea9e29 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -606,6 +606,10 @@ lltok::Kind LLLexer::LexIdentifier() { // FIXME: Remove in LLVM 3.0. // Autoupgrade malloc instruction. return lltok::kw_malloc; + } else if (Len == 4 && !memcmp(StartChar, "free", 4)) { + // FIXME: Remove in LLVM 3.0. + // Autoupgrade malloc instruction. + return lltok::kw_free; } // Keywords for instructions. @@ -646,7 +650,6 @@ lltok::Kind LLLexer::LexIdentifier() { INSTKEYWORD(unreachable, Unreachable); INSTKEYWORD(alloca, Alloca); - INSTKEYWORD(free, Free); INSTKEYWORD(load, Load); INSTKEYWORD(store, Store); INSTKEYWORD(getelementptr, GetElementPtr); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 037854e26f..535740b3fb 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1054,11 +1054,6 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Vals.push_back(VE.getValueID(I.getOperand(i))); break; - case Instruction::Free: - Code = bitc::FUNC_CODE_INST_FREE; - PushValueAndType(I.getOperand(0), InstID, Vals, VE); - break; - case Instruction::Alloca: Code = bitc::FUNC_CODE_INST_ALLOCA; Vals.push_back(VE.getTypeID(I.getType())); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index d862e40603..f3a0622157 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -5486,26 +5486,6 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) { DAG.setRoot(Chain); } -void SelectionDAGLowering::visitFree(FreeInst &I) { |