Commit 209d5a12 authored by Francis Visoiu Mistrih's avatar Francis Visoiu Mistrih
Browse files

[Remarks] Emit the remarks section by default for certain formats

Emit a remarks section by default for the following formats:

* bitstream
* yaml-strtab

while still providing -remarks-section=<bool> to override the defaults.
parent a51fc8dd
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -581,9 +581,13 @@ This diff file can be displayed using :ref:`opt-viewer.py <optviewerpy>`.
Emitting remark diagnostics in the object file
==============================================

A section containing metadata on remark diagnostics will be emitted when
-remarks-section is passed. The section contains the metadata associated to the
format used to serialize the remarks.
A section containing metadata on remark diagnostics will be emitted for the
following formats:

* ``yaml-strtab``
* ``bitstream``

This can be overridden by using the flag ``-remarks-section=<bool>``.

The section is named:

+2 −1
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ class MCTargetOptions;
class MDNode;
class Module;
class raw_ostream;
class RemarkStreamer;
class StackMaps;
class TargetLoweringObjectFile;
class TargetMachine;
@@ -319,7 +320,7 @@ public:

  void emitStackSizeSection(const MachineFunction &MF);

  void emitRemarksSection(Module &M);
  void emitRemarksSection(RemarkStreamer &RS);

  enum CFIMoveType { CFI_M_None, CFI_M_EH, CFI_M_Debug };
  CFIMoveType needsCFIMoves() const;
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public:
  Error setFilter(StringRef Filter);
  /// Emit a diagnostic through the streamer.
  void emit(const DiagnosticInfoOptimizationBase &Diag);
  /// Check if the remarks also need to have associated metadata in a section.
  bool needsSection() const;
};

template <typename ThisError>
+7 −12
Original line number Diff line number Diff line
@@ -146,11 +146,6 @@ static const char *const CodeViewLineTablesGroupDescription =

STATISTIC(EmittedInsts, "Number of machine instrs printed");

static cl::opt<bool> EnableRemarksSection(
    "remarks-section",
    cl::desc("Emit a section containing remark diagnostics metadata"),
    cl::init(false));

char AsmPrinter::ID = 0;

using gcp_map_type = DenseMap<GCStrategy *, std::unique_ptr<GCMetadataPrinter>>;
@@ -1365,14 +1360,14 @@ void AsmPrinter::emitGlobalIndirectSymbol(Module &M,
  }
}

void AsmPrinter::emitRemarksSection(Module &M) {
  RemarkStreamer *RS = M.getContext().getRemarkStreamer();
  if (!RS)
void AsmPrinter::emitRemarksSection(RemarkStreamer &RS) {
  if (!RS.needsSection())
    return;
  remarks::RemarkSerializer &RemarkSerializer = RS->getSerializer();

  remarks::RemarkSerializer &RemarkSerializer = RS.getSerializer();

  Optional<SmallString<128>> Filename;
  if (Optional<StringRef> FilenameRef = RS->getFilename()) {
  if (Optional<StringRef> FilenameRef = RS.getFilename()) {
    Filename = *FilenameRef;
    sys::fs::make_absolute(*Filename);
    assert(!Filename->empty() && "The filename can't be empty.");
@@ -1427,8 +1422,8 @@ bool AsmPrinter::doFinalization(Module &M) {
  // Emit the remarks section contents.
  // FIXME: Figure out when is the safest time to emit this section. It should
  // not come after debug info.
  if (EnableRemarksSection)
    emitRemarksSection(M);
  if (RemarkStreamer *RS = M.getContext().getRemarkStreamer())
    emitRemarksSection(*RS);

  const TargetLoweringObjectFile &TLOF = getObjFileLowering();

+32 −0
Original line number Diff line number Diff line
@@ -21,6 +21,13 @@

using namespace llvm;

static cl::opt<cl::boolOrDefault> EnableRemarksSection(
    "remarks-section",
    cl::desc(
        "Emit a section containing remark diagnostics metadata. By default, "
        "this is enabled for the following formats: yaml-strtab, bitstream."),
    cl::init(cl::BOU_UNSET), cl::Hidden);

RemarkStreamer::RemarkStreamer(
    std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
    Optional<StringRef> FilenameIn)
@@ -104,6 +111,31 @@ void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) {
  RemarkSerializer->emit(R);
}

bool RemarkStreamer::needsSection() const {
  if (EnableRemarksSection == cl::BOU_TRUE)
    return true;

  if (EnableRemarksSection == cl::BOU_FALSE)
    return false;

  assert(EnableRemarksSection == cl::BOU_UNSET);

  // We only need a section if we're in separate mode.
  if (RemarkSerializer->Mode != remarks::SerializerMode::Separate)
    return false;

  // Only some formats need a section:
  // * bitstream
  // * yaml-strtab
  switch (RemarkSerializer->SerializerFormat) {
  case remarks::Format::YAMLStrTab:
  case remarks::Format::Bitstream:
    return true;
  default:
    return false;
  }
}

char RemarkSetupFileError::ID = 0;
char RemarkSetupPatternError::ID = 0;
char RemarkSetupFormatError::ID = 0;
Loading