llvm.org GIT mirror llvm / 6e2d3e3
[LTO] Share the optimization remarks setup between Thin/Full LTO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294807 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
5 changed file(s) with 35 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
2525 #include "llvm/Linker/IRMover.h"
2626 #include "llvm/Object/IRObjectFile.h"
2727 #include "llvm/Support/Error.h"
28 #include "llvm/Support/ToolOutputFile.h"
2829 #include "llvm/Support/thread.h"
2930 #include "llvm/Target/TargetOptions.h"
3031 #include "llvm/Transforms/IPO/FunctionImport.h"
6768 std::string getThinLTOOutputFile(const std::string &Path,
6869 const std::string &OldPrefix,
6970 const std::string &NewPrefix);
71
72 /// Setup optimization remarks.
73 Expected>
74 setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
75 bool LTOPassRemarksWithHotness, int Count = -1);
7076
7177 class LTO;
7278 struct SymbolResolution;
206206 void emitError(const std::string &ErrMsg);
207207 void emitWarning(const std::string &ErrMsg);
208208
209 Expected> setupOptimizationRemarks();
210209 void finishOptimizationRemarks();
211210
212211 LLVMContext &Context;
986986
987987 return BackendProc->wait();
988988 }
989
990 Expected>
991 lto::setupOptimizationRemarks(LLVMContext &Context,
992 StringRef LTORemarksFilename,
993 bool LTOPassRemarksWithHotness, int Count) {
994 if (LTORemarksFilename.empty())
995 return nullptr;
996
997 std::string Filename = LTORemarksFilename;
998 if (Count != -1)
999 Filename += ".thin." + llvm::utostr(Count) + ".yaml";
1000
1001 std::error_code EC;
1002 auto DiagnosticFile =
1003 llvm::make_unique(Filename, EC, sys::fs::F_None);
1004 if (EC)
1005 return errorCodeToError(EC);
1006 Context.setDiagnosticsOutputFile(
1007 llvm::make_unique(DiagnosticFile->os()));
1008 if (LTOPassRemarksWithHotness)
1009 Context.setDiagnosticHotnessRequested(true);
1010 DiagnosticFile->keep();
1011 return std::move(DiagnosticFile);
1012 }
3434 #include "llvm/IR/Module.h"
3535 #include "llvm/IR/Verifier.h"
3636 #include "llvm/InitializePasses.h"
37 #include "llvm/LTO/LTO.h"
3738 #include "llvm/LTO/legacy/LTOModule.h"
3839 #include "llvm/LTO/legacy/UpdateCompilerUsed.h"
3940 #include "llvm/Linker/Linker.h"
505506 report_fatal_error("Broken module found, compilation aborted!");
506507 }
507508
508
509 Expected>
510 LTOCodeGenerator::setupOptimizationRemarks() {
511 if (LTORemarksFilename.empty())
512 return nullptr;
513
514 std::error_code EC;
515 auto DiagnosticFile = llvm::make_unique(
516 LTORemarksFilename, EC, sys::fs::F_None);
517 if (EC)
518 return errorCodeToError(EC);
519 Context.setDiagnosticsOutputFile(
520 llvm::make_unique(DiagnosticFile->os()));
521 if (LTOPassRemarksWithHotness)
522 Context.setDiagnosticHotnessRequested(true);
523 return std::move(DiagnosticFile);
524 }
525
526509 void LTOCodeGenerator::finishOptimizationRemarks() {
527510 if (DiagnosticOutputFile) {
528511 DiagnosticOutputFile->keep();
538521 if (!this->determineTarget())
539522 return false;
540523
541 auto DiagFileOrErr = setupOptimizationRemarks();
524 auto DiagFileOrErr = lto::setupOptimizationRemarks(
525 Context, LTORemarksFilename, LTOPassRemarksWithHotness);
542526 if (!DiagFileOrErr) {
543527 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
544528 report_fatal_error("Can't get an output file for the remarks");
7272 static cl::opt
7373 ThreadCount("threads", cl::init(llvm::heavyweight_hardware_concurrency()));
7474
75 Expected>
76 setupOptimizationRemarks(LLVMContext &Ctx, int Count) {
77 if (LTOPassRemarksWithHotness)
78 Ctx.setDiagnosticHotnessRequested(true);
79
80 if (LTORemarksFilename.empty())
81 return nullptr;
82
83 std::string FileName =
84 LTORemarksFilename + ".thin." + llvm::utostr(Count) + ".yaml";
85 std::error_code EC;
86 auto DiagnosticOutputFile =
87 llvm::make_unique(FileName, EC, sys::fs::F_None);
88 if (EC)
89 return errorCodeToError(EC);
90 Ctx.setDiagnosticsOutputFile(
91 llvm::make_unique(DiagnosticOutputFile->os()));
92 DiagnosticOutputFile->keep();
93 return std::move(DiagnosticOutputFile);
94 }
95
9675 // Simple helper to save temporary files for debug.
9776 static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
9877 unsigned count, StringRef Suffix) {
987966 LLVMContext Context;
988967 Context.setDiscardValueNames(LTODiscardValueNames);
989968 Context.enableDebugTypeODRUniquing();
990 auto DiagFileOrErr = setupOptimizationRemarks(Context, count);
969 auto DiagFileOrErr = lto::setupOptimizationRemarks(
970 Context, LTORemarksFilename, LTOPassRemarksWithHotness, count);
991971 if (!DiagFileOrErr) {
992972 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
993973 report_fatal_error("ThinLTO: Can't get an output file for the "