Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 1 | //===- AArch64LegalizerInfo.cpp ----------------------------------*- C++ -*-==// |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 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 | /// \file |
| 10 | /// This file implements the targeting of the Machinelegalizer class for |
| 11 | /// AArch64. |
| 12 | /// \todo This should be generated by TableGen. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 15 | #include "AArch64LegalizerInfo.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" |
Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineInstr.h" |
| 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/TargetOpcodes.h" |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/ValueTypes.h" |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Type.h" |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 26 | /// FIXME: The following static functions are SizeChangeStrategy functions |
| 27 | /// that are meant to temporarily mimic the behaviour of the old legalization |
| 28 | /// based on doubling/halving non-legal types as closely as possible. This is |
| 29 | /// not entirly possible as only legalizing the types that are exactly a power |
| 30 | /// of 2 times the size of the legal types would require specifying all those |
| 31 | /// sizes explicitly. |
| 32 | /// In practice, not specifying those isn't a problem, and the below functions |
| 33 | /// should disappear quickly as we add support for legalizing non-power-of-2 |
| 34 | /// sized types further. |
| 35 | static void |
| 36 | addAndInterleaveWithUnsupported(LegalizerInfo::SizeAndActionsVec &result, |
| 37 | const LegalizerInfo::SizeAndActionsVec &v) { |
| 38 | for (unsigned i = 0; i < v.size(); ++i) { |
| 39 | result.push_back(v[i]); |
| 40 | if (i + 1 < v[i].first && i + 1 < v.size() && |
| 41 | v[i + 1].first != v[i].first + 1) |
| 42 | result.push_back({v[i].first + 1, LegalizerInfo::Unsupported}); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | static LegalizerInfo::SizeAndActionsVec |
| 47 | widen_1_narrow_128_ToLargest(const LegalizerInfo::SizeAndActionsVec &v) { |
| 48 | assert(v.size() >= 1); |
| 49 | assert(v[0].first > 2); |
| 50 | LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::WidenScalar}, |
| 51 | {2, LegalizerInfo::Unsupported}}; |
| 52 | addAndInterleaveWithUnsupported(result, v); |
| 53 | auto Largest = result.back().first; |
| 54 | assert(Largest + 1 < 128); |
| 55 | result.push_back({Largest + 1, LegalizerInfo::Unsupported}); |
| 56 | result.push_back({128, LegalizerInfo::NarrowScalar}); |
| 57 | result.push_back({129, LegalizerInfo::Unsupported}); |
| 58 | return result; |
| 59 | } |
| 60 | |
| 61 | static LegalizerInfo::SizeAndActionsVec |
| 62 | widen_16(const LegalizerInfo::SizeAndActionsVec &v) { |
| 63 | assert(v.size() >= 1); |
| 64 | assert(v[0].first > 17); |
| 65 | LegalizerInfo::SizeAndActionsVec result = {{1, LegalizerInfo::Unsupported}, |
| 66 | {16, LegalizerInfo::WidenScalar}, |
| 67 | {17, LegalizerInfo::Unsupported}}; |
| 68 | addAndInterleaveWithUnsupported(result, v); |
| 69 | auto Largest = result.back().first; |
| 70 | result.push_back({Largest + 1, LegalizerInfo::Unsupported}); |
| 71 | return result; |
| 72 | } |
| 73 | |
| 74 | static LegalizerInfo::SizeAndActionsVec |
| 75 | widen_1_8(const LegalizerInfo::SizeAndActionsVec &v) { |
| 76 | assert(v.size() >= 1); |
| 77 | assert(v[0].first > 9); |
| 78 | LegalizerInfo::SizeAndActionsVec result = { |
| 79 | {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, |
| 80 | {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}}; |
| 81 | addAndInterleaveWithUnsupported(result, v); |
| 82 | auto Largest = result.back().first; |
| 83 | result.push_back({Largest + 1, LegalizerInfo::Unsupported}); |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | static LegalizerInfo::SizeAndActionsVec |
| 88 | widen_1_8_16(const LegalizerInfo::SizeAndActionsVec &v) { |
| 89 | assert(v.size() >= 1); |
| 90 | assert(v[0].first > 17); |
| 91 | LegalizerInfo::SizeAndActionsVec result = { |
| 92 | {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, |
| 93 | {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, |
| 94 | {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}}; |
| 95 | addAndInterleaveWithUnsupported(result, v); |
| 96 | auto Largest = result.back().first; |
| 97 | result.push_back({Largest + 1, LegalizerInfo::Unsupported}); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | static LegalizerInfo::SizeAndActionsVec |
| 102 | widen_1_8_16_narrowToLargest(const LegalizerInfo::SizeAndActionsVec &v) { |
| 103 | assert(v.size() >= 1); |
| 104 | assert(v[0].first > 17); |
| 105 | LegalizerInfo::SizeAndActionsVec result = { |
| 106 | {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, |
| 107 | {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, |
| 108 | {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}}; |
| 109 | addAndInterleaveWithUnsupported(result, v); |
| 110 | auto Largest = result.back().first; |
| 111 | result.push_back({Largest + 1, LegalizerInfo::NarrowScalar}); |
| 112 | return result; |
| 113 | } |
| 114 | |
| 115 | static LegalizerInfo::SizeAndActionsVec |
| 116 | widen_1_8_16_32(const LegalizerInfo::SizeAndActionsVec &v) { |
| 117 | assert(v.size() >= 1); |
| 118 | assert(v[0].first > 33); |
| 119 | LegalizerInfo::SizeAndActionsVec result = { |
| 120 | {1, LegalizerInfo::WidenScalar}, {2, LegalizerInfo::Unsupported}, |
| 121 | {8, LegalizerInfo::WidenScalar}, {9, LegalizerInfo::Unsupported}, |
| 122 | {16, LegalizerInfo::WidenScalar}, {17, LegalizerInfo::Unsupported}, |
| 123 | {32, LegalizerInfo::WidenScalar}, {33, LegalizerInfo::Unsupported}}; |
| 124 | addAndInterleaveWithUnsupported(result, v); |
| 125 | auto Largest = result.back().first; |
| 126 | result.push_back({Largest + 1, LegalizerInfo::Unsupported}); |
| 127 | return result; |
| 128 | } |
| 129 | |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 130 | AArch64LegalizerInfo::AArch64LegalizerInfo() { |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 131 | using namespace TargetOpcode; |
Tim Northover | 5ae8350 | 2016-09-15 09:20:34 +0000 | [diff] [blame] | 132 | const LLT p0 = LLT::pointer(0, 64); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 133 | const LLT s1 = LLT::scalar(1); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 134 | const LLT s8 = LLT::scalar(8); |
| 135 | const LLT s16 = LLT::scalar(16); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 136 | const LLT s32 = LLT::scalar(32); |
| 137 | const LLT s64 = LLT::scalar(64); |
Quentin Colombet | 7c114d3 | 2017-10-16 22:28:27 +0000 | [diff] [blame] | 138 | const LLT s128 = LLT::scalar(128); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 139 | const LLT v2s32 = LLT::vector(2, 32); |
| 140 | const LLT v4s32 = LLT::vector(4, 32); |
| 141 | const LLT v2s64 = LLT::vector(2, 64); |
| 142 | |
Tim Northover | ff5e7e1 | 2017-06-30 20:27:36 +0000 | [diff] [blame] | 143 | for (auto Ty : {p0, s1, s8, s16, s32, s64}) |
| 144 | setAction({G_IMPLICIT_DEF, Ty}, Legal); |
| 145 | |
Amara Emerson | 1cd89ca | 2017-10-08 15:29:11 +0000 | [diff] [blame] | 146 | for (auto Ty : {s16, s32, s64, p0}) |
Aditya Nandakumar | efd8a84 | 2017-08-23 20:45:48 +0000 | [diff] [blame] | 147 | setAction({G_PHI, Ty}, Legal); |
| 148 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 149 | setLegalizeScalarToDifferentSizeStrategy(G_PHI, 0, widen_1_8); |
Aditya Nandakumar | 892979e | 2017-08-25 04:57:27 +0000 | [diff] [blame] | 150 | |
Daniel Sanders | 83e23d1 | 2017-09-19 14:25:15 +0000 | [diff] [blame] | 151 | for (auto Ty : { s32, s64 }) |
| 152 | setAction({G_BSWAP, Ty}, Legal); |
| 153 | |
Quentin Colombet | 24203cf | 2017-01-27 01:13:30 +0000 | [diff] [blame] | 154 | for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SHL}) { |
Tim Northover | fe880a8 | 2016-08-25 17:37:39 +0000 | [diff] [blame] | 155 | // These operations naturally get the right answer when used on |
| 156 | // GPR32, even if the actual type is narrower. |
Ahmed Bougacha | cfb384d | 2017-01-23 21:10:05 +0000 | [diff] [blame] | 157 | for (auto Ty : {s32, s64, v2s32, v4s32, v2s64}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 158 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | cfb384d | 2017-01-23 21:10:05 +0000 | [diff] [blame] | 159 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 160 | if (BinOp != G_ADD) |
| 161 | setLegalizeScalarToDifferentSizeStrategy(BinOp, 0, |
| 162 | widen_1_8_16_narrowToLargest); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 165 | setAction({G_GEP, p0}, Legal); |
| 166 | setAction({G_GEP, 1, s64}, Legal); |
Tim Northover | 22d82cf | 2016-09-15 11:02:19 +0000 | [diff] [blame] | 167 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 168 | setLegalizeScalarToDifferentSizeStrategy(G_GEP, 1, widen_1_8_16_32); |
Tim Northover | 22d82cf | 2016-09-15 11:02:19 +0000 | [diff] [blame] | 169 | |
Tim Northover | 398c5f5 | 2017-02-14 20:56:29 +0000 | [diff] [blame] | 170 | setAction({G_PTR_MASK, p0}, Legal); |
| 171 | |
Quentin Colombet | 24203cf | 2017-01-27 01:13:30 +0000 | [diff] [blame] | 172 | for (unsigned BinOp : {G_LSHR, G_ASHR, G_SDIV, G_UDIV}) { |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 173 | for (auto Ty : {s32, s64}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 174 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 175 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 176 | setLegalizeScalarToDifferentSizeStrategy(BinOp, 0, widen_1_8_16); |
Tim Northover | 7a753d9 | 2016-08-26 17:46:06 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Quentin Colombet | 24203cf | 2017-01-27 01:13:30 +0000 | [diff] [blame] | 179 | for (unsigned BinOp : {G_SREM, G_UREM}) |
Tim Northover | cecee56 | 2016-08-26 17:46:13 +0000 | [diff] [blame] | 180 | for (auto Ty : { s1, s8, s16, s32, s64 }) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 181 | setAction({BinOp, Ty}, Lower); |
Tim Northover | cecee56 | 2016-08-26 17:46:13 +0000 | [diff] [blame] | 182 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 183 | for (unsigned Op : {G_SMULO, G_UMULO}) { |
| 184 | setAction({Op, 0, s64}, Lower); |
| 185 | setAction({Op, 1, s1}, Legal); |
| 186 | } |
Tim Northover | 0a9b279 | 2017-02-08 21:22:15 +0000 | [diff] [blame] | 187 | |
| 188 | for (unsigned Op : {G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_SMULH, G_UMULH}) { |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 189 | for (auto Ty : { s32, s64 }) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 190 | setAction({Op, Ty}, Legal); |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 191 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 192 | setAction({Op, 1, s1}, Legal); |
Tim Northover | d8a6d7c | 2016-08-25 17:37:41 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Daniel Sanders | 40b66d6 | 2017-07-18 14:10:07 +0000 | [diff] [blame] | 195 | for (unsigned BinOp : {G_FADD, G_FSUB, G_FMA, G_FMUL, G_FDIV}) |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 196 | for (auto Ty : {s32, s64}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 197 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 198 | |
Tim Northover | e041841 | 2017-02-08 23:23:39 +0000 | [diff] [blame] | 199 | for (unsigned BinOp : {G_FREM, G_FPOW}) { |
| 200 | setAction({BinOp, s32}, Libcall); |
| 201 | setAction({BinOp, s64}, Libcall); |
| 202 | } |
Tim Northover | edb3c8c | 2016-08-29 19:07:16 +0000 | [diff] [blame] | 203 | |
Tim Northover | 3e6a7af | 2017-03-03 23:05:47 +0000 | [diff] [blame] | 204 | for (auto Ty : {s32, s64, p0}) { |
Tim Northover | 0e6afbd | 2017-02-06 21:56:47 +0000 | [diff] [blame] | 205 | setAction({G_INSERT, Ty}, Legal); |
| 206 | setAction({G_INSERT, 1, Ty}, Legal); |
| 207 | } |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 208 | setLegalizeScalarToDifferentSizeStrategy(G_INSERT, 0, |
| 209 | widen_1_8_16_narrowToLargest); |
Tim Northover | 0e6afbd | 2017-02-06 21:56:47 +0000 | [diff] [blame] | 210 | for (auto Ty : {s1, s8, s16}) { |
Tim Northover | 3e6a7af | 2017-03-03 23:05:47 +0000 | [diff] [blame] | 211 | setAction({G_INSERT, 1, Ty}, Legal); |
Tim Northover | 0e6afbd | 2017-02-06 21:56:47 +0000 | [diff] [blame] | 212 | // FIXME: Can't widen the sources because that violates the constraints on |
| 213 | // G_INSERT (It seems entirely reasonable that inputs shouldn't overlap). |
| 214 | } |
| 215 | |
Tim Northover | c2d5e6d | 2017-06-26 20:34:13 +0000 | [diff] [blame] | 216 | for (auto Ty : {s1, s8, s16, s32, s64, p0}) |
| 217 | setAction({G_EXTRACT, Ty}, Legal); |
| 218 | |
| 219 | for (auto Ty : {s32, s64}) |
| 220 | setAction({G_EXTRACT, 1, Ty}, Legal); |
| 221 | |
Quentin Colombet | 24203cf | 2017-01-27 01:13:30 +0000 | [diff] [blame] | 222 | for (unsigned MemOp : {G_LOAD, G_STORE}) { |
Quentin Colombet | d3126d5 | 2016-10-11 00:21:08 +0000 | [diff] [blame] | 223 | for (auto Ty : {s8, s16, s32, s64, p0, v2s32}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 224 | setAction({MemOp, Ty}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 225 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 226 | setLegalizeScalarToDifferentSizeStrategy(MemOp, 0, |
| 227 | widen_1_narrow_128_ToLargest); |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 228 | |
| 229 | // And everything's fine in addrspace 0. |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 230 | setAction({MemOp, 1, p0}, Legal); |
Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 233 | // Constants |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 234 | for (auto Ty : {s32, s64}) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 235 | setAction({TargetOpcode::G_CONSTANT, Ty}, Legal); |
| 236 | setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 239 | setAction({G_CONSTANT, p0}, Legal); |
Tim Northover | 7a1ec01 | 2016-08-25 17:37:35 +0000 | [diff] [blame] | 240 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 241 | setLegalizeScalarToDifferentSizeStrategy(G_CONSTANT, 0, widen_1_8_16); |
| 242 | setLegalizeScalarToDifferentSizeStrategy(G_FCONSTANT, 0, widen_16); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 243 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 244 | setAction({G_ICMP, 1, s32}, Legal); |
| 245 | setAction({G_ICMP, 1, s64}, Legal); |
| 246 | setAction({G_ICMP, 1, p0}, Legal); |
Tim Northover | 6cd4b23 | 2016-08-23 21:01:26 +0000 | [diff] [blame] | 247 | |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 248 | setLegalizeScalarToDifferentSizeStrategy(G_ICMP, 0, widen_1_8_16); |
| 249 | setLegalizeScalarToDifferentSizeStrategy(G_FCMP, 0, widen_1_8_16); |
| 250 | setLegalizeScalarToDifferentSizeStrategy(G_ICMP, 1, widen_1_8_16); |
Tim Northover | 6cd4b23 | 2016-08-23 21:01:26 +0000 | [diff] [blame] | 251 | |
Aditya Nandakumar | 02c602e | 2017-07-31 17:00:16 +0000 | [diff] [blame] | 252 | setAction({G_ICMP, s32}, Legal); |
| 253 | setAction({G_FCMP, s32}, Legal); |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 254 | setAction({G_FCMP, 1, s32}, Legal); |
| 255 | setAction({G_FCMP, 1, s64}, Legal); |
Tim Northover | 30bd36e | 2016-08-26 17:46:19 +0000 | [diff] [blame] | 256 | |
Tim Northover | 2c4a838 | 2016-08-25 17:37:25 +0000 | [diff] [blame] | 257 | // Extensions |
| 258 | for (auto Ty : { s1, s8, s16, s32, s64 }) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 259 | setAction({G_ZEXT, Ty}, Legal); |
| 260 | setAction({G_SEXT, Ty}, Legal); |
| 261 | setAction({G_ANYEXT, Ty}, Legal); |
Tim Northover | 2c4a838 | 2016-08-25 17:37:25 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Ahmed Bougacha | 106dd03 | 2017-09-12 21:04:11 +0000 | [diff] [blame] | 264 | // FP conversions |
| 265 | for (auto Ty : { s16, s32 }) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 266 | setAction({G_FPTRUNC, Ty}, Legal); |
Ahmed Bougacha | 106dd03 | 2017-09-12 21:04:11 +0000 | [diff] [blame] | 267 | setAction({G_FPEXT, 1, Ty}, Legal); |
| 268 | } |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 269 | |
Ahmed Bougacha | 106dd03 | 2017-09-12 21:04:11 +0000 | [diff] [blame] | 270 | for (auto Ty : { s32, s64 }) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 271 | setAction({G_FPTRUNC, 1, Ty}, Legal); |
Ahmed Bougacha | 106dd03 | 2017-09-12 21:04:11 +0000 | [diff] [blame] | 272 | setAction({G_FPEXT, Ty}, Legal); |
| 273 | } |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 274 | |
Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 275 | // Conversions |
Ahmed Bougacha | d294823 | 2017-01-20 01:37:24 +0000 | [diff] [blame] | 276 | for (auto Ty : { s32, s64 }) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 277 | setAction({G_FPTOSI, 0, Ty}, Legal); |
| 278 | setAction({G_FPTOUI, 0, Ty}, Legal); |
| 279 | setAction({G_SITOFP, 1, Ty}, Legal); |
| 280 | setAction({G_UITOFP, 1, Ty}, Legal); |
Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 281 | } |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 282 | setLegalizeScalarToDifferentSizeStrategy(G_FPTOSI, 0, widen_1_8_16); |
| 283 | setLegalizeScalarToDifferentSizeStrategy(G_FPTOUI, 0, widen_1_8_16); |
| 284 | setLegalizeScalarToDifferentSizeStrategy(G_SITOFP, 1, widen_1_8_16); |
| 285 | setLegalizeScalarToDifferentSizeStrategy(G_UITOFP, 1, widen_1_8_16); |
Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 286 | |
| 287 | for (auto Ty : { s32, s64 }) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 288 | setAction({G_FPTOSI, 1, Ty}, Legal); |
| 289 | setAction({G_FPTOUI, 1, Ty}, Legal); |
| 290 | setAction({G_SITOFP, 0, Ty}, Legal); |
| 291 | setAction({G_UITOFP, 0, Ty}, Legal); |
Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 292 | } |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 293 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 294 | // Control-flow |
Tim Northover | 6aacd27 | 2016-10-12 22:48:36 +0000 | [diff] [blame] | 295 | for (auto Ty : {s1, s8, s16, s32}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 296 | setAction({G_BRCOND, Ty}, Legal); |
Kristof Beyls | 65a12c0 | 2017-01-30 09:13:18 +0000 | [diff] [blame] | 297 | setAction({G_BRINDIRECT, p0}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 298 | |
Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 299 | // Select |
Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 300 | setLegalizeScalarToDifferentSizeStrategy(G_SELECT, 0, widen_1_8_16); |
Tim Northover | 868332d | 2017-02-06 23:41:27 +0000 | [diff] [blame] | 301 | |
| 302 | for (auto Ty : {s32, s64, p0}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 303 | setAction({G_SELECT, Ty}, Legal); |
Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 304 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 305 | setAction({G_SELECT, 1, s1}, Legal); |
Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 306 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 307 | // Pointer-handling |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 308 | setAction({G_FRAME_INDEX, p0}, Legal); |
| 309 | setAction({G_GLOBAL_VALUE, p0}, Legal); |
Ahmed Bougacha | 0306b5e | 2016-08-16 14:02:42 +0000 | [diff] [blame] | 310 | |
Tim Northover | 037af52c | 2016-10-31 18:31:09 +0000 | [diff] [blame] | 311 | for (auto Ty : {s1, s8, s16, s32, s64}) |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 312 | setAction({G_PTRTOINT, 0, Ty}, Legal); |
Tim Northover | 037af52c | 2016-10-31 18:31:09 +0000 | [diff] [blame] | 313 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 314 | setAction({G_PTRTOINT, 1, p0}, Legal); |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 315 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 316 | setAction({G_INTTOPTR, 0, p0}, Legal); |
| 317 | setAction({G_INTTOPTR, 1, s64}, Legal); |
Tim Northover | 456a3c0 | 2016-08-23 19:30:38 +0000 | [diff] [blame] | 318 | |
Quentin Colombet | 404e435 | 2016-10-12 03:57:43 +0000 | [diff] [blame] | 319 | // Casts for 32 and 64-bit width type are just copies. |
Quentin Colombet | 7c114d3 | 2017-10-16 22:28:27 +0000 | [diff] [blame] | 320 | // Same for 128-bit width type, except they are on the FPR bank. |
| 321 | for (auto Ty : {s1, s8, s16, s32, s64, s128}) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 322 | setAction({G_BITCAST, 0, Ty}, Legal); |
| 323 | setAction({G_BITCAST, 1, Ty}, Legal); |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 326 | // For the sake of copying bits around, the type does not really |
| 327 | // matter as long as it fits a register. |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 328 | for (int EltSize = 8; EltSize <= 64; EltSize *= 2) { |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 329 | setAction({G_BITCAST, 0, LLT::vector(128/EltSize, EltSize)}, Legal); |
| 330 | setAction({G_BITCAST, 1, LLT::vector(128/EltSize, EltSize)}, Legal); |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 331 | if (EltSize >= 64) |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 332 | continue; |
| 333 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 334 | setAction({G_BITCAST, 0, LLT::vector(64/EltSize, EltSize)}, Legal); |
| 335 | setAction({G_BITCAST, 1, LLT::vector(64/EltSize, EltSize)}, Legal); |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 336 | if (EltSize >= 32) |
| 337 | continue; |
| 338 | |
Quentin Colombet | e15e460 | 2017-01-27 01:13:25 +0000 | [diff] [blame] | 339 | setAction({G_BITCAST, 0, LLT::vector(32/EltSize, EltSize)}, Legal); |
| 340 | setAction({G_BITCAST, 1, LLT::vector(32/EltSize, EltSize)}, Legal); |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Tim Northover | e9600d8 | 2017-02-08 17:57:27 +0000 | [diff] [blame] | 343 | setAction({G_VASTART, p0}, Legal); |
| 344 | |
Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 345 | // va_list must be a pointer, but most sized types are pretty easy to handle |
| 346 | // as the destination. |
| 347 | setAction({G_VAARG, 1, p0}, Legal); |
| 348 | |
| 349 | for (auto Ty : {s8, s16, s32, s64, p0}) |
| 350 | setAction({G_VAARG, Ty}, Custom); |
| 351 | |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 352 | computeTables(); |
| 353 | } |
Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 354 | |
| 355 | bool AArch64LegalizerInfo::legalizeCustom(MachineInstr &MI, |
| 356 | MachineRegisterInfo &MRI, |
| 357 | MachineIRBuilder &MIRBuilder) const { |
| 358 | switch (MI.getOpcode()) { |
| 359 | default: |
| 360 | // No idea what to do. |
| 361 | return false; |
| 362 | case TargetOpcode::G_VAARG: |
| 363 | return legalizeVaArg(MI, MRI, MIRBuilder); |
| 364 | } |
| 365 | |
| 366 | llvm_unreachable("expected switch to return"); |
| 367 | } |
| 368 | |
| 369 | bool AArch64LegalizerInfo::legalizeVaArg(MachineInstr &MI, |
| 370 | MachineRegisterInfo &MRI, |
| 371 | MachineIRBuilder &MIRBuilder) const { |
| 372 | MIRBuilder.setInstr(MI); |
| 373 | MachineFunction &MF = MIRBuilder.getMF(); |
| 374 | unsigned Align = MI.getOperand(2).getImm(); |
| 375 | unsigned Dst = MI.getOperand(0).getReg(); |
| 376 | unsigned ListPtr = MI.getOperand(1).getReg(); |
| 377 | |
| 378 | LLT PtrTy = MRI.getType(ListPtr); |
| 379 | LLT IntPtrTy = LLT::scalar(PtrTy.getSizeInBits()); |
| 380 | |
| 381 | const unsigned PtrSize = PtrTy.getSizeInBits() / 8; |
| 382 | unsigned List = MRI.createGenericVirtualRegister(PtrTy); |
| 383 | MIRBuilder.buildLoad( |
| 384 | List, ListPtr, |
| 385 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOLoad, |
| 386 | PtrSize, /* Align = */ PtrSize)); |
| 387 | |
| 388 | unsigned DstPtr; |
| 389 | if (Align > PtrSize) { |
| 390 | // Realign the list to the actual required alignment. |
Aditya Nandakumar | 1745121 | 2017-07-06 19:40:07 +0000 | [diff] [blame] | 391 | auto AlignMinus1 = MIRBuilder.buildConstant(IntPtrTy, Align - 1); |
Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 392 | |
| 393 | unsigned ListTmp = MRI.createGenericVirtualRegister(PtrTy); |
Aditya Nandakumar | 1745121 | 2017-07-06 19:40:07 +0000 | [diff] [blame] | 394 | MIRBuilder.buildGEP(ListTmp, List, AlignMinus1->getOperand(0).getReg()); |
Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 395 | |
| 396 | DstPtr = MRI.createGenericVirtualRegister(PtrTy); |
| 397 | MIRBuilder.buildPtrMask(DstPtr, ListTmp, Log2_64(Align)); |
| 398 | } else |
| 399 | DstPtr = List; |
| 400 | |
| 401 | uint64_t ValSize = MRI.getType(Dst).getSizeInBits() / 8; |
| 402 | MIRBuilder.buildLoad( |
| 403 | Dst, DstPtr, |
| 404 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOLoad, |
| 405 | ValSize, std::max(Align, PtrSize))); |
| 406 | |
| 407 | unsigned SizeReg = MRI.createGenericVirtualRegister(IntPtrTy); |
| 408 | MIRBuilder.buildConstant(SizeReg, alignTo(ValSize, PtrSize)); |
| 409 | |
| 410 | unsigned NewList = MRI.createGenericVirtualRegister(PtrTy); |
| 411 | MIRBuilder.buildGEP(NewList, DstPtr, SizeReg); |
| 412 | |
| 413 | MIRBuilder.buildStore( |
| 414 | NewList, ListPtr, |
| 415 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOStore, |
| 416 | PtrSize, /* Align = */ PtrSize)); |
| 417 | |
| 418 | MI.eraseFromParent(); |
| 419 | return true; |
| 420 | } |