llvm.org GIT mirror llvm / 0f00485
Revert "[Remarks] Refactor optimization remarks setup" This reverts commit 6e6e3af55bb97e1a4c97375c15a2b0099120c5a7. This breaks greendragon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363343 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 2 months ago
11 changed file(s) with 140 addition(s) and 163 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/Remarks/RemarkSerializer.h"
1717 #include "llvm/Support/Error.h"
1818 #include "llvm/Support/Regex.h"
19 #include "llvm/Support/ToolOutputFile.h"
2019 #include "llvm/Support/raw_ostream.h"
2120 #include
2221 #include
5756 /// Emit a diagnostic through the streamer.
5857 void emit(const DiagnosticInfoOptimizationBase &Diag);
5958 };
60
61 template
62 struct RemarkSetupErrorInfo : public ErrorInfo {
63 Error E;
64 RemarkSetupErrorInfo(Error E) : E(std::move(E)) {}
65 void log(raw_ostream &OS) const override { OS << E; }
66 std::error_code convertToErrorCode() const override {
67 return errorToErrorCode(E);
68 }
69 };
70
71 struct RemarkSetupFileError : RemarkSetupErrorInfo {
72 static char ID;
73 using RemarkSetupErrorInfo::RemarkSetupErrorInfo;
74 };
75
76 struct RemarkSetupPatternError : RemarkSetupErrorInfo {
77 static char ID;
78 using RemarkSetupErrorInfo::RemarkSetupErrorInfo;
79 };
80
81 /// Setup optimization remarks.
82 Expected>
83 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
84 StringRef RemarksPasses, bool RemarksWithHotness,
85 unsigned RemarksHotnessThreshold = 0);
86
8759 } // end namespace llvm
8860
8961 #endif // LLVM_IR_REMARKSTREAMER_H
8383
8484 /// Setup optimization remarks.
8585 Expected>
86 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
87 StringRef RemarksPasses, bool RemarksWithHotness,
88 int Count = -1);
86 setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
87 StringRef LTORemarksPasses,
88 bool LTOPassRemarksWithHotness, int Count = -1);
8989
9090 /// Setups the output file for saving statistics.
9191 Expected>
105105 // Then, emit the remark through the serializer.
106106 Serializer->emit(R);
107107 }
108
109 char RemarkSetupFileError::ID = 0;
110 char RemarkSetupPatternError::ID = 0;
111
112 Expected>
113 llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
114 StringRef RemarksPasses, bool RemarksWithHotness,
115 unsigned RemarksHotnessThreshold) {
116 if (RemarksWithHotness)
117 Context.setDiagnosticsHotnessRequested(true);
118
119 if (RemarksHotnessThreshold)
120 Context.setDiagnosticsHotnessThreshold(RemarksHotnessThreshold);
121
122 if (RemarksFilename.empty())
123 return nullptr;
124
125 std::error_code EC;
126 auto RemarksFile =
127 llvm::make_unique(RemarksFilename, EC, sys::fs::F_None);
128 // We don't use llvm::FileError here because some diagnostics want the file
129 // name separately.
130 if (EC)
131 return errorCodeToError(EC);
132
133 Context.setRemarkStreamer(llvm::make_unique(
134 RemarksFilename,
135 llvm::make_unique(RemarksFile->os())));
136
137 if (!RemarksPasses.empty())
138 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
139 return std::move(E);
140
141 return std::move(RemarksFile);
142 }
13371337 }
13381338
13391339 Expected>
1340 lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
1341 StringRef RemarksPasses, bool RemarksWithHotness,
1342 int Count) {
1343 std::string Filename = RemarksFilename;
1344 if (!Filename.empty() && Count != -1)
1340 lto::setupOptimizationRemarks(LLVMContext &Context,
1341 StringRef LTORemarksFilename,
1342 StringRef LTORemarksPasses,
1343 bool LTOPassRemarksWithHotness, int Count) {
1344 if (LTOPassRemarksWithHotness)
1345 Context.setDiagnosticsHotnessRequested(true);
1346 if (LTORemarksFilename.empty())
1347 return nullptr;
1348
1349 std::string Filename = LTORemarksFilename;
1350 if (Count != -1)
13451351 Filename += ".thin." + llvm::utostr(Count) + ".yaml";
13461352
1347 auto ResultOrErr = llvm::setupOptimizationRemarks(
1348 Context, Filename, RemarksPasses, RemarksWithHotness);
1349 if (Error E = ResultOrErr.takeError())
1350 return std::move(E);
1351
1352 if (*ResultOrErr)
1353 (*ResultOrErr)->keep();
1354
1355 return ResultOrErr;
1353 std::error_code EC;
1354 auto DiagnosticFile =
1355 llvm::make_unique(Filename, EC, sys::fs::F_None);
1356 if (EC)
1357 return errorCodeToError(EC);
1358 Context.setRemarkStreamer(llvm::make_unique(
1359 Filename,
1360 llvm::make_unique(DiagnosticFile->os())));
1361
1362 if (!LTORemarksPasses.empty())
1363 if (Error E = Context.getRemarkStreamer()->setFilter(LTORemarksPasses))
1364 return std::move(E);
1365
1366 DiagnosticFile->keep();
1367 return std::move(DiagnosticFile);
13561368 }
13571369
13581370 Expected>
2121 #include "llvm/Bitcode/BitcodeWriter.h"
2222 #include "llvm/IR/LegacyPassManager.h"
2323 #include "llvm/IR/PassManager.h"
24 #include "llvm/IR/RemarkStreamer.h"
2524 #include "llvm/IR/Verifier.h"
2625 #include "llvm/LTO/LTO.h"
2726 #include "llvm/MC/SubtargetFeature.h"
3231 #include "llvm/Support/MemoryBuffer.h"
3332 #include "llvm/Support/Path.h"
3433 #include "llvm/Support/Program.h"
34 #include "llvm/Support/raw_ostream.h"
3535 #include "llvm/Support/TargetRegistry.h"
3636 #include "llvm/Support/ThreadPool.h"
37 #include "llvm/Support/raw_ostream.h"
3837 #include "llvm/Target/TargetMachine.h"
3938 #include "llvm/Transforms/IPO.h"
4039 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
3232 #include "llvm/IR/Mangler.h"
3333 #include "llvm/IR/Module.h"
3434 #include "llvm/IR/PassTimingInfo.h"
35 #include "llvm/IR/RemarkStreamer.h"
3635 #include "llvm/IR/Verifier.h"
3736 #include "llvm/InitializePasses.h"
3837 #include "llvm/LTO/LTO.h"
8079 #endif
8180 cl::Hidden);
8281
83 cl::opt<bool> RemarksWithHotness(
82 cl::opt<std::string>
83 LTORemarksFilename("lto-pass-remarks-output",
84 cl::desc("Output filename for pass remarks"),
85 cl::value_desc("filename"));
86
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
93 cl::opt LTOPassRemarksWithHotness(
8494 "lto-pass-remarks-with-hotness",
8595 cl::desc("With PGO, include profile count in optimization remarks"),
8696 cl::Hidden);
87
88 cl::opt
89 RemarksFilename("lto-pass-remarks-output",
90 cl::desc("Output filename for pass remarks"),
91 cl::value_desc("filename"));
92
93 cl::opt
94 RemarksPasses("lto-pass-remarks-filter",
95 cl::desc("Only record optimization remarks from passes whose "
96 "names match the given regular expression"),
97 cl::value_desc("regex"));
9897
9998 cl::opt LTOStatsFile(
10099 "lto-stats-file",
517516 return false;
518517
519518 auto DiagFileOrErr = lto::setupOptimizationRemarks(
520 Context, RemarksFilename, RemarksPasses, RemarksWithHotness);
519 Context, LTORemarksFilename, LTORemarksPasses, LTOPassRemarksWithHotness);
521520 if (!DiagFileOrErr) {
522521 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
523522 report_fatal_error("Can't get an output file for the remarks");
2828 #include "llvm/IR/LegacyPassManager.h"
2929 #include "llvm/IR/Mangler.h"
3030 #include "llvm/IR/PassTimingInfo.h"
31 #include "llvm/IR/RemarkStreamer.h"
3231 #include "llvm/IR/Verifier.h"
3332 #include "llvm/IRReader/IRReader.h"
3433 #include "llvm/LTO/LTO.h"
6968 namespace llvm {
7069 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
7170 extern cl::opt LTODiscardValueNames;
72 extern cl::opt RemarksFilename;
73 extern cl::opt RemarksPasses;
74 extern cl::opt<bool> RemarksWithHotness;
71 extern cl::opt<std::string> LTORemarksFilename;
72 extern cl::opt LTORemarksPasses;
73 extern cl::opt LTOPassRemarksWithHotness;
7574 }
7675
7776 namespace {
10191018 Context.setDiscardValueNames(LTODiscardValueNames);
10201019 Context.enableDebugTypeODRUniquing();
10211020 auto DiagFileOrErr = lto::setupOptimizationRemarks(
1022 Context, RemarksFilename, RemarksPasses,
1023 RemarksWithHotness, count);
1021 Context, LTORemarksFilename, LTORemarksPasses,
1022 LTOPassRemarksWithHotness, count);
10241023 if (!DiagFileOrErr) {
10251024 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
10261025 report_fatal_error("ThinLTO: Can't get an output file for the "
205205 static std::string stats_file;
206206
207207 // Optimization remarks filename, accepted passes and hotness options
208 static std::string RemarksFilename;
209 static std::string RemarksPasses;
210 static bool RemarksWithHotness = false;
208 static std::string OptRemarksFilename;
209 static std::string OptRemarksFilter;
210 static bool OptRemarksWithHotness = false;
211211
212212 // Context sensitive PGO options.
213213 static std::string cs_profile_path;
284284 } else if (opt.startswith("dwo_dir=")) {
285285 dwo_dir = opt.substr(strlen("dwo_dir="));
286286 } else if (opt.startswith("opt-remarks-filename=")) {
287 RemarksFilename = opt.substr(strlen("opt-remarks-filename="));
287 OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
288288 } else if (opt.startswith("opt-remarks-passes=")) {
289 RemarksPasses = opt.substr(strlen("opt-remarks-passes="));
289 OptRemarksFilter = opt.substr(strlen("opt-remarks-passes="));
290290 } else if (opt == "opt-remarks-with-hotness") {
291 RemarksWithHotness = true;
291 OptRemarksWithHotness = true;
292292 } else if (opt.startswith("stats-file=")) {
293293 stats_file = opt.substr(strlen("stats-file="));
294294 } else {
909909 Conf.DwoDir = options::dwo_dir;
910910
911911 // Set up optimization remarks handling.
912 Conf.RemarksFilename = options::RemarksFilename;
913 Conf.RemarksPasses = options::RemarksPasses;
914 Conf.RemarksWithHotness = options::RemarksWithHotness;
912 Conf.RemarksFilename = options::OptRemarksFilename;
913 Conf.RemarksPasses = options::OptRemarksFilter;
914 Conf.RemarksWithHotness = options::OptRemarksWithHotness;
915915
916916 // Use new pass manager if set in driver
917917 Conf.UseNewPM = options::new_pass_manager;
132132
133133 static cl::list IncludeDirs("I", cl::desc("include search path"));
134134
135 static cl::opt RemarksWithHotness(
135 static cl::opt PassRemarksWithHotness(
136136 "pass-remarks-with-hotness",
137137 cl::desc("With PGO, include profile count in optimization remarks"),
138138 cl::Hidden);
139139
140 static cl::opt
141 RemarksHotnessThreshold("pass-remarks-hotness-threshold",
142 cl::desc("Minimum profile count required for "
143 "an optimization remark to be output"),
144 cl::Hidden);
140 static cl::opt PassRemarksHotnessThreshold(
141 "pass-remarks-hotness-threshold",
142 cl::desc("Minimum profile count required for an optimization remark to be output"),
143 cl::Hidden);
145144
146145 static cl::opt
147146 RemarksFilename("pass-remarks-output",
148 cl::desc("Output filename for pass remarks"),
147 cl::desc("YAML output filename for pass remarks"),
149148 cl::value_desc("filename"));
150149
151150 static cl::opt
326325 llvm::make_unique(&HasError));
327326 Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
328327
329 Expected> RemarksFileOrErr =
330 setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
331 RemarksWithHotness, RemarksHotnessThreshold);
332 if (Error E = RemarksFileOrErr.takeError()) {
333 WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
334 return 1;
335 }
336 std::unique_ptr RemarksFile = std::move(*RemarksFileOrErr);
328 if (PassRemarksWithHotness)
329 Context.setDiagnosticsHotnessRequested(true);
330
331 if (PassRemarksHotnessThreshold)
332 Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
333
334 std::unique_ptr YamlFile;
335 if (RemarksFilename != "") {
336 std::error_code EC;
337 YamlFile =
338 llvm::make_unique(RemarksFilename, EC, sys::fs::F_None);
339 if (EC) {
340 WithColor::error(errs(), argv[0]) << EC.message() << '\n';
341 return 1;
342 }
343 Context.setRemarkStreamer(llvm::make_unique(
344 RemarksFilename,
345 llvm::make_unique(YamlFile->os())));
346
347 if (!RemarksPasses.empty())
348 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
349 WithColor::error(errs(), argv[0]) << E << '\n';
350 return 1;
351 }
352 }
337353
338354 if (InputLanguage != "" && InputLanguage != "ir" &&
339355 InputLanguage != "mir") {
348364 if (int RetVal = compileModule(argv, Context))
349365 return RetVal;
350366
351 if (RemarksFile)
352 RemarksFile->keep();
367 if (YamlFile)
368 YamlFile->keep();
353369 return 0;
354370 }
355371
9090 cl::desc(
9191 "Replace unspecified target triples in input files with this triple"));
9292
93 static cl::opt<bool> RemarksWithHotness(
93 static cl::opt<std::string>
94 OptRemarksOutput("pass-remarks-output",
95 cl::desc("YAML output file for optimization remarks"));
96
97 static cl::opt OptRemarksWithHotness(
9498 "pass-remarks-with-hotness",
95 cl::desc("With PGO, include profile count in optimization remarks"),
96 cl::Hidden);
99 cl::desc("Whether to include hotness informations in the remarks.\n"
100 "Has effect only if -pass-remarks-output is specified."));
97101
98102 static cl::opt
99 RemarksFilename("pass-remarks-output",
100 cl::desc("Output filename for pass remarks"),
101 cl::value_desc("filename"));
102
103 static cl::opt
104 RemarksPasses("pass-remarks-filter",
105 cl::desc("Only record optimization remarks from passes whose "
106 "names match the given regular expression"),
107 cl::value_desc("regex"));
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"));
108107
109108 static cl::opt
110109 SamplePGOFile("lto-sample-profile-file",
225224 "Config::addSaveTemps failed");
226225
227226 // Optimization remarks.
228 Conf.RemarksFilename = RemarksFilename;
229 Conf.RemarksPasses = RemarksPasses;
230 Conf.RemarksWithHotness = RemarksWithHotness;
227 Conf.RemarksFilename = OptRemarksOutput;
228 Conf.RemarksPasses = OptRemarksPasses;
229 Conf.RemarksWithHotness = OptRemarksWithHotness;
231230
232231 Conf.SampleProfile = SamplePGOFile;
233232 Conf.CSIRProfile = CSPGOFile;
250250 cl::desc("Enable coroutine passes."),
251251 cl::init(false), cl::Hidden);
252252
253 static cl::opt RemarksWithHotness(
253 static cl::opt PassRemarksWithHotness(
254254 "pass-remarks-with-hotness",
255255 cl::desc("With PGO, include profile count in optimization remarks"),
256256 cl::Hidden);
257257
258 static cl::opt
259 RemarksHotnessThreshold("pass-remarks-hotness-threshold",
260 cl::desc("Minimum profile count required for "
261 "an optimization remark to be output"),
262 cl::Hidden);
258 static cl::opt PassRemarksHotnessThreshold(
259 "pass-remarks-hotness-threshold",
260 cl::desc("Minimum profile count required for an optimization remark to be output"),
261 cl::Hidden);
263262
264263 static cl::opt
265264 RemarksFilename("pass-remarks-output",
266 cl::desc("Output filename for pass remarks"),
265 cl::desc("YAML output filename for pass remarks"),
267266 cl::value_desc("filename"));
268267
269268 static cl::opt
549548 if (!DisableDITypeMap)
550549 Context.enableDebugTypeODRUniquing();
551550
552 Expected> RemarksFileOrErr =
553 setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
554 RemarksWithHotness, RemarksHotnessThreshold);
555 if (Error E = RemarksFileOrErr.takeError()) {
556 errs() << toString(std::move(E)) << '\n';
557 return 1;
558 }
559 std::unique_ptr RemarksFile = std::move(*RemarksFileOrErr);
551 if (PassRemarksWithHotness)
552 Context.setDiagnosticsHotnessRequested(true);
553
554 if (PassRemarksHotnessThreshold)
555 Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
556
557 std::unique_ptr OptRemarkFile;
558 if (RemarksFilename != "") {
559 std::error_code EC;
560 OptRemarkFile =
561 llvm::make_unique(RemarksFilename, EC, sys::fs::F_None);
562 if (EC) {
563 errs() << EC.message() << '\n';
564 return 1;
565 }
566 Context.setRemarkStreamer(llvm::make_unique(
567 RemarksFilename,
568 llvm::make_unique(OptRemarkFile->os())));
569
570 if (!RemarksPasses.empty())
571 if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
572 errs() << E << '\n';
573 return 1;
574 }
575 }
560576
561577 // Load the input module...
562578 std::unique_ptr M =
670686 // string. Hand off the rest of the functionality to the new code for that
671687 // layer.
672688 return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
673 RemarksFile.get(), PassPipeline, OK, VK,
689 OptRemarkFile.get(), PassPipeline, OK, VK,
674690 PreserveAssemblyUseListOrder,
675691 PreserveBitcodeUseListOrder, EmitSummaryIndex,
676692 EmitModuleHash, EnableDebugify)
906922 "the compile-twice option\n";
907923 Out->os() << BOS->str();
908924 Out->keep();
909 if (RemarksFile)
910 RemarksFile->keep();
925 if (OptRemarkFile)
926 OptRemarkFile->keep();
911927 return 1;
912928 }
913929 Out->os() << BOS->str();
920936 if (!NoOutput || PrintBreakpoints)
921937 Out->keep();
922938
923 if (RemarksFile)
924 RemarksFile->keep();
939 if (OptRemarkFile)
940 OptRemarkFile->keep();
925941
926942 if (ThinLinkOut)
927943 ThinLinkOut->keep();