blob: 1a2b96a31c6478ab8f945eb274a3650e978f6a14 [file] [log] [blame]
Tom Stellardca166212017-01-30 21:56:46 +00001//===- AMDGPULegalizerInfo.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/// AMDGPU.
12/// \todo This should be generated by TableGen.
13//===----------------------------------------------------------------------===//
14
Yaxun Liu0124b542018-02-13 18:00:25 +000015#include "AMDGPU.h"
Tom Stellardca166212017-01-30 21:56:46 +000016#include "AMDGPULegalizerInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000017#include "llvm/CodeGen/TargetOpcodes.h"
Tom Stellardca166212017-01-30 21:56:46 +000018#include "llvm/CodeGen/ValueTypes.h"
Tom Stellardca166212017-01-30 21:56:46 +000019#include "llvm/IR/DerivedTypes.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000020#include "llvm/IR/Type.h"
Tom Stellardca166212017-01-30 21:56:46 +000021#include "llvm/Support/Debug.h"
22
23using namespace llvm;
Daniel Sanders9ade5592018-01-29 17:37:29 +000024using namespace LegalizeActions;
Tom Stellardca166212017-01-30 21:56:46 +000025
Tom Stellardca166212017-01-30 21:56:46 +000026AMDGPULegalizerInfo::AMDGPULegalizerInfo() {
27 using namespace TargetOpcode;
28
Tom Stellarde0424122017-06-03 01:13:33 +000029 const LLT S1= LLT::scalar(1);
Tom Stellardff63ee02017-06-19 13:15:45 +000030 const LLT V2S16 = LLT::vector(2, 16);
Tom Stellardca166212017-01-30 21:56:46 +000031 const LLT S32 = LLT::scalar(32);
32 const LLT S64 = LLT::scalar(64);
Yaxun Liu0124b542018-02-13 18:00:25 +000033 const LLT P1 = LLT::pointer(AMDGPUAS::GLOBAL_ADDRESS, 64);
34 const LLT P2 = LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64);
Tom Stellardca166212017-01-30 21:56:46 +000035
Tom Stellardee6e6452017-06-12 20:54:56 +000036 setAction({G_ADD, S32}, Legal);
Matt Arsenaultdc14ec02018-03-01 19:22:05 +000037 setAction({G_MUL, S32}, Legal);
Tom Stellardaf552dc2017-06-23 15:17:17 +000038 setAction({G_AND, S32}, Legal);
Matt Arsenault3f6a2042018-03-01 19:09:21 +000039 setAction({G_OR, S32}, Legal);
40 setAction({G_XOR, S32}, Legal);
Tom Stellardee6e6452017-06-12 20:54:56 +000041
Tom Stellardff63ee02017-06-19 13:15:45 +000042 setAction({G_BITCAST, V2S16}, Legal);
43 setAction({G_BITCAST, 1, S32}, Legal);
44
45 setAction({G_BITCAST, S32}, Legal);
46 setAction({G_BITCAST, 1, V2S16}, Legal);
47
Tom Stellarde0424122017-06-03 01:13:33 +000048 // FIXME: i1 operands to intrinsics should always be legal, but other i1
49 // values may not be legal. We need to figure out how to distinguish
50 // between these two scenarios.
51 setAction({G_CONSTANT, S1}, Legal);
Tom Stellarda0d67c72017-05-12 16:46:46 +000052 setAction({G_CONSTANT, S32}, Legal);
Tom Stellardca166212017-01-30 21:56:46 +000053 setAction({G_CONSTANT, S64}, Legal);
54
Tom Stellarddde28a82017-05-26 16:40:03 +000055 setAction({G_FCONSTANT, S32}, Legal);
Matt Arsenault2a26a282018-02-26 17:20:43 +000056 setAction({G_FCONSTANT, S64}, Legal);
Tom Stellarddde28a82017-05-26 16:40:03 +000057
Matt Arsenault06cbb272018-03-01 19:16:52 +000058 setAction({G_IMPLICIT_DEF, S32}, Legal);
59 setAction({G_IMPLICIT_DEF, S64}, Legal);
60
Tom Stellardd0c6cf22017-10-27 23:57:41 +000061 setAction({G_FADD, S32}, Legal);
62
Matt Arsenault8e80a5f2018-03-01 19:09:16 +000063 setAction({G_FCMP, S1}, Legal);
64 setAction({G_FCMP, 1, S32}, Legal);
65 setAction({G_FCMP, 1, S64}, Legal);
66
Tom Stellard3337d742017-08-02 22:56:30 +000067 setAction({G_FMUL, S32}, Legal);
68
Matt Arsenault0529a8e2018-03-01 20:56:21 +000069 setAction({G_ZEXT, S64}, Legal);
70 setAction({G_ZEXT, 1, S32}, Legal);
71
Matt Arsenaultdd022ce2018-03-01 19:04:25 +000072 setAction({G_FPTOSI, S32}, Legal);
73 setAction({G_FPTOSI, 1, S32}, Legal);
74
Tom Stellard33445762018-02-07 04:47:59 +000075 setAction({G_FPTOUI, S32}, Legal);
76 setAction({G_FPTOUI, 1, S32}, Legal);
77
Tom Stellardca166212017-01-30 21:56:46 +000078 setAction({G_GEP, P1}, Legal);
79 setAction({G_GEP, P2}, Legal);
80 setAction({G_GEP, 1, S64}, Legal);
81
Tom Stellard8cd60a52017-06-06 14:16:50 +000082 setAction({G_ICMP, S1}, Legal);
83 setAction({G_ICMP, 1, S32}, Legal);
84
Tom Stellardca166212017-01-30 21:56:46 +000085 setAction({G_LOAD, P1}, Legal);
86 setAction({G_LOAD, P2}, Legal);
87 setAction({G_LOAD, S32}, Legal);
88 setAction({G_LOAD, 1, P1}, Legal);
89 setAction({G_LOAD, 1, P2}, Legal);
90
Tom Stellard2860a422017-06-07 13:54:51 +000091 setAction({G_SELECT, S32}, Legal);
92 setAction({G_SELECT, 1, S1}, Legal);
93
Tom Stellardeb8f1e22017-06-26 15:56:52 +000094 setAction({G_SHL, S32}, Legal);
95
Tom Stellardca166212017-01-30 21:56:46 +000096 setAction({G_STORE, S32}, Legal);
97 setAction({G_STORE, 1, P1}, Legal);
98
99 // FIXME: When RegBankSelect inserts copies, it will only create new
100 // registers with scalar types. This means we can end up with
101 // G_LOAD/G_STORE/G_GEP instruction with scalar types for their pointer
102 // operands. In assert builds, the instruction selector will assert
103 // if it sees a generic instruction which isn't legal, so we need to
104 // tell it that scalar types are legal for pointer operands
105 setAction({G_GEP, S64}, Legal);
106 setAction({G_LOAD, 1, S64}, Legal);
107 setAction({G_STORE, 1, S64}, Legal);
108
Matt Arsenault71272e62018-03-05 16:25:15 +0000109 // FIXME: Doesn't handle extract of illegal sizes.
110 getActionDefinitionsBuilder(G_EXTRACT)
111 .unsupportedIf([=](const LegalityQuery &Query) {
112 return Query.Types[0].getSizeInBits() >= Query.Types[1].getSizeInBits();
113 })
114 .legalIf([=](const LegalityQuery &Query) {
115 const LLT &Ty0 = Query.Types[0];
116 const LLT &Ty1 = Query.Types[1];
117 return (Ty0.getSizeInBits() % 32 == 0) &&
118 (Ty1.getSizeInBits() % 32 == 0);
119 });
120
Tom Stellardca166212017-01-30 21:56:46 +0000121 computeTables();
122}