113
113
#include " llvm/Support/Format.h"
114
114
#include " llvm/Support/MathExtras.h"
115
115
#include " llvm/Support/Path.h"
116
- #include " llvm/Support/Timer.h"
117
116
#include " llvm/Support/VCSRevision.h"
118
117
#include " llvm/Support/raw_ostream.h"
119
118
#include " llvm/Target/TargetLoweringObjectFile.h"
@@ -156,17 +155,6 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
156
155
" Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
157
156
" extracted from PGO related analysis." ));
158
157
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
-
170
158
STATISTIC (EmittedInsts, " Number of machine instrs printed" );
171
159
172
160
char AsmPrinter::ID = 0 ;
@@ -550,19 +538,13 @@ bool AsmPrinter::doInitialization(Module &M) {
550
538
551
539
if (MAI->doesSupportDebugInformation ()) {
552
540
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 ));
559
543
if (!EmitCodeView || M.getDwarfVersion ()) {
560
544
assert (MMI && " MMI could not be nullptr here!" );
561
545
if (MMI->hasDebugInfo ()) {
562
546
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));
566
548
}
567
549
}
568
550
}
@@ -625,26 +607,16 @@ bool AsmPrinter::doInitialization(Module &M) {
625
607
break ;
626
608
}
627
609
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));
631
611
632
612
// Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
633
613
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 ));
637
615
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);
648
620
649
621
return false ;
650
622
}
@@ -791,11 +763,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
791
763
// sections and expected to be contiguous (e.g. ObjC metadata).
792
764
const Align Alignment = getGVAlignment (GV, DL);
793
765
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);
799
768
800
769
// Handle common symbols
801
770
if (GVKind.isCommon ()) {
@@ -1066,22 +1035,14 @@ void AsmPrinter::emitFunctionHeader() {
1066
1035
}
1067
1036
1068
1037
// 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 ());
1084
1041
}
1042
+ for (auto &Handler : Handlers)
1043
+ Handler->beginFunction (MF);
1044
+ for (auto &Handler : Handlers)
1045
+ Handler->beginBasicBlockSection (MF->front ());
1085
1046
1086
1047
// Emit the prologue data.
1087
1048
if (F.hasPrologueData ())
@@ -1776,11 +1737,8 @@ void AsmPrinter::emitFunctionBody() {
1776
1737
if (MDNode *MD = MI.getPCSections ())
1777
1738
emitPCSectionsLabel (*MF, *MD);
1778
1739
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);
1784
1742
1785
1743
if (isVerbose ())
1786
1744
emitComments (MI, OutStreamer->getCommentOS ());
@@ -1874,11 +1832,8 @@ void AsmPrinter::emitFunctionBody() {
1874
1832
if (MCSymbol *S = MI.getPostInstrSymbol ())
1875
1833
OutStreamer->emitLabel (S);
1876
1834
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 ();
1882
1837
}
1883
1838
1884
1839
// We must emit temporary symbol for the end of this basic block, if either
@@ -2009,22 +1964,13 @@ void AsmPrinter::emitFunctionBody() {
2009
1964
// Call endBasicBlockSection on the last block now, if it wasn't already
2010
1965
// called.
2011
1966
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 ());
2027
1971
}
1972
+ for (auto &Handler : Handlers)
1973
+ Handler->markFunctionEnd ();
2028
1974
2029
1975
MBBSectionRanges[MF->front ().getSectionIDNum ()] =
2030
1976
MBBSectionRange{CurrentFnBegin, CurrentFnEnd};
@@ -2033,16 +1979,10 @@ void AsmPrinter::emitFunctionBody() {
2033
1979
emitJumpTableInfo ();
2034
1980
2035
1981
// 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);
2046
1986
2047
1987
// Emit section containing BB address offsets and their metadata, when
2048
1988
// BB labels are requested for this function. Skip empty functions.
@@ -2479,16 +2419,10 @@ bool AsmPrinter::doFinalization(Module &M) {
2479
2419
emitGlobalIFunc (M, IFunc);
2480
2420
2481
2421
// 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 ();
2492
2426
2493
2427
// This deletes all the ephemeral handlers that AsmPrinter added, while
2494
2428
// keeping all the user-added handlers alive until the AsmPrinter is
@@ -4010,9 +3944,9 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB,
4010
3944
void AsmPrinter::emitBasicBlockStart (const MachineBasicBlock &MBB) {
4011
3945
// End the previous funclet and start a new one.
4012
3946
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);
4016
3950
}
4017
3951
}
4018
3952
@@ -4083,21 +4017,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
4083
4017
// if it begins a section (Entry block call is handled separately, next to
4084
4018
// beginFunction).
4085
4019
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);
4090
4024
}
4091
4025
}
4092
4026
4093
4027
void AsmPrinter::emitBasicBlockEnd (const MachineBasicBlock &MBB) {
4094
4028
// Check if CFI information needs to be updated for this MBB with basic block
4095
4029
// sections.
4096
4030
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);
4101
4035
}
4102
4036
}
4103
4037
@@ -4225,6 +4159,17 @@ void AsmPrinter::emitStackMaps() {
4225
4159
SM.serializeToStackMapSection ();
4226
4160
}
4227
4161
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
+
4228
4173
// / Pin vtable to this file.
4229
4174
AsmPrinterHandler::~AsmPrinterHandler () = default ;
4230
4175
0 commit comments