blob: e6012aa1cef41e7221505d41b082b1fbd30ce5f6 [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 Northovera01bece2016-08-23 19:30:42 +000029 const LLT p0 = LLT::pointer(0);
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 Northover61c16142016-08-04 21:39:49 +000039 for (auto BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) {
Ahmed Bougachaad30db32016-08-02 15:10:28 +000040 for (auto Ty : {s32, s64, v2s32, v4s32, v2s64})
Tim Northovera01bece2016-08-23 19:30:42 +000041 setAction({BinOp, Ty}, Legal);
Ahmed Bougachaad30db32016-08-02 15:10:28 +000042
Tim Northover9656f142016-08-04 20:54:13 +000043 for (auto Ty : {s8, s16})
Tim Northovera01bece2016-08-23 19:30:42 +000044 setAction({BinOp, Ty}, WidenScalar);
Tim Northover9656f142016-08-04 20:54:13 +000045 }
46
Ahmed Bougacha1d0560b2016-08-18 15:17:13 +000047 for (auto BinOp : {G_SHL, G_LSHR, G_ASHR, G_SDIV, G_UDIV})
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000048 for (auto Ty : {s32, s64})
Tim Northovera01bece2016-08-23 19:30:42 +000049 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha2ac5bf92016-08-16 14:02:47 +000050
Tim Northover438c77c2016-08-25 17:37:32 +000051 for (auto Op : { G_UADDE, G_USUBE, G_SADDO, G_SSUBO, G_SMULO, G_UMULO })
52 for (auto Ty : { s32, s64 })
53 setAction({Op, Ty}, Legal);
54
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000055 for (auto BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
56 for (auto Ty : {s32, s64})
Tim Northovera01bece2016-08-23 19:30:42 +000057 setAction({BinOp, Ty}, Legal);
Ahmed Bougacha33e19fe2016-08-18 16:05:11 +000058
Tim Northover3c73e362016-08-23 18:20:09 +000059 for (auto MemOp : {G_LOAD, G_STORE}) {
60 for (auto Ty : {s8, s16, s32, s64})
Tim Northovera01bece2016-08-23 19:30:42 +000061 setAction({MemOp, Ty}, Legal);
Ahmed Bougachaad30db32016-08-02 15:10:28 +000062
Tim Northovera01bece2016-08-23 19:30:42 +000063 setAction({MemOp, s1}, WidenScalar);
64
65 // And everything's fine in addrspace 0.
66 setAction({MemOp, 1, p0}, Legal);
Tim Northover3c73e362016-08-23 18:20:09 +000067 }
68
Tim Northoverb3a0be42016-08-23 21:01:20 +000069 // Constants
Tim Northoverea904f92016-08-19 22:40:00 +000070 for (auto Ty : {s32, s64}) {
Tim Northovera01bece2016-08-23 19:30:42 +000071 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
72 setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal);
Tim Northoverea904f92016-08-19 22:40:00 +000073 }
74
75 for (auto Ty : {s1, s8, s16})
Tim Northovera01bece2016-08-23 19:30:42 +000076 setAction({TargetOpcode::G_CONSTANT, Ty}, WidenScalar);
Tim Northoverea904f92016-08-19 22:40:00 +000077
Tim Northovera01bece2016-08-23 19:30:42 +000078 setAction({TargetOpcode::G_FCONSTANT, s16}, WidenScalar);
Tim Northover9656f142016-08-04 20:54:13 +000079
Tim Northover6cd4b232016-08-23 21:01:26 +000080 // Comparisons: we produce a result in s32 with undefined high-bits for
81 // now. Values being compared can be 32 or 64-bits.
82 for (auto CmpOp : { G_ICMP }) {
83 setAction({CmpOp, 0, s32}, Legal);
84 setAction({CmpOp, 1, s32}, Legal);
85 setAction({CmpOp, 1, s64}, Legal);
86
87 for (auto Ty : {s1, s8, s16}) {
88 setAction({CmpOp, 0, Ty}, WidenScalar);
89 setAction({CmpOp, 1, Ty}, WidenScalar);
90 }
91 }
92
Tim Northover2c4a8382016-08-25 17:37:25 +000093 // Extensions
94 for (auto Ty : { s1, s8, s16, s32, s64 }) {
95 setAction({G_ZEXT, Ty}, Legal);
96 setAction({G_SEXT, Ty}, Legal);
97 setAction({G_ANYEXT, Ty}, Legal);
98 }
99
100 for (auto Ty : { s1, s8, s16, s32 }) {
101 setAction({G_ZEXT, 1, Ty}, Legal);
102 setAction({G_SEXT, 1, Ty}, Legal);
103 setAction({G_ANYEXT, 1, Ty}, Legal);
104 }
105
Tim Northover438c77c2016-08-25 17:37:32 +0000106 // Truncations
107 for (auto Ty : { s16, s32 })
108 setAction({G_FPTRUNC, Ty}, Legal);
109
110 for (auto Ty : { s32, s64 })
111 setAction({G_FPTRUNC, 1, Ty}, Legal);
112
113 for (auto Ty : { s1, s8, s16, s32 })
114 setAction({G_TRUNC, Ty}, Legal);
115
116 for (auto Ty : { s8, s16, s32, s64 })
117 setAction({G_TRUNC, 1, Ty}, Legal);
118
119
Tim Northoverb3a0be42016-08-23 21:01:20 +0000120 // Control-flow
Tim Northovera01bece2016-08-23 19:30:42 +0000121 setAction({G_BR, LLT::unsized()}, Legal);
Tim Northoverb3a0be42016-08-23 21:01:20 +0000122 setAction({G_BRCOND, s32}, Legal);
123 for (auto Ty : {s1, s8, s16})
124 setAction({G_BRCOND, Ty}, WidenScalar);
Ahmed Bougachaad30db32016-08-02 15:10:28 +0000125
Tim Northoverb3a0be42016-08-23 21:01:20 +0000126 // Pointer-handling
Tim Northovera01bece2016-08-23 19:30:42 +0000127 setAction({G_FRAME_INDEX, p0}, Legal);
Ahmed Bougacha0306b5e2016-08-16 14:02:42 +0000128
Tim Northovera01bece2016-08-23 19:30:42 +0000129 setAction({G_PTRTOINT, 0, s64}, Legal);
130 setAction({G_PTRTOINT, 1, p0}, Legal);
131
132 setAction({G_INTTOPTR, 0, p0}, Legal);
133 setAction({G_INTTOPTR, 1, s64}, Legal);
Tim Northover456a3c02016-08-23 19:30:38 +0000134
Tim Northover33b07d62016-07-22 20:03:43 +0000135 computeTables();
136}