Eli pointed out that va_arg instruction result values don't
[oota-llvm.git] / lib / Analysis / DebugInfo.cpp
index 7bbae59b87a81e07b2e1e4bcc32a7d9b820f4b44..46abf333398a5a7d3894d4cf04c78a7f295cea40 100644 (file)
@@ -466,7 +466,7 @@ void DICompileUnit::print(raw_ostream &OS) const {
   if (getLanguage())
     OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
 
-  OS << " [" << getDirectory() << "/" << getFilename() << " ]";
+  OS << " [" << getDirectory() << "/" << getFilename() << "]";
 }
 
 /// print - Print type.
@@ -527,8 +527,8 @@ void DICompositeType::print(raw_ostream &OS) const {
   OS << " [" << A.getNumElements() << " elements]";
 }
 
-/// print - Print global.
-void DIGlobal::print(raw_ostream &OS) const {
+/// print - Print subprogram.
+void DISubprogram::print(raw_ostream &OS) const {
   StringRef Res = getName();
   if (!Res.empty())
     OS << " [" << Res << "] ";
@@ -546,14 +546,12 @@ void DIGlobal::print(raw_ostream &OS) const {
   if (isDefinition())
     OS << " [def] ";
 
-  if (isGlobalVariable())
-    DIGlobalVariable(DbgNode).print(OS);
-
   OS << "\n";
 }
 
-/// print - Print subprogram.
-void DISubprogram::print(raw_ostream &OS) const {
+/// print - Print global variable.
+void DIGlobalVariable::print(raw_ostream &OS) const {
+  OS << " [";
   StringRef Res = getName();
   if (!Res.empty())
     OS << " [" << Res << "] ";
@@ -571,14 +569,9 @@ void DISubprogram::print(raw_ostream &OS) const {
   if (isDefinition())
     OS << " [def] ";
 
-  OS << "\n";
-}
-
-/// print - Print global variable.
-void DIGlobalVariable::print(raw_ostream &OS) const {
-  OS << " [";
-  getGlobal()->print(OS);
-  OS << "] ";
+  if (isGlobalVariable())
+    DIGlobalVariable(DbgNode).print(OS);
+  OS << "]\n";
 }
 
 /// print - Print variable.
@@ -625,11 +618,6 @@ void DICompositeType::dump() const {
   print(dbgs()); dbgs() << '\n';
 }
 
-/// dump - Print global to dbgs() with a newline.
-void DIGlobal::dump() const {
-  print(dbgs()); dbgs() << '\n';
-}
-
 /// dump - Print subprogram to dbgs() with a newline.
 void DISubprogram::dump() const {
   print(dbgs()); dbgs() << '\n';
@@ -1040,7 +1028,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
                                      StringRef Name,
                                      DIFile F,
                                      unsigned LineNo,
-                                     DIType Ty) {
+                                     DIType Ty, bool AlwaysPreserve) {
   Value *Elts[] = {
     GetTagConstant(Tag),
     Context,
@@ -1049,7 +1037,15 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
     ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
     Ty,
   };
-  return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
+  MDNode *Node = MDNode::get(VMContext, &Elts[0], 6);
+  if (AlwaysPreserve) {
+    // 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);
+  }
+  return DIVariable(Node);
 }
 
 
@@ -1114,18 +1110,6 @@ DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
   return DILocation(MDNode::get(VMContext, &Elts[0], 4));
 }
 
-/// CreateLocation - Creates a debug info location.
-DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
-                                     DIScope S, MDNode *OrigLoc) {
- Value *Elts[] = {
-    ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
-    ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo),
-    S,
-    OrigLoc
-  };
-  return DILocation(MDNode::get(VMContext, &Elts[0], 4));
-}
-
 //===----------------------------------------------------------------------===//
 // DIFactory: Routines for inserting code into a function
 //===----------------------------------------------------------------------===//