[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-09-17 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 292469.
djtodoro added a comment.

- Rebasing


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/verify-debug-info-preservation.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-original-di-preservation.py sample.json sample.html
 
+The `original-di-check` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fverify-debuginfo-preserve -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export=sample.json -g -O2 sample.c
+
 Using ``VerifyDIPreserve``
 ^^
 
Index: clang/test/Driver/verify-debug-info-preservation.c
===
--- /dev/null
+++ clang/test/Driver/verify-debug-info-preservation.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE %s
+
+// VERIFYDIPRESERVE: "-fverify-debuginfo-preserve"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve \
+// RUN: -Xclang -fverify-debuginfo-preserve-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE-JSON-EXPORT %s
+
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve"
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -835,6 +835,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDIPreservationVerify =
+  Args.hasArg(OPT_fverify_debuginfo_preserve);
+  // Ignore the option if the -fverify-debuginfo-preserve wasn't enabled.
+  if (Opts.EnableDIPreservationVerify &&
+  Args.hasArg(OPT_fverify_debuginfo_preserve_export)) {
+ Opts.DIBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fverify_debuginfo_preserve_export));
+  }
+
   Opts.ValueTrackingVariableLocations =
   Args.hasArg(OPT_fexperimental_debug_variable_locations);
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -82,6 +82,7 @@
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
+#include "llvm/Transforms/Utils/VerifyDIPreserve.h"
 #include 
 using namespace clang;
 using namespace llvm;
