Index: clang/include/clang/Basic/CodeGenOptions.h =================================================================== --- clang/include/clang/Basic/CodeGenOptions.h +++ clang/include/clang/Basic/CodeGenOptions.h @@ -171,6 +171,9 @@ /// The ABI to use for passing floating point arguments. std::string FloatABI; + /// The file to use for dumping bug report by `debugify` in `original` mode. + std::string DIBugsReportFilePath; + /// The floating-point denormal mode to use. llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE(); Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -65,6 +65,10 @@ CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled. CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of ///< '-g' + 'O>0' level. +CODEGENOPT(EnableDebugifyEachOriginal, 1, 0) ///< Enable debugify each in + ///< original mode (it means check + ///< the original debug info + ///< metadata preservation). CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs ///< is specified. CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls. 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 objects).">; // The driver option takes the key as a parameter to the -msign-return-address= // and -mbranch-protection= options, but CC1 has a separate option so we // don't have to parse the parameter twice. 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/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/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: 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`` ^^^^^^^^^^^^^^^^^^