Skip to content

Commit cc8a72b

Browse files
Prabhukakadutta
authored andcommitted
[clang] Introduce CallGraphSection codegen option (llvm#117037)
1 parent edb1e0f commit cc8a72b

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
@@ -4534,6 +4534,12 @@ defm data_sections : BoolFOption<"data-sections",
45344534
PosFlag<SetTrue, [], [ClangOption, CC1Option],
45354535
"Place each data in its own section">,
45364536
NegFlag<SetFalse>>;
4537+
defm experimental_call_graph_section
4538+
: BoolFOption<"experimental-call-graph-section",
4539+
CodeGenOpts<"CallGraphSection">, DefaultFalse,
4540+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
4541+
"Emit a call graph section">,
4542+
NegFlag<SetFalse>>;
45374543
defm stack_size_section : BoolFOption<"stack-size-section",
45384544
CodeGenOpts<"StackSizeSection">, DefaultFalse,
45394545
PosFlag<SetTrue, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
473473
Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
474474
Options.EmitAddrsig = CodeGenOpts.Addrsig;
475475
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
476+
Options.EmitCallGraphSection = CodeGenOpts.CallGraphSection;
476477
Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
477478
Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
478479
Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;

clang/lib/Driver/ToolChains/Clang.cpp

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

6445+
if (Args.hasFlag(options::OPT_fexperimental_call_graph_section,
6446+
options::OPT_fno_experimental_call_graph_section, false))
6447+
CmdArgs.push_back("-fexperimental-call-graph-section");
6448+
64456449
Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
64466450
options::OPT_fno_stack_size_section);
64476451

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_fexperimental_call_graph_section,
1276+
options::OPT_fno_experimental_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 -### -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)