Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 1 | //===- X86LegalizerInfo.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 X86. |
| 11 | /// \todo This should be generated by TableGen. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "X86LegalizerInfo.h" |
| 15 | #include "X86Subtarget.h" |
| 16 | #include "llvm/CodeGen/ValueTypes.h" |
| 17 | #include "llvm/IR/DerivedTypes.h" |
| 18 | #include "llvm/IR/Type.h" |
| 19 | #include "llvm/Target/TargetOpcodes.h" |
| 20 | |
| 21 | using namespace llvm; |
Igor Breger | 321cf3c | 2017-03-03 08:06:46 +0000 | [diff] [blame^] | 22 | using namespace TargetOpcode; |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 23 | |
| 24 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 25 | #error "You shouldn't build this" |
| 26 | #endif |
| 27 | |
| 28 | X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI) : Subtarget(STI) { |
| 29 | |
| 30 | setLegalizerInfo32bit(); |
| 31 | setLegalizerInfo64bit(); |
Igor Breger | 321cf3c | 2017-03-03 08:06:46 +0000 | [diff] [blame^] | 32 | setLegalizerInfoSSE1(); |
| 33 | setLegalizerInfoSSE2(); |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 34 | |
| 35 | computeTables(); |
| 36 | } |
| 37 | |
| 38 | void X86LegalizerInfo::setLegalizerInfo32bit() { |
| 39 | |
| 40 | const LLT s8 = LLT::scalar(8); |
| 41 | const LLT s16 = LLT::scalar(16); |
| 42 | const LLT s32 = LLT::scalar(32); |
| 43 | |
Igor Breger | f7359d8 | 2017-02-22 12:25:09 +0000 | [diff] [blame] | 44 | for (auto Ty : {s8, s16, s32}) { |
Igor Breger | 321cf3c | 2017-03-03 08:06:46 +0000 | [diff] [blame^] | 45 | setAction({G_ADD, Ty}, Legal); |
| 46 | setAction({G_SUB, Ty}, Legal); |
Igor Breger | f7359d8 | 2017-02-22 12:25:09 +0000 | [diff] [blame] | 47 | } |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 48 | } |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 49 | |
Igor Breger | f7359d8 | 2017-02-22 12:25:09 +0000 | [diff] [blame] | 50 | void X86LegalizerInfo::setLegalizerInfo64bit() { |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 51 | |
| 52 | if (!Subtarget.is64Bit()) |
| 53 | return; |
| 54 | |
| 55 | const LLT s64 = LLT::scalar(64); |
| 56 | |
Igor Breger | 321cf3c | 2017-03-03 08:06:46 +0000 | [diff] [blame^] | 57 | setAction({G_ADD, s64}, Legal); |
| 58 | setAction({G_SUB, s64}, Legal); |
| 59 | } |
| 60 | |
| 61 | void X86LegalizerInfo::setLegalizerInfoSSE1() { |
| 62 | if (!Subtarget.hasSSE1()) |
| 63 | return; |
| 64 | |
| 65 | const LLT s32 = LLT::scalar(32); |
| 66 | const LLT v4s32 = LLT::vector(4, 32); |
| 67 | |
| 68 | for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV}) |
| 69 | for (auto Ty : {s32, v4s32}) |
| 70 | setAction({BinOp, Ty}, Legal); |
| 71 | } |
| 72 | |
| 73 | void X86LegalizerInfo::setLegalizerInfoSSE2() { |
| 74 | if (!Subtarget.hasSSE2()) |
| 75 | return; |
| 76 | |
| 77 | const LLT s64 = LLT::scalar(64); |
| 78 | const LLT v4s32 = LLT::vector(4, 32); |
| 79 | const LLT v2s64 = LLT::vector(2, 64); |
| 80 | |
| 81 | for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV}) |
| 82 | for (auto Ty : {s64, v2s64}) |
| 83 | setAction({BinOp, Ty}, Legal); |
| 84 | |
| 85 | for (unsigned BinOp : {G_ADD, G_SUB}) |
| 86 | for (auto Ty : {v4s32}) |
| 87 | setAction({BinOp, Ty}, Legal); |
| 88 | |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 89 | } |