1//==- SystemZ.h - Top-Level Interface for SystemZ representation -*- 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//
10// This file contains the entry points for global functions defined in
11// the LLVM SystemZ backend.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
16#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZ_H
17
18#include "MCTargetDesc/SystemZMCTargetDesc.h"
19#include "llvm/Support/CodeGen.h"
20
21namespace llvm {
22class SystemZTargetMachine;
23class FunctionPass;
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 CS.
51const unsigned CCMASK_CS_EQ = CCMASK_0;
52const unsigned CCMASK_CS_NE = CCMASK_1;
53const unsigned CCMASK_CS    = CCMASK_0 | CCMASK_1;
54
55// Condition-code mask assignments for a completed SRST loop.
56const unsigned CCMASK_SRST_FOUND    = CCMASK_1;
57const unsigned CCMASK_SRST_NOTFOUND = CCMASK_2;
58const unsigned CCMASK_SRST          = CCMASK_1 | CCMASK_2;
59
60// Condition-code mask assignments for TEST UNDER MASK.
61const unsigned CCMASK_TM_ALL_0       = CCMASK_0;
62const unsigned CCMASK_TM_MIXED_MSB_0 = CCMASK_1;
63const unsigned CCMASK_TM_MIXED_MSB_1 = CCMASK_2;
64const unsigned CCMASK_TM_ALL_1       = CCMASK_3;
65const unsigned CCMASK_TM_SOME_0      = CCMASK_TM_ALL_1 ^ CCMASK_ANY;
66const unsigned CCMASK_TM_SOME_1      = CCMASK_TM_ALL_0 ^ CCMASK_ANY;
67const unsigned CCMASK_TM_MSB_0       = CCMASK_0 | CCMASK_1;
68const unsigned CCMASK_TM_MSB_1       = CCMASK_2 | CCMASK_3;
69const unsigned CCMASK_TM             = CCMASK_ANY;
70
71// Condition-code mask assignments for TRANSACTION_BEGIN.
72const unsigned CCMASK_TBEGIN_STARTED       = CCMASK_0;
73const unsigned CCMASK_TBEGIN_INDETERMINATE = CCMASK_1;
74const unsigned CCMASK_TBEGIN_TRANSIENT     = CCMASK_2;
75const unsigned CCMASK_TBEGIN_PERSISTENT    = CCMASK_3;
76const unsigned CCMASK_TBEGIN               = CCMASK_ANY;
77
78// Condition-code mask assignments for TRANSACTION_END.
79const unsigned CCMASK_TEND_TX   = CCMASK_0;
80const unsigned CCMASK_TEND_NOTX = CCMASK_2;
81const unsigned CCMASK_TEND      = CCMASK_TEND_TX | CCMASK_TEND_NOTX;
82
83// Condition-code mask assignments for vector comparisons (and similar
84// operations).
85const unsigned CCMASK_VCMP_ALL       = CCMASK_0;
86const unsigned CCMASK_VCMP_MIXED     = CCMASK_1;
87const unsigned CCMASK_VCMP_NONE      = CCMASK_3;
88const unsigned CCMASK_VCMP           = CCMASK_0 | CCMASK_1 | CCMASK_3;
89
90// The position of the low CC bit in an IPM result.
91const unsigned IPM_CC = 28;
92
93// Mask assignments for PFD.
94const unsigned PFD_READ  = 1;
95const unsigned PFD_WRITE = 2;
96
97// Number of bits in a vector register.
98const unsigned VectorBits = 128;
99
100// Number of bytes in a vector register (and consequently the number of
101// bytes in a general permute vector).
102const unsigned VectorBytes = VectorBits / 8;
103
104// Return true if Val fits an LLILL operand.
105static inline bool isImmLL(uint64_t Val) {
106  return (Val & ~0x000000000000ffffULL) == 0;
107}
108
109// Return true if Val fits an LLILH operand.
110static inline bool isImmLH(uint64_t Val) {
111  return (Val & ~0x00000000ffff0000ULL) == 0;
112}
113
114// Return true if Val fits an LLIHL operand.
115static inline bool isImmHL(uint64_t Val) {
116  return (Val & ~0x00000ffff00000000ULL) == 0;
117}
118
119// Return true if Val fits an LLIHH operand.
120static inline bool isImmHH(uint64_t Val) {
121  return (Val & ~0xffff000000000000ULL) == 0;
122}
123
124// Return true if Val fits an LLILF operand.
125static inline bool isImmLF(uint64_t Val) {
126  return (Val & ~0x00000000ffffffffULL) == 0;
127}
128
129// Return true if Val fits an LLIHF operand.
130static inline bool isImmHF(uint64_t Val) {
131  return (Val & ~0xffffffff00000000ULL) == 0;
132}
133} // end namespace SystemZ
134
135FunctionPass *createSystemZISelDag(SystemZTargetMachine &TM,
136                                   CodeGenOpt::Level OptLevel);
137FunctionPass *createSystemZElimComparePass(SystemZTargetMachine &TM);
138FunctionPass *createSystemZShortenInstPass(SystemZTargetMachine &TM);
139FunctionPass *createSystemZLongBranchPass(SystemZTargetMachine &TM);
140FunctionPass *createSystemZLDCleanupPass(SystemZTargetMachine &TM);
141} // end namespace llvm
142
143#endif
144