1 //===---- AMDCallingConv.td - Calling Conventions for Radeon GPUs ---------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This describes the calling conventions for the AMD Radeon GPUs.
11 //===----------------------------------------------------------------------===//
13 // Inversion of CCIfInReg
14 class CCIfNotInReg<CCAction A> : CCIf<"!ArgFlags.isInReg()", A> {}
15 class CCIfExtend<CCAction A>
16 : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>;
18 // Calling convention for SI
19 def CC_SI : CallingConv<[
21 CCIfInReg<CCIfType<[f32, i32, f16, v2i16, v2f16] , CCAssignToReg<[
22 SGPR0, SGPR1, SGPR2, SGPR3, SGPR4, SGPR5, SGPR6, SGPR7,
23 SGPR8, SGPR9, SGPR10, SGPR11, SGPR12, SGPR13, SGPR14, SGPR15,
24 SGPR16, SGPR17, SGPR18, SGPR19, SGPR20, SGPR21, SGPR22, SGPR23,
25 SGPR24, SGPR25, SGPR26, SGPR27, SGPR28, SGPR29, SGPR30, SGPR31,
26 SGPR32, SGPR33, SGPR34, SGPR35, SGPR36, SGPR37, SGPR38, SGPR39
29 // We have no way of referring to the generated register tuples
30 // here, so use a custom function.
31 CCIfInReg<CCIfType<[i64], CCCustom<"allocateSGPRTuple">>>,
32 CCIfByVal<CCIfType<[i64], CCCustom<"allocateSGPRTuple">>>,
34 // 32*4 + 4 is the minimum for a fetch shader consumer with 32 inputs.
35 CCIfNotInReg<CCIfType<[f32, i32, f16, v2i16, v2f16] , CCAssignToReg<[
36 VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7,
37 VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15,
38 VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23,
39 VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31,
40 VGPR32, VGPR33, VGPR34, VGPR35, VGPR36, VGPR37, VGPR38, VGPR39,
41 VGPR40, VGPR41, VGPR42, VGPR43, VGPR44, VGPR45, VGPR46, VGPR47,
42 VGPR48, VGPR49, VGPR50, VGPR51, VGPR52, VGPR53, VGPR54, VGPR55,
43 VGPR56, VGPR57, VGPR58, VGPR59, VGPR60, VGPR61, VGPR62, VGPR63,
44 VGPR64, VGPR65, VGPR66, VGPR67, VGPR68, VGPR69, VGPR70, VGPR71,
45 VGPR72, VGPR73, VGPR74, VGPR75, VGPR76, VGPR77, VGPR78, VGPR79,
46 VGPR80, VGPR81, VGPR82, VGPR83, VGPR84, VGPR85, VGPR86, VGPR87,
47 VGPR88, VGPR89, VGPR90, VGPR91, VGPR92, VGPR93, VGPR94, VGPR95,
48 VGPR96, VGPR97, VGPR98, VGPR99, VGPR100, VGPR101, VGPR102, VGPR103,
49 VGPR104, VGPR105, VGPR106, VGPR107, VGPR108, VGPR109, VGPR110, VGPR111,
50 VGPR112, VGPR113, VGPR114, VGPR115, VGPR116, VGPR117, VGPR118, VGPR119,
51 VGPR120, VGPR121, VGPR122, VGPR123, VGPR124, VGPR125, VGPR126, VGPR127,
52 VGPR128, VGPR129, VGPR130, VGPR131, VGPR132, VGPR133, VGPR134, VGPR135
56 def RetCC_SI_Shader : CallingConv<[
57 CCIfType<[i32] , CCAssignToReg<[
58 SGPR0, SGPR1, SGPR2, SGPR3, SGPR4, SGPR5, SGPR6, SGPR7,
59 SGPR8, SGPR9, SGPR10, SGPR11, SGPR12, SGPR13, SGPR14, SGPR15,
60 SGPR16, SGPR17, SGPR18, SGPR19, SGPR20, SGPR21, SGPR22, SGPR23,
61 SGPR24, SGPR25, SGPR26, SGPR27, SGPR28, SGPR29, SGPR30, SGPR31,
62 SGPR32, SGPR33, SGPR34, SGPR35, SGPR36, SGPR37, SGPR38, SGPR39
65 // 32*4 + 4 is the minimum for a fetch shader with 32 outputs.
66 CCIfType<[f32, f16, v2f16] , CCAssignToReg<[
67 VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7,
68 VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15,
69 VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23,
70 VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31,
71 VGPR32, VGPR33, VGPR34, VGPR35, VGPR36, VGPR37, VGPR38, VGPR39,
72 VGPR40, VGPR41, VGPR42, VGPR43, VGPR44, VGPR45, VGPR46, VGPR47,
73 VGPR48, VGPR49, VGPR50, VGPR51, VGPR52, VGPR53, VGPR54, VGPR55,
74 VGPR56, VGPR57, VGPR58, VGPR59, VGPR60, VGPR61, VGPR62, VGPR63,
75 VGPR64, VGPR65, VGPR66, VGPR67, VGPR68, VGPR69, VGPR70, VGPR71,
76 VGPR72, VGPR73, VGPR74, VGPR75, VGPR76, VGPR77, VGPR78, VGPR79,
77 VGPR80, VGPR81, VGPR82, VGPR83, VGPR84, VGPR85, VGPR86, VGPR87,
78 VGPR88, VGPR89, VGPR90, VGPR91, VGPR92, VGPR93, VGPR94, VGPR95,
79 VGPR96, VGPR97, VGPR98, VGPR99, VGPR100, VGPR101, VGPR102, VGPR103,
80 VGPR104, VGPR105, VGPR106, VGPR107, VGPR108, VGPR109, VGPR110, VGPR111,
81 VGPR112, VGPR113, VGPR114, VGPR115, VGPR116, VGPR117, VGPR118, VGPR119,
82 VGPR120, VGPR121, VGPR122, VGPR123, VGPR124, VGPR125, VGPR126, VGPR127,
83 VGPR128, VGPR129, VGPR130, VGPR131, VGPR132, VGPR133, VGPR134, VGPR135
87 def CSR_AMDGPU_VGPRs_24_255 : CalleeSavedRegs<
88 (sequence "VGPR%u", 24, 255)
91 def CSR_AMDGPU_VGPRs_32_255 : CalleeSavedRegs<
92 (sequence "VGPR%u", 32, 255)
95 def CSR_AMDGPU_SGPRs_32_103 : CalleeSavedRegs<
96 (sequence "SGPR%u", 32, 103)
99 def CSR_AMDGPU_HighRegs : CalleeSavedRegs<
100 (add CSR_AMDGPU_VGPRs_32_255, CSR_AMDGPU_SGPRs_32_103)
103 // Calling convention for leaf functions
104 def CC_AMDGPU_Func : CallingConv<[
105 CCIfByVal<CCPassByVal<4, 4>>,
106 CCIfType<[i1], CCPromoteToType<i32>>,
107 CCIfType<[i1, i8, i16], CCIfExtend<CCPromoteToType<i32>>>,
108 CCIfType<[i32, f32, i16, f16, v2i16, v2f16, i1], CCAssignToReg<[
109 VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7,
110 VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15,
111 VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23,
112 VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31]>>,
113 CCIfType<[i64, f64, v2i32, v2f32, v4i32, v4f32, v8i32, v8f32, v16i32, v16f32, v2i64, v2f64, v4i16, v4f16], CCCustom<"allocateVGPRTuple">>,
114 CCIfType<[i32, f32, v2i16, v2f16, i16, f16, i1], CCAssignToStack<4, 4>>,
115 CCIfType<[i64, f64, v2i32, v2f32], CCAssignToStack<8, 4>>,
116 CCIfType<[v4i32, v4f32, v2i64, v2f64], CCAssignToStack<16, 4>>,
117 CCIfType<[v8i32, v8f32], CCAssignToStack<32, 4>>,
118 CCIfType<[v16i32, v16f32], CCAssignToStack<64, 4>>
121 // Calling convention for leaf functions
122 def RetCC_AMDGPU_Func : CallingConv<[
123 CCIfType<[i1], CCPromoteToType<i32>>,
124 CCIfType<[i1, i16], CCIfExtend<CCPromoteToType<i32>>>,
125 CCIfType<[i32, f32, i16, f16, v2i16, v2f16], CCAssignToReg<[
126 VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7,
127 VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15,
128 VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23,
129 VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31]>>,
130 CCIfType<[i64, f64, v2i32, v2f32, v4i32, v4f32, v8i32, v8f32, v16i32, v16f32, v2i64, v2f64, v4i16, v4f16], CCCustom<"allocateVGPRTuple">>
133 def CC_AMDGPU : CallingConv<[
134 CCIf<"static_cast<const GCNSubtarget&>"
135 "(State.getMachineFunction().getSubtarget()).getGeneration() >= "
136 "AMDGPUSubtarget::SOUTHERN_ISLANDS",
137 CCDelegateTo<CC_SI>>,
138 CCIf<"static_cast<const GCNSubtarget&>"
139 "(State.getMachineFunction().getSubtarget()).getGeneration() >= "
140 "AMDGPUSubtarget::SOUTHERN_ISLANDS && State.getCallingConv() == CallingConv::C",
141 CCDelegateTo<CC_AMDGPU_Func>>