Skip to content

Commit afb1b5e

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

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
@@ -4512,6 +4512,12 @@ defm data_sections : BoolFOption<"data-sections",
45124512
PosFlag<SetTrue, [], [ClangOption, CC1Option],
45134513
"Place each data in its own section">,
45144514
NegFlag<SetFalse>>;
4515+
defm call_graph_section
4516+
: BoolFOption<"call-graph-section", CodeGenOpts<"CallGraphSection">,
4517+
DefaultFalse,
4518+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
4519+
"Emit a call graph section">,
4520+
NegFlag<SetFalse>>;
45154521
defm stack_size_section : BoolFOption<"stack-size-section",
45164522
CodeGenOpts<"StackSizeSection">, DefaultFalse,
45174523
PosFlag<SetTrue, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

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

clang/lib/Driver/ToolChains/Clang.cpp

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

6450+
if (Args.hasFlag(options::OPT_fcall_graph_section,
6451+
options::OPT_fno_call_graph_section, false))
6452+
CmdArgs.push_back("-fcall-graph-section");
6453+
64506454
Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
64516455
options::OPT_fno_stack_size_section);
64526456

clang/lib/Driver/ToolChains/CommonArgs.cpp

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

1275+
if (Args.hasFlag(options::OPT_fcall_graph_section,
1276+
options::OPT_fno_call_graph_section, false))
1277+
CmdArgs.push_back(
1278+
Args.MakeArgString(Twine(PluginOptPrefix) + "-call-graph-section"));
1279+
12751280
// Setup statistics file output.
12761281
SmallString<128> StatsFile = getStatsFileName(Args, Output, *Input, D);
12771282
if (!StatsFile.empty())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -fcall-graph-section %s 2>&1 | FileCheck --check-prefix=CALL-GRAPH-SECTION %s
2+
// RUN: %clang -### -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s
3+
4+
// CALL-GRAPH-SECTION: "-fcall-graph-section"
5+
// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section"

0 commit comments

Comments
 (0)