<div dir="ltr">For your convenience, attached is the patch against r196270, so the "fix" is more obvious.</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/3 Timur Iskhodzhanov <span dir="ltr"><<a href="mailto:timurrrr@google.com" target="_blank">timurrrr@google.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: timurrrr<br>
Date: Tue Dec  3 09:10:23 2013<br>
New Revision: 196288<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=196288&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=196288&view=rev</a><br>
Log:<br>
Reland 196270 "Generalize debug info / EH emission in AsmPrinter"<br>
<br>
Addressing the existense AMDGPUAsmPrinter and other subclasses of AsmPrinter<br>
<br>
Added:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h<br>
Modified:<br>
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Dec  3 09:10:23 2013<br>
@@ -22,6 +22,7 @@<br>
 #include "llvm/Support/ErrorHandling.h"<br>
<br>
 namespace llvm {<br>
+  class AsmPrinterHandler;<br>
   class BlockAddress;<br>
   class GCStrategy;<br>
   class Constant;<br>
@@ -110,13 +111,21 @@ namespace llvm {<br>
     /// function.<br>
     MachineLoopInfo *LI;<br>
<br>
+    struct HandlerInfo {<br>
+      AsmPrinterHandler *Handler;<br>
+      const char *TimerName, *TimerGroupName;<br>
+      HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName,<br>
+                  const char *TimerGroupName)<br>
+          : Handler(Handler), TimerName(TimerName),<br>
+            TimerGroupName(TimerGroupName) {}<br>
+    };<br>
+    /// Handlers - a vector of all debug/EH info emitters we should use.<br>
+    /// This vector maintains ownership of the emitters.<br>
+    SmallVector<HandlerInfo, 1> Handlers;<br>
+<br>
     /// DD - If the target supports dwarf debug info, this pointer is non-null.<br>
     DwarfDebug *DD;<br>
<br>
-    /// DE - If the target supports dwarf exception info, this pointer is<br>
-    /// non-null.<br>
-    DwarfException *DE;<br>
-<br>
   protected:<br>
     explicit AsmPrinter(TargetMachine &TM, MCStreamer &Streamer);<br>
<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp Tue Dec  3 09:10:23 2013<br>
@@ -66,7 +66,7 @@ void ARMException::beginFunction(const M<br>
<br>
 /// endFunction - Gather and emit post-function exception information.<br>
 ///<br>
-void ARMException::endFunction() {<br>
+void ARMException::endFunction(const MachineFunction *) {<br>
   ARMTargetStreamer &ATS = getTargetStreamer();<br>
   if (!Asm->MF->getFunction()->needsUnwindTableEntry())<br>
     ATS.emitCantUnwind();<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Dec  3 09:10:23 2013<br>
@@ -99,14 +99,14 @@ AsmPrinter::AsmPrinter(TargetMachine &tm<br>
     OutContext(Streamer.getContext()),<br>
     OutStreamer(Streamer),<br>
     LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {<br>
-  DD = 0; DE = 0; MMI = 0; LI = 0; MF = 0;<br>
+  DD = 0; MMI = 0; LI = 0; MF = 0;<br>
   CurrentFnSym = CurrentFnSymForSize = 0;<br>
   GCMetadataPrinters = 0;<br>
   VerboseAsm = Streamer.isVerboseAsm();<br>
 }<br>
<br>
 AsmPrinter::~AsmPrinter() {<br>
-  assert(DD == 0 && DE == 0 && "Debug/EH info didn't get finalized");<br>
+  assert(DD == 0 && Handlers.empty() && "Debug/EH info didn't get finalized");<br>
<br>
   if (GCMetadataPrinters != 0) {<br>
     gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);<br>
@@ -192,25 +192,29 @@ bool AsmPrinter::doInitialization(Module<br>
     OutStreamer.AddBlankLine();<br>
   }<br>
<br>
-  if (MAI->doesSupportDebugInformation())<br>
+  if (MAI->doesSupportDebugInformation()) {<br>
     DD = new DwarfDebug(this, &M);<br>
+    Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName));<br>
+  }<br>
<br>
+  DwarfException *DE = 0;<br>
   switch (MAI->getExceptionHandlingType()) {<br>
   case ExceptionHandling::None:<br>
-    return false;<br>
+    break;<br>
   case ExceptionHandling::SjLj:<br>
   case ExceptionHandling::DwarfCFI:<br>
     DE = new DwarfCFIException(this);<br>
-    return false;<br>
+    break;<br>
   case ExceptionHandling::ARM:<br>
     DE = new ARMException(this);<br>
-    return false;<br>
+    break;<br>
   case ExceptionHandling::Win64:<br>
     DE = new Win64Exception(this);<br>
-    return false;<br>
+    break;<br>
   }<br>
-<br>
-  llvm_unreachable("Unknown exception type.");<br>
+  if (DE)<br>
+    Handlers.push_back(HandlerInfo(DE, EHTimerName, DWARFGroupName));<br>
+  return false;<br>
 }<br>
<br>
 void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {<br>
@@ -311,8 +315,11 @@ void AsmPrinter::EmitGlobalVariable(cons<br>
   // sections and expected to be contiguous (e.g. ObjC metadata).<br>
   unsigned AlignLog = getGVAlignmentLog2(GV, *DL);<br>
<br>
-  if (DD)<br>
-    DD->setSymbolSize(GVSym, Size);<br>
+  for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {<br>
+    const HandlerInfo &OI = Handlers[I];<br>
+    NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);<br>
+    OI.Handler->setSymbolSize(GVSym, Size);<br>
+  }<br>
<br>
   // Handle common and BSS local symbols (.lcomm).<br>
   if (GVKind.isCommon() || GVKind.isBSSLocal()) {<br>
@@ -482,13 +489,10 @@ void AsmPrinter::EmitFunctionHeader() {<br>
   }<br>
<br>
   // Emit pre-function debug and/or EH information.<br>
-  if (DE) {<br>
-    NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-    DE->beginFunction(MF);<br>
-  }<br>
-  if (DD) {<br>
-    NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-    DD->beginFunction(MF);<br>
+  for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {<br>
+    const HandlerInfo &OI = Handlers[I];<br>
+    NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);<br>
+    OI.Handler->beginFunction(MF);<br>
   }<br>
<br>
   // Emit the prefix data.<br>
@@ -693,7 +697,7 @@ void AsmPrinter::EmitFunctionBody() {<br>
   // Emit target-specific gunk before the function body.<br>
   EmitFunctionBodyStart();<br>
<br>
-  bool ShouldPrintDebugScopes = DD && MMI->hasDebugInfo();<br>
+  bool ShouldPrintDebugScopes = MMI->hasDebugInfo();<br>
<br>
   // Print out code for the function.<br>
   bool HasAnyRealCode = false;<br>
@@ -714,8 +718,12 @@ void AsmPrinter::EmitFunctionBody() {<br>
       }<br>
<br>
       if (ShouldPrintDebugScopes) {<br>
-        NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-        DD->beginInstruction(II);<br>
+        for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III) {<br>
+          const HandlerInfo &OI = Handlers[III];<br>
+          NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,<br>
+                             TimePassesIsEnabled);<br>
+          OI.Handler->beginInstruction(II);<br>
+        }<br>
       }<br>
<br>
       if (isVerbose())<br>
@@ -754,8 +762,12 @@ void AsmPrinter::EmitFunctionBody() {<br>
       }<br>
<br>
       if (ShouldPrintDebugScopes) {<br>
-        NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-        DD->endInstruction(II);<br>
+        for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III) {<br>
+          const HandlerInfo &OI = Handlers[III];<br>
+          NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,<br>
+                             TimePassesIsEnabled);<br>
+          OI.Handler->endInstruction();<br>
+        }<br>
       }<br>
     }<br>
   }<br>
