#define LLVM_IR_REMARKSTREAMER_H
#include "llvm/IR/DiagnosticInfo.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Regex.h"
#include <string>
#include <vector>
const std::string Filename;
/// The open raw_ostream that the remark diagnostics are emitted to.
raw_ostream &OS;
- /// The regex used to filter remarks based on the passes that emit them.
- Optional<Regex> PassFilter;
/// The YAML streamer.
yaml::Output YAMLOutput;
StringRef getFilename() const { return Filename; }
/// Return stream that the remark diagnostics are emitted to.
raw_ostream &getStream() { return OS; }
- /// Set a pass filter based on a regex \p Filter.
- /// Returns an error if the regex is invalid.
- Error setFilter(StringRef Filter);
/// Emit a diagnostic through the streamer.
void emit(const DiagnosticInfoOptimizationBase &Diag);
};
/// Optimization remarks file path.
std::string RemarksFilename = "";
- /// Optimization remarks pass filter.
- std::string RemarksPasses = "";
-
/// Whether to emit optimization remarks with hotness informations.
bool RemarksWithHotness = false;
/// Setup optimization remarks.
Expected<std::unique_ptr<ToolOutputFile>>
setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
- StringRef LTORemarksPasses,
bool LTOPassRemarksWithHotness, int Count = -1);
class LTO;
assert(!Filename.empty() && "This needs to be a real filename.");
}
-Error RemarkStreamer::setFilter(StringRef Filter) {
- Regex R = Regex(Filter);
- std::string RegexError;
- if (!R.isValid(RegexError))
- return createStringError(std::make_error_code(std::errc::invalid_argument),
- RegexError.data());
- PassFilter = std::move(R);
- return Error::success();
-}
-
void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
- if (Optional<Regex> &Filter = PassFilter)
- if (!Filter->match(Diag.getPassName()))
- return;
-
DiagnosticInfoOptimizationBase *DiagPtr =
const_cast<DiagnosticInfoOptimizationBase *>(&Diag);
YAMLOutput << DiagPtr;
Expected<std::unique_ptr<ToolOutputFile>>
lto::setupOptimizationRemarks(LLVMContext &Context,
StringRef LTORemarksFilename,
- StringRef LTORemarksPasses,
bool LTOPassRemarksWithHotness, int Count) {
if (LTOPassRemarksWithHotness)
Context.setDiagnosticsHotnessRequested(true);
return errorCodeToError(EC);
Context.setRemarkStreamer(
llvm::make_unique<RemarkStreamer>(Filename, DiagnosticFile->os()));
-
- if (!LTORemarksPasses.empty())
- if (Error E = Context.getRemarkStreamer()->setFilter(LTORemarksPasses))
- return std::move(E);
-
DiagnosticFile->keep();
return std::move(DiagnosticFile);
}
std::unique_ptr<TargetMachine> TM = createTargetMachine(C, *TOrErr, *Mod);
// Setup optimization remarks.
- auto DiagFileOrErr =
- lto::setupOptimizationRemarks(Mod->getContext(), C.RemarksFilename,
- C.RemarksPasses, C.RemarksWithHotness);
+ auto DiagFileOrErr = lto::setupOptimizationRemarks(
+ Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
if (!DiagFileOrErr)
return DiagFileOrErr.takeError();
auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
// Setup optimization remarks.
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Mod.getContext(), Conf.RemarksFilename, Conf.RemarksPasses,
- Conf.RemarksWithHotness, Task);
+ Mod.getContext(), Conf.RemarksFilename, Conf.RemarksWithHotness, Task);
if (!DiagFileOrErr)
return DiagFileOrErr.takeError();
auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
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(
"lto-pass-remarks-with-hotness",
cl::desc("With PGO, include profile count in optimization remarks"),
return false;
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, LTORemarksFilename, LTORemarksPasses, LTOPassRemarksWithHotness);
+ Context, LTORemarksFilename, LTOPassRemarksWithHotness);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("Can't get an output file for the remarks");
// 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;
}
Context.setDiscardValueNames(LTODiscardValueNames);
Context.enableDebugTypeODRUniquing();
auto DiagFileOrErr = lto::setupOptimizationRemarks(
- Context, LTORemarksFilename, LTORemarksPasses,
- LTOPassRemarksWithHotness, count);
+ Context, LTORemarksFilename, LTOPassRemarksWithHotness, count);
if (!DiagFileOrErr) {
errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
report_fatal_error("ThinLTO: Can't get an output file for the "
; RUN: llvm-as < %s >%t.bc
; RUN: rm -f %t.yaml
; RUN: llvm-lto2 run -pass-remarks-output=%t.yaml \
-; RUN: -pass-remarks-filter=inline \
; RUN: -r %t.bc,tinkywinky,p \
; RUN: -r %t.bc,patatino,px \
; RUN: -r %t.bc,main,px -o %t.o %t.bc
; RUN: opt -module-summary %s -o %t.bc
; RUN: rm -f %t.thin.1.yaml
; RUN: llvm-lto2 run -pass-remarks-output=%t \
-; RUN: -pass-remarks-filter=inline \
; RUN: -r %t.bc,tinkywinky,p \
; RUN: -r %t.bc,patatino,px \
; RUN: -r %t.bc,main,px -o %t.o %t.bc
; RUN: rm -f %t.yaml.thin.0.yaml %t.yaml.thin.1.yaml
; RUN: llvm-lto -thinlto-action=run \
; RUN: -lto-pass-remarks-output=%t.yaml \
-; RUN: -lto-pass-remarks-filter=inline \
; RUN: -exported-symbol _func2 \
; RUN: -exported-symbol _main %t1.bc %t2.bc 2>&1 | \
; RUN: FileCheck %s -allow-empty
/// Statistics output filename.
static std::string stats_file;
- // Optimization remarks filename, accepted passes and hotness options
+ // Optimization remarks filename and hotness options
static std::string OptRemarksFilename;
- static std::string OptRemarksFilter;
static bool OptRemarksWithHotness = false;
// Context sensitive PGO options.
dwo_dir = opt.substr(strlen("dwo_dir="));
} else if (opt.startswith("opt-remarks-filename=")) {
OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
- } else if (opt.startswith("opt-remarks-passes=")) {
- OptRemarksFilter = opt.substr(strlen("opt-remarks-passes="));
} else if (opt == "opt-remarks-with-hotness") {
OptRemarksWithHotness = true;
} else if (opt.startswith("stats-file=")) {
// Set up optimization remarks handling.
Conf.RemarksFilename = options::OptRemarksFilename;
- Conf.RemarksPasses = options::OptRemarksFilter;
Conf.RemarksWithHotness = options::OptRemarksWithHotness;
// Use new pass manager if set in driver
cl::desc("YAML output filename for pass remarks"),
cl::value_desc("filename"));
-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"));
-
namespace {
static ManagedStatic<std::vector<std::string>> RunPassNames;
}
Context.setRemarkStreamer(
llvm::make_unique<RemarkStreamer>(RemarksFilename, YamlFile->os()));
-
- if (!RemarksPasses.empty())
- if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
- WithColor::error(errs(), argv[0]) << E << '\n';
- return 1;
- }
}
if (InputLanguage != "" && InputLanguage != "ir" &&
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>
- 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",
cl::desc("Specify a SamplePGO profile file"));
// Optimization remarks.
Conf.RemarksFilename = OptRemarksOutput;
- Conf.RemarksPasses = OptRemarksPasses;
Conf.RemarksWithHotness = OptRemarksWithHotness;
Conf.SampleProfile = SamplePGOFile;
cl::desc("YAML output filename for pass remarks"),
cl::value_desc("filename"));
-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"));
-
cl::opt<PGOKind>
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
cl::desc("The kind of profile guided optimization"),
}
Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
RemarksFilename, OptRemarkFile->os()));
-
- if (!RemarksPasses.empty())
- if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses)) {
- errs() << E << '\n';
- return 1;
- }
}
// Load the input module...