diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 14:58:56 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 14:58:56 +0000 |
commit | 36bf506ad3c99a309ca8bd73bd03563d8d068ac0 (patch) | |
tree | b4dc751bcee540346911aa4115729eff2f991657 /lib/VMCore | |
parent | f9666f9b3a3d26810deae8cd54feb6e47ecee61a (diff) |
Notes
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 26 | ||||
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 19 | ||||
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 39 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 124 | ||||
-rw-r--r-- | lib/VMCore/ConstantsContext.h | 20 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Dominators.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 15 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 1 | ||||
-rw-r--r-- | lib/VMCore/Instruction.cpp | 39 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 645 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 31 | ||||
-rw-r--r-- | lib/VMCore/LeakDetector.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/LeaksContext.h | 1 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 10 | ||||
-rw-r--r-- | lib/VMCore/PassManager.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/PrintModulePass.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Type.cpp | 21 | ||||
-rw-r--r-- | lib/VMCore/TypeSymbolTable.cpp | 31 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 13 |
21 files changed, 560 insertions, 499 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index d8a708dbbcc56..9a803a1662809 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -23,6 +23,7 @@ #include "llvm/InlineAsm.h" #include "llvm/Instruction.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Operator.h" #include "llvm/Metadata.h" #include "llvm/Module.h" @@ -1059,6 +1060,15 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV, Out << "zeroinitializer"; return; } + + if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) { + Out << "blockaddress("; + WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine); + Out << ", "; + WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine); + Out << ")"; + return; + } if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { // As a special case, print the array as a string if it is an array of @@ -1831,7 +1841,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(BI.getSuccessor(1), true); } else if (isa<SwitchInst>(I)) { - // Special case switch statement to get formatting nice and correct... + // Special case switch instruction to get formatting nice and correct. Out << ' '; writeOperand(Operand , true); Out << ", "; @@ -1845,6 +1855,18 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(I.getOperand(op+1), true); } Out << "\n ]"; + } else if (isa<IndirectBrInst>(I)) { + // Special case indirectbr instruction to get formatting nice and correct. + Out << ' '; + writeOperand(Operand, true); + Out << ", ["; + + for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) { + if (i != 1) + Out << ", "; + writeOperand(I.getOperand(i), true); + } + Out << ']'; } else if (isa<PHINode>(I)) { Out << ' '; TypePrinter.print(I.getType(), Out); @@ -1966,7 +1988,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << " unwind "; writeOperand(II->getUnwindDest(), true); - } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(&I)) { + } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { Out << ' '; TypePrinter.print(AI->getType()->getElementType(), Out); if (!AI->getArraySize() || AI->isArrayAllocation()) { diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 50cf84c3fe624..23d0557dc7479 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -58,6 +58,24 @@ BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent, BasicBlock::~BasicBlock() { + // If the address of the block is taken and it is being deleted (e.g. because + // it is dead), this means that there is either a dangling constant expr + // hanging off the block, or an undefined use of the block (source code + // expecting the address of a label to keep the block alive even though there + // is no indirect branch). Handle these cases by zapping the BlockAddress + // nodes. There are no other possible uses at this point. + if (hasAddressTaken()) { + assert(!use_empty() && "There should be at least one blockaddress!"); + Constant *Replacement = + ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1); + while (!use_empty()) { + BlockAddress *BA = cast<BlockAddress>(use_back()); + BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement, + BA->getType())); + BA->destroyConstant(); + } + } + assert(getParent() == 0 && "BasicBlock still linked into the program!"); dropAllReferences(); InstList.clear(); @@ -277,3 +295,4 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) { } return New; } + diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 2c0a67f1d0435..7f713d15c67a4 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -215,7 +215,7 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, switch (CE->getOpcode()) { default: return 0; case Instruction::Or: { - Constant *RHS = ExtractConstantBytes(C->getOperand(1), ByteStart, ByteSize); + Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize); if (RHS == 0) return 0; @@ -224,13 +224,13 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, if (RHSC->isAllOnesValue()) return RHSC; - Constant *LHS = ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize); + Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize); if (LHS == 0) return 0; return ConstantExpr::getOr(LHS, RHS); } case Instruction::And: { - Constant *RHS = ExtractConstantBytes(C->getOperand(1), ByteStart, ByteSize); + Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize); if (RHS == 0) return 0; @@ -238,7 +238,7 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, if (RHS->isNullValue()) return RHS; - Constant *LHS = ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize); + Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize); if (LHS == 0) return 0; return ConstantExpr::getAnd(LHS, RHS); @@ -259,7 +259,7 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, ByteSize*8)); // If the extract is known to be fully in the input, extract it. if (ByteStart+ByteSize+ShAmt <= CSize) - return ExtractConstantBytes(C->getOperand(0), ByteStart+ShAmt, ByteSize); + return ExtractConstantBytes(CE->getOperand(0), ByteStart+ShAmt, ByteSize); // TODO: Handle the 'partially zero' case. return 0; @@ -281,7 +281,7 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, ByteSize*8)); // If the extract is known to be fully in the input, extract it. if (ByteStart >= ShAmt) - return ExtractConstantBytes(C->getOperand(0), ByteStart-ShAmt, ByteSize); + return ExtractConstantBytes(CE->getOperand(0), ByteStart-ShAmt, ByteSize); // TODO: Handle the 'partially zero' case. return 0; @@ -289,7 +289,7 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, case Instruction::ZExt: { unsigned SrcBitSize = - cast<IntegerType>(C->getOperand(0)->getType())->getBitWidth(); + cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth(); // If extracting something that is completely zero, return 0. if (ByteStart*8 >= SrcBitSize) @@ -298,18 +298,18 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, // If exactly extracting the input, return it. if (ByteStart == 0 && ByteSize*8 == SrcBitSize) - return C->getOperand(0); + return CE->getOperand(0); // If extracting something completely in the input, if if the input is a // multiple of 8 bits, recurse. if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize) - return ExtractConstantBytes(C->getOperand(0), ByteStart, ByteSize); + return ExtractConstantBytes(CE->getOperand(0), ByteStart, ByteSize); // Otherwise, if extracting a subset of the input, which is not multiple of // 8 bits, do a shift and trunc to get the bits. if ((ByteStart+ByteSize)*8 < SrcBitSize) { assert((SrcBitSize&7) && "Shouldn't get byte sized case here"); - Constant *Res = C->getOperand(0); + Constant *Res = CE->getOperand(0); if (ByteStart) Res = ConstantExpr::getLShr(Res, ConstantInt::get(Res->getType(), ByteStart*8)); @@ -634,7 +634,15 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context, Idxs + NumIdx)); // Otherwise recurse. - return ConstantFoldExtractValueInstruction(Context, Agg->getOperand(*Idxs), + if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Agg)) + return ConstantFoldExtractValueInstruction(Context, CS->getOperand(*Idxs), + Idxs+1, NumIdx-1); + + if (ConstantArray *CA = dyn_cast<ConstantArray>(Agg)) + return ConstantFoldExtractValueInstruction(Context, CA->getOperand(*Idxs), + Idxs+1, NumIdx-1); + ConstantVector *CV = cast<ConstantVector>(Agg); + return ConstantFoldExtractValueInstruction(Context, CV->getOperand(*Idxs), Idxs+1, NumIdx-1); } @@ -714,11 +722,10 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context, // Insertion of constant into aggregate constant. std::vector<Constant*> Ops(Agg->getNumOperands()); for (unsigned i = 0; i < Agg->getNumOperands(); ++i) { - Constant *Op = - (*Idxs == i) ? - ConstantFoldInsertValueInstruction(Context, Agg->getOperand(i), - Val, Idxs+1, NumIdx-1) : - Agg->getOperand(i); + Constant *Op = cast<Constant>(Agg->getOperand(i)); + if (*Idxs == i) + Op = ConstantFoldInsertValueInstruction(Context, Op, + Val, Idxs+1, NumIdx-1); Ops[i] = Op; } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 02c33528ecfb3..000a063cc1bb7 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file implements the Constant* classes... +// This file implements the Constant* classes. // //===----------------------------------------------------------------------===// @@ -29,9 +29,6 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/GetElementPtrTypeIterator.h" -#include "llvm/System/Mutex.h" -#include "llvm/System/RWMutex.h" -#include "llvm/System/Threading.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include <algorithm> @@ -44,7 +41,7 @@ using namespace llvm; // Constructor to create a '0' constant of arbitrary type... static const uint64_t zero[2] = {0, 0}; -Constant* Constant::getNullValue(const Type* Ty) { +Constant *Constant::getNullValue(const Type *Ty) { switch (Ty->getTypeID()) { case Type::IntegerTyID: return ConstantInt::get(Ty, 0); @@ -72,7 +69,7 @@ Constant* Constant::getNullValue(const Type* Ty) { } } -Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) { +Constant* Constant::getIntegerValue(const Type *Ty, const APInt &V) { const Type *ScalarTy = Ty->getScalarType(); // Create the base integer constant. @@ -89,13 +86,13 @@ Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) { return C; } -Constant* Constant::getAllOnesValue(const Type* Ty) { - if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) +Constant* Constant::getAllOnesValue(const Type *Ty) { + if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) return ConstantInt::get(Ty->getContext(), APInt::getAllOnesValue(ITy->getBitWidth())); std::vector<Constant*> Elts; - const VectorType* VTy = cast<VectorType>(Ty); + const VectorType *VTy = cast<VectorType>(Ty); Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType())); assert(Elts[0] && "Not a vector integer type!"); return cast<ConstantVector>(ConstantVector::get(Elts)); @@ -140,7 +137,7 @@ bool Constant::canTrap() const { // ConstantExpr traps if any operands can trap. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - if (getOperand(i)->canTrap()) + if (CE->getOperand(i)->canTrap()) return true; // Otherwise, only specific operations can trap. @@ -154,12 +151,27 @@ bool Constant::canTrap() const { case Instruction::SRem: case Instruction::FRem: // Div and rem can trap if the RHS is not known to be non-zero. - if (!isa<ConstantInt>(getOperand(1)) || getOperand(1)->isNullValue()) + if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue()) return true; return false; } } +/// isConstantUsed - Return true if the constant has users other than constant +/// exprs and other dangling things. +bool Constant::isConstantUsed() const { + for (use_const_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) { + const Constant *UC = dyn_cast<Constant>(*UI); + if (UC == 0 || isa<GlobalValue>(UC)) + return true; + + if (UC->isConstantUsed()) + return true; + } + return false; +} + + /// getRelocationInfo - This method classifies the entry according to /// whether or not it may generate a relocation entry. This must be @@ -182,9 +194,13 @@ Constant::PossibleRelocationsTy Constant::getRelocationInfo() const { return GlobalRelocations; // Global reference. } + if (const BlockAddress *BA = dyn_cast<BlockAddress>(this)) + return BA->getFunction()->getRelocationInfo(); + PossibleRelocationsTy Result = NoRelocation; for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - Result = std::max(Result, getOperand(i)->getRelocationInfo()); + Result = std::max(Result, + cast<Constant>(getOperand(i))->getRelocationInfo()); return Result; } @@ -987,7 +1003,7 @@ Constant *ConstantVector::getSplatValue() { return Elt; } -//---- ConstantPointerNull::get() implementation... +//---- ConstantPointerNull::get() implementation. // ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) { @@ -1004,23 +1020,95 @@ void ConstantPointerNull::destroyConstant() { } -//---- UndefValue::get() implementation... +//---- UndefValue::get() implementation. // UndefValue *UndefValue::get(const Type *Ty) { - // Implicitly locked. return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0); } // destroyConstant - Remove the constant from the constant table. // void UndefValue::destroyConstant() { - // Implicitly locked. getType()->getContext().pImpl->UndefValueConstants.remove(this); destroyConstantImpl(); } -//---- ConstantExpr::get() implementations... +//---- BlockAddress::get() implementation. +// + +BlockAddress *BlockAddress::get(BasicBlock *BB) { + assert(BB->getParent() != 0 && "Block must have a parent"); + return get(BB->getParent(), BB); +} + +BlockAddress *BlockAddress::get(Function *F, BasicBlock *BB) { + BlockAddress *&BA = + F->getContext().pImpl->BlockAddresses[std::make_pair(F, BB)]; + if (BA == 0) + BA = new BlockAddress(F, BB); + + assert(BA->getFunction() == F && "Basic block moved between functions"); + return BA; +} + +BlockAddress::BlockAddress(Function *F, BasicBlock *BB) +: Constant(Type::getInt8PtrTy(F->getContext()), Value::BlockAddressVal, + &Op<0>(), 2) { + setOperand(0, F); + setOperand(1, BB); + BB->AdjustBlockAddressRefCount(1); +} + + +// destroyConstant - Remove the constant from the constant table. +// +void BlockAddress::destroyConstant() { + getFunction()->getType()->getContext().pImpl + ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock())); + getBasicBlock()->AdjustBlockAddressRefCount(-1); + destroyConstantImpl(); +} + +void BlockAddress::replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) { + // This could be replacing either the Basic Block or the Function. In either + // case, we have to remove the map entry. + Function *NewF = getFunction(); + BasicBlock *NewBB = getBasicBlock(); + + if (U == &Op<0>()) + NewF = cast<Function>(To); + else + NewBB = cast<BasicBlock>(To); + + // See if the 'new' entry already exists, if not, just update this in place + // and return early. + BlockAddress *&NewBA = + getContext().pImpl->BlockAddresses[std::make_pair(NewF, NewBB)]; + if (NewBA == 0) { + getBasicBlock()->AdjustBlockAddressRefCount(-1); + + // Remove the old entry, this can't cause the map to rehash (just a + // tombstone will get added). + getContext().pImpl->BlockAddresses.erase(std::make_pair(getFunction(), + getBasicBlock())); + NewBA = this; + setOperand(0, NewF); + setOperand(1, NewBB); + getBasicBlock()->AdjustBlockAddressRefCount(1); + return; + } + + // Otherwise, I do need to replace this with an existing value. + assert(NewBA != this && "I didn't contain From!"); + + // Everyone using this now uses the replacement. + uncheckedReplaceAllUsesWith(NewBA); + + destroyConstant(); +} + +//---- ConstantExpr::get() implementations. // /// This is a utility function to handle folding of casts and lookup of the @@ -1838,7 +1926,7 @@ const char *ConstantExpr::getOpcodeName() const { /// single invocation handles all 1000 uses. Handling them one at a time would /// work, but would be really slow because it would have to unique each updated /// array instance. - +/// void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) { assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!"); diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h index 526b4b1b7ee34..268a6602fa90d 100644 --- a/lib/VMCore/ConstantsContext.h +++ b/lib/VMCore/ConstantsContext.h @@ -20,8 +20,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/Mutex.h" -#include "llvm/System/RWMutex.h" #include <map> namespace llvm { @@ -332,7 +330,7 @@ struct ExprMapKeyType { // The number of operands for each ConstantCreator::create method is // determined by the ConstantTraits template. // ConstantCreator - A class that is used to create constants by -// ValueMap*. This class should be partially specialized if there is +// ConstantUniqueMap*. This class should be partially specialized if there is // something strange that needs to be done to interface to the ctor for the // constant. // @@ -506,7 +504,7 @@ struct ConstantKeyData<UndefValue> { template<class ValType, class TypeClass, class ConstantClass, bool HasLargeKey = false /*true for arrays and structs*/ > -class ValueMap : public AbstractTypeUser { +class ConstantUniqueMap : public AbstractTypeUser { public: typedef std::pair<const TypeClass*, ValType> MapKey; typedef std::map<MapKey, ConstantClass *> MapTy; @@ -529,12 +527,7 @@ private: /// AbstractTypeMapTy AbstractTypeMap; - /// ValueMapLock - Mutex for this map. - sys::SmartMutex<true> ValueMapLock; - public: - // NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. typename MapTy::iterator map_begin() { return Map.begin(); } typename MapTy::iterator map_end() { return Map.end(); } @@ -551,8 +544,6 @@ public: /// entry and Exists=true. If not, the iterator points to the newly /// inserted entry and returns Exists=false. Newly inserted entries have /// I->second == 0, and should be filled in. - /// NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. typename MapTy::iterator InsertOrGetItem(std::pair<MapKey, ConstantClass *> &InsertVal, bool &Exists) { @@ -619,7 +610,6 @@ public: /// getOrCreate - Return the specified constant from the map, creating it if /// necessary. ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { - sys::SmartScopedLock<true> Lock(ValueMapLock); MapKey Lookup(Ty, V); ConstantClass* Result = 0; @@ -674,7 +664,6 @@ public: } void remove(ConstantClass *CP) { - sys::SmartScopedLock<true> Lock(ValueMapLock); typename MapTy::iterator I = FindExistingElement(CP); assert(I != Map.end() && "Constant not found in constant table!"); assert(I->second == CP && "Didn't find correct element?"); @@ -694,8 +683,6 @@ public: /// MoveConstantToNewSlot - If we are about to change C to be the element /// specified by I, update our internal data structures to reflect this /// fact. - /// NOTE: This function is not locked. It is the responsibility of the - /// caller to enforce proper synchronization if using this method. void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) { // First, remove the old location of the specified constant in the map. typename MapTy::iterator OldI = FindExistingElement(C); @@ -725,7 +712,6 @@ public: } void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { - sys::SmartScopedLock<true> Lock(ValueMapLock); typename AbstractTypeMapTy::iterator I = AbstractTypeMap.find(OldTy); assert(I != AbstractTypeMap.end() && @@ -778,7 +764,7 @@ public: } void dump() const { - DEBUG(errs() << "Constant.cpp: ValueMap\n"); + DEBUG(errs() << "Constant.cpp: ConstantUniqueMap\n"); } }; diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index a28037d3f28f3..9a49d42475311 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -1724,7 +1724,8 @@ LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, } LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) { - return wrap(unwrap(B)->CreateFree(unwrap(PointerVal))); + return wrap(unwrap(B)->Insert( + CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock()))); } diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index b49faf84dceaf..26c02e0f50439 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -322,7 +322,7 @@ DominanceFrontier::calculate(const DominatorTree &DT, void DominanceFrontierBase::print(raw_ostream &OS, const Module* ) const { for (const_iterator I = begin(), E = end(); I != E; ++I) { - OS << " DomFrontier for BB"; + OS << " DomFrontier for BB "; if (I->first) WriteAsOperand(OS, I->first, false); else @@ -332,11 +332,13 @@ void DominanceFrontierBase::print(raw_ostream &OS, const Module* ) const { const std::set<BasicBlock*> &BBs = I->second; for (std::set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end(); - I != E; ++I) + I != E; ++I) { + OS << ' '; if (*I) WriteAsOperand(OS, *I, false); else - OS << " <<exit node>>"; + OS << "<<exit node>>"; + } OS << "\n"; } } diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 8ad885c4c23d1..6cf2c8186f9be 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -217,7 +217,20 @@ void Function::setParent(Module *parent) { void Function::dropAllReferences() { for (iterator I = begin(), E = end(); I != E; ++I) I->dropAllReferences(); - BasicBlocks.clear(); // Delete all basic blocks... + + // Delete all basic blocks. + while (!BasicBlocks.empty()) { + // If there is still a reference to the block, it must be a 'blockaddress' + // constant pointing to it. Just replace the BlockAddress with undef. + BasicBlock *BB = BasicBlocks.begin(); + if (!BB->use_empty()) { + BlockAddress *BA = cast<BlockAddress>(BB->use_back()); + BA->replaceAllUsesWith(UndefValue::get(BA->getType())); + BA->destroyConstant(); + } + + BB->eraseFromParent(); + } } void Function::addAttribute(unsigned i, Attributes attr) { diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index d18a20162dd9e..03ceecb6f1aff 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -75,6 +75,7 @@ void GlobalValue::removeDeadConstantUsers() const { } } + /// Override destroyConstant to make sure it doesn't get called on /// GlobalValue's because they shouldn't be treated like other constants. void GlobalValue::destroyConstant() { diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index dd8a543050226..ce253d64cedf9 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -103,6 +103,7 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Ret: return "ret"; case Br: return "br"; case Switch: return "switch"; + case IndirectBr: return "indirectbr"; case Invoke: return "invoke"; case Unwind: return "unwind"; case Unreachable: return "unreachable"; @@ -127,7 +128,6 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { case Xor: return "xor"; // Memory instructions... - case Free: return "free"; case Alloca: return "alloca"; case Load: return "load"; case Store: return "store"; @@ -308,7 +308,6 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { bool Instruction::mayReadFromMemory() const { switch (getOpcode()) { default: return false; - case Instruction::Free: case Instruction::VAArg: case Instruction::Load: return true; @@ -326,7 +325,6 @@ bool Instruction::mayReadFromMemory() const { bool Instruction::mayWriteToMemory() const { switch (getOpcode()) { default: return false; - case Instruction::Free: case Instruction::Store: case Instruction::VAArg: return true; @@ -380,7 +378,7 @@ bool Instruction::isCommutative(unsigned op) { } } -// Code here matches isMalloc from MallocHelper, which is not in VMCore. +// Code here matches isMalloc from MemoryBuiltins, which is not in VMCore. static bool isMalloc(const Value* I) { const CallInst *CI = dyn_cast<CallInst>(I); if (!CI) { @@ -390,15 +388,25 @@ static bool isMalloc(const Value* I) { CI = dyn_cast<CallInst>(BCI->getOperand(0)); } - if (!CI) return false; - - const Module* M = CI->getParent()->getParent()->getParent(); - Constant *MallocFunc = M->getFunction("malloc"); + if (!CI) + return false; + Function *Callee = CI->getCalledFunction(); + if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc") + return false; - if (CI->getOperand(0) != MallocFunc) + // Check malloc prototype. + // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin + // attribute will exist. + const FunctionType *FTy = Callee->getFunctionType(); + if (FTy->getNumParams() != 1) return false; + if (IntegerType *ITy = dyn_cast<IntegerType>(FTy->param_begin()->get())) { + if (ITy->getBitWidth() != 32 && ITy->getBitWidth() != 64) + return false; + return true; + } - return true; + return false; } bool Instruction::isSafeToSpeculativelyExecute() const { @@ -426,7 +434,7 @@ bool Instruction::isSafeToSpeculativelyExecute() const { case Load: { if (cast<LoadInst>(this)->isVolatile()) return false; - if (isa<AllocationInst>(getOperand(0)) || isMalloc(getOperand(0))) + if (isa<AllocaInst>(getOperand(0)) || isMalloc(getOperand(0))) return true; if (GlobalVariable *GV = dyn_cast<GlobalVariable>(getOperand(0))) return !GV->hasExternalWeakLinkage(); @@ -444,7 +452,6 @@ bool Instruction::isSafeToSpeculativelyExecute() const { case Invoke: case PHI: case Store: - case Free: case Ret: case Br: case Switch: @@ -453,3 +460,11 @@ bool Instruction::isSafeToSpeculativelyExecute() const { return false; // Misc instructions which have effects } } + +Instruction *Instruction::clone() const { + Instruction *New = clone_impl(); + New->SubclassOptionalData = SubclassOptionalData; + if (hasMetadata()) + getContext().pImpl->TheMetadata.ValueIsCloned(this, New); + return New; +} diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index e212d5c542a76..52d8735d89b7a 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -559,6 +559,51 @@ Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, ArraySize, MallocF, Name); } +static Instruction* createFree(Value* Source, Instruction *InsertBefore, + BasicBlock *InsertAtEnd) { + assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && + "createFree needs either InsertBefore or InsertAtEnd"); + assert(isa<PointerType>(Source->getType()) && + "Can not free something of nonpointer type!"); + + BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd; + Module* M = BB->getParent()->getParent(); + + const Type *VoidTy = Type::getVoidTy(M->getContext()); + const Type *IntPtrTy = Type::getInt8PtrTy(M->getContext()); + // prototype free as "void free(void*)" + Constant *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, NULL); + + CallInst* Result = NULL; + Value *PtrCast = Source; + if (InsertBefore) { + if (Source->getType() != IntPtrTy) + PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertBefore); + Result = CallInst::Create(FreeFunc, PtrCast, "", InsertBefore); + } else { + if (Source->getType() != IntPtrTy) + PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertAtEnd); + Result = CallInst::Create(FreeFunc, PtrCast, ""); + } + Result->setTailCall(); + + return Result; +} + +/// CreateFree - Generate the IR for a call to the builtin free function. +void CallInst::CreateFree(Value* Source, Instruction *InsertBefore) { + createFree(Source, InsertBefore, NULL); +} + +/// CreateFree - Generate the IR for a call to the builtin free function. +/// Note: This function does not add the call to the basic block, that is the +/// responsibility of the caller. +Instruction* CallInst::CreateFree(Value* Source, BasicBlock *InsertAtEnd) { + Instruction* FreeCall = createFree(Source, NULL, InsertAtEnd); + assert(FreeCall && "CreateFree did not create a CallInst"); + return FreeCall; +} + //===----------------------------------------------------------------------===// // InvokeInst Implementation //===----------------------------------------------------------------------===// @@ -838,7 +883,7 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) { //===----------------------------------------------------------------------===// -// AllocationInst Implementation +// AllocaInst Implementation //===----------------------------------------------------------------------===// static Value *getAISize(LLVMContext &Context, Value *Amt) { @@ -853,20 +898,54 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) { return Amt; } -AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, - unsigned Align, const Twine &Name, - Instruction *InsertBefore) - : UnaryInstruction(PointerType::getUnqual(Ty), iTy, +AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, + const Twine &Name, Instruction *InsertBefore) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, + getAISize(Ty->getContext(), ArraySize), InsertBefore) { + setAlignment(0); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); + setName(Name); +} + +AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, + const Twine &Name, BasicBlock *InsertAtEnd) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, + getAISize(Ty->getContext(), ArraySize), InsertAtEnd) { + setAlignment(0); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); + setName(Name); +} + +AllocaInst::AllocaInst(const Type *Ty, const Twine &Name, + Instruction *InsertBefore) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, + getAISize(Ty->getContext(), 0), InsertBefore) { + setAlignment(0); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); + setName(Name); +} + +AllocaInst::AllocaInst(const Type *Ty, const Twine &Name, + BasicBlock *InsertAtEnd) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, + getAISize(Ty->getContext(), 0), InsertAtEnd) { + setAlignment(0); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); + setName(Name); +} + +AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, + const Twine &Name, Instruction *InsertBefore) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, getAISize(Ty->getContext(), ArraySize), InsertBefore) { setAlignment(Align); assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); setName(Name); } -AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, - unsigned Align, const Twine &Name, - BasicBlock *InsertAtEnd) - : UnaryInstruction(PointerType::getUnqual(Ty), iTy, +AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, + const Twine &Name, BasicBlock *InsertAtEnd) + : UnaryInstruction(PointerType::getUnqual(Ty), Alloca, getAISize(Ty->getContext(), ArraySize), InsertAtEnd) { setAlignment(Align); assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); @@ -874,22 +953,22 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, } // Out of line virtual method, so the vtable, etc has a home. -AllocationInst::~AllocationInst() { +AllocaInst::~AllocaInst() { } -void AllocationInst::setAlignment(unsigned Align) { +void AllocaInst::setAlignment(unsigned Align) { assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); SubclassData = Log2_32(Align) + 1; assert(getAlignment() == Align && "Alignment representation error!"); } -bool AllocationInst::isArrayAllocation() const { +bool AllocaInst::isArrayAllocation() const { if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0))) return CI->getZExtValue() != 1; return true; } -const Type *AllocationInst::getAllocatedType() const { +const Type *AllocaInst::getAllocatedType() const { return getType()->getElementType(); } @@ -906,28 +985,6 @@ bool AllocaInst::isStaticAlloca() const { } //===----------------------------------------------------------------------===// -// FreeInst Implementation -//===----------------------------------------------------------------------===// - -void FreeInst::AssertOK() { - assert(isa<PointerType>(getOperand(0)->getType()) && - "Can not free something of nonpointer type!"); -} - -FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) - : UnaryInstruction(Type::getVoidTy(Ptr->getContext()), - Free, Ptr, InsertBefore) { - AssertOK(); -} - -FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd) - : UnaryInstruction(Type::getVoidTy(Ptr->getContext()), - Free, Ptr, InsertAtEnd) { - AssertOK(); -} - - -//===----------------------------------------------------------------------===// // LoadInst Implementation //===----------------------------------------------------------------------===// @@ -2780,17 +2837,6 @@ ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) { } } -bool ICmpInst::isSignedPredicate(Predicate pred) { - switch (pred) { - default: assert(! "Unknown icmp predicate!"); - case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE: - return true; - case ICMP_EQ: case ICMP_NE: case ICMP_UGT: case ICMP_ULT: - case ICMP_UGE: case ICMP_ULE: - return false; - } -} - /// Initialize a set of values that all satisfy the condition with C. /// ConstantRange @@ -2864,7 +2910,7 @@ bool CmpInst::isUnsigned(unsigned short predicate) { } } -bool CmpInst::isSigned(unsigned short predicate){ +bool CmpInst::isSigned(unsigned short predicate) { switch (predicate) { default: return false; case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT: @@ -2890,6 +2936,23 @@ bool CmpInst::isUnordered(unsigned short predicate) { } } +bool CmpInst::isTrueWhenEqual(unsigned short predicate) { + switch(predicate) { + default: return false; + case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE: + case FCMP_TRUE: case FCMP_UEQ: case FCMP_UGE: case FCMP_ULE: return true; + } +} + +bool CmpInst::isFalseWhenEqual(unsigned short predicate) { + switch(predicate) { + case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT: + case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true; + default: return false; + } +} + + //===----------------------------------------------------------------------===// // SwitchInst Implementation //===----------------------------------------------------------------------===// @@ -3023,364 +3086,272 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) { setSuccessor(idx, B); } +//===----------------------------------------------------------------------===// +// SwitchInst Implementation +//===----------------------------------------------------------------------===// + +void IndirectBrInst::init(Value *Address, unsigned NumDests) { + assert(Address && isa<PointerType>(Address->getType()) && + "Address of indirectbr must be a pointer"); + ReservedSpace = 1+NumDests; + NumOperands = 1; + OperandList = allocHungoffUses(ReservedSpace); + + OperandList[0] = Address; +} + + +/// resizeOperands - resize operands - This adjusts the length of the operands +/// list according to the following behavior: +/// 1. If NumOps == 0, grow the operand list in response to a push_back style +/// of operation. This grows the number of ops by 2 times. +/// 2. If NumOps > NumOperands, reserve space for NumOps operands. +/// 3. If NumOps == NumOperands, trim the reserved space. +/// +void IndirectBrInst::resizeOperands(unsigned NumOps) { + unsigned e = getNumOperands(); + if (NumOps == 0) { + NumOps = e*2; + } else if (NumOps*2 > NumOperands) { + // No resize needed. + if (ReservedSpace >= NumOps) return; + } else if (NumOps == NumOperands) { + if (ReservedSpace == NumOps) return; + } else { + return; + } + + ReservedSpace = NumOps; + Use *NewOps = allocHungoffUses(NumOps); + Use *OldOps = OperandList; + for (unsigned i = 0; i != e; ++i) + NewOps[i] = OldOps[i]; + OperandList = NewOps; + if (OldOps) Use::zap(OldOps, OldOps + e, true); +} + +IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases, + Instruction *InsertBefore) +: TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr, + 0, 0, InsertBefore) { + init(Address, NumCases); +} + +IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases, + BasicBlock *InsertAtEnd) +: TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr, + 0, 0, InsertAtEnd) { + init(Address, NumCases); +} + +IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI) + : TerminatorInst(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr, + allocHungoffUses(IBI.getNumOperands()), + IBI.getNumOperands()) { + Use *OL = OperandList, *InOL = IBI.OperandList; + for (unsigned i = 0, E = IBI.getNumOperands(); i != E; ++i) + OL[i] = InOL[i]; + SubclassOptionalData = IBI.SubclassOptionalData; +} + +IndirectBrInst::~IndirectBrInst() { + dropHungoffUses(OperandList); +} + +/// addDestination - Add a destination. +/// +void IndirectBrInst::addDestination(BasicBlock *DestBB) { + unsigned OpNo = NumOperands; + if (OpNo+1 > ReservedSpace) + resizeOperands(0); // Get more space! + // Initialize some new operands. + assert(OpNo < ReservedSpace && "Growing didn't work!"); + NumOperands = OpNo+1; + OperandList[OpNo] = DestBB; +} + +/// removeDestination - This method removes the specified successor from the +/// indirectbr instruction. +void IndirectBrInst::removeDestination(unsigned idx) { + assert(idx < getNumOperands()-1 && "Successor index out of range!"); + + unsigned NumOps = getNumOperands(); + Use *OL = OperandList; + + // Replace this value with the last one. + OL[idx+1] = OL[NumOps-1]; + + // Nuke the last value. + OL[NumOps-1].set(0); + NumOperands = NumOps-1; +} + +BasicBlock *IndirectBrInst::getSuccessorV(unsigned idx) const { + return getSuccessor(idx); +} +unsigned IndirectBrInst::getNumSuccessorsV() const { + return getNumSuccessors(); +} +void IndirectBrInst::setSuccessorV(unsigned idx, BasicBlock *B) { + setSuccessor(idx, B); +} + +//===----------------------------------------------------------------------===// +// clone_impl() implementations +//===----------------------------------------------------------------------===// + // Define these methods here so vtables don't get emitted into every translation // unit that uses these classes. -GetElementPtrInst *GetElementPtrInst::clone() const { - GetElementPtrInst *New = new(getNumOperands()) GetElementPtrInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +GetElementPtrInst *GetElementPtrInst::clone_impl() const { + return new (getNumOperands()) GetElementPtrInst(*this); } -BinaryOperator *BinaryOperator::clone() const { - BinaryOperator *New = Create(getOpcode(), Op<0>(), Op<1>()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +BinaryOperator *BinaryOperator::clone_impl() const { + return Create(getOpcode(), Op<0>(), Op<1>()); } -FCmpInst* FCmpInst::clone() const { - FCmpInst *New = new FCmpInst(getPredicate(), Op<0>(), Op<1>()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; -} -ICmpInst* ICmpInst::clone() const { - ICmpInst *New = new ICmpInst(getPredicate(), Op<0>(), Op<1>()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +FCmpInst* FCmpInst::clone_impl() const { + return new FCmpInst(getPredicate(), Op<0>(), Op<1>()); } -ExtractValueInst *ExtractValueInst::clone() const { - ExtractValueInst *New = new ExtractValueInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; -} -InsertValueInst *InsertValueInst::clone() const { - InsertValueInst *New = new InsertValueInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +ICmpInst* ICmpInst::clone_impl() const { + return new ICmpInst(getPredicate(), Op<0>(), Op<1>()); } -AllocaInst *AllocaInst::clone() const { - AllocaInst *New = new AllocaInst(getAllocatedType(), - (Value*)getOperand(0), - getAlignment()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +ExtractValueInst *ExtractValueInst::clone_impl() const { + return new ExtractValueInst(*this); } -FreeInst *FreeInst::clone() const { - FreeInst *New = new FreeInst(getOperand(0)); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +InsertValueInst *InsertValueInst::clone_impl() const { + return new InsertValueInst(*this); } -LoadInst *LoadInst::clone() const { - LoadInst *New = new LoadInst(getOperand(0), - Twine(), isVolatile(), - getAlignment()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +AllocaInst *AllocaInst::clone_impl() const { + return new AllocaInst(getAllocatedType(), + (Value*)getOperand(0), + getAlignment()); } -StoreInst *StoreInst::clone() const { - StoreInst *New = new StoreInst(getOperand(0), getOperand(1), - isVolatile(), getAlignment()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +LoadInst *LoadInst::clone_impl() const { + return new LoadInst(getOperand(0), + Twine(), isVolatile(), + getAlignment()); } -TruncInst *TruncInst::clone() const { - TruncInst *New = new TruncInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +StoreInst *StoreInst::clone_impl() const { + return new StoreInst(getOperand(0), getOperand(1), + isVolatile(), getAlignment()); } -ZExtInst *ZExtInst::clone() const { - ZExtInst *New = new ZExtInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +TruncInst *TruncInst::clone_impl() const { + return new TruncInst(getOperand(0), getType()); } -SExtInst *SExtInst::clone() const { - SExtInst *New = new SExtInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +ZExtInst *ZExtInst::clone_impl() const { + return new ZExtInst(getOperand(0), getType()); } -FPTruncInst *FPTruncInst::clone() const { - FPTruncInst *New = new FPTruncInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +SExtInst *SExtInst::clone_impl() const { + return new SExtInst(getOperand(0), getType()); } -FPExtInst *FPExtInst::clone() const { - FPExtInst *New = new FPExtInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +FPTruncInst *FPTruncInst::clone_impl() const { + return new FPTruncInst(getOperand(0), getType()); } -UIToFPInst *UIToFPInst::clone() const { - UIToFPInst *New = new UIToFPInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +FPExtInst *FPExtInst::clone_impl() const { + return new FPExtInst(getOperand(0), getType()); } -SIToFPInst *SIToFPInst::clone() const { - SIToFPInst *New = new SIToFPInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +UIToFPInst *UIToFPInst::clone_impl() const { + return new UIToFPInst(getOperand(0), getType()); } -FPToUIInst *FPToUIInst::clone() const { - FPToUIInst *New = new FPToUIInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +SIToFPInst *SIToFPInst::clone_impl() const { + return new SIToFPInst(getOperand(0), getType()); } -FPToSIInst *FPToSIInst::clone() const { - FPToSIInst *New = new FPToSIInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +FPToUIInst *FPToUIInst::clone_impl() const { + return new FPToUIInst(getOperand(0), getType()); } -PtrToIntInst *PtrToIntInst::clone() const { - PtrToIntInst *New = new PtrToIntInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +FPToSIInst *FPToSIInst::clone_impl() const { + return new FPToSIInst(getOperand(0), getType()); } -IntToPtrInst *IntToPtrInst::clone() const { - IntToPtrInst *New = new IntToPtrInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +PtrToIntInst *PtrToIntInst::clone_impl() const { + return new PtrToIntInst(getOperand(0), getType()); } -BitCastInst *BitCastInst::clone() const { - BitCastInst *New = new BitCastInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +IntToPtrInst *IntToPtrInst::clone_impl() const { + return new IntToPtrInst(getOperand(0), getType()); } -CallInst *CallInst::clone() const { - CallInst *New = new(getNumOperands()) CallInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +BitCastInst *BitCastInst::clone_impl() const { + return new BitCastInst(getOperand(0), getType()); } -SelectInst *SelectInst::clone() const { - SelectInst *New = SelectInst::Create(getOperand(0), - getOperand(1), - getOperand(2)); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +CallInst *CallInst::clone_impl() const { + return new(getNumOperands()) CallInst(*this); } -VAArgInst *VAArgInst::clone() const { - VAArgInst *New = new VAArgInst(getOperand(0), getType()); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +SelectInst *SelectInst::clone_impl() const { + return SelectInst::Create(getOperand(0), getOperand(1), getOperand(2)); } -ExtractElementInst *ExtractElementInst::clone() const { - ExtractElementInst *New = ExtractElementInst::Create(getOperand(0), - getOperand(1)); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +VAArgInst *VAArgInst::clone_impl() const { + return new VAArgInst(getOperand(0), getType()); } -InsertElementInst *InsertElementInst::clone() const { - InsertElementInst *New = InsertElementInst::Create(getOperand(0), - getOperand(1), - getOperand(2)); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +ExtractElementInst *ExtractElementInst::clone_impl() const { + return ExtractElementInst::Create(getOperand(0), getOperand(1)); } -ShuffleVectorInst *ShuffleVectorInst::clone() const { - ShuffleVectorInst *New = new ShuffleVectorInst(getOperand(0), - getOperand(1), - getOperand(2)); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +InsertElementInst *InsertElementInst::clone_impl() const { + return InsertElementInst::Create(getOperand(0), + getOperand(1), + getOperand(2)); } -PHINode *PHINode::clone() const { - PHINode *New = new PHINode(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +ShuffleVectorInst *ShuffleVectorInst::clone_impl() const { + return new ShuffleVectorInst(getOperand(0), + getOperand(1), + getOperand(2)); } -ReturnInst *ReturnInst::clone() const { - ReturnInst *New = new(getNumOperands()) ReturnInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +PHINode *PHINode::clone_impl() const { + return new PHINode(*this); } -BranchInst *BranchInst::clone() const { +ReturnInst *ReturnInst::clone_impl() const { + return new(getNumOperands()) ReturnInst(*this); +} + +BranchInst *BranchInst::clone_impl() const { unsigned Ops(getNumOperands()); - BranchInst *New = new(Ops, Ops == 1) BranchInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; + return new(Ops, Ops == 1) BranchInst(*this); } -SwitchInst *SwitchInst::clone() const { - SwitchInst *New = new SwitchInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +SwitchInst *SwitchInst::clone_impl() const { + return new SwitchInst(*this); } -InvokeInst *InvokeInst::clone() const { - InvokeInst *New = new(getNumOperands()) InvokeInst(*this); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) { - LLVMContext &Context = getContext(); - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - } - return New; +IndirectBrInst *IndirectBrInst::clone_impl() const { + return new IndirectBrInst(*this); +} + + +InvokeInst *InvokeInst::clone_impl() const { + return new(getNumOperands()) InvokeInst(*this); } -UnwindInst *UnwindInst::clone() const { +UnwindInst *UnwindInst::clone_impl() const { LLVMContext &Context = getContext(); - UnwindInst *New = new UnwindInst(Context); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - return New; + return new UnwindInst(Context); } -UnreachableInst *UnreachableInst::clone() const { +UnreachableInst *UnreachableInst::clone_impl() const { LLVMContext &Context = getContext(); - UnreachableInst *New = new UnreachableInst(Context); - New->SubclassOptionalData = SubclassOptionalData; - if (hasMetadata()) - Context.pImpl->TheMetadata.ValueIsCloned(this, New); - return New; + return new UnreachableInst(Context); } diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 84902d53559eb..1c3244ba4dc26 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -22,8 +22,6 @@ #include "llvm/Metadata.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" -#include "llvm/System/Mutex.h" -#include "llvm/System/RWMutex.h" #include "llvm/Assembly/Writer.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" @@ -108,41 +106,32 @@ public: FoldingSet<MDNode> MDNodeSet; - ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants; + ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants; - typedef ValueMap<std::vector<Constant*>, ArrayType, + typedef ConstantUniqueMap<std::vector<Constant*>, ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy; ArrayConstantsTy ArrayConstants; - typedef ValueMap<std::vector<Constant*>, StructType, - ConstantStruct, true /*largekey*/> StructConstantsTy; + typedef ConstantUniqueMap<std::vector<Constant*>, StructType, + ConstantStruct, true /*largekey*/> StructConstantsTy; StructConstantsTy StructConstants; - typedef ValueMap<std::vector<Constant*>, VectorType, - ConstantVector> VectorConstantsTy; + typedef ConstantUniqueMap<std::vector<Constant*>, VectorType, + ConstantVector> VectorConstantsTy; VectorConstantsTy VectorConstants; - ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants; + ConstantUniqueMap<char, PointerType, ConstantPointerNull> NullPtrConstants; - ValueMap<char, Type, UndefValue> UndefValueConstants; + ConstantUniqueMap<char, Type, UndefValue> UndefValueConstants; - ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants; + DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; + ConstantUniqueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants; ConstantInt *TheTrueVal; ConstantInt *TheFalseVal; - // Lock used for guarding access to the leak detector - sys::SmartMutex<true> LLVMObjectsLock; LeakDetectorImpl<Value> LLVMObjects; - // Lock used for guarding access to the type maps. - sys::SmartMutex<true> TypeMapLock; - - // Recursive lock used for guarding access to AbstractTypeUsers. - // NOTE: The true template parameter means this will no-op when we're not in - // multithreaded mode. - sys::SmartMutex<true> AbstractTypeUsersLock; - // Basic type instances. const Type VoidTy; const Type LabelTy; diff --git a/lib/VMCore/LeakDetector.cpp b/lib/VMCore/LeakDetector.cpp index 5ebd4f5ac03b3..a44f61d822eee 100644 --- a/lib/VMCore/LeakDetector.cpp +++ b/lib/VMCore/LeakDetector.cpp @@ -36,7 +36,6 @@ void LeakDetector::addGarbageObjectImpl(void *Object) { void LeakDetector::addGarbageObjectImpl(const Value *Object) { LLVMContextImpl *pImpl = Object->getContext().pImpl; - sys::SmartScopedLock<true> Lock(pImpl->LLVMObjectsLock); pImpl->LLVMObjects.addGarbage(Object); } @@ -47,7 +46,6 @@ void LeakDetector::removeGarbageObjectImpl(void *Object) { void LeakDetector::removeGarbageObjectImpl(const Value *Object) { LLVMContextImpl *pImpl = Object->getContext().pImpl; - sys::SmartScopedLock<true> Lock(pImpl->LLVMObjectsLock); pImpl->LLVMObjects.removeGarbage(Object); } @@ -55,7 +53,6 @@ void LeakDetector::checkForGarbageImpl(LLVMContext &Context, const std::string &Message) { LLVMContextImpl *pImpl = Context.pImpl; sys::SmartScopedLock<true> Lock(*ObjectsLock); - sys::SmartScopedLock<true> CLock(pImpl->LLVMObjectsLock); Objects->setName("GENERIC"); pImpl->LLVMObjects.setName("LLVM"); diff --git a/lib/VMCore/LeaksContext.h b/lib/VMCore/LeaksContext.h index b0c3a14fe84aa..bd10a479ae2a0 100644 --- a/lib/VMCore/LeaksContext.h +++ b/lib/VMCore/LeaksContext.h @@ -14,7 +14,6 @@ #include "llvm/Value.h" #include "llvm/ADT/SmallPtrSet.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; template <class T> diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index ad9653f1b958f..4fadfed503be0 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -344,20 +344,22 @@ getMDs(const Instruction *Inst, SmallVectorImpl<MDPairTy> &MDs) const { MDStoreTy::iterator I = MetadataStore.find(Inst); if (I == MetadataStore.end()) return; + MDs.resize(I->second.size()); for (MDMapTy::iterator MI = I->second.begin(), ME = I->second.end(); MI != ME; ++MI) - MDs.push_back(std::make_pair(MI->first, MI->second)); - std::sort(MDs.begin(), MDs.end()); + // MD kinds are numbered from 1. + MDs[MI->first - 1] = std::make_pair(MI->first, MI->second); } /// getHandlerNames - Populate client supplied smallvector using custome /// metadata name and ID. void MetadataContextImpl:: getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&Names) const { + Names.resize(MDHandlerNames.size()); for (StringMap<unsigned>::const_iterator I = MDHandlerNames.begin(), E = MDHandlerNames.end(); I != E; ++I) - Names.push_back(std::make_pair(I->second, I->first())); - std::sort(Names.begin(), Names.end()); + // MD Handlers are numbered from 1. + Names[I->second - 1] = std::make_pair(I->second, I->first()); } /// ValueIsCloned - This handler is used to update metadata store diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index f10bc6f5ef6f7..eb097ed1fc51d 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -105,8 +105,7 @@ namespace { /// BBPassManager manages BasicBlockPass. It batches all the /// pass together and sequence them to process one basic block before /// processing next basic block. -class VISIBILITY_HIDDEN BBPassManager : public PMDataManager, - public FunctionPass { +class BBPassManager : public PMDataManager, public FunctionPass { public: static char ID; @@ -367,7 +366,7 @@ namespace { static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex; -class VISIBILITY_HIDDEN TimingInfo { +class TimingInfo { std::map<Pass*, Timer> TimingData; TimerGroup TG; diff --git a/lib/VMCore/PrintModulePass.cpp b/lib/VMCore/PrintModulePass.cpp index 0a7f4497a8e6a..3d4f19df05d8a 100644 --- a/lib/VMCore/PrintModulePass.cpp +++ b/lib/VMCore/PrintModulePass.cpp @@ -16,13 +16,12 @@ #include "llvm/Function.h" #include "llvm/Module.h" #include "llvm/Pass.h" -#include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { - class VISIBILITY_HIDDEN PrintModulePass : public ModulePass { + class PrintModulePass : public ModulePass { raw_ostream *Out; // raw_ostream to print on bool DeleteStream; // Delete the ostream in our dtor? public: diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 7afbc682d15d7..739c463d91b4f 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -27,8 +27,6 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/Mutex.h" -#include "llvm/System/RWMutex.h" #include "llvm/System/Threading.h" #include <algorithm> #include <cstdarg> @@ -768,7 +766,6 @@ const IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) { // First, see if the type is already in the table, for which // a reader lock suffices. - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); ITy = pImpl->IntegerTypes.get(IVT); if (!ITy) { @@ -810,7 +807,6 @@ FunctionType *FunctionType::get(const Type *ReturnType, LLVMContextImpl *pImpl = ReturnType->getContext().pImpl; - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); FT = pImpl->FunctionTypes.get(VT); if (!FT) { @@ -835,7 +831,6 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) { LLVMContextImpl *pImpl = ElementType->getContext().pImpl; - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); AT = pImpl->ArrayTypes.get(AVT); if (!AT) { @@ -861,7 +856,6 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) { LLVMContextImpl *pImpl = ElementType->getContext().pImpl; - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); PT = pImpl->VectorTypes.get(PVT); if (!PT) { @@ -890,7 +884,6 @@ StructType *StructType::get(LLVMContext &Context, LLVMContextImpl *pImpl = Context.pImpl; - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); ST = pImpl->StructTypes.get(STV); if (!ST) { @@ -938,7 +931,6 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) { LLVMContextImpl *pImpl = ValueType->getContext().pImpl; - sys::SmartScopedLock<true> L(pImpl->TypeMapLock); PT = pImpl->PointerTypes.get(PVT); if (!PT) { @@ -970,10 +962,7 @@ bool PointerType::isValidElementType(const Type *ElemTy) { // it. This function is called primarily by the PATypeHandle class. void Type::addAbstractTypeUser(AbstractTypeUser *U) const { assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!"); - LLVMContextImpl *pImpl = getContext().pImpl; - pImpl->AbstractTypeUsersLock.acquire(); AbstractTypeUsers.push_back(U); - pImpl->AbstractTypeUsersLock.release(); } @@ -983,8 +972,6 @@ void Type::addAbstractTypeUser(AbstractTypeUser *U) const { // is annihilated, because there is no way to get a reference to it ever again. // void Type::removeAbstractTypeUser(AbstractTypeUser *U) const { - LLVMContextImpl *pImpl = getContext().pImpl; - pImpl->AbstractTypeUsersLock.acquire(); // Search from back to front because we will notify users from back to // front. Also, it is likely that there will be a stack like behavior to @@ -1013,7 +1000,6 @@ void Type::removeAbstractTypeUser(AbstractTypeUser *U) const { this->destroy(); } - pImpl->AbstractTypeUsersLock.release(); } // unlockedRefineAbstractTypeTo - This function is used when it is discovered @@ -1065,7 +1051,6 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) { // will not cause users to drop off of the use list. If we resolve to ourself // we succeed! // - pImpl->AbstractTypeUsersLock.acquire(); while (!AbstractTypeUsers.empty() && NewTy != this) { AbstractTypeUser *User = AbstractTypeUsers.back(); @@ -1081,7 +1066,6 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) { assert(AbstractTypeUsers.size() != OldSize && "AbsTyUser did not remove self from user list!"); } - pImpl->AbstractTypeUsersLock.release(); // If we were successful removing all users from the type, 'this' will be // deleted when the last PATypeHolder is destroyed or updated from this type. @@ -1095,7 +1079,6 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) { void DerivedType::refineAbstractTypeTo(const Type *NewType) { // All recursive calls will go through unlockedRefineAbstractTypeTo, // to avoid deadlock problems. - sys::SmartScopedLock<true> L(NewType->getContext().pImpl->TypeMapLock); unlockedRefineAbstractTypeTo(NewType); } @@ -1107,9 +1090,6 @@ void DerivedType::notifyUsesThatTypeBecameConcrete() { DEBUG(errs() << "typeIsREFINED type: " << (void*)this << " " << *this <<"\n"); #endif - LLVMContextImpl *pImpl = getContext().pImpl; - - pImpl->AbstractTypeUsersLock.acquire(); unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize; while (!AbstractTypeUsers.empty()) { AbstractTypeUser *ATU = AbstractTypeUsers.back(); @@ -1118,7 +1098,6 @@ void DerivedType::notifyUsesThatTypeBecameConcrete() { assert(AbstractTypeUsers.size() < OldSize-- && "AbstractTypeUser did not remove itself from the use list!"); } - pImpl->AbstractTypeUsersLock.release(); } // refineAbstractType - Called when a contained type is found to be more diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp index f31ea6693e0b8..3440a77946970 100644 --- a/lib/VMCore/TypeSymbolTable.cpp +++ b/lib/VMCore/TypeSymbolTable.cpp @@ -17,16 +17,12 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/RWMutex.h" -#include "llvm/System/Threading.h" #include <algorithm> using namespace llvm; #define DEBUG_SYMBOL_TABLE 0 #define DEBUG_ABSTYPE 0 -static ManagedStatic<sys::SmartRWMutex<true> > TypeSymbolTableLock; - TypeSymbolTable::~TypeSymbolTable() { // Drop all abstract type references in the type plane... for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) { @@ -38,8 +34,6 @@ TypeSymbolTable::~TypeSymbolTable() { std::string TypeSymbolTable::getUniqueName(const StringRef &BaseName) const { std::string TryName = BaseName; - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); - const_iterator End = tmap.end(); // See if the name exists @@ -50,8 +44,6 @@ std::string TypeSymbolTable::getUniqueName(const StringRef &BaseName) const { // lookup a type by name - returns null on failure Type* TypeSymbolTable::lookup(const StringRef &Name) const { - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); - const_iterator TI = tmap.find(Name); Type* result = 0; if (TI != tmap.end()) @@ -59,21 +51,9 @@ Type* TypeSymbolTable::lookup(const StringRef &Name) const { return result; } -TypeSymbolTable::iterator TypeSymbolTable::find(const StringRef &Name) { - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); - return tmap.find(Name); -} - -TypeSymbolTable::const_iterator -TypeSymbolTable::find(const StringRef &Name) const { - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); - return tmap.find(Name); -} // remove - Remove a type from the symbol table... Type* TypeSymbolTable::remove(iterator Entry) { - TypeSymbolTableLock->writer_acquire(); - assert(Entry != tmap.end() && "Invalid entry to remove!"); const Type* Result = Entry->second; @@ -84,8 +64,6 @@ Type* TypeSymbolTable::remove(iterator Entry) { tmap.erase(Entry); - TypeSymbolTableLock->writer_release(); - // If we are removing an abstract type, remove the symbol table from it's use // list... if (Result->isAbstract()) { @@ -105,8 +83,6 @@ Type* TypeSymbolTable::remove(iterator Entry) { void TypeSymbolTable::insert(const StringRef &Name, const Type* T) { assert(T && "Can't insert null type into symbol table!"); - TypeSymbolTableLock->writer_acquire(); - if (tmap.insert(std::make_pair(Name, T)).second) { // Type inserted fine with no conflict. @@ -132,8 +108,6 @@ void TypeSymbolTable::insert(const StringRef &Name, const Type* T) { tmap.insert(make_pair(UniqueName, T)); } - TypeSymbolTableLock->writer_release(); - // If we are adding an abstract type, add the symbol table to it's use list. if (T->isAbstract()) { cast<DerivedType>(T)->addAbstractTypeUser(this); @@ -146,8 +120,6 @@ void TypeSymbolTable::insert(const StringRef &Name, const Type* T) { // This function is called when one of the types in the type plane are refined void TypeSymbolTable::refineAbstractType(const DerivedType *OldType, const Type *NewType) { - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); - // Loop over all of the types in the symbol table, replacing any references // to OldType with references to NewType. Note that there may be multiple // occurrences, and although we only need to remove one at a time, it's @@ -177,7 +149,6 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) { // Loop over all of the types in the symbol table, dropping any abstract // type user entries for AbsTy which occur because there are names for the // type. - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); for (iterator TI = begin(), TE = end(); TI != TE; ++TI) if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy))) AbsTy->removeAbstractTypeUser(this); @@ -191,8 +162,6 @@ static void DumpTypes(const std::pair<const std::string, const Type*>& T ) { void TypeSymbolTable::dump() const { errs() << "TypeSymbolPlane: "; - sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock); for_each(tmap.begin(), tmap.end(), DumpTypes); } -// vim: sw=2 ai diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 35ec9bef9125c..826e8a10b5e46 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -27,8 +27,6 @@ #include "llvm/Support/LeakDetector.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ValueHandle.h" -#include "llvm/System/RWMutex.h" -#include "llvm/System/Threading.h" #include "llvm/ADT/DenseMap.h" #include <algorithm> using namespace llvm; diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 3bfd47c67c342..5990e481686c9 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -62,7 +62,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> @@ -70,7 +69,7 @@ using namespace llvm; namespace { // Anonymous namespace for class - struct VISIBILITY_HIDDEN PreVerifier : public FunctionPass { + struct PreVerifier : public FunctionPass { static char ID; // Pass ID, replacement for typeid PreVerifier() : FunctionPass(&ID) { } @@ -321,7 +320,7 @@ namespace { void visitUserOp1(Instruction &I); void visitUserOp2(Instruction &I) { visitUserOp1(I); } void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI); - void visitAllocationInst(AllocationInst &AI); + void visitAllocaInst(AllocaInst &AI); void visitExtractValueInst(ExtractValueInst &EVI); void visitInsertValueInst(InsertValueInst &IVI); @@ -659,6 +658,12 @@ void Verifier::visitFunction(Function &F) { BasicBlock *Entry = &F.getEntryBlock(); Assert1(pred_begin(Entry) == pred_end(Entry), "Entry block to function must not have predecessors!", Entry); + + // The address of the entry block cannot be taken, unless it is dead. + if (Entry->hasAddressTaken()) { + Assert1(!BlockAddress::get(Entry)->isConstantUsed(), + "blockaddress may not be used with the entry block!", Entry); + } } // If this function is actually an intrinsic, verify that it is only used in @@ -1282,7 +1287,7 @@ void Verifier::visitStoreInst(StoreInst &SI) { visitInstruction(SI); } -void Verifier::visitAllocationInst(AllocationInst &AI) { +void Verifier::visitAllocaInst(AllocaInst &AI) { const PointerType *PTy = AI.getType(); Assert1(PTy->getAddressSpace() == 0, "Allocation instruction pointer not in the generic address space!", |