Skip to content

[llvm] Extract and propagate callee_type metadata #87575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
d2d56f4
[𝘀𝗽𝗿] changes to main this commit is based on
necipfazil Apr 3, 2024
f805007
[𝘀𝗽𝗿] initial version
necipfazil Apr 3, 2024
058a100
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2024
2a17e59
Rebased on top of main
necipfazil Apr 24, 2024
3065b9b
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 29, 2024
a998707
dyn_cast to isa
necipfazil Apr 29, 2024
c2f27b3
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 1, 2024
4a36a0c
Rebased on upstream main.
necipfazil May 1, 2024
58e5ecf
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Nov 14, 2024
851f62e
Rebase patchset
necipfazil Nov 14, 2024
966ac5a
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Nov 14, 2024
460f02a
Update inline comment as suggested.
necipfazil Nov 14, 2024
1a8d810
Fixed the tests and addressed most of the review comments.
necipfazil Nov 19, 2024
a993e6d
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Nov 20, 2024
4f31680
Rebase on top of upstream main. Remove opt has_value, value use.
necipfazil Nov 20, 2024
bb9d714
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Nov 20, 2024
086baf0
Break clang and llvm parts into separate commits.
necipfazil Nov 20, 2024
746e03c
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Dec 10, 2024
5d09cf0
Address review comments. Break llvm and clang patches.
necipfazil Dec 10, 2024
67662e4
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Feb 2, 2025
f38ce99
Rebase on top of main.
necipfazil Feb 2, 2025
cfcb9c4
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Feb 5, 2025
f80a182
Rename OB_type to OB_callee_type.
necipfazil Feb 5, 2025
8c18c46
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Feb 11, 2025
fe1b3e2
Rebase on top of main
necipfazil Feb 11, 2025
80f879e
Update IR verifier.
necipfazil Feb 11, 2025
f769ce6
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Mar 13, 2025
162e967
Add requested tests part 1.
necipfazil Mar 13, 2025
647db9a
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Mar 13, 2025
ddc8de5
Update comments in tests.
necipfazil Mar 13, 2025
5e97695
Remove unnecessary asserts. Remove autos for better readability.
necipfazil Mar 13, 2025
1429f1d
Add RISC-V support. Clean up test files.
necipfazil Mar 14, 2025
306e08b
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Mar 15, 2025
061fd55
Clean up test files.
necipfazil Mar 15, 2025
9a63148
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Mar 19, 2025
09a933d
Address code refactoring and test cleanup comments.
Prabhuk Mar 19, 2025
4a45618
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 19, 2025
f1be618
Use metadata instead of OB to construct CallSiteInfo.
Prabhuk Apr 19, 2025
3eee130
Address review comments.
Prabhuk Apr 19, 2025
9ceb54c
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 23, 2025
55ea3e2
Add tailcall tests.
Prabhuk Apr 23, 2025
175b5f1
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 23, 2025
4724c6e
Move verifier down to parent change.
Prabhuk Apr 23, 2025
721cb8b
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 23, 2025
f6a71b5
Address review comments.
Prabhuk Apr 23, 2025
7a32b7e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 24, 2025
a55c857
Address review comments.
Prabhuk Apr 24, 2025
484ad23
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 24, 2025
5e5690a
Rebase on parent.
Prabhuk Apr 24, 2025
11b6b2f
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 24, 2025
baaa763
Rebase on parent.
Prabhuk Apr 24, 2025
dd2c0b8
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Apr 28, 2025
6c0b729
Rebase on parent.
Prabhuk Apr 28, 2025
b813c25
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 1, 2025
5d49a8d
Rebase on parent.
Prabhuk May 1, 2025
35ef409
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 5, 2025
706478e
Rebase on parent.
Prabhuk May 5, 2025
07b7f6c
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 10, 2025
dd7e4b4
Rebase on parent change.
Prabhuk May 10, 2025
d7e6843
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 13, 2025
a388287
Remove dso_local and noundef from tests.
Prabhuk May 13, 2025
29cc917
Test direct call sites.
Prabhuk May 13, 2025
7e133e5
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 14, 2025
00d17d1
Rebase change stack on top of parent.
Prabhuk May 14, 2025
5ec5e7a
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 14, 2025
195cd6e
Rebase on main.
Prabhuk May 14, 2025
f1154ce
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk May 27, 2025
70ca198
Drop local_unnamed_addr.
Prabhuk May 27, 2025
24fd769
Replace not check with positive checks.
Prabhuk May 27, 2025
b8f1934
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jun 11, 2025
5431cd5
Rebase.
Prabhuk Jun 11, 2025
37faf58
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jun 11, 2025
38ac87a
Rebase on parent
Prabhuk Jun 11, 2025
975676e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 10, 2025
a7ac510
Rebase on top of main.
Prabhuk Jul 10, 2025
9c96517
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
3f9848f
Rebase on top of main.
Prabhuk Jul 18, 2025
3c53c18
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
72f6773
Rebase on parent
Prabhuk Jul 18, 2025
11dc6bf
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
34eb039
Rebase on top of parent change.
Prabhuk Jul 18, 2025
ac406a5
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
fd7299f
Rebase on parent.
Prabhuk Jul 18, 2025
67756fc
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
2065a88
Rebase on parent.
Prabhuk Jul 18, 2025
37e8d19
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 18, 2025
44d4463
Address review comments.
Prabhuk Jul 18, 2025
690ff13
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 21, 2025
3ec7216
Rebase on top of main.
Prabhuk Jul 21, 2025
de6003d
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 22, 2025
0e2eb95
Rebase.
Prabhuk Jul 22, 2025
4f76066
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
faf9f8f
Reduce tests. Update comments in tests. Rename functions in tests.
Prabhuk Jul 23, 2025
7b846f0
Rebase on main.
Prabhuk Jul 23, 2025
858480f
Change test var name.
Prabhuk Jul 23, 2025
230e666
Rebase after reapplying parent patch.
Prabhuk Jul 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/ArrayRecycler.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Recycler.h"
#include "llvm/Target/TargetOptions.h"
#include <bitset>
Expand Down Expand Up @@ -517,6 +520,32 @@ class LLVM_ABI MachineFunction {
SmallVector<ArgRegPair, 1> ArgRegPairs;
/// Callee type ids.
SmallVector<ConstantInt *, 4> CalleeTypeIds;

CallSiteInfo() = default;

/// Extracts the numeric type id from the CallBase's callee_type Metadata,
/// and sets CalleeTypeIds. This is used as type id for the indirect call in
/// the call graph section.
CallSiteInfo(const CallBase &CB) {
// Call graph section needs numeric callee_type id only for indirect
// calls.
if (!CB.isIndirectCall())
return;

MDNode *CalleeTypeList = CB.getMetadata(LLVMContext::MD_callee_type);
if (!CalleeTypeList)
return;

for (const MDOperand &Op : CalleeTypeList->operands()) {
MDNode *TypeMD = cast<MDNode>(Op);
MDString *TypeIdStr = cast<MDString>(TypeMD->getOperand(1));
// Compute numeric type id from generalized type id string
uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString());
IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext());
CalleeTypeIds.push_back(
ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false));
}
}
};

