llvm.org GIT mirror llvm / a2fbfc9
[LTO] Add stats-file option to LTO/Config.h. This patch adds a StatsFile option to LTO/Config.h and updates both LLVMGold and llvm-lto2 to set it. Reviewers: MatzeB, tejohnson, espindola Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D45531 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330411 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 2 years ago
6 changed file(s) with 79 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
8686
8787 /// Whether to emit the pass manager debuggging informations.
8888 bool DebugPassManager = false;
89
90 /// Statistics output file path.
91 std::string StatsFile;
8992
9093 bool ShouldDiscardValueNames = true;
9194 DiagnosticHandlerFunction DiagHandler;
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/LTO/LTO.h"
14 #include "llvm/ADT/Statistic.h"
1415 #include "llvm/Analysis/TargetLibraryInfo.h"
1516 #include "llvm/Analysis/TargetTransformInfo.h"
1617 #include "llvm/Bitcode/BitcodeReader.h"
790791 };
791792 computeDeadSymbols(ThinLTO.CombinedIndex, GUIDPreservedSymbols, isPrevailing);
792793
793 if (auto E = runRegularLTO(AddStream))
794 return E;
795 return runThinLTO(AddStream, Cache);
794 // Setup output file to emit statistics.
795 std::unique_ptr StatsFile = nullptr;
796 if (!Conf.StatsFile.empty()) {
797 EnableStatistics(false);
798 std::error_code EC;
799 StatsFile =
800 llvm::make_unique(Conf.StatsFile, EC, sys::fs::F_None);
801 if (EC)
802 return errorCodeToError(EC);
803 StatsFile->keep();
804 }
805
806 Error Result = runRegularLTO(AddStream);
807 if (!Result)
808 Result = runThinLTO(AddStream, Cache);
809
810 if (StatsFile)
811 PrintStatisticsJSON(StatsFile->os());
812
813 return Result;
796814 }
797815
798816 Error LTO::runRegularLTO(AddStreamFn AddStream) {
0 ; RUN: llvm-as -o %t.bc %s
1
2 ; Try to save statistics to file.
3 ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=stats-file=%t2.stats \
4 ; RUN: -m elf_x86_64 -r -o %t.o %t.bc
5 ; RUN: FileCheck --input-file=%t2.stats %s
6
7 ; CHECK: {
8 ; CHECK: "asm-printer.EmittedInsts":
9 ; CHECK: }
10
11
12 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
13 target triple = "x86_64-unknown-linux-gnu"
14
15 define i32 @foo() {
16 ret i32 10
17 }
18
19 ; Try to save statistics to an invalid file.
20 ; RUN: not %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=stats-file=%t2/foo.stats \
21 ; RUN: -m elf_x86_64 -r -o %t.o %t.bc 2>&1 | FileCheck --check-prefix=ERROR %s
22 ; ERROR: LLVM gold plugin: No such file or directory
0 ; RUN: llvm-as < %s > %t1.bc
1
2 ; Try to save statistics to file.
3 ; RUN: llvm-lto2 run %t1.bc -o %t.o -r %t1.bc,patatino,px -stats-file=%t2.stats
4 ; RUN: FileCheck --input-file=%t2.stats %s
5
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
8
9 define void @patatino() {
10 fence seq_cst
11 ret void
12 }
13
14 ; CHECK: {
15 ; CHECK: "asm-printer.EmittedInsts":
16 ; CHECK: }
17
18
19 ; Try to save statistics to an invalid file.
20 ; RUN: not llvm-lto2 run %t1.bc -o %t.o -r %t1.bc,patatino,px \
21 ; RUN: -stats-file=%t2/foo.stats 2>&1 | FileCheck --check-prefix=ERROR %s
22 ; ERROR: LTO::run failed: No such file or directory
202202 static std::string objcopy;
203203 // Directory to store the .dwo files.
204204 static std::string dwo_dir;
205 /// Statistics output filename.
206 static std::string stats_file;
205207
206208 // Optimization remarks filename and hotness options
207209 static std::string OptRemarksFilename;
277279 OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
278280 } else if (opt == "opt-remarks-with-hotness") {
279281 OptRemarksWithHotness = true;
282 } else if (opt.startswith("stats-file=")) {
283 stats_file = opt.substr(strlen("stats-file="));
280284 } else {
281285 // Save this option to pass to the code generator.
282286 // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
898902 // Debug new pass manager if requested
899903 Conf.DebugPassManager = options::debug_pass_manager;
900904
905 Conf.StatsFile = options::stats_file;
901906 return llvm::make_unique(std::move(Conf), Backend,
902907 options::ParallelCodeGenParallelismLevel);
903908 }
111111 static cl::opt
112112 DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
113113 cl::desc("Print pass management debugging information"));
114
115 static cl::opt
116 StatsFile("stats-file", cl::desc("Filename to write statistics to"));
114117
115118 static void check(Error E, std::string Msg) {
116119 if (!E)
239242
240243 Conf.OverrideTriple = OverrideTriple;
241244 Conf.DefaultTriple = DefaultTriple;
245 Conf.StatsFile = StatsFile;
242246
243247 ThinBackend Backend;
244248 if (ThinLTODistributedIndexes)