summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/RemarkStreamer.cpp35
-rw-r--r--llvm/lib/LTO/LTO.cpp36
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp3
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp27
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp11
5 files changed, 69 insertions, 43 deletions
diff --git a/llvm/lib/IR/RemarkStreamer.cpp b/llvm/lib/IR/RemarkStreamer.cpp
index fe1a128f473..fe9cea0d5b5 100644
--- a/llvm/lib/IR/RemarkStreamer.cpp
+++ b/llvm/lib/IR/RemarkStreamer.cpp
@@ -106,3 +106,38 @@ void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
// Then, emit the remark through the serializer.
Serializer->emit(R);
}
+
+char RemarkSetupFileError::ID = 0;
+char RemarkSetupPatternError::ID = 0;
+
+Expected<std::unique_ptr<ToolOutputFile>>
+llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
+ StringRef RemarksPasses, bool RemarksWithHotness,
+ unsigned RemarksHotnessThreshold) {
+ if (RemarksWithHotness)
+ Context.setDiagnosticsHotnessRequested(true);
+
+ if (RemarksHotnessThreshold)
+ Context.setDiagnosticsHotnessThreshold(RemarksHotnessThreshold);
+
+ if (RemarksFilename.empty())
+ return nullptr;
+
+ std::error_code EC;
+ auto RemarksFile =
+ llvm::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::F_None);
+ // We don't use llvm::FileError here because some diagnostics want the file
+ // name separately.
+ if (EC)
+ return errorCodeToError(EC);
+
+ Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
+ RemarksFilename,
+ llvm::make_unique<remarks::YAMLSerializer>(RemarksFile->os())));
+
+ if (!RemarksPasses.empty())
+ if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
+ return std::move(E);
+
+ return std::move(RemarksFile);
+}
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 882b15525c1..fe1bdfcaa96 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1338,34 +1338,22 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
}
Expected<std::unique_ptr<ToolOutputFile>>
-lto::setupOptimizationRemarks(LLVMContext &Context,
- StringRef LTORemarksFilename,
- StringRef LTORemarksPasses,
- bool LTOPassRemarksWithHotness, int Count) {
- if (LTOPassRemarksWithHotness)
- Context.setDiagnosticsHotnessRequested(true);
- if (LTORemarksFilename.empty())
- return nullptr;
-
- std::string Filename = LTORemarksFilename;
- if (Count != -1)
+lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
+ StringRef RemarksPasses, bool RemarksWithHotness,
+ int Count) {
+ std::string Filename = RemarksFilename;
+ if (!Filename.empty() && Count != -1)
Filename += ".thin." + llvm::utostr(Count) + ".yaml";
- std::error_code EC;
- auto DiagnosticFile =
- llvm::make_unique<ToolOutputFile>(Filename, EC, sys::fs::F_None);
- if (EC)
- return errorCodeToError(EC);
- Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
- Filename,
- llvm::make_unique<remarks::YAMLSerializer>(DiagnosticFile->os())));
+ auto ResultOrErr = llvm::setupOptimizationRemarks(
+ Context, Filename, RemarksPasses, RemarksWithHotness);
+ if (Error E = ResultOrErr.takeError())
+ return std::move(E);
- if (!LTORemarksPasses.empty())
- if (Error E = Context.getRemarkStreamer()->setFilter(LTORemarksPasses))
- return std::move(E);
+ if (*ResultOrErr)
+ (*ResultOrErr)->keep();
- DiagnosticFile->keep();
- return std::move(DiagnosticFile);
+ return ResultOrErr;
}
Expected<std::unique_ptr<ToolOutputFile>>
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 9c2d0ed5d54..317d0163674 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -22,6 +22,7 @@
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/IR/RemarkStreamer.h"
#include "llvm/IR/Verifier.h"
#include "llvm/LTO/LTO.h"
#include "llvm/MC/SubtargetFeature.h"
@@ -32,9 +33,9 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index f6d955d59c6..ebc4cc5794a 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -33,6 +33,7 @@
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassTimingInfo.h"
+#include "llvm/IR/RemarkStreamer.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/LTO/LTO.h"
@@ -80,22 +81,22 @@ cl::opt<bool> LTODiscardValueNames(
#endif
cl::Hidden);
-cl::opt<std::string>
- LTORemarksFilename("lto-pass-remarks-output",
- cl::desc("Output filename for pass remarks"),
- cl::value_desc("filename"));
-
-cl::opt<std::string>
- LTORemarksPasses("lto-pass-remarks-filter",
- cl::desc("Only record optimization remarks from passes "
- "whose names match the given regular expression"),
- cl::value_desc("regex"));
-
-cl::opt<bool> LTOPassRemarksWithHotness(
+cl::opt<bool> RemarksWithHotness(
"lto-pass-remarks-with-hotness",
cl::desc("With PGO, include profile count in optimization remarks"),
cl::Hidden);
+cl::opt<std::string>
+ RemarksFilename("lto-pass-remarks-output",
+ cl::desc("Output filename for pass remarks"),
+ cl::value_desc("filename"));
+
+cl::opt<std::string>
+ RemarksPasses("lto-pass-remarks-filter",
+ cl::desc("Only record optimization remarks from passes whose "
+ "names match the given regular expression"),
+ cl::value_desc("regex"));
+
cl::opt<std::string> LTOStatsFile(
"lto-stats-file",
cl::desc("Save statistics to the specified file"),
@@ -517,7 +518,7 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
return false;
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, LTORemarksFilename, LTORemarksPasses, LTOPassRemarksWithHotness);
+ Context, RemarksFilename, RemarksPasses, RemarksWithHotness);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("Can't get an output file for the remarks");
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index df18dd3f9ca..5d9aa8e571b 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -29,6 +29,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/PassTimingInfo.h"
+#include "llvm/IR/RemarkStreamer.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/LTO/LTO.h"
@@ -69,9 +70,9 @@ using namespace llvm;
namespace llvm {
// Flags -discard-value-names, defined in LTOCodeGenerator.cpp
extern cl::opt<bool> LTODiscardValueNames;
-extern cl::opt<std::string> LTORemarksFilename;
-extern cl::opt<std::string> LTORemarksPasses;
-extern cl::opt<bool> LTOPassRemarksWithHotness;
+extern cl::opt<std::string> RemarksFilename;
+extern cl::opt<std::string> RemarksPasses;
+extern cl::opt<bool> RemarksWithHotness;
}
namespace {
@@ -1019,8 +1020,8 @@ void ThinLTOCodeGenerator::run() {
Context.setDiscardValueNames(LTODiscardValueNames);
Context.enableDebugTypeODRUniquing();
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, LTORemarksFilename, LTORemarksPasses,
- LTOPassRemarksWithHotness, count);
+ Context, RemarksFilename, RemarksPasses,
+ RemarksWithHotness, count);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("ThinLTO: Can't get an output file for the "
OpenPOWER on IntegriCloud