https://github.com/kaviya2510 updated 
https://github.com/llvm/llvm-project/pull/188022

>From af1b47537ca490f898a166f1b3958bb224e048ec Mon Sep 17 00:00:00 2001
From: Kaviya Rajendiran <[email protected]>
Date: Mon, 23 Mar 2026 17:19:28 +0530
Subject: [PATCH 1/2] [LLVM-Flang] Add support for -fdebug-info-for-profiling
 option

---
 clang/include/clang/Options/Options.td        |  4 +--
 clang/lib/Driver/ToolChains/Flang.cpp         |  5 +++
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 .../flang/Optimizer/Passes/Pipelines.h        |  4 +--
 .../flang/Optimizer/Transforms/Passes.td      |  3 ++
 flang/include/flang/Tools/CrossToolHelpers.h  |  2 ++
 flang/lib/Frontend/CompilerInvocation.cpp     |  3 ++
 flang/lib/Frontend/FrontendActions.cpp        | 24 ++++++++-----
 flang/lib/Optimizer/Passes/Pipelines.cpp      | 14 +++++---
 .../lib/Optimizer/Transforms/AddDebugInfo.cpp |  2 +-
 .../test/Driver/fdebug-info-for-profiling.f90 | 36 +++++++++++++++++++
 llvm/include/llvm/IR/DebugInfoMetadata.h      |  1 +
 mlir/include/mlir-c/Dialect/LLVM.h            |  4 +--
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td       |  4 ++-
 .../Dialect/LLVMIR/LLVMDialectBytecode.td     |  4 ++-
 mlir/lib/CAPI/Dialect/LLVM.cpp                |  7 ++--
 mlir/lib/Target/LLVMIR/DebugImporter.cpp      |  3 +-
 mlir/lib/Target/LLVMIR/DebugTranslation.cpp   |  2 +-
 mlir/test/CAPI/llvm.c                         |  2 +-
 19 files changed, 96 insertions(+), 29 deletions(-)
 create mode 100644 flang/test/Driver/fdebug-info-for-profiling.f90

diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 8b0c701521728..44f795e36b105 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1820,9 +1820,9 @@ def ffile_compilation_dir_EQ : Joined<["-"], 
"ffile-compilation-dir=">, Group<f_
     HelpText<"The compilation directory to embed in the debug info and 
coverage mapping.">;
 defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
   CodeGenOpts<"DebugInfoForProfiling">, DefaultFalse,
-  PosFlag<SetTrue, [], [ClangOption, CC1Option],
+  PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option],
           "Emit extra debug info to make sample profile more accurate">,
-  NegFlag<SetFalse>>;
+  NegFlag<SetFalse, [], [ClangOption, FlangOption]>>;
 def fprofile_generate_cold_function_coverage : Flag<["-"], 
"fprofile-generate-cold-function-coverage">,
     Group<f_Group>, Visibility<[ClangOption, CLOption]>,
     HelpText<"Generate instrumented code to collect coverage info for cold 
functions into default.profraw file (overridden by '=' form of option or 
LLVM_PROFILE_FILE env var)">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d56a8c4448469..0b45a8dc8498c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -193,6 +193,11 @@ void Flang::addDebugOptions(const llvm::opt::ArgList 
&Args, const JobAction &JA,
       CmdArgs.push_back(SplitDWARFOut);
     }
   }
+  if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
+                   options::OPT_fno_debug_info_for_profiling, false) &&
+      checkDebugInfoOption(
+          Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args, D, 
TC))
+    CmdArgs.push_back("-fdebug-info-for-profiling");
 }
 
 void Flang::addCodegenOptions(const ArgList &Args,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index c877e3320b264..38f1a85b998dc 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -51,6 +51,7 @@ CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
 CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
 CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
 CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
+CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra debug info to make 
sample profile more accurate.
 
 CODEGENOPT(Underscoring, 1, 1)
 ENUM_CODEGENOPT(FPMaxminBehavior, Fortran::common::FPMaxminBehavior, 2, 
Fortran::common::FPMaxminBehavior::Legacy)
diff --git a/flang/include/flang/Optimizer/Passes/Pipelines.h 
b/flang/include/flang/Optimizer/Passes/Pipelines.h
index 6c2a1e3c3c074..cf8e8fba7d171 100644
--- a/flang/include/flang/Optimizer/Passes/Pipelines.h
+++ b/flang/include/flang/Optimizer/Passes/Pipelines.h
@@ -104,8 +104,8 @@ void 
addCompilerGeneratedNamesConversionPass(mlir::PassManager &pm);
 void addDebugInfoPass(mlir::PassManager &pm,
                       llvm::codegenoptions::DebugInfoKind debugLevel,
                       llvm::OptimizationLevel optLevel,
-                      llvm::StringRef inputFilename, int32_t dwarfVersion,
-                      llvm::StringRef splitDwarfFile,
+                      bool debugInfoForProfiling, llvm::StringRef 
inputFilename,
+                      int32_t dwarfVersion, llvm::StringRef splitDwarfFile,
                       llvm::StringRef dwarfDebugFlags);
 
 /// Create FIRToLLVMPassOptions from pipeline configuration.
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td 
b/flang/include/flang/Optimizer/Transforms/Passes.td
index 38c5fc8db911c..82d89c4df42c3 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -250,6 +250,9 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> 
{
     Option<"isOptimized", "is-optimized",
            "bool", /*default=*/"false",
            "is optimized.">,
+    Option<"debugInfoForProfiling", "debug-info-for-profiling", "bool",
+           /*default=*/"false",
+            "Emit extra debug info to make sample profile more accurate">,
     Option<"inputFilename", "file-name",
            "std::string",
            /*default=*/"std::string{}",
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h 
b/flang/include/flang/Tools/CrossToolHelpers.h
index db4a93846850a..d4bdc3bbd30a7 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -106,6 +106,7 @@ struct MLIRToLLVMPassPipelineConfig : public 
FlangEPCallBacks {
         ApproxFuncFPMath && mathOpts.getFPContractEnabled();
     Reciprocals = opts.Reciprocals;
     PreferVectorWidth = opts.PreferVectorWidth;
+    DebugInfoForProfiling = opts.DebugInfoForProfiling;
     if (opts.InstrumentFunctions) {
       InstrumentFunctionEntry = "__cyg_profile_func_enter";
       InstrumentFunctionExit = "__cyg_profile_func_exit";
@@ -139,6 +140,7 @@ struct MLIRToLLVMPassPipelineConfig : public 
FlangEPCallBacks {
                                       ///< functions.
   bool NSWOnLoopVarInc = true; ///< Add nsw flag to loop variable increments.
   bool EnableOpenMP = false; ///< Enable OpenMP lowering.
+  bool DebugInfoForProfiling = false; /// Enable extra debugging info
   bool EnableOpenMPSimd = false; ///< Enable OpenMP simd-only mode.
   bool SkipConvertComplexPow = false; ///< Do not run complex pow conversion.
   std::string InstrumentFunctionEntry =
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 36791201825ce..8d99fc9d4403e 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -170,6 +170,9 @@ static bool 
parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
           args.getLastArg(clang::options::OPT_dwarf_debug_flags))
     opts.DwarfDebugFlags = arg->getValue();
 
+  opts.DebugInfoForProfiling =
+      args.hasArg(clang::options::OPT_fdebug_info_for_profiling);
+
   return true;
 }
 
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index e74c913cfa137..7d85b26f718af 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -968,14 +968,14 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
 
   if (opts.hasProfileIRInstr()) {
     // -fprofile-generate.
-    pgoOpt = llvm::PGOOptions(opts.InstrProfileOutput.empty()
-                                  ? llvm::driver::getDefaultProfileGenName()
-                                  : opts.InstrProfileOutput,
-                              "", "", opts.MemoryProfileUsePath,
-                              llvm::PGOOptions::IRInstr,
-                              llvm::PGOOptions::NoCSAction,
-                              llvm::PGOOptions::ColdFuncOpt::Default, false,
-                              /*PseudoProbeForProfiling=*/false, false);
+    pgoOpt = llvm::PGOOptions(
+        opts.InstrProfileOutput.empty()
+            ? llvm::driver::getDefaultProfileGenName()
+            : opts.InstrProfileOutput,
+        "", "", opts.MemoryProfileUsePath, llvm::PGOOptions::IRInstr,
+        llvm::PGOOptions::NoCSAction, llvm::PGOOptions::ColdFuncOpt::Default,
+        opts.DebugInfoForProfiling,
+        /*PseudoProbeForProfiling=*/false, false);
   } else if (opts.hasProfileIRUse()) {
     // -fprofile-use.
     auto CSAction = opts.hasProfileCSIRUse() ? llvm::PGOOptions::CSIRUse
@@ -983,7 +983,13 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
     pgoOpt = llvm::PGOOptions(
         opts.ProfileInstrumentUsePath, "", opts.ProfileRemappingFile,
         opts.MemoryProfileUsePath, llvm::PGOOptions::IRUse, CSAction,
-        llvm::PGOOptions::ColdFuncOpt::Default, false);
+        llvm::PGOOptions::ColdFuncOpt::Default, opts.DebugInfoForProfiling);
+  } else if (opts.DebugInfoForProfiling) {
+    // -fdebug-info-for-profiling
+    pgoOpt = llvm::PGOOptions("", "", "", /*MemoryProfile=*/"",
+                              llvm::PGOOptions::NoAction,
+                              llvm::PGOOptions::NoCSAction,
+                              llvm::PGOOptions::ColdFuncOpt::Default, true);
   }
 
   llvm::StandardInstrumentations si(llvmModule->getContext(),
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp 
b/flang/lib/Optimizer/Passes/Pipelines.cpp
index e9cd5da56083e..631496a2cea20 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -96,13 +96,14 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) {
 void addDebugInfoPass(mlir::PassManager &pm,
                       llvm::codegenoptions::DebugInfoKind debugLevel,
                       llvm::OptimizationLevel optLevel,
-                      llvm::StringRef inputFilename, int32_t dwarfVersion,
-                      llvm::StringRef splitDwarfFile,
+                      bool debugInfoForProfiling, llvm::StringRef 
inputFilename,
+                      int32_t dwarfVersion, llvm::StringRef splitDwarfFile,
                       llvm::StringRef dwarfDebugFlags) {
   fir::AddDebugInfoOptions options;
   options.debugLevel = getEmissionKind(debugLevel);
   options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
   options.inputFilename = inputFilename;
+  options.debugInfoForProfiling = debugInfoForProfiling;
   options.dwarfVersion = dwarfVersion;
   options.splitDwarfFile = splitDwarfFile;
   options.dwarfDebugFlags = dwarfDebugFlags;
@@ -372,12 +373,14 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
 void createDebugPasses(mlir::PassManager &pm,
                        llvm::codegenoptions::DebugInfoKind debugLevel,
                        llvm::OptimizationLevel OptLevel,
+                       bool debugInfoForProfiling,
                        llvm::StringRef inputFilename, int32_t dwarfVersion,
                        llvm::StringRef splitDwarfFile,
                        llvm::StringRef dwarfDebugFlags) {
   if (debugLevel != llvm::codegenoptions::NoDebugInfo)
-    addDebugInfoPass(pm, debugLevel, OptLevel, inputFilename, dwarfVersion,
-                     splitDwarfFile, dwarfDebugFlags);
+    addDebugInfoPass(pm, debugLevel, OptLevel, debugInfoForProfiling,
+                     inputFilename, dwarfVersion, splitDwarfFile,
+                     dwarfDebugFlags);
 }
 
 void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
@@ -395,7 +398,8 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager 
&pm,
   fir::addCodeGenRewritePass(
       pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
   fir::addExternalNameConversionPass(pm, config.Underscoring);
-  fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename,
+  fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel,
+                         config.DebugInfoForProfiling, inputFilename,
                          config.DwarfVersion, config.SplitDwarfFile,
                          config.DwarfDebugFlags);
   fir::addTargetRewritePass(pm);
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp 
b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index c42f5a29ecd62..389581c376a6d 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -936,7 +936,7 @@ void AddDebugInfoPass::runOnOperation() {
   mlir::LLVM::DICompileUnitAttr cuAttr = mlir::LLVM::DICompileUnitAttr::get(
       mlir::DistinctAttr::create(mlir::UnitAttr::get(context)),
       llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer,
-      isOptimized, debugLevel,
+      isOptimized, debugLevel, debugInfoForProfiling,
       /*nameTableKind=*/mlir::LLVM::DINameTableKind::Default,
       splitDwarfFile.empty() ? mlir::StringAttr()
                              : mlir::StringAttr::get(context, splitDwarfFile));
diff --git a/flang/test/Driver/fdebug-info-for-profiling.f90 
b/flang/test/Driver/fdebug-info-for-profiling.f90
new file mode 100644
index 0000000000000..2e72e2b569164
--- /dev/null
+++ b/flang/test/Driver/fdebug-info-for-profiling.f90
@@ -0,0 +1,36 @@
+! Test to check the option "-fdebug-info-for-profiling".
+
+!RUN: %flang -### -S -fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+!RUN: %flang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling 
-fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+! RUN: %flang -S -emit-llvm -fdebug-info-for-profiling -g -o - %s | FileCheck 
%s
+
+! CHECK-DEBUG-INFO: "-fdebug-info-for-profiling"
+
+! CHECK: !DICompileUnit({{.*}}debugInfoForProfiling: true{{.*}})
+! CHECK: !DILexicalBlockFile(
+! CHECK: discriminator:
+
+program test
+   implicit none
+   integer :: i, sum
+   sum = 0
+   do i = 1, 20
+      if (mod(i, 2) == 0) then
+         sum = sum + compute(i)
+      else
+         sum = sum + compute(i)*2
+      end if
+   end do
+
+contains
+   integer function compute(x)
+      implicit none
+      integer, intent(in) :: x
+      if (x < 10) then
+         compute = x*x
+      else
+         compute = x + 5
+      end if
+   end function compute
+
+end program test
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h 
b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 3ce899db66217..e28b47d87d4e5 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2118,6 +2118,7 @@ class DICompileUnit : public DIScope {
 
   DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
   bool isOptimized() const { return IsOptimized; }
+  bool isDebugInfoForProfiling() const { return DebugInfoForProfiling; }
   unsigned getRuntimeVersion() const { return RuntimeVersion; }
   DebugEmissionKind getEmissionKind() const {
     return (DebugEmissionKind)EmissionKind;
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h 
b/mlir/include/mlir-c/Dialect/LLVM.h
index 2c167d23a7d9a..02ae71e41b8b7 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -366,8 +366,8 @@ typedef enum MlirLLVMDINameTableKind 
MlirLLVMDINameTableKind;
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
     MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
     MlirAttribute file, MlirAttribute producer, bool isOptimized,
-    MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind,
-    MlirAttribute splitDebugFilename);
+    MlirLLVMDIEmissionKind emissionKind, bool debugInfoForProfiling,
+    MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename);
 
 MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompileUnitAttrGetName(void);
 
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td 
b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 14a4f888bd51d..89bdbe96c01b9 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -425,6 +425,7 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", 
"di_compile_unit",
     OptionalParameter<"StringAttr">:$producer,
     "bool":$isOptimized,
     "DIEmissionKind":$emissionKind,
+    OptionalParameter<"bool">:$debugInfoForProfiling,
     OptionalParameter<"DINameTableKind">:$nameTableKind,
     OptionalParameter<"StringAttr">:$splitDebugFilename
   );
@@ -433,11 +434,12 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", 
"di_compile_unit",
       "DistinctAttr":$id, "unsigned":$sourceLanguage, "DIFileAttr":$file,
       "StringAttr":$producer, "bool":$isOptimized,
       "DIEmissionKind":$emissionKind,
+      CArg<"bool", "false">:$debugInfoForProfiling,
       CArg<"DINameTableKind", "DINameTableKind::Default">:$nameTableKind,
       CArg<"StringAttr", "{}">:$splitDebugFilename
     ), [{
       return $_get(id.getContext(), id, sourceLanguage, file, producer,
-                   isOptimized, emissionKind, nameTableKind, 
splitDebugFilename);
+                   isOptimized, emissionKind, debugInfoForProfiling, 
nameTableKind, splitDebugFilename);
     }]>
   ];
   let assemblyFormat = "`<` struct(params) `>`";
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td 
b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
index 659c535c1b671..9ab725af71495 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
@@ -136,9 +136,11 @@ def DICompileUnitAttr : DialectAttribute<(attr
   Bool:$isOptimized,
   EnumClassFlag<"DIEmissionKind", "getEmissionKind()">:$_rawEmissionKind,
   LocalVar<"DIEmissionKind", "(DIEmissionKind)_rawEmissionKind">:$emissionKind,
+  Bool:$debugInfoForProfiling,
   EnumClassFlag<"DINameTableKind", "getNameTableKind()">:$_rawNameTableKind,
   LocalVar<"DINameTableKind",
-           "(DINameTableKind)_rawNameTableKind">:$nameTableKind
+           "(DINameTableKind)_rawNameTableKind">:$nameTableKind,
+  OptionalAttribute<"StringAttr">:$splitDebugFilename
 )>;
 
 
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index 154ebbc51e961..c1f60fb2753f3 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -345,12 +345,13 @@ MlirStringRef mlirLLVMDIFileAttrGetName(void) { return 
wrap(DIFileAttr::name); }
 MlirAttribute mlirLLVMDICompileUnitAttrGet(
     MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
     MlirAttribute file, MlirAttribute producer, bool isOptimized,
-    MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind,
-    MlirAttribute splitDebugFilename) {
+    MlirLLVMDIEmissionKind emissionKind, bool debugInfoForProfiling,
+    MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename) {
   return wrap(DICompileUnitAttr::get(
       unwrap(ctx), cast<DistinctAttr>(unwrap(id)), sourceLanguage,
       cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
-      isOptimized, DIEmissionKind(emissionKind), 
DINameTableKind(nameTableKind),
+      isOptimized, DIEmissionKind(emissionKind), debugInfoForProfiling,
+      DINameTableKind(nameTableKind),
       cast<StringAttr>(unwrap(splitDebugFilename))));
 }
 
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp 
b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index 37140e3a949c7..c099865bdd16e 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -61,7 +61,8 @@ DICompileUnitAttr 
DebugImporter::translateImpl(llvm::DICompileUnit *node) {
       context, getOrCreateDistinctID(node),
       node->getSourceLanguage().getUnversionedName(),
       translate(node->getFile()), getStringAttrOrNull(node->getRawProducer()),
-      node->isOptimized(), emissionKind.value(), nameTableKind.value(),
+      node->isOptimized(), emissionKind.value(),
+      node->isDebugInfoForProfiling(), nameTableKind.value(),
       getStringAttrOrNull(node->getRawSplitDebugFilename()));
 }
 
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp 
b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 08eee68c195db..588998b6f6c73 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -130,7 +130,7 @@ llvm::DICompileUnit 
*DebugTranslation::translateImpl(DICompileUnitAttr attr) {
                                    : "",
       static_cast<llvm::DICompileUnit::DebugEmissionKind>(
           attr.getEmissionKind()),
-      0, true, false,
+      0, true, attr.getDebugInfoForProfiling(),
       static_cast<llvm::DICompileUnit::DebugNameTableKind>(
           attr.getNameTableKind()));
 }
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 32f6b8c8d8a33..0e9c1ce0d7ccd 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -278,7 +278,7 @@ static void testDebugInfoAttributes(MlirContext ctx) {
 
   MlirAttribute compile_unit = mlirLLVMDICompileUnitAttrGet(
       ctx, id, LLVMDWARFSourceLanguageC99, file, foo, false,
-      MlirLLVMDIEmissionKindFull, MlirLLVMDINameTableKindDefault, bar);
+      MlirLLVMDIEmissionKindFull, false, MlirLLVMDINameTableKindDefault, bar);
 
   // CHECK: #llvm.di_compile_unit<{{.*}}>
   mlirAttributeDump(compile_unit);

