[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2019-06-23 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya added a comment.

Minor suggestion, you may want to update http://clang.llvm.org/cxx_status.html 
page for "typename optional in more contexts" with in this change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53847/new/

https://reviews.llvm.org/D53847



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63381: Allow copy/move assignment operator to be coroutine as per N4775

2019-06-19 Thread Vivek Pandya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363804: Allow copy/move assignment operator to be coroutine 
as per N4775 (authored by vivekvpandya, committed by ).
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D63381?vs=204934&id=205581#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63381/new/

https://reviews.llvm.org/D63381

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaCoroutine.cpp
  cfe/trunk/test/SemaCXX/coroutines.cpp


Index: cfe/trunk/test/SemaCXX/coroutines.cpp
===
--- cfe/trunk/test/SemaCXX/coroutines.cpp
+++ cfe/trunk/test/SemaCXX/coroutines.cpp
@@ -296,18 +296,17 @@
   ~CtorDtor() {
 co_return 0; // expected-error {{'co_return' cannot be used in a 
destructor}}
   }
-  // FIXME: The spec says this is ill-formed.
   void operator=(CtorDtor&) {
-co_yield 0; // expected-error {{'co_yield' cannot be used in a copy 
assignment operator}}
+co_yield 0; // OK.
   }
   void operator=(CtorDtor const &) {
-co_yield 0; // expected-error {{'co_yield' cannot be used in a copy 
assignment operator}}
+co_yield 0; // OK.
   }
   void operator=(CtorDtor &&) {
-co_await a; // expected-error {{'co_await' cannot be used in a move 
assignment operator}}
+co_await a; // OK.
   }
   void operator=(CtorDtor const &&) {
-co_await a; // expected-error {{'co_await' cannot be used in a move 
assignment operator}}
+co_await a; // OK.
   }
   void operator=(int) {
 co_await a; // OK. Not a special member
Index: cfe/trunk/lib/Sema/SemaCoroutine.cpp
===
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp
@@ -204,8 +204,6 @@
   enum InvalidFuncDiag {
 DiagCtor = 0,
 DiagDtor,
-DiagCopyAssign,
-DiagMoveAssign,
 DiagMain,
 DiagConstexpr,
 DiagAutoRet,
@@ -219,23 +217,15 @@
 return false;
   };
 
-  // Diagnose when a constructor, destructor, copy/move assignment operator,
+  // Diagnose when a constructor, destructor
   // or the function 'main' are declared as a coroutine.
   auto *MD = dyn_cast(FD);
-  // [class.ctor]p6: "A constructor shall not be a coroutine."
+  // [class.ctor]p11: "A constructor shall not be a coroutine."
   if (MD && isa(MD))
 return DiagInvalid(DiagCtor);
   // [class.dtor]p17: "A destructor shall not be a coroutine."
   else if (MD && isa(MD))
 return DiagInvalid(DiagDtor);
-  // N4499 [special]p6: "A special member function shall not be a coroutine."
-  // Per C++ [special]p1, special member functions are the "default 
constructor,
-  // copy constructor and copy assignment operator, move constructor and move
-  // assignment operator, and destructor."
-  else if (MD && MD->isCopyAssignmentOperator())
-return DiagInvalid(DiagCopyAssign);
-  else if (MD && MD->isMoveAssignmentOperator())
-return DiagInvalid(DiagMoveAssign);
   // [basic.start.main]p3: "The function main shall not be a coroutine."
   else if (FD->isMain())
 return DiagInvalid(DiagMain);
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9432,9 +9432,9 @@
   "'%0' cannot be used outside a function">;
 def err_coroutine_invalid_func_context : Error<
   "'%1' cannot be used in %select{a constructor|a destructor"
-  "|a copy assignment operator|a move assignment operator|the 'main' function"
-  "|a constexpr function|a function with a deduced return type"
-  "|a varargs function|a consteval function}0">;
+  "|the 'main' function|a constexpr function"
+  "|a function with a deduced return type|a varargs function"
+  "|a consteval function}0">;
 def err_implied_coroutine_type_not_found : Error<
   "%0 type was not found; include  before defining "
   "a coroutine">;


Index: cfe/trunk/test/SemaCXX/coroutines.cpp
===
--- cfe/trunk/test/SemaCXX/coroutines.cpp
+++ cfe/trunk/test/SemaCXX/coroutines.cpp
@@ -296,18 +296,17 @@
   ~CtorDtor() {
 co_return 0; // expected-error {{'co_return' cannot be used in a destructor}}
   }
-  // FIXME: The spec says this is ill-formed.
   void operator=(CtorDtor&) {
-co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}}
+co_yield 0; // OK.
   }
   void operator=(CtorDtor const &) {
-co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}}
+co_yield 0; // OK.
   }
   void operator=(CtorDtor &&) {
-co_await a; // expected-error {{'co_await' cannot be used in a move assignment operator}}
+co_await a; // OK.
   }
   void operator=(CtorDtor const &&) {
-co_await a;

[PATCH] D63381: Allow copy/move assignment operator to be coroutine as per N4775

2019-06-18 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya added a comment.

Ping!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63381/new/

https://reviews.llvm.org/D63381



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33514: [WIP] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-13 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 115086.
vivekvpandya added a comment.

Added method to detach unique_ptr from LLVMContext.


https://reviews.llvm.org/D33514

Files:
  include/llvm/Analysis/OptimizationDiagnosticInfo.h
  include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
  include/llvm/IR/DiagnosticHandler.h
  include/llvm/IR/DiagnosticInfo.h
  include/llvm/IR/LLVMContext.h
  include/llvm/LTO/Config.h
  include/llvm/LTO/legacy/LTOCodeGenerator.h
  lib/IR/CMakeLists.txt
  lib/IR/Core.cpp
  lib/IR/DiagnosticHandler.cpp
  lib/IR/DiagnosticInfo.cpp
  lib/IR/LLVMContext.cpp
  lib/IR/LLVMContextImpl.cpp
  lib/IR/LLVMContextImpl.h
  lib/LTO/LTOCodeGenerator.cpp
  lib/Transforms/Scalar/GVN.cpp
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/GVN/opt-remarks.ll
  tools/llc/llc.cpp
  tools/llvm-dis/llvm-dis.cpp
  tools/llvm-link/llvm-link.cpp
  tools/llvm-lto/llvm-lto.cpp
  tools/lto/lto.cpp

Index: tools/lto/lto.cpp
===
--- tools/lto/lto.cpp
+++ tools/lto/lto.cpp
@@ -75,20 +75,23 @@
 
 static LLVMContext *LTOContext = nullptr;
 
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  if (DI.getSeverity() != DS_Error) {
-DiagnosticPrinterRawOStream DP(errs());
-DI.print(DP);
-errs() << '\n';
-return;
-  }
-  sLastErrorString = "";
-  {
-raw_string_ostream Stream(sLastErrorString);
-DiagnosticPrinterRawOStream DP(Stream);
-DI.print(DP);
+struct LTOToolDiagnosticHandler : public DiagnosticHandler {
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+if (DI.getSeverity() != DS_Error) {
+  DiagnosticPrinterRawOStream DP(errs());
+  DI.print(DP);
+  errs() << '\n';
+  return true;
+}
+sLastErrorString = "";
+{
+  raw_string_ostream Stream(sLastErrorString);
+  DiagnosticPrinterRawOStream DP(Stream);
+  DI.print(DP);
+}
+return true;
   }
-}
+};
 
 // Initialize the configured targets if they have not been initialized.
 static void lto_initialize() {
@@ -108,7 +111,8 @@
 
 static LLVMContext Context;
 LTOContext = &Context;
-LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+LTOContext->setDiagnosticHandler(
+llvm::make_unique(), true);
 initialized = true;
   }
 }
