LLVM  16.0.0git
NativeTypeFunctionSig.cpp
Go to the documentation of this file.
1 //===- NativeTypeFunctionSig.cpp - info about function signature -*- 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 
17 
18 using namespace llvm;
19 using namespace llvm::codeview;
20 using namespace llvm::pdb;
21 
22 namespace {
23 // This is kind of a silly class, hence why we keep it private to the file.
24 // It's only purpose is to wrap the real type record. I guess this is so that
25 // we can have the lexical parent point to the function instead of the global
26 // scope.
27 class NativeTypeFunctionArg : public NativeRawSymbol {
28 public:
29  NativeTypeFunctionArg(NativeSession &Session,
30  std::unique_ptr<PDBSymbol> RealType)
31  : NativeRawSymbol(Session, PDB_SymType::FunctionArg, 0),
32  RealType(std::move(RealType)) {}
33 
34  void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields,
35  PdbSymbolIdField RecurseIdFields) const override {
36  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
37 
38  dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
39  PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
40  }
41 
42  SymIndexId getTypeId() const override { return RealType->getSymIndexId(); }
43 
44  std::unique_ptr<PDBSymbol> RealType;
45 };
46 
47 class NativeEnumFunctionArgs : public IPDBEnumChildren<PDBSymbol> {
48 public:
49  NativeEnumFunctionArgs(NativeSession &Session,
50  std::unique_ptr<NativeEnumTypes> TypeEnumerator)
51  : Session(Session), TypeEnumerator(std::move(TypeEnumerator)) {}
52 
53  uint32_t getChildCount() const override {
54  return TypeEnumerator->getChildCount();
55  }
56  std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override {
57  return wrap(TypeEnumerator->getChildAtIndex(Index));
58  }
59  std::unique_ptr<PDBSymbol> getNext() override {
60  return wrap(TypeEnumerator->getNext());
61  }
62 
63  void reset() override { TypeEnumerator->reset(); }
64 
65 private:
66  std::unique_ptr<PDBSymbol> wrap(std::unique_ptr<PDBSymbol> S) const {
67  if (!S)
68  return nullptr;
69  auto NTFA = std::make_unique<NativeTypeFunctionArg>(Session, std::move(S));
70  return PDBSymbol::create(Session, std::move(NTFA));
71  }
72  NativeSession &Session;
73  std::unique_ptr<NativeEnumTypes> TypeEnumerator;
74 };
75 } // namespace
76 
77 NativeTypeFunctionSig::NativeTypeFunctionSig(NativeSession &Session,
78  SymIndexId Id,
82  Proc(std::move(Proc)), Index(Index), IsMemberFunction(false) {}
83 
88  MemberFunc(std::move(MemberFunc)), Index(Index), IsMemberFunction(true) {}
89 
91  if (IsMemberFunction) {
92  ClassParentId =
94  initializeArgList(MemberFunc.ArgumentList);
95  } else {
96  initializeArgList(Proc.ArgumentList);
97  }
98 }
99 
101 
102 void NativeTypeFunctionSig::initializeArgList(codeview::TypeIndex ArgListTI) {
104  CVType CVT = Tpi.typeCollection().getType(ArgListTI);
105 
106  cantFail(TypeDeserializer::deserializeAs<ArgListRecord>(CVT, ArgList));
107 }
108 
110  PdbSymbolIdField ShowIdFields,
111  PdbSymbolIdField RecurseIdFields) const {
112 
113  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
114 
115  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
116  PdbSymbolIdField::LexicalParent, ShowIdFields,
117  RecurseIdFields);
118 
119  dumpSymbolField(OS, "callingConvention", getCallingConvention(), Indent);
120  dumpSymbolField(OS, "count", getCount(), Indent);
121  dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
122  PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
123  if (IsMemberFunction)
124  dumpSymbolField(OS, "thisAdjust", getThisAdjust(), Indent);
125  dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
126  dumpSymbolField(OS, "constType", isConstType(), Indent);
127  dumpSymbolField(OS, "isConstructorVirtualBase", isConstructorVirtualBase(),
128  Indent);
129  dumpSymbolField(OS, "isCxxReturnUdt", isCxxReturnUdt(), Indent);
130  dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
131  dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
132 }
133 
134 std::unique_ptr<IPDBEnumSymbols>
137  return std::make_unique<NullEnumerator<PDBSymbol>>();
138 
139  auto NET = std::make_unique<NativeEnumTypes>(Session,
140  /* copy */ ArgList.ArgIndices);
141  return std::unique_ptr<IPDBEnumSymbols>(
142  new NativeEnumFunctionArgs(Session, std::move(NET)));
143 }
144 
146  if (!IsMemberFunction)
147  return 0;
148 
149  return ClassParentId;
150 }
151 
153  return IsMemberFunction ? MemberFunc.CallConv : Proc.CallConv;
154 }
155 
157  return IsMemberFunction ? (1 + MemberFunc.getParameterCount())
159 }
160 
162  TypeIndex ReturnTI =
163  IsMemberFunction ? MemberFunc.getReturnType() : Proc.getReturnType();
164 
166  return Result;
167 }
168 
170  return IsMemberFunction ? MemberFunc.getThisPointerAdjustment() : 0;
171 }
172 
174  if (!IsMemberFunction)
175  return false;
176 
177  return (MemberFunc.getOptions() & FunctionOptions::Constructor) !=
179 }
180 
181 bool NativeTypeFunctionSig::isConstType() const { return false; }
182 
184  if (!IsMemberFunction)
185  return false;
186 
187  return (MemberFunc.getOptions() &
188  FunctionOptions::ConstructorWithVirtualBases) !=
190 }
191 
194  IsMemberFunction ? MemberFunc.getOptions() : Proc.getOptions();
195  return (Options & FunctionOptions::CxxReturnUdt) != FunctionOptions::None;
196 }
197 
198 bool NativeTypeFunctionSig::isUnalignedType() const { return false; }
199 
200 bool NativeTypeFunctionSig::isVolatileType() const { return false; }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::codeview::MemberFunctionRecord::CallConv
CallingConvention CallConv
Definition: TypeRecord.h:198
llvm::pdb::PDB_SymType::FunctionSig
@ FunctionSig
TpiStream.h
llvm::pdb::NativeTypeFunctionSig::NativeTypeFunctionSig
NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ProcedureRecord Proc)
Definition: NativeTypeFunctionSig.cpp:77
llvm::codeview::FunctionOptions
FunctionOptions
Definition: CodeView.h:246
llvm::pdb::NativeTypeFunctionSig::isConstructorVirtualBase
bool isConstructorVirtualBase() const override
Definition: NativeTypeFunctionSig.cpp:183
llvm::pdb::NativeSession::getPDBFile
PDBFile & getPDBFile()
Definition: NativeSession.h:109
llvm::pdb::PdbSymbolIdField::Type
@ Type
llvm::pdb::NativeTypeFunctionSig::initialize
void initialize() override
Definition: NativeTypeFunctionSig.cpp:90
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1793
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::codeview::ProcedureRecord::getOptions
FunctionOptions getOptions() const
Definition: TypeRecord.h:159
llvm::pdb::NativeTypeFunctionSig::MemberFunc
codeview::MemberFunctionRecord MemberFunc
Definition: NativeTypeFunctionSig.h:57
llvm::dump
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Definition: SparseBitVector.h:877
llvm::pdb::NativeTypeFunctionSig::getCallingConvention
PDB_CallingConv getCallingConvention() const override
Definition: NativeTypeFunctionSig.cpp:152
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::codeview::ProcedureRecord::getReturnType
TypeIndex getReturnType() const
Definition: TypeRecord.h:157
llvm::pdb::NativeTypeFunctionSig::isUnalignedType
bool isUnalignedType() const override
Definition: NativeTypeFunctionSig.cpp:198
llvm::codeview::MemberFunctionRecord::getReturnType
TypeIndex getReturnType() const
Definition: TypeRecord.h:186
llvm::pdb::SymIndexId
uint32_t SymIndexId
Definition: PDBTypes.h:26
LazyRandomTypeCollection.h
llvm::pdb::NativeTypeFunctionSig::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeTypeFunctionSig.cpp:109
llvm::pdb::NativeTypeFunctionSig::getThisAdjust
int32_t getThisAdjust() const override
Definition: NativeTypeFunctionSig.cpp:169
llvm::pdb::PDB_SymType::FunctionArg
@ FunctionArg
llvm::pdb::PdbSymbolIdField::LexicalParent
@ LexicalParent
NativeTypeFunctionSig.h
llvm::codeview::MemberFunctionRecord::ClassType
TypeIndex ClassType
Definition: TypeRecord.h:196
false
Definition: StackSlotColoring.cpp:141
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::codeview::MemberFunctionRecord
Definition: TypeRecord.h:171
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::NativeTypeFunctionSig::Proc
codeview::ProcedureRecord Proc
Definition: NativeTypeFunctionSig.h:58
llvm::pdb::NativeTypeFunctionSig::findChildren
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const override
Definition: NativeTypeFunctionSig.cpp:135
llvm::codeview::ProcedureRecord::ArgumentList
TypeIndex ArgumentList
Definition: TypeRecord.h:167
llvm::pdb::NativeTypeFunctionSig::hasConstructor
bool hasConstructor() const override
Definition: NativeTypeFunctionSig.cpp:173
llvm::codeview::MemberFunctionRecord::getThisPointerAdjustment
int32_t getThisPointerAdjustment() const
Definition: TypeRecord.h:193
llvm::pdb::NativeTypeFunctionSig::~NativeTypeFunctionSig
~NativeTypeFunctionSig() override
llvm::pdb::dumpSymbolField
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
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::pdb::dumpSymbolIdField
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:113
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1861
llvm::codeview::ProcedureRecord::getParameterCount
uint16_t getParameterCount() const
Definition: TypeRecord.h:160
NativeEnumTypes.h
llvm::pdb::NativeTypeFunctionSig::isConstType
bool isConstType() const override
Definition: NativeTypeFunctionSig.cpp:181
llvm::codeview::ArgListRecord::ArgIndices
std::vector< TypeIndex > ArgIndices
Definition: TypeRecord.h:246
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:279
llvm::codeview::CVRecord< TypeLeafKind >
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:744
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::pdb::NativeTypeFunctionSig::isCxxReturnUdt
bool isCxxReturnUdt() const override
Definition: NativeTypeFunctionSig.cpp:192
llvm::codeview::ProcedureRecord
Definition: TypeRecord.h:146
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:301
llvm::pdb::NativeTypeFunctionSig::getCount
uint32_t getCount() const override
Definition: NativeTypeFunctionSig.cpp:156
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:158
std
Definition: BitVector.h:851
llvm::None
constexpr std::nullopt_t None
Definition: None.h:27
llvm::codeview::MemberFunctionRecord::getParameterCount
uint16_t getParameterCount() const
Definition: TypeRecord.h:191
llvm::codeview::ProcedureRecord::CallConv
CallingConvention CallConv
Definition: TypeRecord.h:164
llvm::pdb::NativeTypeFunctionSig::getClassParentId
SymIndexId getClassParentId() const override
Definition: NativeTypeFunctionSig.cpp:145
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:21
llvm::pdb::NativeSession
Definition: NativeSession.h:32
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
PDBFile.h
PDBExtras.h
llvm::pdb::TpiStream
Definition: TpiStream.h:34
llvm::codeview::CallingConvention
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:175
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::msgpack::Type
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
llvm::pdb::NativeTypeFunctionSig::isVolatileType
bool isVolatileType() const override
Definition: NativeTypeFunctionSig.cpp:200
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::pdb::IPDBEnumChildren
Definition: IPDBEnumChildren.h:20
llvm::codeview::LazyRandomTypeCollection::getType
CVType getType(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:91
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:241
llvm::codeview::MemberFunctionRecord::ArgumentList
TypeIndex ArgumentList
Definition: TypeRecord.h:201
llvm::pdb::TpiStream::typeCollection
codeview::LazyRandomTypeCollection & typeCollection()
Definition: TpiStream.h:59
llvm::pdb::NativeTypeFunctionSig::getTypeId
SymIndexId getTypeId() const override
Definition: NativeTypeFunctionSig.cpp:161
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
llvm::codeview::MemberFunctionRecord::getOptions
FunctionOptions getOptions() const
Definition: TypeRecord.h:190
NativeSession.h