Skip to content

Commit cebc746

Browse files
konstantinschwarzF-Stuckmann
authored andcommitted
[AIE2P] Add alternative calling convention for library calls
In AIEs default calling convention, all vector registers are caller saved. However, most compiler-rt builtin library functions do not use vector registers. To avoid having to spill vectors to memory in the caller function, we can attach a different calling convention to these library functions.
1 parent 7f68bce commit cebc746

File tree

13 files changed

+61
-19
lines changed

13 files changed

+61
-19
lines changed

llvm/include/llvm/IR/CallingConv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ namespace CallingConv {
270270
/// Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
271271
AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1 = 111,
272272

273+
/// Preserve vector registers.
274+
AIE_PreserveAll_Vec = 112,
275+
273276
/// The highest possible ID. Must be some 2^k - 1.
274277
MaxID = 1023
275278
};

llvm/lib/Target/AIE/AIEBaseISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "MCTargetDesc/AIE2MCTargetDesc.h"
1919
#include "MCTargetDesc/AIEMCTargetDesc.h"
2020
#include "MCTargetDesc/aie2p/AIE2PMCTargetDesc.h"
21+
#include "llvm/IR/RuntimeLibcalls.h"
2122
#include "llvm/MC/MCRegister.h"
2223
using namespace llvm;
2324

llvm/lib/Target/AIE/aie2p/AIE2PCallingConv.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,12 @@ def CC_AIE2P : CallingConv<[
219219
def CSR_AIE2P
220220
: CalleeSavedRegs<(add lr, r8, r9, r10, r11, r12, r13, r14, r15, p6, p7)>;
221221

222+
def CSR_AIE2P_Vec
223+
: CalleeSavedRegs<(add lr, r8, r9, r10, r11, r12, r13, r14, r15, p6, p7,
224+
wl0, wl2, wl4, wl6, wl8, wl10, wl1, wl3, wl5, wl7, wl9, wl11, wh0,
225+
wh2, wh4, wh6, wh8, wh10, wh1, wh3, wh5, wh7, wh9, wh11, bmll0, bmll1,
226+
bmll2, bmll3, bmll4, bmhl0, bmhl1, bmhl2, bmhl3, bmhl4, bmlh0, bmlh1,
227+
bmlh2, bmlh3, bmlh4, bmhh0, bmhh1, bmhh2, bmhh3, bmhh4)>;
228+
222229
// Needed for implementation of AIERegisterInfo::getNoPreservedMask()
223230
def CSR_NoRegs : CalleeSavedRegs<(add)>;

llvm/lib/Target/AIE/aie2p/AIE2PISelLowering.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,34 @@ using namespace llvm;
2222

2323
#define DEBUG_TYPE "aie-lower"
2424

25+
cl::opt<bool>
26+
VecCCLibcalls("aie-libcalls-preserve-vectors", cl::init(true), cl::Hidden,
27+
cl::desc("Assume all vector registers are callee-saved by "
28+
"builtin library functions."));
29+
2530
AIE2PTargetLowering::AIE2PTargetLowering(const TargetMachine &TM,
2631
const AIEBaseSubtarget &STI)
2732
: AIEBaseTargetLowering(TM, STI) {
33+
34+
if (VecCCLibcalls) {
35+
setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32,
36+
CallingConv::AIE_PreserveAll_Vec);
37+
setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64,
38+
CallingConv::AIE_PreserveAll_Vec);
39+
setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32,
40+
CallingConv::AIE_PreserveAll_Vec);
41+
setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64,
42+
CallingConv::AIE_PreserveAll_Vec);
43+
setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::AIE_PreserveAll_Vec);
44+
setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::AIE_PreserveAll_Vec);
45+
setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::AIE_PreserveAll_Vec);
46+
setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::AIE_PreserveAll_Vec);
47+
setLibcallCallingConv(RTLIB::SREM_I32, CallingConv::AIE_PreserveAll_Vec);
48+
setLibcallCallingConv(RTLIB::SREM_I64, CallingConv::AIE_PreserveAll_Vec);
49+
setLibcallCallingConv(RTLIB::UREM_I32, CallingConv::AIE_PreserveAll_Vec);
50+
setLibcallCallingConv(RTLIB::UREM_I64, CallingConv::AIE_PreserveAll_Vec);
51+
}
52+
2853
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
2954

3055
// We already define in .td which types are legal for each register class.

llvm/lib/Target/AIE/aie2p/AIE2PRegisterInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/CodeGen/RegisterScavenging.h"
2626
#include "llvm/CodeGen/TargetFrameLowering.h"
2727
#include "llvm/CodeGen/TargetRegisterInfo.h"
28+
#include "llvm/IR/CallingConv.h"
2829
#include "llvm/Support/ErrorHandling.h"
2930

3031
#define GET_REGINFO_TARGET_DESC
@@ -279,8 +280,13 @@ AIE2PRegisterInfo::getPointerRegClass(const MachineFunction &MF,
279280

280281
const uint32_t *
281282
AIE2PRegisterInfo::getCallPreservedMask(const MachineFunction &MF,
282-
CallingConv::ID /*CC*/) const {
283-
return CSR_AIE2P_RegMask;
283+
CallingConv::ID CC) const {
284+
switch (CC) {
285+
case CallingConv::AIE_PreserveAll_Vec:
286+
return CSR_AIE2P_Vec_RegMask;
287+
default:
288+
return CSR_AIE2P_RegMask;
289+
}
284290
}
285291

286292
bool AIE2PRegisterInfo::isTypeLegalForClass(const TargetRegisterClass &RC,

llvm/test/CodeGen/AIE/GlobalISel/legalize-sdiv.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
77
# RUN: llc -mtriple aie -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=1 %s
88
# RUN: llc -mtriple aie2 -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2 %s
9-
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p %s
9+
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p_vec %s
1010

1111
---
1212
name: sdiv_s32

llvm/test/CodeGen/AIE/GlobalISel/legalize-sdivrem.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
77
# RUN: llc -mtriple aie -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=1 %s
88
# RUN: llc -mtriple aie2 -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2 %s
9-
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p %s
9+
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p_vec %s
1010

1111
---
1212
name: sdivrem_s32

llvm/test/CodeGen/AIE/GlobalISel/legalize-sitofp.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
66
# RUN: llc -mtriple aie2 -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2 --check-prefix=COMMON --check-prefix=AIE2 %s
7-
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p --check-prefix=COMMON --check-prefix=AIE2P %s
7+
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p_vec --check-prefix=COMMON --check-prefix=AIE2P %s
88

99
---
1010
name: test_sitofp_s32_to_s32

llvm/test/CodeGen/AIE/GlobalISel/legalize-srem.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
77
# RUN: llc -mtriple aie -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=1 %s
88
# RUN: llc -mtriple aie2 -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2 %s
9-
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p %s
9+
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p_vec %s
1010

1111
---
1212
name: srem_s32

llvm/test/CodeGen/AIE/GlobalISel/legalize-udiv.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
77
# RUN: llc -mtriple aie -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=1 %s
88
# RUN: llc -mtriple aie2 -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2 %s
9-
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p %s
9+
# RUN: llc -mtriple aie2p -run-pass=legalizer %s -verify-machineinstrs -o - | FileCheck -DVER=2p_vec %s
1010

1111
---
1212
name: udiv_s32

0 commit comments

Comments
 (0)