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