@@ -274,7 +278,8 @@
 
   // Create a local context. Ownership will be transferred to LTOModule.
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
 
   ErrorOr> M = LTOModule::createInLocalContext(
   std::move(Context), mem, length, Options, StringRef(path));
Index: tools/llvm-lto/llvm-lto.cpp
===
--- tools/llvm-lto/llvm-lto.cpp
+++ tools/llvm-lto/llvm-lto.cpp
@@ -235,34 +235,40 @@
 }
 
 static std::string CurrentActivity;
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  raw_ostream &OS = errs();
-  OS << "llvm-lto: ";
-  switch (DI.getSeverity()) {
-  case DS_Error:
-OS << "error";
-break;
-  case DS_Warning:
-OS << "warning";
-break;
-  case DS_Remark:
-OS << "remark";
-break;
-  case DS_Note:
-OS << "note";
-break;
-  }
-  if (!CurrentActivity.empty())
-OS << ' ' << CurrentActivity;
-  OS << ": ";
-
-  DiagnosticPrinterRawOStream DP(OS);
-  DI.print(DP);
-  OS << '\n';
 
-  if (DI.getSeverity() == DS_Error)
-exit(1);
-}
+namespace {
+  struct LLVMLTODiagnosticHandler : public DiagnosticHandler {
+bool handleDiagnostics(const DiagnosticInfo &DI) override {
+  raw_ostream &OS = errs();
+  OS << "llvm-lto: ";
+  switch (DI.getSeverity()) {
+  case DS_Error:
+OS << "error";
+break;
+  case DS_Warning:
+OS << "warning";
+break;
+  case DS_Remark:
+OS << "remark";
+break;
+  case DS_Note:
+OS << "note";
+break;
+  }
+  if (!CurrentActivity.empty())
+OS << ' ' << CurrentActivity;
+  OS << ": ";
+  
+  DiagnosticPrinterRawOStream DP(OS);
+  DI.print(DP);
+  OS << '\n';
+  
+  if (DI.getSeverity() == DS_Error)
+exit(1);
+  return true;
+}
+  };
+  }
 
 static void error(const Twine &Msg) {
   errs() << "llvm-lto: " << Msg << '\n';
@@ -293,7 +299,8 @@
   Buffer = std::move(BufferOrErr.get());
   CurrentActivity = ("loading file '" + Path + "'").str();
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
   ErrorOr> Ret = LTOModule::createInLocalContext(
   std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(),
   Options, Path);
@@ -837,7 +844,8 @@
   unsigned BaseArg = 0;
 
   LLVMContext Context;
-  Co

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-13 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 115085.
vivekvpandya added a comment.

update


https://reviews.llvm.org/D37196

Files:
  lib/CodeGen/CodeGenAction.cpp


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -46,6 +46,31 @@
 using namespace llvm;
 
 namespace clang {
+  class BackendConsumer;
+  class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
+: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+  
+bool handleDiagnostics(const DiagnosticInfo &DI) override;
+bool isAnalysisRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
+  CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+}
+bool isMissedOptRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkMissedPattern &&
+  CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+}
+bool isPassedOptRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkPattern &&
+  CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+}
+  
+  private:
+const CodeGenOptions &CodeGenOpts;
+BackendConsumer *BackendCon;
+  };
+
   class BackendConsumer : public ASTConsumer {
 using LinkModule = CodeGenAction::LinkModule;
 
@@ -224,10 +249,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  std::unique_ptr OldDiagnosticHandler =
   Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  Ctx.setDiagnosticHandler(llvm::make_unique(
+CodeGenOpts, this));
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +289,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -299,11 +324,6 @@
   ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
 }
 
