LLVM 20.0.0git
XCOFF.cpp
Go to the documentation of this file.
1//===-- llvm/BinaryFormat/XCOFF.cpp - The XCOFF file format -----*- 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
11#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/Errc.h"
14#include "llvm/Support/Error.h"
16
17using namespace llvm;
18
19#define SMC_CASE(A) \
20 case XCOFF::XMC_##A: \
21 return #A;
23 switch (SMC) {
24 SMC_CASE(PR)
25 SMC_CASE(RO)
26 SMC_CASE(DB)
27 SMC_CASE(GL)
28 SMC_CASE(XO)
29 SMC_CASE(SV)
30 SMC_CASE(SV64)
31 SMC_CASE(SV3264)
32 SMC_CASE(TI)
33 SMC_CASE(TB)
34 SMC_CASE(RW)
35 SMC_CASE(TC0)
36 SMC_CASE(TC)
37 SMC_CASE(TD)
38 SMC_CASE(DS)
39 SMC_CASE(UA)
40 SMC_CASE(BS)
41 SMC_CASE(UC)
42 SMC_CASE(TL)
43 SMC_CASE(UL)
44 SMC_CASE(TE)
45#undef SMC_CASE
46 }
47
48 // TODO: need to add a test case for "Unknown" and other SMC.
49 return "Unknown";
50}
51
52#define RELOC_CASE(A) \
53 case XCOFF::A: \
54 return #A;
56 switch (Type) {
80 }
81 return "Unknown";
82}
83#undef RELOC_CASE
84
85#define LANG_CASE(A) \
86 case XCOFF::TracebackTable::A: \
87 return #A;
88
91 switch (LangId) {
93 LANG_CASE(Fortran)
94 LANG_CASE(Pascal)
95 LANG_CASE(Ada)
96 LANG_CASE(PL1)
98 LANG_CASE(Lisp)
99 LANG_CASE(Cobol)
100 LANG_CASE(Modula2)
101 LANG_CASE(Rpg)
102 LANG_CASE(PL8)
103 LANG_CASE(Assembly)
104 LANG_CASE(Java)
105 LANG_CASE(ObjectiveC)
106 LANG_CASE(CPlusPlus)
107 }
108 return "Unknown";
109}
110#undef LANG_CASE
111
113 StringRef CPU = PPC::normalizeCPUName(CPUName);
115 .Cases("generic", "COM", XCOFF::TCPU_COM)
116 .Case("601", XCOFF::TCPU_601)
117 .Cases("602", "603", "603e", "603ev", XCOFF::TCPU_603)
118 .Cases("604", "604e", XCOFF::TCPU_604)
119 .Case("620", XCOFF::TCPU_620)
120 .Case("970", XCOFF::TCPU_970)
121 .Cases("a2", "g3", "g4", "g5", "e500", XCOFF::TCPU_COM)
122 .Cases("pwr3", "pwr4", XCOFF::TCPU_COM)
123 .Cases("pwr5", "PWR5", XCOFF::TCPU_PWR5)
124 .Cases("pwr5x", "PWR5X", XCOFF::TCPU_PWR5X)
125 .Cases("pwr6", "PWR6", XCOFF::TCPU_PWR6)
126 .Cases("pwr6x", "PWR6E", XCOFF::TCPU_PWR6E)
127 .Cases("pwr7", "PWR7", XCOFF::TCPU_PWR7)
128 .Cases("pwr8", "PWR8", XCOFF::TCPU_PWR8)
129 .Cases("pwr9", "PWR9", XCOFF::TCPU_PWR9)
130 .Cases("pwr10", "PWR10", XCOFF::TCPU_PWR10)
131 .Cases("ppc", "PPC", "ppc32", "ppc64", XCOFF::TCPU_COM)
132 .Case("ppc64le", XCOFF::TCPU_PWR8)
133 .Case("future", XCOFF::TCPU_PWR10)
134 .Cases("any", "ANY", XCOFF::TCPU_ANY)
136}
137
138#define TCPU_CASE(A) \
139 case XCOFF::TCPU_##A: \
140 return #A;
142 switch (TCPU) {
143 TCPU_CASE(INVALID)
144 TCPU_CASE(PPC)
145 TCPU_CASE(PPC64)
146 TCPU_CASE(COM)
147 TCPU_CASE(PWR)
148 TCPU_CASE(ANY)
149 TCPU_CASE(601)
150 TCPU_CASE(603)
151 TCPU_CASE(604)
152 TCPU_CASE(620)
153 TCPU_CASE(A35)
154 TCPU_CASE(PWR5)
155 TCPU_CASE(970)
156 TCPU_CASE(PWR6)
157 TCPU_CASE(PWR5X)
158 TCPU_CASE(PWR6E)
159 TCPU_CASE(PWR7)
160 TCPU_CASE(PWR8)
161 TCPU_CASE(PWR9)
162 TCPU_CASE(PWR10)
163 TCPU_CASE(PWRX)
164 }
165 return "INVALID";
166}
167#undef TCPU_CASE
168
170 unsigned FixedParmsNum,
171 unsigned FloatingParmsNum) {
172 SmallString<32> ParmsType;
173 int Bits = 0;
174 unsigned ParsedFixedNum = 0;
175 unsigned ParsedFloatingNum = 0;
176 unsigned ParsedNum = 0;
177 unsigned ParmsNum = FixedParmsNum + FloatingParmsNum;
178
179 // In the function PPCFunctionInfo::getParmsType(), when there are no vector
180 // parameters, the 31st bit of ParmsType is always zero even if it indicates a
181 // floating point parameter. The parameter type information is lost. There
182 // are only 8 GPRs used for parameters passing, the floating parameters
183 // also occupy GPRs if there are available, so the 31st bit can never be a
184 // fixed parameter. At the same time, we also do not know whether the zero of
185 // the 31st bit indicates a float or double parameter type here. Therefore, we
186 // ignore the 31st bit.
187 while (Bits < 31 && ParsedNum < ParmsNum) {
188 if (++ParsedNum > 1)
189 ParmsType += ", ";
191 // Fixed parameter type.
192 ParmsType += "i";
193 ++ParsedFixedNum;
194 Value <<= 1;
195 ++Bits;
196 } else {
198 // Float parameter type.
199 ParmsType += "f";
200 else
201 // Double parameter type.
202 ParmsType += "d";
203 ++ParsedFloatingNum;
204 Value <<= 2;
205 Bits += 2;
206 }
207 }
208
209 // We have more parameters than the 32 Bits could encode.
210 if (ParsedNum < ParmsNum)
211 ParmsType += ", ...";
212
213 if (Value != 0u || ParsedFixedNum > FixedParmsNum ||
214 ParsedFloatingNum > FloatingParmsNum)
215 return createStringError(errc::invalid_argument,
216 "ParmsType encodes can not map to ParmsNum "
217 "parameters in parseParmsType.");
218 return ParmsType;
219}
220
222 SmallString<32> Res;
223
224 if (Flag & ExtendedTBTableFlag::TB_OS1)
225 Res += "TB_OS1 ";
226 if (Flag & ExtendedTBTableFlag::TB_RESERVED)
227 Res += "TB_RESERVED ";
228 if (Flag & ExtendedTBTableFlag::TB_SSP_CANARY)
229 Res += "TB_SSP_CANARY ";
230 if (Flag & ExtendedTBTableFlag::TB_OS2)
231 Res += "TB_OS2 ";
232 if (Flag & ExtendedTBTableFlag::TB_EH_INFO)
233 Res += "TB_EH_INFO ";
234 if (Flag & ExtendedTBTableFlag::TB_LONGTBTABLE2)
235 Res += "TB_LONGTBTABLE2 ";
236
237 // Two of the bits that haven't got used in the mask.
238 if (Flag & 0x06)
239 Res += "Unknown ";
240
241 // Pop the last space.
242 Res.pop_back();
243 return Res;
244}
245
248 unsigned FloatingParmsNum,
249 unsigned VectorParmsNum) {
250 SmallString<32> ParmsType;
251
252 unsigned ParsedFixedNum = 0;
253 unsigned ParsedFloatingNum = 0;
254 unsigned ParsedVectorNum = 0;
255 unsigned ParsedNum = 0;
256 unsigned ParmsNum = FixedParmsNum + FloatingParmsNum + VectorParmsNum;
257
258 for (int Bits = 0; Bits < 32 && ParsedNum < ParmsNum; Bits += 2) {
259 if (++ParsedNum > 1)
260 ParmsType += ", ";
261
264 ParmsType += "i";
265 ++ParsedFixedNum;
266 break;
268 ParmsType += "v";
269 ++ParsedVectorNum;
270 break;
272 ParmsType += "f";
273 ++ParsedFloatingNum;
274 break;
276 ParmsType += "d";
277 ++ParsedFloatingNum;
278 break;
279 default:
280 assert(false && "Unrecognized bits in ParmsType.");
281 }
282 Value <<= 2;
283 }
284
285 // We have more parameters than the 32 Bits could encode.
286 if (ParsedNum < ParmsNum)
287 ParmsType += ", ...";
288
289 if (Value != 0u || ParsedFixedNum > FixedParmsNum ||
290 ParsedFloatingNum > FloatingParmsNum || ParsedVectorNum > VectorParmsNum)
291 return createStringError(
292 errc::invalid_argument,
293 "ParmsType encodes can not map to ParmsNum parameters "
294 "in parseParmsTypeWithVecInfo.");
295
296 return ParmsType;
297}
298
300 unsigned ParmsNum) {
301 SmallString<32> ParmsType;
302 unsigned ParsedNum = 0;
303 for (int Bits = 0; ParsedNum < ParmsNum && Bits < 32; Bits += 2) {
304 if (++ParsedNum > 1)
305 ParmsType += ", ";
308 ParmsType += "vc";
309 break;
310
312 ParmsType += "vs";
313 break;
314
316 ParmsType += "vi";
317 break;
318
320 ParmsType += "vf";
321 break;
322 }
323
324 Value <<= 2;
325 }
326
327 // We have more parameters than the 32 Bits could encode.
328 if (ParsedNum < ParmsNum)
329 ParmsType += ", ...";
330
331 if (Value != 0u)
332 return createStringError(errc::invalid_argument,
333 "ParmsType encodes more than ParmsNum parameters "
334 "in parseVectorParmsType.");
335 return ParmsType;
336}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
#define LANG_CASE(A)
Definition: XCOFF.cpp:85
#define SMC_CASE(A)
Definition: XCOFF.cpp:19
#define RELOC_CASE(A)
Definition: XCOFF.cpp:52
#define TCPU_CASE(A)
Definition: XCOFF.cpp:138
Tagged union holding either a T or a Error.
Definition: Error.h:481
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Definition: StringSwitch.h:90
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StringRef normalizeCPUName(StringRef CPUName)
SmallString< 32 > getExtendedTBTableFlagString(uint8_t Flag)
Definition: XCOFF.cpp:221
XCOFF::CFileCpuId getCpuID(StringRef CPU)
Definition: XCOFF.cpp:112
Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
Definition: XCOFF.cpp:247
StringRef getRelocationTypeString(XCOFF::RelocationType Type)
Definition: XCOFF.cpp:55
Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
Definition: XCOFF.cpp:169
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:22
Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
Definition: XCOFF.cpp:299
RelocationType
Definition: XCOFF.h:262
@ R_RBR
Branch relative to self relocation.
Definition: XCOFF.h:306
@ R_TOC
Relative to the TOC relocation.
Definition: XCOFF.h:274
@ R_RLA
Positive load address relocation. Modifiable instruction.
Definition: XCOFF.h:266
@ R_TLSML
Module reference to the local TLS storage.
Definition: XCOFF.h:315
@ R_TRL
TOC relative indirect load relocation.
Definition: XCOFF.h:277
@ R_BR
Branch relative to self relocation.
Definition: XCOFF.h:300
@ R_POS
Positive relocation.
Definition: XCOFF.h:263
@ R_RBA
Branch absolute relocation.
Definition: XCOFF.h:304
@ R_BA
Branch absolute relocation.
Definition: XCOFF.h:298
@ R_REL
Relative to self relocation.
Definition: XCOFF.h:270
@ R_NEG
Negative relocation.
Definition: XCOFF.h:268
@ R_TLS_IE
Initial-exec reference to TLS symbol.
Definition: XCOFF.h:310
@ R_TLSM
Module reference to TLS.
Definition: XCOFF.h:313
@ R_GL
Global linkage-external TOC address relocation.
Definition: XCOFF.h:287
@ R_REF
A non-relocating relocation.
Definition: XCOFF.h:293
@ R_RL
Positive indirect load relocation. Modifiable instruction.
Definition: XCOFF.h:265
@ R_TRLA
Relative to the TOC or to the thread-local storage base relocation.
Definition: XCOFF.h:280
@ R_TCL
Local object TOC address relocation.
Definition: XCOFF.h:290
@ R_TOCL
Relative to TOC lower.
Definition: XCOFF.h:319
@ R_TOCU
Relative to TOC upper.
Definition: XCOFF.h:317
@ R_TLS_LD
Local-dynamic reference to TLS symbol.
Definition: XCOFF.h:311
@ R_TLS
General-dynamic reference to TLS symbol.
Definition: XCOFF.h:309
@ R_TLS_LE
Local-exec reference to TLS symbol.
Definition: XCOFF.h:312
@ TCPU_PWR6E
Definition: XCOFF.h:356
@ TCPU_PWR9
Definition: XCOFF.h:359
@ TCPU_604
604 implementation of PowerPC architecture.
Definition: XCOFF.h:347
@ TCPU_PWR7
Definition: XCOFF.h:357
@ TCPU_PWR8
Definition: XCOFF.h:358
@ TCPU_ANY
Mixture of any incompatable POWER and PowerPC architecture implementations.
Definition: XCOFF.h:343
@ TCPU_PWR10
Definition: XCOFF.h:360
@ TCPU_PWR5X
Definition: XCOFF.h:355
@ TCPU_COM
POWER and PowerPC architecture common.
Definition: XCOFF.h:341
@ TCPU_603
603 implementation of PowerPC architecture.
Definition: XCOFF.h:346
@ TCPU_PWR6
Definition: XCOFF.h:354
@ TCPU_PWR5
Definition: XCOFF.h:352
@ TCPU_620
Definition: XCOFF.h:350
@ TCPU_601
601 implementation of PowerPC architecture.
Definition: XCOFF.h:345
@ TCPU_970
Definition: XCOFF.h:353
@ TCPU_INVALID
Invalid id - assumes POWER for old objects.
Definition: XCOFF.h:338
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:103
StringRef getTCPUString(XCOFF::CFileCpuId TCPU)
Definition: XCOFF.cpp:141
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId)
Definition: XCOFF.cpp:89
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1291
static constexpr uint32_t ParmTypeFloatingIsDoubleBit
Definition: XCOFF.h:457
static constexpr uint32_t ParmTypeIsFloatingBit
Definition: XCOFF.h:456
static constexpr uint32_t ParmTypeIsVectorShortBit
Definition: XCOFF.h:476
static constexpr uint32_t ParmTypeMask
Definition: XCOFF.h:463
static constexpr uint32_t ParmTypeIsDoubleBits
Definition: XCOFF.h:462
static constexpr uint32_t ParmTypeIsVectorIntBit
Definition: XCOFF.h:477
static constexpr uint32_t ParmTypeIsFixedBits
Definition: XCOFF.h:459
static constexpr uint32_t ParmTypeIsVectorBits
Definition: XCOFF.h:460
static constexpr uint32_t ParmTypeIsVectorCharBit
Definition: XCOFF.h:475
static constexpr uint32_t ParmTypeIsVectorFloatBit
Definition: XCOFF.h:478
static constexpr uint32_t ParmTypeIsFloatingBits
Definition: XCOFF.h:461