@@ -893,7 +894,17 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  VerifyDIPreserveCustomPassManager PerModulePasses;
+  DebugInfoPerPassMap DIPreservationMap;
+  if (CodeGenOpts.EnableDIPreservationVerify) {
+PerModulePasses.setVerifyDIPreserveMode(
+VerifyDIPreserveMode::OriginalDebugInfo);
+PerModulePasses.setDIPreservationMap(DIPreservationMap);
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setOrigDIVerifyBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3894,6 +3894,16 @@
 def fexperimental_debug_variable_locations : Flag<["-"],
 "fexperimental-debug-variable-locations">,
 HelpText<"Use experimental new value-tracking variable locations">;
+def fverify_debuginfo_preserve
+: Flag<["-"], "fverify-debuginfo-preserve">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">;
+def fverify_debuginfo_preserve_export
+: Joined<["-"], "fverify-debuginfo-preserve-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debug info (by testing original Debug Info) failures "
+   "into specified (JSON) file (should be abs path as we use "
+   "append mode to insert new JSON 

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-14 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 277781.
djtodoro added a comment.
Herald added a subscriber: dang.

- Rebase


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/Driver/debugify-each-original.c
===
--- /dev/null
+++ clang/test/Driver/debugify-each-original.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY %s
+
+// DEBUGIFY: "-fenable-debugify-each-original"
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \
+// RUN: -Xclang -fenable-debugify-original-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY-JSON-EXPORT %s
+
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-each-original"
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-original-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -867,7 +868,14 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  DebugifyCustomPassManager PerModulePasses;
+  if (CodeGenOpts.EnableDebugifyEachOriginal) {
+PerModulePasses.enableDebugifyEachOriginal();
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setDebugifyOriginalBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/CC1Options.td
===
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -389,6 +389,16 @@
 HelpText<"Prints debug information for the new pass manager">;
 def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">,
 HelpText<"Disables debug printing for the new pass manager">;
+def fenable_debugify_each_original
+: Flag<["-"], "fenable-debugify-each-original">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">;
+def fenable_debugify_original_export
+: Joined<["-"], "fenable-debugify-original-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debugify (by testing original Debug Info) failures into "
+   "specified (JSON) file (should be abs path as we use "
+   "append mode to insert new JSON 

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-08 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 276398.
djtodoro added a comment.

- Rebase on top of D83391 


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/Driver/debugify-each-original.c
===
--- /dev/null
+++ clang/test/Driver/debugify-each-original.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY %s
+
+// DEBUGIFY: "-fenable-debugify-each-original"
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \
+// RUN: -Xclang -fenable-debugify-original-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY-JSON-EXPORT %s
+
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-each-original"
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-original-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -867,7 +868,14 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  llvm::legacy::DebugifyCustomPassManager PerModulePasses;
+  if (CodeGenOpts.EnableDebugifyEachOriginal) {
+PerModulePasses.enableDebugifyEachOriginal();
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setDebugifyOriginalBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/CC1Options.td
===
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -389,6 +389,16 @@
 HelpText<"Prints debug information for the new pass manager">;
 def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">,
 HelpText<"Disables debug printing for the new pass manager">;
+def fenable_debugify_each_original
+: Flag<["-"], "fenable-debugify-each-original">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">;
+def fenable_debugify_original_export
+: Joined<["-"], "fenable-debugify-original-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debugify (by testing original Debug Info) failures into "
+   "specified (JSON) file (should be abs path as we use "
+   

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-08 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked an inline comment as done.
djtodoro added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:855
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:

djtodoro wrote:
> vsk wrote:
> > Please factor out OptCustomPassManager from opt and generalize it so it can 
> > be used by both opt and clang. That should help ensure that extensions and 
> > bug fixes are only made to one custom 'debugify' pass manager.
> I'll try that with the latest code. I remember I've tried it once, but I 
> ended up moving it into the IR library (since we need to link it within 
> legacy pass manager).
Hi @vsk, I've posted the patch as D83391. Thanks!


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-06 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked 2 inline comments as done.
djtodoro added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:855
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:

vsk wrote:
> Please factor out OptCustomPassManager from opt and generalize it so it can 
> be used by both opt and clang. That should help ensure that extensions and 
> bug fixes are only made to one custom 'debugify' pass manager.
I'll try that with the latest code. I remember I've tried it once, but I ended 
up moving it into the IR library (since we need to link it within legacy pass 
manager).



Comment at: clang/lib/CodeGen/BackendUtil.cpp:893
+
+  void enableDebugifyEachOriginal() { DebugifyEachOriginalEnabled = true; }
+

vsk wrote:
> I don't think the discussion from 'RFC: Introduce LLVM DI Checker utility' is 
> complete, and I'd ask that you split off changes for 'original mode' from 
> this patch until there's some consensus about what that mode should look like.
> 
> There are open questions about to what extent a new mode is needed (e.g., it 
> may be that the interesting questions compiler developers need to answer 
> about debug info loss are simpler to determine some other way (which is not 
> to say that that's true -- just that we haven't explored the space much 
> yet)). Or what its output should look like.
OK, I'll split off this and notify you/resend a message on the RFC.


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-05 Thread Vedant Kumar via Phabricator via cfe-commits
vsk requested changes to this revision.
vsk added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:855
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:

Please factor out OptCustomPassManager from opt and generalize it so it can be 
used by both opt and clang. That should help ensure that extensions and bug 
fixes are only made to one custom 'debugify' pass manager.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:893
+
+  void enableDebugifyEachOriginal() { DebugifyEachOriginalEnabled = true; }
+

I don't think the discussion from 'RFC: Introduce LLVM DI Checker utility' is 
complete, and I'd ask that you split off changes for 'original mode' from this 
patch until there's some consensus about what that mode should look like.

There are open questions about to what extent a new mode is needed (e.g., it 
may be that the interesting questions compiler developers need to answer about 
debug info loss are simpler to determine some other way (which is not to say 
that that's true -- just that we haven't explored the space much yet)). Or what 
its output should look like.


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-01 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked an inline comment as done.
djtodoro added inline comments.



Comment at: clang/test/Driver/debugify-each-original.c:9
+
+// RUN: rm -rf %t.json
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \

aprantl wrote:
> I think this is redundant?
It is, thanks!


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-01 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 274690.
djtodoro added a comment.

- Remove redundant line from the test


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/Driver/debugify-each-original.c
===
--- /dev/null
+++ clang/test/Driver/debugify-each-original.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY %s
+
+// DEBUGIFY: "-fenable-debugify-each-original"
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \
+// RUN: -Xclang -fenable-debugify-original-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY-JSON-EXPORT %s
+
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-each-original"
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-original-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIOriginalBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -851,6 +852,61 @@
   return true;
 }
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:
+  void add(Pass *P) override {
+bool WrapWithDebugifyOriginal = DebugifyEachOriginalEnabled &&
+!P->getAsImmutablePass() &&
+!isIRPrintingPass(P);
+if (!WrapWithDebugifyOriginal) {
+  PassManager::add(P);
+  return;
+}
+
+PassKind Kind = P->getPassKind();
+StringRef Name = P->getPassName();
+
+// TODO: Implement Debugify for LoopPass.
+switch (Kind) {
+case PT_Function:
+  PassManager::add(createDebugifyFunctionPass(
+  DebugifyMode::OriginalDebugInfo, Name, ));
+  PassManager::add(P);
+  PassManager::add(createCheckDebugifyFunctionPass(
+  false, Name, nullptr, DebugifyMode::OriginalDebugInfo,
+  , getDebugifyEachOriginalPath()));
+  break;
+case PT_Module:
+  PassManager::add(createDebugifyModulePass(DebugifyMode::OriginalDebugInfo,
+Name, ));
+  PassManager::add(P);
+  PassManager::add(createCheckDebugifyModulePass(
+  false, Name, nullptr, DebugifyMode::OriginalDebugInfo,
+  , getDebugifyEachOriginalPath()));
+  break;
+default:
+  PassManager::add(P);
+  break;
+}
+  }
+
+  void enableDebugifyEachOriginal() { DebugifyEachOriginalEnabled = true; }
+
+  void
+  setDIOriginalBugsReportFilePath(StringRef 

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-30 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/debugify-each-original.c:9
+
+// RUN: rm -rf %t.json
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \

I think this is redundant?


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-30 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 274433.
djtodoro added a comment.

- Add the Driver test
- Remove the old high level test in order to avoid troubles when someone 
updates an LLVM pass with the impact on Debugify output (e.g. a new debug info 
bugs)
- clang-formatted


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/Driver/debugify-each-original.c
===
--- /dev/null
+++ clang/test/Driver/debugify-each-original.c
@@ -0,0 +1,15 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY %s
+
+// DEBUGIFY: "-fenable-debugify-each-original"
+
+// RUN: rm -rf %t.json
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \
+// RUN: -Xclang -fenable-debugify-original-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY-JSON-EXPORT %s
+
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-each-original"
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-original-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIOriginalBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -851,6 +852,61 @@
   return true;
 }
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:
+  void add(Pass *P) override {
+bool WrapWithDebugifyOriginal = DebugifyEachOriginalEnabled &&
+!P->getAsImmutablePass() &&
+!isIRPrintingPass(P);
+if (!WrapWithDebugifyOriginal) {
+  PassManager::add(P);
+  return;
+}
+
+PassKind Kind = P->getPassKind();
+StringRef Name = P->getPassName();
+
+// TODO: Implement Debugify for LoopPass.
+switch (Kind) {
+case PT_Function:
+  PassManager::add(createDebugifyFunctionPass(
+  DebugifyMode::OriginalDebugInfo, Name, ));
+  PassManager::add(P);
+  PassManager::add(createCheckDebugifyFunctionPass(
+  false, Name, nullptr, DebugifyMode::OriginalDebugInfo,
+  , getDebugifyEachOriginalPath()));
+  break;
+case PT_Module:
+  PassManager::add(createDebugifyModulePass(DebugifyMode::OriginalDebugInfo,
+Name, ));
+  PassManager::add(P);
+  PassManager::add(createCheckDebugifyModulePass(
+  false, Name, nullptr, DebugifyMode::OriginalDebugInfo,
+  , getDebugifyEachOriginalPath()));
+  break;
+default:
+ 

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-30 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked an inline comment as done.
djtodoro added inline comments.



Comment at: clang/test/DebugInfo/debugify-each-original.c:16
+// CHECK: Force set function attributes: {{.*}}
+// CHECK-NEXT: Infer set function attributes: {{.*}}
+// CHECK-NEXT: Interprocedural Sparse Conditional Constant Propagation: {{.*}}

aprantl wrote:
> I think this is still implicitly hardcoding the pass pipeline just through 
> the order of CHECK lines. If there were a way to dump the flags Clang is 
> passing to LLVM and check that, or get the pass manager to dump its 
> configuration, that would be better. I'm not sure if there is such an 
> affordance.
I see... It is hard to test it that way, but as far as I can see, it is enough 
to test only the `Driver` in situations like this, so I am adding a new test 
case and getting rid of this one.


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-29 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/test/DebugInfo/debugify-each-original.c:16
+// CHECK: Force set function attributes: {{.*}}
+// CHECK-NEXT: Infer set function attributes: {{.*}}
+// CHECK-NEXT: Interprocedural Sparse Conditional Constant Propagation: {{.*}}

I think this is still implicitly hardcoding the pass pipeline just through the 
order of CHECK lines. If there were a way to dump the flags Clang is passing to 
LLVM and check that, or get the pass manager to dump its configuration, that 
would be better. I'm not sure if there is such an affordance.


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-29 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked an inline comment as done.
djtodoro added inline comments.



Comment at: clang/test/DebugInfo/debugify-each-original.c:57
+// CHECK-NEXT: Hoist/decompose integer division and remainder: PASS
+// CHECK-NEXT: Simplify the CFG: PASS

aprantl wrote:
> aprantl wrote:
> > We probably shouldn't check the effects of LLVM passes in the Clang test 
> > suite. When someone breaks one of those LLVM passes and that shouldn't 
> > cause an error in the Clang *frontend* test suite. It's sufficient to check 
> > that the pass is passed on to LLVM here. The operation of it should be 
> > checked either in LLVM or in an end-to-end test, e.g., inside 
> > debug-info-tests.
> I probably should emphasize that an end-to-end test will probably just cause 
> us trouble: Someone will make an unrelated change to a pass, that pushes a 
> subsequent pass into a behavior that doesn't pass the debugify verifier, and 
> now the author of the unrelated patch is on the hook to fix that other pass. 
> I think that will make everyone unhappy. Maybe it should be treated more like 
> the debug info statistics?
@aprantl Thanks for your comments!

I agree with this... I refactored the test a bit, please take look.

>Maybe it should be treated more like the debug info statistics?
The final goal of this is to be used either from the python script that should 
process the JSON objects (shared within previous patch), or the JSON objects 
could be used from 
http://green.lab.llvm.org/green/view/LLDB/job/clang-3.4-debuginfo-statistics/ 
as well with some additional (groovy) scripts.



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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-29 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 274054.
djtodoro added a comment.

-Update the test


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/DebugInfo/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/DebugInfo/debugify-each-original.c
===
--- /dev/null
+++ clang/test/DebugInfo/debugify-each-original.c
@@ -0,0 +1,61 @@
+// Ensure that we tested each pass with the feature, but we do not
+// check the final result here. It is up to LLVM test suite to check the real
+// logic of the functionality.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -emit-llvm -S \
+// RUN: -O1 -o - %s 2>&1 | FileCheck %s
+
+int main()
+{
+  int x = 1;
+  int y = 2;
+  return x + y;
+}
+
+// CHECK: Force set function attributes: {{.*}}
+// CHECK-NEXT: Infer set function attributes: {{.*}}
+// CHECK-NEXT: Interprocedural Sparse Conditional Constant Propagation: {{.*}}
+// CHECK-NEXT: Called Value Propagation: {{.*}}
+// CHECK-NEXT: Global Variable Optimizer: {{.*}}
+// CHECK-NEXT: Promote Memory to Register: {{.*}}
+// CHECK-NEXT: Dead Argument Elimination: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Globals Alias Analysis: {{.*}}
+// CHECK-NEXT: SROA: {{.*}}
+// CHECK-NEXT: Early CSE w/ MemorySSA: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: Conditionally eliminate dead library calls: {{.*}}
+// CHECK-NEXT: PGOMemOPSize: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Reassociate expressions: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: MemCpy Optimization: {{.*}}
+// CHECK-NEXT: Sparse Conditional Constant Propagation: {{.*}}
+// CHECK-NEXT: Bit-Tracking Dead Code Elimination: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: Aggressive Dead Code Elimination: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: A No-Op Barrier {{.*}}: {{.*}}
+// CHECK-NEXT: Deduce function attributes in RPO: {{.*}}
+// CHECK-NEXT: Global Variable Optimizer: {{.*}}
+// CHECK-NEXT: Dead Global Elimination: {{.*}}
+// CHECK-NEXT: Globals Alias Analysis: {{.*}}
+// CHECK-NEXT: Float to int: {{.*}}
+// CHECK-NEXT: Lower constant intrinsics: {{.*}}
+// CHECK-NEXT: Loop Distribution: {{.*}}
+// CHECK-NEXT: Loop Vectorization: {{.*}}
+// CHECK-NEXT: Loop Load Elimination: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
+// CHECK-NEXT: Optimize scalar/vector ops: {{.*}}
+// CHECK-NEXT: Combine redundant instructions: {{.*}}
+// CHECK-NEXT: Warn about non-applied transformations: {{.*}}
+// CHECK-NEXT: Alignment from assumptions: {{.*}}
+// CHECK-NEXT: Strip Unused Function Prototypes: {{.*}}
+// CHECK-NEXT: Remove redundant instructions: {{.*}}
+// CHECK-NEXT: Hoist/decompose integer division and remainder: {{.*}}
+// CHECK-NEXT: Simplify the CFG: {{.*}}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIOriginalBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = 

[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-26 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/test/DebugInfo/debugify-each-original.c:57
+// CHECK-NEXT: Hoist/decompose integer division and remainder: PASS
+// CHECK-NEXT: Simplify the CFG: PASS

aprantl wrote:
> We probably shouldn't check the effects of LLVM passes in the Clang test 
> suite. When someone breaks one of those LLVM passes and that shouldn't cause 
> an error in the Clang *frontend* test suite. It's sufficient to check that 
> the pass is passed on to LLVM here. The operation of it should be checked 
> either in LLVM or in an end-to-end test, e.g., inside debug-info-tests.
I probably should emphasize that an end-to-end test will probably just cause us 
trouble: Someone will make an unrelated change to a pass, that pushes a 
subsequent pass into a behavior that doesn't pass the debugify verifier, and 
now the author of the unrelated patch is on the hook to fix that other pass. I 
think that will make everyone unhappy. Maybe it should be treated more like the 
debug info statistics?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-26 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/test/DebugInfo/debugify-each-original.c:57
+// CHECK-NEXT: Hoist/decompose integer division and remainder: PASS
+// CHECK-NEXT: Simplify the CFG: PASS

We probably shouldn't check the effects of LLVM passes in the Clang test suite. 
When someone breaks one of those LLVM passes and that shouldn't cause an error 
in the Clang *frontend* test suite. It's sufficient to check that the pass is 
passed on to LLVM here. The operation of it should be checked either in LLVM or 
in an end-to-end test, e.g., inside debug-info-tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-06-25 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro created this revision.
djtodoro added reviewers: vsk, aprantl, dblaikie, probinson.
djtodoro added projects: debug-info, LLVM.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.
djtodoro added a parent revision: D82546: [Debugify][OriginalMode] Export the 
report into JSON file.

In order to test the preservation of the original Debug Info metadata in your 
projects, a front end option could be very useful, since users usually report 
that a concrete entity (e.g. variable `x`, or function `fn2()`) is missing 
debug info. The [0] is an example of running the utility on GDB Project.

[0] https://djolertrk.github.io/di-checker-html-report-example/


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/DebugInfo/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/DebugInfo/debugify-each-original.c
===
--- /dev/null
+++ clang/test/DebugInfo/debugify-each-original.c
@@ -0,0 +1,57 @@
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -emit-llvm -S \
+// RUN: -O1 -o - %s 2>&1 | FileCheck %s
+
+int main()
+{
+  int x = 1;
+  int y = 2;
+  return x + y;
+}
+
+// CHECK: Force set function attributes: PASS
+// CHECK-NEXT: Infer set function attributes: PASS
+// CHECK-NEXT: Interprocedural Sparse Conditional Constant Propagation: PASS
+// CHECK-NEXT: Called Value Propagation: PASS
+// CHECK-NEXT: Global Variable Optimizer: PASS
+// CHECK-NEXT: Promote Memory to Register: PASS
+// CHECK-NEXT: Dead Argument Elimination: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Globals Alias Analysis: PASS
+// CHECK-NEXT: SROA: PASS
+// CHECK-NEXT: Early CSE w/ MemorySSA: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: Conditionally eliminate dead library calls: PASS
+// CHECK-NEXT: PGOMemOPSize: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Reassociate expressions: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: MemCpy Optimization: PASS
+// CHECK-NEXT: Sparse Conditional Constant Propagation: PASS
+// CHECK-NEXT: Bit-Tracking Dead Code Elimination: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: Aggressive Dead Code Elimination: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: A No-Op Barrier Pass: PASS
+// CHECK-NEXT: Deduce function attributes in RPO: PASS
+// CHECK-NEXT: Global Variable Optimizer: PASS
+// CHECK-NEXT: Dead Global Elimination: PASS
+// CHECK-NEXT: Globals Alias Analysis: PASS
+// CHECK-NEXT: Float to int: PASS
+// CHECK-NEXT: Lower constant intrinsics: PASS
+// CHECK-NEXT: Loop Distribution: PASS
+// CHECK-NEXT: Loop Vectorization: PASS
+// CHECK-NEXT: Loop Load Elimination: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
+// CHECK-NEXT: Optimize scalar/vector ops: PASS
+// CHECK-NEXT: Combine redundant instructions: PASS
+// CHECK-NEXT: Warn about non-applied transformations: PASS
+// CHECK-NEXT: Alignment from assumptions: PASS
+// CHECK-NEXT: Strip Unused Function Prototypes: PASS
+// CHECK-NEXT: Remove redundant instructions: PASS
+// CHECK-NEXT: Hoist/decompose integer division and remainder: PASS
+// CHECK-NEXT: Simplify the CFG: PASS
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+