Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 24 | #error "You shouldn't build this" |
| 25 | #endif |
| 26 | |
| 27 | AArch64MachineLegalizer::AArch64MachineLegalizer() { |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 28 | using namespace TargetOpcode; |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 29 | const LLT p0 = LLT::pointer(0); |
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 | 61c1614 | 2016-08-04 21:39:49 +0000 | [diff] [blame] | 39 | for (auto BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) { |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 40 | for (auto Ty : {s32, s64, v2s32, v4s32, v2s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 41 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 42 | |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 43 | for (auto Ty : {s8, s16}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 44 | setAction({BinOp, Ty}, WidenScalar); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Ahmed Bougacha | 1d0560b | 2016-08-18 15:17:13 +0000 | [diff] [blame] | 47 | for (auto BinOp : {G_SHL, G_LSHR, G_ASHR, G_SDIV, G_UDIV}) |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 48 | for (auto Ty : {s32, s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 49 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 2ac5bf9 | 2016-08-16 14:02:47 +0000 | [diff] [blame] | 50 | |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 51 | for (auto BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV}) |
| 52 | for (auto Ty : {s32, s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 53 | setAction({BinOp, Ty}, Legal); |
Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 54 | |
Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 55 | for (auto MemOp : {G_LOAD, G_STORE}) { |
| 56 | for (auto Ty : {s8, s16, s32, s64}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 57 | setAction({MemOp, Ty}, Legal); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 58 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 59 | setAction({MemOp, s1}, WidenScalar); |
| 60 | |
| 61 | // And everything's fine in addrspace 0. |
| 62 | setAction({MemOp, 1, p0}, Legal); |
Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame^] | 65 | // Constants |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 66 | for (auto Ty : {s32, s64}) { |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 67 | setAction({TargetOpcode::G_CONSTANT, Ty}, Legal); |
| 68 | setAction({TargetOpcode::G_FCONSTANT, Ty}, Legal); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | for (auto Ty : {s1, s8, s16}) |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 72 | setAction({TargetOpcode::G_CONSTANT, Ty}, WidenScalar); |
Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 73 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 74 | setAction({TargetOpcode::G_FCONSTANT, s16}, WidenScalar); |
Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 75 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame^] | 76 | // Control-flow |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 77 | setAction({G_BR, LLT::unsized()}, Legal); |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame^] | 78 | setAction({G_BRCOND, s32}, Legal); |
| 79 | for (auto Ty : {s1, s8, s16}) |
| 80 | setAction({G_BRCOND, Ty}, WidenScalar); |
Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 81 | |
Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame^] | 82 | // Pointer-handling |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 83 | setAction({G_FRAME_INDEX, p0}, Legal); |
Ahmed Bougacha | 0306b5e | 2016-08-16 14:02:42 +0000 | [diff] [blame] | 84 | |
Tim Northover | a01bece | 2016-08-23 19:30:42 +0000 | [diff] [blame] | 85 | setAction({G_PTRTOINT, 0, s64}, Legal); |
| 86 | setAction({G_PTRTOINT, 1, p0}, Legal); |
| 87 | |
| 88 | setAction({G_INTTOPTR, 0, p0}, Legal); |
| 89 | setAction({G_INTTOPTR, 1, s64}, Legal); |
Tim Northover | 456a3c0 | 2016-08-23 19:30:38 +0000 | [diff] [blame] | 90 | |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 91 | computeTables(); |
| 92 | } |