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 ;
@@ -548,19 +536,13 @@ bool AsmPrinter::doInitialization(Module &M) {
548
536
549
537
if (MAI->doesSupportDebugInformation ()) {
550
538
bool EmitCodeView = M.getCodeViewFlag ();
551
- if (EmitCodeView && TM.getTargetTriple ().isOSWindows ()) {
552
- DebugHandlers.emplace_back (std::make_unique<CodeViewDebug>(this ),
553
- DbgTimerName, DbgTimerDescription,
554
- CodeViewLineTablesGroupName,
555
- CodeViewLineTablesGroupDescription);
556
- }
539
+ if (EmitCodeView && TM.getTargetTriple ().isOSWindows ())
540
+ DebugHandlers.push_back (std::make_unique<CodeViewDebug>(this ));
557
541
if (!EmitCodeView || M.getDwarfVersion ()) {
558
542
assert (MMI && " MMI could not be nullptr here!" );
559
543
if (MMI->hasDebugInfo ()) {
560
544
DD = new DwarfDebug (this );
561
- DebugHandlers.emplace_back (std::unique_ptr<DwarfDebug>(DD),
562
- DbgTimerName, DbgTimerDescription,
563
- DWARFGroupName, DWARFGroupDescription);
545
+ DebugHandlers.push_back (std::unique_ptr<DwarfDebug>(DD));
564
546
}
565
547
}
566
548
}
@@ -623,26 +605,16 @@ bool AsmPrinter::doInitialization(Module &M) {
623
605
break ;
624
606
}
625
607
if (ES)
626
- Handlers.emplace_back (std::unique_ptr<EHStreamer>(ES), EHTimerName,
627
- EHTimerDescription, DWARFGroupName,
628
- DWARFGroupDescription);
608
+ Handlers.push_back (std::unique_ptr<EHStreamer>(ES));
629
609
630
610
// Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
631
611
if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag (" cfguard" )))
632
- Handlers.emplace_back (std::make_unique<WinCFGuard>(this ), CFGuardName,
633
- CFGuardDescription, DWARFGroupName,
634
- DWARFGroupDescription);
635
-
636
- for (const auto &HI : DebugHandlers) {
637
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
638
- HI.TimerGroupDescription , TimePassesIsEnabled);
639
- HI.Handler ->beginModule (&M);
640
- }
641
- for (const auto &HI : Handlers) {
642
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
643
- HI.TimerGroupDescription , TimePassesIsEnabled);
644
- HI.Handler ->beginModule (&M);
645
- }
612
+ Handlers.push_back (std::make_unique<WinCFGuard>(this ));
613
+
614
+ for (auto &Handler : DebugHandlers)
615
+ Handler->beginModule (&M);
616
+ for (auto &Handler : Handlers)
617
+ Handler->beginModule (&M);
646
618
647
619
return false ;
648
620
}
@@ -789,11 +761,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
789
761
// sections and expected to be contiguous (e.g. ObjC metadata).
790
762
const Align Alignment = getGVAlignment (GV, DL);
791
763
792
- for (auto &HI : DebugHandlers) {
793
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
794
- HI.TimerGroupDescription , TimePassesIsEnabled);
795
- HI.Handler ->setSymbolSize (GVSym, Size);
796
- }
764
+ for (auto &Handler : DebugHandlers)
765
+ Handler->setSymbolSize (GVSym, Size);
797
766
798
767
// Handle common symbols
799
768
if (GVKind.isCommon ()) {
@@ -1064,22 +1033,14 @@ void AsmPrinter::emitFunctionHeader() {
1064
1033
}
1065
1034
1066
1035
// Emit pre-function debug and/or EH information.
1067
- for (const auto &HI : DebugHandlers) {
1068
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1069
- HI.TimerGroupDescription , TimePassesIsEnabled);
1070
- HI.Handler ->beginFunction (MF);
1071
- HI.Handler ->beginBasicBlockSection (MF->front ());
1072
- }
1073
- for (const auto &HI : Handlers) {
1074
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1075
- HI.TimerGroupDescription , TimePassesIsEnabled);
1076
- HI.Handler ->beginFunction (MF);
1077
- }
1078
- for (const auto &HI : Handlers) {
1079
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
1080
- HI.TimerGroupDescription , TimePassesIsEnabled);
1081
- HI.Handler ->beginBasicBlockSection (MF->front ());
1036
+ for (auto &Handler : DebugHandlers) {
1037
+ Handler->beginFunction (MF);
1038
+ Handler->beginBasicBlockSection (MF->front ());
1082
1039
}
1040
+ for (auto &Handler : Handlers)
1041
+ Handler->beginFunction (MF);
1042
+ for (auto &Handler : Handlers)
1043
+ Handler->beginBasicBlockSection (MF->front ());
1083
1044
1084
1045
// Emit the prologue data.
1085
1046
if (F.hasPrologueData ())
@@ -1773,8 +1734,8 @@ void AsmPrinter::emitFunctionBody() {
1773
1734
if (MDNode *MD = MI.getPCSections ())
1774
1735
emitPCSectionsLabel (*MF, *MD);
1775
1736
1776
- for (const auto &HI : DebugHandlers)
1777
- HI. Handler ->beginInstruction (&MI);
1737
+ for (auto &Handler : DebugHandlers)
1738
+ Handler->beginInstruction (&MI);
1778
1739
1779
1740
if (isVerbose ())
1780
1741
emitComments (MI, OutStreamer->getCommentOS ());
@@ -1868,8 +1829,8 @@ void AsmPrinter::emitFunctionBody() {
1868
1829
if (MCSymbol *S = MI.getPostInstrSymbol ())
1869
1830
OutStreamer->emitLabel (S);
1870
1831
1871
- for (const auto &HI : DebugHandlers)
1872
- HI. Handler ->endInstruction ();
1832
+ for (auto &Handler : DebugHandlers)
1833
+ Handler->endInstruction ();
1873
1834
}
1874
1835
1875
1836
// We must emit temporary symbol for the end of this basic block, if either
@@ -2000,22 +1961,13 @@ void AsmPrinter::emitFunctionBody() {
2000
1961
// Call endBasicBlockSection on the last block now, if it wasn't already
2001
1962
// called.
2002
1963
if (!MF->back ().isEndSection ()) {
2003
- for (const auto &HI : DebugHandlers) {
2004
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2005
- HI.TimerGroupDescription , TimePassesIsEnabled);
2006
- HI.Handler ->endBasicBlockSection (MF->back ());
2007
- }
2008
- for (const auto &HI : Handlers) {
2009
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2010
- HI.TimerGroupDescription , TimePassesIsEnabled);
2011
- HI.Handler ->endBasicBlockSection (MF->back ());
2012
- }
2013
- }
2014
- for (const auto &HI : Handlers) {
2015
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2016
- HI.TimerGroupDescription , TimePassesIsEnabled);
2017
- HI.Handler ->markFunctionEnd ();
1964
+ for (auto &Handler : DebugHandlers)
1965
+ Handler->endBasicBlockSection (MF->back ());
1966
+ for (auto &Handler : Handlers)
1967
+ Handler->endBasicBlockSection (MF->back ());
2018
1968
}
1969
+ for (auto &Handler : Handlers)
1970
+ Handler->markFunctionEnd ();
2019
1971
2020
1972
MBBSectionRanges[MF->front ().getSectionIDNum ()] =
2021
1973
MBBSectionRange{CurrentFnBegin, CurrentFnEnd};
@@ -2024,16 +1976,10 @@ void AsmPrinter::emitFunctionBody() {
2024
1976
emitJumpTableInfo ();
2025
1977
2026
1978
// Emit post-function debug and/or EH information.
2027
- for (const auto &HI : DebugHandlers) {
2028
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2029
- HI.TimerGroupDescription , TimePassesIsEnabled);
2030
- HI.Handler ->endFunction (MF);
2031
- }
2032
- for (const auto &HI : Handlers) {
2033
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2034
- HI.TimerGroupDescription , TimePassesIsEnabled);
2035
- HI.Handler ->endFunction (MF);
2036
- }
1979
+ for (auto &Handler : DebugHandlers)
1980
+ Handler->endFunction (MF);
1981
+ for (auto &Handler : Handlers)
1982
+ Handler->endFunction (MF);
2037
1983
2038
1984
// Emit section containing BB address offsets and their metadata, when
2039
1985
// BB labels are requested for this function. Skip empty functions.
@@ -2470,16 +2416,10 @@ bool AsmPrinter::doFinalization(Module &M) {
2470
2416
emitGlobalIFunc (M, IFunc);
2471
2417
2472
2418
// Finalize debug and EH information.
2473
- for (const auto &HI : DebugHandlers) {
2474
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2475
- HI.TimerGroupDescription , TimePassesIsEnabled);
2476
- HI.Handler ->endModule ();
2477
- }
2478
- for (const auto &HI : Handlers) {
2479
- NamedRegionTimer T (HI.TimerName , HI.TimerDescription , HI.TimerGroupName ,
2480
- HI.TimerGroupDescription , TimePassesIsEnabled);
2481
- HI.Handler ->endModule ();
2482
- }
2419
+ for (auto &Handler : DebugHandlers)
2420
+ Handler->endModule ();
2421
+ for (auto &Handler : Handlers)
2422
+ Handler->endModule ();
2483
2423
2484
2424
// This deletes all the ephemeral handlers that AsmPrinter added, while
2485
2425
// keeping all the user-added handlers alive until the AsmPrinter is
@@ -4001,9 +3941,9 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB,
4001
3941
void AsmPrinter::emitBasicBlockStart (const MachineBasicBlock &MBB) {
4002
3942
// End the previous funclet and start a new one.
4003
3943
if (MBB.isEHFuncletEntry ()) {
4004
- for (const auto &HI : Handlers) {
4005
- HI. Handler ->endFunclet ();
4006
- HI. Handler ->beginFunclet (MBB);
3944
+ for (auto &Handler : Handlers) {
3945
+ Handler->endFunclet ();
3946
+ Handler->beginFunclet (MBB);
4007
3947
}
4008
3948
}
4009
3949
@@ -4074,21 +4014,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
4074
4014
// if it begins a section (Entry block call is handled separately, next to
4075
4015
// beginFunction).
4076
4016
if (MBB.isBeginSection () && !MBB.isEntryBlock ()) {
4077
- for (const auto &HI : DebugHandlers)
4078
- HI. Handler ->beginBasicBlockSection (MBB);
4079
- for (const auto &HI : Handlers)
4080
- HI. Handler ->beginBasicBlockSection (MBB);
4017
+ for (auto &Handler : DebugHandlers)
4018
+ Handler->beginBasicBlockSection (MBB);
4019
+ for (auto &Handler : Handlers)
4020
+ Handler->beginBasicBlockSection (MBB);
4081
4021
}
4082
4022
}
4083
4023
4084
4024
void AsmPrinter::emitBasicBlockEnd (const MachineBasicBlock &MBB) {
4085
4025
// Check if CFI information needs to be updated for this MBB with basic block
4086
4026
// sections.
4087
4027
if (MBB.isEndSection ()) {
4088
- for (const auto &HI : DebugHandlers)
4089
- HI. Handler ->endBasicBlockSection (MBB);
4090
- for (const auto &HI : Handlers)
4091
- HI. Handler ->endBasicBlockSection (MBB);
4028
+ for (auto &Handler : DebugHandlers)
4029
+ Handler->endBasicBlockSection (MBB);
4030
+ for (auto &Handler : Handlers)
4031
+ Handler->endBasicBlockSection (MBB);
4092
4032
}
4093
4033
}
4094
4034
0 commit comments