>From 12b02e03a0a245abad905725d8857c48e63bdc7b Mon Sep 17 00:00:00 2001
From: Kaviya Rajendiran <[email protected]>
Date: Tue, 24 Mar 2026 16:43:46 +0530
Subject: [PATCH 2/2] [LLVM-Flang] Addressed review comments and modified
 testcases in mlir

---
 clang/include/clang/Driver/CommonArgs.h       |  4 ++
 clang/lib/Driver/ToolChains/Clang.cpp         |  6 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp    | 10 ++++
 clang/lib/Driver/ToolChains/Flang.cpp         |  6 +-
 flang/lib/Optimizer/Passes/Pipelines.cpp      | 38 ++++--------
 .../test/Driver/fdebug-info-for-profiling.f90 | 60 +++++++++----------
 .../Integration/debug-info-for-profiling.f90  | 36 +++++++++++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td       |  6 +-
 .../Dialect/LLVMIR/LLVMDialectBytecode.td     |  2 +-
 mlir/lib/Target/LLVMIR/DebugTranslation.cpp   |  2 +-
 mlir/test/Dialect/LLVMIR/debuginfo.mlir       |  4 +-
 mlir/test/Target/LLVMIR/Import/debug-info.ll  |  4 +-
 mlir/test/Target/LLVMIR/llvmir-debug.mlir     | 46 +++++++-------
 13 files changed, 126 insertions(+), 98 deletions(-)
 create mode 100644 flang/test/Integration/debug-info-for-profiling.f90

