LLVM  16.0.0git
TypeRecordHelpers.cpp
Go to the documentation of this file.
1 //===- TypeRecordHelpers.cpp ------------------------------------*- 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 
11 #include "llvm/ADT/SmallVector.h"
14 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 
18 template <typename RecordT> static ClassOptions getUdtOptions(CVType CVT) {
19  RecordT Record;
20  if (auto EC = TypeDeserializer::deserializeAs<RecordT>(CVT, Record)) {
22  return ClassOptions::None;
23  }
24  return Record.getOptions();
25 }
26 
28  ClassOptions UdtOptions = ClassOptions::None;
29  switch (CVT.kind()) {
30  case LF_STRUCTURE:
31  case LF_CLASS:
32  case LF_INTERFACE:
33  UdtOptions = getUdtOptions<ClassRecord>(std::move(CVT));
34  break;
35  case LF_ENUM:
36  UdtOptions = getUdtOptions<EnumRecord>(std::move(CVT));
37  break;
38  case LF_UNION:
39  UdtOptions = getUdtOptions<UnionRecord>(std::move(CVT));
40  break;
41  default:
42  return false;
43  }
44  return (UdtOptions & ClassOptions::ForwardReference) != ClassOptions::None;
45 }
46 
48  assert(CVT.kind() == LF_MODIFIER);
50  discoverTypeIndices(CVT, Refs);
51  return Refs.front();
52 }
53 
55  if (!TI.isSimple())
56  return 0;
58  // We have a native pointer.
59  switch (TI.getSimpleMode()) {
63  return 2;
66  return 4;
68  return 8;
70  return 16;
71  default:
72  assert(false && "invalid simple type mode!");
73  }
74  }
75  switch (TI.getSimpleKind()) {
78  return 0;
80  return 4;
83  return 1;
84 
85  // Signed/unsigned integer.
90  return 2;
95  return 4;
100  return 8;
105  return 16;
106 
107  // Signed/Unsigned character.
112  return 1;
115  return 2;
117  return 4;
118 
119  // Float.
121  return 2;
123  return 4;
125  return 6;
127  return 8;
129  return 10;
131  return 16;
132 
133  // Boolean.
135  return 1;
137  return 2;
139  return 4;
141  return 8;
143  return 16;
144 
145  // Complex float.
147  return 2;
149  return 4;
151  return 8;
153  return 10;
155  return 16;
156 
157  default:
158  return 0;
159  }
160 }
161 
162 template <typename RecordT> static uint64_t getUdtSize(CVType CVT) {
163  RecordT Record;
164  if (auto EC = TypeDeserializer::deserializeAs<RecordT>(CVT, Record)) {
166  return 0;
167  }
168  return Record.getSize();
169 }
170 
172  switch (CVT.kind()) {
173  case LF_STRUCTURE:
174  case LF_CLASS:
175  case LF_INTERFACE:
176  return getUdtSize<ClassRecord>(std::move(CVT));
177  case LF_UNION:
178  return getUdtSize<UnionRecord>(std::move(CVT));
179  default:
180  return CVT.length();
181  }
182 }
llvm::codeview::SimpleTypeKind::Byte
@ Byte
llvm::codeview::ClassOptions::ForwardReference
@ ForwardReference
llvm::codeview::SimpleTypeMode::NearPointer32
@ NearPointer32
llvm::codeview::SimpleTypeKind::Complex128
@ Complex128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::codeview::SimpleTypeKind::Int32
@ Int32
llvm::codeview::SimpleTypeKind::Int64Quad
@ Int64Quad
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::codeview::SimpleTypeKind::UInt64Quad
@ UInt64Quad
llvm::codeview::SimpleTypeKind::Complex64
@ Complex64
llvm::codeview::SimpleTypeKind::Complex80
@ Complex80
llvm::codeview::isUdtForwardRef
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
Definition: TypeRecordHelpers.cpp:27
llvm::codeview::SimpleTypeKind::Float80
@ Float80
llvm::codeview::SimpleTypeKind::NarrowCharacter
@ NarrowCharacter
llvm::codeview::SimpleTypeKind::Boolean8
@ Boolean8
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1042
llvm::codeview::SimpleTypeKind::None
@ None
llvm::codeview::SimpleTypeMode::NearPointer
@ NearPointer
llvm::codeview::SimpleTypeKind::Boolean128
@ Boolean128
llvm::codeview::getModifiedType
TypeIndex getModifiedType(const CVType &CVT)
Given a CVType which is assumed to be an LF_MODIFIER, return the TypeIndex of the type that the LF_MO...
Definition: TypeRecordHelpers.cpp:47
llvm::codeview::SimpleTypeMode::Direct
@ Direct
llvm::codeview::getSizeInBytesForTypeIndex
uint64_t getSizeInBytesForTypeIndex(TypeIndex TI)
Given an arbitrary codeview type index, determine its size.
Definition: TypeRecordHelpers.cpp:54
llvm::codeview::SimpleTypeKind::Boolean32
@ Boolean32
llvm::codeview::SimpleTypeKind::Boolean16
@ Boolean16
llvm::codeview::SimpleTypeKind::Int16Short
@ Int16Short
llvm::codeview::SimpleTypeKind::Int128
@ Int128
llvm::codeview::ClassOptions::None
@ None
llvm::codeview::SimpleTypeKind::Complex32
@ Complex32
getUdtOptions
static ClassOptions getUdtOptions(CVType CVT)
Definition: TypeRecordHelpers.cpp:18
llvm::codeview::SimpleTypeKind::UInt32Long
@ UInt32Long
llvm::codeview::ClassOptions
ClassOptions
Definition: CodeView.h:203
llvm::codeview::SimpleTypeKind::Character8
@ Character8
llvm::codeview::TypeIndex::getSimpleKind
SimpleTypeKind getSimpleKind() const
Definition: TypeIndex.h:136
llvm::codeview::SimpleTypeKind::UInt16Short
@ UInt16Short
llvm::codeview::SimpleTypeKind::Float128
@ Float128
uint64_t
llvm::codeview::CVRecord::kind
Kind kind() const
Definition: CVRecord.h:42
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::codeview::SimpleTypeKind::Float64
@ Float64
llvm::codeview::SimpleTypeKind::Void
@ Void
llvm::codeview::SimpleTypeMode::HugePointer
@ HugePointer
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::SimpleTypeKind::Int128Oct
@ Int128Oct
TypeRecordHelpers.h
llvm::codeview::CompileSym2Flags::EC
@ EC
getUdtSize
static uint64_t getUdtSize(CVType CVT)
Definition: TypeRecordHelpers.cpp:162
llvm::Record
Definition: Record.h:1573
llvm::codeview::SimpleTypeKind::Boolean64
@ Boolean64
llvm::codeview::SimpleTypeKind::Int16
@ Int16
llvm::codeview::CVRecord< TypeLeafKind >
llvm::codeview::TypeIndex::getSimpleMode
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:141
llvm::codeview::SimpleTypeKind::Int32Long
@ Int32Long
llvm::codeview::SimpleTypeMode::FarPointer
@ FarPointer
llvm::codeview::SimpleTypeKind::Float16
@ Float16
llvm::codeview::SimpleTypeKind::Float32
@ Float32
llvm::codeview::SimpleTypeMode::NearPointer64
@ NearPointer64
TypeDeserializer.h
llvm::codeview::SimpleTypeKind::UInt128Oct
@ UInt128Oct
llvm::codeview::discoverTypeIndices
void discoverTypeIndices(ArrayRef< uint8_t > RecordData, SmallVectorImpl< TiReference > &Refs)
Definition: TypeIndexDiscovery.cpp:493
llvm::codeview::SimpleTypeKind::Character32
@ Character32
llvm::codeview::SimpleTypeKind::SByte
@ SByte
llvm::codeview::SimpleTypeKind::WideCharacter
@ WideCharacter
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::SimpleTypeKind::UInt16
@ UInt16
llvm::codeview::SimpleTypeKind::UnsignedCharacter
@ UnsignedCharacter
llvm::codeview::getSizeInBytesForTypeRecord
uint64_t getSizeInBytesForTypeRecord(CVType CVT)
Given an arbitrary codeview type, return the type's size in the case of aggregate (LF_STRUCTURE,...
Definition: TypeRecordHelpers.cpp:171
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition: TypeIndex.h:113
llvm::codeview::SimpleTypeKind::Complex16
@ Complex16
SmallVector.h
llvm::codeview::SimpleTypeKind::Float48
@ Float48
llvm::codeview::SimpleTypeKind::Int64
@ Int64
llvm::codeview::SimpleTypeKind::UInt32
@ UInt32
llvm::codeview::SimpleTypeKind::HResult
@ HResult
llvm::codeview::SimpleTypeMode::FarPointer32
@ FarPointer32
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
TypeIndexDiscovery.h
llvm::codeview::SimpleTypeKind::UInt128
@ UInt128
llvm::codeview::SimpleTypeKind::Character16
@ Character16
llvm::codeview::SimpleTypeKind::SignedCharacter
@ SignedCharacter
llvm::codeview::SimpleTypeMode::NearPointer128
@ NearPointer128
llvm::codeview::SimpleTypeKind::UInt64
@ UInt64
llvm::codeview::CVRecord::length
uint32_t length() const
Definition: CVRecord.h:40