| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 1 | //=== AArch64CallingConv.h - Custom Calling Convention Routines -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the custom routines for the AArch64 Calling Convention |
| 11 | // that aren't done by tablegen. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64CALLINGCONVENTION_H |
| 16 | #define LLVM_LIB_TARGET_AARCH64_AARCH64CALLINGCONVENTION_H |
| 17 | |
| 18 | #include "AArch64.h" |
| 19 | #include "AArch64InstrInfo.h" |
| 20 | #include "AArch64Subtarget.h" |
| 21 | #include "llvm/CodeGen/CallingConvLower.h" |
| 22 | #include "llvm/IR/CallingConv.h" |
| 23 | #include "llvm/Target/TargetInstrInfo.h" |
| 24 | |
| 25 | namespace { |
| 26 | using namespace llvm; |
| 27 | |
| 28 | static const uint16_t XRegList[] = {AArch64::X0, AArch64::X1, AArch64::X2, |
| 29 | AArch64::X3, AArch64::X4, AArch64::X5, |
| 30 | AArch64::X6, AArch64::X7}; |
| Tim Northover | 67be569 | 2014-12-08 17:54:58 +0000 | [diff] [blame] | 31 | static const uint16_t HRegList[] = {AArch64::H0, AArch64::H1, AArch64::H2, |
| 32 | AArch64::H3, AArch64::H4, AArch64::H5, |
| 33 | AArch64::H6, AArch64::H7}; |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 34 | static const uint16_t SRegList[] = {AArch64::S0, AArch64::S1, AArch64::S2, |
| 35 | AArch64::S3, AArch64::S4, AArch64::S5, |
| 36 | AArch64::S6, AArch64::S7}; |
| 37 | static const uint16_t DRegList[] = {AArch64::D0, AArch64::D1, AArch64::D2, |
| 38 | AArch64::D3, AArch64::D4, AArch64::D5, |
| 39 | AArch64::D6, AArch64::D7}; |
| 40 | static const uint16_t QRegList[] = {AArch64::Q0, AArch64::Q1, AArch64::Q2, |
| 41 | AArch64::Q3, AArch64::Q4, AArch64::Q5, |
| 42 | AArch64::Q6, AArch64::Q7}; |
| 43 | |
| 44 | static bool finishStackBlock(SmallVectorImpl<CCValAssign> &PendingMembers, |
| 45 | MVT LocVT, ISD::ArgFlagsTy &ArgFlags, |
| 46 | CCState &State, unsigned SlotAlign) { |
| 47 | unsigned Size = LocVT.getSizeInBits() / 8; |
| 48 | unsigned StackAlign = State.getMachineFunction() |
| Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 49 | .getTarget() |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 50 | .getDataLayout() |
| 51 | ->getStackAlignment(); |
| 52 | unsigned Align = std::min(ArgFlags.getOrigAlign(), StackAlign); |
| 53 | |
| 54 | for (auto &It : PendingMembers) { |
| 55 | It.convertToMem(State.AllocateStack(Size, std::max(Align, SlotAlign))); |
| 56 | State.addLoc(It); |
| 57 | SlotAlign = 1; |
| 58 | } |
| 59 | |
| 60 | // All pending members have now been allocated |
| 61 | PendingMembers.clear(); |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | /// The Darwin variadic PCS places anonymous arguments in 8-byte stack slots. An |
| 66 | /// [N x Ty] type must still be contiguous in memory though. |
| 67 | static bool CC_AArch64_Custom_Stack_Block( |
| 68 | unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, |
| 69 | ISD::ArgFlagsTy &ArgFlags, CCState &State) { |
| 70 | SmallVectorImpl<CCValAssign> &PendingMembers = State.getPendingLocs(); |
| 71 | |
| 72 | // Add the argument to the list to be allocated once we know the size of the |
| 73 | // block. |
| 74 | PendingMembers.push_back( |
| 75 | CCValAssign::getPending(ValNo, ValVT, LocVT, LocInfo)); |
| 76 | |
| 77 | if (!ArgFlags.isInConsecutiveRegsLast()) |
| 78 | return true; |
| 79 | |
| 80 | return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, 8); |
| 81 | } |
| 82 | |
| 83 | /// Given an [N x Ty] block, it should be passed in a consecutive sequence of |
| 84 | /// registers. If no such sequence is available, mark the rest of the registers |
| 85 | /// of that type as used and place the argument on the stack. |
| 86 | static bool CC_AArch64_Custom_Block(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 87 | CCValAssign::LocInfo &LocInfo, |
| 88 | ISD::ArgFlagsTy &ArgFlags, CCState &State) { |
| 89 | // Try to allocate a contiguous block of registers, each of the correct |
| 90 | // size to hold one member. |
| Tim Northover | a38e5cb | 2014-11-27 21:29:20 +0000 | [diff] [blame] | 91 | ArrayRef<uint16_t> RegList; |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 92 | if (LocVT.SimpleTy == MVT::i64) |
| 93 | RegList = XRegList; |
| Tim Northover | 67be569 | 2014-12-08 17:54:58 +0000 | [diff] [blame] | 94 | else if (LocVT.SimpleTy == MVT::f16) |
| 95 | RegList = HRegList; |
| Tim Northover | 24ec87d | 2014-12-02 17:15:22 +0000 | [diff] [blame] | 96 | else if (LocVT.SimpleTy == MVT::f32 || LocVT.is32BitVector()) |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 97 | RegList = SRegList; |
| Tim Northover | 24ec87d | 2014-12-02 17:15:22 +0000 | [diff] [blame] | 98 | else if (LocVT.SimpleTy == MVT::f64 || LocVT.is64BitVector()) |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 99 | RegList = DRegList; |
| Tim Northover | 24ec87d | 2014-12-02 17:15:22 +0000 | [diff] [blame] | 100 | else if (LocVT.SimpleTy == MVT::f128 || LocVT.is128BitVector()) |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 101 | RegList = QRegList; |
| 102 | else { |
| 103 | // Not an array we want to split up after all. |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | SmallVectorImpl<CCValAssign> &PendingMembers = State.getPendingLocs(); |
| 108 | |
| 109 | // Add the argument to the list to be allocated once we know the size of the |
| 110 | // block. |
| 111 | PendingMembers.push_back( |
| 112 | CCValAssign::getPending(ValNo, ValVT, LocVT, LocInfo)); |
| 113 | |
| 114 | if (!ArgFlags.isInConsecutiveRegsLast()) |
| 115 | return true; |
| 116 | |
| 117 | unsigned RegResult = State.AllocateRegBlock(RegList, PendingMembers.size()); |
| 118 | if (RegResult) { |
| 119 | for (auto &It : PendingMembers) { |
| 120 | It.convertToReg(RegResult); |
| 121 | State.addLoc(It); |
| 122 | ++RegResult; |
| 123 | } |
| 124 | PendingMembers.clear(); |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | // Mark all regs in the class as unavailable |
| 129 | for (auto Reg : RegList) |
| 130 | State.AllocateReg(Reg); |
| 131 | |
| 132 | const AArch64Subtarget &Subtarget = static_cast<const AArch64Subtarget &>( |
| 133 | State.getMachineFunction().getSubtarget()); |
| 134 | unsigned SlotAlign = Subtarget.isTargetDarwin() ? 1 : 8; |
| 135 | |
| 136 | return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, SlotAlign); |
| 137 | } |
| 138 | |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame^] | 139 | } |
| Tim Northover | 3c55cca | 2014-11-27 21:02:42 +0000 | [diff] [blame] | 140 | |
| 141 | #endif |