@@ -206,12 +206,24 @@ static cl::opt<std::string> RemarksFormat(
206206 cl::desc (" The format used for serializing remarks (default: YAML)" ),
207207 cl::value_desc(" format" ), cl::init(" yaml" ));
208208
209- static cl::opt<std::string> SaveStats (
209+ enum SaveStatsMode {
210+ None,
211+ Cwd,
212+ Obj
213+ };
214+
215+ static cl::opt<SaveStatsMode> SaveStats (
210216 " save-stats" ,
211217 cl::desc (" Save LLVM statistics to a file in the current directory"
212218 " (`-save-stats`/`-save-stats=cwd`) or the directory of the output"
213219 " file (`-save-stats=obj`). (default: cwd)" ),
214- cl::init(" " ), cl::ValueOptional);
220+ cl::values(clEnumValN(SaveStatsMode::Cwd, " cwd" ,
221+ " Save to the current working directory" ),
222+ clEnumValN(SaveStatsMode::Cwd, " " ,
223+ " " ),
224+ clEnumValN(SaveStatsMode::Obj, " obj" ,
225+ " Save to the output file directory" )),
226+ cl::init(SaveStatsMode::None), cl::ValueOptional);
215227
216228static cl::opt<bool > EnableNewPassManager (
217229 " enable-new-pm" , cl::desc(" Enable the new pass manager" ), cl::init(false ));
@@ -367,46 +379,43 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
367379}
368380
369381static int MaybeEnableStats () {
370- if (SaveStats.getNumOccurrences () > 0 ) {
371- if (SaveStats.empty () || SaveStats == " cwd" || SaveStats == " obj" ) {
372- llvm::EnableStatistics (false );
373- } else {
374- WithColor::error (errs (), " llc" )
375- << " Invalid --save-stats value: " << SaveStats
376- << " , must be empty, 'cwd' or 'obj'\n " ;
377- return 1 ;
378- }
382+ if (SaveStats == SaveStatsMode::None) {
383+ return 0 ;
379384 }
385+
386+ llvm::EnableStatistics (false );
380387 return 0 ;
381388}
382389
383390static int MaybeSaveStats (std::string &&OutputFilename) {
384- if (SaveStats.getNumOccurrences () > 0 ) {
385- SmallString<128 > StatsFilename;
386- if (SaveStats == " obj" ) {
387- StatsFilename = OutputFilename;
388- llvm::sys::path::remove_filename (StatsFilename);
389- } else {
390- assert ((SaveStats.empty () || SaveStats == " cwd" ) &&
391- " Should have been a valid --save-stats value" );
392- }
391+ if (SaveStats == SaveStatsMode::None) {
392+ return 0 ;
393+ }
394+
395+ SmallString<128 > StatsFilename;
396+ if (SaveStats == SaveStatsMode::Obj) {
397+ StatsFilename = OutputFilename;
398+ llvm::sys::path::remove_filename (StatsFilename);
399+ } else {
400+ assert ((SaveStats == SaveStatsMode::Cwd) &&
401+ " Should have been a valid --save-stats value" );
402+ }
393403
394- auto BaseName = llvm::sys::path::filename (OutputFilename);
395- llvm::sys::path::append (StatsFilename, BaseName);
396- llvm::sys::path::replace_extension (StatsFilename, " stats" );
404+ auto BaseName = llvm::sys::path::filename (OutputFilename);
405+ llvm::sys::path::append (StatsFilename, BaseName);
406+ llvm::sys::path::replace_extension (StatsFilename, " stats" );
397407
398- auto FileFlags = llvm::sys::fs::OF_TextWithCRLF;
399- std::error_code EC;
400- auto StatsOS =
401- std::make_unique<llvm::raw_fd_ostream>(StatsFilename, EC, FileFlags);
402- if (EC) {
403- WithColor::error (errs (), " llc" )
404- << " Unable to open statistics file: " << EC.message () << " \n " ;
405- return 1 ;
406- } else {
407- llvm::PrintStatisticsJSON (*StatsOS);
408- }
408+ auto FileFlags = llvm::sys::fs::OF_TextWithCRLF;
409+ std::error_code EC;
410+ auto StatsOS =
411+ std::make_unique<llvm::raw_fd_ostream>(StatsFilename, EC, FileFlags);
412+ if (EC) {
413+ WithColor::error (errs (), " llc" )
414+ << " Unable to open statistics file: " << EC.message () << " \n " ;
415+ return 1 ;
409416 }
417+
418+ llvm::PrintStatisticsJSON (*StatsOS);
410419 return 0 ;
411420}
412421
0 commit comments