diff --git a/clang/include/clang/Driver/CommonArgs.h 
b/clang/include/clang/Driver/CommonArgs.h
index a895579be7419..0af1b89425227 100644
--- a/clang/include/clang/Driver/CommonArgs.h
+++ b/clang/include/clang/Driver/CommonArgs.h
@@ -118,6 +118,10 @@ bool checkDebugInfoOption(const llvm::opt::Arg *A,
                           const llvm::opt::ArgList &Args, const Driver &D,
                           const ToolChain &TC);
 
+void addDebugInfoForProfilingArgs(const Driver &D, const ToolChain &TC,
+                                  const llvm::opt::ArgList &Args,
+                                  llvm::opt::ArgStringList &CmdArgs);
+
 void AddAssemblerKPIC(const ToolChain &ToolChain,
                       const llvm::opt::ArgList &Args,
                       llvm::opt::ArgStringList &CmdArgs);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6416baf9126ff..6e5499eccd3ca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4408,11 +4408,7 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, 
const llvm::Triple &T,
                      !isHIP(InputType) && !isObjC(InputType) &&
                      !isOpenCL(InputType);
 
-  if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
-                   options::OPT_fno_debug_info_for_profiling, false) &&
-      checkDebugInfoOption(
-          Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args, D, 
TC))
-    CmdArgs.push_back("-fdebug-info-for-profiling");
+  addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
 
   // The 'g' groups options involve a somewhat intricate sequence of decisions
   // about what to pass from the driver to the frontend, but by the time they
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 9a17fa2546e68..461bc6a31b603 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2347,6 +2347,16 @@ bool tools::checkDebugInfoOption(const Arg *A, const 
ArgList &Args,
   return false;
 }
 
+void tools::addDebugInfoForProfilingArgs(const Driver &D, const ToolChain &TC,
+                                         const ArgList &Args,
+                                         ArgStringList &CmdArgs) {
+  if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
+                   options::OPT_fno_debug_info_for_profiling, false) &&
+      checkDebugInfoOption(
+          Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args, D, 
TC))
+    CmdArgs.push_back("-fdebug-info-for-profiling");
+}
+
 void tools::AddAssemblerKPIC(const ToolChain &ToolChain, const ArgList &Args,
                              ArgStringList &CmdArgs) {
   llvm::Reloc::Model RelocationModel;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 0b45a8dc8498c..c7716b52009f6 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -193,11 +193,7 @@ void Flang::addDebugOptions(const llvm::opt::ArgList 
&Args, const JobAction &JA,
       CmdArgs.push_back(SplitDWARFOut);
     }
   }
-  if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
-                   options::OPT_fno_debug_info_for_profiling, false) &&
-      checkDebugInfoOption(
-          Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args, D, 
TC))
-    CmdArgs.push_back("-fdebug-info-for-profiling");
+  addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
 }
 
 void Flang::addCodegenOptions(const ArgList &Args,
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp 
b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 631496a2cea20..2216fc0c68494 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -94,19 +94,16 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) {
 }
 
 void addDebugInfoPass(mlir::PassManager &pm,
-                      llvm::codegenoptions::DebugInfoKind debugLevel,
-                      llvm::OptimizationLevel optLevel,
-                      bool debugInfoForProfiling, llvm::StringRef 
inputFilename,
-                      int32_t dwarfVersion, llvm::StringRef splitDwarfFile,
-                      llvm::StringRef dwarfDebugFlags) {
+                      const MLIRToLLVMPassPipelineConfig &config,
+                      llvm::StringRef inputFilename) {
   fir::AddDebugInfoOptions options;
-  options.debugLevel = getEmissionKind(debugLevel);
-  options.isOptimized = optLevel != llvm::OptimizationLevel::O0;
+  options.debugLevel = getEmissionKind(config.DebugInfo);
+  options.isOptimized = config.OptLevel != llvm::OptimizationLevel::O0;
   options.inputFilename = inputFilename;
-  options.debugInfoForProfiling = debugInfoForProfiling;
-  options.dwarfVersion = dwarfVersion;
-  options.splitDwarfFile = splitDwarfFile;
-  options.dwarfDebugFlags = dwarfDebugFlags;
+  options.debugInfoForProfiling = config.DebugInfoForProfiling;
+  options.dwarfVersion = config.DwarfVersion;
+  options.splitDwarfFile = config.SplitDwarfFile;
+  options.dwarfDebugFlags = config.DwarfDebugFlags;
   addPassConditionally(pm, disableDebugInfo,
                        [&]() { return fir::createAddDebugInfoPass(options); });
 }
@@ -371,16 +368,10 @@ void createOpenMPFIRPassPipeline(mlir::PassManager &pm,
 }
 
 void createDebugPasses(mlir::PassManager &pm,
-                       llvm::codegenoptions::DebugInfoKind debugLevel,
-                       llvm::OptimizationLevel OptLevel,
-                       bool debugInfoForProfiling,
-                       llvm::StringRef inputFilename, int32_t dwarfVersion,
-                       llvm::StringRef splitDwarfFile,
-                       llvm::StringRef dwarfDebugFlags) {
-  if (debugLevel != llvm::codegenoptions::NoDebugInfo)
-    addDebugInfoPass(pm, debugLevel, OptLevel, debugInfoForProfiling,
-                     inputFilename, dwarfVersion, splitDwarfFile,
-                     dwarfDebugFlags);
+                       const MLIRToLLVMPassPipelineConfig &config,
+                       llvm::StringRef inputFilename) {
+  if (config.DebugInfo != llvm::codegenoptions::NoDebugInfo)
+    addDebugInfoPass(pm, config, inputFilename);
 }
 
 void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
@@ -398,10 +389,7 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager 
&pm,
   fir::addCodeGenRewritePass(
       pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
   fir::addExternalNameConversionPass(pm, config.Underscoring);
-  fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel,
-                         config.DebugInfoForProfiling, inputFilename,
-                         config.DwarfVersion, config.SplitDwarfFile,
-                         config.DwarfDebugFlags);
+  fir::createDebugPasses(pm, config, inputFilename);
   fir::addTargetRewritePass(pm);
   fir::addCompilerGeneratedNamesConversionPass(pm);
 
