clang 23.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 member function pointer constant to a constant of the ABI
61 /// type. The returned constant is represented as an attribute as well.
62 virtual mlir::TypedAttr
63 lowerMethodConstant(cir::MethodAttr attr, const mlir::DataLayout &layout,
64 const mlir::TypeConverter &typeConverter) const = 0;
65
66 /// Lower the given cir.get_runtime_member op to a sequence of more
67 /// "primitive" CIR operations that act on the ABI types.
68 virtual mlir::Operation *
69 lowerGetRuntimeMember(cir::GetRuntimeMemberOp op, mlir::Type loweredResultTy,
70 mlir::Value loweredAddr, mlir::Value loweredMember,
71 mlir::OpBuilder &builder) const = 0;
72
73 /// Lower the given cir.get_method op to a sequence of more "primitive" CIR
74 /// operations that act on the ABI types. The lowered result values will be
75 /// stored in the given loweredResults array.
76 virtual void
77 lowerGetMethod(cir::GetMethodOp op, mlir::Value &callee, mlir::Value &thisArg,
78 mlir::Value loweredMethod, mlir::Value loweredObjectPtr,
79 mlir::ConversionPatternRewriter &rewriter) const = 0;
80
81 /// Lower the given cir.base_data_member op to a sequence of more "primitive"
82 /// CIR operations that act on the ABI types.
83 virtual mlir::Value lowerBaseDataMember(cir::BaseDataMemberOp op,
84 mlir::Value loweredSrc,
85 mlir::OpBuilder &builder) const = 0;
86
87 /// Lower the given cir.derived_data_member op to a sequence of more
88 /// "primitive" CIR operations that act on the ABI types.
89 virtual mlir::Value
90 lowerDerivedDataMember(cir::DerivedDataMemberOp op, mlir::Value loweredSrc,
91 mlir::OpBuilder &builder) const = 0;
92
93 virtual mlir::Value lowerBaseMethod(cir::BaseMethodOp op,
94 mlir::Value loweredSrc,
95 mlir::OpBuilder &builder) const = 0;
96
97 virtual mlir::Value lowerDerivedMethod(cir::DerivedMethodOp op,
98 mlir::Value loweredSrc,
99 mlir::OpBuilder &builder) const = 0;
100
101 virtual mlir::Value lowerDataMemberCmp(cir::CmpOp op, mlir::Value loweredLhs,
102 mlir::Value loweredRhs,
103 mlir::OpBuilder &builder) const = 0;
104
105 virtual mlir::Value lowerMethodCmp(cir::CmpOp op, mlir::Value loweredLhs,
106 mlir::Value loweredRhs,
107 mlir::OpBuilder &builder) const = 0;
108
109 virtual mlir::Value
110 lowerDataMemberBitcast(cir::CastOp op, mlir::Type loweredDstTy,
111 mlir::Value loweredSrc,
112 mlir::OpBuilder &builder) const = 0;
113
114 virtual mlir::Value
115 lowerDataMemberToBoolCast(cir::CastOp op, mlir::Value loweredSrc,
116 mlir::OpBuilder &builder) const = 0;
117
118 virtual mlir::Value lowerMethodBitcast(cir::CastOp op,
119 mlir::Type loweredDstTy,
120 mlir::Value loweredSrc,
121 mlir::OpBuilder &builder) const = 0;
122
123 virtual mlir::Value lowerMethodToBoolCast(cir::CastOp op,
124 mlir::Value loweredSrc,
125 mlir::OpBuilder &builder) const = 0;
126
127 virtual mlir::Value lowerDynamicCast(cir::DynamicCastOp op,
128 mlir::OpBuilder &builder) const = 0;
129
130 virtual mlir::Value
131 lowerVTableGetTypeInfo(cir::VTableGetTypeInfoOp op,
132 mlir::OpBuilder &builder) const = 0;
133
134 /// Read the array cookie for a dynamically-allocated array whose first
135 /// element is at \p elementPtr. Returns the number of elements, the
136 /// original allocation pointer (before the cookie) as a void*, and the
137 /// cookie size in bytes. Delegates to getArrayCookieSizeImpl and
138 /// readArrayCookieImpl.
139 void readArrayCookie(mlir::Location loc, mlir::Value elementPtr,
140 const mlir::DataLayout &dataLayout,
141 CIRBaseBuilderTy &builder, mlir::Value &numElements,
142 mlir::Value &allocPtr,
143 clang::CharUnits &cookieSize) const;
144
145protected:
146 /// Returns the cookie size in bytes for a dynamically-allocated array of
147 /// elements with the given type. Only called when a cookie is required.
148 virtual clang::CharUnits
149 getArrayCookieSizeImpl(mlir::Type elementType,
150 const mlir::DataLayout &dataLayout) const = 0;
151
152 /// Reads the element count from an array cookie. \p allocPtr is a byte
153 /// pointer to the start of the allocation (the beginning of the cookie).
154 /// \p cookieSize is the value returned by getArrayCookieSizeImpl.
155 /// \p cookieAlignment is the alignment at the cookie start, derived from
156 /// the element type's ABI alignment.
157 virtual mlir::Value readArrayCookieImpl(mlir::Location loc,
158 mlir::Value allocPtr,
159 clang::CharUnits cookieSize,
160 clang::CharUnits cookieAlignment,
161 const mlir::DataLayout &dataLayout,
162 CIRBaseBuilderTy &builder) const = 0;
163};
164
165/// Creates an Itanium-family ABI.
166std::unique_ptr<CIRCXXABI> createItaniumCXXABI(LowerModule &lm);
167
168} // namespace cir
169
170#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::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.