@@ -811,14 +823,11 @@ void AsmPrinter::EmitFunctionBody() {<br>
     OutStreamer.EmitELFSize(CurrentFnSym, SizeExp);<br>
   }<br>
<br>
-  // Emit post-function debug information.<br>
-  if (DD) {<br>
-    NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-    DD->endFunction(MF);<br>
-  }<br>
-  if (DE) {<br>
-    NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-    DE->endFunction();<br>
+  // Emit post-function debug and/or EH information.<br>
+  for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {<br>
+    const HandlerInfo &OI = Handlers[I];<br>
+    NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);<br>
+    OI.Handler->endFunction(MF);<br>
   }<br>
   MMI->EndFunction();<br>
<br>
@@ -907,20 +916,15 @@ bool AsmPrinter::doFinalization(Module &<br>
   OutStreamer.Flush();<br>
<br>
   // Finalize debug and EH information.<br>
-  if (DE) {<br>
-    {<br>
-      NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-      DE->endModule();<br>
-    }<br>
-    delete DE; DE = 0;<br>
-  }<br>
-  if (DD) {<br>
-    {<br>
-      NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);<br>
-      DD->endModule();<br>
-    }<br>
-    delete DD; DD = 0;<br>
+  for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {<br>
+    const HandlerInfo &OI = Handlers[I];<br>
+    NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,<br>
+                       TimePassesIsEnabled);<br>
+    OI.Handler->endModule();<br>
+    delete OI.Handler;<br>
   }<br>