diff --git a/flang/test/Driver/fdebug-info-for-profiling.f90 
b/flang/test/Driver/fdebug-info-for-profiling.f90
index 2e72e2b569164..b15f1e1c3325c 100644
--- a/flang/test/Driver/fdebug-info-for-profiling.f90
+++ b/flang/test/Driver/fdebug-info-for-profiling.f90
@@ -1,36 +1,34 @@
 ! Test to check the option "-fdebug-info-for-profiling".
 
-!RUN: %flang -### -S -fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
-!RUN: %flang -### -S -fdebug-info-for-profiling -fno-debug-info-for-profiling 
-fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
-! RUN: %flang -S -emit-llvm -fdebug-info-for-profiling -g -o - %s | FileCheck 
%s
+!RUN: %flang -### -fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+!RUN: %flang -### -fdebug-info-for-profiling -fno-debug-info-for-profiling 
-fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+!RUN: %flang -### %s 2>&1 | FileCheck %s 
+!RUN: %flang -### -fdebug-info-for-profiling -fno-debug-info-for-profiling %s 
2>&1 | FileCheck %s
 
 ! CHECK-DEBUG-INFO: "-fdebug-info-for-profiling"
-
-! CHECK: !DICompileUnit({{.*}}debugInfoForProfiling: true{{.*}})
-! CHECK: !DILexicalBlockFile(
-! CHECK: discriminator:
-
+! CHECK-NOT: "-fdebug-info-for-profiling"
 program test
-   implicit none
-   integer :: i, sum
-   sum = 0
-   do i = 1, 20
-      if (mod(i, 2) == 0) then
-         sum = sum + compute(i)
-      else
-         sum = sum + compute(i)*2
-      end if
-   end do
-
-contains
-   integer function compute(x)
-      implicit none
-      integer, intent(in) :: x
-      if (x < 10) then
-         compute = x*x
-      else
-         compute = x + 5
-      end if
-   end function compute
-
-end program test
+    implicit none
+    integer :: i, sum
+    sum = 0
+    do i = 1, 20
+       if (mod(i, 2) == 0) then
+          sum = sum + compute(i)
+       else
+          sum = sum + compute(i)*2
+       end if
+    end do
+ 
+ contains
+    integer function compute(x)
+       implicit none
+       integer, intent(in) :: x
+       if (x < 10) then
+          compute = x*x
+       else
+          compute = x + 5
+       end if
+    end function compute
+ 
+ end program test
+ 
\ No newline at end of file
diff --git a/flang/test/Integration/debug-info-for-profiling.f90 
b/flang/test/Integration/debug-info-for-profiling.f90
new file mode 100644
index 0000000000000..808e950f0803a
--- /dev/null
+++ b/flang/test/Integration/debug-info-for-profiling.f90
@@ -0,0 +1,36 @@
+! Test to check the option "-fdebug-info-for-profiling".
+
+!RUN: %flang -### -fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+!RUN: %flang -### -fdebug-info-for-profiling -fno-debug-info-for-profiling 
-fdebug-info-for-profiling %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DEBUG-INFO
+! RUN: %flang -S -emit-llvm -fdebug-info-for-profiling -g -o - %s | FileCheck 
%s
+
+! CHECK-DEBUG-INFO: "-fdebug-info-for-profiling"
+
+! CHECK: !DICompileUnit({{.*}}debugInfoForProfiling: true{{.*}})
+! CHECK: !DILexicalBlockFile(
+! CHECK: discriminator:
+
+program test
+   implicit none
+   integer :: i, sum
+   sum = 0
+   do i = 1, 20
+      if (mod(i, 2) == 0) then
+         sum = sum + compute(i)
+      else
+         sum = sum + compute(i)*2
+      end if
+   end do
+
+contains
+   integer function compute(x)
+      implicit none
+      integer, intent(in) :: x
+      if (x < 10) then
+         compute = x*x
+      else
+         compute = x + 5
+      end if
+   end function compute
+
+end program test
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td 
b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 89bdbe96c01b9..ee82badadb642 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -425,7 +425,7 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", 
"di_compile_unit",
     OptionalParameter<"StringAttr">:$producer,
     "bool":$isOptimized,
     "DIEmissionKind":$emissionKind,
-    OptionalParameter<"bool">:$debugInfoForProfiling,
+    OptionalParameter<"bool">:$isDebugInfoForProfiling,
     OptionalParameter<"DINameTableKind">:$nameTableKind,
     OptionalParameter<"StringAttr">:$splitDebugFilename
   );
@@ -434,12 +434,12 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", 
"di_compile_unit",
       "DistinctAttr":$id, "unsigned":$sourceLanguage, "DIFileAttr":$file,
       "StringAttr":$producer, "bool":$isOptimized,
       "DIEmissionKind":$emissionKind,
-      CArg<"bool", "false">:$debugInfoForProfiling,
+      CArg<"bool", "false">:$isDebugInfoForProfiling,
       CArg<"DINameTableKind", "DINameTableKind::Default">:$nameTableKind,
       CArg<"StringAttr", "{}">:$splitDebugFilename
     ), [{
       return $_get(id.getContext(), id, sourceLanguage, file, producer,
-                   isOptimized, emissionKind, debugInfoForProfiling, 
nameTableKind, splitDebugFilename);
+                   isOptimized, emissionKind, isDebugInfoForProfiling, 
nameTableKind, splitDebugFilename);
     }]>
   ];
   let assemblyFormat = "`<` struct(params) `>`";
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td 
b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
index 9ab725af71495..5f3821f0299b6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
@@ -136,7 +136,7 @@ def DICompileUnitAttr : DialectAttribute<(attr
   Bool:$isOptimized,
   EnumClassFlag<"DIEmissionKind", "getEmissionKind()">:$_rawEmissionKind,
   LocalVar<"DIEmissionKind", "(DIEmissionKind)_rawEmissionKind">:$emissionKind,
-  Bool:$debugInfoForProfiling,
+  Bool:$isDebugInfoForProfiling,
   EnumClassFlag<"DINameTableKind", "getNameTableKind()">:$_rawNameTableKind,
   LocalVar<"DINameTableKind",
            "(DINameTableKind)_rawNameTableKind">:$nameTableKind,
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp 
b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 588998b6f6c73..ab4662edf42ab 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -130,7 +130,7 @@ llvm::DICompileUnit 
*DebugTranslation::translateImpl(DICompileUnitAttr attr) {
                                    : "",
       static_cast<llvm::DICompileUnit::DebugEmissionKind>(
           attr.getEmissionKind()),
-      0, true, attr.getDebugInfoForProfiling(),
+      0, true, attr.getIsDebugInfoForProfiling(),
       static_cast<llvm::DICompileUnit::DebugNameTableKind>(
           attr.getNameTableKind()));
 }
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir 
b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index f6f52b3fcc001..8b02d0f44ab0a 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -3,10 +3,10 @@
 // CHECK-DAG: #[[FILE:.*]] = #llvm.di_file<"debuginfo.mlir" in "/test/">
 #file = #llvm.di_file<"debuginfo.mlir" in "/test/">
 
-// CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<id = distinct[0]<>, 
sourceLanguage = DW_LANG_C, file = #[[FILE]], producer = "MLIR", isOptimized = 
true, emissionKind = Full>
+// CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<id = distinct[0]<>, 
sourceLanguage = DW_LANG_C, file = #[[FILE]], producer = "MLIR", isOptimized = 
true, emissionKind = Full, isDebugInfoForProfiling = true>
 #cu = #llvm.di_compile_unit<
   id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #file,
-  producer = "MLIR", isOptimized = true, emissionKind = Full
+  producer = "MLIR", isOptimized = true, emissionKind = Full, 
isDebugInfoForProfiling = true
 >
 
 // CHECK-DAG: #[[NULL:.*]] = #llvm.di_null_type
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll 
b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 3c2691217e0bf..e4284c6041312 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -218,7 +218,7 @@ define void @composite_type() !dbg !3 {
 ; // -----
 
 ; CHECK-DAG: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">
-; CHECK-DAG: #[[CU:.+]] = #llvm.di_compile_unit<id = distinct[0]<>, 
sourceLanguage = DW_LANG_C, file = #[[FILE]], isOptimized = false, emissionKind 
= None, nameTableKind = None, splitDebugFilename = "test.dwo">
+; CHECK-DAG: #[[CU:.+]] = #llvm.di_compile_unit<id = distinct[0]<>, 
sourceLanguage = DW_LANG_C, file = #[[FILE]], isOptimized = false, emissionKind 
= None, isDebugInfoForProfiling = true, nameTableKind = None, 
splitDebugFilename = "test.dwo">
 ; Verify an empty subroutine types list is supported.
 ; CHECK-DAG: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<callingConvention = 
DW_CC_normal>
 ; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, 
compileUnit = #[[CU]], scope = #[[FILE]], name = "subprogram", linkageName = 
"subprogram", file = #[[FILE]], line = 42, scopeLine = 42, subprogramFlags = 
Definition, type = #[[SP_TYPE]]>
@@ -230,7 +230,7 @@ define void @subprogram() !dbg !3 {
 !llvm.dbg.cu = !{!1}
 !llvm.module.flags = !{!0}
 !0 = !{i32 2, !"Debug Info Version", i32 3}
-!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, nameTableKind: 
None, splitDebugFilename: "test.dwo")
+!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, nameTableKind: 
None, debugInfoForProfiling: true, splitDebugFilename: "test.dwo")
 !2 = !DIFile(filename: "debug-info.ll", directory: "/")
 !3 = distinct !DISubprogram(name: "subprogram", linkageName: "subprogram", 
scope: !2, file: !2, line: 42, scopeLine: 42, spFlags: DISPFlagDefinition, 
unit: !1, type: !4)
 !4 = !DISubroutineType(cc: DW_CC_normal, types: !5)
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir 
b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 1aa6362fc42d3..6ce5b3795fa89 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -50,8 +50,8 @@ llvm.func @func_no_debug() {
 >
 #cu = #llvm.di_compile_unit<
   id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #file,
-  producer = "MLIR", isOptimized = true, emissionKind = Full,
-  nameTableKind = None, splitDebugFilename = "test.dwo"
+  producer = "MLIR", isOptimized = true, 
+  emissionKind = Full, isDebugInfoForProfiling = true, nameTableKind = None, 
splitDebugFilename = "test.dwo"
 >
 #composite = #llvm.di_composite_type<
   tag = DW_TAG_structure_type, name = "composite", file = #file,
@@ -148,7 +148,7 @@ llvm.func @empty_types() {
   llvm.return
 } loc(fused<#sp1>["foo.mlir":2:1])
 
-// CHECK: ![[CU_LOC:.*]] = distinct !DICompileUnit(language: DW_LANG_C, file: 
![[CU_FILE_LOC:.*]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
splitDebugFilename: "test.dwo", emissionKind: FullDebug, nameTableKind: None)
+// CHECK: ![[CU_LOC:.*]] = distinct !DICompileUnit(language: DW_LANG_C, file: 
![[CU_FILE_LOC:.*]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
splitDebugFilename: "test.dwo", emissionKind: FullDebug, debugInfoForProfiling: 
true, nameTableKind: None)
 // CHECK: ![[CU_FILE_LOC]] = !DIFile(filename: "foo.mlir", directory: "/test/")
 
 // CHECK: ![[FUNC_LOC]] = distinct !DISubprogram(name: "func_with_debug", 
linkageName: "func_with_debug", scope: ![[NESTED_NAMESPACE:.*]], file: 
![[CU_FILE_LOC]], line: 3, type: ![[FUNC_TYPE:.*]], scopeLine: 3, spFlags: 
DISPFlagDefinition | DISPFlagOptimized, unit: ![[CU_LOC]])
@@ -215,7 +215,7 @@ llvm.func @func_decl_with_subprogram() -> (i32) 
loc(fused<#di_subprogram>["foo.m
 #di_file = #llvm.di_file<"foo.mlir" in "/test/">
 #di_compile_unit = #llvm.di_compile_unit<
   id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file,
-  producer = "MLIR", isOptimized = true, emissionKind = Full
+  producer = "MLIR", isOptimized = true, emissionKind = Full, 
isDebugInfoForProfiling = true
 >
 #di_subprogram = #llvm.di_subprogram<
   compileUnit = #di_compile_unit, scope = #di_file, name = "outer_func",
@@ -259,7 +259,7 @@ llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) 
{
 #di_file = #llvm.di_file<"foo.mlir" in "/test/">
 #di_compile_unit = #llvm.di_compile_unit<
   id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file,
-  producer = "MLIR", isOptimized = true, emissionKind = Full
+  producer = "MLIR", isOptimized = true, emissionKind = Full, 
isDebugInfoForProfiling = true
 >
 #di_subprogram = #llvm.di_subprogram<
   compileUnit = #di_compile_unit, scope = #di_file, name = "func",
@@ -288,7 +288,7 @@ llvm.func @func_without_subprogram(%0 : i32) {
 #di_file = #llvm.di_file<"foo.mlir" in "/test/">
 #di_compile_unit = #llvm.di_compile_unit<
   id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file,
-  producer = "MLIR", isOptimized = true, emissionKind = Full
+  producer = "MLIR", isOptimized = true, emissionKind = Full, 
isDebugInfoForProfiling = true
 >
 #di_subprogram = #llvm.di_subprogram<
   compileUnit = #di_compile_unit, scope = #di_file, name = "outer_func",
@@ -319,7 +319,7 @@ llvm.func @dbg_intrinsics_with_no_location(%arg0: i32) -> 
(i32) {
 // CHECK-DAG: !llvm.dbg.cu = !{{{.*}}}
 // CHECK-DAG: ![[FILE:.*]] = !DIFile(filename: "not", directory: "existence")
 // CHECK-DAG: ![[TYPE:.*]] = !DIBasicType(name: "uint64_t", size: 64, 
encoding: DW_ATE_unsigned)
-// CHECK-DAG: ![[SCOPE:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: FullDebug, globals: ![[GVALS:.*]])
+// CHECK-DAG: ![[SCOPE:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: FullDebug, globals: ![[GVALS:.*]], debugInfoForProfiling: true)
 // CHECK-DAG: ![[GVAR0:.*]] = distinct !DIGlobalVariable(name: 
"global_with_expr_1", linkageName: "global_with_expr_1", scope: ![[SCOPE]], 
file: ![[FILE]], line: 370, type: ![[TYPE]], isLocal: false, isDefinition: 
false)
 // CHECK-DAG: ![[GVAR1:.*]] = distinct !DIGlobalVariable(name: 
"global_with_expr_2", linkageName: "global_with_expr_2", scope: ![[SCOPE]], 
file: ![[FILE]], line: 371, type: ![[TYPE]], isLocal: true, isDefinition: true, 
align: 8)
 // CHECK-DAG: ![[GEXPR0:.*]] = !DIGlobalVariableExpression(var: ![[GVAR0]], 
expr: !DIExpression())
@@ -327,7 +327,7 @@ llvm.func @dbg_intrinsics_with_no_location(%arg0: i32) -> 
(i32) {
 // CHECK-DAG: ![[GVALS]] = !{![[GEXPR0]], ![[GEXPR1]]}
 
 #di_file_2 = #llvm.di_file<"not" in "existence">
-#di_compile_unit_2 = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_2, producer = "MLIR", isOptimized = true, 
emissionKind = Full>
+#di_compile_unit_2 = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_2, producer = "MLIR", isOptimized = true, 
emissionKind = Full, isDebugInfoForProfiling = true>
 #di_basic_type_2 = #llvm.di_basic_type<tag = DW_TAG_base_type, name = 
"uint64_t", sizeInBits = 64, encoding = DW_ATE_unsigned>
 llvm.mlir.global external @global_with_expr_1() {addr_space = 0 : i32, 
dbg_exprs = [#llvm.di_global_variable_expression<var = <scope = 
#di_compile_unit_2, name = "global_with_expr_1", linkageName = 
"global_with_expr_1", file = #di_file_2, line = 370, type = #di_basic_type_2>, 
expr = <>>]} : i64
 llvm.mlir.global external @global_with_expr_2() {addr_space = 0 : i32, 
dbg_exprs = [#llvm.di_global_variable_expression<var = <scope = 
#di_compile_unit_2, name = "global_with_expr_2", linkageName = 
"global_with_expr_2", file = #di_file_2, line = 371, type = #di_basic_type_2, 
isLocalToUnit = true, isDefined = true, alignInBits = 8>, expr = <>>]} : i64
@@ -339,14 +339,14 @@ llvm.mlir.global external @global_with_expr_2() 
{addr_space = 0 : i32, dbg_exprs
 // CHECK-DAG: !llvm.dbg.cu = !{{{.*}}}
 // CHECK-DAG: ![[FILE:.*]] = !DIFile(filename: "test.f90", directory: 
"existence")
 // CHECK-DAG: ![[TYPE:.*]] = !DIBasicType(name: "integer", size: 64, encoding: 
DW_ATE_signed)
-// CHECK-DAG: ![[SCOPE:.*]] = distinct !DICompileUnit(language: 
DW_LANG_Fortran95, file: ![[FILE]], producer: "MLIR", isOptimized: true, 
runtimeVersion: 0, emissionKind: FullDebug, globals: ![[GVALS:.*]])
+// CHECK-DAG: ![[SCOPE:.*]] = distinct !DICompileUnit(language: 
DW_LANG_Fortran95, file: ![[FILE]], producer: "MLIR", isOptimized: true, 
runtimeVersion: 0, emissionKind: FullDebug, globals: ![[GVALS:.*]], 
debugInfoForProfiling: true)
 // CHECK-DAG: ![[SCOPE1:.*]] = !DIModule(scope: ![[SCOPE]], name: "module2", 
