LLVM  14.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 
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/Errc.h"
13 #include "llvm/Support/Error.h"
14 
15 using 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) {
90  LANG_CASE(C)
92  LANG_CASE(Pascal)
93  LANG_CASE(Ada)
94  LANG_CASE(PL1)
95  LANG_CASE(Basic)
96  LANG_CASE(Lisp)
98  LANG_CASE(Modula2)
99  LANG_CASE(Rpg)
100  LANG_CASE(PL8)
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)
157  "ParmsType encodes can not map to ParmsNum "
158  "parameters in parseParmsType.");
159  return ParmsType;
160 }
161 
163  SmallString<32> Res;
164 
166  Res += "TB_OS1 ";
168  Res += "TB_RESERVED ";
170  Res += "TB_SSP_CANARY ";
172  Res += "TB_OS2 ";
174  Res += "TB_EH_INFO ";
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(
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)
274  "ParmsType encodes more than ParmsNum parameters "
275  "in parseVectorParmsType.");
276  return ParmsType;
277 }
llvm::errc::invalid_argument
@ invalid_argument
llvm::XCOFF::getExtendedTBTableFlagString
SmallString< 32 > getExtendedTBTableFlagString(uint8_t Flag)
Definition: XCOFF.cpp:162
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
SMC_CASE
#define SMC_CASE(A)
Definition: XCOFF.cpp:17
llvm::SIInstrFlags::DS
@ DS
Definition: SIDefines.h:59
llvm::XCOFF::R_TRLA
@ R_TRLA
Relative to the TOC or to the thread-local storage base relocation. Compilers are not permitted to ge...
Definition: XCOFF.h:221
StringRef.h
llvm::XCOFF::TB_OS2
@ TB_OS2
Reserved for OS use.
Definition: XCOFF.h:404
Error.h
Errc.h
llvm::XCOFF::TracebackTable::ParmTypeIsFloatingBit
static constexpr uint32_t ParmTypeIsFloatingBit
Definition: XCOFF.h:372
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::XCOFF::TracebackTable::ParmTypeFloatingIsDoubleBit
static constexpr uint32_t ParmTypeFloatingIsDoubleBit
Definition: XCOFF.h:373
llvm::XCOFF::R_TLS_LE
@ R_TLS_LE
Local-exec reference to TLS symbol.
Definition: XCOFF.h:253
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::XCOFF::R_TLS_LD
@ R_TLS_LD
Local-dynamic reference to TLS symbol.
Definition: XCOFF.h:252
llvm::XCOFF::R_RBA
@ R_RBA
Branch absolute relocation. Similar to R_BA but references a modifiable instruction.
Definition: XCOFF.h:245
RELOC_CASE
#define RELOC_CASE(A)
Definition: XCOFF.cpp:50
llvm::XCOFF::R_TOCU
@ R_TOCU
Relative to TOC upper. Specifies the high-order 16 bits of a large code model TOC-relative relocation...
Definition: XCOFF.h:258
llvm::XCOFF::R_GL
@ R_GL
Global linkage-external TOC address relocation. Provides the address of the external TOC associated w...
Definition: XCOFF.h:228
XCOFF.h
SmallString.h
llvm::XCOFF::TB_SSP_CANARY
@ TB_SSP_CANARY
stack smasher canary present on stack.
Definition: XCOFF.h:403
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::XCOFF::R_TRL
@ R_TRL
TOC relative indirect load relocation. Similar to R_TOC, but not modifiable instruction.
Definition: XCOFF.h:218
llvm::XCOFF::R_RLA
@ R_RLA
Positive load address relocation. Modifiable instruction.
Definition: XCOFF.h:207
llvm::XCOFF::R_TLS
@ R_TLS
General-dynamic reference to TLS symbol.
Definition: XCOFF.h:250
llvm::XCOFF::R_POS
@ R_POS
Positive relocation. Provides the address of the referenced symbol.
Definition: XCOFF.h:204
llvm::XCOFF::TB_EH_INFO
@ TB_EH_INFO
Exception handling info present.
Definition: XCOFF.h:405
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
llvm::XCOFF::getMappingClassString
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:20
llvm::codeview::Java
@ Java
Definition: CodeView.h:160
llvm::XCOFF::R_RL
@ R_RL
Positive indirect load relocation. Modifiable instruction.
Definition: XCOFF.h:206
llvm::XCOFF::R_NEG
@ R_NEG
Negative relocation. Provides the negative of the address of the referenced symbol.
Definition: XCOFF.h:209
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:46
llvm::SmallString< 32 >
llvm::XCOFF::TracebackTable::LanguageID
LanguageID
Definition: XCOFF.h:303
llvm::codeview::Fortran
@ Fortran
Definition: CodeView.h:149
llvm::XCOFF::parseParmsTypeWithVecInfo
Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
Definition: XCOFF.cpp:188
llvm::XCOFF::parseVectorParmsType
Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
Definition: XCOFF.cpp:240
llvm::XCOFF::R_RBR
@ R_RBR
Branch relative to self relocation. Similar to the R_BR relocation type, but references a modifiable ...
Definition: XCOFF.h:247
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::XCOFF::TracebackTable::ParmTypeIsVectorBits
static constexpr uint32_t ParmTypeIsVectorBits
Definition: XCOFF.h:376
llvm::X86II::TB
@ TB
Definition: X86BaseInfo.h:800
llvm::XCOFF::R_TLSML
@ R_TLSML
Module reference to the local TLS storage.
Definition: XCOFF.h:256
llvm::XCOFF::TracebackTable::ParmTypeIsVectorFloatBit
static constexpr uint32_t ParmTypeIsVectorFloatBit
Definition: XCOFF.h:394
llvm::XCOFF::TracebackTable::ParmTypeIsFloatingBits
static constexpr uint32_t ParmTypeIsFloatingBits
Definition: XCOFF.h:377
llvm::XCOFF::TB_OS1
@ TB_OS1
Reserved for OS use.
Definition: XCOFF.h:401
llvm::XCOFF::parseParmsType
Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
Definition: XCOFF.cpp:110
llvm::XCOFF::R_TLS_IE
@ R_TLS_IE
Initial-exec reference to TLS symbol.
Definition: XCOFF.h:251
llvm::XCOFF::TracebackTable::ParmTypeIsVectorIntBit
static constexpr uint32_t ParmTypeIsVectorIntBit
Definition: XCOFF.h:393
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::XCOFF::TracebackTable::ParmTypeIsVectorCharBit
static constexpr uint32_t ParmTypeIsVectorCharBit
Definition: XCOFF.h:391
llvm::XCOFF::R_REF
@ R_REF
A non-relocating relocation. Used to prevent the binder from garbage collecting a csect (such as code...
Definition: XCOFF.h:234
llvm::XCOFF::TracebackTable::ParmTypeMask
static constexpr uint32_t ParmTypeMask
Definition: XCOFF.h:379
llvm::XCOFF::TracebackTable::ParmTypeIsDoubleBits
static constexpr uint32_t ParmTypeIsDoubleBits
Definition: XCOFF.h:378
uint32_t
llvm::XCOFF::R_TOC
@ R_TOC
Relative to the TOC relocation. Provides a displacement that is the difference between the address of...
Definition: XCOFF.h:215
LANG_CASE
#define LANG_CASE(A)
Definition: XCOFF.cpp:83
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::XCOFF::R_BR
@ R_BR
Branch relative to self relocation. Provides the displacement that is the difference between the addr...
Definition: XCOFF.h:241
llvm::XCOFF::R_REL
@ R_REL
Relative to self relocation. Provides a displacement value between the address of the referenced symb...
Definition: XCOFF.h:211
llvm::XCOFF::TracebackTable::ParmTypeIsFixedBits
static constexpr uint32_t ParmTypeIsFixedBits
Definition: XCOFF.h:375
llvm::XCOFF::R_BA
@ R_BA
Branch absolute relocation. Provides the address of the referenced symbol. References a non-modifiabl...
Definition: XCOFF.h:239
llvm::XCOFF::RelocationType
RelocationType
Definition: XCOFF.h:203
llvm::XCOFF::getRelocationTypeString
StringRef getRelocationTypeString(XCOFF::RelocationType Type)
Definition: XCOFF.cpp:53
llvm::codeview::Cobol
@ Cobol
Definition: CodeView.h:153
llvm::XCOFF::R_TOCL
@ R_TOCL
Relative to TOC lower. Specifies the low-order 16 bits of a large code model TOC-relative relocation.
Definition: XCOFF.h:260
llvm::XCOFF::getNameForTracebackTableLanguageId
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId)
Definition: XCOFF.cpp:87
llvm::XCOFF::TracebackTable::ParmTypeIsVectorShortBit
static constexpr uint32_t ParmTypeIsVectorShortBit
Definition: XCOFF.h:392
llvm::XCOFF::TB_LONGTBTABLE2
@ TB_LONGTBTABLE2
Additional tbtable extension exists.
Definition: XCOFF.h:406
llvm::OutputFileType::Assembly
@ Assembly
llvm::XCOFF::R_TCL
@ R_TCL
Local object TOC address relocation. Provides the address of the local TOC entry of a defined externa...
Definition: XCOFF.h:231
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::XCOFF::TB_RESERVED
@ TB_RESERVED
Reserved for compiler.
Definition: XCOFF.h:402
llvm::XCOFF::R_TLSM
@ R_TLSM
Module reference to TLS. Provides a handle for the module containing the referenced symbol.
Definition: XCOFF.h:254