aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Function.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-04-22 05:46:44 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-04-22 05:46:44 +0000
commit4f859aa532dbf061736f9c23e0d0882b5cdfe566 (patch)
tree5b03ace46223602b455c373f25432ef52f8ea2b4 /lib/VMCore/Function.cpp
parent3b87d6a7b57277a17e75ec83759ea95e0579e219 (diff)
For PR1146:
Make ParamAttrsList objects unique. You can no longer directly create or destroy them but instead must go through the ParamAttrsList::get() interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36327 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Function.cpp')
-rw-r--r--lib/VMCore/Function.cpp49
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index dbd21481c0..b6ff70d6a3 100644
--- a/lib/VMCore/Function.cpp
+++ b/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;
}
//===----------------------------------------------------------------------===//