[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj edited https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
@@ -124,6 +128,8 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions. bool NSWOnLoopVarInc = true; ///< Add nsw flag to loop variable increments. bool EnableOpenMP = false; ///< Enable OpenMP lowering. + std::string InstrumentFunctionsEntry = ""; anchuraj wrote: Thank you for the review. I missed adding the description . Will update it. https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj created https://github.com/llvm/llvm-project/pull/137996 `f-instrument-functions` helps in profiling functions. This PR adds support for the option by defining values for function attributes `instrument_function_entry` and `instrument_function_exit`. LLVM Backend adds calls to the functions `__cyg_profile_func_enter` and `__cyg_profile_func_exit` which can be intercepted by user to profile every function. LLVM Dialect support is added in https://github.com/llvm/llvm-project/pull/137856. These changes are to support https://github.com/llvm/llvm-project/issues/112330. >From bb486c5e7cbe7b1c4a87469e06ca51bf49ddd081 Mon Sep 17 00:00:00 2001 From: Anchu Rajendran Date: Tue, 29 Apr 2025 14:41:55 -0500 Subject: [PATCH] [flang] Support flag -finstrument-functions --- clang/include/clang/Driver/Options.td| 10 ++ clang/lib/Driver/ToolChains/Flang.cpp| 3 ++- flang/include/flang/Frontend/CodeGenOptions.h| 2 ++ flang/include/flang/Optimizer/Transforms/Passes.td | 8 flang/include/flang/Tools/CrossToolHelpers.h | 8 +++- flang/lib/Frontend/CompilerInvocation.cpp| 4 flang/lib/Optimizer/Passes/Pipelines.cpp | 3 ++- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 10 ++ flang/test/Driver/func-attr-instrument-functions.f90 | 9 + 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 flang/test/Driver/func-attr-instrument-functions.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c0f469e04375c..8a3b74c397b95 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2824,10 +2824,12 @@ def finput_charset_EQ : Joined<["-"], "finput-charset=">, Visibility<[ClangOption, FlangOption, FC1Option]>, Group, HelpText<"Specify the default character set for source files">; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group; -def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, - Visibility<[ClangOption, CC1Option]>, - HelpText<"Generate calls to instrument function entry and exit">, - MarshallingInfoFlag>; +def finstrument_functions +: Flag<["-"], "finstrument-functions">, + Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + HelpText<"Generate calls to instrument function entry and exit">, + MarshallingInfoFlag>; def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Like -finstrument-functions, but insert the calls after inlining">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index e9d5a844ab073..a407e295c09bd 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -128,7 +128,8 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { options::OPT_std_EQ, options::OPT_W_Joined, options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ, options::OPT_funderscoring, options::OPT_fno_underscoring, - options::OPT_funsigned, options::OPT_fno_unsigned}); + options::OPT_funsigned, options::OPT_fno_unsigned, + options::OPT_finstrument_functions}); llvm::codegenoptions::DebugInfoKind DebugInfoKind; if (Args.hasArg(options::OPT_gN_Group)) { diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..93711ae382f17 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; + // The RemarkKind enum class and OptRemark struct are identical to what Clang // has // TODO: Share with clang instead of re-implementing here diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c59416fa2c024..9b6919eec3f73 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -393,6 +393,14 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::All, "All", ""), clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::Reserved, "Reserved", "") )}]>, + Option<"instrumentFunctionEntry", "instrument-function-entry", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "entry">, + Option<"instrumentFunctio
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj updated https://github.com/llvm/llvm-project/pull/137996 >From bb486c5e7cbe7b1c4a87469e06ca51bf49ddd081 Mon Sep 17 00:00:00 2001 From: Anchu Rajendran Date: Tue, 29 Apr 2025 14:41:55 -0500 Subject: [PATCH 1/2] [flang] Support flag -finstrument-functions --- clang/include/clang/Driver/Options.td| 10 ++ clang/lib/Driver/ToolChains/Flang.cpp| 3 ++- flang/include/flang/Frontend/CodeGenOptions.h| 2 ++ flang/include/flang/Optimizer/Transforms/Passes.td | 8 flang/include/flang/Tools/CrossToolHelpers.h | 8 +++- flang/lib/Frontend/CompilerInvocation.cpp| 4 flang/lib/Optimizer/Passes/Pipelines.cpp | 3 ++- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 10 ++ flang/test/Driver/func-attr-instrument-functions.f90 | 9 + 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 flang/test/Driver/func-attr-instrument-functions.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c0f469e04375c..8a3b74c397b95 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2824,10 +2824,12 @@ def finput_charset_EQ : Joined<["-"], "finput-charset=">, Visibility<[ClangOption, FlangOption, FC1Option]>, Group, HelpText<"Specify the default character set for source files">; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group; -def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, - Visibility<[ClangOption, CC1Option]>, - HelpText<"Generate calls to instrument function entry and exit">, - MarshallingInfoFlag>; +def finstrument_functions +: Flag<["-"], "finstrument-functions">, + Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + HelpText<"Generate calls to instrument function entry and exit">, + MarshallingInfoFlag>; def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Like -finstrument-functions, but insert the calls after inlining">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index e9d5a844ab073..a407e295c09bd 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -128,7 +128,8 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { options::OPT_std_EQ, options::OPT_W_Joined, options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ, options::OPT_funderscoring, options::OPT_fno_underscoring, - options::OPT_funsigned, options::OPT_fno_unsigned}); + options::OPT_funsigned, options::OPT_fno_unsigned, + options::OPT_finstrument_functions}); llvm::codegenoptions::DebugInfoKind DebugInfoKind; if (Args.hasArg(options::OPT_gN_Group)) { diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..93711ae382f17 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; + // The RemarkKind enum class and OptRemark struct are identical to what Clang // has // TODO: Share with clang instead of re-implementing here diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c59416fa2c024..9b6919eec3f73 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -393,6 +393,14 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::All, "All", ""), clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::Reserved, "Reserved", "") )}]>, + Option<"instrumentFunctionEntry", "instrument-function-entry", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "entry">, + Option<"instrumentFunctionExit", "instrument-function-exit", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "exit">, Option<"noInfsFPMath", "no-infs-fp-math", "bool", /*default=*/"false", "Set the no-infs-fp-math attribute on functions in the module.">, Option<"noNaNsFPMath", "no-nans-fp-math", "bool", /*default=*/"false", diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolH
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj updated https://github.com/llvm/llvm-project/pull/137996 >From bb486c5e7cbe7b1c4a87469e06ca51bf49ddd081 Mon Sep 17 00:00:00 2001 From: Anchu Rajendran Date: Tue, 29 Apr 2025 14:41:55 -0500 Subject: [PATCH 1/3] [flang] Support flag -finstrument-functions --- clang/include/clang/Driver/Options.td| 10 ++ clang/lib/Driver/ToolChains/Flang.cpp| 3 ++- flang/include/flang/Frontend/CodeGenOptions.h| 2 ++ flang/include/flang/Optimizer/Transforms/Passes.td | 8 flang/include/flang/Tools/CrossToolHelpers.h | 8 +++- flang/lib/Frontend/CompilerInvocation.cpp| 4 flang/lib/Optimizer/Passes/Pipelines.cpp | 3 ++- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 10 ++ flang/test/Driver/func-attr-instrument-functions.f90 | 9 + 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 flang/test/Driver/func-attr-instrument-functions.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c0f469e04375c..8a3b74c397b95 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2824,10 +2824,12 @@ def finput_charset_EQ : Joined<["-"], "finput-charset=">, Visibility<[ClangOption, FlangOption, FC1Option]>, Group, HelpText<"Specify the default character set for source files">; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group; -def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, - Visibility<[ClangOption, CC1Option]>, - HelpText<"Generate calls to instrument function entry and exit">, - MarshallingInfoFlag>; +def finstrument_functions +: Flag<["-"], "finstrument-functions">, + Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + HelpText<"Generate calls to instrument function entry and exit">, + MarshallingInfoFlag>; def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Like -finstrument-functions, but insert the calls after inlining">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index e9d5a844ab073..a407e295c09bd 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -128,7 +128,8 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { options::OPT_std_EQ, options::OPT_W_Joined, options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ, options::OPT_funderscoring, options::OPT_fno_underscoring, - options::OPT_funsigned, options::OPT_fno_unsigned}); + options::OPT_funsigned, options::OPT_fno_unsigned, + options::OPT_finstrument_functions}); llvm::codegenoptions::DebugInfoKind DebugInfoKind; if (Args.hasArg(options::OPT_gN_Group)) { diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..93711ae382f17 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; + // The RemarkKind enum class and OptRemark struct are identical to what Clang // has // TODO: Share with clang instead of re-implementing here diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c59416fa2c024..9b6919eec3f73 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -393,6 +393,14 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::All, "All", ""), clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::Reserved, "Reserved", "") )}]>, + Option<"instrumentFunctionEntry", "instrument-function-entry", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "entry">, + Option<"instrumentFunctionExit", "instrument-function-exit", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "exit">, Option<"noInfsFPMath", "no-infs-fp-math", "bool", /*default=*/"false", "Set the no-infs-fp-math attribute on functions in the module.">, Option<"noNaNsFPMath", "no-nans-fp-math", "bool", /*default=*/"false", diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolH
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
@@ -310,6 +310,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, args.filtered(clang::driver::options::OPT_fembed_offload_object_EQ)) opts.OffloadObjects.push_back(a->getValue()); + if (args.hasFlag(clang::driver::options::OPT_finstrument_functions, anchuraj wrote: Sure I dint notice the part it takes two flags as input https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj updated https://github.com/llvm/llvm-project/pull/137996 >From bb486c5e7cbe7b1c4a87469e06ca51bf49ddd081 Mon Sep 17 00:00:00 2001 From: Anchu Rajendran Date: Tue, 29 Apr 2025 14:41:55 -0500 Subject: [PATCH 1/3] [flang] Support flag -finstrument-functions --- clang/include/clang/Driver/Options.td| 10 ++ clang/lib/Driver/ToolChains/Flang.cpp| 3 ++- flang/include/flang/Frontend/CodeGenOptions.h| 2 ++ flang/include/flang/Optimizer/Transforms/Passes.td | 8 flang/include/flang/Tools/CrossToolHelpers.h | 8 +++- flang/lib/Frontend/CompilerInvocation.cpp| 4 flang/lib/Optimizer/Passes/Pipelines.cpp | 3 ++- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 10 ++ flang/test/Driver/func-attr-instrument-functions.f90 | 9 + 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 flang/test/Driver/func-attr-instrument-functions.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c0f469e04375c..8a3b74c397b95 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2824,10 +2824,12 @@ def finput_charset_EQ : Joined<["-"], "finput-charset=">, Visibility<[ClangOption, FlangOption, FC1Option]>, Group, HelpText<"Specify the default character set for source files">; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group; -def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, - Visibility<[ClangOption, CC1Option]>, - HelpText<"Generate calls to instrument function entry and exit">, - MarshallingInfoFlag>; +def finstrument_functions +: Flag<["-"], "finstrument-functions">, + Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + HelpText<"Generate calls to instrument function entry and exit">, + MarshallingInfoFlag>; def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Like -finstrument-functions, but insert the calls after inlining">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index e9d5a844ab073..a407e295c09bd 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -128,7 +128,8 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { options::OPT_std_EQ, options::OPT_W_Joined, options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ, options::OPT_funderscoring, options::OPT_fno_underscoring, - options::OPT_funsigned, options::OPT_fno_unsigned}); + options::OPT_funsigned, options::OPT_fno_unsigned, + options::OPT_finstrument_functions}); llvm::codegenoptions::DebugInfoKind DebugInfoKind; if (Args.hasArg(options::OPT_gN_Group)) { diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..93711ae382f17 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; + // The RemarkKind enum class and OptRemark struct are identical to what Clang // has // TODO: Share with clang instead of re-implementing here diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c59416fa2c024..9b6919eec3f73 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -393,6 +393,14 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::All, "All", ""), clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::Reserved, "Reserved", "") )}]>, + Option<"instrumentFunctionEntry", "instrument-function-entry", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "entry">, + Option<"instrumentFunctionExit", "instrument-function-exit", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "exit">, Option<"noInfsFPMath", "no-infs-fp-math", "bool", /*default=*/"false", "Set the no-infs-fp-math attribute on functions in the module.">, Option<"noNaNsFPMath", "no-nans-fp-math", "bool", /*default=*/"false", diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolH
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
@@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; anchuraj wrote: Updated. Thank you! https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj closed https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
https://github.com/anchuraj updated https://github.com/llvm/llvm-project/pull/137996 >From bb486c5e7cbe7b1c4a87469e06ca51bf49ddd081 Mon Sep 17 00:00:00 2001 From: Anchu Rajendran Date: Tue, 29 Apr 2025 14:41:55 -0500 Subject: [PATCH 1/4] [flang] Support flag -finstrument-functions --- clang/include/clang/Driver/Options.td| 10 ++ clang/lib/Driver/ToolChains/Flang.cpp| 3 ++- flang/include/flang/Frontend/CodeGenOptions.h| 2 ++ flang/include/flang/Optimizer/Transforms/Passes.td | 8 flang/include/flang/Tools/CrossToolHelpers.h | 8 +++- flang/lib/Frontend/CompilerInvocation.cpp| 4 flang/lib/Optimizer/Passes/Pipelines.cpp | 3 ++- flang/lib/Optimizer/Transforms/FunctionAttr.cpp | 10 ++ flang/test/Driver/func-attr-instrument-functions.f90 | 9 + 9 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 flang/test/Driver/func-attr-instrument-functions.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c0f469e04375c..8a3b74c397b95 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2824,10 +2824,12 @@ def finput_charset_EQ : Joined<["-"], "finput-charset=">, Visibility<[ClangOption, FlangOption, FC1Option]>, Group, HelpText<"Specify the default character set for source files">; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group; -def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, - Visibility<[ClangOption, CC1Option]>, - HelpText<"Generate calls to instrument function entry and exit">, - MarshallingInfoFlag>; +def finstrument_functions +: Flag<["-"], "finstrument-functions">, + Group, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + HelpText<"Generate calls to instrument function entry and exit">, + MarshallingInfoFlag>; def finstrument_functions_after_inlining : Flag<["-"], "finstrument-functions-after-inlining">, Group, Visibility<[ClangOption, CC1Option]>, HelpText<"Like -finstrument-functions, but insert the calls after inlining">, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index e9d5a844ab073..a407e295c09bd 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -128,7 +128,8 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { options::OPT_std_EQ, options::OPT_W_Joined, options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ, options::OPT_funderscoring, options::OPT_fno_underscoring, - options::OPT_funsigned, options::OPT_fno_unsigned}); + options::OPT_funsigned, options::OPT_fno_unsigned, + options::OPT_finstrument_functions}); llvm::codegenoptions::DebugInfoKind DebugInfoKind; if (Args.hasArg(options::OPT_gN_Group)) { diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 2b4e823b3fef4..93711ae382f17 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; + // The RemarkKind enum class and OptRemark struct are identical to what Clang // has // TODO: Share with clang instead of re-implementing here diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c59416fa2c024..9b6919eec3f73 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -393,6 +393,14 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> { clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::All, "All", ""), clEnumValN(mlir::LLVM::framePointerKind::FramePointerKind::Reserved, "Reserved", "") )}]>, + Option<"instrumentFunctionEntry", "instrument-function-entry", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "entry">, + Option<"instrumentFunctionExit", "instrument-function-exit", + "std::string", /*default=*/"", + "Sets the name of the profiling function called during function " + "exit">, Option<"noInfsFPMath", "no-infs-fp-math", "bool", /*default=*/"false", "Set the no-infs-fp-math attribute on functions in the module.">, Option<"noNaNsFPMath", "no-nans-fp-math", "bool", /*default=*/"false", diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolH
[clang] [flang] [flang][flang-driver] Support flag -finstrument-functions (PR #137996)
@@ -81,6 +81,8 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Options to add to the linker for the object file std::vector DependentLibs; + bool InstrumentFunctions{false}; anchuraj wrote: Thank you for the review @tblah . Updated. https://github.com/llvm/llvm-project/pull/137996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits