blob: 06c11c84e3551701b72a0145a3cbb85ca7c618e8 [file] [log] [blame]
Igor Bregerb4442f32017-02-10 07:05:56 +00001//===- 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
21using namespace llvm;
Igor Breger321cf3c2017-03-03 08:06:46 +000022using namespace TargetOpcode;
Igor Bregerb4442f32017-02-10 07:05:56 +000023
24#ifndef LLVM_BUILD_GLOBAL_ISEL
25#error "You shouldn't build this"
26#endif
27
28X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI) : Subtarget(STI) {
29
30 setLegalizerInfo32bit();
31 setLegalizerInfo64bit();
Igor Breger321cf3c2017-03-03 08:06:46 +000032 setLegalizerInfoSSE1();
33 setLegalizerInfoSSE2();
Igor Bregerb4442f32017-02-10 07:05:56 +000034
35 computeTables();
36}
37
38void 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 Bregerf7359d82017-02-22 12:25:09 +000044 for (auto Ty : {s8, s16, s32}) {
Igor Breger321cf3c2017-03-03 08:06:46 +000045 setAction({G_ADD, Ty}, Legal);
46 setAction({G_SUB, Ty}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +000047 }
Igor Bregerb4442f32017-02-10 07:05:56 +000048}
Igor Bregerb4442f32017-02-10 07:05:56 +000049
Igor Bregerf7359d82017-02-22 12:25:09 +000050void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +000051
52 if (!Subtarget.is64Bit())
53 return;
54
55 const LLT s64 = LLT::scalar(64);
56
Igor Breger321cf3c2017-03-03 08:06:46 +000057 setAction({G_ADD, s64}, Legal);
58 setAction({G_SUB, s64}, Legal);
59}
60
61void 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
73void 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 Bregerb4442f32017-02-10 07:05:56 +000089}