file: ![[FILE]], line: 120)
 // CHECK-DAG: ![[GVAR:.*]] = distinct !DIGlobalVariable(name: "module_global", 
linkageName: "module_global", scope: ![[SCOPE1]], file: ![[FILE]], line: 121, 
type: ![[TYPE]], isLocal: false, isDefinition: true)
 // CHECK-DAG: ![[GEXPR:.*]] = !DIGlobalVariableExpression(var: ![[GVAR]], 
expr: !DIExpression())
 // CHECK-DAG: ![[GVALS]] = !{![[GEXPR]]}
 
 #di_file = #llvm.di_file<"test.f90" in "existence">
-#di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = 
DW_LANG_Fortran95, file = #di_file, producer = "MLIR", isOptimized = true, 
emissionKind = Full>
+#di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = 
DW_LANG_Fortran95, file = #di_file, producer = "MLIR", isOptimized = true, 
emissionKind = Full, isDebugInfoForProfiling = true>
 #di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", 
sizeInBits = 64, encoding = DW_ATE_signed>
 #di_module = #llvm.di_module<file = #di_file, scope = #di_compile_unit, name = 
"module2", configMacros = "", includePath = "", apinotes = "", line = 120, 
isDecl = false >
 llvm.mlir.global external @module_global() {dbg_exprs = 
[#llvm.di_global_variable_expression<var = <scope = #di_module, name = 
"module_global", linkageName = "module_global", file = #di_file, line = 121, 
type = #di_basic_type, isLocalToUnit = false, isDefined = true>, expr = <>>]} : 
i64
@@ -354,14 +354,14 @@ llvm.mlir.global external @module_global() {dbg_exprs = 
[#llvm.di_global_variabl
 // -----
 
 // CHECK: @func_global = external global i64, !dbg {{.*}}
-// CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}globals: 
![[GVALS:.*]])
+// CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}globals: 
![[GVALS:[0-9]+]], debugInfoForProfiling: true)
 // CHECK-DAG: ![[SP:.*]] = distinct !DISubprogram(name: 
"fn_with_gl"{{.*}}unit: ![[CU]])
 // CHECK-DAG: ![[GVAR:.*]] = distinct !DIGlobalVariable(name: 
"func_global"{{.*}}, scope: ![[SP]]{{.*}})
 // CHECK-DAG: ![[GEXPR:.*]] = !DIGlobalVariableExpression(var: ![[GVAR]], 
expr: !DIExpression())
 // CHECK-DAG: ![[GVALS]] = !{![[GEXPR]]}
 
 #file = #llvm.di_file<"test.f90" in "existence">
-#cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = 
DW_LANG_Fortran95, file = #file, producer = "MLIR", isOptimized = true, 
emissionKind = Full>
+#cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = 
DW_LANG_Fortran95, file = #file, producer = "MLIR", isOptimized = true, 
emissionKind = Full, isDebugInfoForProfiling = true>
 #ty1 = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", 
sizeInBits = 64, encoding = DW_ATE_signed>
 #sp = #llvm.di_subprogram<compileUnit = #cu, scope = #file, name = 
