summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r--llvm/lib/VMCore/AsmWriter.cpp11
-rw-r--r--llvm/lib/VMCore/Function.cpp49
-rw-r--r--llvm/lib/VMCore/Instructions.cpp2
-rw-r--r--llvm/lib/VMCore/Type.cpp44
4 files changed, 46 insertions, 60 deletions
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 {
OpenPOWER on IntegriCloud