Allow diagnostic handlers to check for optimization remarks.
authorDiego Novillo <dnovillo@google.com>
Wed, 16 Apr 2014 16:53:41 +0000 (16:53 +0000)
committerDiego Novillo <dnovillo@google.com>
Wed, 16 Apr 2014 16:53:41 +0000 (16:53 +0000)
Summary:
When optimization remarks are enabled via the driver flag -Rpass, we
should allow the FE diagnostic handler to check if the given pass name
needs a diagnostic.

We were unconditionally checking the pattern defined in opt's
-pass-remarks flag. This was causing the FE to not emit any diagnostics.

Reviewers: qcolombet

CC: llvm-commits
Differential Revision: http://reviews.llvm.org/D3362

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206400 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/LLVMContext.cpp

index bd87ef3ab6908eb077a6d833cea5a92092602198..588e1217bd45b30946898c5b38286f9f053ec55e 100644 (file)
@@ -130,6 +130,16 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
     pImpl->DiagnosticHandler(DI, pImpl->DiagnosticContext);
     return;
   }
+
+  // Optimization remarks are selective. They need to check whether
+  // the regexp pattern, passed via -pass-remarks, matches the name
+  // of the pass that is emitting the diagnostic. If there is no match,
+  // ignore the diagnostic and return.
+  if (DI.getKind() == llvm::DK_OptimizationRemark &&
+      !pImpl->optimizationRemarksEnabledFor(
+          cast<DiagnosticInfoOptimizationRemark>(DI).getPassName()))
+    return;
+
   // Otherwise, print the message with a prefix based on the severity.
   std::string MsgStorage;
   raw_string_ostream Stream(MsgStorage);
@@ -160,8 +170,7 @@ void LLVMContext::emitOptimizationRemark(const char *PassName,
                                          const Function &Fn,
                                          const DebugLoc &DLoc,
                                          const Twine &Msg) {
-  if (pImpl->optimizationRemarksEnabledFor(PassName))
-    diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
+  diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
 }
 
 //===----------------------------------------------------------------------===//