blob: 3ab80c4f20ca4d226df246195575ef6daf67e0c0 [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"
Igor Breger531a2032017-03-26 08:11:12 +000016#include "X86TargetMachine.h"
Igor Bregerb4442f32017-02-10 07:05:56 +000017#include "llvm/CodeGen/ValueTypes.h"
18#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/Type.h"
20#include "llvm/Target/TargetOpcodes.h"
21
22using namespace llvm;
Igor Breger321cf3c2017-03-03 08:06:46 +000023using namespace TargetOpcode;
Igor Bregerb4442f32017-02-10 07:05:56 +000024
25#ifndef LLVM_BUILD_GLOBAL_ISEL
26#error "You shouldn't build this"
27#endif
28
Igor Breger531a2032017-03-26 08:11:12 +000029X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
30 const X86TargetMachine &TM)
31 : Subtarget(STI), TM(TM) {
Igor Bregerb4442f32017-02-10 07:05:56 +000032
33 setLegalizerInfo32bit();
34 setLegalizerInfo64bit();
Igor Breger321cf3c2017-03-03 08:06:46 +000035 setLegalizerInfoSSE1();
36 setLegalizerInfoSSE2();
Igor Bregerb4442f32017-02-10 07:05:56 +000037
38 computeTables();
39}
40
41void X86LegalizerInfo::setLegalizerInfo32bit() {
42
Igor Bregera8ba5722017-03-23 15:25:57 +000043 if (Subtarget.is64Bit())
44 return;
45
46 const LLT p0 = LLT::pointer(0, 32);
Igor Bregerb4442f32017-02-10 07:05:56 +000047 const LLT s8 = LLT::scalar(8);
48 const LLT s16 = LLT::scalar(16);
49 const LLT s32 = LLT::scalar(32);
50
Igor Bregera8ba5722017-03-23 15:25:57 +000051 for (unsigned BinOp : {G_ADD, G_SUB})
52 for (auto Ty : {s8, s16, s32})
53 setAction({BinOp, Ty}, Legal);
54
55 for (unsigned MemOp : {G_LOAD, G_STORE}) {
56 for (auto Ty : {s8, s16, s32, p0})
57 setAction({MemOp, Ty}, Legal);
58
59 // And everything's fine in addrspace 0.
60 setAction({MemOp, 1, p0}, Legal);
Igor Bregerf7359d82017-02-22 12:25:09 +000061 }
Igor Breger531a2032017-03-26 08:11:12 +000062
63 // Pointer-handling
64 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +000065}
Igor Bregerb4442f32017-02-10 07:05:56 +000066
Igor Bregerf7359d82017-02-22 12:25:09 +000067void X86LegalizerInfo::setLegalizerInfo64bit() {
Igor Bregerb4442f32017-02-10 07:05:56 +000068
69 if (!Subtarget.is64Bit())
70 return;
71
Igor Breger531a2032017-03-26 08:11:12 +000072 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
Igor Bregera8ba5722017-03-23 15:25:57 +000073 const LLT s8 = LLT::scalar(8);
74 const LLT s16 = LLT::scalar(16);
75 const LLT s32 = LLT::scalar(32);
Igor Bregerb4442f32017-02-10 07:05:56 +000076 const LLT s64 = LLT::scalar(64);
77
Igor Bregera8ba5722017-03-23 15:25:57 +000078 for (unsigned BinOp : {G_ADD, G_SUB})
79 for (auto Ty : {s8, s16, s32, s64})
80 setAction({BinOp, Ty}, Legal);
81
82 for (unsigned MemOp : {G_LOAD, G_STORE}) {
83 for (auto Ty : {s8, s16, s32, s64, p0})
84 setAction({MemOp, Ty}, Legal);
85
86 // And everything's fine in addrspace 0.
87 setAction({MemOp, 1, p0}, Legal);
88 }
Igor Breger531a2032017-03-26 08:11:12 +000089
90 // Pointer-handling
91 setAction({G_FRAME_INDEX, p0}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +000092}
93
94void X86LegalizerInfo::setLegalizerInfoSSE1() {
95 if (!Subtarget.hasSSE1())
96 return;
97
98 const LLT s32 = LLT::scalar(32);
99 const LLT v4s32 = LLT::vector(4, 32);
Igor Bregera8ba5722017-03-23 15:25:57 +0000100 const LLT v2s64 = LLT::vector(2, 64);
Igor Breger321cf3c2017-03-03 08:06:46 +0000101
102 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
103 for (auto Ty : {s32, v4s32})
104 setAction({BinOp, Ty}, Legal);
Igor Bregera8ba5722017-03-23 15:25:57 +0000105
106 for (unsigned MemOp : {G_LOAD, G_STORE})
107 for (auto Ty : {v4s32, v2s64})
108 setAction({MemOp, Ty}, Legal);
Igor Breger321cf3c2017-03-03 08:06:46 +0000109}
110
111void X86LegalizerInfo::setLegalizerInfoSSE2() {
112 if (!Subtarget.hasSSE2())
113 return;
114
115 const LLT s64 = LLT::scalar(64);
116 const LLT v4s32 = LLT::vector(4, 32);
117 const LLT v2s64 = LLT::vector(2, 64);
118
119 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
120 for (auto Ty : {s64, v2s64})
121 setAction({BinOp, Ty}, Legal);
122
123 for (unsigned BinOp : {G_ADD, G_SUB})
124 for (auto Ty : {v4s32})
125 setAction({BinOp, Ty}, Legal);
Igor Bregerb4442f32017-02-10 07:05:56 +0000126}