1 //===----- ABI.h - ABI related declarations ---------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Enums/classes describing ABI related information about constructors,
11 /// destructors and thunks.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_ABI_H
16 #define LLVM_CLANG_BASIC_ABI_H
18 #include "llvm/Support/DataTypes.h"
23 /// C++ constructor types.
25 Ctor_Complete, ///< Complete object ctor
26 Ctor_Base, ///< Base object ctor
27 Ctor_Comdat, ///< The COMDAT used for ctors
28 Ctor_CopyingClosure, ///< Copying closure variant of a ctor
29 Ctor_DefaultClosure, ///< Default closure variant of a ctor
32 /// C++ destructor types.
34 Dtor_Deleting, ///< Deleting dtor
35 Dtor_Complete, ///< Complete object dtor
36 Dtor_Base, ///< Base object dtor
37 Dtor_Comdat ///< The COMDAT used for dtors
40 /// A return adjustment.
41 struct ReturnAdjustment {
42 /// The non-virtual adjustment from the derived object to its
43 /// nearest virtual base.
46 /// Holds the ABI-specific information about the virtual return
47 /// adjustment, if needed.
48 union VirtualAdjustment {
51 /// The offset (in bytes), relative to the address point
52 /// of the virtual base class offset.
53 int64_t VBaseOffsetOffset;
58 /// The offset (in bytes) of the vbptr, relative to the beginning
59 /// of the derived class.
62 /// Index of the virtual base in the vbtable.
67 memset(this, 0, sizeof(*this));
70 bool Equals(const VirtualAdjustment &Other) const {
71 return memcmp(this, &Other, sizeof(Other)) == 0;
74 bool isEmpty() const {
75 VirtualAdjustment Zero;
79 bool Less(const VirtualAdjustment &RHS) const {
80 return memcmp(this, &RHS, sizeof(RHS)) < 0;
84 ReturnAdjustment() : NonVirtual(0) {}
86 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
88 friend bool operator==(const ReturnAdjustment &LHS,
89 const ReturnAdjustment &RHS) {
90 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
93 friend bool operator!=(const ReturnAdjustment &LHS, const ReturnAdjustment &RHS) {
97 friend bool operator<(const ReturnAdjustment &LHS,
98 const ReturnAdjustment &RHS) {
99 if (LHS.NonVirtual < RHS.NonVirtual)
102 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
106 /// A \c this pointer adjustment.
107 struct ThisAdjustment {
108 /// The non-virtual adjustment from the derived object to its
109 /// nearest virtual base.
112 /// Holds the ABI-specific information about the virtual this
113 /// adjustment, if needed.
114 union VirtualAdjustment {
117 /// The offset (in bytes), relative to the address point,
118 /// of the virtual call offset.
119 int64_t VCallOffsetOffset;
123 /// The offset of the vtordisp (in bytes), relative to the ECX.
124 int32_t VtordispOffset;
126 /// The offset of the vbptr of the derived class (in bytes),
127 /// relative to the ECX after vtordisp adjustment.
130 /// The offset (in bytes) of the vbase offset in the vbtable.
131 int32_t VBOffsetOffset;
134 VirtualAdjustment() {
135 memset(this, 0, sizeof(*this));
138 bool Equals(const VirtualAdjustment &Other) const {
139 return memcmp(this, &Other, sizeof(Other)) == 0;
142 bool isEmpty() const {
143 VirtualAdjustment Zero;
147 bool Less(const VirtualAdjustment &RHS) const {
148 return memcmp(this, &RHS, sizeof(RHS)) < 0;
152 ThisAdjustment() : NonVirtual(0) { }
154 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
156 friend bool operator==(const ThisAdjustment &LHS,
157 const ThisAdjustment &RHS) {
158 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
161 friend bool operator!=(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
162 return !(LHS == RHS);
165 friend bool operator<(const ThisAdjustment &LHS,
166 const ThisAdjustment &RHS) {
167 if (LHS.NonVirtual < RHS.NonVirtual)
170 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
176 /// The \c this pointer adjustment as well as an optional return
177 /// adjustment for a thunk.
179 /// The \c this pointer adjustment.
182 /// The return adjustment.
183 ReturnAdjustment Return;
185 /// Holds a pointer to the overridden method this thunk is for,
186 /// if needed by the ABI to distinguish different thunks with equal
187 /// adjustments. Otherwise, null.
188 /// CAUTION: In the unlikely event you need to sort ThunkInfos, consider using
189 /// an ABI-specific comparator.
190 const CXXMethodDecl *Method;
192 ThunkInfo() : Method(nullptr) { }
194 ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
195 const CXXMethodDecl *Method = nullptr)
196 : This(This), Return(Return), Method(Method) {}
198 friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
199 return LHS.This == RHS.This && LHS.Return == RHS.Return &&
200 LHS.Method == RHS.Method;
203 bool isEmpty() const {
204 return This.isEmpty() && Return.isEmpty() && Method == nullptr;
208 } // end namespace clang