aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Metadata.h18
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.cpp7
-rw-r--r--lib/VMCore/AsmWriter.cpp17
-rw-r--r--lib/VMCore/Metadata.cpp17
4 files changed, 25 insertions, 34 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 3b2f303..49c5b3c 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -110,6 +110,7 @@ class MDNode : public MetadataBase, public FoldingSetNode {
// Use CallbackVH to hold MDNOde elements.
struct ElementVH : public CallbackVH {
MDNode *Parent;
+ ElementVH() {}
ElementVH(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {}
~ElementVH() {}
@@ -124,7 +125,8 @@ class MDNode : public MetadataBase, public FoldingSetNode {
// Replace each instance of F from the element list of this node with T.
void replaceElement(Value *F, Value *T);
- SmallVector<ElementVH, 4> Node;
+ ElementVH *Node;
+ unsigned NodeSize;
protected:
explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals);
@@ -150,19 +152,7 @@ public:
}
/// getNumElements - Return number of MDNode elements.
- unsigned getNumElements() const {
- return Node.size();
- }
-
- // Element access
- typedef SmallVectorImpl<ElementVH>::const_iterator const_elem_iterator;
- typedef SmallVectorImpl<ElementVH>::iterator elem_iterator;
- /// elem_empty - Return true if MDNode is empty.
- bool elem_empty() const { return Node.empty(); }
- const_elem_iterator elem_begin() const { return Node.begin(); }
- const_elem_iterator elem_end() const { return Node.end(); }
- elem_iterator elem_begin() { return Node.begin(); }
- elem_iterator elem_end() { return Node.end(); }
+ unsigned getNumElements() const { return NodeSize; }
/// Profile - calculate a unique identifier for this MDNode to collapse
/// duplicates
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index 60253ad..ca9fc77 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -214,10 +214,9 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
MDValues.push_back(std::make_pair(MD, 1U));
MDValueMap[MD] = MDValues.size();
MDValueID = MDValues.size();
- for (MDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end();
- I != E; ++I) {
- if (*I)
- EnumerateValue(*I);
+ for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
+ if (Value *V = N->getElement(i))
+ EnumerateValue(V);
else
EnumerateType(Type::getVoidTy(MD->getContext()));
}
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index b5ae81b..d2a0f90 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -818,9 +818,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
unsigned DestSlot = mdnNext++;
mdnMap[N] = DestSlot;
- for (MDNode::const_elem_iterator MDI = N->elem_begin(),
- MDE = N->elem_end(); MDI != MDE; ++MDI) {
- const Value *TV = *MDI;
+ for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
+ const Value *TV = N->getElement(i);
if (TV)
if (const MDNode *N2 = dyn_cast<MDNode>(TV))
CreateMetadataSlot(N2);
@@ -906,9 +905,8 @@ static void WriteMDNodes(formatted_raw_ostream &Out, TypePrinting &TypePrinter,
Out << '!' << i << " = metadata ";
const MDNode *Node = Nodes[i];
Out << "!{";
- for (MDNode::const_elem_iterator NI = Node->elem_begin(),
- NE = Node->elem_end(); NI != NE;) {
- const Value *V = *NI;
+ for (unsigned mi = 0, me = Node->getNumElements(); mi != me; ++mi) {
+ const Value *V = Node->getElement(mi);
if (!V)
Out << "null";
else if (const MDNode *N = dyn_cast<MDNode>(V)) {
@@ -916,11 +914,12 @@ static void WriteMDNodes(formatted_raw_ostream &Out, TypePrinting &TypePrinter,
Out << '!' << Machine.getMetadataSlot(N);
}
else {
- TypePrinter.print((*NI)->getType(), Out);
+ TypePrinter.print(V->getType(), Out);
Out << ' ';
- WriteAsOperandInternal(Out, *NI, &TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, Node->getElement(mi),
+ &TypePrinter, &Machine);
}
- if (++NI != NE)
+ if (mi + 1 != me)
Out << ", ";
}
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index dcfac6b..6da3ec1 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -67,6 +67,9 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = 0;
resizeOperands(NumVals);
+ NodeSize = NumVals;
+ Node = new ElementVH[NodeSize];
+ ElementVH *Ptr = Node;
for (unsigned i = 0; i != NumVals; ++i) {
// Only record metadata uses.
if (MetadataBase *MB = dyn_cast_or_null<MetadataBase>(Vals[i]))
@@ -74,13 +77,13 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
else if(Vals[i] &&
Vals[i]->getType()->getTypeID() == Type::MetadataTyID)
OperandList[NumOperands++] = Vals[i];
- Node.push_back(ElementVH(Vals[i], this));
+ *Ptr++ = ElementVH(Vals[i], this);
}
}
void MDNode::Profile(FoldingSetNodeID &ID) const {
- for (const_elem_iterator I = elem_begin(), E = elem_end(); I != E; ++I)
- ID.AddPointer(*I);
+ for (unsigned i = 0, e = getNumElements(); i != e; ++i)
+ ID.AddPointer(getElement(i));
}
MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
@@ -109,7 +112,8 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
/// dropAllReferences - Remove all uses and clear node vector.
void MDNode::dropAllReferences() {
User::dropAllReferences();
- Node.clear();
+ delete [] Node;
+ Node = NULL;
}
MDNode::~MDNode() {
@@ -132,9 +136,8 @@ void MDNode::replaceElement(Value *From, Value *To) {
// From in this MDNode's element list.
SmallVector<unsigned, 4> Indexes;
unsigned Index = 0;
- for (SmallVector<ElementVH, 4>::iterator I = Node.begin(),
- E = Node.end(); I != E; ++I, ++Index) {
- Value *V = *I;
+ for (unsigned i = 0, e = getNumElements(); i != e; ++i, ++Index) {
+ Value *V = getElement(i);
if (V && V == From)
Indexes.push_back(Index);
}