struct CalledGlobalInfo {
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ EmitSchedule(MachineBasicBlock::iterator &InsertPos) {
}

if (MI->isCandidateForAdditionalCallInfo()) {
if (DAG->getTarget().Options.EmitCallSiteInfo)
if (DAG->getTarget().Options.EmitCallSiteInfo ||
DAG->getTarget().Options.EmitCallGraphSection)
MF.addCallSiteInfo(MI, DAG->getCallSiteInfo(Node));

if (auto CalledGlobal = DAG->getCalledGlobal(Node))
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8952,6 +8952,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
bool &IsTailCall = CLI.IsTailCall;
CallingConv::ID &CallConv = CLI.CallConv;
bool IsVarArg = CLI.IsVarArg;
const CallBase *CB = CLI.CB;

MachineFunction &MF = DAG.getMachineFunction();
MachineFunction::CallSiteInfo CSInfo;
Expand Down Expand Up @@ -8991,6 +8992,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
*DAG.getContext());
RetCCInfo.AnalyzeCallResult(Ins, RetCC);

// Set type id for call site info.
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
CSInfo = MachineFunction::CallSiteInfo(*CB);

// Check callee args/returns for SVE registers and set calling convention
// accordingly.
if (CallConv == CallingConv::C || CallConv == CallingConv::Fast) {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,7 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
CallingConv::ID CallConv = CLI.CallConv;
bool doesNotRet = CLI.DoesNotReturn;
bool isVarArg = CLI.IsVarArg;
const CallBase *CB = CLI.CB;

MachineFunction &MF = DAG.getMachineFunction();
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
Expand All @@ -2446,6 +2447,10 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
!Subtarget->noBTIAtReturnTwice())
GuardWithBTI = AFI->branchTargetEnforcement();

// Set type id for call site info.
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
CSInfo = MachineFunction::CallSiteInfo(*CB);

// Determine whether this is a non-secure function call.
if (CLI.CB && CLI.CB->getAttributes().hasFnAttr("cmse_nonsecure_call"))
isCmseNSCall = true;
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/Mips/MipsISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
bool &IsTailCall = CLI.IsTailCall;
CallingConv::ID CallConv = CLI.CallConv;
bool IsVarArg = CLI.IsVarArg;
const CallBase *CB = CLI.CB;

MachineFunction &MF = DAG.getMachineFunction();
MachineFrameInfo &MFI = MF.getFrameInfo();
Expand Down Expand Up @@ -3397,8 +3398,11 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// Get a count of how many bytes are to be pushed on the stack.
unsigned StackSize = CCInfo.getStackSize();

// Call site info for function parameters tracking.
// Call site info for function parameters tracking and call base type info.
MachineFunction::CallSiteInfo CSInfo;
// Set type id for call site info.
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
CSInfo = MachineFunction::CallSiteInfo(*CB);

// Check if it's really possible to do a tail call. Restrict it to functions
// that are part of this compilation unit.
Expand Down
13 changes: 13 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22636,8 +22636,14 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
bool IsVarArg = CLI.IsVarArg;
EVT PtrVT = getPointerTy(DAG.getDataLayout());
MVT XLenVT = Subtarget.getXLenVT();
const CallBase *CB = CLI.CB;

MachineFunction &MF = DAG.getMachineFunction();
MachineFunction::CallSiteInfo CSInfo;

// Set type id for call site info.
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
CSInfo = MachineFunction::CallSiteInfo(*CB);

// Analyze the operands of the call, assigning locations to each operand.
SmallVector<CCValAssign, 16> ArgLocs;
Expand Down Expand Up @@ -22895,13 +22901,20 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
if (CLI.CFIType)
Ret.getNode()->setCFIType(CLI.CFIType->getZExtValue());
DAG.addNoMergeSiteInfo(Ret.getNode(), CLI.NoMerge);
if (MF.getTarget().Options.EmitCallGraphSection && CB &&
CB->isIndirectCall())
DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
return Ret;
}

