@@ -99,14 +99,14 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, MCStreamer &Streamer)
9999 OutContext(Streamer.getContext()),
100100 OutStreamer(Streamer),
101101 LastMI(0 ), LastFn(0 ), Counter(~0U ), SetCounter(0 ) {
102- DD = 0 ; DE = 0 ; MMI = 0 ; LI = 0 ; MF = 0 ;
102+ DD = 0 ; MMI = 0 ; LI = 0 ; MF = 0 ;
103103 CurrentFnSym = CurrentFnSymForSize = 0 ;
104104 GCMetadataPrinters = 0 ;
105105 VerboseAsm = Streamer.isVerboseAsm ();
106106}
107107
108108AsmPrinter::~AsmPrinter () {
109- assert (DD == 0 && DE == 0 && " Debug/EH info didn't get finalized" );
109+ assert (DD == 0 && Handlers. empty () && " Debug/EH info didn't get finalized" );
110110
111111 if (GCMetadataPrinters != 0 ) {
112112 gcp_map_type &GCMap = getGCMap (GCMetadataPrinters);
@@ -192,25 +192,29 @@ bool AsmPrinter::doInitialization(Module &M) {
192192 OutStreamer.AddBlankLine ();
193193 }
194194
195- if (MAI->doesSupportDebugInformation ())
195+ if (MAI->doesSupportDebugInformation ()) {
196196 DD = new DwarfDebug (this , &M);
197+ Handlers.push_back (HandlerInfo (DD, DbgTimerName, DWARFGroupName));
198+ }
197199
200+ DwarfException *DE = 0 ;
198201 switch (MAI->getExceptionHandlingType ()) {
199202 case ExceptionHandling::None:
200- return false ;
203+ break ;
201204 case ExceptionHandling::SjLj:
202205 case ExceptionHandling::DwarfCFI:
203206 DE = new DwarfCFIException (this );
204- return false ;
207+ break ;
205208 case ExceptionHandling::ARM:
206209 DE = new ARMException (this );
207- return false ;
210+ break ;
208211 case ExceptionHandling::Win64:
209212 DE = new Win64Exception (this );
210- return false ;
213+ break ;
211214 }
212-
213- llvm_unreachable (" Unknown exception type." );
215+ if (DE)
216+ Handlers.push_back (HandlerInfo (DE, EHTimerName, DWARFGroupName));
217+ return false ;
214218}
215219
216220void AsmPrinter::EmitLinkage (const GlobalValue *GV, MCSymbol *GVSym) const {
@@ -311,8 +315,11 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
311315 // sections and expected to be contiguous (e.g. ObjC metadata).
312316 unsigned AlignLog = getGVAlignmentLog2 (GV, *DL);
313317
314- if (DD)
315- DD->setSymbolSize (GVSym, Size);
318+ for (unsigned I = 0 , E = Handlers.size (); I != E; ++I) {
319+ const HandlerInfo &OI = Handlers[I];
320+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName , TimePassesIsEnabled);
321+ OI.Handler ->setSymbolSize (GVSym, Size);
322+ }
316323
317324 // Handle common and BSS local symbols (.lcomm).
318325 if (GVKind.isCommon () || GVKind.isBSSLocal ()) {
@@ -482,13 +489,10 @@ void AsmPrinter::EmitFunctionHeader() {
482489 }
483490
484491 // Emit pre-function debug and/or EH information.
485- if (DE) {
486- NamedRegionTimer T (EHTimerName, DWARFGroupName, TimePassesIsEnabled);
487- DE->beginFunction (MF);
488- }
489- if (DD) {
490- NamedRegionTimer T (DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
491- DD->beginFunction (MF);
492+ for (unsigned I = 0 , E = Handlers.size (); I != E; ++I) {
493+ const HandlerInfo &OI = Handlers[I];
494+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName , TimePassesIsEnabled);
495+ OI.Handler ->beginFunction (MF);
492496 }
493497
494498 // Emit the prefix data.
@@ -693,7 +697,7 @@ void AsmPrinter::EmitFunctionBody() {
693697 // Emit target-specific gunk before the function body.
694698 EmitFunctionBodyStart ();
695699
696- bool ShouldPrintDebugScopes = DD && MMI->hasDebugInfo ();
700+ bool ShouldPrintDebugScopes = MMI->hasDebugInfo ();
697701
698702 // Print out code for the function.
699703 bool HasAnyRealCode = false ;
@@ -714,8 +718,12 @@ void AsmPrinter::EmitFunctionBody() {
714718 }
715719
716720 if (ShouldPrintDebugScopes) {
717- NamedRegionTimer T (DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
718- DD->beginInstruction (II);
721+ for (unsigned III = 0 , EEE = Handlers.size (); III != EEE; ++III) {
722+ const HandlerInfo &OI = Handlers[III];
723+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName ,
724+ TimePassesIsEnabled);
725+ OI.Handler ->beginInstruction (II);
726+ }
719727 }
720728
721729 if (isVerbose ())
@@ -754,8 +762,12 @@ void AsmPrinter::EmitFunctionBody() {
754762 }
755763
756764 if (ShouldPrintDebugScopes) {
757- NamedRegionTimer T (DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
758- DD->endInstruction (II);
765+ for (unsigned III = 0 , EEE = Handlers.size (); III != EEE; ++III) {
766+ const HandlerInfo &OI = Handlers[III];
767+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName ,
768+ TimePassesIsEnabled);
769+ OI.Handler ->endInstruction ();
770+ }
759771 }
760772 }
761773 }
@@ -811,14 +823,11 @@ void AsmPrinter::EmitFunctionBody() {
811823 OutStreamer.EmitELFSize (CurrentFnSym, SizeExp);
812824 }
813825
814- // Emit post-function debug information.
815- if (DD) {
816- NamedRegionTimer T (DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
817- DD->endFunction (MF);
818- }
819- if (DE) {
820- NamedRegionTimer T (EHTimerName, DWARFGroupName, TimePassesIsEnabled);
821- DE->endFunction ();
826+ // Emit post-function debug and/or EH information.
827+ for (unsigned I = 0 , E = Handlers.size (); I != E; ++I) {
828+ const HandlerInfo &OI = Handlers[I];
829+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName , TimePassesIsEnabled);
830+ OI.Handler ->endFunction (MF);
822831 }
823832 MMI->EndFunction ();
824833
@@ -907,20 +916,15 @@ bool AsmPrinter::doFinalization(Module &M) {
907916 OutStreamer.Flush ();
908917
909918 // Finalize debug and EH information.
910- if (DE) {
911- {
912- NamedRegionTimer T (EHTimerName, DWARFGroupName, TimePassesIsEnabled);
913- DE->endModule ();
914- }
915- delete DE; DE = 0 ;
916- }
917- if (DD) {
918- {
919- NamedRegionTimer T (DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
920- DD->endModule ();
921- }
922- delete DD; DD = 0 ;
923- }
919+ for (unsigned I = 0 , E = Handlers.size (); I != E; ++I) {
920+ const HandlerInfo &OI = Handlers[I];
921+ NamedRegionTimer T (OI.TimerName , OI.TimerGroupName ,
922+ TimePassesIsEnabled);
923+ OI.Handler ->endModule ();
924+ delete OI.Handler ;
925+ }
926+ Handlers.clear ();
927+ DD = 0 ;
924928
925929 // If the target wants to know about weak references, print them all.
926930 if (MAI->getWeakRefDirective ()) {
0 commit comments