-static void DiagnosticHandler(const llvm::DiagnosticInfo &DI,
-  void *Context) {
-  ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
-}
-
 /// Get the best possible source location to represent a diagnostic that
 /// may have associated debug info.
 const FullSourceLoc
@@ -343,6 +363,11 @@
   void BackendConsumer::anchor() {}
 }
 
+bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) {
+  BackendCon->DiagnosticHandlerImpl(DI);
+  return true;
+}
+
 /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr
 /// buffer to be a valid FullSourceLoc.
 static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -46,6 +46,31 @@
 using namespace llvm;
 
 namespace clang {
+  class BackendConsumer;
+  class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
+: CodeGenOpts(CGOpts), BackendCon(BCon) {}
+  
+bool handleDiagnostics(const DiagnosticInfo &DI) override;
+bool isAnalysisRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
+  CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+}
+bool isMissedOptRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkMissedPattern &&
+  CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+}
+bool isPassedOptRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkPattern &&
+  CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+}
+  
+  private:
+const CodeGenOptions &CodeGenOpts;
+BackendConsumer *BackendCon;
+  };
+
   class BackendConsumer : public ASTConsumer {
 using LinkModule = CodeGenAction::LinkModule;
 
@@ -224,10 +249,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  std::unique_ptr OldDiagnosticHandler =
   Ctx.getD

[PATCH] D33514: [WIP] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-12 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 114869.
vivekvpandya marked 3 inline comments as done.
vivekvpandya added a comment.

Update.


https://reviews.llvm.org/D33514

Files:
  include/llvm/Analysis/OptimizationDiagnosticInfo.h
  include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
  include/llvm/IR/DiagnosticHandler.h
  include/llvm/IR/DiagnosticInfo.h
  include/llvm/IR/LLVMContext.h
  include/llvm/LTO/Config.h
  include/llvm/LTO/legacy/LTOCodeGenerator.h
  lib/IR/CMakeLists.txt
  lib/IR/Core.cpp
  lib/IR/DiagnosticHandler.cpp
  lib/IR/DiagnosticInfo.cpp
  lib/IR/LLVMContext.cpp
  lib/IR/LLVMContextImpl.cpp
  lib/IR/LLVMContextImpl.h
  lib/LTO/LTOCodeGenerator.cpp
  lib/Transforms/Scalar/GVN.cpp
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/GVN/opt-remarks.ll
  tools/llc/llc.cpp
  tools/llvm-dis/llvm-dis.cpp
  tools/llvm-link/llvm-link.cpp
  tools/llvm-lto/llvm-lto.cpp
  tools/lto/lto.cpp

Index: tools/lto/lto.cpp
===
--- tools/lto/lto.cpp
+++ tools/lto/lto.cpp
@@ -75,20 +75,23 @@
 
 static LLVMContext *LTOContext = nullptr;
 
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  if (DI.getSeverity() != DS_Error) {
-DiagnosticPrinterRawOStream DP(errs());
-DI.print(DP);
-errs() << '\n';
-return;
-  }
-  sLastErrorString = "";
-  {
-raw_string_ostream Stream(sLastErrorString);
-DiagnosticPrinterRawOStream DP(Stream);
-DI.print(DP);
+struct LTOToolDiagnosticHandler : public DiagnosticHandler {
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+if (DI.getSeverity() != DS_Error) {
+  DiagnosticPrinterRawOStream DP(errs());
+  DI.print(DP);
+  errs() << '\n';
+  return true;
+}
+sLastErrorString = "";
+{
+  raw_string_ostream Stream(sLastErrorString);
+  DiagnosticPrinterRawOStream DP(Stream);
+  DI.print(DP);
+}
+return true;
   }
-}
+};
 
 // Initialize the configured targets if they have not been initialized.
 static void lto_initialize() {
@@ -108,7 +111,8 @@
 
 static LLVMContext Context;
 LTOContext = &Context;
-LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+LTOContext->setDiagnosticHandler(
+llvm::make_unique(), true);
 initialized = true;
   }
 }
