llvm.org GIT mirror llvm / 54c3fca
[lib/LTO] Rework optimization remarkers setup. This makes this code much more similar to what ThinLTO is using (also API wise), so now we can probably use a single code path instead of copying stuff around. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294792 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
2 changed file(s) with 22 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
4040 #include "llvm/ADT/StringSet.h"
4141 #include "llvm/IR/GlobalValue.h"
4242 #include "llvm/IR/Module.h"
43 #include "llvm/Support/Error.h"
4344 #include "llvm/Support/ToolOutputFile.h"
4445 #include "llvm/Target/TargetMachine.h"
4546 #include "llvm/Target/TargetOptions.h"
205206 void emitError(const std::string &ErrMsg);
206207 void emitWarning(const std::string &ErrMsg);
207208
208 bool setupOptimizationRemarks();
209 Expected> setupOptimizationRemarks();
209210 void finishOptimizationRemarks();
210211
211212 LLVMContext &Context;
505505 report_fatal_error("Broken module found, compilation aborted!");
506506 }
507507
508 bool LTOCodeGenerator::setupOptimizationRemarks() {
509 if (LTORemarksFilename != "") {
510 std::error_code EC;
511 DiagnosticOutputFile = llvm::make_unique(
512 LTORemarksFilename, EC, sys::fs::F_None);
513 if (EC) {
514 emitError(EC.message());
515 return false;
516 }
517 Context.setDiagnosticsOutputFile(
518 llvm::make_unique(DiagnosticOutputFile->os()));
519 }
520
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()));
521521 if (LTOPassRemarksWithHotness)
522522 Context.setDiagnosticHotnessRequested(true);
523
524 return true;
523 return std::move(DiagnosticFile);
525524 }
526525
527526 void LTOCodeGenerator::finishOptimizationRemarks() {
539538 if (!this->determineTarget())
540539 return false;
541540
542 if (!setupOptimizationRemarks())
543 return false;
541 auto DiagFileOrErr = setupOptimizationRemarks();
542 if (!DiagFileOrErr) {
543 errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
544 report_fatal_error("Can't get an output file for the remarks");
545 }
546 DiagnosticOutputFile = std::move(*DiagFileOrErr);
544547
545548 // We always run the verifier once on the merged module, the `DisableVerify`
546549 // parameter only applies to subsequent verify.