unsigned CallOpc = NeedSWGuarded ? RISCVISD::SW_GUARDED_CALL : RISCVISD::CALL;
Chain = DAG.getNode(CallOpc, DL, NodeTys, Ops);
if (CLI.CFIType)
Chain.getNode()->setCFIType(CLI.CFIType->getZExtValue());

if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));

DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge);
Glue = Chain.getValue(1);

Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/X86/X86FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3673,6 +3673,12 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) {
CLI.NumResultRegs = RVLocs.size();
CLI.Call = MIB;

// Add call site info for call graph section.
if (TM.Options.EmitCallGraphSection && CB && CB->isIndirectCall()) {
MachineFunction::CallSiteInfo CSInfo(*CB);
MF->addCallSiteInfo(CLI.Call, std::move(CSInfo));
}

return true;
}

Expand Down Expand Up @@ -4042,6 +4048,8 @@ bool X86FastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
MO.setReg(IndexReg);
}

if (MI->isCall())
FuncInfo.MF->moveAdditionalCallInfo(MI, Result);
Result->addMemOperand(*FuncInfo.MF, createMachineMemOperandFor(LI));
Result->cloneInstrSymbols(*FuncInfo.MF, *MI);
MachineBasicBlock::iterator I(MI);
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/X86/X86ISelLoweringCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,10 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
if (CallConv == CallingConv::X86_INTR)
report_fatal_error("X86 interrupts may not be called directly");

// Set type id for call site info.
if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
CSInfo = MachineFunction::CallSiteInfo(*CB);

