| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 1 | //===---- AMDCallingConv.td - Calling Conventions for Radeon GPUs ---------===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This describes the calling conventions for the AMD Radeon GPUs. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | // Inversion of CCIfInReg |
| 14 | class CCIfNotInReg<CCAction A> : CCIf<"!ArgFlags.isInReg()", A> {} |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 15 | class CCIfExtend<CCAction A> |
| 16 | : CCIf<"ArgFlags.isSExt() || ArgFlags.isZExt()", A>; |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 17 | |
| 18 | // Calling convention for SI |
| 19 | def CC_SI : CallingConv<[ |
| 20 | |
| Matt Arsenault | 55ab921 | 2018-08-01 19:57:34 +0000 | [diff] [blame] | 21 | CCIfInReg<CCIfType<[f32, i32, f16, v2i16, v2f16] , CCAssignToReg<[ |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 22 | SGPR0, SGPR1, SGPR2, SGPR3, SGPR4, SGPR5, SGPR6, SGPR7, |
| Tom Stellard | afcf12f | 2013-09-12 02:55:14 +0000 | [diff] [blame] | 23 | SGPR8, SGPR9, SGPR10, SGPR11, SGPR12, SGPR13, SGPR14, SGPR15, |
| Marek Olsak | 4e99b6e | 2016-01-13 11:46:48 +0000 | [diff] [blame] | 24 | SGPR16, SGPR17, SGPR18, SGPR19, SGPR20, SGPR21, SGPR22, SGPR23, |
| 25 | SGPR24, SGPR25, SGPR26, SGPR27, SGPR28, SGPR29, SGPR30, SGPR31, |
| Ryan Taylor | 29257eb | 2019-05-15 14:43:55 +0000 | [diff] [blame] | 26 | SGPR32, SGPR33, SGPR34, SGPR35, SGPR36, SGPR37, SGPR38, SGPR39, |
| Ryan Taylor | 3b1459e | 2019-08-28 15:00:45 +0000 | [diff] [blame] | 27 | SGPR40, SGPR41, SGPR42, SGPR43 |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 28 | ]>>>, |
| 29 | |
| Marek Olsak | 4e99b6e | 2016-01-13 11:46:48 +0000 | [diff] [blame] | 30 | // 32*4 + 4 is the minimum for a fetch shader consumer with 32 inputs. |
| Matt Arsenault | 55ab921 | 2018-08-01 19:57:34 +0000 | [diff] [blame] | 31 | CCIfNotInReg<CCIfType<[f32, i32, f16, v2i16, v2f16] , CCAssignToReg<[ |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 32 | VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7, |
| 33 | VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15, |
| 34 | VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23, |
| Marek Olsak | 4e99b6e | 2016-01-13 11:46:48 +0000 | [diff] [blame] | 35 | VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31, |
| 36 | VGPR32, VGPR33, VGPR34, VGPR35, VGPR36, VGPR37, VGPR38, VGPR39, |
| 37 | VGPR40, VGPR41, VGPR42, VGPR43, VGPR44, VGPR45, VGPR46, VGPR47, |
| 38 | VGPR48, VGPR49, VGPR50, VGPR51, VGPR52, VGPR53, VGPR54, VGPR55, |
| 39 | VGPR56, VGPR57, VGPR58, VGPR59, VGPR60, VGPR61, VGPR62, VGPR63, |
| 40 | VGPR64, VGPR65, VGPR66, VGPR67, VGPR68, VGPR69, VGPR70, VGPR71, |
| 41 | VGPR72, VGPR73, VGPR74, VGPR75, VGPR76, VGPR77, VGPR78, VGPR79, |
| 42 | VGPR80, VGPR81, VGPR82, VGPR83, VGPR84, VGPR85, VGPR86, VGPR87, |
| 43 | VGPR88, VGPR89, VGPR90, VGPR91, VGPR92, VGPR93, VGPR94, VGPR95, |
| 44 | VGPR96, VGPR97, VGPR98, VGPR99, VGPR100, VGPR101, VGPR102, VGPR103, |
| 45 | VGPR104, VGPR105, VGPR106, VGPR107, VGPR108, VGPR109, VGPR110, VGPR111, |
| 46 | VGPR112, VGPR113, VGPR114, VGPR115, VGPR116, VGPR117, VGPR118, VGPR119, |
| 47 | VGPR120, VGPR121, VGPR122, VGPR123, VGPR124, VGPR125, VGPR126, VGPR127, |
| 48 | VGPR128, VGPR129, VGPR130, VGPR131, VGPR132, VGPR133, VGPR134, VGPR135 |
| Matt Arsenault | dd10884 | 2017-04-06 17:37:27 +0000 | [diff] [blame] | 49 | ]>>> |
| Tom Stellard | ed882c2 | 2013-06-03 17:40:11 +0000 | [diff] [blame] | 50 | ]>; |
| 51 | |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 52 | def RetCC_SI_Shader : CallingConv<[ |
| Marek Olsak | 8a0f335 | 2016-01-13 17:23:04 +0000 | [diff] [blame] | 53 | CCIfType<[i32] , CCAssignToReg<[ |
| 54 | SGPR0, SGPR1, SGPR2, SGPR3, SGPR4, SGPR5, SGPR6, SGPR7, |
| 55 | SGPR8, SGPR9, SGPR10, SGPR11, SGPR12, SGPR13, SGPR14, SGPR15, |
| 56 | SGPR16, SGPR17, SGPR18, SGPR19, SGPR20, SGPR21, SGPR22, SGPR23, |
| 57 | SGPR24, SGPR25, SGPR26, SGPR27, SGPR28, SGPR29, SGPR30, SGPR31, |
| Ryan Taylor | 29257eb | 2019-05-15 14:43:55 +0000 | [diff] [blame] | 58 | SGPR32, SGPR33, SGPR34, SGPR35, SGPR36, SGPR37, SGPR38, SGPR39, |
| Ryan Taylor | 3b1459e | 2019-08-28 15:00:45 +0000 | [diff] [blame] | 59 | SGPR40, SGPR41, SGPR42, SGPR43 |
| Marek Olsak | 8a0f335 | 2016-01-13 17:23:04 +0000 | [diff] [blame] | 60 | ]>>, |
| 61 | |
| 62 | // 32*4 + 4 is the minimum for a fetch shader with 32 outputs. |
| Matt Arsenault | 55ab921 | 2018-08-01 19:57:34 +0000 | [diff] [blame] | 63 | CCIfType<[f32, f16, v2f16] , CCAssignToReg<[ |
| Marek Olsak | 8a0f335 | 2016-01-13 17:23:04 +0000 | [diff] [blame] | 64 | VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7, |
| 65 | VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15, |
| 66 | VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23, |
| 67 | VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31, |
| 68 | VGPR32, VGPR33, VGPR34, VGPR35, VGPR36, VGPR37, VGPR38, VGPR39, |
| 69 | VGPR40, VGPR41, VGPR42, VGPR43, VGPR44, VGPR45, VGPR46, VGPR47, |
| 70 | VGPR48, VGPR49, VGPR50, VGPR51, VGPR52, VGPR53, VGPR54, VGPR55, |
| 71 | VGPR56, VGPR57, VGPR58, VGPR59, VGPR60, VGPR61, VGPR62, VGPR63, |
| 72 | VGPR64, VGPR65, VGPR66, VGPR67, VGPR68, VGPR69, VGPR70, VGPR71, |
| 73 | VGPR72, VGPR73, VGPR74, VGPR75, VGPR76, VGPR77, VGPR78, VGPR79, |
| 74 | VGPR80, VGPR81, VGPR82, VGPR83, VGPR84, VGPR85, VGPR86, VGPR87, |
| 75 | VGPR88, VGPR89, VGPR90, VGPR91, VGPR92, VGPR93, VGPR94, VGPR95, |
| 76 | VGPR96, VGPR97, VGPR98, VGPR99, VGPR100, VGPR101, VGPR102, VGPR103, |
| 77 | VGPR104, VGPR105, VGPR106, VGPR107, VGPR108, VGPR109, VGPR110, VGPR111, |
| 78 | VGPR112, VGPR113, VGPR114, VGPR115, VGPR116, VGPR117, VGPR118, VGPR119, |
| 79 | VGPR120, VGPR121, VGPR122, VGPR123, VGPR124, VGPR125, VGPR126, VGPR127, |
| 80 | VGPR128, VGPR129, VGPR130, VGPR131, VGPR132, VGPR133, VGPR134, VGPR135 |
| 81 | ]>> |
| 82 | ]>; |
| 83 | |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 84 | def CSR_AMDGPU_VGPRs_24_255 : CalleeSavedRegs< |
| 85 | (sequence "VGPR%u", 24, 255) |
| 86 | >; |
| 87 | |
| 88 | def CSR_AMDGPU_VGPRs_32_255 : CalleeSavedRegs< |
| 89 | (sequence "VGPR%u", 32, 255) |
| 90 | >; |
| 91 | |
| Matt Arsenault | 60ba03e | 2019-05-21 23:23:05 +0000 | [diff] [blame] | 92 | def CSR_AMDGPU_SGPRs_32_105 : CalleeSavedRegs< |
| 93 | (sequence "SGPR%u", 32, 105) |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 94 | >; |
| 95 | |
| Matt Arsenault | 5b0922f | 2019-07-03 23:32:29 +0000 | [diff] [blame] | 96 | // Just to get the regmask, not for calling convention purposes. |
| 97 | def CSR_AMDGPU_AllVGPRs : CalleeSavedRegs< |
| 98 | (sequence "VGPR%u", 0, 255) |
| 99 | >; |
| 100 | |
| 101 | // Just to get the regmask, not for calling convention purposes. |
| 102 | def CSR_AMDGPU_AllAllocatableSRegs : CalleeSavedRegs< |
| 103 | (add (sequence "SGPR%u", 0, 105), VCC_LO, VCC_HI) |
| 104 | >; |
| 105 | |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 106 | def CSR_AMDGPU_HighRegs : CalleeSavedRegs< |
| Matt Arsenault | 60ba03e | 2019-05-21 23:23:05 +0000 | [diff] [blame] | 107 | (add CSR_AMDGPU_VGPRs_32_255, CSR_AMDGPU_SGPRs_32_105) |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 108 | >; |
| 109 | |
| 110 | // Calling convention for leaf functions |
| 111 | def CC_AMDGPU_Func : CallingConv<[ |
| 112 | CCIfByVal<CCPassByVal<4, 4>>, |
| 113 | CCIfType<[i1], CCPromoteToType<i32>>, |
| 114 | CCIfType<[i1, i8, i16], CCIfExtend<CCPromoteToType<i32>>>, |
| 115 | CCIfType<[i32, f32, i16, f16, v2i16, v2f16, i1], CCAssignToReg<[ |
| 116 | VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7, |
| 117 | VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15, |
| 118 | VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23, |
| 119 | VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31]>>, |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 120 | CCIfType<[i32, f32, v2i16, v2f16, i16, f16, i1], CCAssignToStack<4, 4>>, |
| 121 | CCIfType<[i64, f64, v2i32, v2f32], CCAssignToStack<8, 4>>, |
| Tim Renouf | 361b5b2 | 2019-03-21 12:01:21 +0000 | [diff] [blame] | 122 | CCIfType<[v3i32, v3f32], CCAssignToStack<12, 4>>, |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 123 | CCIfType<[v4i32, v4f32, v2i64, v2f64], CCAssignToStack<16, 4>>, |
| Tim Renouf | 033f99a | 2019-03-22 10:11:21 +0000 | [diff] [blame] | 124 | CCIfType<[v5i32, v5f32], CCAssignToStack<20, 4>>, |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 125 | CCIfType<[v8i32, v8f32], CCAssignToStack<32, 4>>, |
| 126 | CCIfType<[v16i32, v16f32], CCAssignToStack<64, 4>> |
| 127 | ]>; |
| 128 | |
| 129 | // Calling convention for leaf functions |
| 130 | def RetCC_AMDGPU_Func : CallingConv<[ |
| 131 | CCIfType<[i1], CCPromoteToType<i32>>, |
| 132 | CCIfType<[i1, i16], CCIfExtend<CCPromoteToType<i32>>>, |
| 133 | CCIfType<[i32, f32, i16, f16, v2i16, v2f16], CCAssignToReg<[ |
| 134 | VGPR0, VGPR1, VGPR2, VGPR3, VGPR4, VGPR5, VGPR6, VGPR7, |
| 135 | VGPR8, VGPR9, VGPR10, VGPR11, VGPR12, VGPR13, VGPR14, VGPR15, |
| 136 | VGPR16, VGPR17, VGPR18, VGPR19, VGPR20, VGPR21, VGPR22, VGPR23, |
| 137 | VGPR24, VGPR25, VGPR26, VGPR27, VGPR28, VGPR29, VGPR30, VGPR31]>>, |
| Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 138 | ]>; |
| 139 | |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 140 | def CC_AMDGPU : CallingConv<[ |
| Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 141 | CCIf<"static_cast<const GCNSubtarget&>" |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 142 | "(State.getMachineFunction().getSubtarget()).getGeneration() >= " |
| 143 | "AMDGPUSubtarget::SOUTHERN_ISLANDS", |
| 144 | CCDelegateTo<CC_SI>>, |
| Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 145 | CCIf<"static_cast<const GCNSubtarget&>" |
| Matt Arsenault | b62a4eb | 2017-08-01 19:54:18 +0000 | [diff] [blame] | 146 | "(State.getMachineFunction().getSubtarget()).getGeneration() >= " |
| 147 | "AMDGPUSubtarget::SOUTHERN_ISLANDS && State.getCallingConv() == CallingConv::C", |
| Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 148 | CCDelegateTo<CC_AMDGPU_Func>> |
| Christian Konig | 2c8f6d5 | 2013-03-07 09:03:52 +0000 | [diff] [blame] | 149 | ]>; |