[InstCombine] Signed saturation patterns
[llvm-core.git] / lib / Target / SystemZ / SystemZ.h
blob88cf589a3f1024ed3a15aacb7bbf419ec43eca2b
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
15 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
17 #include "MCTargetDesc/SystemZMCTargetDesc.h"
18 #include "llvm/Support/CodeGen.h"
20 namespace llvm {
21 class SystemZTargetMachine;
22 class FunctionPass;
24 namespace SystemZ {
25 // Condition-code mask values.
26 const unsigned CCMASK_0 = 1 << 3;
27 const unsigned CCMASK_1 = 1 << 2;
28 const unsigned CCMASK_2 = 1 << 1;
29 const unsigned CCMASK_3 = 1 << 0;
30 const unsigned CCMASK_ANY = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
32 // Condition-code mask assignments for integer and floating-point
33 // comparisons.
34 const unsigned CCMASK_CMP_EQ = CCMASK_0;
35 const unsigned CCMASK_CMP_LT = CCMASK_1;
36 const unsigned CCMASK_CMP_GT = CCMASK_2;
37 const unsigned CCMASK_CMP_NE = CCMASK_CMP_LT | CCMASK_CMP_GT;
38 const unsigned CCMASK_CMP_LE = CCMASK_CMP_EQ | CCMASK_CMP_LT;
39 const unsigned CCMASK_CMP_GE = CCMASK_CMP_EQ | CCMASK_CMP_GT;
41 // Condition-code mask assignments for floating-point comparisons only.
42 const unsigned CCMASK_CMP_UO = CCMASK_3;
43 const unsigned CCMASK_CMP_O = CCMASK_ANY ^ CCMASK_CMP_UO;
45 // All condition-code values produced by comparisons.
46 const unsigned CCMASK_ICMP = CCMASK_0 | CCMASK_1 | CCMASK_2;
47 const unsigned CCMASK_FCMP = CCMASK_0 | CCMASK_1 | CCMASK_2 | CCMASK_3;
49 // Condition-code mask assignments for arithmetical operations.
50 const unsigned CCMASK_ARITH_EQ = CCMASK_0;
51 const unsigned CCMASK_ARITH_LT = CCMASK_1;
52 const unsigned CCMASK_ARITH_GT = CCMASK_2;
53 const unsigned CCMASK_ARITH_OVERFLOW = CCMASK_3;
54 const unsigned CCMASK_ARITH = CCMASK_ANY;
56 // Condition-code mask assignments for logical operations.
57 const unsigned CCMASK_LOGICAL_ZERO = CCMASK_0 | CCMASK_2;
58 const unsigned CCMASK_LOGICAL_NONZERO = CCMASK_1 | CCMASK_2;
59 const unsigned CCMASK_LOGICAL_CARRY = CCMASK_2 | CCMASK_3;
60 const unsigned CCMASK_LOGICAL_NOCARRY = CCMASK_0 | CCMASK_1;
61 const unsigned CCMASK_LOGICAL_BORROW = CCMASK_LOGICAL_NOCARRY;
62 const unsigned CCMASK_LOGICAL_NOBORROW = CCMASK_LOGICAL_CARRY;
63 const unsigned CCMASK_LOGICAL = CCMASK_ANY;
65 // Condition-code mask assignments for CS.
66 const unsigned CCMASK_CS_EQ = CCMASK_0;
67 const unsigned CCMASK_CS_NE = CCMASK_1;
68 const unsigned CCMASK_CS = CCMASK_0 | CCMASK_1;
70 // Condition-code mask assignments for a completed SRST loop.
71 const unsigned CCMASK_SRST_FOUND = CCMASK_1;
72 const unsigned CCMASK_SRST_NOTFOUND = CCMASK_2;
73 const unsigned CCMASK_SRST = CCMASK_1 | CCMASK_2;
75 // Condition-code mask assignments for TEST UNDER MASK.
76 const unsigned CCMASK_TM_ALL_0 = CCMASK_0;
77 const unsigned CCMASK_TM_MIXED_MSB_0 = CCMASK_1;
78 const unsigned CCMASK_TM_MIXED_MSB_1 = CCMASK_2;
79 const unsigned CCMASK_TM_ALL_1 = CCMASK_3;
80 const unsigned CCMASK_TM_SOME_0 = CCMASK_TM_ALL_1 ^ CCMASK_ANY;
81 const unsigned CCMASK_TM_SOME_1 = CCMASK_TM_ALL_0 ^ CCMASK_ANY;
82 const unsigned CCMASK_TM_MSB_0 = CCMASK_0 | CCMASK_1;
83 const unsigned CCMASK_TM_MSB_1 = CCMASK_2 | CCMASK_3;
84 const unsigned CCMASK_TM = CCMASK_ANY;
86 // Condition-code mask assignments for TRANSACTION_BEGIN.
87 const unsigned CCMASK_TBEGIN_STARTED = CCMASK_0;
88 const unsigned CCMASK_TBEGIN_INDETERMINATE = CCMASK_1;
89 const unsigned CCMASK_TBEGIN_TRANSIENT = CCMASK_2;
90 const unsigned CCMASK_TBEGIN_PERSISTENT = CCMASK_3;
91 const unsigned CCMASK_TBEGIN = CCMASK_ANY;
93 // Condition-code mask assignments for TRANSACTION_END.
94 const unsigned CCMASK_TEND_TX = CCMASK_0;
95 const unsigned CCMASK_TEND_NOTX = CCMASK_2;
96 const unsigned CCMASK_TEND = CCMASK_TEND_TX | CCMASK_TEND_NOTX;
98 // Condition-code mask assignments for vector comparisons (and similar
99 // operations).
100 const unsigned CCMASK_VCMP_ALL = CCMASK_0;
101 const unsigned CCMASK_VCMP_MIXED = CCMASK_1;
102 const unsigned CCMASK_VCMP_NONE = CCMASK_3;
103 const unsigned CCMASK_VCMP = CCMASK_0 | CCMASK_1 | CCMASK_3;
105 // Condition-code mask assignments for Test Data Class.
106 const unsigned CCMASK_TDC_NOMATCH = CCMASK_0;
107 const unsigned CCMASK_TDC_MATCH = CCMASK_1;
108 const unsigned CCMASK_TDC = CCMASK_TDC_NOMATCH | CCMASK_TDC_MATCH;
110 // The position of the low CC bit in an IPM result.
111 const unsigned IPM_CC = 28;
113 // Mask assignments for PFD.
114 const unsigned PFD_READ = 1;
115 const unsigned PFD_WRITE = 2;
117 // Mask assignments for TDC
118 const unsigned TDCMASK_ZERO_PLUS = 0x800;
119 const unsigned TDCMASK_ZERO_MINUS = 0x400;
120 const unsigned TDCMASK_NORMAL_PLUS = 0x200;
121 const unsigned TDCMASK_NORMAL_MINUS = 0x100;
122 const unsigned TDCMASK_SUBNORMAL_PLUS = 0x080;
123 const unsigned TDCMASK_SUBNORMAL_MINUS = 0x040;
124 const unsigned TDCMASK_INFINITY_PLUS = 0x020;
125 const unsigned TDCMASK_INFINITY_MINUS = 0x010;
126 const unsigned TDCMASK_QNAN_PLUS = 0x008;
127 const unsigned TDCMASK_QNAN_MINUS = 0x004;
128 const unsigned TDCMASK_SNAN_PLUS = 0x002;
129 const unsigned TDCMASK_SNAN_MINUS = 0x001;
131 const unsigned TDCMASK_ZERO = TDCMASK_ZERO_PLUS | TDCMASK_ZERO_MINUS;
132 const unsigned TDCMASK_POSITIVE = TDCMASK_NORMAL_PLUS |
133 TDCMASK_SUBNORMAL_PLUS |
134 TDCMASK_INFINITY_PLUS;
135 const unsigned TDCMASK_NEGATIVE = TDCMASK_NORMAL_MINUS |
136 TDCMASK_SUBNORMAL_MINUS |
137 TDCMASK_INFINITY_MINUS;
138 const unsigned TDCMASK_NAN = TDCMASK_QNAN_PLUS |
139 TDCMASK_QNAN_MINUS |
140 TDCMASK_SNAN_PLUS |
141 TDCMASK_SNAN_MINUS;
142 const unsigned TDCMASK_PLUS = TDCMASK_POSITIVE |
143 TDCMASK_ZERO_PLUS |
144 TDCMASK_QNAN_PLUS |
145 TDCMASK_SNAN_PLUS;
146 const unsigned TDCMASK_MINUS = TDCMASK_NEGATIVE |
147 TDCMASK_ZERO_MINUS |
148 TDCMASK_QNAN_MINUS |
149 TDCMASK_SNAN_MINUS;
150 const unsigned TDCMASK_ALL = TDCMASK_PLUS | TDCMASK_MINUS;
152 // Number of bits in a vector register.
153 const unsigned VectorBits = 128;
155 // Number of bytes in a vector register (and consequently the number of
156 // bytes in a general permute vector).
157 const unsigned VectorBytes = VectorBits / 8;
159 // Return true if Val fits an LLILL operand.
160 static inline bool isImmLL(uint64_t Val) {
161 return (Val & ~0x000000000000ffffULL) == 0;
164 // Return true if Val fits an LLILH operand.
165 static inline bool isImmLH(uint64_t Val) {
166 return (Val & ~0x00000000ffff0000ULL) == 0;
169 // Return true if Val fits an LLIHL operand.
170 static inline bool isImmHL(uint64_t Val) {
171 return (Val & ~0x00000ffff00000000ULL) == 0;
174 // Return true if Val fits an LLIHH operand.
175 static inline bool isImmHH(uint64_t Val) {
176 return (Val & ~0xffff000000000000ULL) == 0;
179 // Return true if Val fits an LLILF operand.
180 static inline bool isImmLF(uint64_t Val) {
181 return (Val & ~0x00000000ffffffffULL) == 0;
184 // Return true if Val fits an LLIHF operand.
185 static inline bool isImmHF(uint64_t Val) {
186 return (Val & ~0xffffffff00000000ULL) == 0;
188 } // end namespace SystemZ
190 FunctionPass *createSystemZISelDag(SystemZTargetMachine &TM,
191 CodeGenOpt::Level OptLevel);
192 FunctionPass *createSystemZElimComparePass(SystemZTargetMachine &TM);
193 FunctionPass *createSystemZShortenInstPass(SystemZTargetMachine &TM);
194 FunctionPass *createSystemZLongBranchPass(SystemZTargetMachine &TM);
195 FunctionPass *createSystemZLDCleanupPass(SystemZTargetMachine &TM);
196 FunctionPass *createSystemZPostRewritePass(SystemZTargetMachine &TM);
197 FunctionPass *createSystemZTDCPass();
198 } // end namespace llvm
200 #endif