if (IsIndirectCall && !IsWin64 &&
M->getModuleFlag("import-call-optimization"))
errorUnsupported(DAG, dl,
Expand Down
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;; Tests that callee_type metadata attached to direct call sites are safely ignored.

; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

;; Test that `calleeTypeIds` field is not present in `callSites`
; CHECK-LABEL: callSites:
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
define i32 @foo(i32 %x, i32 %y) !type !0 {
entry:
;; Call instruction with accurate callee_type.
;; callee_type should be dropped seemlessly.
%call = call i32 @fizz(i32 %x, i32 %y), !callee_type !1
;; Call instruction with mismatched callee_type.
;; callee_type should be dropped seemlessly without errors.
%call1 = call i32 @fizz(i32 %x, i32 %y), !callee_type !3
%add = add nsw i32 %call, %call1
;; Call instruction with mismatched callee_type.
;; callee_type should be dropped seemlessly without errors.
%call2 = call i32 @fizz(i32 %add, i32 %y), !callee_type !3
%sub = sub nsw i32 %add, %call2
ret i32 %sub
}

declare !type !2 i32 @fizz(i32, i32)

!0 = !{i64 0, !"_ZTSFiiiiE.generalized"}
!1 = !{!2}
!2 = !{i64 0, !"_ZTSFiiiE.generalized"}
!3 = !{!4}
!4 = !{i64 0, !"_ZTSFicE.generalized"}
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/AArch64/callsite-emit-calleetypeid-tailcall.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; Tests that call site callee type ids can be extracted and set from
;; callee_type metadata for indirect tail calls.

;; Verify the exact calleeTypeId value to ensure it is not garbage but the value
;; computed as the type id from the callee_type metadata.
; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

define i32 @check_tailcall(ptr %func, i8 %x) !type !0 {
entry:
; CHECK: callSites:
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
; CHECK-NEXT: [ 3498816979441845844 ] }
%call = tail call i32 %func(i8 signext %x), !callee_type !1
ret i32 %call
}

!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
!1 = !{!2}
!2 = !{i64 0, !"_ZTSFicE.generalized"}
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/AArch64/callsite-emit-calleetypeid.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;; Tests that call site callee type ids can be extracted and set from
;; callee_type metadata.

;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value
;; computed as the type id from the callee_type metadata.
; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

; CHECK: name: main
; CHECK: callSites:
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
; CHECK-NEXT: [ 7854600665770582568 ] }
define i32 @main() {
entry:
%fn = load ptr, ptr null, align 8
call void %fn(i8 0), !callee_type !0
ret i32 0
}

!0 = !{!1}
!1 = !{i64 0, !"_ZTSFvcE.generalized"}
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;; Tests that callee_type metadata attached to direct call sites are safely ignored.

; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

;; Test that `calleeTypeIds` field is not present in `callSites`
; CHECK-LABEL: callSites:
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
define i32 @foo(i32 %x, i32 %y) !type !0 {
entry:
;; Call instruction with accurate callee_type.
;; callee_type should be dropped seemlessly.
%call = call i32 @fizz(i32 %x, i32 %y), !callee_type !1
;; Call instruction with mismatched callee_type.
;; callee_type should be dropped seemlessly without errors.
%call1 = call i32 @fizz(i32 %x, i32 %y), !callee_type !3
%add = add nsw i32 %call, %call1
;; Call instruction with mismatched callee_type.
;; callee_type should be dropped seemlessly without errors.
%call2 = call i32 @fizz(i32 %add, i32 %y), !callee_type !3
%sub = sub nsw i32 %add, %call2
ret i32 %sub
}

declare !type !2 i32 @fizz(i32, i32)

!0 = !{i64 0, !"_ZTSFiiiiE.generalized"}
!1 = !{!2}
!2 = !{i64 0, !"_ZTSFiiiE.generalized"}
!3 = !{!4}
!4 = !{i64 0, !"_ZTSFicE.generalized"}
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/ARM/callsite-emit-calleetypeid-tailcall.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; Tests that call site callee type ids can be extracted and set from
;; callee_type metadata for indirect tail calls.

;; Verify the exact calleeTypeId value to ensure it is not garbage but the value
;; computed as the type id from the callee_type metadata.
; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

define i32 @check_tailcall(ptr %func, i8 %x) !type !0 {
entry:
; CHECK: callSites:
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
; CHECK-NEXT: [ 3498816979441845844 ] }
%call = tail call i32 %func(i8 signext %x), !callee_type !1
ret i32 %call
}

!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
!1 = !{!2}
!2 = !{i64 0, !"_ZTSFicE.generalized"}
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/ARM/callsite-emit-calleetypeid.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;; Tests that call site callee type ids can be extracted and set from
;; callee_type metadata.

;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value
;; computed as the type id from the callee_type metadata.
; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck --match-full-lines %s

; CHECK: name: main
; CHECK: callSites:
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
; CHECK-NEXT: [ 7854600665770582568 ] }
define i32 @main() {
entry:
%fn = load ptr, ptr null, align 8
call void %fn(i8 0), !callee_type !0
ret i32 0
}

!0 = !{!1}
!1 = !{i64 0, !"_ZTSFvcE.generalized"}
Loading
Loading