summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-10-28 11:10:07 -0700
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-10-28 12:50:46 -0700
commit209d5a12c55fe674686b5dbff8ba59cad665a56a (patch)
treedf84e93967d8462a58b08c9bd04217d6c7e60d9f
parenta51fc8ddf8800ed2f28d1e18b995e6c42f0bd3af (diff)
downloadbcm5719-llvm-209d5a12c55fe674686b5dbff8ba59cad665a56a.tar.gz
bcm5719-llvm-209d5a12c55fe674686b5dbff8ba59cad665a56a.zip
[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.
-rw-r--r--llvm/docs/Remarks.rst10
-rw-r--r--llvm/include/llvm/CodeGen/AsmPrinter.h3
-rw-r--r--llvm/include/llvm/IR/RemarkStreamer.h2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp19
-rw-r--r--llvm/lib/IR/RemarkStreamer.cpp32
-rw-r--r--llvm/test/CodeGen/X86/remarks-section.ll21
6 files changed, 71 insertions, 16 deletions
diff --git a/llvm/docs/Remarks.rst b/llvm/docs/Remarks.rst
index 8dba1947d70..0496a5a3f64 100644
--- a/llvm/docs/Remarks.rst
+++ b/llvm/docs/Remarks.rst
@@ -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:
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index a4580da5aec..16298ff7b72 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -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;
diff --git a/llvm/include/llvm/IR/RemarkStreamer.h b/llvm/include/llvm/IR/RemarkStreamer.h
index 2abf6f99cb0..9ea12e8389f 100644
--- a/llvm/include/llvm/IR/RemarkStreamer.h
+++ b/llvm/include/llvm/IR/RemarkStreamer.h
@@ -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>
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3692a03c268..b784d2980cb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -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();
diff --git a/llvm/lib/IR/RemarkStreamer.cpp b/llvm/lib/IR/RemarkStreamer.cpp
index 0fcc06b961f..9ad1243fc68 100644
--- a/llvm/lib/IR/RemarkStreamer.cpp
+++ b/llvm/lib/IR/RemarkStreamer.cpp
@@ -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;
diff --git a/llvm/test/CodeGen/X86/remarks-section.ll b/llvm/test/CodeGen/X86/remarks-section.ll
index 7c4d40220a0..3388e7879dc 100644
--- a/llvm/test/CodeGen/X86/remarks-section.ll
+++ b/llvm/test/CodeGen/X86/remarks-section.ll
@@ -2,6 +2,12 @@
; RUN: llc < %s -mtriple=x86_64-darwin -remarks-section -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN -DPATH=%/t.yaml %s
; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=yaml-strtab -remarks-section -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-STRTAB -DPATH=%/t.yaml %s
+; RUN: llc < %s -mtriple=x86_64-darwin -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-DEFAULT %s
+; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=yaml-strtab -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-DEFAULT-YAML-STRTAB %s
+; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=bitstream -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-DEFAULT-BITSTREAM %s
+; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=bitstream -remarks-section=false -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-OVERRIDE-BITSTREAM %s
+; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=yaml -remarks-section=true -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-OVERRIDE-YAML %s
+
; CHECK-LABEL: func1:
; CHECK: .section .remarks,"e",@progbits
@@ -12,6 +18,21 @@
; CHECK-DARWIN-STRTAB: .section __LLVM,__remarks,regular,debug
; CHECK-DARWIN-STRTAB-NEXT: .byte
+
+; By default, the format is YAML which does not need a section.
+; CHECK-DARWIN-DEFAULT-NOT: .section __LLVM,__remarks
+
+; yaml-strtab needs a section.
+; CHECK-DARWIN-DEFAULT-YAML-STRTAB: .section __LLVM,__remarks
+
+; bitstream needs a section.
+; CHECK-DARWIN-DEFAULT-BITSTREAM: .section __LLVM,__remarks
+
+; -remarks-section should force disable the section.
+; CHECK-DARWIN-OVERRIDE-BITSTREAM-NOT: .section __LLVM,__remarks
+
+; -remarks-section should also force enable the section.
+; CHECK-DARWIN-OVERRIDE-YAML: .section __LLVM,__remarks
define void @func1() {
ret void
}
OpenPOWER on IntegriCloud