27#include "llvm/ADT/iterator.h"
45 assert(RD->isUnion() &&
"RecordType is expected to be a union.");
46 if (
const FieldDecl *FD = RD->findFirstNamedDataMember()) {
47 return FD->getIdentifier();
54struct DecompositionDeclName {
55 using BindingArray = ArrayRef<const BindingDecl*>;
58 BindingArray Bindings;
62 : llvm::iterator_adaptor_base<Iterator, BindingArray::const_iterator,
63 std::random_access_iterator_tag,
64 const IdentifierInfo *> {
65 Iterator(BindingArray::const_iterator It) : iterator_adaptor_base(It) {}
67 return (*this->I)->getIdentifier();
70 Iterator begin()
const {
return Iterator(Bindings.begin()); }
71 Iterator end()
const {
return Iterator(Bindings.end()); }
77struct DenseMapInfo<DecompositionDeclName> {
78 using ArrayInfo = llvm::DenseMapInfo<ArrayRef<const BindingDecl*>>;
80 return llvm::hash_combine_range(Key);
82 static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS) {
83 return LHS.Bindings.size() == RHS.Bindings.size() &&
84 std::equal(LHS.begin(), LHS.end(), RHS.begin());
94 ItaniumMangleContext *Mangler;
95 llvm::StringMap<unsigned> LambdaManglingNumbers;
96 unsigned BlockManglingNumber = 0;
97 llvm::DenseMap<const IdentifierInfo *, unsigned> VarManglingNumbers;
98 llvm::DenseMap<const IdentifierInfo *, unsigned> TagManglingNumbers;
99 llvm::DenseMap<DecompositionDeclName, unsigned>
100 DecompsitionDeclManglingNumbers;
103 ItaniumNumberingContext(ItaniumMangleContext *Mangler) : Mangler(Mangler) {}
105 unsigned getManglingNumber(
const CXXMethodDecl *CallOperator)
override {
106 const CXXRecordDecl *Lambda = CallOperator->
getParent();
111 llvm::SmallString<128> LambdaSig;
112 llvm::raw_svector_ostream
Out(LambdaSig);
113 Mangler->mangleLambdaSig(Lambda, Out);
115 return ++LambdaManglingNumbers[LambdaSig];
118 unsigned getManglingNumber(
const BlockDecl *BD)
override {
119 return ++BlockManglingNumber;
122 unsigned getStaticLocalNumber(
const VarDecl *VD)
override {
127 unsigned getManglingNumber(
const VarDecl *VD,
unsigned)
override {
128 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
129 DecompositionDeclName Name{DD->bindings()};
130 return ++DecompsitionDeclManglingNumbers[Name];
137 Identifier = findAnonymousUnionVarDeclName(*VD);
139 return ++VarManglingNumbers[Identifier];
142 unsigned getManglingNumber(
const TagDecl *TD,
unsigned)
override {
151class ItaniumSYCLNumberingContext :
public ItaniumNumberingContext {
152 llvm::DenseMap<const CXXMethodDecl *, unsigned> ManglingNumbers;
153 using ManglingItr =
decltype(ManglingNumbers)::iterator;
156 ItaniumSYCLNumberingContext(ItaniumMangleContext *Mangler)
157 : ItaniumNumberingContext(Mangler) {}
159 unsigned getManglingNumber(
const CXXMethodDecl *CallOperator)
override {
160 unsigned Number = ItaniumNumberingContext::getManglingNumber(CallOperator);
161 std::pair<ManglingItr, bool> emplace_result =
162 ManglingNumbers.try_emplace(CallOperator, Number);
163 (void)emplace_result;
164 assert(emplace_result.second &&
"Lambda number set multiple times?");
168 using ItaniumNumberingContext::getManglingNumber;
170 unsigned getDeviceManglingNumber(
const CXXMethodDecl *CallOperator)
override {
171 ManglingItr Itr = ManglingNumbers.find(CallOperator);
172 assert(Itr != ManglingNumbers.end() &&
"Lambda not yet mangled?");
178class ItaniumCXXABI :
public CXXABI {
180 std::unique_ptr<MangleContext> Mangler;
184 ItaniumCXXABI(ASTContext &Ctx)
185 : Mangler(Ctx.createMangleContext()), Context(Ctx) {}
188 getMemberPointerInfo(
const MemberPointerType *MPT)
const override {
189 const TargetInfo &
Target = Context.getTargetInfo();
190 TargetInfo::IntType PtrDiff =
Target.getPtrDiffType(LangAS::Default);
191 MemberPointerInfo MPI;
192 MPI.Width =
Target.getTypeWidth(PtrDiff);
193 MPI.Align =
Target.getTypeAlign(PtrDiff);
194 MPI.HasPadding =
false;
200 CallingConv getDefaultMethodCallConv(
bool isVariadic)
const override {
201 const llvm::Triple &T = Context.getTargetInfo().getTriple();
202 if (!isVariadic && T.isWindowsGNUEnvironment() &&
203 T.getArch() == llvm::Triple::x86)
205 return Context.getTargetInfo().getDefaultCallingConv();
210 bool isNearlyEmpty(
const CXXRecordDecl *RD)
const override {
216 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
217 CharUnits PointerSize = Context.toCharUnitsFromBits(
218 Context.getTargetInfo().getPointerWidth(LangAS::Default));
222 const CXXConstructorDecl *
223 getCopyConstructorForExceptionObject(CXXRecordDecl *RD)
override {
227 void addCopyConstructorForExceptionObject(CXXRecordDecl *RD,
228 CXXConstructorDecl *CD)
override {}
230 void addTypedefNameForUnnamedTagDecl(TagDecl *TD,
231 TypedefNameDecl *DD)
override {}
233 TypedefNameDecl *getTypedefNameForUnnamedTagDecl(
const TagDecl *TD)
override {
237 void addDeclaratorForUnnamedTagDecl(TagDecl *TD,
238 DeclaratorDecl *DD)
override {}
240 DeclaratorDecl *getDeclaratorForUnnamedTagDecl(
const TagDecl *TD)
override {
244 std::unique_ptr<MangleNumberingContext>
245 createMangleNumberingContext()
const override {
246 if (Context.getLangOpts().isSYCL())
247 return std::make_unique<ItaniumSYCLNumberingContext>(
249 return std::make_unique<ItaniumNumberingContext>(
256 return new ItaniumCXXABI(Ctx);
259std::unique_ptr<MangleNumberingContext>
261 return std::make_unique<ItaniumNumberingContext>(
Defines the clang::ASTContext interface.
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, clang::CharUnits CU)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
#define CXXABI(Name, Str)
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
Implements C++ ABI-specific semantic analysis functions.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isLambda() const
Determine whether this class describes a lambda function object.
bool isDynamicClass() const
Represents a member of a struct/union/class.
One of these records is kept for each identifier that is lexed.
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
RecordDecl * castAsRecordDecl() const
Represents a variable declaration or definition.
Defines the clang::TargetInfo interface.
@ Number
Just a number, nothing else.
Top level wrappers for InstallAPI frontend operations.
std::unique_ptr< MangleNumberingContext > createItaniumNumberingContext(MangleContext *)
CXXABI * CreateItaniumCXXABI(ASTContext &Ctx)
Creates an instance of a C++ ABI class.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
Diagnostic wrappers for TextAPI types for error reporting.
llvm::DenseMapInfo< ArrayRef< const BindingDecl * > > ArrayInfo
static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS)
static unsigned getHashValue(DecompositionDeclName Key)