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