@@ -274,7 +278,8 @@
 
   // Create a local context. Ownership will be transferred to LTOModule.
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
 
   ErrorOr> M = LTOModule::createInLocalContext(
   std::move(Context), mem, length, Options, StringRef(path));
Index: tools/llvm-lto/llvm-lto.cpp
===
--- tools/llvm-lto/llvm-lto.cpp
+++ tools/llvm-lto/llvm-lto.cpp
@@ -235,34 +235,40 @@
 }
 
 static std::string CurrentActivity;
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  raw_ostream &OS = errs();
-  OS << "llvm-lto: ";
-  switch (DI.getSeverity()) {
-  case DS_Error:
-OS << "error";
-break;
-  case DS_Warning:
-OS << "warning";
-break;
-  case DS_Remark:
-OS << "remark";
-break;
-  case DS_Note:
-OS << "note";
-break;
-  }
-  if (!CurrentActivity.empty())
-OS << ' ' << CurrentActivity;
-  OS << ": ";
-
-  DiagnosticPrinterRawOStream DP(OS);
-  DI.print(DP);
-  OS << '\n';
 
-  if (DI.getSeverity() == DS_Error)
-exit(1);
-}
+namespace {
+  struct LLVMLTODiagnosticHandler : public DiagnosticHandler {
+bool handleDiagnostics(const DiagnosticInfo &DI) override {
+  raw_ostream &OS = errs();
+  OS << "llvm-lto: ";
+  switch (DI.getSeverity()) {
+  case DS_Error:
+OS << "error";
+break;
+  case DS_Warning:
+OS << "warning";
+break;
+  case DS_Remark:
+OS << "remark";
+break;
+  case DS_Note:
+OS << "note";
+break;
+  }
+  if (!CurrentActivity.empty())
+OS << ' ' << CurrentActivity;
+  OS << ": ";
+  
+  DiagnosticPrinterRawOStream DP(OS);
+  DI.print(DP);
+  OS << '\n';
+  
+  if (DI.getSeverity() == DS_Error)
+exit(1);
+  return true;
+}
+  };
+  }
 
 static void error(const Twine &Msg) {
   errs() << "llvm-lto: " << Msg << '\n';
@@ -293,7 +299,8 @@
   Buffer = std::move(BufferOrErr.get());
   CurrentActivity = ("loading file '" + Path + "'").str();
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
   ErrorOr> Ret = LTOModule::createInLocalContext(
   std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(),
   Options, Path);
@@ -837,7 +844,8 @@
   unsigned BaseArg = 0;
 
   LLVMContext Context;
- 

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-12 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya added a comment.

Why? That was inside BackendConsumer.

I was getting incomplete type error.

You can just save the old DiagHandler object instead.
I don't think now we need to do that as per my understanding CodeGen i.e 
emitting LLVM IR is last phase in clang which will pass control to LLVMContext. 
LLVMContext will have Base class of DiagnosticHandler which will not handle 
diagnostic and return false so LLVMContext::diagnose() will print diagnostic 
with

DiagnosticPrinterRawOStream DP(errs());

  errs() << getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
  DI.print(DP);
  errs() << "\n";

and clang's diagnostic handler also does similar thing so if we keep 
ClangDiagnosticHandler pointer in LLVMContext it should not break.


https://reviews.llvm.org/D37196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33514: [WIP] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-11 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 114647.
vivekvpandya marked 8 inline comments as done.

https://reviews.llvm.org/D33514

Files:
  include/llvm/Analysis/OptimizationDiagnosticInfo.h
  include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
  include/llvm/IR/DiagnosticHandler.h
  include/llvm/IR/DiagnosticInfo.h
  include/llvm/IR/LLVMContext.h
  include/llvm/LTO/Config.h
  include/llvm/LTO/legacy/LTOCodeGenerator.h
  lib/IR/CMakeLists.txt
  lib/IR/Core.cpp
  lib/IR/DiagnosticHandler.cpp
  lib/IR/DiagnosticInfo.cpp
  lib/IR/LLVMContext.cpp
  lib/IR/LLVMContextImpl.cpp
  lib/IR/LLVMContextImpl.h
  lib/LTO/LTOCodeGenerator.cpp
  lib/Transforms/Scalar/GVN.cpp
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/GVN/opt-remarks.ll
  tools/llc/llc.cpp
  tools/llvm-dis/llvm-dis.cpp
  tools/llvm-link/llvm-link.cpp
  tools/llvm-lto/llvm-lto.cpp
  tools/lto/lto.cpp

Index: tools/lto/lto.cpp
===
--- tools/lto/lto.cpp
+++ tools/lto/lto.cpp
@@ -75,20 +75,23 @@
 
 static LLVMContext *LTOContext = nullptr;
 
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  if (DI.getSeverity() != DS_Error) {
-DiagnosticPrinterRawOStream DP(errs());
-DI.print(DP);
-errs() << '\n';
-return;
-  }
-  sLastErrorString = "";
-  {
-raw_string_ostream Stream(sLastErrorString);
-DiagnosticPrinterRawOStream DP(Stream);
-DI.print(DP);
+struct LTOToolDiagnosticHandler : public DiagnosticHandler {
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+if (DI.getSeverity() != DS_Error) {
+  DiagnosticPrinterRawOStream DP(errs());
+  DI.print(DP);
+  errs() << '\n';
+  return true;
+}
+sLastErrorString = "";
+{
+  raw_string_ostream Stream(sLastErrorString);
+  DiagnosticPrinterRawOStream DP(Stream);
+  DI.print(DP);
+}
+return true;
   }
-}
+};
 
 // Initialize the configured targets if they have not been initialized.
 static void lto_initialize() {
@@ -108,7 +111,8 @@
 
 static LLVMContext Context;
 LTOContext = &Context;
-LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+LTOContext->setDiagnosticHandler(
+llvm::make_unique(), true);
 initialized = true;
   }
 }
