Use separate named MDNode to hold each function's local variable info.
authorDevang Patel <dpatel@apple.com>
Wed, 16 Jun 2010 00:53:55 +0000 (00:53 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 16 Jun 2010 00:53:55 +0000 (00:53 +0000)
This speeds up local variable handling in DwarfDebug.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106075 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/Analysis/DebugInfo.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/VMCore/Module.cpp

index 901fada3ebfc225a809ec13538b7fe691774b21b..15e0a17e1e5b35020679680c9e95d477024e4115 100644 (file)
@@ -326,6 +326,7 @@ public:
   /// specified name. This method returns null if a NamedMDNode with the 
   /// specified name is not found.
   NamedMDNode *getNamedMetadata(StringRef Name) const;
+  NamedMDNode *getNamedMetadataUsingTwine(Twine Name) const;
 
   /// getOrInsertNamedMetadata - Return the first named MDNode in the module 
   /// with the specified name. This method returns a new NamedMDNode if a 
index 774dce064210003d59d355b8a6a6050902167301..6ef160b97260d1a568d3d31d3a8a86f54f1f93e3 100644 (file)
@@ -1053,8 +1053,12 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
     // The optimizer may remove local variable. If there is an interest
     // to preserve variable info in such situation then stash it in a
     // named mdnode.
-    NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.lv");
-    NMD->addOperand(Node);
+    DISubprogram Fn(getDISubprogram(Context));
+    const Twine FnLVName = Twine("llvm.dbg.lv.", Fn.getName());
+    NamedMDNode *FnLocals = M.getNamedMetadataUsingTwine(FnLVName);
+    if (!FnLocals)
+      FnLocals = NamedMDNode::Create(VMContext, FnLVName, NULL, 0, &M);
+    FnLocals->addOperand(Node);
   }
   return DIVariable(Node);
 }
index 4705a0eed3540bc1d9dfe3c0cbf0ad5012a39d39..7da363fa561a1e2e26c84c664cde8d06813706b8 100644 (file)
@@ -2259,8 +2259,9 @@ void DwarfDebug::collectVariableInfo(const MachineFunction *MF) {
   }
 
   // Collect info for variables that were optimized out.
-  if (NamedMDNode *NMD = 
-      MF->getFunction()->getParent()->getNamedMetadata("llvm.dbg.lv")) {
+  const Twine FnLVName = Twine("llvm.dbg.lv.", MF->getFunction()->getName());
+  if (NamedMDNode *NMD =
+      MF->getFunction()->getParent()->getNamedMetadataUsingTwine(FnLVName)) {
     for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
       DIVariable DV(cast_or_null<MDNode>(NMD->getOperand(i)));
       if (!DV || !Processed.insert(DV))
index 94840f07a4abf82857f9566557b63d41600e9add..a4c3d2e9a0ed56e30b67d60da266349ec0253285 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/GVMaterializer.h"
 #include "llvm/LLVMContext.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/LeakDetector.h"
@@ -316,6 +317,12 @@ NamedMDNode *Module::getNamedMetadata(StringRef Name) const {
   return NamedMDSymTab->lookup(Name);
 }
 
+NamedMDNode *Module::getNamedMetadataUsingTwine(Twine Name) const {
+  SmallString<256> NameData;
+  StringRef NameRef = Name.toStringRef(NameData);
+   return NamedMDSymTab->lookup(NameRef);
+}
+
 /// 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.