Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 919f0cd

Browse filesBrowse files
committed
[llvm] Add option to emit callgraph section
Introducing `EnableCallGraphSection` target option. The cl::opt flag to enable this option is `--call-graph-section`. Adding TypeId field to CallSiteInfo for tracking callee type id. Read the type id in and out by the MIR parser/printer. TypeId is only set for callSites.typeId fields from MIR inputs. An upcoming patch will pass type ids from the clang front-end, and they will be read and set while lowering in the LLVM middle-end. Pull Request: llvm#87574
1 parent ce5ae4a commit 919f0cd
Copy full SHA for 919f0cd

File tree

9 files changed

+96
-7
lines changed
Filter options

9 files changed

+96
-7
lines changed

‎llvm/include/llvm/CodeGen/CommandFlags.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/CodeGen/CommandFlags.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ bool getEnableStackSizeSection();
132132

133133
bool getEnableAddrsig();
134134

135+
bool getEnableCallGraphSection();
136+
135137
bool getEmitCallSiteInfo();
136138

137139
bool getEnableMachineFunctionSplitter();

‎llvm/include/llvm/CodeGen/MIRYamlMapping.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/CodeGen/MIRYamlMapping.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ struct CallSiteInfo {
483483
MachineInstrLoc CallLocation;
484484
std::vector<ArgRegPair> ArgForwardingRegs;
485485

486+
/// Numeric callee type identifier used for call graph section.
487+
using TypeIdTy = std::optional<uint64_t>;
488+
TypeIdTy TypeId;
489+
486490
bool operator==(const CallSiteInfo &Other) const {
487491
return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
488492
CallLocation.Offset == Other.CallLocation.Offset;
@@ -511,6 +515,7 @@ template <> struct MappingTraits<CallSiteInfo> {
511515
YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
512516
YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
513517
std::vector<CallSiteInfo::ArgRegPair>());
518+
YamlIO.mapOptional("typeId", CSInfo.TypeId);
514519
}
515520

516521
static const bool flow = true;

‎llvm/include/llvm/CodeGen/MachineFunction.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/CodeGen/MachineFunction.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ class LLVM_ABI MachineFunction {
496496
struct CallSiteInfo {
497497
/// Vector of call argument and its forwarding register.
498498
SmallVector<ArgRegPair, 1> ArgRegPairs;
499+
500+
/// Callee type id.
501+
ConstantInt *TypeId = nullptr;
499502
};
500503

501504
struct CalledGlobalInfo {

‎llvm/include/llvm/Target/TargetOptions.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/Target/TargetOptions.h
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ namespace llvm {
147147
EmitStackSizeSection(false), EnableMachineOutliner(false),
148148
EnableMachineFunctionSplitter(false),
149149
EnableStaticDataPartitioning(false), SupportsDefaultOutlining(false),
150-
EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
151-
SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
152-
ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
153-
XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
150+
EmitAddrsig(false), BBAddrMap(false), EmitCallGraphSection(false),
151+
EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
152+
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
153+
ForceDwarfFrameSection(false), XRayFunctionIndex(true),
154+
DebugStrictDwarf(false), Hotpatch(false),
154155
PPCGenScalarMASSEntries(false), JMCInstrument(false),
155156
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
156157
VerifyArgABICompliance(true),
@@ -333,6 +334,9 @@ namespace llvm {
333334
/// to selectively generate basic block sections.
334335
std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
335336

337+
/// Emit section containing call graph metadata.
338+
unsigned EmitCallGraphSection : 1;
339+
336340
/// The flag enables call site info production. It is used only for debug
337341
/// info, and it is restricted only to optimized code. This can be used for
338342
/// something else, so that should be controlled in the frontend.

‎llvm/lib/CodeGen/CommandFlags.cpp

Copy file name to clipboardExpand all lines: llvm/lib/CodeGen/CommandFlags.cpp
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ CGOPT(EABI, EABIVersion)
101101
CGOPT(DebuggerKind, DebuggerTuningOpt)
102102
CGOPT(bool, EnableStackSizeSection)
103103
CGOPT(bool, EnableAddrsig)
104+
CGOPT(bool, EnableCallGraphSection)
104105
CGOPT(bool, EmitCallSiteInfo)
105106
CGOPT(bool, EnableMachineFunctionSplitter)
106107
CGOPT(bool, EnableStaticDataPartitioning)
@@ -461,6 +462,11 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
461462
cl::init(false));
462463
CGBINDOPT(EnableAddrsig);
463464

465+
static cl::opt<bool> EnableCallGraphSection(
466+
"call-graph-section", cl::desc("Emit a call graph section"),
467+
cl::init(false));
468+
CGBINDOPT(EnableCallGraphSection);
469+
464470
static cl::opt<bool> EmitCallSiteInfo(
465471
"emit-call-site-info",
466472
cl::desc(
@@ -595,6 +601,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
595601
Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
596602
Options.EnableStaticDataPartitioning = getEnableStaticDataPartitioning();
597603
Options.EmitAddrsig = getEnableAddrsig();
604+
Options.EmitCallGraphSection = getEnableCallGraphSection();
598605
Options.EmitCallSiteInfo = getEmitCallSiteInfo();
599606
Options.EnableDebugEntryValues = getEnableDebugEntryValues();
600607
Options.ForceDwarfFrameSection = getForceDwarfFrameSection();

‎llvm/lib/CodeGen/MIRParser/MIRParser.cpp

Copy file name to clipboardExpand all lines: llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,18 @@ bool MIRParserImpl::initializeCallSiteInfo(
504504
return error(Error, ArgRegPair.Reg.SourceRange);
505505
CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
506506
}
507+
if (YamlCSInfo.TypeId.has_value()) {
508+
IntegerType *Int64Ty = Type::getInt64Ty(Context);
509+
CSInfo.TypeId = ConstantInt::get(Int64Ty, YamlCSInfo.TypeId.value(),
510+
/*isSigned=*/false);
511+
}
507512

508-
if (TM.Options.EmitCallSiteInfo)
513+
if (TM.Options.EmitCallSiteInfo || TM.Options.EmitCallGraphSection)
509514
MF.addCallSiteInfo(&*CallI, std::move(CSInfo));
510515
}
511516

512-
if (YamlMF.CallSitesInfo.size() && !TM.Options.EmitCallSiteInfo)
517+
if (YamlMF.CallSitesInfo.size() &&
518+
!(TM.Options.EmitCallSiteInfo || TM.Options.EmitCallGraphSection))
513519
return error(Twine("Call site info provided but not used"));
514520
return false;
515521
}

‎llvm/lib/CodeGen/MIRPrinter.cpp

Copy file name to clipboardExpand all lines: llvm/lib/CodeGen/MIRPrinter.cpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ void MIRPrinter::convertCallSiteObjects(yaml::MachineFunction &YMF,
576576
printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
577577
YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
578578
}
579+
// Get type id.
580+
if (CSInfo.second.TypeId)
581+
YmlCS.TypeId = CSInfo.second.TypeId->getZExtValue();
579582
YMF.CallSitesInfo.push_back(std::move(YmlCS));
580583
}
581584

‎llvm/lib/CodeGen/MachineFunction.cpp

Copy file name to clipboardExpand all lines: llvm/lib/CodeGen/MachineFunction.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
920920
assert(MI->isCandidateForAdditionalCallInfo() &&
921921
"Call site info refers only to call (MI) candidates");
922922

923-
if (!Target.Options.EmitCallSiteInfo)
923+
if (!Target.Options.EmitCallSiteInfo && !Target.Options.EmitCallGraphSection)
924924
return CallSitesInfo.end();
925925
return CallSitesInfo.find(MI);
926926
}
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Test MIR printer and parser for type id field in callSites. It is used
2+
# for propogating call site type identifiers to emit in the call graph section.
3+
4+
# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s
5+
# CHECK: name: main
6+
# CHECK: callSites:
7+
# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId:
8+
# CHECK-NEXT: 123456789 }
9+
10+
--- |
11+
define dso_local void @foo(i8 signext %a) {
12+
entry:
13+
ret void
14+
}
15+
16+
define dso_local i32 @main() {
17+
entry:
18+
%retval = alloca i32, align 4
19+
%fp = alloca ptr, align 8
20+
store i32 0, ptr %retval, align 4
21+
store ptr @foo, ptr %fp, align 8
22+
%0 = load ptr, ptr %fp, align 8
23+
call void %0(i8 signext 97)
24+
ret i32 0
25+
}
26+
27+
...
28+
---
29+
name: foo
30+
tracksRegLiveness: true
31+
body: |
32+
bb.0.entry:
33+
RET 0
34+
35+
...
36+
---
37+
name: main
38+
tracksRegLiveness: true
39+
stack:
40+
- { id: 0, name: retval, size: 4, alignment: 4 }
41+
- { id: 1, name: fp, size: 8, alignment: 8 }
42+
callSites:
43+
- { bb: 0, offset: 6, fwdArgRegs: [], typeId:
44+
123456789 }
45+
body: |
46+
bb.0.entry:
47+
MOV32mi %stack.0.retval, 1, $noreg, 0, $noreg, 0 :: (store (s32) into %ir.retval)
48+
MOV64mi32 %stack.1.fp, 1, $noreg, 0, $noreg, @foo :: (store (s64) into %ir.fp)
49+
%0:gr64 = MOV32ri64 @foo
50+
ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
51+
%1:gr32 = MOV32ri 97
52+
$edi = COPY %1
53+
CALL64r killed %0, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp
54+
ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
55+
%2:gr32 = MOV32r0 implicit-def dead $eflags
56+
$eax = COPY %2
57+
RET 0, $eax
58+
59+
...

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.