@@ -274,7 +278,8 @@
 
   // Create a local context. Ownership will be transferred to LTOModule.
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
 
   ErrorOr> M = LTOModule::createInLocalContext(
   std::move(Context), mem, length, Options, StringRef(path));
Index: tools/llvm-lto/llvm-lto.cpp
===
--- tools/llvm-lto/llvm-lto.cpp
+++ tools/llvm-lto/llvm-lto.cpp
@@ -235,34 +235,40 @@
 }
 
 static std::string CurrentActivity;
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
-  raw_ostream &OS = errs();
-  OS << "llvm-lto: ";
-  switch (DI.getSeverity()) {
-  case DS_Error:
-OS << "error";
-break;
-  case DS_Warning:
-OS << "warning";
-break;
-  case DS_Remark:
-OS << "remark";
-break;
-  case DS_Note:
-OS << "note";
-break;
-  }
-  if (!CurrentActivity.empty())
-OS << ' ' << CurrentActivity;
-  OS << ": ";
-
-  DiagnosticPrinterRawOStream DP(OS);
-  DI.print(DP);
-  OS << '\n';
 
-  if (DI.getSeverity() == DS_Error)
-exit(1);
-}
+namespace {
+  struct LLVMLTODiagnosticHandler : public DiagnosticHandler {
+bool handleDiagnostics(const DiagnosticInfo &DI) override {
+  raw_ostream &OS = errs();
+  OS << "llvm-lto: ";
+  switch (DI.getSeverity()) {
+  case DS_Error:
+OS << "error";
+break;
+  case DS_Warning:
+OS << "warning";
+break;
+  case DS_Remark:
+OS << "remark";
+break;
+  case DS_Note:
+OS << "note";
+break;
+  }
+  if (!CurrentActivity.empty())
+OS << ' ' << CurrentActivity;
+  OS << ": ";
+  
+  DiagnosticPrinterRawOStream DP(OS);
+  DI.print(DP);
+  OS << '\n';
+  
+  if (DI.getSeverity() == DS_Error)
+exit(1);
+  return true;
+}
+  };
+  }
 
 static void error(const Twine &Msg) {
   errs() << "llvm-lto: " << Msg << '\n';
@@ -293,7 +299,8 @@
   Buffer = std::move(BufferOrErr.get());
   CurrentActivity = ("loading file '" + Path + "'").str();
   std::unique_ptr Context = llvm::make_unique();
-  Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+  Context->setDiagnosticHandler(llvm::make_unique(),
+true);
   ErrorOr> Ret = LTOModule::createInLocalContext(
   std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(),
   Options, Path);
@@ -837,7 +844,8 @@
   unsigned BaseArg = 0;
 
   LLVMContext Context;
-  Context.setDiagnosticHandler(diagnostic

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-11 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 114645.
vivekvpandya added a comment.

Update


https://reviews.llvm.org/D37196

Files:
  lib/CodeGen/CodeGenAction.cpp


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,6 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,8 +260,6 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
-
   if (OptRecordFile)
 OptRecordFile->keep();
 }
@@ -299,11 +293,6 @@
   ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
 }
 
