blob: 871556c8ed9c3ca886943a1dee3ccc4eb985d9a0 [file] [log] [blame]
Tim Northover69fa84a2016-10-14 22:18:18 +00001//===- AArch64LegalizerInfo.cpp ----------------------------------*- C++ -*-==//
Tim Northover33b07d62016-07-22 20:03:43 +00002//
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 Northover69fa84a2016-10-14 22:18:18 +000015#include "AArch64LegalizerInfo.h"
Tim Northover33b07d62016-07-22 20:03:43 +000016#include "llvm/CodeGen/ValueTypes.h"
17#include "llvm/IR/Type.h"
18#include "llvm/IR/DerivedTypes.h"
19#include "llvm/Target/TargetOpcodes.h"
20
21using namespace llvm;
22
23#ifndef LLVM_BUILD_GLOBAL_ISEL
24#error "You shouldn't build this"
25#endif
26
Tim Northover69fa84a2016-10-14 22:18:18 +000027AArch64LegalizerInfo::AArch64LegalizerInfo() {
Ahmed Bougachaad30db32016-08-02 15:10:28 +000028 using namespace TargetOpcode;
Tim Northover5ae83502016-09-15 09:20:34 +000029 const LLT p0 = LLT::pointer(0, 64);
Tim Northoverea904f92016-08-19 22:40:00 +000030 const LLT s1 = LLT::scalar(1);
Tim Northover9656f142016-08-04 20:54:13 +000031 const LLT s8 = LLT::scalar(8);
32 const LLT s16 = LLT::scalar(16);
Ahmed Bougachaad30db32016-08-02 15:10:28 +000033 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 Northover7a753d92016-08-26 17:46:06 +000039 for (auto BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SHL}) {
Tim Northoverfe880a82016-08-25 17:37:39 +000040 // These operations naturally get the right answer when used on
41 // GPR32, even if the actual type is narrower.
Ahmed Bougachacfb384d2017-01-23 21:10:05 +000042 for (auto Ty : {s32, s64, v2s32, v4s32, v2s64})
Quentin Colombete15e4602017-01-27 01:13:25 +000043 setAction({BinOp, Ty}, Legal);
Ahmed Bougachacfb384d2017-01-23 21:10:05 +000044
45 for (auto Ty : {s1, s8, s16})
Quentin Colombete15e4602017-01-27 01:13:25 +000046 setAction({BinOp, Ty}, WidenScalar);
Tim Northover9656f142016-08-04 20:54:13 +000047 }
48
Quentin Colombete15e4602017-01-27 01:13:25 +000049 setAction({G_GEP, p0}, Legal);
50 setAction({G_GEP, 1, s64}, Legal);
Tim Northover22d82cf2016-09-15 11:02:19 +000051
52 for (auto Ty : {s1, s8, s16, s32})
Quentin Colombete15e4602017-01-27 01:13:25 +000053 setAction({G_GEP, 1, Ty}, WidenScalar);
Tim Northover22d82cf2016-09-15 11:02:19 +000054
Tim Northover7a753d92016-08-26 17:46:06 +000055 for (auto BinOp : {G_LSHR, G_ASHR, G_SDIV, G_UDIV}) {
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000056 for (auto Ty : {s32, s64})
Quentin Colombete15e4602017-01-27 01:13:25 +000057 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000058
Tim Northover7a753d92016-08-26 17:46:06 +000059 for (auto Ty : {s1, s8, s16})
Quentin Colombete15e4602017-01-27 01:13:25 +000060 setAction({BinOp, Ty}, WidenScalar);
Tim Northover7a753d92016-08-26 17:46:06 +000061 }
62
Tim Northovercecee562016-08-26 17:46:13 +000063 for (auto BinOp : { G_SREM, G_UREM })
64 for (auto Ty : { s1, s8, s16, s32, s64 })
Quentin Colombete15e4602017-01-27 01:13:25 +000065 setAction({BinOp, Ty}, Lower);
Tim Northovercecee562016-08-26 17:46:13 +000066
Tim Northoverd8a6d7c2016-08-25 17:37:41 +000067 for (auto Op : { G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_SMULO, G_UMULO }) {
Tim Northover438c77c2016-08-25 17:37:32 +000068 for (auto Ty : { s32, s64 })
Quentin Colombete15e4602017-01-27 01:13:25 +000069 setAction({Op, Ty}, Legal);
Tim Northover438c77c2016-08-25 17:37:32 +000070
Quentin Colombete15e4602017-01-27 01:13:25 +000071 setAction({Op, 1, s1}, Legal);
Tim Northoverd8a6d7c2016-08-25 17:37:41 +000072 }
73
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000074 for (auto BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
75 for (auto Ty : {s32, s64})
Quentin Colombete15e4602017-01-27 01:13:25 +000076 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000077
Quentin Colombete15e4602017-01-27 01:13:25 +000078 setAction({G_FREM, s32}, Libcall);
79 setAction({G_FREM, s64}, Libcall);
Tim Northoveredb3c8c2016-08-29 19:07:16 +000080
Tim Northover3c73e362016-08-23 18:20:09 +000081 for (auto MemOp : {G_LOAD, G_STORE}) {
Quentin Colombetd3126d52016-10-11 00:21:08 +000082 for (auto Ty : {s8, s16, s32, s64, p0, v2s32})
Quentin Colombete15e4602017-01-27 01:13:25 +000083 setAction({MemOp, Ty}, Legal);
Ahmed Bougachaad30db32016-08-02 15:10:28 +000084
Quentin Colombete15e4602017-01-27 01:13:25 +000085 setAction({MemOp, s1}, WidenScalar);
Tim Northovera01bece2016-08-23 19:30:42 +000086
87 // And everything's fine in addrspace 0.
Quentin Colombete15e4602017-01-27 01:13:25 +000088 setAction({MemOp, 1, p0}, Legal);
Tim Northover3c73e362016-08-23 18:20:09 +000089 }
90
Tim Northoverb3a0be42016-08-23 21:01:20 +000091 // Constants
Tim Northoverea904f92016-08-19 22:40:00 +000092 for (auto Ty : {s32, s64}) {
Quentin Colombete15e4602017-01-27 01:13:25 +000093 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
94 setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal);
Tim Northoverea904f92016-08-19 22:40:00 +000095 }
96
Quentin Colombete15e4602017-01-27 01:13:25 +000097 setAction({G_CONSTANT, p0}, Legal);
Tim Northover7a1ec012016-08-25 17:37:35 +000098
Tim Northoverea904f92016-08-19 22:40:00 +000099 for (auto Ty : {s1, s8, s16})
Quentin Colombete15e4602017-01-27 01:13:25 +0000100 setAction({TargetOpcode::G_CONSTANT, Ty}, WidenScalar);
Tim Northoverea904f92016-08-19 22:40:00 +0000101
Quentin Colombete15e4602017-01-27 01:13:25 +0000102 setAction({TargetOpcode::G_FCONSTANT, s16}, WidenScalar);
Tim Northover9656f142016-08-04 20:54:13 +0000103
Quentin Colombete15e4602017-01-27 01:13:25 +0000104 setAction({G_ICMP, s1}, Legal);
105 setAction({G_ICMP, 1, s32}, Legal);
106 setAction({G_ICMP, 1, s64}, Legal);
107 setAction({G_ICMP, 1, p0}, Legal);
Tim Northover6cd4b232016-08-23 21:01:26 +0000108
Tim Northover051b8ad2016-08-26 17:46:17 +0000109 for (auto Ty : {s1, s8, s16}) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000110 setAction({G_ICMP, 1, Ty}, WidenScalar);
Tim Northover6cd4b232016-08-23 21:01:26 +0000111 }
112
Quentin Colombete15e4602017-01-27 01:13:25 +0000113 setAction({G_FCMP, s1}, Legal);
114 setAction({G_FCMP, 1, s32}, Legal);
115 setAction({G_FCMP, 1, s64}, Legal);
Tim Northover30bd36e2016-08-26 17:46:19 +0000116
Tim Northover2c4a8382016-08-25 17:37:25 +0000117 // Extensions
118 for (auto Ty : { s1, s8, s16, s32, s64 }) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000119 setAction({G_ZEXT, Ty}, Legal);
120 setAction({G_SEXT, Ty}, Legal);
121 setAction({G_ANYEXT, Ty}, Legal);
Tim Northover2c4a8382016-08-25 17:37:25 +0000122 }
123
124 for (auto Ty : { s1, s8, s16, s32 }) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000125 setAction({G_ZEXT, 1, Ty}, Legal);
126 setAction({G_SEXT, 1, Ty}, Legal);
127 setAction({G_ANYEXT, 1, Ty}, Legal);
Tim Northover2c4a8382016-08-25 17:37:25 +0000128 }
129
Quentin Colombete15e4602017-01-27 01:13:25 +0000130 setAction({G_FPEXT, s64}, Legal);
131 setAction({G_FPEXT, 1, s32}, Legal);
Tim Northoverbc1701c2016-08-26 17:46:22 +0000132
Tim Northover438c77c2016-08-25 17:37:32 +0000133 // Truncations
134 for (auto Ty : { s16, s32 })
Quentin Colombete15e4602017-01-27 01:13:25 +0000135 setAction({G_FPTRUNC, Ty}, Legal);
Tim Northover438c77c2016-08-25 17:37:32 +0000136
137 for (auto Ty : { s32, s64 })
Quentin Colombete15e4602017-01-27 01:13:25 +0000138 setAction({G_FPTRUNC, 1, Ty}, Legal);
Tim Northover438c77c2016-08-25 17:37:32 +0000139
140 for (auto Ty : { s1, s8, s16, s32 })
Quentin Colombete15e4602017-01-27 01:13:25 +0000141 setAction({G_TRUNC, Ty}, Legal);
Tim Northover438c77c2016-08-25 17:37:32 +0000142
143 for (auto Ty : { s8, s16, s32, s64 })
Quentin Colombete15e4602017-01-27 01:13:25 +0000144 setAction({G_TRUNC, 1, Ty}, Legal);
Tim Northover438c77c2016-08-25 17:37:32 +0000145
Tim Northover5d0eaa42016-08-26 17:45:58 +0000146 // Conversions
Ahmed Bougachad2948232017-01-20 01:37:24 +0000147 for (auto Ty : { s32, s64 }) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000148 setAction({G_FPTOSI, 0, Ty}, Legal);
149 setAction({G_FPTOUI, 0, Ty}, Legal);
150 setAction({G_SITOFP, 1, Ty}, Legal);
151 setAction({G_UITOFP, 1, Ty}, Legal);
Tim Northover5d0eaa42016-08-26 17:45:58 +0000152 }
Ahmed Bougachad2948232017-01-20 01:37:24 +0000153 for (auto Ty : { s1, s8, s16 }) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000154 setAction({G_FPTOSI, 0, Ty}, WidenScalar);
155 setAction({G_FPTOUI, 0, Ty}, WidenScalar);
156 setAction({G_SITOFP, 1, Ty}, WidenScalar);
157 setAction({G_UITOFP, 1, Ty}, WidenScalar);
Ahmed Bougachad2948232017-01-20 01:37:24 +0000158 }
Tim Northover5d0eaa42016-08-26 17:45:58 +0000159
160 for (auto Ty : { s32, s64 }) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000161 setAction({G_FPTOSI, 1, Ty}, Legal);
162 setAction({G_FPTOUI, 1, Ty}, Legal);
163 setAction({G_SITOFP, 0, Ty}, Legal);
164 setAction({G_UITOFP, 0, Ty}, Legal);
Tim Northover5d0eaa42016-08-26 17:45:58 +0000165 }
Tim Northover438c77c2016-08-25 17:37:32 +0000166
Tim Northoverb3a0be42016-08-23 21:01:20 +0000167 // Control-flow
Tim Northover6aacd272016-10-12 22:48:36 +0000168 for (auto Ty : {s1, s8, s16, s32})
Quentin Colombete15e4602017-01-27 01:13:25 +0000169 setAction({G_BRCOND, Ty}, Legal);
Ahmed Bougachaad30db32016-08-02 15:10:28 +0000170
Tim Northover1d18a992016-08-26 17:46:03 +0000171 // Select
Kristof Beylse9412b42017-01-19 13:32:14 +0000172 for (auto Ty : {s1, s8, s16, s32, s64, p0})
Quentin Colombete15e4602017-01-27 01:13:25 +0000173 setAction({G_SELECT, Ty}, Legal);
Tim Northover1d18a992016-08-26 17:46:03 +0000174
Quentin Colombete15e4602017-01-27 01:13:25 +0000175 setAction({G_SELECT, 1, s1}, Legal);
Tim Northover1d18a992016-08-26 17:46:03 +0000176
Tim Northoverb3a0be42016-08-23 21:01:20 +0000177 // Pointer-handling
Quentin Colombete15e4602017-01-27 01:13:25 +0000178 setAction({G_FRAME_INDEX, p0}, Legal);
179 setAction({G_GLOBAL_VALUE, p0}, Legal);
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000180
Tim Northover037af52c2016-10-31 18:31:09 +0000181 for (auto Ty : {s1, s8, s16, s32, s64})
Quentin Colombete15e4602017-01-27 01:13:25 +0000182 setAction({G_PTRTOINT, 0, Ty}, Legal);
Tim Northover037af52c2016-10-31 18:31:09 +0000183
Quentin Colombete15e4602017-01-27 01:13:25 +0000184 setAction({G_PTRTOINT, 1, p0}, Legal);
Tim Northovera01bece2016-08-23 19:30:42 +0000185
Quentin Colombete15e4602017-01-27 01:13:25 +0000186 setAction({G_INTTOPTR, 0, p0}, Legal);
187 setAction({G_INTTOPTR, 1, s64}, Legal);
Tim Northover456a3c02016-08-23 19:30:38 +0000188
Quentin Colombet404e4352016-10-12 03:57:43 +0000189 // Casts for 32 and 64-bit width type are just copies.
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000190 for (auto Ty : {s1, s8, s16, s32, s64}) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000191 setAction({G_BITCAST, 0, Ty}, Legal);
192 setAction({G_BITCAST, 1, Ty}, Legal);
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000193 }
194
Quentin Colombetdb643d92016-10-13 00:12:01 +0000195 // For the sake of copying bits around, the type does not really
196 // matter as long as it fits a register.
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000197 for (int EltSize = 8; EltSize <= 64; EltSize *= 2) {
Quentin Colombete15e4602017-01-27 01:13:25 +0000198 setAction({G_BITCAST, 0, LLT::vector(128/EltSize, EltSize)}, Legal);
199 setAction({G_BITCAST, 1, LLT::vector(128/EltSize, EltSize)}, Legal);
Quentin Colombetdb643d92016-10-13 00:12:01 +0000200 if (EltSize >= 64)
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000201 continue;
202
Quentin Colombete15e4602017-01-27 01:13:25 +0000203 setAction({G_BITCAST, 0, LLT::vector(64/EltSize, EltSize)}, Legal);
204 setAction({G_BITCAST, 1, LLT::vector(64/EltSize, EltSize)}, Legal);
Quentin Colombetdb643d92016-10-13 00:12:01 +0000205 if (EltSize >= 32)
206 continue;
207
Quentin Colombete15e4602017-01-27 01:13:25 +0000208 setAction({G_BITCAST, 0, LLT::vector(32/EltSize, EltSize)}, Legal);
209 setAction({G_BITCAST, 1, LLT::vector(32/EltSize, EltSize)}, Legal);
Tim Northoverc1d8c2b2016-10-11 22:29:23 +0000210 }
211
Tim Northover33b07d62016-07-22 20:03:43 +0000212 computeTables();
213}