113113#include " llvm/Support/Format.h"
114114#include " llvm/Support/MathExtras.h"
115115#include " llvm/Support/Path.h"
116- #include " llvm/Support/Timer.h"
117116#include " llvm/Support/VCSRevision.h"
118117#include " llvm/Support/raw_ostream.h"
119118#include " llvm/Target/TargetLoweringObjectFile.h"
@@ -156,17 +155,6 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
156155 " Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
157156 " extracted from PGO related analysis." ));
158157
159- const char DWARFGroupName[] = " dwarf" ;
160- const char DWARFGroupDescription[] = " DWARF Emission" ;
161- const char DbgTimerName[] = " emit" ;
162- const char DbgTimerDescription[] = " Debug Info Emission" ;
163- const char EHTimerName[] = " write_exception" ;
164- const char EHTimerDescription[] = " DWARF Exception Writer" ;
165- const char CFGuardName[] = " Control Flow Guard" ;
166- const char CFGuardDescription[] = " Control Flow Guard" ;
167- const char CodeViewLineTablesGroupName[] = " linetables" ;
168- const char CodeViewLineTablesGroupDescription[] = " CodeView Line Tables" ;
169-
170158STATISTIC (EmittedInsts, " Number of machine instrs printed" );
171159
172160char AsmPrinter::ID = 0 ;
@@ -550,19 +538,13 @@ bool AsmPrinter::doInitialization(Module &M) {
550538
551539 if (MAI->doesSupportDebugInformation ()) {
552540 bool EmitCodeView = M.getCodeViewFlag ();
553- if (EmitCodeView && TM.getTargetTriple ().isOSWindows ()) {
554- DebugHandlers.emplace_back (std::make_unique<CodeViewDebug>(this ),
555- DbgTimerName, DbgTimerDescription,
556- CodeViewLineTablesGroupName,
557- CodeViewLineTablesGroupDescription);
558- }
541+ if (EmitCodeView && TM.getTargetTriple ().isOSWindows ())
542+ DebugHandlers.push_back (std::make_unique<CodeViewDebug>(this ));
559543 if (!EmitCodeView || M.getDwarfVersion ()) {
560544 assert (MMI && " MMI could not be nullptr here!" );
561545 if (MMI->hasDebugInfo ()) {
562546 DD = new DwarfDebug (this );
563- DebugHandlers.emplace_back (std::unique_ptr<DwarfDebug>(DD),
564- DbgTimerName, DbgTimerDescription,
565- DWARFGroupName, DWARFGroupDescription);
547+ DebugHandlers.push_back (std::unique_ptr<DwarfDebug>(DD));
566548 }
567549 }
568550 }
@@ -625,26 +607,16 @@ bool AsmPrinter::doInitialization(Module &M) {
625607 break ;
626608 }
627609 if (ES)
628- Handlers.emplace_back (std::unique_ptr<EHStreamer>(ES), EHTimerName,
629- EHTimerDescription, DWARFGroupName,
630- DWARFGroupDescription);
610+ Handlers.push_back (std::unique_ptr<EHStreamer>(ES));
631611
632612 // Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
633613 if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag (" cfguard" )))
634- Handlers.emplace_back (std::make_unique<WinCFGuard>(this ), CFGuardName,
635- CFGuardDescription, DWARFGroupName,
636- DWARFGroupDescription);
614+ Handlers.push_back (std::make_unique<WinCFGuard>(this ));
637615
638- for (const auto &HI : DebugHandlers) {
639- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
640- HI.TimerGroupDescription , TimePassesIsEnabled);
641- HI.Handler ->beginModule (&M);
642- }
643- for (const auto &HI : Handlers) {
644- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
645- HI.TimerGroupDescription , TimePassesIsEnabled);
646- HI.Handler ->beginModule (&M);
647- }
616+ for (auto &Handler : DebugHandlers)
617+ Handler->beginModule (&M);
618+ for (auto &Handler : Handlers)
619+ Handler->beginModule (&M);
648620
649621 return false ;
650622}
@@ -791,11 +763,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
791763 // sections and expected to be contiguous (e.g. ObjC metadata).
792764 const Align Alignment = getGVAlignment (GV, DL);
793765
794- for (auto &HI : DebugHandlers) {
795- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
796- HI.TimerGroupDescription , TimePassesIsEnabled);
797- HI.Handler ->setSymbolSize (GVSym, Size);
798- }
766+ for (auto &Handler : DebugHandlers)
767+ Handler->setSymbolSize (GVSym, Size);
799768
800769 // Handle common symbols
801770 if (GVKind.isCommon ()) {
@@ -1066,22 +1035,14 @@ void AsmPrinter::emitFunctionHeader() {
10661035 }
10671036
10681037 // Emit pre-function debug and/or EH information.
1069- for (const auto &HI : DebugHandlers) {
1070- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1071- HI.TimerGroupDescription , TimePassesIsEnabled);
1072- HI.Handler ->beginFunction (MF);
1073- HI.Handler ->beginBasicBlockSection (MF->front ());
1074- }
1075- for (const auto &HI : Handlers) {
1076- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1077- HI.TimerGroupDescription , TimePassesIsEnabled);
1078- HI.Handler ->beginFunction (MF);
1079- }
1080- for (const auto &HI : Handlers) {
1081- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1082- HI.TimerGroupDescription , TimePassesIsEnabled);
1083- HI.Handler ->beginBasicBlockSection (MF->front ());
1038+ for (auto &Handler : DebugHandlers) {
1039+ Handler->beginFunction (MF);
1040+ Handler->beginBasicBlockSection (MF->front ());
10841041 }
1042+ for (auto &Handler : Handlers)
1043+ Handler->beginFunction (MF);
1044+ for (auto &Handler : Handlers)
1045+ Handler->beginBasicBlockSection (MF->front ());
10851046
10861047 // Emit the prologue data.
10871048 if (F.hasPrologueData ())
@@ -1776,11 +1737,8 @@ void AsmPrinter::emitFunctionBody() {
17761737 if (MDNode *MD = MI.getPCSections ())
17771738 emitPCSectionsLabel (*MF, *MD);
17781739
1779- for (const auto &HI : DebugHandlers) {
1780- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1781- HI.TimerGroupDescription , TimePassesIsEnabled);
1782- HI.Handler ->beginInstruction (&MI);
1783- }
1740+ for (auto &Handler : DebugHandlers)
1741+ Handler->beginInstruction (&MI);
17841742
17851743 if (isVerbose ())
17861744 emitComments (MI, OutStreamer->getCommentOS ());
@@ -1874,11 +1832,8 @@ void AsmPrinter::emitFunctionBody() {
18741832 if (MCSymbol *S = MI.getPostInstrSymbol ())
18751833 OutStreamer->emitLabel (S);
18761834
1877- for (const auto &HI : DebugHandlers) {
1878- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1879- HI.TimerGroupDescription , TimePassesIsEnabled);
1880- HI.Handler ->endInstruction ();
1881- }
1835+ for (auto &Handler : DebugHandlers)
1836+ Handler->endInstruction ();
18821837 }
18831838
18841839 // We must emit temporary symbol for the end of this basic block, if either
@@ -2009,22 +1964,13 @@ void AsmPrinter::emitFunctionBody() {
20091964 // Call endBasicBlockSection on the last block now, if it wasn't already
20101965 // called.
20111966 if (!MF->back ().isEndSection ()) {
2012- for (const auto &HI : DebugHandlers) {
2013- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2014- HI.TimerGroupDescription , TimePassesIsEnabled);
2015- HI.Handler ->endBasicBlockSection (MF->back ());
2016- }
2017- for (const auto &HI : Handlers) {
2018- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2019- HI.TimerGroupDescription , TimePassesIsEnabled);
2020- HI.Handler ->endBasicBlockSection (MF->back ());
2021- }
2022- }
2023- for (const auto &HI : Handlers) {
2024- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2025- HI.TimerGroupDescription , TimePassesIsEnabled);
2026- HI.Handler ->markFunctionEnd ();
1967+ for (auto &Handler : DebugHandlers)
1968+ Handler->endBasicBlockSection (MF->back ());
1969+ for (auto &Handler : Handlers)
1970+ Handler->endBasicBlockSection (MF->back ());
20271971 }
1972+ for (auto &Handler : Handlers)
1973+ Handler->markFunctionEnd ();
20281974
20291975 MBBSectionRanges[MF->front ().getSectionIDNum ()] =
20301976 MBBSectionRange{CurrentFnBegin, CurrentFnEnd};
@@ -2033,16 +1979,10 @@ void AsmPrinter::emitFunctionBody() {
20331979 emitJumpTableInfo ();
20341980
20351981 // Emit post-function debug and/or EH information.
2036- for (const auto &HI : DebugHandlers) {
2037- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2038- HI.TimerGroupDescription , TimePassesIsEnabled);
2039- HI.Handler ->endFunction (MF);
2040- }
2041- for (const auto &HI : Handlers) {
2042- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2043- HI.TimerGroupDescription , TimePassesIsEnabled);
2044- HI.Handler ->endFunction (MF);
2045- }
1982+ for (auto &Handler : DebugHandlers)
1983+ Handler->endFunction (MF);
1984+ for (auto &Handler : Handlers)
1985+ Handler->endFunction (MF);
20461986
20471987 // Emit section containing BB address offsets and their metadata, when
20481988 // BB labels are requested for this function. Skip empty functions.
@@ -2479,16 +2419,10 @@ bool AsmPrinter::doFinalization(Module &M) {
24792419 emitGlobalIFunc (M, IFunc);
24802420
24812421 // Finalize debug and EH information.
2482- for (const auto &HI : DebugHandlers) {
2483- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2484- HI.TimerGroupDescription , TimePassesIsEnabled);
2485- HI.Handler ->endModule ();
2486- }
2487- for (const auto &HI : Handlers) {
2488- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2489- HI.TimerGroupDescription , TimePassesIsEnabled);
2490- HI.Handler ->endModule ();
2491- }
2422+ for (auto &Handler : DebugHandlers)
2423+ Handler->endModule ();
2424+ for (auto &Handler : Handlers)
2425+ Handler->endModule ();
24922426
24932427 // This deletes all the ephemeral handlers that AsmPrinter added, while
24942428 // keeping all the user-added handlers alive until the AsmPrinter is
@@ -4010,9 +3944,9 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB,
40103944void AsmPrinter::emitBasicBlockStart (const MachineBasicBlock &MBB) {
40113945 // End the previous funclet and start a new one.
40123946 if (MBB.isEHFuncletEntry ()) {
4013- for (const auto &HI : Handlers) {
4014- HI. Handler ->endFunclet ();
4015- HI. Handler ->beginFunclet (MBB);
3947+ for (auto &Handler : Handlers) {
3948+ Handler->endFunclet ();
3949+ Handler->beginFunclet (MBB);
40163950 }
40173951 }
40183952
@@ -4083,21 +4017,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
40834017 // if it begins a section (Entry block call is handled separately, next to
40844018 // beginFunction).
40854019 if (MBB.isBeginSection () && !MBB.isEntryBlock ()) {
4086- for (const auto &HI : DebugHandlers)
4087- HI. Handler ->beginBasicBlockSection (MBB);
4088- for (const auto &HI : Handlers)
4089- HI. Handler ->beginBasicBlockSection (MBB);
4020+ for (auto &Handler : DebugHandlers)
4021+ Handler->beginBasicBlockSection (MBB);
4022+ for (auto &Handler : Handlers)
4023+ Handler->beginBasicBlockSection (MBB);
40904024 }
40914025}
40924026
40934027void AsmPrinter::emitBasicBlockEnd (const MachineBasicBlock &MBB) {
40944028 // Check if CFI information needs to be updated for this MBB with basic block
40954029 // sections.
40964030 if (MBB.isEndSection ()) {
4097- for (const auto &HI : DebugHandlers)
4098- HI. Handler ->endBasicBlockSection (MBB);
4099- for (const auto &HI : Handlers)
4100- HI. Handler ->endBasicBlockSection (MBB);
4031+ for (auto &Handler : DebugHandlers)
4032+ Handler->endBasicBlockSection (MBB);
4033+ for (auto &Handler : Handlers)
4034+ Handler->endBasicBlockSection (MBB);
41014035 }
41024036}
41034037
@@ -4225,6 +4159,17 @@ void AsmPrinter::emitStackMaps() {
42254159 SM.serializeToStackMapSection ();
42264160}
42274161
4162+ void AsmPrinter::addAsmPrinterHandler (
4163+ std::unique_ptr<AsmPrinterHandler> Handler) {
4164+ Handlers.insert (Handlers.begin (), std::move (Handler));
4165+ NumUserHandlers++;
4166+ }
4167+
4168+ void AsmPrinter::addDebugHandler (std::unique_ptr<DebugHandlerBase> Handler) {
4169+ DebugHandlers.insert (DebugHandlers.begin (), std::move (Handler));
4170+ NumUserDebugHandlers++;
4171+ }
4172+
42284173// / Pin vtable to this file.
42294174AsmPrinterHandler::~AsmPrinterHandler () = default ;
42304175
0 commit comments