mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[Remarks] Allow the RemarkStreamer to be used directly with a stream
The filename in the RemarkStreamer should be optional to allow clients to stream remarks to memory or to existing streams. This introduces a new overload of `setupOptimizationRemarks`, and avoids enforcing the presence of a filename at different places. llvm-svn: 372195
This commit is contained in:
parent
023768353b
commit
e75b4debb9
@ -25,12 +25,12 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
/// Streamer for remarks.
|
/// Streamer for remarks.
|
||||||
class RemarkStreamer {
|
class RemarkStreamer {
|
||||||
/// The filename that the remark diagnostics are emitted to.
|
|
||||||
const std::string Filename;
|
|
||||||
/// The regex used to filter remarks based on the passes that emit them.
|
/// The regex used to filter remarks based on the passes that emit them.
|
||||||
Optional<Regex> PassFilter;
|
Optional<Regex> PassFilter;
|
||||||
/// The object used to serialize the remarks to a specific format.
|
/// The object used to serialize the remarks to a specific format.
|
||||||
std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
|
std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
|
||||||
|
/// The filename that the remark diagnostics are emitted to.
|
||||||
|
const Optional<std::string> Filename;
|
||||||
|
|
||||||
/// Convert diagnostics into remark objects.
|
/// Convert diagnostics into remark objects.
|
||||||
/// The lifetime of the members of the result is bound to the lifetime of
|
/// The lifetime of the members of the result is bound to the lifetime of
|
||||||
@ -38,10 +38,12 @@ class RemarkStreamer {
|
|||||||
remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag);
|
remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RemarkStreamer(StringRef Filename,
|
RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
|
||||||
std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer);
|
Optional<StringRef> Filename = None);
|
||||||
/// Return the filename that the remark diagnostics are emitted to.
|
/// Return the filename that the remark diagnostics are emitted to.
|
||||||
StringRef getFilename() const { return Filename; }
|
Optional<StringRef> getFilename() const {
|
||||||
|
return Filename ? Optional<StringRef>(*Filename) : None;
|
||||||
|
}
|
||||||
/// Return stream that the remark diagnostics are emitted to.
|
/// Return stream that the remark diagnostics are emitted to.
|
||||||
raw_ostream &getStream() { return RemarkSerializer->OS; }
|
raw_ostream &getStream() { return RemarkSerializer->OS; }
|
||||||
/// Return the serializer used for this stream.
|
/// Return the serializer used for this stream.
|
||||||
@ -84,13 +86,21 @@ struct RemarkSetupFormatError : RemarkSetupErrorInfo<RemarkSetupFormatError> {
|
|||||||
using RemarkSetupErrorInfo<RemarkSetupFormatError>::RemarkSetupErrorInfo;
|
using RemarkSetupErrorInfo<RemarkSetupFormatError>::RemarkSetupErrorInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Setup optimization remarks.
|
/// Setup optimization remarks that output to a file.
|
||||||
Expected<std::unique_ptr<ToolOutputFile>>
|
Expected<std::unique_ptr<ToolOutputFile>>
|
||||||
setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
|
setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
|
||||||
StringRef RemarksPasses, StringRef RemarksFormat,
|
StringRef RemarksPasses, StringRef RemarksFormat,
|
||||||
bool RemarksWithHotness,
|
bool RemarksWithHotness,
|
||||||
unsigned RemarksHotnessThreshold = 0);
|
unsigned RemarksHotnessThreshold = 0);
|
||||||
|
|
||||||
|
/// Setup optimization remarks that output directly to a raw_ostream.
|
||||||
|
/// \p OS is managed by the caller and should be open for writing as long as \p
|
||||||
|
/// Context is streaming remarks to it.
|
||||||
|
Error setupOptimizationRemarks(LLVMContext &Context, raw_ostream &OS,
|
||||||
|
StringRef RemarksPasses, StringRef RemarksFormat,
|
||||||
|
bool RemarksWithHotness,
|
||||||
|
unsigned RemarksHotnessThreshold = 0);
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // LLVM_IR_REMARKSTREAMER_H
|
#endif // LLVM_IR_REMARKSTREAMER_H
|
||||||
|
@ -1349,15 +1349,18 @@ void AsmPrinter::emitRemarksSection(Module &M) {
|
|||||||
return;
|
return;
|
||||||
remarks::RemarkSerializer &RemarkSerializer = RS->getSerializer();
|
remarks::RemarkSerializer &RemarkSerializer = RS->getSerializer();
|
||||||
|
|
||||||
StringRef FilenameRef = RS->getFilename();
|
Optional<SmallString<128>> Filename;
|
||||||
SmallString<128> Filename = FilenameRef;
|
if (Optional<StringRef> FilenameRef = RS->getFilename()) {
|
||||||
sys::fs::make_absolute(Filename);
|
Filename = *FilenameRef;
|
||||||
assert(!Filename.empty() && "The filename can't be empty.");
|
sys::fs::make_absolute(*Filename);
|
||||||
|
assert(!Filename->empty() && "The filename can't be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
std::string Buf;
|
std::string Buf;
|
||||||
raw_string_ostream OS(Buf);
|
raw_string_ostream OS(Buf);
|
||||||
std::unique_ptr<remarks::MetaSerializer> MetaSerializer =
|
std::unique_ptr<remarks::MetaSerializer> MetaSerializer =
|
||||||
RemarkSerializer.metaSerializer(OS, StringRef(Filename));
|
Filename ? RemarkSerializer.metaSerializer(OS, StringRef(*Filename))
|
||||||
|
: RemarkSerializer.metaSerializer(OS);
|
||||||
MetaSerializer->emit();
|
MetaSerializer->emit();
|
||||||
|
|
||||||
// Switch to the right section: .remarks/__remarks.
|
// Switch to the right section: .remarks/__remarks.
|
||||||
|
@ -22,12 +22,10 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
RemarkStreamer::RemarkStreamer(
|
RemarkStreamer::RemarkStreamer(
|
||||||
StringRef Filename,
|
std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
|
||||||
std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer)
|
Optional<StringRef> FilenameIn)
|
||||||
: Filename(Filename), PassFilter(),
|
: PassFilter(), RemarkSerializer(std::move(RemarkSerializer)),
|
||||||
RemarkSerializer(std::move(RemarkSerializer)) {
|
Filename(FilenameIn ? Optional<std::string>(FilenameIn->str()) : None) {}
|
||||||
assert(!Filename.empty() && "This needs to be a real filename.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Error RemarkStreamer::setFilter(StringRef Filter) {
|
Error RemarkStreamer::setFilter(StringRef Filter) {
|
||||||
Regex R = Regex(Filter);
|
Regex R = Regex(Filter);
|
||||||
@ -137,12 +135,13 @@ llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
|
|||||||
return make_error<RemarkSetupFormatError>(std::move(E));
|
return make_error<RemarkSetupFormatError>(std::move(E));
|
||||||
|
|
||||||
Expected<std::unique_ptr<remarks::RemarkSerializer>> RemarkSerializer =
|
Expected<std::unique_ptr<remarks::RemarkSerializer>> RemarkSerializer =
|
||||||
remarks::createRemarkSerializer(*Format, remarks::SerializerMode::Separate, RemarksFile->os());
|
remarks::createRemarkSerializer(
|
||||||
|
*Format, remarks::SerializerMode::Separate, RemarksFile->os());
|
||||||
if (Error E = RemarkSerializer.takeError())
|
if (Error E = RemarkSerializer.takeError())
|
||||||
return make_error<RemarkSetupFormatError>(std::move(E));
|
return make_error<RemarkSetupFormatError>(std::move(E));
|
||||||
|
|
||||||
Context.setRemarkStreamer(std::make_unique<RemarkStreamer>(
|
Context.setRemarkStreamer(std::make_unique<RemarkStreamer>(
|
||||||
RemarksFilename, std::move(*RemarkSerializer)));
|
std::move(*RemarkSerializer), RemarksFilename));
|
||||||
|
|
||||||
if (!RemarksPasses.empty())
|
if (!RemarksPasses.empty())
|
||||||
if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
|
if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
|
||||||
@ -150,3 +149,34 @@ llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
|
|||||||
|
|
||||||
return std::move(RemarksFile);
|
return std::move(RemarksFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error llvm::setupOptimizationRemarks(LLVMContext &Context, raw_ostream &OS,
|
||||||
|
StringRef RemarksPasses,
|
||||||
|
StringRef RemarksFormat,
|
||||||
|
bool RemarksWithHotness,
|
||||||
|
unsigned RemarksHotnessThreshold) {
|
||||||
|
if (RemarksWithHotness)
|
||||||
|
Context.setDiagnosticsHotnessRequested(true);
|
||||||
|
|
||||||
|
if (RemarksHotnessThreshold)
|
||||||
|
Context.setDiagnosticsHotnessThreshold(RemarksHotnessThreshold);
|
||||||
|
|
||||||
|
Expected<remarks::Format> Format = remarks::parseFormat(RemarksFormat);
|
||||||
|
if (Error E = Format.takeError())
|
||||||
|
return make_error<RemarkSetupFormatError>(std::move(E));
|
||||||
|
|
||||||
|
Expected<std::unique_ptr<remarks::RemarkSerializer>> RemarkSerializer =
|
||||||
|
remarks::createRemarkSerializer(*Format,
|
||||||
|
remarks::SerializerMode::Separate, OS);
|
||||||
|
if (Error E = RemarkSerializer.takeError())
|
||||||
|
return make_error<RemarkSetupFormatError>(std::move(E));
|
||||||
|
|
||||||
|
Context.setRemarkStreamer(
|
||||||
|
std::make_unique<RemarkStreamer>(std::move(*RemarkSerializer)));
|
||||||
|
|
||||||
|
if (!RemarksPasses.empty())
|
||||||
|
if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))
|
||||||
|
return make_error<RemarkSetupPatternError>(std::move(E));
|
||||||
|
|
||||||
|
return Error::success();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user