@@ -104,6 +104,21 @@ static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
104
104
" sanitizer-early-opt-ep" , cl::Optional,
105
105
cl::desc (" Insert sanitizers on OptimizerEarlyEP." ));
106
106
107
+ // Experiment to mark cold functions as optsize/minsize/optnone.
108
+ // TODO: remove once this is exposed as a proper driver flag.
109
+ static cl::opt<PGOOptions::ColdFuncOpt> ClPGOColdFuncAttr (
110
+ " pgo-cold-func-opt" , cl::init(PGOOptions::ColdFuncOpt::Default), cl::Hidden,
111
+ cl::desc(
112
+ " Function attribute to apply to cold functions as determined by PGO" ),
113
+ cl::values(clEnumValN(PGOOptions::ColdFuncOpt::Default, " default" ,
114
+ " Default (no attribute)" ),
115
+ clEnumValN(PGOOptions::ColdFuncOpt::OptSize, " optsize" ,
116
+ " Mark cold functions with optsize." ),
117
+ clEnumValN(PGOOptions::ColdFuncOpt::MinSize, " minsize" ,
118
+ " Mark cold functions with minsize." ),
119
+ clEnumValN(PGOOptions::ColdFuncOpt::OptNone, " optnone" ,
120
+ " Mark cold functions with optnone." )));
121
+
107
122
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
108
123
109
124
// Re-link builtin bitcodes after optimization
@@ -768,42 +783,41 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
768
783
CodeGenOpts.InstrProfileOutput .empty () ? getDefaultProfileGenName ()
769
784
: CodeGenOpts.InstrProfileOutput ,
770
785
" " , " " , CodeGenOpts.MemoryProfileUsePath , nullptr , PGOOptions::IRInstr,
771
- PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default ,
786
+ PGOOptions::NoCSAction, ClPGOColdFuncAttr ,
772
787
CodeGenOpts.DebugInfoForProfiling ,
773
788
/* PseudoProbeForProfiling=*/ false , CodeGenOpts.AtomicProfileUpdate );
774
789
else if (CodeGenOpts.hasProfileIRUse ()) {
775
790
// -fprofile-use.
776
791
auto CSAction = CodeGenOpts.hasProfileCSIRUse () ? PGOOptions::CSIRUse
777
792
: PGOOptions::NoCSAction;
778
- PGOOpt = PGOOptions (
779
- CodeGenOpts.ProfileInstrumentUsePath , " " ,
780
- CodeGenOpts. ProfileRemappingFile , CodeGenOpts.MemoryProfileUsePath , VFS,
781
- PGOOptions::IRUse, CSAction, PGOOptions::ColdFuncOpt::Default ,
782
- CodeGenOpts.DebugInfoForProfiling );
793
+ PGOOpt = PGOOptions (CodeGenOpts. ProfileInstrumentUsePath , " " ,
794
+ CodeGenOpts.ProfileRemappingFile ,
795
+ CodeGenOpts.MemoryProfileUsePath , VFS,
796
+ PGOOptions::IRUse, CSAction, ClPGOColdFuncAttr ,
797
+ CodeGenOpts.DebugInfoForProfiling );
783
798
} else if (!CodeGenOpts.SampleProfileFile .empty ())
784
799
// -fprofile-sample-use
785
800
PGOOpt = PGOOptions (
786
801
CodeGenOpts.SampleProfileFile , " " , CodeGenOpts.ProfileRemappingFile ,
787
802
CodeGenOpts.MemoryProfileUsePath , VFS, PGOOptions::SampleUse,
788
- PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default ,
803
+ PGOOptions::NoCSAction, ClPGOColdFuncAttr ,
789
804
CodeGenOpts.DebugInfoForProfiling , CodeGenOpts.PseudoProbeForProfiling );
790
805
else if (!CodeGenOpts.MemoryProfileUsePath .empty ())
791
806
// -fmemory-profile-use (without any of the above options)
792
807
PGOOpt = PGOOptions (" " , " " , " " , CodeGenOpts.MemoryProfileUsePath , VFS,
793
808
PGOOptions::NoAction, PGOOptions::NoCSAction,
794
- PGOOptions::ColdFuncOpt::Default,
795
- CodeGenOpts.DebugInfoForProfiling );
809
+ ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling );
796
810
else if (CodeGenOpts.PseudoProbeForProfiling )
797
811
// -fpseudo-probe-for-profiling
798
- PGOOpt = PGOOptions ( " " , " " , " " , /* MemoryProfile= */ " " , nullptr ,
799
- PGOOptions::NoAction, PGOOptions::NoCSAction ,
800
- PGOOptions::ColdFuncOpt::Default ,
801
- CodeGenOpts.DebugInfoForProfiling , true );
812
+ PGOOpt =
813
+ PGOOptions ( " " , " " , " " , /* MemoryProfile= */ " " , nullptr ,
814
+ PGOOptions::NoAction, PGOOptions::NoCSAction ,
815
+ ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling , true );
802
816
else if (CodeGenOpts.DebugInfoForProfiling )
803
817
// -fdebug-info-for-profiling
804
818
PGOOpt = PGOOptions (" " , " " , " " , /* MemoryProfile=*/ " " , nullptr ,
805
819
PGOOptions::NoAction, PGOOptions::NoCSAction,
806
- PGOOptions::ColdFuncOpt::Default , true );
820
+ ClPGOColdFuncAttr , true );
807
821
808
822
// Check to see if we want to generate a CS profile.
809
823
if (CodeGenOpts.hasProfileCSIRInstr ()) {
@@ -820,14 +834,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
820
834
: CodeGenOpts.InstrProfileOutput ;
821
835
PGOOpt->CSAction = PGOOptions::CSIRInstr;
822
836
} else
823
- PGOOpt =
824
- PGOOptions (" " ,
825
- CodeGenOpts.InstrProfileOutput .empty ()
826
- ? getDefaultProfileGenName ()
827
- : CodeGenOpts.InstrProfileOutput ,
828
- " " , /* MemoryProfile=*/ " " , nullptr , PGOOptions::NoAction,
829
- PGOOptions::CSIRInstr, PGOOptions::ColdFuncOpt::Default,
830
- CodeGenOpts.DebugInfoForProfiling );
837
+ PGOOpt = PGOOptions (" " ,
838
+ CodeGenOpts.InstrProfileOutput .empty ()
839
+ ? getDefaultProfileGenName ()
840
+ : CodeGenOpts.InstrProfileOutput ,
841
+ " " , /* MemoryProfile=*/ " " , nullptr ,
842
+ PGOOptions::NoAction, PGOOptions::CSIRInstr,
843
+ ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling );
831
844
}
832
845
if (TM)
833
846
TM->setPGOOption (PGOOpt);
0 commit comments