llvm.org GIT mirror llvm / a826459
Revert "[Remarks] Add -foptimization-record-passes to filter remark emission" This reverts commit 20fff32b7d1f1a1bd417b22aa9f26ededd97a3e5. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355976 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 5 months ago
14 changed file(s) with 6 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
1313 #define LLVM_IR_REMARKSTREAMER_H
1414
1515 #include "llvm/IR/DiagnosticInfo.h"
16 #include "llvm/Support/Error.h"
1716 #include "llvm/Support/YAMLTraits.h"
1817 #include "llvm/Support/raw_ostream.h"
19 #include "llvm/Support/Regex.h"
2018 #include
2119 #include
2220
2725 const std::string Filename;
2826 /// The open raw_ostream that the remark diagnostics are emitted to.
2927 raw_ostream &OS;
30 /// The regex used to filter remarks based on the passes that emit them.
31 Optional PassFilter;
3228
3329 /// The YAML streamer.
3430 yaml::Output YAMLOutput;
3935 StringRef getFilename() const { return Filename; }
4036 /// Return stream that the remark diagnostics are emitted to.
4137 raw_ostream &getStream() { return OS; }
42 /// Set a pass filter based on a regex \p Filter.
43 /// Returns an error if the regex is invalid.
44 Error setFilter(StringRef Filter);
4538 /// Emit a diagnostic through the streamer.
4639 void emit(const DiagnosticInfoOptimizationBase &Diag);
4740 };
9494
9595 /// Optimization remarks file path.
9696 std::string RemarksFilename = "";
97
98 /// Optimization remarks pass filter.
99 std::string RemarksPasses = "";
10097
10198 /// Whether to emit optimization remarks with hotness informations.
10299 bool RemarksWithHotness = false;
8383 /// Setup optimization remarks.
8484 Expected>
8585 setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
86 StringRef LTORemarksPasses,
8786 bool LTOPassRemarksWithHotness, int Count = -1);
8887
8988 class LTO;
2020 assert(!Filename.empty() && "This needs to be a real filename.");
2121 }
2222
23 Error RemarkStreamer::setFilter(StringRef Filter) {
24 Regex R = Regex(Filter);
25 std::string RegexError;
26 if (!R.isValid(RegexError))
27 return createStringError(std::make_error_code(std::errc::invalid_argument),
28 RegexError.data());
29 PassFilter = std::move(R);
30 return Error::success();
31 }
32
3323 void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
34 if (Optional &Filter = PassFilter)
35 if (!Filter->match(Diag.getPassName()))
36 return;
37
3824 DiagnosticInfoOptimizationBase *DiagPtr =
3925 const_cast(&Diag);
4026 YAMLOutput << DiagPtr;
13111311 Expected>
13121312 lto::setupOptimizationRemarks(LLVMContext &Context,
13131313 StringRef LTORemarksFilename,
1314 StringRef LTORemarksPasses,
13151314 bool LTOPassRemarksWithHotness, int Count) {
13161315 if (LTOPassRemarksWithHotness)
13171316 Context.setDiagnosticsHotnessRequested(true);
13291328 return errorCodeToError(EC);
13301329 Context.setRemarkStreamer(
13311330 llvm::make_unique(Filename, DiagnosticFile->os()));
1332
1333 if (!LTORemarksPasses.empty())
1334 if (Error E = Context.getRemarkStreamer()->setFilter(LTORemarksPasses))
1335 return std::move(E);
1336
13371331 DiagnosticFile->keep();
13381332 return std::move(DiagnosticFile);
13391333 }
428428 std::unique_ptr TM = createTargetMachine(C, *TOrErr, *Mod);
429429
430430 // Setup optimization remarks.
431 auto DiagFileOrErr =
432 lto::setupOptimizationRemarks(Mod->getContext(), C.RemarksFilename,
433 C.RemarksPasses, C.RemarksWithHotness);
431 auto DiagFileOrErr = lto::setupOptimizationRemarks(
432 Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
434433 if (!DiagFileOrErr)
435434 return DiagFileOrErr.takeError();
436435 auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
484483
485484 // Setup optimization remarks.
486485 auto DiagFileOrErr = lto::setupOptimizationRemarks(
487 Mod.getContext(), Conf.RemarksFilename, Conf.RemarksPasses,
488 Conf.RemarksWithHotness, Task);
486 Mod.getContext(), Conf.RemarksFilename, Conf.RemarksWithHotness, Task);
489487 if (!DiagFileOrErr)
490488 return DiagFileOrErr.takeError();
491489 auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
8484 cl::desc("Output filename for pass remarks"),
8585 cl::value_desc("filename"));
8686
87 cl::opt
88 LTORemarksPasses("lto-pass-remarks-filter",
89 cl::desc("Only record optimization remarks from passes "
90 "whose names match the given regular expression"),
91 cl::value_desc("regex"));
92
9387 cl::opt LTOPassRemarksWithHotness(
9488 "lto-pass-remarks-with-hotness",
9589 cl::desc("With PGO, include profile count in optimization remarks"),
510504 return false;
511505
512506 auto DiagFileOrErr = lto::setupOptimizationRemarks(
513 Context, LTORemarksFilename, LTORemarksPasses, LTOPassRemarksWithHotness);
507 Context, LTORemarksFilename, LTOPassRemarksWithHotness);
514508 if (!DiagFileOrErr) {
515509 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
516510 report_fatal_error("Can't get an output file for the remarks");
6969 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
7070 extern cl::opt LTODiscardValueNames;
7171 extern cl::opt LTORemarksFilename;
72 extern cl::opt LTORemarksPasses;
7372 extern cl::opt LTOPassRemarksWithHotness;
7473 }
7574
972971 Context.setDiscardValueNames(LTODiscardValueNames);
973972 Context.enableDebugTypeODRUniquing();
974973 auto DiagFileOrErr = lto::setupOptimizationRemarks(
975 Context, LTORemarksFilename, LTORemarksPasses,
976 LTOPassRemarksWithHotness, count);
974 Context, LTORemarksFilename, LTOPassRemarksWithHotness, count);
977975 if (!DiagFileOrErr) {
978976 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
979977 report_fatal_error("ThinLTO: Can't get an output file for the "
33 ; RUN: llvm-as < %s >%t.bc
44 ; RUN: rm -f %t.yaml
55 ; RUN: llvm-lto2 run -pass-remarks-output=%t.yaml \
6 ; RUN: -pass-remarks-filter=inline \
76 ; RUN: -r %t.bc,tinkywinky,p \
87 ; RUN: -r %t.bc,patatino,px \
98 ; RUN: -r %t.bc,main,px -o %t.o %t.bc
1312 ; RUN: opt -module-summary %s -o %t.bc
1413 ; RUN: rm -f %t.thin.1.yaml
1514 ; RUN: llvm-lto2 run -pass-remarks-output=%t \
16 ; RUN: -pass-remarks-filter=inline \
1715 ; RUN: -r %t.bc,tinkywinky,p \
1816 ; RUN: -r %t.bc,patatino,px \
1917 ; RUN: -r %t.bc,main,px -o %t.o %t.bc
44 ; RUN: rm -f %t.yaml.thin.0.yaml %t.yaml.thin.1.yaml
55 ; RUN: llvm-lto -thinlto-action=run \
66 ; RUN: -lto-pass-remarks-output=%t.yaml \
7 ; RUN: -lto-pass-remarks-filter=inline \
87 ; RUN: -exported-symbol _func2 \
98 ; RUN: -exported-symbol _main %t1.bc %t2.bc 2>&1 | \
109 ; RUN: FileCheck %s -allow-empty
204204 /// Statistics output filename.
205205 static std::string stats_file;
206206
207 // Optimization remarks filename, accepted passes and hotness options
207 // Optimization remarks filename and hotness options
208208 static std::string OptRemarksFilename;
209 static std::string OptRemarksFilter;
210209 static bool OptRemarksWithHotness = false;
211210
212211 // Context sensitive PGO options.
285284 dwo_dir = opt.substr(strlen("dwo_dir="));
286285 } else if (opt.startswith("opt-remarks-filename=")) {
287286 OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
288 } else if (opt.startswith("opt-remarks-passes=")) {
289 OptRemarksFilter = opt.substr(strlen("opt-remarks-passes="));
290287 } else if (opt == "opt-remarks-with-hotness") {
291288 OptRemarksWithHotness = true;
292289 } else if (opt.startswith("stats-file=")) {
910907
911908 // Set up optimization remarks handling.
912909 Conf.RemarksFilename = options::OptRemarksFilename;
913 Conf.RemarksPasses = options::OptRemarksFilter;
914910 Conf.RemarksWithHotness = options::OptRemarksWithHotness;
915911
916912 // Use new pass manager if set in driver
147147 cl::desc("YAML output filename for pass remarks"),
148148 cl::value_desc("filename"));
149149
150 static cl::opt
151 RemarksPasses("pass-remarks-filter",
152 cl::desc("Only record optimization remarks from passes whose "
153 "names match the given regular expression"),
154 cl::value_desc("regex"));
155
156150 namespace {
157151 static ManagedStatic> RunPassNames;
158152
341335 }
342336 Context.setRemarkStreamer(
343337 llvm::make_unique(RemarksFilename, YamlFile->os()));
344
345 if (!RemarksPasses.empty())
346 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
347 WithColor::error(errs(), argv[0]) << E << '\n';
348 return 1;
349 }
350338 }
351339
352340 if (InputLanguage != "" && InputLanguage != "ir" &&
9898 "pass-remarks-with-hotness",
9999 cl::desc("Whether to include hotness informations in the remarks.\n"
100100 "Has effect only if -pass-remarks-output is specified."));
101
102 static cl::opt
103 OptRemarksPasses("pass-remarks-filter",
104 cl::desc("Only record optimization remarks from passes "
105 "whose names match the given regular expression"),
106 cl::value_desc("regex"));
107101
108102 static cl::opt
109103 SamplePGOFile("lto-sample-profile-file",
225219
226220 // Optimization remarks.
227221 Conf.RemarksFilename = OptRemarksOutput;
228 Conf.RemarksPasses = OptRemarksPasses;
229222 Conf.RemarksWithHotness = OptRemarksWithHotness;
230223
231224 Conf.SampleProfile = SamplePGOFile;
274274 cl::desc("YAML output filename for pass remarks"),
275275 cl::value_desc("filename"));
276276
277 static cl::opt
278 RemarksPasses("pass-remarks-filter",
279 cl::desc("Only record optimization remarks from passes whose "
280 "names match the given regular expression"),
281 cl::value_desc("regex"));
282
283277 cl::opt
284278 PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
285279 cl::desc("The kind of profile guided optimization"),
571565 }
572566 Context.setRemarkStreamer(llvm::make_unique(
573567 RemarksFilename, OptRemarkFile->os()));
574
575 if (!RemarksPasses.empty())
576 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
577 errs() << E << '\n';
578 return 1;
579 }
580568 }
581569
582570 // Load the input module...