+  Handlers.clear();<br>
+  DD = 0;<br>
<br>
   // If the target wants to know about weak references, print them all.<br>
   if (MAI->getWeakRefDirective()) {<br>
<br>
Added: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h?rev=196288&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h?rev=196288&view=auto</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h (added)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h Tue Dec  3 09:10:23 2013<br>
@@ -0,0 +1,56 @@<br>
+//===-- lib/CodeGen/AsmPrinter/AsmPrinterHandler.h -------------*- C++ -*--===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file contains a generic interface for AsmPrinter handlers,<br>
+// like debug and EH info emitters.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__<br>
+#define CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__<br>
+<br>
+#include "llvm/Support/DataTypes.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+class MachineFunction;<br>
+class MachineInstr;<br>
+class MCSymbol;<br>
+<br>
+/// \brief Collects and handles AsmPrinter objects required to build debug<br>
+/// or EH information.<br>
+class AsmPrinterHandler {<br>
+public:<br>
+  virtual ~AsmPrinterHandler() {}<br>
+<br>
+  /// \brief For symbols that have a size designated (e.g. common symbols),<br>
+  /// this tracks that size.<br>
+  virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) = 0;<br>
+<br>
+  /// \brief Emit all sections that should come after the content.<br>
+  virtual void endModule() = 0;<br>
+<br>
+  /// \brief Gather pre-function debug information.<br>
+  /// Every beginFunction(MF) call should be followed by an endFunction(MF) call.<br>
+  virtual void beginFunction(const MachineFunction *MF) = 0;<br>
+<br>
+  /// \brief Gather post-function debug information.<br>
+  /// Please note that some AsmPrinter implementationss may not call<br>
+  /// beginFunction at all.<br>
+  virtual void endFunction(const MachineFunction *MF) = 0;<br>
+<br>
+  /// \brief Process beginning of an instruction.<br>
+  virtual void beginInstruction(const MachineInstr *MI) = 0;<br>
+<br>
+  /// \brief Process end of an instruction.<br>
+  virtual void endInstruction() = 0;<br>
+};<br>
+} // End of namespace llvm<br>
+<br>
+#endif<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Tue Dec  3 09:10:23 2013<br>
@@ -390,7 +390,9 @@ unsigned DIEEntry::getRefAddrSize(AsmPri<br>
   // specified to be four bytes in the DWARF 32-bit format and eight bytes<br>
   // in the DWARF 64-bit format, while DWARF Version 2 specifies that such<br>
   // references have the same size as an address on the target system.<br>
-  if (AP->getDwarfDebug()->getDwarfVersion() == 2)<br>
+  const DwarfDebug *DD = AP->getDwarfDebug();<br>
+  assert(DD && "Expected Dwarf Debug info to be available");<br>
+  if (DD->getDwarfVersion() == 2)<br>
     return AP->getDataLayout().getPointerSize();<br>
   return sizeof(int32_t);<br>
 }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp Tue Dec  3 09:10:23 2013<br>
