clang 24.0.0git
CIRCXXABI.h
Go to the documentation of this file.
1//===----- CIRCXXABI.h - Interface to C++ ABIs for CIR Dialect --*- 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//
9// This file partially mimics the CodeGen/CGCXXABI.h class. The main difference
10// is that this is adapted to operate on the CIR dialect.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRCXXABI_H
15#define CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRCXXABI_H
16
17#include "mlir/Transforms/DialectConversion.h"
18#include "clang/AST/CharUnits.h"
22
23namespace cir {
24
25// Forward declarations.
26class LowerModule;
27
28class CIRCXXABI {
29 friend class LowerModule;
30
31protected:
33
35
36 unsigned getPtrSizeInBits() const;
37
38public:
39 virtual ~CIRCXXABI();
40
41 /// Lower the given data member pointer type to its ABI type. The returned
42 /// type is also a CIR type.
43 virtual mlir::Type
44 lowerDataMemberType(cir::DataMemberType type,
45 const mlir::TypeConverter &typeConverter) const = 0;
46
47 /// Lower the given member function pointer type to its ABI type. The returned
48 /// type is also a CIR type.
49 virtual mlir::Type
50 lowerMethodType(cir::MethodType type,
51 const mlir::TypeConverter &typeConverter) const = 0;
52
53 /// Lower the given data member pointer constant to a constant of the ABI
54 /// type. The returned constant is represented as an attribute as well.
55 virtual mlir::TypedAttr
56 lowerDataMemberConstant(cir::DataMemberAttr attr,
57 const mlir::DataLayout &layout,
58 const mlir::TypeConverter &typeConverter) const = 0;
59
60 /// Lower the given by-offset data member pointer constant (used for members
61 /// with no CIR field index, e.g. no_unique_address empty fields) to a
62 /// constant of the ABI type.
63 virtual mlir::TypedAttr lowerDataMemberOffsetConstant(
64 cir::DataMemberOffsetAttr attr, const mlir::DataLayout &layout,
65 const mlir::TypeConverter &typeConverter) const = 0;
66
67 /// Lower the given member function pointer constant to a constant of the ABI
68 /// type. The returned constant is represented as an attribute as well.
69 virtual mlir::TypedAttr
70 lowerMethodConstant(cir::MethodAttr attr, const mlir::DataLayout &layout,
71 const mlir::TypeConverter &typeConverter) const = 0;
72
73 /// Lower the given cir.get_runtime_member op to a sequence of more
74 /// "primitive" CIR operations that act on the ABI types.
75 virtual mlir::Operation *
76 lowerGetRuntimeMember(cir::GetRuntimeMemberOp op, mlir::Type loweredResultTy,
77 mlir::Value loweredAddr, mlir::Value loweredMember,
78 mlir::OpBuilder &builder) const = 0;
79
80 /// Lower the given cir.get_method op to a sequence of more "primitive" CIR
81 /// operations that act on the ABI types. The lowered result values will be
82 /// stored in the given loweredResults array.
83 virtual void
84 lowerGetMethod(cir::GetMethodOp op, mlir::Value &callee, mlir::Value &thisArg,
85 mlir::Value loweredMethod, mlir::Value loweredObjectPtr,
86 mlir::ConversionPatternRewriter &rewriter) const = 0;
87
88 /// Lower the given cir.base_data_member op to a sequence of more "primitive"
89 /// CIR operations that act on the ABI types.
90 virtual mlir::Value lowerBaseDataMember(cir::BaseDataMemberOp op,
91 mlir::Value loweredSrc,
92 mlir::OpBuilder &builder) const = 0;
93
94 /// Lower the given cir.derived_data_member op to a sequence of more
95 /// "primitive" CIR operations that act on the ABI types.
96 virtual mlir::Value
97 lowerDerivedDataMember(cir::DerivedDataMemberOp op, mlir::Value loweredSrc,
98 mlir::OpBuilder &builder) const = 0;
99
100 virtual mlir::Value lowerBaseMethod(cir::BaseMethodOp op,
101 mlir::Value loweredSrc,
102 mlir::OpBuilder &builder) const = 0;
103
104 virtual mlir::Value lowerDerivedMethod(cir::DerivedMethodOp op,
105 mlir::Value loweredSrc,
106 mlir::OpBuilder &builder) const = 0;
107
108 virtual mlir::Value lowerDataMemberCmp(cir::CmpOp op, mlir::Value loweredLhs,
109 mlir::Value loweredRhs,
110 mlir::OpBuilder &builder) const = 0;
111
112 virtual mlir::Value lowerMethodCmp(cir::CmpOp op, mlir::Value loweredLhs,
113 mlir::Value loweredRhs,
114 mlir::OpBuilder &builder) const = 0;
115
116 virtual mlir::Value
117 lowerDataMemberBitcast(cir::CastOp op, mlir::Type loweredDstTy,
118 mlir::Value loweredSrc,
119 mlir::OpBuilder &builder) const = 0;
120
121 virtual mlir::Value
122 lowerDataMemberToBoolCast(cir::CastOp op, mlir::Value loweredSrc,
123 mlir::OpBuilder &builder) const = 0;
124
125 virtual mlir::Value lowerMethodBitcast(cir::CastOp op,
126 mlir::Type loweredDstTy,
127 mlir::Value loweredSrc,
128 mlir::OpBuilder &builder) const = 0;
129
130 virtual mlir::Value lowerMethodToBoolCast(cir::CastOp op,
131 mlir::Value loweredSrc,
132 mlir::OpBuilder &builder) const = 0;
133
134 virtual mlir::Value lowerDynamicCast(cir::DynamicCastOp op,
135 mlir::OpBuilder &builder) const = 0;
136
137 virtual mlir::Value
138 lowerVTableGetTypeInfo(cir::VTableGetTypeInfoOp op,
139 mlir::OpBuilder &builder) const = 0;
140
141 /// Read the array cookie for a dynamically-allocated array whose first
142 /// element is at \p elementPtr. Returns the number of elements, the
143 /// original allocation pointer (before the cookie) as a void*, and the
144 /// cookie size in bytes. Delegates to getArrayCookieSizeImpl and
145 /// readArrayCookieImpl.
146 void readArrayCookie(mlir::Location loc, mlir::Value elementPtr,
147 const mlir::DataLayout &dataLayout,
148 CIRBaseBuilderTy &builder, mlir::Value &numElements,
149 mlir::Value &allocPtr,
150 clang::CharUnits &cookieSize) const;
151
152protected:
153 /// Returns the cookie size in bytes for a dynamically-allocated array of
154 /// elements with the given type. Only called when a cookie is required.
155 virtual clang::CharUnits
156 getArrayCookieSizeImpl(mlir::Type elementType,
157 const mlir::DataLayout &dataLayout) const = 0;
158
159 /// Reads the element count from an array cookie. \p allocPtr is a byte
160 /// pointer to the start of the allocation (the beginning of the cookie).
161 /// \p cookieSize is the value returned by getArrayCookieSizeImpl.
162 /// \p cookieAlignment is the alignment at the cookie start, derived from
163 /// the element type's ABI alignment.
164 virtual mlir::Value readArrayCookieImpl(mlir::Location loc,
165 mlir::Value allocPtr,
166 clang::CharUnits cookieSize,
167 clang::CharUnits cookieAlignment,
168 const mlir::DataLayout &dataLayout,
169 CIRBaseBuilderTy &builder) const = 0;
170};
171
172/// Creates an Itanium-family ABI.
173std::unique_ptr<CIRCXXABI> createItaniumCXXABI(LowerModule &lm);
174
175} // namespace cir
176
177#endif // CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRCXXABI_H
virtual mlir::Value lowerDynamicCast(cir::DynamicCastOp op, mlir::OpBuilder &builder) const =0
virtual clang::CharUnits getArrayCookieSizeImpl(mlir::Type elementType, const mlir::DataLayout &dataLayout) const =0
Returns the cookie size in bytes for a dynamically-allocated array of elements with the given type.
virtual ~CIRCXXABI()
Definition CIRCXXABI.cpp:19
virtual mlir::Type lowerMethodType(cir::MethodType type, const mlir::TypeConverter &typeConverter) const =0
Lower the given member function pointer type to its ABI type.
void readArrayCookie(mlir::Location loc, mlir::Value elementPtr, const mlir::DataLayout &dataLayout, CIRBaseBuilderTy &builder, mlir::Value &numElements, mlir::Value &allocPtr, clang::CharUnits &cookieSize) const
Read the array cookie for a dynamically-allocated array whose first element is at elementPtr.
Definition CIRCXXABI.cpp:25
virtual void lowerGetMethod(cir::GetMethodOp op, mlir::Value &callee, mlir::Value &thisArg, mlir::Value loweredMethod, mlir::Value loweredObjectPtr, mlir::ConversionPatternRewriter &rewriter) const =0
Lower the given cir.get_method op to a sequence of more "primitive" CIR operations that act on the AB...
virtual mlir::Value lowerDataMemberBitcast(cir::CastOp op, mlir::Type loweredDstTy, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
virtual mlir::Operation * lowerGetRuntimeMember(cir::GetRuntimeMemberOp op, mlir::Type loweredResultTy, mlir::Value loweredAddr, mlir::Value loweredMember, mlir::OpBuilder &builder) const =0
Lower the given cir.get_runtime_member op to a sequence of more "primitive" CIR operations that act o...
virtual mlir::Value lowerMethodToBoolCast(cir::CastOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
virtual mlir::Value lowerDataMemberCmp(cir::CmpOp op, mlir::Value loweredLhs, mlir::Value loweredRhs, mlir::OpBuilder &builder) const =0
virtual mlir::TypedAttr lowerDataMemberConstant(cir::DataMemberAttr attr, const mlir::DataLayout &layout, const mlir::TypeConverter &typeConverter) const =0
Lower the given data member pointer constant to a constant of the ABI type.
virtual mlir::Value lowerDataMemberToBoolCast(cir::CastOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
CIRCXXABI(LowerModule &lm)
Definition CIRCXXABI.h:34
LowerModule & lm
Definition CIRCXXABI.h:32
virtual mlir::TypedAttr lowerDataMemberOffsetConstant(cir::DataMemberOffsetAttr attr, const mlir::DataLayout &layout, const mlir::TypeConverter &typeConverter) const =0
Lower the given by-offset data member pointer constant (used for members with no CIR field index,...
virtual mlir::Value readArrayCookieImpl(mlir::Location loc, mlir::Value allocPtr, clang::CharUnits cookieSize, clang::CharUnits cookieAlignment, const mlir::DataLayout &dataLayout, CIRBaseBuilderTy &builder) const =0
Reads the element count from an array cookie.
unsigned getPtrSizeInBits() const
Definition CIRCXXABI.cpp:21
virtual mlir::Value lowerBaseMethod(cir::BaseMethodOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
virtual mlir::Value lowerDerivedMethod(cir::DerivedMethodOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
virtual mlir::Value lowerBaseDataMember(cir::BaseDataMemberOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
Lower the given cir.base_data_member op to a sequence of more "primitive" CIR operations that act on ...
friend class LowerModule
Definition CIRCXXABI.h:29
virtual mlir::TypedAttr lowerMethodConstant(cir::MethodAttr attr, const mlir::DataLayout &layout, const mlir::TypeConverter &typeConverter) const =0
Lower the given member function pointer constant to a constant of the ABI type.
virtual mlir::Value lowerMethodCmp(cir::CmpOp op, mlir::Value loweredLhs, mlir::Value loweredRhs, mlir::OpBuilder &builder) const =0
virtual mlir::Value lowerMethodBitcast(cir::CastOp op, mlir::Type loweredDstTy, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
virtual mlir::Value lowerVTableGetTypeInfo(cir::VTableGetTypeInfoOp op, mlir::OpBuilder &builder) const =0
virtual mlir::Type lowerDataMemberType(cir::DataMemberType type, const mlir::TypeConverter &typeConverter) const =0
Lower the given data member pointer type to its ABI type.
virtual mlir::Value lowerDerivedDataMember(cir::DerivedDataMemberOp op, mlir::Value loweredSrc, mlir::OpBuilder &builder) const =0
Lower the given cir.derived_data_member op to a sequence of more "primitive" CIR operations that act ...
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
std::unique_ptr< CIRCXXABI > createItaniumCXXABI(LowerModule &lm)
Creates an Itanium-family ABI.