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" |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/ValueTypes.h" |
| 17 | #include "llvm/IR/Type.h" |
| 18 | #include "llvm/IR/DerivedTypes.h" |
| 19 | #include "llvm/Target/TargetOpcodes.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 24 | #error "You shouldn't build this" |
| 25 | #endif |
| 26 | |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 27 | AArch64LegalizerInfo::AArch64LegalizerInfo() { |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 28 | using namespace TargetOpcode; |
Tim Northover | 5ae8350 | 2016-09-15 09:20:34 +0000 | [diff] [blame] | 29 | const LLT p0 = LLT::pointer(0, 64); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 30 | const LLT s1 = LLT::scalar(1); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 31 | const LLT s8 = LLT::scalar(8); |
| 32 | const LLT s16 = LLT::scalar(16); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 33 | const LLT s32 = LLT::scalar(32); |
| 34 | const LLT s64 = LLT::scalar(64); |
| 35 | const LLT v2s32 = LLT::vector(2, 32); |
| 36 | const LLT v4s32 = LLT::vector(4, 32); |
| 37 | const LLT v2s64 = LLT::vector(2, 64); |
| 38 | |
Tim Northover | 7a753d9 | 2016-08-26 17:46:06 +0000 | [diff] [blame] | 39 | for (auto 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] | 40 | // These operations naturally get the right answer when used on |
| 41 | // GPR32, even if the actual type is narrower. |
| 42 | for (auto Ty : {s1, s8, s16, s32, s64, v2s32, v4s32, v2s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 43 | setAction({BinOp, Ty}, Legal); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Tim Northover | 22d82cf | 2016-09-15 11:02:19 +0000 | [diff] [blame] | 46 | setAction({G_GEP, p0}, Legal); |
| 47 | setAction({G_GEP, 1, s64}, Legal); |
| 48 | |
| 49 | for (auto Ty : {s1, s8, s16, s32}) |
| 50 | setAction({G_GEP, 1, Ty}, WidenScalar); |
| 51 | |
Tim Northover | 7a753d9 | 2016-08-26 17:46:06 +0000 | [diff] [blame] | 52 | for (auto BinOp : {G_LSHR, G_ASHR, G_SDIV, G_UDIV}) { |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 53 | for (auto Ty : {s32, s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 54 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 55 | |
Tim Northover | 7a753d9 | 2016-08-26 17:46:06 +0000 | [diff] [blame] | 56 | for (auto Ty : {s1, s8, s16}) |
| 57 | setAction({BinOp, Ty}, WidenScalar); |
| 58 | } |
| 59 | |
Tim Northover | cecee56 | 2016-08-26 17:46:13 +0000 | [diff] [blame] | 60 | for (auto BinOp : { G_SREM, G_UREM }) |
| 61 | for (auto Ty : { s1, s8, s16, s32, s64 }) |
| 62 | setAction({BinOp, Ty}, Lower); |
| 63 | |
Tim Northover | d8a6d7c | 2016-08-25 17:37:41 +0000 | [diff] [blame] | 64 | for (auto Op : { G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_SMULO, G_UMULO }) { |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 65 | for (auto Ty : { s32, s64 }) |
| 66 | setAction({Op, Ty}, Legal); |
| 67 | |
Tim Northover | d8a6d7c | 2016-08-25 17:37:41 +0000 | [diff] [blame] | 68 | setAction({Op, 1, s1}, Legal); |
| 69 | } |
| 70 | |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 71 | for (auto BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV}) |
| 72 | for (auto Ty : {s32, s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 73 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 74 | |
Tim Northover | edb3c8c | 2016-08-29 19:07:16 +0000 | [diff] [blame] | 75 | setAction({G_FREM, s32}, Libcall); |
| 76 | setAction({G_FREM, s64}, Libcall); |
| 77 | |
Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 78 | for (auto MemOp : {G_LOAD, G_STORE}) { |
Quentin Colombet | d3126d5 | 2016-10-11 00:21:08 +0000 | [diff] [blame] | 79 | for (auto Ty : {s8, s16, s32, s64, p0, v2s32}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 80 | setAction({MemOp, Ty}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 81 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 82 | setAction({MemOp, s1}, WidenScalar); |
| 83 | |
| 84 | // And everything's fine in addrspace 0. |
| 85 | setAction({MemOp, 1, p0}, Legal); |
Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 88 | // Constants |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 89 | for (auto Ty : {s32, s64}) { |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 90 | setAction({TargetOpcode::G_CONSTANT, Ty}, Legal); |
| 91 | setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Tim Northover | 7a1ec01 | 2016-08-25 17:37:35 +0000 | [diff] [blame] | 94 | setAction({G_CONSTANT, p0}, Legal); |
| 95 | |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 96 | for (auto Ty : {s1, s8, s16}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 97 | setAction({TargetOpcode::G_CONSTANT, Ty}, WidenScalar); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 98 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 99 | setAction({TargetOpcode::G_FCONSTANT, s16}, WidenScalar); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 100 | |
Tim Northover | 051b8ad | 2016-08-26 17:46:17 +0000 | [diff] [blame] | 101 | setAction({G_ICMP, s1}, Legal); |
| 102 | setAction({G_ICMP, 1, s32}, Legal); |
| 103 | setAction({G_ICMP, 1, s64}, Legal); |
Tim Northover | 4cf0a48 | 2016-09-15 10:40:38 +0000 | [diff] [blame] | 104 | setAction({G_ICMP, 1, p0}, Legal); |
Tim Northover | 6cd4b23 | 2016-08-23 21:01:26 +0000 | [diff] [blame] | 105 | |
Tim Northover | 051b8ad | 2016-08-26 17:46:17 +0000 | [diff] [blame] | 106 | for (auto Ty : {s1, s8, s16}) { |
| 107 | setAction({G_ICMP, 1, Ty}, WidenScalar); |
Tim Northover | 6cd4b23 | 2016-08-23 21:01:26 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Tim Northover | 30bd36e | 2016-08-26 17:46:19 +0000 | [diff] [blame] | 110 | setAction({G_FCMP, s1}, Legal); |
| 111 | setAction({G_FCMP, 1, s32}, Legal); |
| 112 | setAction({G_FCMP, 1, s64}, Legal); |
| 113 | |
Tim Northover | 2c4a838 | 2016-08-25 17:37:25 +0000 | [diff] [blame] | 114 | // Extensions |
| 115 | for (auto Ty : { s1, s8, s16, s32, s64 }) { |
| 116 | setAction({G_ZEXT, Ty}, Legal); |
| 117 | setAction({G_SEXT, Ty}, Legal); |
| 118 | setAction({G_ANYEXT, Ty}, Legal); |
| 119 | } |
| 120 | |
| 121 | for (auto Ty : { s1, s8, s16, s32 }) { |
| 122 | setAction({G_ZEXT, 1, Ty}, Legal); |
| 123 | setAction({G_SEXT, 1, Ty}, Legal); |
| 124 | setAction({G_ANYEXT, 1, Ty}, Legal); |
| 125 | } |
| 126 | |
Tim Northover | bc1701c | 2016-08-26 17:46:22 +0000 | [diff] [blame] | 127 | setAction({G_FPEXT, s64}, Legal); |
| 128 | setAction({G_FPEXT, 1, s32}, Legal); |
| 129 | |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 130 | // Truncations |
| 131 | for (auto Ty : { s16, s32 }) |
| 132 | setAction({G_FPTRUNC, Ty}, Legal); |
| 133 | |
| 134 | for (auto Ty : { s32, s64 }) |
| 135 | setAction({G_FPTRUNC, 1, Ty}, Legal); |
| 136 | |
| 137 | for (auto Ty : { s1, s8, s16, s32 }) |
| 138 | setAction({G_TRUNC, Ty}, Legal); |
| 139 | |
| 140 | for (auto Ty : { s8, s16, s32, s64 }) |
| 141 | setAction({G_TRUNC, 1, Ty}, Legal); |
| 142 | |
Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 143 | // Conversions |
| 144 | for (auto Ty : { s1, s8, s16, s32, s64 }) { |
| 145 | setAction({G_FPTOSI, 0, Ty}, Legal); |
| 146 | setAction({G_FPTOUI, 0, Ty}, Legal); |
| 147 | setAction({G_SITOFP, 1, Ty}, Legal); |
| 148 | setAction({G_UITOFP, 1, Ty}, Legal); |
| 149 | } |
| 150 | |
| 151 | for (auto Ty : { s32, s64 }) { |
| 152 | setAction({G_FPTOSI, 1, Ty}, Legal); |
| 153 | setAction({G_FPTOUI, 1, Ty}, Legal); |
| 154 | setAction({G_SITOFP, 0, Ty}, Legal); |
| 155 | setAction({G_UITOFP, 0, Ty}, Legal); |
| 156 | } |
Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 157 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 158 | // Control-flow |
Tim Northover | 6aacd27 | 2016-10-12 22:48:36 +0000 | [diff] [blame] | 159 | for (auto Ty : {s1, s8, s16, s32}) |
| 160 | setAction({G_BRCOND, Ty}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 161 | |
Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 162 | // Select |
| 163 | for (auto Ty : {s1, s8, s16, s32, s64}) |
| 164 | setAction({G_SELECT, Ty}, Legal); |
| 165 | |
| 166 | setAction({G_SELECT, 1, s1}, Legal); |
| 167 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 168 | // Pointer-handling |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 169 | setAction({G_FRAME_INDEX, p0}, Legal); |
Tim Northover | ad0acca | 2016-10-10 21:49:53 +0000 | [diff] [blame] | 170 | setAction({G_GLOBAL_VALUE, p0}, Legal); |
Ahmed Bougacha | 0306b5e | 2016-08-16 14:02:42 +0000 | [diff] [blame] | 171 | |
Tim Northover | 037af52c | 2016-10-31 18:31:09 +0000 | [diff] [blame^] | 172 | for (auto Ty : {s1, s8, s16, s32, s64}) |
| 173 | setAction({G_PTRTOINT, 0, Ty}, Legal); |
| 174 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 175 | setAction({G_PTRTOINT, 1, p0}, Legal); |
| 176 | |
| 177 | setAction({G_INTTOPTR, 0, p0}, Legal); |
| 178 | setAction({G_INTTOPTR, 1, s64}, Legal); |
Tim Northover | 456a3c0 | 2016-08-23 19:30:38 +0000 | [diff] [blame] | 179 | |
Quentin Colombet | 404e435 | 2016-10-12 03:57:43 +0000 | [diff] [blame] | 180 | // Casts for 32 and 64-bit width type are just copies. |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 181 | for (auto Ty : {s1, s8, s16, s32, s64}) { |
| 182 | setAction({G_BITCAST, 0, Ty}, Legal); |
| 183 | setAction({G_BITCAST, 1, Ty}, Legal); |
| 184 | } |
| 185 | |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 186 | // For the sake of copying bits around, the type does not really |
| 187 | // matter as long as it fits a register. |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 188 | for (int EltSize = 8; EltSize <= 64; EltSize *= 2) { |
| 189 | setAction({G_BITCAST, 0, LLT::vector(128/EltSize, EltSize)}, Legal); |
Quentin Colombet | 404e435 | 2016-10-12 03:57:43 +0000 | [diff] [blame] | 190 | setAction({G_BITCAST, 1, LLT::vector(128/EltSize, EltSize)}, Legal); |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 191 | if (EltSize >= 64) |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 192 | continue; |
| 193 | |
| 194 | setAction({G_BITCAST, 0, LLT::vector(64/EltSize, EltSize)}, Legal); |
Quentin Colombet | 404e435 | 2016-10-12 03:57:43 +0000 | [diff] [blame] | 195 | setAction({G_BITCAST, 1, LLT::vector(64/EltSize, EltSize)}, Legal); |
Quentin Colombet | db643d9 | 2016-10-13 00:12:01 +0000 | [diff] [blame] | 196 | if (EltSize >= 32) |
| 197 | continue; |
| 198 | |
| 199 | setAction({G_BITCAST, 0, LLT::vector(32/EltSize, EltSize)}, Legal); |
| 200 | setAction({G_BITCAST, 1, LLT::vector(32/EltSize, EltSize)}, Legal); |
Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 203 | computeTables(); |
| 204 | } |