[llvm-commits] [llvm] r93247 - in /llvm/trunk: include/llvm/Metadata.h include/llvm/Module.h include/llvm/ValueSymbolTable.h lib/VMCore/Metadata.cpp lib/VMCore/Module.cpp
Devang Patel
dpatel at apple.com
Tue Jan 12 10:34:06 PST 2010
Author: dpatel
Date: Tue Jan 12 12:34:06 2010
New Revision: 93247
URL: http://llvm.org/viewvc/llvm-project?rev=93247&view=rev
Log:
Use ilist_tratis to autoinsert and remove NamedMDNode from MDSymbolTable.
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/include/llvm/Module.h
llvm/trunk/include/llvm/ValueSymbolTable.h
llvm/trunk/lib/VMCore/Metadata.cpp
llvm/trunk/lib/VMCore/Module.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=93247&r1=93246&r2=93247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Jan 12 12:34:06 2010
@@ -184,8 +184,8 @@
/// NamedMDNode is always named. All NamedMDNode operand has a type of metadata.
class NamedMDNode : public Value, public ilist_node<NamedMDNode> {
friend class SymbolTableListTraits<NamedMDNode, Module>;
+ friend class ilist_traits<NamedMDNode>;
friend class LLVMContextImpl;
-
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
std::string Name;
Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=93247&r1=93246&r2=93247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Tue Jan 12 12:34:06 2010
@@ -57,6 +57,7 @@
static GlobalAlias *createSentinel();
static void destroySentinel(GlobalAlias *GA) { delete GA; }
};
+
template<> struct ilist_traits<NamedMDNode>
: public SymbolTableListTraits<NamedMDNode, Module> {
// createSentinel is used to get hold of a node that marks the end of
@@ -69,6 +70,8 @@
NamedMDNode *provideInitialHead() const { return createSentinel(); }
NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); }
static void noteHead(NamedMDNode*, NamedMDNode*) {}
+ void addNodeToList(NamedMDNode *N);
+ void removeNodeFromList(NamedMDNode *N);
private:
mutable ilist_node<NamedMDNode> Sentinel;
};
@@ -324,10 +327,6 @@
/// NamedMDNode with the specified name is not found.
NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
- /// addMDNodeName - Insert an entry in the NamedMDNode symbol table mapping
- /// Name to NMD.
- void addMDNodeName(StringRef Name, NamedMDNode *NMD);
-
/// @}
/// @name Type Accessors
/// @{
Modified: llvm/trunk/include/llvm/ValueSymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ValueSymbolTable.h?rev=93247&r1=93246&r2=93247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ValueSymbolTable.h (original)
+++ llvm/trunk/include/llvm/ValueSymbolTable.h Tue Jan 12 12:34:06 2010
@@ -17,6 +17,7 @@
#include "llvm/Value.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/System/DataTypes.h"
+#include "llvm/ADT/ilist_node.h"
namespace llvm {
template<typename ValueSubClass, typename ItemParentClass>
@@ -39,7 +40,6 @@
friend class SymbolTableListTraits<Function, Module>;
friend class SymbolTableListTraits<GlobalVariable, Module>;
friend class SymbolTableListTraits<GlobalAlias, Module>;
- friend class SymbolTableListTraits<NamedMDNode, Module>;
/// @name Types
/// @{
public:
@@ -133,6 +133,7 @@
/// essentially a StringMap wrapper.
class MDSymbolTable {
+ friend class SymbolTableListTraits<NamedMDNode, Module>;
/// @name Types
/// @{
private:
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=93247&r1=93246&r2=93247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Jan 12 12:34:06 2010
@@ -239,6 +239,26 @@
//===----------------------------------------------------------------------===//
// NamedMDNode implementation.
//
+
+namespace llvm {
+// SymbolTableListTraits specialization for MDSymbolTable.
+void ilist_traits<NamedMDNode>
+::addNodeToList(NamedMDNode *N) {
+ assert(N->getParent() == 0 && "Value already in a container!!");
+ Module *Owner = getListOwner();
+ N->setParent(Owner);
+ MDSymbolTable &ST = Owner->getMDSymbolTable();
+ ST.insert(N->getName(), N);
+}
+
+void ilist_traits<NamedMDNode>::removeNodeFromList(NamedMDNode *N) {
+ N->setParent(0);
+ Module *Owner = getListOwner();
+ MDSymbolTable &ST = Owner->getMDSymbolTable();
+ ST.remove(N->getName());
+}
+}
+
static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
return *(SmallVector<WeakVH, 4>*)Operands;
}
@@ -254,10 +274,8 @@
for (unsigned i = 0; i != NumMDs; ++i)
Node.push_back(WeakVH(MDs[i]));
- if (ParentModule) {
+ if (ParentModule)
ParentModule->getNamedMDList().push_back(this);
- ParentModule->addMDNodeName(N, this);
- }
}
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
@@ -295,7 +313,6 @@
/// eraseFromParent - Drop all references and remove the node from parent
/// module.
void NamedMDNode::eraseFromParent() {
- getParent()->getMDSymbolTable().remove(getName());
getParent()->getNamedMDList().erase(this);
}
@@ -306,8 +323,10 @@
/// setName - Set the name of this named metadata.
void NamedMDNode::setName(StringRef N) {
- if (!N.empty())
- Name = N.str();
+ assert (!N.empty() && "Invalid named metadata name!");
+ Name = N.str();
+ if (Parent)
+ Parent->getMDSymbolTable().insert(N, this);
}
/// getName - Return a constant reference to this named metadata's name.
Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=93247&r1=93246&r2=93247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Tue Jan 12 12:34:06 2010
@@ -325,12 +325,6 @@
return NMD;
}
-/// addMDNodeName - Insert an entry in the NamedMDNode symbol table mapping
-/// Name to NMD.
-void Module::addMDNodeName(StringRef Name, NamedMDNode *NMD) {
- NamedMDSymTab->insert(Name, NMD);
-}
-
//===----------------------------------------------------------------------===//
// Methods for easy access to the types in the module.
//
More information about the llvm-commits
mailing list