-static void DiagnosticHandler(const llvm::DiagnosticInfo &DI,
-  void *Context) {
-  ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
-}
-
 /// Get the best possible source location to represent a diagnostic that
 /// may have associated debug info.
 const FullSourceLoc
@@ -756,6 +745,33 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
+
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+BackendCon->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
+CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+  }
+  bool isMissedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkMissedPattern &&
+CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+  }
+  bool isPassedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkPattern &&
+CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+  }
+
+private:
+  const CodeGenOptions &CodeGenOpts;
+  BackendConsumer *BackendCon;
+};
+
 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
   OwnsVMContext(!_VMContext) {}
@@ -853,7 +869,8 @@
   CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
   std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
   BEConsumer = Result.get();
-
+  VMContext->setDiagnosticHandler(llvm::make_unique(
+  CI.getCodeGenOpts(), Result.get()));
   // Enable generating macro debug info only when debug info is not disabled 
and
   // also macro debug info is enabled.
   if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,6 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,8 +260,6 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
-
   if (OptRecordFile)
 OptRecordFile->keep();
 }
@@ -299,11 +293,6 @@
   ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
 }
 
-static void DiagnosticHandler(const llvm::DiagnosticInfo &DI,
-  void *Context) {
-  ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
-}
-
 /// Get the best possible source location to represent a diagnostic that
 /// may have associated debug info.
 const FullSourceLoc
