LLVM 19.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"
12#include "llvm/Support/Errc.h"
13#include "llvm/Support/Error.h"
14
15using namespace llvm;
16
17#define SMC_CASE(A) \
18 case XCOFF::XMC_##A: \
19 return #A;
21 switch (SMC) {
22 SMC_CASE(PR)
23 SMC_CASE(RO)
24 SMC_CASE(DB)
25 SMC_CASE(GL)
26 SMC_CASE(XO)
27 SMC_CASE(SV)
28 SMC_CASE(SV64)
29 SMC_CASE(SV3264)
30 SMC_CASE(TI)
31 SMC_CASE(TB)
32 SMC_CASE(RW)
33 SMC_CASE(TC0)
34 SMC_CASE(TC)
35 SMC_CASE(TD)
36 SMC_CASE(DS)
37 SMC_CASE(UA)
38 SMC_CASE(BS)
39 SMC_CASE(UC)
40 SMC_CASE(TL)
41 SMC_CASE(UL)
42 SMC_CASE(TE)
43#undef SMC_CASE
44 }
45
46 // TODO: need to add a test case for "Unknown" and other SMC.
47 return "Unknown";
48}
49
50#define RELOC_CASE(A) \
51 case XCOFF::A: \
52 return #A;
54 switch (Type) {
78 }
79 return "Unknown";
80}
81#undef RELOC_CASE
82
83#define LANG_CASE(A) \
84 case XCOFF::TracebackTable::A: \
85 return #A;
86
89 switch (LangId) {
91 LANG_CASE(Fortran)
92 LANG_CASE(Pascal)
93 LANG_CASE(Ada)
94 LANG_CASE(PL1)
96 LANG_CASE(Lisp)
97 LANG_CASE(Cobol)
98 LANG_CASE(Modula2)
99 LANG_CASE(Rpg)
100 LANG_CASE(PL8)
101 LANG_CASE(Assembly)
102 LANG_CASE(Java)
103 LANG_CASE(ObjectiveC)
104 LANG_CASE(CPlusPlus)
105 }
106 return "Unknown";
107}
108#undef LANG_CASE
109
111 unsigned FixedParmsNum,
112 unsigned FloatingParmsNum) {
113 SmallString<32> ParmsType;
114 int Bits = 0;
115 unsigned ParsedFixedNum = 0;
116 unsigned ParsedFloatingNum = 0;
117 unsigned ParsedNum = 0;
118 unsigned ParmsNum = FixedParmsNum + FloatingParmsNum;
119
120 // In the function PPCFunctionInfo::getParmsType(), when there are no vector
121 // parameters, the 31st bit of ParmsType is always zero even if it indicates a
122 // floating point parameter. The parameter type information is lost. There
123 // are only 8 GPRs used for parameters passing, the floating parameters
124 // also occupy GPRs if there are available, so the 31st bit can never be a
125 // fixed parameter. At the same time, we also do not know whether the zero of
126 // the 31st bit indicates a float or double parameter type here. Therefore, we
127 // ignore the 31st bit.
128 while (Bits < 31 && ParsedNum < ParmsNum) {
129 if (++ParsedNum > 1)
130 ParmsType += ", ";
132 // Fixed parameter type.
133 ParmsType += "i";
134 ++ParsedFixedNum;
135 Value <<= 1;
136 ++Bits;
137 } else {
139 // Float parameter type.
140 ParmsType += "f";
141 else
142 // Double parameter type.
143 ParmsType += "d";
144 ++ParsedFloatingNum;
145 Value <<= 2;
146 Bits += 2;
147 }
148 }
149
150 // We have more parameters than the 32 Bits could encode.
151 if (ParsedNum < ParmsNum)
152 ParmsType += ", ...";
153
154 if (Value != 0u || ParsedFixedNum > FixedParmsNum ||
155 ParsedFloatingNum > FloatingParmsNum)
156 return createStringError(errc::invalid_argument,
157 "ParmsType encodes can not map to ParmsNum "
158 "parameters in parseParmsType.");
159 return ParmsType;
160}
161
163 SmallString<32> Res;
164
165 if (Flag & ExtendedTBTableFlag::TB_OS1)
166 Res += "TB_OS1 ";
167 if (Flag & ExtendedTBTableFlag::TB_RESERVED)
168 Res += "TB_RESERVED ";
169 if (Flag & ExtendedTBTableFlag::TB_SSP_CANARY)
170 Res += "TB_SSP_CANARY ";
171 if (Flag & ExtendedTBTableFlag::TB_OS2)
172 Res += "TB_OS2 ";
173 if (Flag & ExtendedTBTableFlag::TB_EH_INFO)
174 Res += "TB_EH_INFO ";
175 if (Flag & ExtendedTBTableFlag::TB_LONGTBTABLE2)
176 Res += "TB_LONGTBTABLE2 ";
177
178 // Two of the bits that haven't got used in the mask.
179 if (Flag & 0x06)
180 Res += "Unknown ";
181
182 // Pop the last space.
183 Res.pop_back();
184 return Res;
185}
186
189 unsigned FloatingParmsNum,
190 unsigned VectorParmsNum) {
191 SmallString<32> ParmsType;
192
193 unsigned ParsedFixedNum = 0;
194 unsigned ParsedFloatingNum = 0;
195 unsigned ParsedVectorNum = 0;
196 unsigned ParsedNum = 0;
197 unsigned ParmsNum = FixedParmsNum + FloatingParmsNum + VectorParmsNum;
198
199 for (int Bits = 0; Bits < 32 && ParsedNum < ParmsNum; Bits += 2) {
200 if (++ParsedNum > 1)
201 ParmsType += ", ";
202
205 ParmsType += "i";
206 ++ParsedFixedNum;
207 break;
209 ParmsType += "v";
210 ++ParsedVectorNum;
211 break;
213 ParmsType += "f";
214 ++ParsedFloatingNum;
215 break;
217 ParmsType += "d";
218 ++ParsedFloatingNum;
219 break;
220 default:
221 assert(false && "Unrecognized bits in ParmsType.");
222 }
223 Value <<= 2;
224 }
225
226 // We have more parameters than the 32 Bits could encode.
227 if (ParsedNum < ParmsNum)
228 ParmsType += ", ...";
229
230 if (Value != 0u || ParsedFixedNum > FixedParmsNum ||
231 ParsedFloatingNum > FloatingParmsNum || ParsedVectorNum > VectorParmsNum)
232 return createStringError(
233 errc::invalid_argument,
234 "ParmsType encodes can not map to ParmsNum parameters "
235 "in parseParmsTypeWithVecInfo.");
236
237 return ParmsType;
238}
239
241 unsigned ParmsNum) {
242 SmallString<32> ParmsType;
243 unsigned ParsedNum = 0;
244 for (int Bits = 0; ParsedNum < ParmsNum && Bits < 32; Bits += 2) {
245 if (++ParsedNum > 1)
246 ParmsType += ", ";
249 ParmsType += "vc";
250 break;
251
253 ParmsType += "vs";
254 break;
255
257 ParmsType += "vi";
258 break;
259
261 ParmsType += "vf";
262 break;
263 }
264
265 Value <<= 2;
266 }
267
268 // We have more parameters than the 32 Bits could encode.
269 if (ParsedNum < ParmsNum)
270 ParmsType += ", ...";
271
272 if (Value != 0u)
273 return createStringError(errc::invalid_argument,
274 "ParmsType encodes more than ParmsNum parameters "
275 "in parseVectorParmsType.");
276 return ParmsType;
277}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
#define LANG_CASE(A)
Definition: XCOFF.cpp:83
#define SMC_CASE(A)
Definition: XCOFF.cpp:17
#define RELOC_CASE(A)
Definition: XCOFF.cpp:50
Tagged union holding either a T or a Error.
Definition: Error.h:474
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:50
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
SmallString< 32 > getExtendedTBTableFlagString(uint8_t Flag)
Definition: XCOFF.cpp:162
Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
Definition: XCOFF.cpp:188
StringRef getRelocationTypeString(XCOFF::RelocationType Type)
Definition: XCOFF.cpp:53
Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
Definition: XCOFF.cpp:110
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:20
Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
Definition: XCOFF.cpp:240
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
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:103
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId)
Definition: XCOFF.cpp:87
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:1258
static constexpr uint32_t ParmTypeFloatingIsDoubleBit
Definition: XCOFF.h:433
static constexpr uint32_t ParmTypeIsFloatingBit
Definition: XCOFF.h:432
static constexpr uint32_t ParmTypeIsVectorShortBit
Definition: XCOFF.h:452
static constexpr uint32_t ParmTypeMask
Definition: XCOFF.h:439
static constexpr uint32_t ParmTypeIsDoubleBits
Definition: XCOFF.h:438
static constexpr uint32_t ParmTypeIsVectorIntBit
Definition: XCOFF.h:453
static constexpr uint32_t ParmTypeIsFixedBits
Definition: XCOFF.h:435
static constexpr uint32_t ParmTypeIsVectorBits
Definition: XCOFF.h:436
static constexpr uint32_t ParmTypeIsVectorCharBit
Definition: XCOFF.h:451
static constexpr uint32_t ParmTypeIsVectorFloatBit
Definition: XCOFF.h:454
static constexpr uint32_t ParmTypeIsFloatingBits
Definition: XCOFF.h:437