aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-10-21 23:57:35 +0000
committerDevang Patel <dpatel@apple.com>2009-10-21 23:57:35 +0000
commit49708ad993529611cedfbe49ae44bb10beb73abe (patch)
tree5b4e1e0eb704805d78a52af94bda4b15a441ca44
parent857eb5793e5d7fc239f75be3a39d9569914aebf0 (diff)
downloadexternal_llvm-49708ad993529611cedfbe49ae44bb10beb73abe.zip
external_llvm-49708ad993529611cedfbe49ae44bb10beb73abe.tar.gz
external_llvm-49708ad993529611cedfbe49ae44bb10beb73abe.tar.bz2
Derive metadata hierarchy from Value instead of User.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84801 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/LLVMContext.h1
-rw-r--r--include/llvm/Metadata.h37
-rw-r--r--lib/Transforms/IPO/GlobalDCE.cpp3
-rw-r--r--lib/Transforms/IPO/StripSymbols.cpp2
-rw-r--r--lib/VMCore/LLVMContext.cpp26
-rw-r--r--lib/VMCore/LLVMContextImpl.h4
-rw-r--r--lib/VMCore/Metadata.cpp76
7 files changed, 10 insertions, 139 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index a135f67..b9ffeb0 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -33,7 +33,6 @@ class LLVMContext {
public:
LLVMContextImpl* const pImpl;
MetadataContext &getMetadata();
- bool RemoveDeadMetadata();
LLVMContext();
~LLVMContext();
};
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 3cb34f9..4a19100 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -16,7 +16,7 @@
#ifndef LLVM_METADATA_H
#define LLVM_METADATA_H
-#include "llvm/User.h"
+#include "llvm/Value.h"
#include "llvm/Type.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -33,17 +33,11 @@ class LLVMContext;
//===----------------------------------------------------------------------===//
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
-class MetadataBase : public User {
-private:
- /// ReservedSpace - The number of operands actually allocated. NumOperands is
- /// the number actually in use.
- unsigned ReservedSpace;
-
+class MetadataBase : public Value {
protected:
MetadataBase(const Type *Ty, unsigned scid)
- : User(Ty, scid, NULL, 0), ReservedSpace(0) {}
+ : Value(Ty, scid) {}
- void resizeOperands(unsigned NumOps);
public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -60,8 +54,6 @@ public:
/// MDString is always unnamd.
class MDString : public MetadataBase {
MDString(const MDString &); // DO NOT IMPLEMENT
- void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
- unsigned getNumOperands(); // DO NOT IMPLEMENT
StringRef Str;
protected:
@@ -69,10 +61,6 @@ protected:
: MetadataBase(Type::getMetadataTy(C), Value::MDStringVal), Str(begin, l) {}
public:
- // Do not allocate any space for operands.
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
static MDString *get(LLVMContext &Context, const StringRef &Str);
StringRef getString() const { return Str; }
@@ -102,9 +90,6 @@ public:
/// MDNode is always unnamed.
class MDNode : public MetadataBase, public FoldingSetNode {
MDNode(const MDNode &); // DO NOT IMPLEMENT
- void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
- // getNumOperands - Make this only available for private uses.
- unsigned getNumOperands() { return User::getNumOperands(); }
friend class ElementVH;
// Use CallbackVH to hold MDNOde elements.
@@ -131,17 +116,10 @@ class MDNode : public MetadataBase, public FoldingSetNode {
protected:
explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals);
public:
- // Do not allocate any space for operands.
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
// Constructors and destructors.
static MDNode *get(LLVMContext &Context,
Value *const *Vals, unsigned NumVals);
- /// dropAllReferences - Remove all uses and clear node vector.
- void dropAllReferences();
-
/// ~MDNode - Destroy MDNode.
~MDNode();
@@ -193,9 +171,6 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
friend class LLVMContextImpl;
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
- void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
- // getNumOperands - Make this only available for private uses.
- unsigned getNumOperands() { return User::getNumOperands(); }
Module *Parent;
SmallVector<WeakMetadataVH, 4> Node;
@@ -206,10 +181,6 @@ protected:
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
unsigned NumVals, Module *M = 0);
public:
- // Do not allocate any space for operands.
- void *operator new(size_t s) {
- return User::operator new(s, 0);
- }
static NamedMDNode *Create(LLVMContext &C, const Twine &N,
MetadataBase *const *MDs,
unsigned NumMDs, Module *M = 0) {
@@ -245,8 +216,6 @@ public:
/// addElement - Add metadata element.
void addElement(MetadataBase *M) {
- resizeOperands(NumOperands + 1);
- OperandList[NumOperands++] = M;
Node.push_back(WeakMetadataVH(M));
}
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp
index 09ef12f..8f4e8b3 100644
--- a/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/lib/Transforms/IPO/GlobalDCE.cpp
@@ -149,9 +149,6 @@ bool GlobalDCE::runOnModule(Module &M) {
// Make sure that all memory is released
AliveGlobals.clear();
- // Remove dead metadata.
- // FIXME - Enable this.
- // Changed |= M.getContext().RemoveDeadMetadata();
return Changed;
}
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp
index 77d44b2..57aaf43 100644
--- a/lib/Transforms/IPO/StripSymbols.cpp
+++ b/lib/Transforms/IPO/StripSymbols.cpp
@@ -250,8 +250,6 @@ static bool StripDebugInfo(Module &M) {
if (NMD)
NMD->eraseFromParent();
- // Remove dead metadata.
- M.getContext().RemoveDeadMetadata();
return true;
}
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 39ed7ed..3b4a1a3 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -45,32 +45,6 @@ GetElementPtrConstantExpr::GetElementPtrConstantExpr
OperandList[i+1] = IdxList[i];
}
-bool LLVMContext::RemoveDeadMetadata() {
- std::vector<WeakVH> DeadMDNodes;
- bool Changed = false;
- while (1) {
-
- for (FoldingSet<MDNode>::iterator
- I = pImpl->MDNodeSet.begin(),
- E = pImpl->MDNodeSet.end(); I != E; ++I) {
- MDNode *N = &(*I);
- if (N->use_empty())
- DeadMDNodes.push_back(WeakVH(N));
- }
-
- if (DeadMDNodes.empty())
- return Changed;
-
- while (!DeadMDNodes.empty()) {
- Value *V = DeadMDNodes.back(); DeadMDNodes.pop_back();
- if (const MDNode *N = dyn_cast_or_null<MDNode>(V))
- if (N->use_empty())
- delete N;
- }
- }
- return Changed;
-}
-
MetadataContext &LLVMContext::getMetadata() {
return pImpl->TheMetadata;
}
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index 58e8870..84902d5 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -203,9 +203,6 @@ public:
AggZeroConstants.freeConstants();
NullPtrConstants.freeConstants();
UndefValueConstants.freeConstants();
- for (FoldingSet<MDNode>::iterator I = MDNodeSet.begin(),
- E = MDNodeSet.end(); I != E; ++I)
- I->dropAllReferences();
for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
I != E; ++I) {
if (I->second->use_empty())
@@ -216,6 +213,7 @@ public:
if (I->second->use_empty())
delete I->second;
}
+ MDNodeSet.clear();
}
};
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 365fe8b..faf79fd 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -23,30 +23,6 @@ using namespace llvm;
// MetadataBase implementation.
//
-/// resizeOperands - Metadata keeps track of other metadata uses using
-/// OperandList. Resize this list to hold anticipated number of metadata
-/// operands.
-void MetadataBase::resizeOperands(unsigned NumOps) {
- unsigned e = getNumOperands();
- if (NumOps == 0) {
- NumOps = e*2;
- if (NumOps < 2) NumOps = 2;
- } else if (NumOps > NumOperands) {
- // No resize needed.
- if (ReservedSpace >= NumOps) return;
- } else if (NumOps == NumOperands) {
- if (ReservedSpace == NumOps) return;
- } else {
- return;
- }
-
- ReservedSpace = NumOps;
- Use *OldOps = OperandList;
- Use *NewOps = allocHungoffUses(NumOps);
- std::copy(OldOps, OldOps + e, NewOps);
- OperandList = NewOps;
- if (OldOps) Use::zap(OldOps, OldOps + e, true);
-}
//===----------------------------------------------------------------------===//
// MDString implementation.
//
@@ -65,20 +41,11 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
//
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]))
- OperandList[NumOperands++] = MB;
- else if(Vals[i] &&
- Vals[i]->getType()->getTypeID() == Type::MetadataTyID)
- OperandList[NumOperands++] = Vals[i];
+ for (unsigned i = 0; i != NumVals; ++i)
*Ptr++ = ElementVH(Vals[i], this);
- }
}
void MDNode::Profile(FoldingSetNodeID &ID) const {
@@ -109,19 +76,14 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
return N;
}
-/// dropAllReferences - Remove all uses and clear node vector.
-void MDNode::dropAllReferences() {
- User::dropAllReferences();
- delete [] Node;
- Node = NULL;
-}
-
+/// ~MDNode - Destroy MDNode.
MDNode::~MDNode() {
{
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
pImpl->MDNodeSet.RemoveNode(this);
}
- dropAllReferences();
+ delete [] Node;
+ Node = NULL;
}
// Replace value from this node's element list.
@@ -148,27 +110,6 @@ void MDNode::replaceElement(Value *From, Value *To) {
// Remove "this" from the context map.
pImpl->MDNodeSet.RemoveNode(this);
- // MDNode only lists metadata elements in operand list, because MDNode
- // used by MDNode is considered a valid use. However on the side, MDNode
- // using a non-metadata value is not considered a "use" of non-metadata
- // value.
- SmallVector<unsigned, 4> OpIndexes;
- unsigned OpIndex = 0;
- for (User::op_iterator OI = op_begin(), OE = op_end();
- OI != OE; ++OI, OpIndex++) {
- if (*OI == From)
- OpIndexes.push_back(OpIndex);
- }
- if (MetadataBase *MDTo = dyn_cast_or_null<MetadataBase>(To)) {
- for (SmallVector<unsigned, 4>::iterator OI = OpIndexes.begin(),
- OE = OpIndexes.end(); OI != OE; ++OI)
- setOperand(*OI, MDTo);
- } else {
- for (SmallVector<unsigned, 4>::iterator OI = OpIndexes.begin(),
- OE = OpIndexes.end(); OI != OE; ++OI)
- setOperand(*OI, 0);
- }
-
// Replace From element(s) in place.
for (SmallVector<unsigned, 4>::iterator I = Indexes.begin(), E = Indexes.end();
I != E; ++I) {
@@ -207,14 +148,10 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
unsigned NumMDs, Module *ParentModule)
: MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N);
- NumOperands = 0;
- resizeOperands(NumMDs);
- for (unsigned i = 0; i != NumMDs; ++i) {
- if (MDs[i])
- OperandList[NumOperands++] = MDs[i];
+ for (unsigned i = 0; i != NumMDs; ++i)
Node.push_back(WeakMetadataVH(MDs[i]));
- }
+
if (ParentModule)
ParentModule->getNamedMDList().push_back(this);
}
@@ -236,7 +173,6 @@ void NamedMDNode::eraseFromParent() {
/// dropAllReferences - Remove all uses and clear node vector.
void NamedMDNode::dropAllReferences() {
- User::dropAllReferences();
Node.clear();
}