@@ -756,6 +745,33 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
+  : CodeGenOpts(CGOpts), BackendCon(BCon) {}
+
+  bool handleDiagnostics(const D

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-11 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya marked an inline comment as done.
vivekvpandya added inline comments.



Comment at: lib/CodeGen/CodeGenAction.cpp:882-883
   BEConsumer = Result.get();
-
+  VMContext->setDiagnosticHandler(llvm::make_unique(
+  CI.getCodeGenOpts(), Result.get()));
   // Enable generating macro debug info only when debug info is not disabled 
and

anemet wrote:
> Any reason you moved where we set this up?
 

  #  At older place I was not able to define ClangDiagnosticHandler class as it 
will require definition of BackendComsumer and vice versa.
  # and this seems to be appropriate place to create and tie DiagnosticHandler 
to LLVMContext

 
But I am not sure about why old diagnostic handler was tied back to  context 
that is why I wanted someone from clang to look at this.




https://reviews.llvm.org/D37196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-09-05 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 113879.
vivekvpandya added a comment.

Clang-formated


https://reviews.llvm.org/D37196

Files:
  lib/CodeGen/CodeGenAction.cpp


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,32 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, void *DiagContext)
+  : DiagnosticHandler(DiagContext), CodeGenOpts(CGOpts) {}
+
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+((BackendConsumer *)DiagnosticContext)->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
+CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+  }
+  bool isMissedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkMissedPattern &&
+CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+  }
+  bool isPassedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkPattern &&
+CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+  }
+
+private:
+  const CodeGenOptions &CodeGenOpts;
+};
+
 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
   OwnsVMContext(!_VMContext) {}
@@ -853,7 +879,8 @@
   CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
   std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
   BEConsumer = Result.get();
-
+  VMContext->setDiagnosticHandler(llvm::make_unique(
+  CI.getCodeGenOpts(), Result.get()));
   // Enable generating macro debug info only when debug info is not disabled 
and
   // also macro debug info is enabled.
   if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,32 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, void *DiagContext)
+  : DiagnosticHandler(DiagContext), CodeGenOpts(CGOpts) {}
+
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+((BackendConsumer *)DiagnosticContext)->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkAnal

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-08-31 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya updated this revision to Diff 113434.
vivekvpandya added a comment.

