llvm.org GIT mirror llvm / 1cb383e
[Remarks] Extend -fsave-optimization-record to specify the format Use -fsave-optimization-record=<format> to specify a different format than the default, which is YAML. For now, only YAML is supported. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363573 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 3 months ago
14 changed file(s) with 95 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
8484 using RemarkSetupErrorInfo::RemarkSetupErrorInfo;
8585 };
8686
87 struct RemarkSetupFormatError : RemarkSetupErrorInfo {
88 static char ID;
89 using RemarkSetupErrorInfo::RemarkSetupErrorInfo;
90 };
91
92 enum class RemarksSerializerFormat { Unknown, YAML };
93
94 Expected parseSerializerFormat(StringRef Format);
95
8796 /// Setup optimization remarks.
8897 Expected>
8998 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
90 StringRef RemarksPasses, bool RemarksWithHotness,
99 StringRef RemarksPasses, StringRef RemarksFormat,
100 bool RemarksWithHotness,
91101 unsigned RemarksHotnessThreshold = 0);
92102
93103 } // end namespace llvm
106106
107107 /// Whether to emit optimization remarks with hotness informations.
108108 bool RemarksWithHotness = false;
109
110 /// The format used for serializing remarks (default: YAML).
111 std::string RemarksFormat = "";
109112
110113 /// Whether to emit the pass manager debuggging informations.
111114 bool DebugPassManager = false;
1919 #include "llvm/ADT/StringSet.h"
2020 #include "llvm/IR/DiagnosticInfo.h"
2121 #include "llvm/IR/ModuleSummaryIndex.h"
22 #include "llvm/IR/RemarkStreamer.h"
2223 #include "llvm/LTO/Config.h"
2324 #include "llvm/Linker/IRMover.h"
2425 #include "llvm/Object/IRSymtab.h"
8485 /// Setup optimization remarks.
8586 Expected>
8687 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
87 StringRef RemarksPasses, bool RemarksWithHotness,
88 int Count = -1);
88 StringRef RemarksPasses, StringRef RemarksFormat,
89 bool RemarksWithHotness, int Count = -1);
8990
9091 /// Setups the output file for saving statistics.
9192 Expected>
108108
109109 char RemarkSetupFileError::ID = 0;
110110 char RemarkSetupPatternError::ID = 0;
111 char RemarkSetupFormatError::ID = 0;
112
113 static std::unique_ptr
114 formatToSerializer(RemarksSerializerFormat RemarksFormat, raw_ostream &OS) {
115 switch (RemarksFormat) {
116 default:
117 llvm_unreachable("Unknown remark serializer format.");
118 return nullptr;
119 case RemarksSerializerFormat::YAML:
120 return llvm::make_unique(OS);
121 };
122 }
123
124 Expected
125 llvm::parseSerializerFormat(StringRef StrFormat) {
126 auto Format = StringSwitch(StrFormat)
127 .Cases("", "yaml", RemarksSerializerFormat::YAML)
128 .Default(RemarksSerializerFormat::Unknown);
129
130 if (Format == RemarksSerializerFormat::Unknown)
131 return createStringError(std::make_error_code(std::errc::invalid_argument),
132 "Unknown remark serializer format: '%s'",
133 StrFormat.data());
134
135 return Format;
136 }
111137
112138 Expected>
113139 llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
114 StringRef RemarksPasses, bool RemarksWithHotness,
140 StringRef RemarksPasses, StringRef RemarksFormat,
141 bool RemarksWithHotness,
115142 unsigned RemarksHotnessThreshold) {
116143 if (RemarksWithHotness)
117144 Context.setDiagnosticsHotnessRequested(true);
130157 if (EC)
131158 return make_error(errorCodeToError(EC));
132159
160 Expected Format =
161 parseSerializerFormat(RemarksFormat);
162 if (Error E = Format.takeError())
163 return make_error(std::move(E));
164
133165 Context.setRemarkStreamer(llvm::make_unique(
134 RemarksFilename,
135 llvm::make_unique(RemarksFile->os())));
166 RemarksFilename, formatToSerializer(*Format, RemarksFile->os())));
136167
137168 if (!RemarksPasses.empty())
138169 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
13381338
13391339 Expected>
13401340 lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
1341 StringRef RemarksPasses, bool RemarksWithHotness,
1342 int Count) {
1341 StringRef RemarksPasses, StringRef RemarksFormat,
1342 bool RemarksWithHotness, int Count) {
13431343 std::string Filename = RemarksFilename;
13441344 if (!Filename.empty() && Count != -1)
13451345 Filename += ".thin." + llvm::utostr(Count) + ".yaml";
13461346
13471347 auto ResultOrErr = llvm::setupOptimizationRemarks(
1348 Context, Filename, RemarksPasses, RemarksWithHotness);
1348 Context, Filename, RemarksPasses, RemarksFormat, RemarksWithHotness);
13491349 if (Error E = ResultOrErr.takeError())
13501350 return std::move(E);
13511351
430430 std::unique_ptr TM = createTargetMachine(C, *TOrErr, *Mod);
431431
432432 // Setup optimization remarks.
433 auto DiagFileOrErr =
434 lto::setupOptimizationRemarks(Mod->getContext(), C.RemarksFilename,
435 C.RemarksPasses, C.RemarksWithHotness);
433 auto DiagFileOrErr = lto::setupOptimizationRemarks(
434 Mod->getContext(), C.RemarksFilename, C.RemarksPasses, C.RemarksFormat,
435 C.RemarksWithHotness);
436436 if (!DiagFileOrErr)
437437 return DiagFileOrErr.takeError();
438438 auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
487487 // Setup optimization remarks.
488488 auto DiagFileOrErr = lto::setupOptimizationRemarks(
489489 Mod.getContext(), Conf.RemarksFilename, Conf.RemarksPasses,
490 Conf.RemarksWithHotness, Task);
490 Conf.RemarksFormat, Conf.RemarksWithHotness, Task);
491491 if (!DiagFileOrErr)
492492 return DiagFileOrErr.takeError();
493493 auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
9696 "names match the given regular expression"),
9797 cl::value_desc("regex"));
9898
99 cl::opt RemarksFormat(
100 "lto-pass-remarks-format",
101 cl::desc("The format used for serializing remarks (default: YAML)"),
102 cl::value_desc("format"), cl::init("yaml"));
103
99104 cl::opt LTOStatsFile(
100105 "lto-stats-file",
101106 cl::desc("Save statistics to the specified file"),
516521 if (!this->determineTarget())
517522 return false;
518523
519 auto DiagFileOrErr = lto::setupOptimizationRemarks(
520 Context, RemarksFilename, RemarksPasses, RemarksWithHotness);
524 auto DiagFileOrErr =
525 lto::setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
526 RemarksFormat, RemarksWithHotness);
521527 if (!DiagFileOrErr) {
522528 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
523529 report_fatal_error("Can't get an output file for the remarks");
7272 extern cl::opt RemarksFilename;
7373 extern cl::opt RemarksPasses;
7474 extern cl::opt RemarksWithHotness;
75 extern cl::opt RemarksFormat;
7576 }
7677
7778 namespace {
10191020 Context.setDiscardValueNames(LTODiscardValueNames);
10201021 Context.enableDebugTypeODRUniquing();
10211022 auto DiagFileOrErr = lto::setupOptimizationRemarks(
1022 Context, RemarksFilename, RemarksPasses,
1023 Context, RemarksFilename, RemarksPasses, RemarksFormat,
10231024 RemarksWithHotness, count);
10241025 if (!DiagFileOrErr) {
10251026 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
55 ; RUN: llvm-lto -thinlto-action=run \
66 ; RUN: -lto-pass-remarks-output=%t.yaml \
77 ; RUN: -lto-pass-remarks-filter=inline \
8 ; RUN: -lto-pass-remarks-format=yaml \
89 ; RUN: -exported-symbol _func2 \
910 ; RUN: -exported-symbol _main %t1.bc %t2.bc 2>&1 | \
1011 ; RUN: FileCheck %s -allow-empty
22 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
33 ; RUN: -plugin-opt=save-temps \
44 ; RUN: -plugin-opt=opt-remarks-passes=inline \
5 ; RUN: -plugin-opt=opt-remarks-format=yaml \
56 ; RUN: -plugin-opt=opt-remarks-filename=%t.yaml %t.o -o %t2.o 2>&1
67 ; RUN: llvm-dis %t2.o.0.4.opt.bc -o - | FileCheck %s
78 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
89 ; RUN: -plugin-opt=opt-remarks-passes=inline \
10 ; RUN: -plugin-opt=opt-remarks-format=yaml \
911 ; RUN: -plugin-opt=opt-remarks-with-hotness \
1012 ; RUN: -plugin-opt=opt-remarks-filename=%t.hot.yaml %t.o -o %t2.o 2>&1
1113 ; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
208208 static std::string RemarksFilename;
209209 static std::string RemarksPasses;
210210 static bool RemarksWithHotness = false;
211 static std::string RemarksFormat;
211212
212213 // Context sensitive PGO options.
213214 static std::string cs_profile_path;
289290 RemarksPasses = opt.substr(strlen("opt-remarks-passes="));
290291 } else if (opt == "opt-remarks-with-hotness") {
291292 RemarksWithHotness = true;
293 } else if (opt.startswith("opt-remarks-format=")) {
294 RemarksFormat = opt.substr(strlen("opt-remarks-format="));
292295 } else if (opt.startswith("stats-file=")) {
293296 stats_file = opt.substr(strlen("stats-file="));
294297 } else {
912915 Conf.RemarksFilename = options::RemarksFilename;
913916 Conf.RemarksPasses = options::RemarksPasses;
914917 Conf.RemarksWithHotness = options::RemarksWithHotness;
918 Conf.RemarksFormat = options::RemarksFormat;
915919
916920 // Use new pass manager if set in driver
917921 Conf.UseNewPM = options::new_pass_manager;
154154 "names match the given regular expression"),
155155 cl::value_desc("regex"));
156156
157 static cl::opt RemarksFormat(
158 "pass-remarks-format",
159 cl::desc("The format used for serializing remarks (default: YAML)"),
160 cl::value_desc("format"), cl::init("yaml"));
161
157162 namespace {
158163 static ManagedStatic> RunPassNames;
159164
328333
329334 Expected> RemarksFileOrErr =
330335 setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
331 RemarksWithHotness, RemarksHotnessThreshold);
336 RemarksFormat, RemarksWithHotness,
337 RemarksHotnessThreshold);
332338 if (Error E = RemarksFileOrErr.takeError()) {
333339 WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
334340 return 1;
106106 "names match the given regular expression"),
107107 cl::value_desc("regex"));
108108
109 static cl::opt RemarksFormat(
110 "pass-remarks-format",
111 cl::desc("The format used for serializing remarks (default: YAML)"),
112 cl::value_desc("format"), cl::init("yaml"));
113
109114 static cl::opt
110115 SamplePGOFile("lto-sample-profile-file",
111116 cl::desc("Specify a SamplePGO profile file"));
228233 Conf.RemarksFilename = RemarksFilename;
229234 Conf.RemarksPasses = RemarksPasses;
230235 Conf.RemarksWithHotness = RemarksWithHotness;
236 Conf.RemarksFormat = RemarksFormat;
231237
232238 Conf.SampleProfile = SamplePGOFile;
233239 Conf.CSIRProfile = CSPGOFile;
272272 "names match the given regular expression"),
273273 cl::value_desc("regex"));
274274
275 static cl::opt RemarksFormat(
276 "pass-remarks-format",
277 cl::desc("The format used for serializing remarks (default: YAML)"),
278 cl::value_desc("format"), cl::init("yaml"));
279
275280 cl::opt
276281 PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
277282 cl::desc("The kind of profile guided optimization"),
551556
552557 Expected> RemarksFileOrErr =
553558 setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
554 RemarksWithHotness, RemarksHotnessThreshold);
559 RemarksFormat, RemarksWithHotness,
560 RemarksHotnessThreshold);
555561 if (Error E = RemarksFileOrErr.takeError()) {
556562 errs() << toString(std::move(E)) << '\n';
557563 return 1;