1//===-- Sparc.h - Top-level interface for Sparc 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 the LLVM
10// Sparc back-end.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_SPARC_SPARC_H
15#define LLVM_LIB_TARGET_SPARC_SPARC_H
16
17#include "MCTargetDesc/SparcMCTargetDesc.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/ErrorHandling.h"
23#include "llvm/Target/TargetMachine.h"
24
25namespace llvm {
26class AsmPrinter;
27class FunctionPass;
28class MCInst;
29class MachineInstr;
30class PassRegistry;
31class SparcTargetMachine;
32
33class SparcDAGToDAGISelPass : public SelectionDAGISelPass {
34public:
35 SparcDAGToDAGISelPass(SparcTargetMachine &TM, CodeGenOptLevel OptLevel);
36};
37
38FunctionPass *createSparcDAGToDAGISelLegacyPass(SparcTargetMachine &TM,
39 CodeGenOptLevel OptLevel);
40
41class SparcDelaySlotFillerPass
42 : public RequiredPassInfoMixin<SparcDelaySlotFillerPass> {
43public:
44 PreservedAnalyses run(MachineFunction &MF,
45 MachineFunctionAnalysisManager &MFAM);
46
47 MachineFunctionProperties getRequiredProperties() const {
48 return MachineFunctionProperties().setNoVRegs();
49 }
50};
51
52FunctionPass *createSparcDelaySlotFillerLegacyPass();
53
54class SparcErrataWorkaroundPass
55 : public RequiredPassInfoMixin<SparcErrataWorkaroundPass> {
56public:
57 PreservedAnalyses run(MachineFunction &MF,
58 MachineFunctionAnalysisManager &MFAM);
59};
60
61void initializeSparcAsmPrinterPass(PassRegistry &);
62void initializeSparcDAGToDAGISelLegacyPass(PassRegistry &);
63void initializeSparcErrataWorkaroundLegacyPass(PassRegistry &);
64} // namespace llvm
65
66namespace llvm {
67 // Enums corresponding to Sparc condition codes, both icc's and fcc's. These
68 // values must be kept in sync with the ones in the .td file.
69 namespace SPCC {
70 enum CondCodes {
71 ICC_A = 8, // Always
72 ICC_N = 0, // Never
73 ICC_NE = 9, // Not Equal
74 ICC_E = 1, // Equal
75 ICC_G = 10, // Greater
76 ICC_LE = 2, // Less or Equal
77 ICC_GE = 11, // Greater or Equal
78 ICC_L = 3, // Less
79 ICC_GU = 12, // Greater Unsigned
80 ICC_LEU = 4, // Less or Equal Unsigned
81 ICC_CC = 13, // Carry Clear/Great or Equal Unsigned
82 ICC_CS = 5, // Carry Set/Less Unsigned
83 ICC_POS = 14, // Positive
84 ICC_NEG = 6, // Negative
85 ICC_VC = 15, // Overflow Clear
86 ICC_VS = 7, // Overflow Set
87
88 FCC_BEGIN = 16,
89 FCC_A = 8 + FCC_BEGIN, // Always
90 FCC_N = 0 + FCC_BEGIN, // Never
91 FCC_U = 7 + FCC_BEGIN, // Unordered
92 FCC_G = 6 + FCC_BEGIN, // Greater
93 FCC_UG = 5 + FCC_BEGIN, // Unordered or Greater
94 FCC_L = 4 + FCC_BEGIN, // Less
95 FCC_UL = 3 + FCC_BEGIN, // Unordered or Less
96 FCC_LG = 2 + FCC_BEGIN, // Less or Greater
97 FCC_NE = 1 + FCC_BEGIN, // Not Equal
98 FCC_E = 9 + FCC_BEGIN, // Equal
99 FCC_UE = 10 + FCC_BEGIN, // Unordered or Equal
100 FCC_GE = 11 + FCC_BEGIN, // Greater or Equal
101 FCC_UGE = 12 + FCC_BEGIN, // Unordered or Greater or Equal
102 FCC_LE = 13 + FCC_BEGIN, // Less or Equal
103 FCC_ULE = 14 + FCC_BEGIN, // Unordered or Less or Equal
104 FCC_O = 15 + FCC_BEGIN, // Ordered
105
106 CPCC_BEGIN = 32,
107 CPCC_A = 8 + CPCC_BEGIN, // Always
108 CPCC_N = 0 + CPCC_BEGIN, // Never
109 CPCC_3 = 7 + CPCC_BEGIN,
110 CPCC_2 = 6 + CPCC_BEGIN,
111 CPCC_23 = 5 + CPCC_BEGIN,
112 CPCC_1 = 4 + CPCC_BEGIN,
113 CPCC_13 = 3 + CPCC_BEGIN,
114 CPCC_12 = 2 + CPCC_BEGIN,
115 CPCC_123 = 1 + CPCC_BEGIN,
116 CPCC_0 = 9 + CPCC_BEGIN,
117 CPCC_03 = 10 + CPCC_BEGIN,
118 CPCC_02 = 11 + CPCC_BEGIN,
119 CPCC_023 = 12 + CPCC_BEGIN,
120 CPCC_01 = 13 + CPCC_BEGIN,
121 CPCC_013 = 14 + CPCC_BEGIN,
122 CPCC_012 = 15 + CPCC_BEGIN,
123
124 REG_BEGIN = 48,
125 REG_Z = 1 + REG_BEGIN, // Is zero
126 REG_LEZ = 2 + REG_BEGIN, // Less or equal to zero
127 REG_LZ = 3 + REG_BEGIN, // Less than zero
128 REG_NZ = 5 + REG_BEGIN, // Is not zero
129 REG_GZ = 6 + REG_BEGIN, // Greater than zero
130 REG_GEZ = 7 + REG_BEGIN // Greater than or equal to zero
131 };
132 }
133
134 inline static const char *SPARCCondCodeToString(SPCC::CondCodes CC) {
135 switch (CC) {
136 case SPCC::ICC_A: return "a";
137 case SPCC::ICC_N: return "n";
138 case SPCC::ICC_NE: return "ne";
139 case SPCC::ICC_E: return "e";
140 case SPCC::ICC_G: return "g";
141 case SPCC::ICC_LE: return "le";
142 case SPCC::ICC_GE: return "ge";
143 case SPCC::ICC_L: return "l";
144 case SPCC::ICC_GU: return "gu";
145 case SPCC::ICC_LEU: return "leu";
146 case SPCC::ICC_CC: return "cc";
147 case SPCC::ICC_CS: return "cs";
148 case SPCC::ICC_POS: return "pos";
149 case SPCC::ICC_NEG: return "neg";
150 case SPCC::ICC_VC: return "vc";
151 case SPCC::ICC_VS: return "vs";
152 case SPCC::FCC_A: return "a";
153 case SPCC::FCC_N: return "n";
154 case SPCC::FCC_U: return "u";
155 case SPCC::FCC_G: return "g";
156 case SPCC::FCC_UG: return "ug";
157 case SPCC::FCC_L: return "l";
158 case SPCC::FCC_UL: return "ul";
159 case SPCC::FCC_LG: return "lg";
160 case SPCC::FCC_NE: return "ne";
161 case SPCC::FCC_E: return "e";
162 case SPCC::FCC_UE: return "ue";
163 case SPCC::FCC_GE: return "ge";
164 case SPCC::FCC_UGE: return "uge";
165 case SPCC::FCC_LE: return "le";
166 case SPCC::FCC_ULE: return "ule";
167 case SPCC::FCC_O: return "o";
168 case SPCC::CPCC_A: return "a";
169 case SPCC::CPCC_N: return "n";
170 case SPCC::CPCC_3: return "3";
171 case SPCC::CPCC_2: return "2";
172 case SPCC::CPCC_23: return "23";
173 case SPCC::CPCC_1: return "1";
174 case SPCC::CPCC_13: return "13";
175 case SPCC::CPCC_12: return "12";
176 case SPCC::CPCC_123: return "123";
177 case SPCC::CPCC_0: return "0";
178 case SPCC::CPCC_03: return "03";
179 case SPCC::CPCC_02: return "02";
180 case SPCC::CPCC_023: return "023";
181 case SPCC::CPCC_01: return "01";
182 case SPCC::CPCC_013: return "013";
183 case SPCC::CPCC_012: return "012";
184 case SPCC::REG_BEGIN:
185 llvm_unreachable("Use of reserved cond code");
186 case SPCC::REG_Z:
187 return "z";
188 case SPCC::REG_LEZ:
189 return "lez";
190 case SPCC::REG_LZ:
191 return "lz";
192 case SPCC::REG_NZ:
193 return "nz";
194 case SPCC::REG_GZ:
195 return "gz";
196 case SPCC::REG_GEZ:
197 return "gez";
198 }
199 llvm_unreachable("Invalid cond code");
200 }
201
202 inline static unsigned HI22(int64_t imm) {
203 return (unsigned)((imm >> 10) & ((1 << 22)-1));
204 }
205
206 inline static unsigned LO10(int64_t imm) {
207 return (unsigned)(imm & 0x3FF);
208 }
209
210 inline static unsigned HIX22(int64_t imm) {
211 return HI22(imm: ~imm);
212 }
213
214 inline static unsigned LOX10(int64_t imm) {
215 return ~LO10(imm: ~imm);
216 }
217
218} // end namespace llvm
219#endif
220