1//==- SystemZ.h - Top-Level Interface for SystemZ representation -*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the entry points for global functions defined in
10// the LLVM SystemZ backend.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
15#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
16
17#include "MCTargetDesc/SystemZMCTargetDesc.h"
18#include "llvm/Support/CodeGen.h"
19
20namespace llvm {
21class FunctionPass;
22class PassRegistry;
23class SystemZTargetMachine;
24
25namespace SystemZ {
26// Condition-code mask values.
27const unsigned CCMASK_0 = 1 << 3;
28const unsigned CCMASK_1 = 1 << 2;
29const unsigned CCMASK_2 = 1 << 1;
30const unsigned CCMASK_3 = 1 << 0;
31const unsigned CCMASK_ANY = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
32
33// Condition-code mask assignments for integer and floating-point
34// comparisons.
35const unsigned CCMASK_CMP_EQ = CCMASK_0;
36const unsigned CCMASK_CMP_LT = CCMASK_1;
37const unsigned CCMASK_CMP_GT = CCMASK_2;
38const unsigned CCMASK_CMP_NE = CCMASK_CMP_LT | CCMASK_CMP_GT;
39const unsigned CCMASK_CMP_LE = CCMASK_CMP_EQ | CCMASK_CMP_LT;
40const unsigned CCMASK_CMP_GE = CCMASK_CMP_EQ | CCMASK_CMP_GT;
41
42// Condition-code mask assignments for floating-point comparisons only.
43const unsigned CCMASK_CMP_UO = CCMASK_3;
44const unsigned CCMASK_CMP_O = CCMASK_ANY ^ CCMASK_CMP_UO;
45
46// All condition-code values produced by comparisons.
47const unsigned CCMASK_ICMP = CCMASK_0 | CCMASK_1 | CCMASK_2;
48const unsigned CCMASK_FCMP = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
49
50// Condition-code mask assignments for arithmetical operations.
51const unsigned CCMASK_ARITH_EQ = CCMASK_0;
52const unsigned CCMASK_ARITH_LT = CCMASK_1;
53const unsigned CCMASK_ARITH_GT = CCMASK_2;
54const unsigned CCMASK_ARITH_OVERFLOW = CCMASK_3;
55const unsigned CCMASK_ARITH = CCMASK_ANY;
56
57// Condition-code mask assignments for logical operations.
58const unsigned CCMASK_LOGICAL_ZERO = CCMASK_0 | CCMASK_2;
59const unsigned CCMASK_LOGICAL_NONZERO = CCMASK_1 | CCMASK_3;
60const unsigned CCMASK_LOGICAL_CARRY = CCMASK_2 | CCMASK_3;
61const unsigned CCMASK_LOGICAL_NOCARRY = CCMASK_0 | CCMASK_1;
62const unsigned CCMASK_LOGICAL_BORROW = CCMASK_LOGICAL_NOCARRY;
63const unsigned CCMASK_LOGICAL_NOBORROW = CCMASK_LOGICAL_CARRY;
64const unsigned CCMASK_LOGICAL = CCMASK_ANY;
65
66// Condition-code mask assignments for CS.
67const unsigned CCMASK_CS_EQ = CCMASK_0;
68const unsigned CCMASK_CS_NE = CCMASK_1;
69const unsigned CCMASK_CS = CCMASK_0 | CCMASK_1;
70
71// Condition-code mask assignments for a completed SRST loop.
72const unsigned CCMASK_SRST_FOUND = CCMASK_1;
73const unsigned CCMASK_SRST_NOTFOUND = CCMASK_2;
74const unsigned CCMASK_SRST = CCMASK_1 | CCMASK_2;
75
76// Condition-code mask assignments for TEST UNDER MASK.
77const unsigned CCMASK_TM_ALL_0 = CCMASK_0;
78const unsigned CCMASK_TM_MIXED_MSB_0 = CCMASK_1;
79const unsigned CCMASK_TM_MIXED_MSB_1 = CCMASK_2;
80const unsigned CCMASK_TM_ALL_1 = CCMASK_3;
81const unsigned CCMASK_TM_SOME_0 = CCMASK_TM_ALL_1 ^ CCMASK_ANY;
82const unsigned CCMASK_TM_SOME_1 = CCMASK_TM_ALL_0 ^ CCMASK_ANY;
83const unsigned CCMASK_TM_MSB_0 = CCMASK_0 | CCMASK_1;
84const unsigned CCMASK_TM_MSB_1 = CCMASK_2 | CCMASK_3;
85const unsigned CCMASK_TM = CCMASK_ANY;
86
87// Condition-code mask assignments for TRANSACTION_BEGIN.
88const unsigned CCMASK_TBEGIN_STARTED = CCMASK_0;
89const unsigned CCMASK_TBEGIN_INDETERMINATE = CCMASK_1;
90const unsigned CCMASK_TBEGIN_TRANSIENT = CCMASK_2;
91const unsigned CCMASK_TBEGIN_PERSISTENT = CCMASK_3;
92const unsigned CCMASK_TBEGIN = CCMASK_ANY;
93
94// Condition-code mask assignments for TRANSACTION_END.
95const unsigned CCMASK_TEND_TX = CCMASK_0;
96const unsigned CCMASK_TEND_NOTX = CCMASK_2;
97const unsigned CCMASK_TEND = CCMASK_TEND_TX | CCMASK_TEND_NOTX;
98
99// Condition-code mask assignments for vector comparisons (and similar
100// operations).
101const unsigned CCMASK_VCMP_ALL = CCMASK_0;
102const unsigned CCMASK_VCMP_MIXED = CCMASK_1;
103const unsigned CCMASK_VCMP_NONE = CCMASK_3;
104const unsigned CCMASK_VCMP = CCMASK_0 | CCMASK_1 | CCMASK_3;
105
106// Condition-code mask assignments for Test Data Class.
107const unsigned CCMASK_TDC_NOMATCH = CCMASK_0;
108const unsigned CCMASK_TDC_MATCH = CCMASK_1;
109const unsigned CCMASK_TDC = CCMASK_TDC_NOMATCH | CCMASK_TDC_MATCH;
110
111// The position of the low CC bit in an IPM result.
112const unsigned IPM_CC = 28;
113
114// Mask assignments for PFD.
115const unsigned PFD_READ = 1;
116const unsigned PFD_WRITE = 2;
117
118// Mask assignments for TDC
119const unsigned TDCMASK_ZERO_PLUS = 0x800;
120const unsigned TDCMASK_ZERO_MINUS = 0x400;
121const unsigned TDCMASK_NORMAL_PLUS = 0x200;
122const unsigned TDCMASK_NORMAL_MINUS = 0x100;
123const unsigned TDCMASK_SUBNORMAL_PLUS = 0x080;
124const unsigned TDCMASK_SUBNORMAL_MINUS = 0x040;
125const unsigned TDCMASK_INFINITY_PLUS = 0x020;
126const unsigned TDCMASK_INFINITY_MINUS = 0x010;
127const unsigned TDCMASK_QNAN_PLUS = 0x008;
128const unsigned TDCMASK_QNAN_MINUS = 0x004;
129const unsigned TDCMASK_SNAN_PLUS = 0x002;
130const unsigned TDCMASK_SNAN_MINUS = 0x001;
131
132const unsigned TDCMASK_ZERO = TDCMASK_ZERO_PLUS | TDCMASK_ZERO_MINUS;
133const unsigned TDCMASK_POSITIVE = TDCMASK_NORMAL_PLUS |
134 TDCMASK_SUBNORMAL_PLUS |
135 TDCMASK_INFINITY_PLUS;
136const unsigned TDCMASK_NEGATIVE = TDCMASK_NORMAL_MINUS |
137 TDCMASK_SUBNORMAL_MINUS |
138 TDCMASK_INFINITY_MINUS;
139const unsigned TDCMASK_NAN = TDCMASK_QNAN_PLUS |
140 TDCMASK_QNAN_MINUS |
141 TDCMASK_SNAN_PLUS |
142 TDCMASK_SNAN_MINUS;
143const unsigned TDCMASK_PLUS = TDCMASK_POSITIVE |
144 TDCMASK_ZERO_PLUS |
145 TDCMASK_QNAN_PLUS |
146 TDCMASK_SNAN_PLUS;
147const unsigned TDCMASK_MINUS = TDCMASK_NEGATIVE |
148 TDCMASK_ZERO_MINUS |
149 TDCMASK_QNAN_MINUS |
150 TDCMASK_SNAN_MINUS;
151const unsigned TDCMASK_ALL = TDCMASK_PLUS | TDCMASK_MINUS;
152
153// Number of bits in a vector register.
154const unsigned VectorBits = 128;
155
156// Number of bytes in a vector register (and consequently the number of
157// bytes in a general permute vector).
158const unsigned VectorBytes = VectorBits / 8;
159
160// Return true if Val fits an LLILL operand.
161static inline bool isImmLL(uint64_t Val) {
162 return (Val & ~0x000000000000ffffULL) == 0;
163}
164
165// Return true if Val fits an LLILH operand.
166static inline bool isImmLH(uint64_t Val) {
167 return (Val & ~0x00000000ffff0000ULL) == 0;
168}
169
170// Return true if Val fits an LLIHL operand.
171static inline bool isImmHL(uint64_t Val) {
172 return (Val & ~0x00000ffff00000000ULL) == 0;
173}
174
175// Return true if Val fits an LLIHH operand.
176static inline bool isImmHH(uint64_t Val) {
177 return (Val & ~0xffff000000000000ULL) == 0;
178}
179
180// Return true if Val fits an LLILF operand.
181static inline bool isImmLF(uint64_t Val) {
182 return (Val & ~0x00000000ffffffffULL) == 0;
183}
184
185// Return true if Val fits an LLIHF operand.
186static inline bool isImmHF(uint64_t Val) {
187 return (Val & ~0xffffffff00000000ULL) == 0;
188}
189} // end namespace SystemZ
190
191FunctionPass *createSystemZISelDag(SystemZTargetMachine &TM,
192 CodeGenOptLevel OptLevel);
193FunctionPass *createSystemZElimComparePass(SystemZTargetMachine &TM);
194FunctionPass *createSystemZShortenInstPass(SystemZTargetMachine &TM);
195FunctionPass *createSystemZLongBranchPass(SystemZTargetMachine &TM);
196FunctionPass *createSystemZLDCleanupPass(SystemZTargetMachine &TM);
197FunctionPass *createSystemZCopyPhysRegsPass(SystemZTargetMachine &TM);
198FunctionPass *createSystemZPostRewritePass(SystemZTargetMachine &TM);
199FunctionPass *createSystemZTDCPass();
200
201void initializeSystemZCopyPhysRegsPass(PassRegistry &);
202void initializeSystemZDAGToDAGISelLegacyPass(PassRegistry &);
203void initializeSystemZElimComparePass(PassRegistry &);
204void initializeSystemZLDCleanupPass(PassRegistry &);
205void initializeSystemZLongBranchPass(PassRegistry &);
206void initializeSystemZPostRewritePass(PassRegistry &);
207void initializeSystemZShortenInstPass(PassRegistry &);
208void initializeSystemZTDCPassPass(PassRegistry &);
209
210} // end namespace llvm
211
212#endif
213