blob: f59804d38539d6b685d27196a2fb2b4f0e79cf8c [file] [log] [blame]
Tim Northover33b07d62016-07-22 20:03:43 +00001//===- AArch64MachineLegalizer.cpp -------------------------------*- 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/// \file
10/// This file implements the targeting of the Machinelegalizer class for
11/// AArch64.
12/// \todo This should be generated by TableGen.
13//===----------------------------------------------------------------------===//
14
15#include "AArch64MachineLegalizer.h"
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
21using namespace llvm;
22
23#ifndef LLVM_BUILD_GLOBAL_ISEL
24#error "You shouldn't build this"
25#endif
26
27AArch64MachineLegalizer::AArch64MachineLegalizer() {
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.
42 for (auto Ty : {s1, s8, s16, s32, s64, v2s32, v4s32, v2s64})
Tim Northovera01bece2016-08-23 19:30:42 +000043 setAction({BinOp, Ty}, Legal);
Tim Northover9656f142016-08-04 20:54:13 +000044 }
45
Tim Northover22d82cf2016-09-15 11:02:19 +000046 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 Northover7a753d92016-08-26 17:46:06 +000052 for (auto BinOp : {G_LSHR, G_ASHR, G_SDIV, G_UDIV}) {
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000053 for (auto Ty : {s32, s64})
Tim Northovera01bece2016-08-23 19:30:42 +000054 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000055
Tim Northover7a753d92016-08-26 17:46:06 +000056 for (auto Ty : {s1, s8, s16})
57 setAction({BinOp, Ty}, WidenScalar);
58 }
59
Tim Northovercecee562016-08-26 17:46:13 +000060 for (auto BinOp : { G_SREM, G_UREM })
61 for (auto Ty : { s1, s8, s16, s32, s64 })
62 setAction({BinOp, Ty}, Lower);
63
Tim Northoverd8a6d7c2016-08-25 17:37:41 +000064 for (auto Op : { G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_SMULO, G_UMULO }) {
Tim Northover438c77c2016-08-25 17:37:32 +000065 for (auto Ty : { s32, s64 })
66 setAction({Op, Ty}, Legal);
67
Tim Northoverd8a6d7c2016-08-25 17:37:41 +000068 setAction({Op, 1, s1}, Legal);
69 }
70
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000071 for (auto BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
72 for (auto Ty : {s32, s64})
Tim Northovera01bece2016-08-23 19:30:42 +000073 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000074
Tim Northoveredb3c8c2016-08-29 19:07:16 +000075 setAction({G_FREM, s32}, Libcall);
76 setAction({G_FREM, s64}, Libcall);
77
Tim Northover3c73e362016-08-23 18:20:09 +000078 for (auto MemOp : {G_LOAD, G_STORE}) {
Quentin Colombetd3126d52016-10-11 00:21:08 +000079 for (auto Ty : {s8, s16, s32, s64, p0, v2s32})
Tim Northovera01bece2016-08-23 19:30:42 +000080 setAction({MemOp, Ty}, Legal);
Ahmed Bougachaad30db32016-08-02 15:10:28 +000081
Tim Northovera01bece2016-08-23 19:30:42 +000082 setAction({MemOp, s1}, WidenScalar);
83
84 // And everything's fine in addrspace 0.
85 setAction({MemOp, 1, p0}, Legal);
Tim Northover3c73e362016-08-23 18:20:09 +000086 }
87
Tim Northoverb3a0be42016-08-23 21:01:20 +000088 // Constants
Tim Northoverea904f92016-08-19 22:40:00 +000089 for (auto Ty : {s32, s64}) {
Tim Northovera01bece2016-08-23 19:30:42 +000090 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
91 setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal);
Tim Northoverea904f92016-08-19 22:40:00 +000092 }
93
Tim Northover7a1ec012016-08-25 17:37:35 +000094 setAction({G_CONSTANT, p0}, Legal);
95
Tim Northoverea904f92016-08-19 22:40:00 +000096 for (auto Ty : {s1, s8, s16})
Tim Northovera01bece2016-08-23 19:30:42 +000097 setAction({TargetOpcode::G_CONSTANT, Ty}, WidenScalar);
Tim Northoverea904f92016-08-19 22:40:00 +000098
Tim Northovera01bece2016-08-23 19:30:42 +000099 setAction({TargetOpcode::G_FCONSTANT, s16}, WidenScalar);
Tim Northover9656f142016-08-04 20:54:13 +0000100
Tim Northover051b8ad2016-08-26 17:46:17 +0000101 setAction({G_ICMP, s1}, Legal);
102 setAction({G_ICMP, 1, s32}, Legal);
103 setAction({G_ICMP, 1, s64}, Legal);
Tim Northover4cf0a482016-09-15 10:40:38 +0000104 setAction({G_ICMP, 1, p0}, Legal);
Tim Northover6cd4b232016-08-23 21:01:26 +0000105
Tim Northover051b8ad2016-08-26 17:46:17 +0000106 for (auto Ty : {s1, s8, s16}) {
107 setAction({G_ICMP, 1, Ty}, WidenScalar);
Tim Northover6cd4b232016-08-23 21:01:26 +0000108 }
109
Tim Northover30bd36e2016-08-26 17:46:19 +0000110 setAction({G_FCMP, s1}, Legal);
111 setAction({G_FCMP, 1, s32}, Legal);
112 setAction({G_FCMP, 1, s64}, Legal);
113
Tim Northover2c4a8382016-08-25 17:37:25 +0000114 // 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 Northoverbc1701c2016-08-26 17:46:22 +0000127 setAction({G_FPEXT, s64}, Legal);
128 setAction({G_FPEXT, 1, s32}, Legal);
129
Tim Northover438c77c2016-08-25 17:37:32 +0000130 // 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 Northover5d0eaa42016-08-26 17:45:58 +0000143 // 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 Northover438c77c2016-08-25 17:37:32 +0000157
Tim Northoverb3a0be42016-08-23 21:01:20 +0000158 // Control-flow
Tim Northoverb3a0be42016-08-23 21:01:20 +0000159 setAction({G_BRCOND, s32}, Legal);
160 for (auto Ty : {s1, s8, s16})
161 setAction({G_BRCOND, Ty}, WidenScalar);
Ahmed Bougachaad30db32016-08-02 15:10:28 +0000162
Tim Northover1d18a992016-08-26 17:46:03 +0000163 // Select
164 for (auto Ty : {s1, s8, s16, s32, s64})
165 setAction({G_SELECT, Ty}, Legal);
166
167 setAction({G_SELECT, 1, s1}, Legal);
168
Tim Northoverb3a0be42016-08-23 21:01:20 +0000169 // Pointer-handling
Tim Northovera01bece2016-08-23 19:30:42 +0000170 setAction({G_FRAME_INDEX, p0}, Legal);
Tim Northoverad0acca2016-10-10 21:49:53 +0000171 setAction({G_GLOBAL_VALUE, p0}, Legal);
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000172
Tim Northovera01bece2016-08-23 19:30:42 +0000173 setAction({G_PTRTOINT, 0, s64}, Legal);
174 setAction({G_PTRTOINT, 1, p0}, Legal);
175
176 setAction({G_INTTOPTR, 0, p0}, Legal);
177 setAction({G_INTTOPTR, 1, s64}, Legal);
Tim Northover456a3c02016-08-23 19:30:38 +0000178
Tim Northover33b07d62016-07-22 20:03:43 +0000179 computeTables();
180}