@@ -124,15 +124,25 @@ namespace clang {
124124extern llvm::cl::opt<bool > ClSanitizeGuardChecks;
125125}
126126
127- namespace {
128-
129127// Default filename used for profile generation.
130- std::string getDefaultProfileGenName () {
128+ static std::string getDefaultProfileGenName () {
131129 return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
132130 ? " default_%m.proflite"
133131 : " default_%m.profraw" ;
134132}
135133
134+ // Path and name of file used for profile generation
135+ static std::string getProfileGenName (const CodeGenOptions &CodeGenOpts) {
136+ std::string FileName = CodeGenOpts.InstrProfileOutput .empty ()
137+ ? getDefaultProfileGenName ()
138+ : CodeGenOpts.InstrProfileOutput ;
139+ if (CodeGenOpts.ContinuousProfileSync )
140+ FileName = " %c" + FileName;
141+ return FileName;
142+ }
143+
144+ namespace {
145+
136146class EmitAssemblyHelper {
137147 CompilerInstance &CI;
138148 DiagnosticsEngine &Diags;
@@ -551,7 +561,9 @@ getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
551561 return std::nullopt ;
552562 InstrProfOptions Options;
553563 Options.NoRedZone = CodeGenOpts.DisableRedZone ;
554- Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput ;
564+ Options.InstrProfileOutput = CodeGenOpts.ContinuousProfileSync
565+ ? (" %c" + CodeGenOpts.InstrProfileOutput )
566+ : CodeGenOpts.InstrProfileOutput ;
555567 Options.Atomic = CodeGenOpts.AtomicProfileUpdate ;
556568 return Options;
557569}
@@ -822,13 +834,12 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
822834
823835 if (CodeGenOpts.hasProfileIRInstr ())
824836 // -fprofile-generate.
825- PGOOpt = PGOOptions (
826- CodeGenOpts.InstrProfileOutput .empty () ? getDefaultProfileGenName ()
827- : CodeGenOpts.InstrProfileOutput ,
828- " " , " " , CodeGenOpts.MemoryProfileUsePath , nullptr , PGOOptions::IRInstr,
829- PGOOptions::NoCSAction, ClPGOColdFuncAttr,
830- CodeGenOpts.DebugInfoForProfiling ,
831- /* PseudoProbeForProfiling=*/ false , CodeGenOpts.AtomicProfileUpdate );
837+ PGOOpt = PGOOptions (getProfileGenName (CodeGenOpts), " " , " " ,
838+ CodeGenOpts.MemoryProfileUsePath , nullptr ,
839+ PGOOptions::IRInstr, PGOOptions::NoCSAction,
840+ ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling ,
841+ /* PseudoProbeForProfiling=*/ false ,
842+ CodeGenOpts.AtomicProfileUpdate );
832843 else if (CodeGenOpts.hasProfileIRUse ()) {
833844 // -fprofile-use.
834845 auto CSAction = CodeGenOpts.hasProfileCSIRUse () ? PGOOptions::CSIRUse
@@ -872,18 +883,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
872883 PGOOpt->Action != PGOOptions::SampleUse &&
873884 " Cannot run CSProfileGen pass with ProfileGen or SampleUse "
874885 " pass" );
875- PGOOpt->CSProfileGenFile = CodeGenOpts.InstrProfileOutput .empty ()
876- ? getDefaultProfileGenName ()
877- : CodeGenOpts.InstrProfileOutput ;
886+ PGOOpt->CSProfileGenFile = getProfileGenName (CodeGenOpts);
878887 PGOOpt->CSAction = PGOOptions::CSIRInstr;
879888 } else
880- PGOOpt = PGOOptions (" " ,
881- CodeGenOpts.InstrProfileOutput .empty ()
882- ? getDefaultProfileGenName ()
883- : CodeGenOpts.InstrProfileOutput ,
884- " " , /* MemoryProfile=*/ " " , nullptr ,
885- PGOOptions::NoAction, PGOOptions::CSIRInstr,
886- ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling );
889+ PGOOpt = PGOOptions (" " , getProfileGenName (CodeGenOpts), " " ,
890+ /* MemoryProfile=*/ " " , nullptr , PGOOptions::NoAction,
891+ PGOOptions::CSIRInstr, ClPGOColdFuncAttr,
892+ CodeGenOpts.DebugInfoForProfiling );
887893 }
888894 if (TM)
889895 TM->setPGOOption (PGOOpt);
0 commit comments