diff options
author | Devang Patel <dpatel@apple.com> | 2010-01-07 19:39:36 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-01-07 19:39:36 +0000 |
commit | 0386f01e061513094504bc11f8352a40173cada7 (patch) | |
tree | 94c2edcbcfba8906e22099dcf3a2c6ef2ebc8897 /lib | |
parent | 3c37bb8dbe886993dcd8f37dec0d94762393f3d4 (diff) | |
download | llvm-0386f01e061513094504bc11f8352a40173cada7.tar.gz llvm-0386f01e061513094504bc11f8352a40173cada7.tar.bz2 llvm-0386f01e061513094504bc11f8352a40173cada7.tar.xz |
Use separate namespace for named metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 7 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 13 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.h | 2 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 18 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 12 |
5 files changed, 40 insertions, 12 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index ce9036bd06..d34e24ccb5 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -528,10 +528,9 @@ static void WriteModuleMetadata(const ValueEnumerator &VE, } // Write name. - std::string Str = NMD->getNameStr(); - const char *StrBegin = Str.c_str(); - for (unsigned i = 0, e = Str.length(); i != e; ++i) - Record.push_back(StrBegin[i]); + StringRef Str = NMD->getName(); + for (unsigned i = 0, e = Str.size(); i != e; ++i) + Record.push_back(Str[i]); Stream.EmitRecord(bitc::METADATA_NAME, Record, 0/*TODO*/); Record.clear(); diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index c409c2066d..54bf84d261 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -74,9 +74,10 @@ ValueEnumerator::ValueEnumerator(const Module *M) { // Enumerate types used by the type symbol table. EnumerateTypeSymbolTable(M->getTypeSymbolTable()); - // Insert constants that are named at module level into the slot pool so that - // the module symbol table can refer to them... + // Insert constants and metadata that are named at module level into the slot + // pool so that the module symbol table can refer to them... EnumerateValueSymbolTable(M->getValueSymbolTable()); + EnumerateMDSymbolTable(M->getMDSymbolTable()); SmallVector<std::pair<unsigned, MDNode*>, 8> MDs; @@ -196,6 +197,14 @@ void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) { EnumerateValue(VI->getValue()); } +/// EnumerateMDSymbolTable - Insert all of the values in the specified metadata +/// table. +void ValueEnumerator::EnumerateMDSymbolTable(const MDSymbolTable &MST) { + for (MDSymbolTable::const_iterator MI = MST.begin(), ME = MST.end(); + MI != ME; ++MI) + EnumerateValue(MI->getValue()); +} + void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) { // Check to see if it's already in! unsigned &MDValueID = MDValueMap[MD]; diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 3c83e35695..a1b188ef9b 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -30,6 +30,7 @@ class MetadataBase; class AttrListPtr; class TypeSymbolTable; class ValueSymbolTable; +class MDSymbolTable; class ValueEnumerator { public: @@ -133,6 +134,7 @@ private: void EnumerateTypeSymbolTable(const TypeSymbolTable &ST); void EnumerateValueSymbolTable(const ValueSymbolTable &ST); + void EnumerateMDSymbolTable(const MDSymbolTable &ST); }; } // End llvm namespace diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 09cd1d5cba..6cc1e1bded 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -214,20 +214,21 @@ static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) { return *(SmallVector<WeakVH, 4>*)Operands; } -NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, +NamedMDNode::NamedMDNode(LLVMContext &C, StringRef N, MDNode *const *MDs, unsigned NumMDs, Module *ParentModule) : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { setName(N); - Operands = new SmallVector<WeakVH, 4>(); SmallVector<WeakVH, 4> &Node = getNMDOps(Operands); 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) { @@ -265,6 +266,7 @@ void NamedMDNode::addOperand(MDNode *M) { /// eraseFromParent - Drop all references and remove the node from parent /// module. void NamedMDNode::eraseFromParent() { + getParent()->getMDSymbolTable().remove(getName()); getParent()->getNamedMDList().erase(this); } @@ -273,6 +275,16 @@ void NamedMDNode::dropAllReferences() { getNMDOps(Operands).clear(); } +/// setName - Set the name of this named metadata. +void NamedMDNode::setName(StringRef N) { + if (!N.empty()) + Name = N.str(); +} + +/// getName - Return a constant reference to this named metadata's name. +StringRef NamedMDNode::getName() const { + return StringRef(Name); +} //===----------------------------------------------------------------------===// // LLVMContext MDKind naming implementation. diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index a7f503bacb..e25a29517a 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -59,6 +59,7 @@ Module::Module(StringRef MID, LLVMContext& C) : Context(C), ModuleID(MID), DataLayout("") { ValSymTab = new ValueSymbolTable(); TypeSymTab = new TypeSymbolTable(); + NamedMDSymTab = new MDSymbolTable(); } Module::~Module() { @@ -307,20 +308,25 @@ GlobalAlias *Module::getNamedAlias(StringRef Name) const { /// specified name. This method returns null if a NamedMDNode with the //// specified name is not found. NamedMDNode *Module::getNamedMetadata(StringRef Name) const { - return dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); + return NamedMDSymTab->lookup(Name); } /// getOrInsertNamedMetadata - Return the first named MDNode in the module /// with the specified name. This method returns a new NamedMDNode if a /// NamedMDNode with the specified name is not found. NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) { - NamedMDNode *NMD = - dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); + NamedMDNode *NMD = NamedMDSymTab->lookup(Name); if (!NMD) NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this); 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. // |