@@ -137,7 +137,7 @@ void DwarfCFIException::beginFunction(co<br>
<br>
 /// endFunction - Gather and emit post-function exception information.<br>
 ///<br>
-void DwarfCFIException::endFunction() {<br>
+void DwarfCFIException::endFunction(const MachineFunction *) {<br>
   if (!shouldEmitPersonality && !shouldEmitMoves)<br>
     return;<br>
<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Dec  3 09:10:23 2013<br>
@@ -197,6 +197,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo<br>
   DwarfAddrSectionSym = 0;<br>
   DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0;<br>
   FunctionBeginSym = FunctionEndSym = 0;<br>
+  CurFn = 0; CurMI = 0;<br>
<br>
   // Turn on accelerator tables for Darwin by default, pubnames by<br>
   // default for non-Darwin, and handle split dwarf.<br>
@@ -1144,6 +1145,8 @@ void DwarfDebug::endSections() {<br>
<br>
 // Emit all Dwarf sections that should come after the content.<br>
 void DwarfDebug::endModule() {<br>
+  assert(CurFn == 0);<br>
+  assert(CurMI == 0);<br>
<br>
   if (!FirstCU)<br>
     return;<br>
@@ -1225,8 +1228,7 @@ DbgVariable *DwarfDebug::findAbstractVar<br>
 }<br>
<br>
 // If Var is a current function argument then add it to CurrentFnArguments list.<br>
-bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,<br>
-                                      DbgVariable *Var, LexicalScope *Scope) {<br>
+bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {<br>
   if (!LScopes.isCurrentFunctionScope(Scope))<br>
     return false;<br>
   DIVariable DV = Var->getVariable();<br>
@@ -1238,7 +1240,7 @@ bool DwarfDebug::addCurrentFnArgument(co<br>
<br>
   size_t Size = CurrentFnArguments.size();<br>
   if (Size == 0)<br>
-    CurrentFnArguments.resize(MF->getFunction()->arg_size());<br>
+    CurrentFnArguments.resize(CurFn->getFunction()->arg_size());<br>
   // llvm::Function argument size is not good indicator of how many<br>
   // arguments does the function have at source level.<br>
   if (ArgNo > Size)<br>
@@ -1249,7 +1251,7 @@ bool DwarfDebug::addCurrentFnArgument(co<br>
<br>
 // Collect variable information from side table maintained by MMI.<br>
 void DwarfDebug::collectVariableInfoFromMMITable(<br>
-    const MachineFunction *MF, SmallPtrSet<const MDNode *, 16> &Processed) {<br>
+    SmallPtrSet<const MDNode *, 16> &Processed) {<br>
   MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();<br>
   for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),<br>
                                                          VE = VMap.end();<br>
@@ -1270,7 +1272,7 @@ void DwarfDebug::collectVariableInfoFrom<br>
     DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);<br>
     DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);<br>
     RegVar->setFrameIndex(VP.first);<br>
-    if (!addCurrentFnArgument(MF, RegVar, Scope))<br>
+    if (!addCurrentFnArgument(RegVar, Scope))<br>
       addScopeVariable(Scope, RegVar);<br>
     if (AbsDbgVariable)<br>
       AbsDbgVariable->setFrameIndex(VP.first);<br>
@@ -1317,11 +1319,10 @@ static DotDebugLocEntry getDebugLocEntry<br>
<br>
 // Find variables for each lexical scope.<br>
 void<br>
-DwarfDebug::collectVariableInfo(const MachineFunction *MF,<br>
-                                SmallPtrSet<const MDNode *, 16> &Processed) {<br>
+DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {<br>
<br>
   // Grab the variable info that was squirreled away in the MMI side-table.<br>
-  collectVariableInfoFromMMITable(MF, Processed);<br>
+  collectVariableInfoFromMMITable(Processed);<br>
<br>
   for (SmallVectorImpl<const MDNode *>::const_iterator<br>
            UVI = UserVariables.begin(),<br>
@@ -1341,7 +1342,7 @@ DwarfDebug::collectVariableInfo(const Ma<br>
     DIVariable DV(Var);<br>
     LexicalScope *Scope = NULL;<br>
     if (DV.getTag() == dwarf::DW_TAG_arg_variable &&<br>
-        DISubprogram(DV.getContext()).describes(MF->getFunction()))<br>
+        DISubprogram(DV.getContext()).describes(CurFn->getFunction()))<br>
       Scope = LScopes.getCurrentFunctionScope();<br>
     else if (MDNode *IA = DV.getInlinedAt())<br>
       Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));<br>
@@ -1355,7 +1356,7 @@ DwarfDebug::collectVariableInfo(const Ma<br>
     assert(MInsn->isDebugValue() && "History must begin with debug value");<br>
     DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());<br>
     DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);<br>
-    if (!addCurrentFnArgument(MF, RegVar, Scope))<br>
+    if (!addCurrentFnArgument(RegVar, Scope))<br>
       addScopeVariable(Scope, RegVar);<br>
     if (AbsVar)<br>
       AbsVar->setMInsn(MInsn);<br>
@@ -1437,6 +1438,8 @@ MCSymbol *DwarfDebug::getLabelAfterInsn(<br>
<br>
 // Process beginning of an instruction.<br>
 void DwarfDebug::beginInstruction(const MachineInstr *MI) {<br>
+  assert(CurMI == 0);<br>
+  CurMI = MI;<br>
   // Check if source location changes, but ignore DBG_VALUE locations.<br>
   if (!MI->isDebugValue()) {<br>
     DebugLoc DL = MI->getDebugLoc();<br>
@@ -1478,14 +1481,16 @@ void DwarfDebug::beginInstruction(const<br>
 }<br>
<br>
 // Process end of an instruction.<br>
-void DwarfDebug::endInstruction(const MachineInstr *MI) {<br>
+void DwarfDebug::endInstruction() {<br>
+  assert(CurMI != 0);<br>
   // Don't create a new label after DBG_VALUE instructions.<br>
   // They don't generate code.<br>
-  if (!MI->isDebugValue())<br>
+  if (!CurMI->isDebugValue())<br>
     PrevLabel = 0;<br>
<br>
   DenseMap<const MachineInstr *, MCSymbol *>::iterator I =<br>
-      LabelsAfterInsn.find(MI);<br>
+      LabelsAfterInsn.find(CurMI);<br>
+  CurMI = 0;<br>
<br>
   // No label needed.<br>
   if (I == LabelsAfterInsn.end())<br>
@@ -1565,6 +1570,7 @@ static DebugLoc getFnDebugLoc(DebugLoc D<br>
 // Gather pre-function debug information.  Assumes being called immediately<br>
 // after the function entry point has been emitted.<br>
 void DwarfDebug::beginFunction(const MachineFunction *MF) {<br>
+  CurFn = MF;<br>
<br>
   // If there's no debug info for the function we're not going to do anything.<br>
   if (!MMI->hasDebugInfo())<br>
@@ -1792,8 +1798,19 @@ void DwarfDebug::addScopeVariable(Lexica<br>
<br>
 // Gather and emit post-function debug information.<br>
 void DwarfDebug::endFunction(const MachineFunction *MF) {<br>
-  if (!MMI->hasDebugInfo() || LScopes.empty())<br>
+  // Every beginFunction(MF) call should be followed by an endFunction(MF) call,<br>
+  // though the beginFunction may not be called at all.<br>
+  // We should handle both cases.<br>
+  if (CurFn == 0)<br>
+    CurFn = MF;<br>
+  else<br>
+    assert(CurFn == MF);<br>
+  assert(CurFn != 0);<br>
+<br>
+  if (!MMI->hasDebugInfo() || LScopes.empty()) {<br>
+    CurFn = 0;<br>
     return;<br>
+  }<br>
<br>
   // Define end label for subprogram.<br>
   FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());<br>
@@ -1803,7 +1820,7 @@ void DwarfDebug::endFunction(const Machi<br>
   Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);<br>
<br>
   SmallPtrSet<const MDNode *, 16> ProcessedVars;<br>
-  collectVariableInfo(MF, ProcessedVars);<br>
+  collectVariableInfo(ProcessedVars);<br>
<br>
   LexicalScope *FnScope = LScopes.getCurrentFunctionScope();<br>
   CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());<br>
@@ -1837,7 +1854,7 @@ void DwarfDebug::endFunction(const Machi<br>
<br>
   DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);<br>
<br>
-  if (!MF->getTarget().Options.DisableFramePointerElim(*MF))<br>
+  if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))<br>
     TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);<br>
<br>
   // Clear debug info<br>
@@ -1853,6 +1870,7 @@ void DwarfDebug::endFunction(const Machi<br>
   LabelsBeforeInsn.clear();<br>
   LabelsAfterInsn.clear();<br>
   PrevLabel = NULL;<br>
+  CurFn = 0;<br>
 }<br>
<br>
 // Register a source line with debug info. Returns the  unique label that was<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Dec  3 09:10:23 2013<br>
@@ -14,6 +14,7 @@<br>
 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__<br>
 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__<br>
<br>
+#include "AsmPrinterHandler.h"<br>
 #include "DIE.h"<br>
 #include "llvm/ADT/DenseMap.h"<br>
 #include "llvm/ADT/FoldingSet.h"<br>
@@ -316,7 +317,7 @@ struct SymbolCU {<br>
 };<br>
<br>
 /// \brief Collects and handles dwarf debug information.<br>
-class DwarfDebug {<br>
+class DwarfDebug : public AsmPrinterHandler {<br>
   // Target of Dwarf emission.<br>
   AsmPrinter *Asm;<br>
<br>
@@ -418,6 +419,12 @@ class DwarfDebug {<br>
   // body.<br>
   DebugLoc PrologEndLoc;<br>
<br>
+  // If nonnull, stores the current machine function we're processing.<br>
+  const MachineFunction *CurFn;<br>
+<br>
+  // If nonnull, stores the current machine instruction we're processing.<br>
+  const MachineInstr *CurMI;<br>
+<br>
   // Section Symbols: these are assembler temporary labels that are emitted at<br>
   // the beginning of each supported dwarf section.  These are used to form<br>
   // section offsets and are created by EmitSectionLabels.<br>
@@ -648,17 +655,14 @@ class DwarfDebug {<br>
<br>
   /// \brief If Var is an current function argument that add it in<br>
   /// CurrentFnArguments list.<br>
-  bool addCurrentFnArgument(const MachineFunction *MF,<br>
-                            DbgVariable *Var, LexicalScope *Scope);<br>
+  bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);<br>
<br>
   /// \brief Populate LexicalScope entries with variables' info.<br>
-  void collectVariableInfo(const MachineFunction *,<br>
-                           SmallPtrSet<const MDNode *, 16> &ProcessedVars);<br>
+  void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);<br>
<br>
   /// \brief Collect variable information from the side table maintained<br>
   /// by MMI.<br>
-  void collectVariableInfoFromMMITable(const MachineFunction * MF,<br>
-                                       SmallPtrSet<const MDNode *, 16> &P);<br>
+  void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);<br>
<br>
   /// \brief Ensure that a label will be emitted before MI.<br>
   void requestLabelBeforeInsn(const MachineInstr *MI) {<br>
@@ -706,7 +710,7 @@ public:<br>
   void beginInstruction(const MachineInstr *MI);<br>
<br>
   /// \brief Process end of an instruction.<br>
-  void endInstruction(const MachineInstr *MI);<br>
+  void endInstruction();<br>
<br>
   /// \brief Add a DIE to the set of types that we're going to pull into<br>
   /// type units.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp Tue Dec  3 09:10:23 2013<br>
@@ -730,7 +730,6 @@ void DwarfException::beginFunction(const<br>
 }<br>
<br>
 /// endFunction - Gather and emit post-function exception information.<br>
-///<br>
-void DwarfException::endFunction() {<br>
+void DwarfException::endFunction(const MachineFunction *) {<br>
   llvm_unreachable("Should be implemented");<br>
 }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h Tue Dec  3 09:10:23 2013<br>
@@ -14,6 +14,7 @@<br>
 #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H<br>
 #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H<br>
<br>
+#include "AsmPrinterHandler.h"<br>
 #include "llvm/ADT/DenseMap.h"<br>
 #include "llvm/CodeGen/AsmPrinter.h"<br>
 #include <vector><br>
@@ -35,7 +36,7 @@ class AsmPrinter;<br>
 //===----------------------------------------------------------------------===//<br>
 /// DwarfException - Emits Dwarf exception handling directives.<br>
 ///<br>
-class DwarfException {<br>
+class DwarfException : public AsmPrinterHandler {<br>
 protected:<br>
   /// Asm - Target of Dwarf emission.<br>
   AsmPrinter *Asm;<br>
@@ -139,7 +140,12 @@ public:<br>
   virtual void beginFunction(const MachineFunction *MF);<br>
<br>
   /// endFunction - Gather and emit post-function exception information.<br>
-  virtual void endFunction();<br>
+  virtual void endFunction(const MachineFunction *);<br>
+<br>
+  // We don't need these.<br>
+  virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}<br>
+  virtual void beginInstruction(const MachineInstr *MI) {}<br>
+  virtual void endInstruction() {}<br>
 };<br>
<br>
 class DwarfCFIException : public DwarfException {<br>
@@ -173,7 +179,7 @@ public:<br>
   virtual void beginFunction(const MachineFunction *MF);<br>
<br>
   /// endFunction - Gather and emit post-function exception information.<br>
-  virtual void endFunction();<br>
+  virtual void endFunction(const MachineFunction *);<br>
 };<br>
<br>
 class ARMException : public DwarfException {<br>
@@ -196,7 +202,7 @@ public:<br>
   virtual void beginFunction(const MachineFunction *MF);<br>
<br>
   /// endFunction - Gather and emit post-function exception information.<br>
-  virtual void endFunction();<br>
+  virtual void endFunction(const MachineFunction *);<br>
 };<br>
<br>
 class Win64Exception : public DwarfException {<br>
@@ -228,7 +234,7 @@ public:<br>
   virtual void beginFunction(const MachineFunction *MF);<br>
<br>
   /// endFunction - Gather and emit post-function exception information.<br>
-  virtual void endFunction();<br>
+  virtual void endFunction(const MachineFunction *);<br>
 };<br>
<br>
 } // End of namespace llvm<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp?rev=196288&r1=196287&r2=196288&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp?rev=196288&r1=196287&r2=196288&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp Tue Dec  3 09:10:23 2013<br>
@@ -88,7 +88,7 @@ void Win64Exception::beginFunction(const<br>
<br>
 /// endFunction - Gather and emit post-function exception information.<br>
 ///<br>
-void Win64Exception::endFunction() {<br>
+void Win64Exception::endFunction(const MachineFunction *) {<br>
   if (!shouldEmitPersonality && !shouldEmitMoves)<br>
     return;<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>