[llvm] [Sanitizer] Use DK_OptimizationRemarkMissed for DiagnosticInfoInstrumentation. (PR #106356)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 23:31:45 PDT 2024


https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/106356

>From 2655ca18dfdd195a88dc42ff0e773561ce142167 Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Wed, 28 Aug 2024 15:03:27 +0530
Subject: [PATCH 1/2] [Sanitizer] Use DK_OptimizationRemarkMissed for
 DiagnosticInfoInstrumentation.

---
 llvm/lib/Transforms/Instrumentation/Instrumentation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
index 305bae0e2010d1..ce742460bcdf5b 100644
--- a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -32,7 +32,7 @@ class DiagnosticInfoInstrumentation : public DiagnosticInfo {
 public:
   DiagnosticInfoInstrumentation(const Twine &DiagMsg,
                                 DiagnosticSeverity Severity = DS_Warning)
-      : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
+      : DiagnosticInfo(DK_OptimizationRemarkMissed, Severity), Msg(DiagMsg) {}
   void print(DiagnosticPrinter &DP) const override { DP << Msg; }
 };
 } // namespace

>From ab53f29ca7ebaf91c5f344d56920788aa7240d09 Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Thu, 29 Aug 2024 12:00:34 +0530
Subject: [PATCH 2/2] [Sanitizer] Extend DiagnosticInfo for IR Instrumentation
 reproting.

---
 llvm/include/llvm/IR/DiagnosticInfo.h           | 17 +++++++++++++++++
 llvm/lib/IR/DiagnosticInfo.cpp                  |  4 ++++
 .../Instrumentation/Instrumentation.cpp         | 13 -------------
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index b35923efdad5d2..0abff016b77792 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -65,6 +65,7 @@ enum DiagnosticKind {
   DK_Lowering,
   DK_DebugMetadataVersion,
   DK_DebugMetadataInvalid,
+  DK_Instrumentation,
   DK_ISelFallback,
   DK_SampleProfile,
   DK_OptimizationRemark,
@@ -950,6 +951,22 @@ class DiagnosticInfoMIRParser : public DiagnosticInfo {
   }
 };
 
+/// Diagnostic information for IR instrumentation reporting.
+class DiagnosticInfoInstrumentation : public DiagnosticInfo {
+  const Twine &Msg;
+
+public:
+  DiagnosticInfoInstrumentation(const Twine &DiagMsg,
+                                DiagnosticSeverity Severity = DS_Warning)
+      : DiagnosticInfo(DK_Instrumentation, Severity), Msg(DiagMsg) {}
+
+  void print(DiagnosticPrinter &DP) const override;
+
+  static bool classof(const DiagnosticInfo *DI) {
+    return DI->getKind() == DK_Instrumentation;
+  }
+};
+
 /// Diagnostic information for ISel fallback path.
 class DiagnosticInfoISelFallback : public DiagnosticInfo {
   /// The function that is concerned by this diagnostic.
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 623f372bb9e740..234280754d547f 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -375,6 +375,10 @@ void DiagnosticInfoUnsupported::print(DiagnosticPrinter &DP) const {
   DP << Str;
 }
 
+void DiagnosticInfoInstrumentation::print(DiagnosticPrinter &DP) const {
+  DP << Msg;
+}
+
 void DiagnosticInfoISelFallback::print(DiagnosticPrinter &DP) const {
   DP << "Instruction selection used fallback path for " << getFunction();
 }
diff --git a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
index ce742460bcdf5b..9c436da7f00612 100644
--- a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -24,19 +24,6 @@ static cl::opt<bool> ClIgnoreRedundantInstrumentation(
     "ignore-redundant-instrumentation",
     cl::desc("Ignore redundant instrumentation"), cl::Hidden, cl::init(false));
 
-namespace {
-/// Diagnostic information for IR instrumentation reporting.
-class DiagnosticInfoInstrumentation : public DiagnosticInfo {
-  const Twine &Msg;
-
-public:
-  DiagnosticInfoInstrumentation(const Twine &DiagMsg,
-                                DiagnosticSeverity Severity = DS_Warning)
-      : DiagnosticInfo(DK_OptimizationRemarkMissed, Severity), Msg(DiagMsg) {}
-  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
-};
-} // namespace
-
 /// Check if module has flag attached, if not add the flag.
 bool llvm::checkIfAlreadyInstrumented(Module &M, StringRef Flag) {
   if (!M.getModuleFlag(Flag)) {



More information about the llvm-commits mailing list