10b57cec5SDimitry Andric//===-- ARMCallingConv.td - Calling Conventions for ARM ----*- tablegen -*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric// This describes the calling conventions for ARM architecture. 90b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 100b57cec5SDimitry Andric 110b57cec5SDimitry Andric/// CCIfAlign - Match of the original alignment of the arg 120b57cec5SDimitry Andricclass CCIfAlign<string Align, CCAction A>: 130b57cec5SDimitry Andric CCIf<!strconcat("ArgFlags.getOrigAlign() == ", Align), A>; 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 160b57cec5SDimitry Andric// ARM APCS Calling Convention 170b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 180b57cec5SDimitry Andriclet Entry = 1 in 190b57cec5SDimitry Andricdef CC_ARM_APCS : CallingConv<[ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric // Handles byval parameters. 220b57cec5SDimitry Andric CCIfByVal<CCPassByVal<4, 4>>, 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 270b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric // A SwiftError is passed in R8. 300b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 330b57cec5SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 340b57cec5SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric // f64 and v2f64 are passed in adjacent GPRs, possibly split onto the stack 370b57cec5SDimitry Andric CCIfType<[f64, v2f64], CCCustom<"CC_ARM_APCS_Custom_f64">>, 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric CCIfType<[f32], CCBitConvertToType<i32>>, 400b57cec5SDimitry Andric CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric CCIfType<[i32], CCAssignToStack<4, 4>>, 430b57cec5SDimitry Andric CCIfType<[f64], CCAssignToStack<8, 4>>, 440b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToStack<16, 4>> 450b57cec5SDimitry Andric]>; 460b57cec5SDimitry Andric 470b57cec5SDimitry Andriclet Entry = 1 in 480b57cec5SDimitry Andricdef RetCC_ARM_APCS : CallingConv<[ 490b57cec5SDimitry Andric CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, 500b57cec5SDimitry Andric CCIfType<[f32], CCBitConvertToType<i32>>, 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 530b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric // A SwiftError is returned in R8. 560b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 590b57cec5SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 600b57cec5SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_APCS_Custom_f64">>, 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, 650b57cec5SDimitry Andric CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>> 660b57cec5SDimitry Andric]>; 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 690b57cec5SDimitry Andric// ARM APCS Calling Convention for FastCC (when VFP2 or later is available) 700b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 710b57cec5SDimitry Andriclet Entry = 1 in 720b57cec5SDimitry Andricdef FastCC_ARM_APCS : CallingConv<[ 730b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 740b57cec5SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 750b57cec5SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, 780b57cec5SDimitry Andric CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>, 790b57cec5SDimitry Andric CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8, 800b57cec5SDimitry Andric S9, S10, S11, S12, S13, S14, S15]>>, 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric // CPRCs may be allocated to co-processor registers or the stack - they 830b57cec5SDimitry Andric // may never be allocated to core registers. 840b57cec5SDimitry Andric CCIfType<[f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>, 850b57cec5SDimitry Andric CCIfType<[f64], CCAssignToStackWithShadow<8, 4, [Q0, Q1, Q2, Q3]>>, 860b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToStackWithShadow<16, 4, [Q0, Q1, Q2, Q3]>>, 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric CCDelegateTo<CC_ARM_APCS> 890b57cec5SDimitry Andric]>; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andriclet Entry = 1 in 920b57cec5SDimitry Andricdef RetFastCC_ARM_APCS : CallingConv<[ 930b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 940b57cec5SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 950b57cec5SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, 980b57cec5SDimitry Andric CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>, 990b57cec5SDimitry Andric CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8, 1000b57cec5SDimitry Andric S9, S10, S11, S12, S13, S14, S15]>>, 1010b57cec5SDimitry Andric CCDelegateTo<RetCC_ARM_APCS> 1020b57cec5SDimitry Andric]>; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1050b57cec5SDimitry Andric// ARM APCS Calling Convention for GHC 1060b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andriclet Entry = 1 in 1090b57cec5SDimitry Andricdef CC_ARM_APCS_GHC : CallingConv<[ 1100b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 1110b57cec5SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 1120b57cec5SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>, 1150b57cec5SDimitry Andric CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>, 1160b57cec5SDimitry Andric CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>, 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric // Promote i8/i16 arguments to i32. 1190b57cec5SDimitry Andric CCIfType<[i8, i16], CCPromoteToType<i32>>, 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim 1220b57cec5SDimitry Andric CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>> 1230b57cec5SDimitry Andric]>; 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1260b57cec5SDimitry Andric// ARM AAPCS (EABI) Calling Convention, common parts 1270b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andricdef CC_ARM_AAPCS_Common : CallingConv<[ 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric // i64/f64 is passed in even pairs of GPRs 1340b57cec5SDimitry Andric // i64 is 8-aligned i32 here, so we may need to eat R1 as a pad register 1350b57cec5SDimitry Andric // (and the same is true for f64 if VFP is not enabled) 1360b57cec5SDimitry Andric CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>, 1370b57cec5SDimitry Andric CCIfType<[i32], CCIf<"ArgFlags.getOrigAlign() != 8", 1380b57cec5SDimitry Andric CCAssignToReg<[R0, R1, R2, R3]>>>, 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric CCIfType<[i32], CCIfAlign<"8", CCAssignToStackWithShadow<4, 8, [R0, R1, R2, R3]>>>, 1410b57cec5SDimitry Andric CCIfType<[i32], CCAssignToStackWithShadow<4, 4, [R0, R1, R2, R3]>>, 1420b57cec5SDimitry Andric CCIfType<[f32], CCAssignToStackWithShadow<4, 4, [Q0, Q1, Q2, Q3]>>, 1430b57cec5SDimitry Andric CCIfType<[f64], CCAssignToStackWithShadow<8, 8, [Q0, Q1, Q2, Q3]>>, 1440b57cec5SDimitry Andric CCIfType<[v2f64], CCIfAlign<"16", 1450b57cec5SDimitry Andric CCAssignToStackWithShadow<16, 16, [Q0, Q1, Q2, Q3]>>>, 1460b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToStackWithShadow<16, 8, [Q0, Q1, Q2, Q3]>> 1470b57cec5SDimitry Andric]>; 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andricdef RetCC_ARM_AAPCS_Common : CallingConv<[ 1500b57cec5SDimitry Andric CCIfType<[i1, i8, i16], CCPromoteToType<i32>>, 1510b57cec5SDimitry Andric CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>, 1520b57cec5SDimitry Andric CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>> 1530b57cec5SDimitry Andric]>; 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1560b57cec5SDimitry Andric// ARM AAPCS (EABI) Calling Convention 1570b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andriclet Entry = 1 in 1600b57cec5SDimitry Andricdef CC_ARM_AAPCS : CallingConv<[ 1610b57cec5SDimitry Andric // Handles byval parameters. 1620b57cec5SDimitry Andric CCIfByVal<CCPassByVal<4, 4>>, 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric // The 'nest' parameter, if any, is passed in R12. 1650b57cec5SDimitry Andric CCIfNest<CCAssignToReg<[R12]>>, 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 168*480093f4SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 169*480093f4SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 1720b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric // A SwiftError is passed in R8. 1750b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric CCIfType<[f64, v2f64], CCCustom<"CC_ARM_AAPCS_Custom_f64">>, 1780b57cec5SDimitry Andric CCIfType<[f32], CCBitConvertToType<i32>>, 1790b57cec5SDimitry Andric CCDelegateTo<CC_ARM_AAPCS_Common> 1800b57cec5SDimitry Andric]>; 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andriclet Entry = 1 in 1830b57cec5SDimitry Andricdef RetCC_ARM_AAPCS : CallingConv<[ 1840b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 185*480093f4SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 186*480093f4SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 1890b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric // A SwiftError is returned in R8. 1920b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric CCIfType<[f64, v2f64], CCCustom<"RetCC_ARM_AAPCS_Custom_f64">>, 1950b57cec5SDimitry Andric CCIfType<[f32], CCBitConvertToType<i32>>, 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric CCDelegateTo<RetCC_ARM_AAPCS_Common> 1980b57cec5SDimitry Andric]>; 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2010b57cec5SDimitry Andric// ARM AAPCS-VFP (EABI) Calling Convention 2020b57cec5SDimitry Andric// Also used for FastCC (when VFP2 or later is available) 2030b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andriclet Entry = 1 in 2060b57cec5SDimitry Andricdef CC_ARM_AAPCS_VFP : CallingConv<[ 2070b57cec5SDimitry Andric // Handles byval parameters. 2080b57cec5SDimitry Andric CCIfByVal<CCPassByVal<4, 4>>, 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 211*480093f4SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 212*480093f4SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 2150b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andric // A SwiftError is passed in R8. 2180b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andric // HFAs are passed in a contiguous block of registers, or on the stack 2210b57cec5SDimitry Andric CCIfConsecutiveRegs<CCCustom<"CC_ARM_AAPCS_Custom_Aggregate">>, 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, 2240b57cec5SDimitry Andric CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>, 2250b57cec5SDimitry Andric CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8, 2260b57cec5SDimitry Andric S9, S10, S11, S12, S13, S14, S15]>>, 2270b57cec5SDimitry Andric CCDelegateTo<CC_ARM_AAPCS_Common> 2280b57cec5SDimitry Andric]>; 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andriclet Entry = 1 in 2310b57cec5SDimitry Andricdef RetCC_ARM_AAPCS_VFP : CallingConv<[ 2320b57cec5SDimitry Andric // Handle all vector types as either f64 or v2f64. 233*480093f4SDimitry Andric CCIfType<[v1i64, v2i32, v4i16, v4f16, v8i8, v2f32], CCBitConvertToType<f64>>, 234*480093f4SDimitry Andric CCIfType<[v2i64, v4i32, v8i16, v8f16, v16i8, v4f32], CCBitConvertToType<v2f64>>, 2350b57cec5SDimitry Andric 2360b57cec5SDimitry Andric // Pass SwiftSelf in a callee saved register. 2370b57cec5SDimitry Andric CCIfSwiftSelf<CCIfType<[i32], CCAssignToReg<[R10]>>>, 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andric // A SwiftError is returned in R8. 2400b57cec5SDimitry Andric CCIfSwiftError<CCIfType<[i32], CCAssignToReg<[R8]>>>, 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric CCIfType<[v2f64], CCAssignToReg<[Q0, Q1, Q2, Q3]>>, 2430b57cec5SDimitry Andric CCIfType<[f64], CCAssignToReg<[D0, D1, D2, D3, D4, D5, D6, D7]>>, 2440b57cec5SDimitry Andric CCIfType<[f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7, S8, 2450b57cec5SDimitry Andric S9, S10, S11, S12, S13, S14, S15]>>, 2460b57cec5SDimitry Andric CCDelegateTo<RetCC_ARM_AAPCS_Common> 2470b57cec5SDimitry Andric]>; 2480b57cec5SDimitry Andric 249*480093f4SDimitry Andric 250*480093f4SDimitry Andric// Windows Control Flow Guard checks take a single argument (the target function 251*480093f4SDimitry Andric// address) and have no return value. 252*480093f4SDimitry Andriclet Entry = 1 in 253*480093f4SDimitry Andricdef CC_ARM_Win32_CFGuard_Check : CallingConv<[ 254*480093f4SDimitry Andric CCIfType<[i32], CCAssignToReg<[R0]>> 255*480093f4SDimitry Andric]>; 256*480093f4SDimitry Andric 257*480093f4SDimitry Andric 258*480093f4SDimitry Andric 2590b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2600b57cec5SDimitry Andric// Callee-saved register lists. 2610b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andricdef CSR_NoRegs : CalleeSavedRegs<(add)>; 2640b57cec5SDimitry Andricdef CSR_FPRegs : CalleeSavedRegs<(add (sequence "D%u", 0, 31))>; 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andricdef CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4, 2670b57cec5SDimitry Andric (sequence "D%u", 15, 8))>; 2680b57cec5SDimitry Andric 269*480093f4SDimitry Andric// The Windows Control Flow Guard Check function preserves the same registers as 270*480093f4SDimitry Andric// AAPCS, and also preserves all floating point registers. 271*480093f4SDimitry Andricdef CSR_Win_AAPCS_CFGuard_Check : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, 272*480093f4SDimitry Andric R6, R5, R4, (sequence "D%u", 15, 0))>; 273*480093f4SDimitry Andric 2740b57cec5SDimitry Andric// R8 is used to pass swifterror, remove it from CSR. 2750b57cec5SDimitry Andricdef CSR_AAPCS_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS, R8)>; 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andric// The order of callee-saved registers needs to match the order we actually push 2780b57cec5SDimitry Andric// them in FrameLowering, because this order is what's used by 2790b57cec5SDimitry Andric// PrologEpilogInserter to allocate frame index slots. So when R7 is the frame 2800b57cec5SDimitry Andric// pointer, we use this AAPCS alternative. 2810b57cec5SDimitry Andricdef CSR_AAPCS_SplitPush : CalleeSavedRegs<(add LR, R7, R6, R5, R4, 2820b57cec5SDimitry Andric R11, R10, R9, R8, 2830b57cec5SDimitry Andric (sequence "D%u", 15, 8))>; 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric// R8 is used to pass swifterror, remove it from CSR. 2860b57cec5SDimitry Andricdef CSR_AAPCS_SplitPush_SwiftError : CalleeSavedRegs<(sub CSR_AAPCS_SplitPush, 2870b57cec5SDimitry Andric R8)>; 2880b57cec5SDimitry Andric 2890b57cec5SDimitry Andric// Constructors and destructors return 'this' in the ARM C++ ABI; since 'this' 2900b57cec5SDimitry Andric// and the pointer return value are both passed in R0 in these cases, this can 2910b57cec5SDimitry Andric// be partially modelled by treating R0 as a callee-saved register 2920b57cec5SDimitry Andric// Only the resulting RegMask is used; the SaveList is ignored 2930b57cec5SDimitry Andricdef CSR_AAPCS_ThisReturn : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, 2940b57cec5SDimitry Andric R5, R4, (sequence "D%u", 15, 8), 2950b57cec5SDimitry Andric R0)>; 2960b57cec5SDimitry Andric 2970b57cec5SDimitry Andric// iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register. 2980b57cec5SDimitry Andric// Also save R7-R4 first to match the stack frame fixed spill areas. 2990b57cec5SDimitry Andricdef CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>; 3000b57cec5SDimitry Andric 3010b57cec5SDimitry Andric// R8 is used to pass swifterror, remove it from CSR. 3020b57cec5SDimitry Andricdef CSR_iOS_SwiftError : CalleeSavedRegs<(sub CSR_iOS, R8)>; 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andricdef CSR_iOS_ThisReturn : CalleeSavedRegs<(add LR, R7, R6, R5, R4, 3050b57cec5SDimitry Andric (sub CSR_AAPCS_ThisReturn, R9))>; 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andricdef CSR_iOS_TLSCall 3080b57cec5SDimitry Andric : CalleeSavedRegs<(add LR, SP, (sub(sequence "R%u", 12, 1), R9, R12), 3090b57cec5SDimitry Andric (sequence "D%u", 31, 0))>; 3100b57cec5SDimitry Andric 3110b57cec5SDimitry Andric// C++ TLS access function saves all registers except SP. Try to match 3120b57cec5SDimitry Andric// the order of CSRs in CSR_iOS. 3130b57cec5SDimitry Andricdef CSR_iOS_CXX_TLS : CalleeSavedRegs<(add CSR_iOS, (sequence "R%u", 12, 1), 3140b57cec5SDimitry Andric (sequence "D%u", 31, 0))>; 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric// CSRs that are handled by prologue, epilogue. 3170b57cec5SDimitry Andricdef CSR_iOS_CXX_TLS_PE : CalleeSavedRegs<(add LR, R12, R11, R7, R5, R4)>; 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric// CSRs that are handled explicitly via copies. 3200b57cec5SDimitry Andricdef CSR_iOS_CXX_TLS_ViaCopy : CalleeSavedRegs<(sub CSR_iOS_CXX_TLS, 3210b57cec5SDimitry Andric CSR_iOS_CXX_TLS_PE)>; 3220b57cec5SDimitry Andric 3230b57cec5SDimitry Andric// The "interrupt" attribute is used to generate code that is acceptable in 3240b57cec5SDimitry Andric// exception-handlers of various kinds. It makes us use a different return 3250b57cec5SDimitry Andric// instruction (handled elsewhere) and affects which registers we must return to 3260b57cec5SDimitry Andric// our "caller" in the same state as we receive them. 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric// For most interrupts, all registers except SP and LR are shared with 3290b57cec5SDimitry Andric// user-space. We mark LR to be saved anyway, since this is what the ARM backend 3300b57cec5SDimitry Andric// generally does rather than tracking its liveness as a normal register. 3310b57cec5SDimitry Andricdef CSR_GenericInt : CalleeSavedRegs<(add LR, (sequence "R%u", 12, 0))>; 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andric// The fast interrupt handlers have more private state and get their own copies 3340b57cec5SDimitry Andric// of R8-R12, in addition to SP and LR. As before, mark LR for saving too. 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric// FIXME: we mark R11 as callee-saved since it's often the frame-pointer, and 3370b57cec5SDimitry Andric// current frame lowering expects to encounter it while processing callee-saved 3380b57cec5SDimitry Andric// registers. 3390b57cec5SDimitry Andricdef CSR_FIQ : CalleeSavedRegs<(add LR, R11, (sequence "R%u", 7, 0))>; 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric 342