summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/LTOCodeGenerator.cpp
diff options
context:
space:
mode:
authorAdam Nemet <anemet@apple.com>2016-11-18 18:06:28 +0000
committerAdam Nemet <anemet@apple.com>2016-11-18 18:06:28 +0000
commite9bd022c4135de7c3af402b114acf7619393bb82 (patch)
treefec0ded8b900be306c4fccaace1cc5c11adabab2 /llvm/lib/LTO/LTOCodeGenerator.cpp
parent23d071ef87a0f442dcba49e37aa1d103eaa78c16 (diff)
downloadbcm5719-llvm-e9bd022c4135de7c3af402b114acf7619393bb82.tar.gz
bcm5719-llvm-e9bd022c4135de7c3af402b114acf7619393bb82.zip
[LTO] Add option to generate optimization records
It is used to drive this from the clang driver via -mllvm. Same option name is used as in opt. Differential Revision: https://reviews.llvm.org/D26832 llvm-svn: 287356
Diffstat (limited to 'llvm/lib/LTO/LTOCodeGenerator.cpp')
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 75810643b9c..d2f964e4d24 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -49,6 +49,7 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetOptions.h"
@@ -92,6 +93,11 @@ cl::opt<bool> LTOStripInvalidDebugInfo(
cl::Hidden);
}
+static cl::opt<std::string>
+ RemarksFilename("pass-remarks-output",
+ cl::desc("Output filename for pass remarks"),
+ cl::value_desc("filename"));
+
LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
: Context(Context), MergedModule(new Module("ld-temp.o", Context)),
TheLinker(new Linker(*MergedModule)) {
@@ -495,6 +501,29 @@ void LTOCodeGenerator::verifyMergedModuleOnce() {
report_fatal_error("Broken module found, compilation aborted!");
}
+bool LTOCodeGenerator::setupOptimizationRemarks() {
+ if (RemarksFilename != "") {
+ std::error_code EC;
+ DiagnosticOutputFile = llvm::make_unique<tool_output_file>(
+ RemarksFilename, EC, sys::fs::F_None);
+ if (EC) {
+ emitError(EC.message());
+ return false;
+ }
+ Context.setDiagnosticsOutputFile(
+ new yaml::Output(DiagnosticOutputFile->os()));
+ }
+ return true;
+}
+
+void LTOCodeGenerator::finishOptimizationRemarks() {
+ if (DiagnosticOutputFile) {
+ DiagnosticOutputFile->keep();
+ // FIXME: LTOCodeGenerator dtor is not invoked on Darwin
+ DiagnosticOutputFile->os().flush();
+ }
+}
+
/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE,
@@ -502,6 +531,9 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
if (!this->determineTarget())
return false;
+ if (!setupOptimizationRemarks())
+ return false;
+
// We always run the verifier once on the merged module, the `DisableVerify`
// parameter only applies to subsequent verify.
verifyMergedModuleOnce();
@@ -535,6 +567,8 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
// Run our queue of passes all at once now, efficiently.
passes.run(*MergedModule);
+ finishOptimizationRemarks();
+
return true;
}
OpenPOWER on IntegriCloud