Skip to content

Commit 2b6eec5

Browse files
necipfazilPrabhuk
authored andcommitted
[CallSiteInfo][CallGraphSection] Extend CallSiteInfo with TypeId
Add TypeId field to CallSiteInfo for tracking callee type id. Read the type id in and out by the MIR parser/printer. With this patch, TypeId is only set from 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. Original RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-June/151044.html Updated RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-July/151739.html Reviewed By: morehouse Differential Revision: https://reviews.llvm.org/D107110?id=362890 Pull Request: llvm#87574
1 parent cc2ae13 commit 2b6eec5

File tree

7 files changed

+91
-5
lines changed

7 files changed

+91
-5
lines changed

llvm/include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ struct CallSiteInfo {
480480
MachineInstrLoc CallLocation;
481481
std::vector<ArgRegPair> ArgForwardingRegs;
482482

483+
/// Numeric callee type identifier used for call graph section.
484+
using TypeIdTy = std::optional<uint64_t>;
485+
TypeIdTy TypeId;
486+
483487
bool operator==(const CallSiteInfo &Other) const {
484488
return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
485489
CallLocation.Offset == Other.CallLocation.Offset;
@@ -508,6 +512,7 @@ template <> struct MappingTraits<CallSiteInfo> {
508512
YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
509513
YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
510514
std::vector<CallSiteInfo::ArgRegPair>());
515+
YamlIO.mapOptional("typeId", CSInfo.TypeId);
511516
}
512517

513518
static const bool flow = true;

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,17 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
485485
struct CallSiteInfo {
486486
/// Vector of call argument and its forwarding register.
487487
SmallVector<ArgRegPair, 1> ArgRegPairs;
488+
489+
/// Callee type id.
490+
ConstantInt *TypeId = nullptr;
488491
};
489492

490493
private:
491494
Delegate *TheDelegate = nullptr;
492495
GISelChangeObserver *Observer = nullptr;
493496

494497
using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;
495-
/// Map a call instruction to call site arguments forwarding info.
498+
/// Map a call instruction to call site arguments forwarding and type id.
496499
CallSiteInfoMap CallSitesInfo;
497500

498501
/// A helper function that returns call site info for a give call
@@ -1346,7 +1349,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
13461349
});
13471350
}
13481351

1349-
/// Start tracking the arguments passed to the call \p CallI.
1352+
/// Start tracking the arguments passed to the call \p CallI and call type.
13501353
void addCallSiteInfo(const MachineInstr *CallI, CallSiteInfo &&CallInfo) {
13511354
assert(CallI->isCandidateForCallSiteEntry());
13521355
bool Inserted =

llvm/lib/CodeGen/MIRParser/MIRParser.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,18 @@ bool MIRParserImpl::initializeCallSiteInfo(
427427
return error(Error, ArgRegPair.Reg.SourceRange);
428428
CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
429429
}
430+
if (YamlCSInfo.TypeId.has_value()) {
431+
IntegerType *Int64Ty = Type::getInt64Ty(Context);
432+
CSInfo.TypeId = ConstantInt::get(Int64Ty, YamlCSInfo.TypeId.value(),
433+
/*isSigned=*/false);
434+
}
430435

431-
if (TM.Options.EmitCallSiteInfo)
436+
if (TM.Options.EmitCallSiteInfo || TM.Options.EmitCallGraphSection)
432437
MF.addCallSiteInfo(&*CallI, std::move(CSInfo));
433438
}
434439

435-
if (YamlMF.CallSitesInfo.size() && !TM.Options.EmitCallSiteInfo)
440+
if (YamlMF.CallSitesInfo.size() &&
441+
!(TM.Options.EmitCallSiteInfo || TM.Options.EmitCallGraphSection))
436442
return error(Twine("Call site info provided but not used"));
437443
return false;
438444
}

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ void MIRPrinter::convertCallSiteObjects(yaml::MachineFunction &YMF,
548548
printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
549549
YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
550550
}
551+
// Get type id.
552+
if (CSInfo.second.TypeId)
553+
YmlCS.TypeId = CSInfo.second.TypeId->getZExtValue();
551554
YMF.CallSitesInfo.push_back(YmlCS);
552555
}
553556

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
878878
assert(MI->isCandidateForCallSiteEntry() &&
879879
"Call site info refers only to call (MI) candidates");
880880

881-
if (!Target.Options.EmitCallSiteInfo)
881+
if (!Target.Options.EmitCallSiteInfo && !Target.Options.EmitCallGraphSection)
882882
return CallSitesInfo.end();
883883
return CallSitesInfo.find(MI);
884884
}

llvm/test/Bitcode/operand-bundles-bc-analyzer.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
; CHECK-NEXT: <OPERAND_BUNDLE_TAG
1414
; CHECK-NEXT: <OPERAND_BUNDLE_TAG
1515
; CHECK-NEXT: <OPERAND_BUNDLE_TAG
16+
; CHECK-NEXT: <OPERAND_BUNDLE_TAG
1617
; CHECK-NEXT: </OPERAND_BUNDLE_TAGS_BLOCK
1718

1819
; CHECK: <FUNCTION_BLOCK
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
; ModuleID = 'test.ll'
12+
source_filename = "test.ll"
13+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
14+
target triple = "x86_64-unknown-linux-gnu"
15+
16+
define dso_local void @foo(i8 signext %a) {
17+
entry:
18+
ret void
19+
}
20+
21+
define dso_local i32 @main() {
22+
entry:
23+
%retval = alloca i32, align 4
24+
%fp = alloca void (i8)*, align 8
25+
store i32 0, i32* %retval, align 4
26+
store void (i8)* @foo, void (i8)** %fp, align 8
27+
%0 = load void (i8)*, void (i8)** %fp, align 8
28+
call void %0(i8 signext 97)
29+
ret i32 0
30+
}
31+
32+
...
33+
---
34+
name: foo
35+
tracksRegLiveness: true
36+
body: |
37+
bb.0.entry:
38+
RET 0
39+
40+
...
41+
---
42+
name: main
43+
tracksRegLiveness: true
44+
stack:
45+
- { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4,
46+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
47+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
48+
- { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8,
49+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
50+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
51+
callSites:
52+
- { bb: 0, offset: 6, fwdArgRegs: [], typeId:
53+
123456789 }
54+
body: |
55+
bb.0.entry:
56+
MOV32mi %stack.0.retval, 1, $noreg, 0, $noreg, 0 :: (store (s32) into %ir.retval)
57+
MOV64mi32 %stack.1.fp, 1, $noreg, 0, $noreg, @foo :: (store (s64) into %ir.fp)
58+
%0:gr64 = MOV32ri64 @foo
59+
ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
60+
%1:gr32 = MOV32ri 97
61+
$edi = COPY %1
62+
CALL64r killed %0, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp
63+
ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
64+
%2:gr32 = MOV32r0 implicit-def dead $eflags
65+
$eax = COPY %2
66+
RET 0, $eax
67+
68+
...

0 commit comments

Comments
 (0)