"fn_with_gl", file = #file, subprogramFlags = "Definition|Optimized">
 llvm.mlir.global @func_global() {dbg_exprs = 
[#llvm.di_global_variable_expression<var = <scope = #sp, name = "func_global", 
linkageName = "func_global", file = #file, line = 121, type = #ty1, 
isLocalToUnit = true, isDefined = true>, expr = <>>]} : i64
@@ -383,7 +383,7 @@ llvm.func @imp_fn() {
 #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = 
DW_CC_program>
 #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>,
   sourceLanguage = DW_LANG_Fortran95, file = #di_file, isOptimized = false,
-  emissionKind = Full>
+  emissionKind = Full, isDebugInfoForProfiling = false>
 #di_module_1 = #llvm.di_module<file = #di_file, scope = #di_compile_unit, name 
= "mod1">
 #di_module_2 = #llvm.di_module<file = #di_file, scope = #di_compile_unit, name 
= "mod2">
 #di_subprogram_self_rec = #llvm.di_subprogram<recId = distinct[1]<>>
@@ -429,10 +429,10 @@ llvm.mlir.global external constant @".str.1"() 
{addr_space = 0 : i32, dbg_exprs
 #di_file_1 = #llvm.di_file<"foo1.mlir" in "/test/">
 // CHECK-DAG: ![[FILE2:.*]] = !DIFile(filename: "foo2.mlir", directory: 
"/test/")
 #di_file_2 = #llvm.di_file<"foo2.mlir" in "/test/">
-// CHECK-DAG: ![[SCOPE2:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE2]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: DebugDirectivesOnly)
-#di_compile_unit_1 = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_1, producer = "MLIR", isOptimized = true, 
emissionKind = LineTablesOnly>
-// CHECK-DAG: ![[SCOPE1:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE1]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: LineTablesOnly)
-#di_compile_unit_2 = #llvm.di_compile_unit<id = distinct[1]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_2, producer = "MLIR", isOptimized = true, 
emissionKind = DebugDirectivesOnly>
+// CHECK-DAG: ![[SCOPE2:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE2]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: DebugDirectivesOnly, debugInfoForProfiling: true)
+#di_compile_unit_1 = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_1, producer = "MLIR", isOptimized = true, 
emissionKind = LineTablesOnly, isDebugInfoForProfiling = true>
+// CHECK-DAG: ![[SCOPE1:.*]] = distinct !DICompileUnit(language: DW_LANG_C, 
file: ![[FILE1]], producer: "MLIR", isOptimized: true, runtimeVersion: 0, 
emissionKind: LineTablesOnly, debugInfoForProfiling: true)
+#di_compile_unit_2 = #llvm.di_compile_unit<id = distinct[1]<>, sourceLanguage 
= DW_LANG_C, file = #di_file_2, producer = "MLIR", isOptimized = true, 
emissionKind = DebugDirectivesOnly, isDebugInfoForProfiling = true>
 #di_subprogram_1 = #llvm.di_subprogram<compileUnit = #di_compile_unit_1, scope 
= #di_file_1, name = "func1", file = #di_file_1, subprogramFlags = 
"Definition|Optimized">
 #di_subprogram_2 = #llvm.di_subprogram<compileUnit = #di_compile_unit_2, scope 
= #di_file_2, name = "func2", file = #di_file_2, subprogramFlags = 
"Definition|Optimized">
 
@@ -451,7 +451,7 @@ llvm.func @func_debug_directives() {
 // Common base nodes.
 #di_file = #llvm.di_file<"test.mlir" in "/">
 #di_null_type = #llvm.di_null_type
-#di_compile_unit = #llvm.di_compile_unit<id = distinct[1]<>, sourceLanguage = 
DW_LANG_C, file = #di_file, isOptimized = false, emissionKind = None>
+#di_compile_unit = #llvm.di_compile_unit<id = distinct[1]<>, sourceLanguage = 
DW_LANG_C, file = #di_file, isOptimized = false, emissionKind = None, 
isDebugInfoForProfiling = false>
 
 // Recursive type itself.
 #di_struct_self = #llvm.di_composite_type<recId = distinct[0]<>, isRecSelf = 
true>
@@ -560,7 +560,7 @@ llvm.mlir.global @global_variable() {dbg_exprs = 
[#di_global_variable_expression
 
 #file = #llvm.di_file<"test.f90" in "">
 #cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = 
DW_LANG_Fortran95,
-  file = #file, producer = "", isOptimized = false, emissionKind = Full>
+  file = #file, producer = "", isOptimized = false, emissionKind = Full, 
isDebugInfoForProfiling = false>
 #i32 = #llvm.di_basic_type<
   tag = DW_TAG_base_type, name = "integer",
   sizeInBits = 32, encoding = DW_ATE_signed
@@ -599,7 +599,7 @@ llvm.func @fn_with_composite() {
 #file = #llvm.di_file<"debug-info.ll" in "/">
 #cu = #llvm.di_compile_unit<id = distinct[1]<>,
  sourceLanguage = DW_LANG_Fortran95, file = #file, isOptimized = false,
- emissionKind = Full>
+ emissionKind = Full, isDebugInfoForProfiling = false>
 #exp1 =  #llvm.di_expression<[DW_OP_push_object_address, DW_OP_plus_uconst(16),
  DW_OP_deref]>
 #comp_ty1 = #llvm.di_composite_type<tag = DW_TAG_array_type,
@@ -662,7 +662,7 @@ llvm.func @subranges(%arg: !llvm.ptr) {
 #bt = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int", sizeInBits = 
32>
 #file = #llvm.di_file<"debug-info.ll" in "/">
 #cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C,
- file = #file, isOptimized = false, emissionKind = Full>
+ file = #file, isOptimized = false, emissionKind = Full, 
isDebugInfoForProfiling = false>
 #sp = #llvm.di_subprogram<compileUnit = #cu, scope = #file, name = "test",
  file = #file, subprogramFlags = Definition>
 #var = #llvm.di_local_variable<scope = #sp, name = "string_size", type = #bt, 
flags = Artificial>
@@ -693,7 +693,7 @@ llvm.func @string_ty(%arg0: !llvm.ptr) {
 #bt = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int", sizeInBits = 
32>
 #file = #llvm.di_file<"test.f90" in "">
 #cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C,
- file = #file, isOptimized = false, emissionKind = Full>
+ file = #file, isOptimized = false, emissionKind = Full, 
isDebugInfoForProfiling = false>
 #sp = #llvm.di_subprogram<compileUnit = #cu, scope = #file, name = "test",
  file = #file, subprogramFlags = Definition>
 #di_common_block = #llvm.di_common_block<scope = #sp, name = "block",
@@ -723,7 +723,7 @@ llvm.func @test() {
 #bt = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int", sizeInBits = 
32>
 #file = #llvm.di_file<"test.f90" in "">
 #cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C,
- file = #file, isOptimized = false, emissionKind = Full>
+ file = #file, isOptimized = false, emissionKind = Full, 
isDebugInfoForProfiling = false>
 #global_var = #llvm.di_global_variable<scope = #cu, name = "a",
  file = #file, line = 2, type = #bt>
 #var_expression = #llvm.di_global_variable_expression<var = #global_var,

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to