diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/llvmAsmParser.y | 99 | ||||
-rw-r--r-- | llvm/lib/Bytecode/Reader/Reader.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/VMCore/AsmWriter.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/VMCore/Function.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/VMCore/Type.cpp | 44 |
6 files changed, 113 insertions, 106 deletions
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y index a0c2e25bc5b..9b5cc5abfd5 100644 --- a/llvm/lib/AsmParser/llvmAsmParser.y +++ b/llvm/lib/AsmParser/llvmAsmParser.y @@ -1299,24 +1299,28 @@ Types } | Types '(' ArgTypeListI ')' OptFuncAttrs { std::vector<const Type*> Params; - ParamAttrsList Attrs; - if ($5 != ParamAttr::None) - Attrs.addAttributes(0, $5); + ParamAttrsVector Attrs; + if ($5 != ParamAttr::None) { + ParamAttrsWithIndex X; X.index = 0; X.attrs = $5; + Attrs.push_back(X); + } unsigned index = 1; TypeWithAttrsList::iterator I = $3->begin(), E = $3->end(); for (; I != E; ++I, ++index) { const Type *Ty = I->Ty->get(); Params.push_back(Ty); if (Ty != Type::VoidTy) - if (I->Attrs != ParamAttr::None) - Attrs.addAttributes(index, I->Attrs); + if (I->Attrs != ParamAttr::None) { + ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs; + Attrs.push_back(X); + } } bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); ParamAttrsList *ActualAttrs = 0; if (!Attrs.empty()) - ActualAttrs = new ParamAttrsList(Attrs); + ActualAttrs = ParamAttrsList::get(Attrs); FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, ActualAttrs); delete $3; // Delete the argument list delete $1; // Delete the return type handle @@ -1325,24 +1329,28 @@ Types } | VOID '(' ArgTypeListI ')' OptFuncAttrs { std::vector<const Type*> Params; - ParamAttrsList Attrs; - if ($5 != ParamAttr::None) - Attrs.addAttributes(0, $5); + ParamAttrsVector Attrs; + if ($5 != ParamAttr::None) { + ParamAttrsWithIndex X; X.index = 0; X.attrs = $5; + Attrs.push_back(X); + } TypeWithAttrsList::iterator I = $3->begin(), E = $3->end(); unsigned index = 1; for ( ; I != E; ++I, ++index) { const Type* Ty = I->Ty->get(); Params.push_back(Ty); if (Ty != Type::VoidTy) - if (I->Attrs != ParamAttr::None) - Attrs.addAttributes(index, I->Attrs); + if (I->Attrs != ParamAttr::None) { + ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs; + Attrs.push_back(X); + } } bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); ParamAttrsList *ActualAttrs = 0; if (!Attrs.empty()) - ActualAttrs = new ParamAttrsList(Attrs); + ActualAttrs = ParamAttrsList::get(Attrs); FunctionType *FT = FunctionType::get($1, Params, isVarArg, ActualAttrs); delete $3; // Delete the argument list @@ -2135,9 +2143,11 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' GEN_ERROR("Reference to abstract result: "+ $2->get()->getDescription()); std::vector<const Type*> ParamTypeList; - ParamAttrsList ParamAttrs; - if ($7 != ParamAttr::None) - ParamAttrs.addAttributes(0, $7); + ParamAttrsVector Attrs; + if ($7 != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $7; + Attrs.push_back(PAWI); + } if ($5) { // If there are arguments... unsigned index = 1; for (ArgListType::iterator I = $5->begin(); I != $5->end(); ++I, ++index) { @@ -2146,20 +2156,21 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' GEN_ERROR("Reference to abstract argument: " + Ty->getDescription()); ParamTypeList.push_back(Ty); if (Ty != Type::VoidTy) - if (I->Attrs != ParamAttr::None) - ParamAttrs.addAttributes(index, I->Attrs); + if (I->Attrs != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs; + Attrs.push_back(PAWI); + } } } bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy; if (isVarArg) ParamTypeList.pop_back(); - ParamAttrsList *ActualAttrs = 0; - if (!ParamAttrs.empty()) - ActualAttrs = new ParamAttrsList(ParamAttrs); + ParamAttrsList *PAL = 0; + if (!Attrs.empty()) + PAL = ParamAttrsList::get(Attrs); - FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg, - ActualAttrs); + FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg, PAL); const PointerType *PFT = PointerType::get(FT); delete $2; @@ -2490,9 +2501,11 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector<const Type*> ParamTypes; - ParamAttrsList ParamAttrs; - if ($8 != ParamAttr::None) - ParamAttrs.addAttributes(0, $8); + ParamAttrsVector Attrs; + if ($8 != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = 8; + Attrs.push_back(PAWI); + } ValueRefList::iterator I = $6->begin(), E = $6->end(); unsigned index = 1; for (; I != E; ++I, ++index) { @@ -2500,14 +2513,16 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... if (Ty == Type::VoidTy) GEN_ERROR("Short call syntax cannot be used with varargs"); ParamTypes.push_back(Ty); - if (I->Attrs != ParamAttr::None) - ParamAttrs.addAttributes(index, I->Attrs); + if (I->Attrs != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs; + Attrs.push_back(PAWI); + } } - ParamAttrsList *Attrs = 0; - if (!ParamAttrs.empty()) - Attrs = new ParamAttrsList(ParamAttrs); - Ty = FunctionType::get($3->get(), ParamTypes, false, Attrs); + ParamAttrsList *PAL = 0; + if (!Attrs.empty()) + PAL = ParamAttrsList::get(Attrs); + Ty = FunctionType::get($3->get(), ParamTypes, false, PAL); PFTy = PointerType::get(Ty); } @@ -2796,9 +2811,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { // Pull out the types of all of the arguments... std::vector<const Type*> ParamTypes; - ParamAttrsList ParamAttrs; - if ($8 != ParamAttr::None) - ParamAttrs.addAttributes(0, $8); + ParamAttrsVector Attrs; + if ($8 != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $8; + Attrs.push_back(PAWI); + } unsigned index = 1; ValueRefList::iterator I = $6->begin(), E = $6->end(); for (; I != E; ++I, ++index) { @@ -2806,15 +2823,17 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { if (Ty == Type::VoidTy) GEN_ERROR("Short call syntax cannot be used with varargs"); ParamTypes.push_back(Ty); - if (I->Attrs != ParamAttr::None) - ParamAttrs.addAttributes(index, I->Attrs); + if (I->Attrs != ParamAttr::None) { + ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs; + Attrs.push_back(PAWI); + } } - ParamAttrsList *Attrs = 0; - if (!ParamAttrs.empty()) - Attrs = new ParamAttrsList(ParamAttrs); + ParamAttrsList *PAL = 0; + if (!Attrs.empty()) + PAL = ParamAttrsList::get(Attrs); - Ty = FunctionType::get($3->get(), ParamTypes, false, Attrs); + Ty = FunctionType::get($3->get(), ParamTypes, false, PAL); PFTy = PointerType::get(Ty); } diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp index 49792693dcc..4cb67c31565 100644 --- a/llvm/lib/Bytecode/Reader/Reader.cpp +++ b/llvm/lib/Bytecode/Reader/Reader.cpp @@ -1078,16 +1078,18 @@ const Type *BytecodeReader::ParseType() { ParamAttrsList *BytecodeReader::ParseParamAttrsList() { unsigned NumAttrs = read_vbr_uint(); - ParamAttrsList *Attrs = 0; + ParamAttrsList *PAL = 0; if (NumAttrs) { - Attrs = new ParamAttrsList(); + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; while (NumAttrs--) { - uint16_t index = read_vbr_uint(); - uint16_t attrs = read_vbr_uint(); - Attrs->addAttributes(index, attrs); + PAWI.index = read_vbr_uint(); + PAWI.attrs = read_vbr_uint(); + Attrs.push_back(PAWI); } + PAL = ParamAttrsList::get(Attrs); } - return Attrs; + return PAL; } diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp index da3b1d7769b..63ec8e423e5 100644 --- a/llvm/lib/VMCore/AsmWriter.cpp +++ b/llvm/lib/VMCore/AsmWriter.cpp @@ -1383,6 +1383,17 @@ void Value::dump() const { print(*cerr.stream()); cerr << '\n'; } // Located here because so much of the needed functionality is here. void Type::dump() const { print(*cerr.stream()); cerr << '\n'; } +void +ParamAttrsList::dump() const { + cerr << "PAL[ "; + for (unsigned i = 0; i < attrs.size(); ++i) { + uint16_t index = getParamIndex(i); + uint16_t attrs = getParamAttrs(index); + cerr << "{" << index << "," << attrs << "} "; + } + cerr << "]\n"; +} + //===----------------------------------------------------------------------===// // SlotMachine Implementation //===----------------------------------------------------------------------===// diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index dbd21481c0c..b6ff70d6a33 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -16,6 +16,7 @@ #include "llvm/ParameterAttributes.h" #include "llvm/IntrinsicInst.h" #include "llvm/Support/LeakDetector.h" +#include "llvm/Support/ManagedStatic.h" #include "SymbolTableListTraitsImpl.h" #include "llvm/ADT/StringExtras.h" using namespace llvm; @@ -103,35 +104,29 @@ ParamAttrsList::getParamAttrsText(uint16_t Attrs) { return Result; } -void -ParamAttrsList::addAttributes(uint16_t Index, uint16_t Attrs) { - // First, try to replace an existing one - for (unsigned i = 0; i < attrs.size(); ++i) - if (attrs[i].index == Index) { - attrs[i].attrs |= Attrs; - return; - } - - // If not found, add a new one - ParamAttrsWithIndex Val; - Val.attrs = Attrs; - Val.index = Index; - attrs.push_back(Val); +void +ParamAttrsList::Profile(FoldingSetNodeID &ID) const { + for (unsigned i = 0; i < attrs.size(); ++i) { + unsigned val = attrs[i].attrs << 16 | attrs[i].index; + ID.AddInteger(val); + } } -void -ParamAttrsList::removeAttributes(uint16_t Index, uint16_t Attrs) { - // Find the index from which to remove the attributes - for (unsigned i = 0; i < attrs.size(); ++i) - if (attrs[i].index == Index) { - attrs[i].attrs &= ~Attrs; - if (attrs[i].attrs == ParamAttr::None) - attrs.erase(&attrs[i]); - return; - } - - // The index wasn't found above - assert(0 && "Index not found for removeAttributes"); +static ManagedStatic<FoldingSet<ParamAttrsList> > ParamAttrsLists; + +ParamAttrsList * +ParamAttrsList::get(const ParamAttrsVector &attrVec) { + assert(!attrVec.empty() && "Illegal to create empty ParamAttrsList"); + ParamAttrsList key(attrVec); + FoldingSetNodeID ID; + key.Profile(ID); + void *InsertPos; + ParamAttrsList* PAL = ParamAttrsLists->FindNodeOrInsertPos(ID, InsertPos); + if (!PAL) { + PAL = new ParamAttrsList(attrVec); + ParamAttrsLists->InsertNode(PAL, InsertPos); + } + return PAL; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index bfda46d9831..3bb565d22a7 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -186,7 +186,6 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { CallInst::~CallInst() { delete [] OperandList; - delete ParamAttrs; // FIXME: ParamAttrsList should be uniqued! } void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) { @@ -354,7 +353,6 @@ CallInst::CallInst(const CallInst &CI) InvokeInst::~InvokeInst() { delete [] OperandList; - delete ParamAttrs; // FIXME: ParamAttrsList should be uniqued! } void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, diff --git a/llvm/lib/VMCore/Type.cpp b/llvm/lib/VMCore/Type.cpp index 01232c41baf..3e5b7eb4911 100644 --- a/llvm/lib/VMCore/Type.cpp +++ b/llvm/lib/VMCore/Type.cpp @@ -643,20 +643,13 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2, return false; const ParamAttrsList *Attrs1 = FTy->getParamAttrs(); const ParamAttrsList *Attrs2 = FTy2->getParamAttrs(); - if ((!Attrs1 && Attrs2 && !Attrs2->empty()) || - (!Attrs2 && Attrs1 && !Attrs1->empty()) || + if ((!Attrs1 && Attrs2) || (!Attrs2 && Attrs1) || (Attrs1 && Attrs2 && (Attrs1->size() != Attrs2->size() || - (Attrs1->size() > 0 && - Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0))))) + (Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0))))) return false; - ParamAttrsList PAL1; - if (Attrs1) - PAL1 = *Attrs1; - ParamAttrsList PAL2; - if (Attrs2) - PAL2 = *Attrs2; + for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) { - if (PAL1.getParamAttrs(i+1) != PAL2.getParamAttrs(i+1)) + if (Attrs1 && Attrs1->getParamAttrs(i+1) != Attrs2->getParamAttrs(i+1)) return false; if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes)) return false; @@ -1065,15 +1058,10 @@ public: if (ParamAttrs) if (MTV.ParamAttrs) return *ParamAttrs < *MTV.ParamAttrs; - else if (ParamAttrs->empty()) - return true; else return false; else if (MTV.ParamAttrs) - if (MTV.ParamAttrs->empty()) - return false; - else - return true; + return true; return false; } }; @@ -1100,26 +1088,20 @@ FunctionType *FunctionType::get(const Type *ReturnType, ParamAttrsList *Attrs) { FunctionValType VT(ReturnType, Params, isVarArg, Attrs); - FunctionType *MT = FunctionTypes->get(VT); - if (MT) { - delete Attrs; // not needed any more - return MT; + FunctionType *FT = FunctionTypes->get(VT); + if (FT) { + return FT; } - - MT = (FunctionType*) new char[sizeof(FunctionType) + + FT = (FunctionType*) new char[sizeof(FunctionType) + sizeof(PATypeHandle)*(Params.size()+1)]; - new (MT) FunctionType(ReturnType, Params, isVarArg, Attrs); - FunctionTypes->add(VT, MT); + new (FT) FunctionType(ReturnType, Params, isVarArg, Attrs); + FunctionTypes->add(VT, FT); #ifdef DEBUG_MERGE_TYPES - DOUT << "Derived new type: " << MT << "\n"; + DOUT << "Derived new type: " << FT << "\n"; #endif - return MT; -} - -FunctionType::~FunctionType() { - delete ParamAttrs; + return FT; } bool FunctionType::isStructReturn() const { |