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/CodeGen/MachineFunctionAnalysisManager.h"
19#include "llvm/CodeGen/SelectionDAGISel.h"
20#include "llvm/IR/Analysis.h"
21#include "llvm/IR/PassManager.h"
22#include "llvm/Support/CodeGen.h"
23
24namespace llvm {
25class FunctionPass;
26class ModulePass;
27class PassRegistry;
28class SystemZTargetMachine;
29
30namespace SystemZ {
31// Condition-code mask values.
32const unsigned CCMASK_NONE = 0;
33const unsigned CCMASK_0 = 1 << 3;
34const unsigned CCMASK_1 = 1 << 2;
35const unsigned CCMASK_2 = 1 << 1;
36const unsigned CCMASK_3 = 1 << 0;
37const unsigned CCMASK_ANY = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
38
39// Condition-code mask assignments for integer and floating-point
40// comparisons.
41const unsigned CCMASK_CMP_EQ = CCMASK_0;
42const unsigned CCMASK_CMP_LT = CCMASK_1;
43const unsigned CCMASK_CMP_GT = CCMASK_2;
44const unsigned CCMASK_CMP_NE = CCMASK_CMP_LT | CCMASK_CMP_GT;
45const unsigned CCMASK_CMP_LE = CCMASK_CMP_EQ | CCMASK_CMP_LT;
46const unsigned CCMASK_CMP_GE = CCMASK_CMP_EQ | CCMASK_CMP_GT;
47
48// Condition-code mask assignments for floating-point comparisons only.
49const unsigned CCMASK_CMP_UO = CCMASK_3;
50const unsigned CCMASK_CMP_O = CCMASK_ANY ^ CCMASK_CMP_UO;
51
52// All condition-code values produced by comparisons.
53const unsigned CCMASK_ICMP = CCMASK_0 | CCMASK_1 | CCMASK_2;
54const unsigned CCMASK_FCMP = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
55
56// Condition-code mask assignments for arithmetical operations.
57const unsigned CCMASK_ARITH_EQ = CCMASK_0;
58const unsigned CCMASK_ARITH_LT = CCMASK_1;
59const unsigned CCMASK_ARITH_GT = CCMASK_2;
60const unsigned CCMASK_ARITH_OVERFLOW = CCMASK_3;
61const unsigned CCMASK_ARITH = CCMASK_ANY;
62
63// Condition-code mask assignments for logical operations.
64const unsigned CCMASK_LOGICAL_ZERO = CCMASK_0 | CCMASK_2;
65const unsigned CCMASK_LOGICAL_NONZERO = CCMASK_1 | CCMASK_3;
66const unsigned CCMASK_LOGICAL_CARRY = CCMASK_2 | CCMASK_3;
67const unsigned CCMASK_LOGICAL_NOCARRY = CCMASK_0 | CCMASK_1;
68const unsigned CCMASK_LOGICAL_BORROW = CCMASK_LOGICAL_NOCARRY;
69const unsigned CCMASK_LOGICAL_NOBORROW = CCMASK_LOGICAL_CARRY;
70const unsigned CCMASK_LOGICAL = CCMASK_ANY;
71
72// Condition-code mask assignments for CS.
73const unsigned CCMASK_CS_EQ = CCMASK_0;
74const unsigned CCMASK_CS_NE = CCMASK_1;
75const unsigned CCMASK_CS = CCMASK_0 | CCMASK_1;
76
77// Condition-code mask assignments for a completed SRST loop.
78const unsigned CCMASK_SRST_FOUND = CCMASK_1;
79const unsigned CCMASK_SRST_NOTFOUND = CCMASK_2;
80const unsigned CCMASK_SRST = CCMASK_1 | CCMASK_2;
81
82// Condition-code mask assignments for TEST UNDER MASK.
83const unsigned CCMASK_TM_ALL_0 = CCMASK_0;
84const unsigned CCMASK_TM_MIXED_MSB_0 = CCMASK_1;
85const unsigned CCMASK_TM_MIXED_MSB_1 = CCMASK_2;
86const unsigned CCMASK_TM_ALL_1 = CCMASK_3;
87const unsigned CCMASK_TM_SOME_0 = CCMASK_TM_ALL_1 ^ CCMASK_ANY;
88const unsigned CCMASK_TM_SOME_1 = CCMASK_TM_ALL_0 ^ CCMASK_ANY;
89const unsigned CCMASK_TM_MSB_0 = CCMASK_0 | CCMASK_1;
90const unsigned CCMASK_TM_MSB_1 = CCMASK_2 | CCMASK_3;
91const unsigned CCMASK_TM = CCMASK_ANY;
92
93// Condition-code mask assignments for TRANSACTION_BEGIN.
94const unsigned CCMASK_TBEGIN_STARTED = CCMASK_0;
95const unsigned CCMASK_TBEGIN_INDETERMINATE = CCMASK_1;
96const unsigned CCMASK_TBEGIN_TRANSIENT = CCMASK_2;
97const unsigned CCMASK_TBEGIN_PERSISTENT = CCMASK_3;
98const unsigned CCMASK_TBEGIN = CCMASK_ANY;
99
100// Condition-code mask assignments for TRANSACTION_END.
101const unsigned CCMASK_TEND_TX = CCMASK_0;
102const unsigned CCMASK_TEND_NOTX = CCMASK_2;
103const unsigned CCMASK_TEND = CCMASK_TEND_TX | CCMASK_TEND_NOTX;
104
105// Condition-code mask assignments for vector comparisons (and similar
106// operations).
107const unsigned CCMASK_VCMP_ALL = CCMASK_0;
108const unsigned CCMASK_VCMP_MIXED = CCMASK_1;
109const unsigned CCMASK_VCMP_NONE = CCMASK_3;
110const unsigned CCMASK_VCMP = CCMASK_0 | CCMASK_1 | CCMASK_3;
111
112// Condition-code mask assignments for Test Data Class.
113const unsigned CCMASK_TDC_NOMATCH = CCMASK_0;
114const unsigned CCMASK_TDC_MATCH = CCMASK_1;
115const unsigned CCMASK_TDC = CCMASK_TDC_NOMATCH | CCMASK_TDC_MATCH;
116
117// The position of the low CC bit in an IPM result.
118const unsigned IPM_CC = 28;
119
120// Mask assignments for PFD.
121const unsigned PFD_READ = 1;
122const unsigned PFD_WRITE = 2;
123
124// Mask assignments for TDC
125const unsigned TDCMASK_ZERO_PLUS = 0x800;
126const unsigned TDCMASK_ZERO_MINUS = 0x400;
127const unsigned TDCMASK_NORMAL_PLUS = 0x200;
128const unsigned TDCMASK_NORMAL_MINUS = 0x100;
129const unsigned TDCMASK_SUBNORMAL_PLUS = 0x080;
130const unsigned TDCMASK_SUBNORMAL_MINUS = 0x040;
131const unsigned TDCMASK_INFINITY_PLUS = 0x020;
132const unsigned TDCMASK_INFINITY_MINUS = 0x010;
133const unsigned TDCMASK_QNAN_PLUS = 0x008;
134const unsigned TDCMASK_QNAN_MINUS = 0x004;
135const unsigned TDCMASK_SNAN_PLUS = 0x002;
136const unsigned TDCMASK_SNAN_MINUS = 0x001;
137
138const unsigned TDCMASK_ZERO = TDCMASK_ZERO_PLUS | TDCMASK_ZERO_MINUS;
139const unsigned TDCMASK_POSITIVE = TDCMASK_NORMAL_PLUS |
140 TDCMASK_SUBNORMAL_PLUS |
141 TDCMASK_INFINITY_PLUS;
142const unsigned TDCMASK_NEGATIVE = TDCMASK_NORMAL_MINUS |
143 TDCMASK_SUBNORMAL_MINUS |
144 TDCMASK_INFINITY_MINUS;
145const unsigned TDCMASK_NAN = TDCMASK_QNAN_PLUS |
146 TDCMASK_QNAN_MINUS |
147 TDCMASK_SNAN_PLUS |
148 TDCMASK_SNAN_MINUS;
149const unsigned TDCMASK_PLUS = TDCMASK_POSITIVE |
150 TDCMASK_ZERO_PLUS |
151 TDCMASK_QNAN_PLUS |
152 TDCMASK_SNAN_PLUS;
153const unsigned TDCMASK_MINUS = TDCMASK_NEGATIVE |
154 TDCMASK_ZERO_MINUS |
155 TDCMASK_QNAN_MINUS |
156 TDCMASK_SNAN_MINUS;
157const unsigned TDCMASK_ALL = TDCMASK_PLUS | TDCMASK_MINUS;
158
159// Number of bits in a vector register.
160const unsigned VectorBits = 128;
161
162// Number of bytes in a vector register (and consequently the number of
163// bytes in a general permute vector).
164const unsigned VectorBytes = VectorBits / 8;
165
166// Return true if Val fits an LLILL operand.
167static inline bool isImmLL(uint64_t Val) {
168 return (Val & ~0x000000000000ffffULL) == 0;
169}
170
171// Return true if Val fits an LLILH operand.
172static inline bool isImmLH(uint64_t Val) {
173 return (Val & ~0x00000000ffff0000ULL) == 0;
174}
175
176// Return true if Val fits an LLIHL operand.
177static inline bool isImmHL(uint64_t Val) {
178 return (Val & ~0x00000ffff00000000ULL) == 0;
179}
180
181// Return true if Val fits an LLIHH operand.
182static inline bool isImmHH(uint64_t Val) {
183 return (Val & ~0xffff000000000000ULL) == 0;
184}
185
186// Return true if Val fits an LLILF operand.
187static inline bool isImmLF(uint64_t Val) {
188 return (Val & ~0x00000000ffffffffULL) == 0;
189}
190
191// Return true if Val fits an LLIHF operand.
192static inline bool isImmHF(uint64_t Val) {
193 return (Val & ~0xffffffff00000000ULL) == 0;
194}
195} // end namespace SystemZ
196
197class SystemZISelDAGToDAGPass : public SelectionDAGISelPass {
198public:
199 SystemZISelDAGToDAGPass(SystemZTargetMachine &TM, CodeGenOptLevel OptLevel);
200};
201
202FunctionPass *createSystemZISelDagLegacyPass(SystemZTargetMachine &TM,
203 CodeGenOptLevel OptLevel);
204
205class SystemZElimComparePass
206 : public OptionalPassInfoMixin<SystemZElimComparePass> {
207public:
208 PreservedAnalyses run(MachineFunction &MF,
209 MachineFunctionAnalysisManager &MFAM);
210};
211
212FunctionPass *createSystemZElimCompareLegacyPass(SystemZTargetMachine &TM);
213
214class SystemZShortenInstPass
215 : public OptionalPassInfoMixin<SystemZShortenInstPass> {
216public:
217 PreservedAnalyses run(MachineFunction &MF,
218 MachineFunctionAnalysisManager &MFAM);
219};
220
221FunctionPass *createSystemZShortenInstLegacyPass(SystemZTargetMachine &TM);
222
223class SystemZLongBranchPass
224 : public RequiredPassInfoMixin<SystemZLongBranchPass> {
225public:
226 PreservedAnalyses run(MachineFunction &MF,
227 MachineFunctionAnalysisManager &MFAM);
228};
229
230FunctionPass *createSystemZLongBranchLegacyPass(SystemZTargetMachine &TM);
231
232class SystemZLDCleanupPass
233 : public OptionalPassInfoMixin<SystemZLDCleanupPass> {
234public:
235 PreservedAnalyses run(MachineFunction &MF,
236 MachineFunctionAnalysisManager &MFAM);
237};
238
239FunctionPass *createSystemZLDCleanupLegacyPass(SystemZTargetMachine &TM);
240
241class SystemZCopyPhysRegsPass
242 : public RequiredPassInfoMixin<SystemZCopyPhysRegsPass> {
243public:
244 PreservedAnalyses run(MachineFunction &MF,
245 MachineFunctionAnalysisManager &MFAM);
246};
247
248FunctionPass *createSystemZCopyPhysRegsLegacyPass(SystemZTargetMachine &TM);
249
250class SystemZPostRewritePass
251 : public RequiredPassInfoMixin<SystemZPostRewritePass> {
252public:
253 PreservedAnalyses run(MachineFunction &MF,
254 MachineFunctionAnalysisManager &MFAM);
255};
256
257FunctionPass *createSystemZPostRewriteLegacyPass(SystemZTargetMachine &TM);
258
259class SystemZTDCPass : public RequiredPassInfoMixin<SystemZTDCPass> {
260 SystemZTargetMachine &TM;
261
262public:
263 SystemZTDCPass(SystemZTargetMachine &TM) : TM(TM) {}
264 PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
265};
266
267FunctionPass *createSystemZTDCLegacyPass();
268
269class SystemZAlignGlobalsPass
270 : public RequiredPassInfoMixin<SystemZAlignGlobalsPass> {
271public:
272 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
273};
274
275ModulePass *createSystemZAlignGlobalsLegacyPass();
276
277void initializeSystemZAsmPrinterPass(PassRegistry &);
278
279void initializeSystemZCopyPhysRegsLegacyPass(PassRegistry &);
280void initializeSystemZDAGToDAGISelLegacyPass(PassRegistry &);
281void initializeSystemZElimCompareLegacyPass(PassRegistry &);
282void initializeSystemZLDCleanupLegacyPass(PassRegistry &);
283void initializeSystemZLongBranchLegacyPass(PassRegistry &);
284void initializeSystemZPostRewriteLegacyPass(PassRegistry &);
285void initializeSystemZShortenInstLegacyPass(PassRegistry &);
286void initializeSystemZTDCLegacyPass(PassRegistry &);
287void initializeSystemZAlignGlobalsLegacyPass(PassRegistry &);
288
289namespace SYSTEMZAS {
290enum : unsigned { PTR32 = 1 };
291} // namespace SYSTEMZAS
292
293} // end namespace llvm
294
295#endif
296