Skip to content

Commit b0687d3

Browse files
committed
[clang] Introduce CallGraphSection codegen option
This patch adds clang CodeGen option to emit callgraph section. The `-fexperimental-call-graph-section` Driver flag is introduced to control the `CallGraphSection` CodeGen option. Pull Request: llvm#117037
1 parent e1d45b1 commit b0687d3

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ CODEGENOPT(EnableNoundefAttrs, 1, 0, Benign) ///< Enable emitting `noundef` attr
7272
CODEGENOPT(DebugPassManager, 1, 0, Benign) ///< Prints debug information for the new
7373
///< pass manager.
7474
CODEGENOPT(DisableRedZone , 1, 0, Benign) ///< Set when -mno-red-zone is enabled.
75+
CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call graph section into the
76+
///< object file.
7577
CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in the case of
7678
///< '-g' + 'O>0' level.
7779
CODEGENOPT(IndirectTlsSegRefs, 1, 0, Benign) ///< Set when -mno-tls-direct-seg-refs

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4440,6 +4440,12 @@ defm data_sections : BoolFOption<"data-sections",
44404440
PosFlag<SetTrue, [], [ClangOption, CC1Option],
44414441
"Place each data in its own section">,
44424442
NegFlag<SetFalse>>;
4443+
defm experimental_call_graph_section
4444+
: BoolFOption<"experimental-call-graph-section",
4445+
CodeGenOpts<"CallGraphSection">, DefaultFalse,
4446+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
4447+
"Emit a call graph section">,
4448+
NegFlag<SetFalse>>;
44434449
defm stack_size_section : BoolFOption<"stack-size-section",
44444450
CodeGenOpts<"StackSizeSection">, DefaultFalse,
44454451
PosFlag<SetTrue, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
462462
Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
463463
Options.EmitAddrsig = CodeGenOpts.Addrsig;
464464
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
465+
Options.EmitCallGraphSection = CodeGenOpts.CallGraphSection;
465466
Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
466467
Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
467468
Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6478,6 +6478,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64786478
CmdArgs.push_back(A->getValue());
64796479
}
64806480

6481+
if (Args.hasFlag(options::OPT_fexperimental_call_graph_section,
6482+
options::OPT_fno_experimental_call_graph_section, false))
6483+
CmdArgs.push_back("-fexperimental-call-graph-section");
6484+
64816485
Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
64826486
options::OPT_fno_stack_size_section);
64836487

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
12691269
CmdArgs.push_back(
12701270
Args.MakeArgString(Twine(PluginOptPrefix) + "-stack-size-section"));
12711271

1272+
if (Args.hasFlag(options::OPT_fexperimental_call_graph_section,
1273+
options::OPT_fno_experimental_call_graph_section, false))
1274+
CmdArgs.push_back(
1275+
Args.MakeArgString(Twine(PluginOptPrefix) + "-call-graph-section"));
1276+
12721277
// Setup statistics file output.
12731278
SmallString<128> StatsFile = getStatsFileName(Args, Output, *Input, D);
12741279
if (!StatsFile.empty())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -fexperimental-call-graph-section %s 2>&1 | FileCheck --check-prefix=CALL-GRAPH-SECTION %s
2+
// RUN: %clang -### -fexperimental-call-graph-section -fno-experimental-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s
3+
4+
// CALL-GRAPH-SECTION: "-fexperimental-call-graph-section"
5+
// NO-CALL-GRAPH-SECTION-NOT: "-fexperimental-call-graph-section"

0 commit comments

Comments
 (0)