[clang] ab49747 - [NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in Flang

2023-03-29 Thread Sacha Ballantyne via cfe-commits

Author: Kiran Chandramohan
Date: 2023-03-29T12:01:54Z
New Revision: ab49747f9d67d82a1cf0f19196ff29f01d4384f5

URL: 
https://github.com/llvm/llvm-project/commit/ab49747f9d67d82a1cf0f19196ff29f01d4384f5
DIFF: 
https://github.com/llvm/llvm-project/commit/ab49747f9d67d82a1cf0f19196ff29f01d4384f5.diff

LOG: [NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in Flang

This patch moves the Debug Options to llvm/Frontend so that it can be shared by 
Flang as well.

Reviewed By: kiranchandramohan, awarzynski

Differential Revision: https://reviews.llvm.org/D142347

Added: 
llvm/include/llvm/Frontend/Debug/Options.h

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/ToolChain.h
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/lib/Driver/ToolChains/HIPSPV.cpp
clang/lib/Driver/ToolChains/HIPSPV.h
clang/lib/Driver/ToolChains/MSVC.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/Rewrite/FrontendActions.cpp
clang/tools/clang-import-test/clang-import-test.cpp

Removed: 
clang/include/clang/Basic/DebugInfoOptions.h



diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d82ad06010857..7151fe9d65682 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -358,7 +358,7 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to 
emit complete
  ///< template parameter descriptions 
in
  ///< forward declarations (versus just
  ///< including them in the name).
-ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
codegenoptions::DebugTemplateNamesKind, 2, 
codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template 
parameters
+ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
llvm::codegenoptions::DebugTemplateNamesKind, 2, 
llvm::codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit 
template parameters
///< in the textual names of 
template
   ///< specializations.
   ///< Implies DebugFwdTemplateNames to
@@ -388,7 +388,7 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
 VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
 
 /// The kind of generated debug info.
-ENUM_CODEGENOPT(DebugInfo, codegenoptions::DebugInfoKind, 4, 
codegenoptions::NoDebugInfo)
+ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, 
llvm::codegenoptions::NoDebugInfo)
 
 /// Whether to generate macro debug info.
 CODEGENOPT(MacroDebugInfo, 1, 0)

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2e067c228a277..97853799807fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -13,10 +13,10 @@
 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
-#include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetOptions.h"
@@ -505,12 +505,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if type and variable info should be emitted.
   bool hasReducedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
+return getDebugInfo() >= llvm::codegenoptions::DebugInfoConstructor;
   }
 
   /// Check if maybe unused type info should be emitted.
   bool hasMaybeUnusedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
+return getDebugInfo() >= llvm::codegenoptions::UnusedTypeInfo;
   }
 
   // Check if any one of SanitizeCoverage* is enabled.

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 4d66e577b107f..e969edfc4e866 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_CLANG_DRIVER_TOOLCHAIN_H
 #define LLVM_CLANG_DRIVER_TOOLCHAIN_H
 
-#include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Sanitizers.h"
@@ -21,6 +20,7 @@
 #include "llvm/ADT/FloatingPointMo

[clang] e2b7424 - [Flang] Add debug flag to enable current debug information pass

2023-03-29 Thread Sacha Ballantyne via cfe-commits

Author: Sacha Ballantyne
Date: 2023-03-29T12:21:26Z
New Revision: e2b7424d06663f92b958c0b4649ed08b55216a49

URL: 
https://github.com/llvm/llvm-project/commit/e2b7424d06663f92b958c0b4649ed08b55216a49
DIFF: 
https://github.com/llvm/llvm-project/commit/e2b7424d06663f92b958c0b4649ed08b55216a49.diff

LOG: [Flang] Add debug flag to enable current debug information pass

While a pass exists to generate basic debug information, currently there is not 
a corresponding flag to enable it.
This patch adds support for activating this pass at any debug level >= -g1, as 
well as emiting a warning for higher levels that the functionality is not yet 
fully implemented.

This patch also adds -g and -gline-tables-only to appear when `flang-new` 
--help is run

Depends on D142347.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D146814

Added: 
flang/test/Driver/mlir-debug-pass-pipeline.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CodeGenOptions.def
flang/include/flang/Frontend/CodeGenOptions.h
flang/include/flang/Tools/CLOptions.inc
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6f3a325d6310d..0cc7052b67105 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3232,9 +3232,9 @@ def femit_dwarf_unwind_EQ : Joined<["-"], 
"femit-dwarf-unwind=">,
   NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
   MarshallingInfoEnum, "Default">;
 def g_Flag : Flag<["-"], "g">, Group,
-  HelpText<"Generate source-level debug information">;
+Flags<[CoreOption,FlangOption]>, HelpText<"Generate source-level debug 
information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
-  Flags<[CoreOption]>, HelpText<"Emit debug line number tables only">;
+  Flags<[CoreOption,FlangOption]>, HelpText<"Emit debug line number tables 
only">;
 def gline_directives_only : Flag<["-"], "gline-directives-only">, 
Group,
   Flags<[CoreOption]>, HelpText<"Emit debug line info directives only">;
 def gmlt : Flag<["-"], "gmlt">, Alias;
@@ -5466,12 +5466,12 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValuesScope<"llvm::Reloc">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
+def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 
 } // let Flags = [CC1Option, CC1AsOption, FC1Option, NoDriverOption]
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
 
-def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 873fb350c0f2c..f5efcebb3bbd9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -403,22 +403,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-// Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases
-// to the corresponding DebugInfoKind.
-static llvm::codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg &A) {
-  assert(A.getOption().matches(options::OPT_gN_Group) &&
- "Not a -g option that specifies a debug-info level");
-  if (A.getOption().matches(options::OPT_g0) ||
-  A.getOption().matches(options::OPT_ggdb0))
-return llvm::codegenoptions::NoDebugInfo;
-  if (A.getOption().matches(options::OPT_gline_tables_only) ||
-  A.getOption().matches(options::OPT_ggdb1))
-return llvm::codegenoptions::DebugLineTablesOnly;
-  if (A.getOption().matches(options::OPT_gline_directives_only))
-return llvm::codegenoptions::DebugDirectivesOnly;
-  return llvm::codegenoptions::DebugInfoConstructor;
-}
-
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
   switch (Triple.getArch()){
   default:
@@ -977,28 +961,7 @@ RenderDebugEnablingArgs(const ArgList &Args, ArgStringList 
&CmdArgs,
 llvm::codegenoptions::DebugInfoKind DebugInfoKind,
 unsigned DwarfVersion,
 llvm::DebuggerKind DebuggerTuning) {
-  switch (DebugInfoKind) {
-  case llvm::codegenoptions::DebugDirectivesOnly:
-CmdArgs.push_back("-debug-info-kind=line-directives-only");
-break;
-  case llvm::codegenoptions::DebugLineTablesOnly:
-CmdArgs.push_back("-deb