[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Function.cpp Instructions.cpp Type.cpp
Reid Spencer
reid at x10sys.com
Sat Apr 21 22:47:25 PDT 2007
Changes in directory llvm/lib/VMCore:
AsmWriter.cpp updated: 1.272 -> 1.273
Function.cpp updated: 1.124 -> 1.125
Instructions.cpp updated: 1.87 -> 1.88
Type.cpp updated: 1.184 -> 1.185
---
Log message:
For PR1146: http://llvm.org/PR1146 :
Make ParamAttrsList objects unique. You can no longer directly create or
destroy them but instead must go through the ParamAttrsList::get()
interface.
---
Diffs of the changes: (+46 -60)
AsmWriter.cpp | 11 +++++++++++
Function.cpp | 49 ++++++++++++++++++++++---------------------------
Instructions.cpp | 2 --
Type.cpp | 44 +++++++++++++-------------------------------
4 files changed, 46 insertions(+), 60 deletions(-)
Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.272 llvm/lib/VMCore/AsmWriter.cpp:1.273
--- llvm/lib/VMCore/AsmWriter.cpp:1.272 Sat Apr 21 13:36:27 2007
+++ llvm/lib/VMCore/AsmWriter.cpp Sun Apr 22 00:46:44 2007
@@ -1383,6 +1383,17 @@
// 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
//===----------------------------------------------------------------------===//
Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.124 llvm/lib/VMCore/Function.cpp:1.125
--- llvm/lib/VMCore/Function.cpp:1.124 Mon Apr 16 23:31:29 2007
+++ llvm/lib/VMCore/Function.cpp Sun Apr 22 00:46:44 2007
@@ -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 @@
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;
- }
+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);
+ }
+}
- // If not found, add a new one
- ParamAttrsWithIndex Val;
- Val.attrs = Attrs;
- Val.index = Index;
- attrs.push_back(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;
- }
+static ManagedStatic<FoldingSet<ParamAttrsList> > ParamAttrsLists;
- // The index wasn't found above
- assert(0 && "Index not found for removeAttributes");
+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;
}
//===----------------------------------------------------------------------===//
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.87 llvm/lib/VMCore/Instructions.cpp:1.88
--- llvm/lib/VMCore/Instructions.cpp:1.87 Sat Apr 21 13:36:27 2007
+++ llvm/lib/VMCore/Instructions.cpp Sun Apr 22 00:46:44 2007
@@ -186,7 +186,6 @@
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 @@
InvokeInst::~InvokeInst() {
delete [] OperandList;
- delete ParamAttrs; // FIXME: ParamAttrsList should be uniqued!
}
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.184 llvm/lib/VMCore/Type.cpp:1.185
--- llvm/lib/VMCore/Type.cpp:1.184 Fri Apr 20 17:33:47 2007
+++ llvm/lib/VMCore/Type.cpp Sun Apr 22 00:46:44 2007
@@ -643,20 +643,13 @@
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 @@
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 @@
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 {
More information about the llvm-commits
mailing list