Updated the patch! I don't think now we require to save OldDiagnosticHandler 
and context as we have ClangDiagnosticHandler class with creation of 
CreateASTConsumer, but I need some review.


https://reviews.llvm.org/D37196

Files:
  lib/CodeGen/CodeGenAction.cpp


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,31 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, void *DiagContext)
+: DiagnosticHandler(DiagContext), CodeGenOpts(CGOpts) {}
+
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+((BackendConsumer *)DiagnosticContext)->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkAnalysisPattern 
+&& CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+  }
+   bool isMissedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkMissedPattern 
+&& CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+  }
+   bool isPassedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkPattern 
+&& CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+  }
+  private:
+const CodeGenOptions &CodeGenOpts; 
+};
+
 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
   OwnsVMContext(!_VMContext) {}
@@ -853,7 +878,8 @@
   CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
   std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
   BEConsumer = Result.get();
-
+  VMContext->setDiagnosticHandler(
+llvm::make_unique(CI.getCodeGenOpts(), 
Result.get()));
   // Enable generating macro debug info only when debug info is not disabled 
and
   // also macro debug info is enabled.
   if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,31 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts, void *DiagContext)
+: DiagnosticHandler(DiagContext), CodeGenOpts(CGOpts) {}
+
+  bool handleDiagnostics(const DiagnosticInfo &DI) override {
+((BackendC

[PATCH] D37196: [Clang] Bug 32352 - Provide a way for OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks are enabled

2017-08-27 Thread Vivek Pandya via Phabricator via cfe-commits
vivekvpandya created this revision.
Herald added a subscriber: fhahn.

Clang changes related to Bug 32352 - Provide a way for 
OptimizationRemarkEmitter::allowExtraAnalysis to check if (specific) remarks 
are enabled


https://reviews.llvm.org/D37196

Files:
  lib/CodeGen/CodeGenAction.cpp


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,30 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts) : CodeGenOpts(CGOpts) {
+  }
+  bool handleDiagnostics(const DiagnosticInfo &DI, void *Context) {
+((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.OptimizationRemarkAnalysisPattern 
+&& CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
+  }
+   bool isMissedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkMissedPattern 
+&& CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
+  }
+   bool isPassedOptRemarkEnable(const std::string &PassName) {
+return (CodeGenOpts.OptimizationRemarkPattern 
+&& CodeGenOpts.OptimizationRemarkPattern->match(PassName));
+  }
+  private:
+const CodeGenOptions &CodeGenOpts; 
+};
+
 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
   OwnsVMContext(!_VMContext) {}
@@ -853,7 +877,7 @@
   CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
   std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
   BEConsumer = Result.get();
-
+  
VMContext->setDiagnosticHandler(llvm::make_unique(CI.getCodeGenOpts()),
 Result.get());
   // Enable generating macro debug info only when debug info is not disabled 
and
   // also macro debug info is enabled.
   if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -224,10 +224,10 @@
   void *OldContext = Ctx.getInlineAsmDiagnosticContext();
   Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
 
-  LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
-  Ctx.getDiagnosticHandler();
-  void *OldDiagnosticContext = Ctx.getDiagnosticContext();
-  Ctx.setDiagnosticHandler(DiagnosticHandler, this);
+  //LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+  //Ctx.getDiagnosticHandler();
+ // void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ // Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
   if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
 Ctx.setDiagnosticsHotnessThreshold(
@@ -264,7 +264,7 @@
 
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
-  Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+  //Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
 
   if (OptRecordFile)
 OptRecordFile->keep();
@@ -756,6 +756,30 @@
 }
 #undef ComputeDiagID
 
+class ClangDiagnosticHandler final : public DiagnosticHandler {
+  public:
+  ClangDiagnosticHandler(const CodeGenOptions &CGOpts) : CodeGenOpts(CGOpts) {
+  }
+  bool handleDiagnostics(const DiagnosticInfo &DI, void *Context) {
+((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
+return true;
+  }
+  bool isAnalysisRemarkEnable(const std::string &PassName) {
+  return (CodeGenOpts.Optimization