Reimplement the parameter attributes support, phase #1. hilights:
1. There is now a "PAListPtr" class, which is a smart pointer around
the underlying uniqued parameter attribute list object, and manages
its refcount. It is now impossible to mess up the refcount.
2. PAListPtr is now the main interface to the underlying object, and
the underlying object is now completely opaque.
3. Implementation details like SmallVector and FoldingSet are now no
longer part of the interface.
4. You can create a PAListPtr with an arbitrary sequence of
ParamAttrsWithIndex's, no need to make a SmallVector of a specific
size (you can just use an array or scalar or vector if you wish).
5. All the client code that had to check for a null pointer before
dereferencing the pointer is simplified to just access the
PAListPtr directly.
6. The interfaces for adding attrs to a list and removing them is a
bit simpler.
Phase #2 will rename some stuff (e.g. PAListPtr) and do other less
invasive changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48289 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index c86ee30..e948329 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -18,7 +18,6 @@
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
-#include "llvm/ParamAttrsList.h"
#include "llvm/AutoUpgrade.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
@@ -32,11 +31,7 @@
std::vector<PATypeHolder>().swap(TypeList);
ValueList.clear();
- // Drop references to ParamAttrs.
- for (unsigned i = 0, e = ParamAttrs.size(); i != e; ++i)
- ParamAttrs[i]->dropRef();
-
- std::vector<const ParamAttrsList*>().swap(ParamAttrs);
+ std::vector<PAListPtr>().swap(ParamAttrs);
std::vector<BasicBlock*>().swap(FunctionBBs);
std::vector<Function*>().swap(FunctionsWithBodies);
DeferredFunctionInfo.clear();
@@ -205,7 +200,7 @@
SmallVector<uint64_t, 64> Record;
- ParamAttrsVector Attrs;
+ SmallVector<ParamAttrsWithIndex, 8> Attrs;
// Read all the records.
while (1) {
@@ -242,13 +237,8 @@
if (Record[i+1] != ParamAttr::None)
Attrs.push_back(ParamAttrsWithIndex::get(Record[i], Record[i+1]));
}
- if (Attrs.empty()) {
- ParamAttrs.push_back(0);
- } else {
- ParamAttrs.push_back(ParamAttrsList::get(Attrs));
- ParamAttrs.back()->addRef();
- }
+ ParamAttrs.push_back(PAListPtr::get(Attrs.begin(), Attrs.end()));
Attrs.clear();
break;
}
@@ -1062,8 +1052,7 @@
Func->setCallingConv(Record[1]);
bool isProto = Record[2];
Func->setLinkage(GetDecodedLinkage(Record[3]));
- const ParamAttrsList *PAL = getParamAttrs(Record[4]);
- Func->setParamAttrs(PAL);
+ Func->setParamAttrs(getParamAttrs(Record[4]));
Func->setAlignment((1 << Record[5]) >> 1);
if (Record[6]) {
@@ -1427,7 +1416,7 @@
case bitc::FUNC_CODE_INST_INVOKE: {
// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
if (Record.size() < 4) return Error("Invalid INVOKE record");
- const ParamAttrsList *PAL = getParamAttrs(Record[0]);
+ PAListPtr PAL = getParamAttrs(Record[0]);
unsigned CCInfo = Record[1];
BasicBlock *NormalBB = getBasicBlock(Record[2]);
BasicBlock *UnwindBB = getBasicBlock(Record[3]);
@@ -1565,7 +1554,7 @@
if (Record.size() < 3)
return Error("Invalid CALL record");
- const ParamAttrsList *PAL = getParamAttrs(Record[0]);
+ PAListPtr PAL = getParamAttrs(Record[0]);
unsigned CCInfo = Record[1];
unsigned OpNum = 2;
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index d7df1a1..9a140d9 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -15,6 +15,7 @@
#define BITCODE_READER_H
#include "llvm/ModuleProvider.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/Type.h"
#include "llvm/User.h"
#include "llvm/Bitcode/BitstreamReader.h"
@@ -24,7 +25,6 @@
namespace llvm {
class MemoryBuffer;
- class ParamAttrsList;
class BitcodeReaderValueList : public User {
std::vector<Use> Uses;
@@ -93,7 +93,7 @@
/// ParamAttrs - The set of parameter attributes by index. Index zero in the
/// file is for null, and is thus not represented here. As such all indices
/// are off by one.
- std::vector<const ParamAttrsList*> ParamAttrs;
+ std::vector<PAListPtr> ParamAttrs;
/// FunctionBBs - While parsing a function body, this is a list of the basic
/// blocks for the function.
@@ -156,10 +156,10 @@
if (ID >= FunctionBBs.size()) return 0; // Invalid ID
return FunctionBBs[ID];
}
- const ParamAttrsList *getParamAttrs(unsigned i) const {
+ PAListPtr getParamAttrs(unsigned i) const {
if (i-1 < ParamAttrs.size())
return ParamAttrs[i-1];
- return 0;
+ return PAListPtr();
}
/// getValueTypePair - Read a value/type pair out of the specified record from
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index aaad226..96f045c 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -20,7 +20,6 @@
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
-#include "llvm/ParamAttrsList.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/MathExtras.h"
@@ -109,17 +108,18 @@
// Emit information about parameter attributes.
static void WriteParamAttrTable(const ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const std::vector<const ParamAttrsList*> &Attrs = VE.getParamAttrs();
+ const std::vector<PAListPtr> &Attrs = VE.getParamAttrs();
if (Attrs.empty()) return;
Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
SmallVector<uint64_t, 64> Record;
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
- const ParamAttrsList *A = Attrs[i];
- for (unsigned op = 0, e = A->size(); op != e; ++op) {
- Record.push_back(A->getParamIndex(op));
- Record.push_back(A->getParamAttrsAtIndex(op));
+ const PAListPtr &A = Attrs[i];
+ for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
+ const ParamAttrsWithIndex &PAWI = A.getSlot(i);
+ Record.push_back(PAWI.Index);
+ Record.push_back(PAWI.Attrs);
}
Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index d2efe07..09a1db3 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -245,10 +245,10 @@
}
}
-void ValueEnumerator::EnumerateParamAttrs(const ParamAttrsList *PAL) {
- if (PAL == 0) return; // null is always 0.
+void ValueEnumerator::EnumerateParamAttrs(const PAListPtr &PAL) {
+ if (PAL.isEmpty()) return; // null is always 0.
// Do a lookup.
- unsigned &Entry = ParamAttrMap[PAL];
+ unsigned &Entry = ParamAttrMap[PAL.getRawPointer()];
if (Entry == 0) {
// Never saw this before, add it.
ParamAttrs.push_back(PAL);
diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h
index 9fb916a..dc40d01 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.h
+++ b/lib/Bitcode/Writer/ValueEnumerator.h
@@ -15,6 +15,7 @@
#define VALUE_ENUMERATOR_H
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ParameterAttributes.h"
#include <vector>
namespace llvm {
@@ -24,7 +25,7 @@
class BasicBlock;
class Function;
class Module;
-class ParamAttrsList;
+class PAListPtr;
class TypeSymbolTable;
class ValueSymbolTable;
@@ -44,9 +45,9 @@
ValueMapType ValueMap;
ValueList Values;
- typedef DenseMap<const ParamAttrsList*, unsigned> ParamAttrMapType;
+ typedef DenseMap<void*, unsigned> ParamAttrMapType;
ParamAttrMapType ParamAttrMap;
- std::vector<const ParamAttrsList*> ParamAttrs;
+ std::vector<PAListPtr> ParamAttrs;
/// BasicBlocks - This contains all the basic blocks for the currently
/// incorporated function. Their reverse mapping is stored in ValueMap.
@@ -75,9 +76,9 @@
return I->second-1;
}
- unsigned getParamAttrID(const ParamAttrsList *PAL) const {
- if (PAL == 0) return 0; // Null maps to zero.
- ParamAttrMapType::const_iterator I = ParamAttrMap.find(PAL);
+ unsigned getParamAttrID(const PAListPtr &PAL) const {
+ if (PAL.isEmpty()) return 0; // Null maps to zero.
+ ParamAttrMapType::const_iterator I = ParamAttrMap.find(PAL.getRawPointer());
assert(I != ParamAttrMap.end() && "ParamAttr not in ValueEnumerator!");
return I->second;
}
@@ -94,7 +95,7 @@
const std::vector<const BasicBlock*> &getBasicBlocks() const {
return BasicBlocks;
}
- const std::vector<const ParamAttrsList*> &getParamAttrs() const {
+ const std::vector<PAListPtr> &getParamAttrs() const {
return ParamAttrs;
}
@@ -115,7 +116,7 @@
void EnumerateValue(const Value *V);
void EnumerateType(const Type *T);
void EnumerateOperandType(const Value *V);
- void EnumerateParamAttrs(const ParamAttrsList *PAL);
+ void EnumerateParamAttrs(const PAListPtr &PAL);
void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
void EnumerateValueSymbolTable(const ValueSymbolTable &ST);