summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-06-14 00:05:56 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-06-14 00:05:56 +0000
commite4147ea1ef4d24e266f71a2700fa7478d2fdc6ba (patch)
treea3c3123cebc1d13386b8e2e9c621e0741c506b5a
parent1e4882c8906f3a31031e47dd5010f4078a9c4702 (diff)
downloadbcm5719-llvm-e4147ea1ef4d24e266f71a2700fa7478d2fdc6ba.tar.gz
bcm5719-llvm-e4147ea1ef4d24e266f71a2700fa7478d2fdc6ba.zip
Revert "[Remarks] Refactor optimization remarks setup"
This reverts commit 6e6e3af55bb97e1a4c97375c15a2b0099120c5a7. This breaks greendragon. llvm-svn: 363343
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp51
-rw-r--r--llvm/include/llvm/IR/RemarkStreamer.h28
-rw-r--r--llvm/include/llvm/LTO/LTO.h6
-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
-rw-r--r--llvm/tools/gold/gold-plugin.cpp18
-rw-r--r--llvm/tools/llc/llc.cpp48
-rw-r--r--llvm/tools/llvm-lto2/llvm-lto2.cpp29
-rw-r--r--llvm/tools/opt/opt.cpp54
12 files changed, 163 insertions, 183 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index e8022c0e637..7671010fc98 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -262,32 +262,35 @@ namespace clang {
Ctx.getDiagnosticHandler();
Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
CodeGenOpts, this));
+ Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
+ if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
+ Ctx.setDiagnosticsHotnessThreshold(
+ CodeGenOpts.DiagnosticsHotnessThreshold);
+
+ std::unique_ptr<llvm::ToolOutputFile> OptRecordFile;
+ if (!CodeGenOpts.OptRecordFile.empty()) {
+ std::error_code EC;
+ OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>(
+ CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
+ if (EC) {
+ Diags.Report(diag::err_cannot_open_file) <<
+ CodeGenOpts.OptRecordFile << EC.message();
+ return;
+ }
- Expected<std::unique_ptr<llvm::ToolOutputFile>> OptRecordFileOrErr =
- setupOptimizationRemarks(Ctx, CodeGenOpts.OptRecordFile,
- CodeGenOpts.OptRecordPasses,
- CodeGenOpts.DiagnosticsWithHotness,
- CodeGenOpts.DiagnosticsHotnessThreshold);
-
- if (Error E = OptRecordFileOrErr.takeError()) {
- handleAllErrors(
- std::move(E),
- [&](const RemarkSetupFileError &E) {
- Diags.Report(diag::err_cannot_open_file)
- << CodeGenOpts.OptRecordFile << E.message();
- },
- [&](const RemarkSetupPatternError &E) {
- Diags.Report(diag::err_drv_optimization_remark_pattern)
- << E.message() << CodeGenOpts.OptRecordPasses;
- });
- return;
- }
- std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
- std::move(*OptRecordFileOrErr);
+ Ctx.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
+ CodeGenOpts.OptRecordFile,
+ llvm::make_unique<remarks::YAMLSerializer>(OptRecordFile->os())));
- if (OptRecordFile &&
- CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
- Ctx.setDiagnosticsHotnessRequested(true);
+ if (!CodeGenOpts.OptRecordPasses.empty())
+ if (Error E = Ctx.getRemarkStreamer()->setFilter(
+ CodeGenOpts.OptRecordPasses))
+ Diags.Report(diag::err_drv_optimization_remark_pattern)
+ << toString(std::move(E)) << CodeGenOpts.OptRecordPasses;
+
+ if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
+ Ctx.setDiagnosticsHotnessRequested(true);
+ }
// Link each LinkModule into our module.
if (LinkInModules())
diff --git a/llvm/include/llvm/IR/RemarkStreamer.h b/llvm/include/llvm/IR/RemarkStreamer.h
index 1db126ffdf7..621ebb3436c 100644
--- a/llvm/include/llvm/IR/RemarkStreamer.h
+++ b/llvm/include/llvm/IR/RemarkStreamer.h
@@ -17,7 +17,6 @@
#include "llvm/Remarks/RemarkSerializer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Regex.h"
-#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <vector>
@@ -58,33 +57,6 @@ public:
/// Emit a diagnostic through the streamer.
void emit(const DiagnosticInfoOptimizationBase &Diag);
};
-
-template <typename ThisError>
-struct RemarkSetupErrorInfo : public ErrorInfo<ThisError> {
- Error E;
- RemarkSetupErrorInfo(Error E) : E(std::move(E)) {}
- void log(raw_ostream &OS) const override { OS << E; }
- std::error_code convertToErrorCode() const override {
- return errorToErrorCode(E);
- }
-};
-
-struct RemarkSetupFileError : RemarkSetupErrorInfo<RemarkSetupFileError> {
- static char ID;
- using RemarkSetupErrorInfo<RemarkSetupFileError>::RemarkSetupErrorInfo;
-};
-
-struct RemarkSetupPatternError : RemarkSetupErrorInfo<RemarkSetupPatternError> {
- static char ID;
- using RemarkSetupErrorInfo<RemarkSetupPatternError>::RemarkSetupErrorInfo;
-};
-
-/// Setup optimization remarks.
-Expected<std::unique_ptr<ToolOutputFile>>
-setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
- StringRef RemarksPasses, bool RemarksWithHotness,
- unsigned RemarksHotnessThreshold = 0);
-
} // end namespace llvm
#endif // LLVM_IR_REMARKSTREAMER_H
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index cbddede66c0..d3a0d3c37dc 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -84,9 +84,9 @@ std::string getThinLTOOutputFile(const std::string &Path,
/// Setup optimization remarks.
Expected<std::unique_ptr<ToolOutputFile>>
-setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
- StringRef RemarksPasses, bool RemarksWithHotness,
- int Count = -1);
+setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
+ StringRef LTORemarksPasses,
+ bool LTOPassRemarksWithHotness, int Count = -1);
/// Setups the output file for saving statistics.
Expected<std::unique_ptr<ToolOutputFile>>
diff --git a/llvm/lib/IR/RemarkStreamer.cpp b/llvm/lib/IR/RemarkStreamer.cpp
index fe9cea0d5b5..fe1a128f473 100644
--- a/llvm/lib/IR/RemarkStreamer.cpp
+++ b/llvm/lib/IR/RemarkStreamer.cpp
@@ -106,38 +106,3 @@ 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 fe1bdfcaa96..882b15525c1 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1338,22 +1338,34 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
}
Expected<std::unique_ptr<ToolOutputFile>>
-lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
- StringRef RemarksPasses, bool RemarksWithHotness,
- int Count) {
- std::string Filename = RemarksFilename;
- if (!Filename.empty() && Count != -1)
+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)
Filename += ".thin." + llvm::utostr(Count) + ".yaml";
- auto ResultOrErr = llvm::setupOptimizationRemarks(
- Context, Filename, RemarksPasses, RemarksWithHotness);
- if (Error E = ResultOrErr.takeError())
- return std::move(E);
+ 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())));
- if (*ResultOrErr)
- (*ResultOrErr)->keep();
+ if (!LTORemarksPasses.empty())
+ if (Error E = Context.getRemarkStreamer()->setFilter(LTORemarksPasses))
+ return std::move(E);
- return ResultOrErr;
+ DiagnosticFile->keep();
+ return std::move(DiagnosticFile);
}
Expected<std::unique_ptr<ToolOutputFile>>
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 317d0163674..9c2d0ed5d54 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -22,7 +22,6 @@
#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"
@@ -33,9 +32,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 ebc4cc5794a..f6d955d59c6 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -33,7 +33,6 @@
#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"
@@ -81,21 +80,21 @@ cl::opt<bool> LTODiscardValueNames(
#endif
cl::Hidden);
-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"));
+ LTORemarksFilename("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"));
+ 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(
+ "lto-pass-remarks-with-hotness",
+ cl::desc("With PGO, include profile count in optimization remarks"),
+ cl::Hidden);
cl::opt<std::string> LTOStatsFile(
"lto-stats-file",
@@ -518,7 +517,7 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
return false;
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, RemarksFilename, RemarksPasses, RemarksWithHotness);
+ Context, LTORemarksFilename, LTORemarksPasses, LTOPassRemarksWithHotness);
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 5d9aa8e571b..df18dd3f9ca 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -29,7 +29,6 @@
#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"
@@ -70,9 +69,9 @@ using namespace llvm;
namespace llvm {
// Flags -discard-value-names, defined in LTOCodeGenerator.cpp
extern cl::opt<bool> LTODiscardValueNames;
-extern cl::opt<std::string> RemarksFilename;
-extern cl::opt<std::string> RemarksPasses;
-extern cl::opt<bool> RemarksWithHotness;
+extern cl::opt<std::string> LTORemarksFilename;
+extern cl::opt<std::string> LTORemarksPasses;
+extern cl::opt<bool> LTOPassRemarksWithHotness;
}
namespace {
@@ -1020,8 +1019,8 @@ void ThinLTOCodeGenerator::run() {
Context.setDiscardValueNames(LTODiscardValueNames);
Context.enableDebugTypeODRUniquing();
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, RemarksFilename, RemarksPasses,
- RemarksWithHotness, count);
+ Context, LTORemarksFilename, LTORemarksPasses,
+ LTOPassRemarksWithHotness, count);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("ThinLTO: Can't get an output file for the "
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 314d8637623..dc61ff925ce 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -206,9 +206,9 @@ namespace options {
static std::string stats_file;
// Optimization remarks filename, accepted passes and hotness options
- static std::string RemarksFilename;
- static std::string RemarksPasses;
- static bool RemarksWithHotness = false;
+ static std::string OptRemarksFilename;
+ static std::string OptRemarksFilter;
+ static bool OptRemarksWithHotness = false;
// Context sensitive PGO options.
static std::string cs_profile_path;
@@ -285,11 +285,11 @@ namespace options {
} else if (opt.startswith("dwo_dir=")) {
dwo_dir = opt.substr(strlen("dwo_dir="));
} else if (opt.startswith("opt-remarks-filename=")) {
- RemarksFilename = opt.substr(strlen("opt-remarks-filename="));
+ OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
} else if (opt.startswith("opt-remarks-passes=")) {
- RemarksPasses = opt.substr(strlen("opt-remarks-passes="));
+ OptRemarksFilter = opt.substr(strlen("opt-remarks-passes="));
} else if (opt == "opt-remarks-with-hotness") {
- RemarksWithHotness = true;
+ OptRemarksWithHotness = true;
} else if (opt.startswith("stats-file=")) {
stats_file = opt.substr(strlen("stats-file="));
} else {
@@ -910,9 +910,9 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
Conf.DwoDir = options::dwo_dir;
// Set up optimization remarks handling.
- Conf.RemarksFilename = options::RemarksFilename;
- Conf.RemarksPasses = options::RemarksPasses;
- Conf.RemarksWithHotness = options::RemarksWithHotness;
+ Conf.RemarksFilename = options::OptRemarksFilename;
+ Conf.RemarksPasses = options::OptRemarksFilter;
+ Conf.RemarksWithHotness = options::OptRemarksWithHotness;
// Use new pass manager if set in driver
Conf.UseNewPM = options::new_pass_manager;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 48a810cf6eb..a84e2b9471f 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -133,20 +133,19 @@ static cl::opt<bool> DiscardValueNames(
static cl::list<std::string> IncludeDirs("I", cl::desc("include search path"));
-static cl::opt<bool> RemarksWithHotness(
+static cl::opt<bool> PassRemarksWithHotness(
"pass-remarks-with-hotness",
cl::desc("With PGO, include profile count in optimization remarks"),
cl::Hidden);
-static cl::opt<unsigned>
- RemarksHotnessThreshold("pass-remarks-hotness-threshold",
- cl::desc("Minimum profile count required for "
- "an optimization remark to be output"),
- cl::Hidden);
+static cl::opt<unsigned> PassRemarksHotnessThreshold(
+ "pass-remarks-hotness-threshold",
+ cl::desc("Minimum profile count required for an optimization remark to be output"),
+ cl::Hidden);
static cl::opt<std::string>
RemarksFilename("pass-remarks-output",
- cl::desc("Output filename for pass remarks"),
+ cl::desc("YAML output filename for pass remarks"),
cl::value_desc("filename"));
static cl::opt<std::string>
@@ -327,14 +326,31 @@ int main(int argc, char **argv) {
llvm::make_unique<LLCDiagnosticHandler>(&HasError));
Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
- Expected<std::unique_ptr<ToolOutputFile>> RemarksFileOrErr =
- setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
- RemarksWithHotness, RemarksHotnessThreshold);
- if (Error E = RemarksFileOrErr.takeError()) {
- WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
- return 1;
+ if (PassRemarksWithHotness)
+ Context.setDiagnosticsHotnessRequested(true);
+
+ if (PassRemarksHotnessThreshold)
+ Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
+
+ std::unique_ptr<ToolOutputFile> YamlFile;
+ if (RemarksFilename != "") {
+ std::error_code EC;
+ YamlFile =
+ llvm::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::F_None);
+ if (EC) {
+ WithColor::error(errs(), argv[0]) << EC.message() << '\n';
+ return 1;
+ }
+ Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
+ RemarksFilename,
+ llvm::make_unique<remarks::YAMLSerializer>(YamlFile->os())));
+
+ if (!RemarksPasses.empty())
+ if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
+ WithColor::error(errs(), argv[0]) << E << '\n';
+ return 1;
+ }
}
- std::unique_ptr<ToolOutputFile> RemarksFile = std::move(*RemarksFileOrErr);
if (InputLanguage != "" && InputLanguage != "ir" &&
InputLanguage != "mir") {
@@ -349,8 +365,8 @@ int main(int argc, char **argv) {
if (int RetVal = compileModule(argv, Context))
return RetVal;
- if (RemarksFile)
- RemarksFile->keep();
+ if (YamlFile)
+ YamlFile->keep();
return 0;
}
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 7f8b5beb716..72d80f64a96 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -91,21 +91,20 @@ static cl::opt<std::string> DefaultTriple(
cl::desc(
"Replace unspecified target triples in input files with this triple"));
-static cl::opt<bool> RemarksWithHotness(
- "pass-remarks-with-hotness",
- cl::desc("With PGO, include profile count in optimization remarks"),
- cl::Hidden);
-
static cl::opt<std::string>
- RemarksFilename("pass-remarks-output",
- cl::desc("Output filename for pass remarks"),
- cl::value_desc("filename"));
+ OptRemarksOutput("pass-remarks-output",
+ cl::desc("YAML output file for optimization remarks"));
+
+static cl::opt<bool> OptRemarksWithHotness(
+ "pass-remarks-with-hotness",
+ cl::desc("Whether to include hotness informations in the remarks.\n"
+ "Has effect only if -pass-remarks-output is specified."));
static cl::opt<std::string>
- RemarksPasses("pass-remarks-filter",
- cl::desc("Only record optimization remarks from passes whose "
- "names match the given regular expression"),
- cl::value_desc("regex"));
+ OptRemarksPasses("pass-remarks-filter",
+ cl::desc("Only record optimization remarks from passes "
+ "whose names match the given regular expression"),
+ cl::value_desc("regex"));
static cl::opt<std::string>
SamplePGOFile("lto-sample-profile-file",
@@ -226,9 +225,9 @@ static int run(int argc, char **argv) {
"Config::addSaveTemps failed");
// Optimization remarks.
- Conf.RemarksFilename = RemarksFilename;
- Conf.RemarksPasses = RemarksPasses;
- Conf.RemarksWithHotness = RemarksWithHotness;
+ Conf.RemarksFilename = OptRemarksOutput;
+ Conf.RemarksPasses = OptRemarksPasses;
+ Conf.RemarksWithHotness = OptRemarksWithHotness;
Conf.SampleProfile = SamplePGOFile;
Conf.CSIRProfile = CSPGOFile;
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index dde1d776fef..4410b4c1679 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -251,20 +251,19 @@ static cl::opt<bool> Coroutines(
cl::desc("Enable coroutine passes."),
cl::init(false), cl::Hidden);
-static cl::opt<bool> RemarksWithHotness(
+static cl::opt<bool> PassRemarksWithHotness(
"pass-remarks-with-hotness",
cl::desc("With PGO, include profile count in optimization remarks"),
cl::Hidden);
-static cl::opt<unsigned>
- RemarksHotnessThreshold("pass-remarks-hotness-threshold",
- cl::desc("Minimum profile count required for "
- "an optimization remark to be output"),
- cl::Hidden);
+static cl::opt<unsigned> PassRemarksHotnessThreshold(
+ "pass-remarks-hotness-threshold",
+ cl::desc("Minimum profile count required for an optimization remark to be output"),
+ cl::Hidden);
static cl::opt<std::string>
RemarksFilename("pass-remarks-output",
- cl::desc("Output filename for pass remarks"),
+ cl::desc("YAML output filename for pass remarks"),
cl::value_desc("filename"));
static cl::opt<std::string>
@@ -550,14 +549,31 @@ int main(int argc, char **argv) {
if (!DisableDITypeMap)
Context.enableDebugTypeODRUniquing();
- Expected<std::unique_ptr<ToolOutputFile>> RemarksFileOrErr =
- setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
- RemarksWithHotness, RemarksHotnessThreshold);
- if (Error E = RemarksFileOrErr.takeError()) {
- errs() << toString(std::move(E)) << '\n';
- return 1;
+ if (PassRemarksWithHotness)
+ Context.setDiagnosticsHotnessRequested(true);
+
+ if (PassRemarksHotnessThreshold)
+ Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
+
+ std::unique_ptr<ToolOutputFile> OptRemarkFile;
+ if (RemarksFilename != "") {
+ std::error_code EC;
+ OptRemarkFile =
+ llvm::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::F_None);
+ if (EC) {
+ errs() << EC.message() << '\n';
+ return 1;
+ }
+ Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
+ RemarksFilename,
+ llvm::make_unique<remarks::YAMLSerializer>(OptRemarkFile->os())));
+
+ if (!RemarksPasses.empty())
+ if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
+ errs() << E << '\n';
+ return 1;
+ }
}
- std::unique_ptr<ToolOutputFile> RemarksFile = std::move(*RemarksFileOrErr);
// Load the input module...
std::unique_ptr<Module> M =
@@ -671,7 +687,7 @@ int main(int argc, char **argv) {
// string. Hand off the rest of the functionality to the new code for that
// layer.
return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
- RemarksFile.get(), PassPipeline, OK, VK,
+ OptRemarkFile.get(), PassPipeline, OK, VK,
PreserveAssemblyUseListOrder,
PreserveBitcodeUseListOrder, EmitSummaryIndex,
EmitModuleHash, EnableDebugify)
@@ -907,8 +923,8 @@ int main(int argc, char **argv) {
"the compile-twice option\n";
Out->os() << BOS->str();
Out->keep();
- if (RemarksFile)
- RemarksFile->keep();
+ if (OptRemarkFile)
+ OptRemarkFile->keep();
return 1;
}
Out->os() << BOS->str();
@@ -921,8 +937,8 @@ int main(int argc, char **argv) {
if (!NoOutput || PrintBreakpoints)
Out->keep();
- if (RemarksFile)
- RemarksFile->keep();
+ if (OptRemarkFile)
+ OptRemarkFile->keep();
if (ThinLinkOut)
ThinLinkOut->keep();
OpenPOWER on IntegriCloud