1 | //===----------------------------------------------------------------------===// |
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 provides an abstract class for C++ code generation. Concrete subclasses |
10 | // of this implement code generation for specific C++ ABIs. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H |
15 | #define LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H |
16 | |
17 | #include "CIRGenCall.h" |
18 | #include "CIRGenFunction.h" |
19 | #include "CIRGenModule.h" |
20 | |
21 | #include "clang/AST/Mangle.h" |
22 | |
23 | namespace clang::CIRGen { |
24 | |
25 | /// Implements C++ ABI-specific code generation functions. |
26 | class CIRGenCXXABI { |
27 | protected: |
28 | CIRGenModule &cgm; |
29 | std::unique_ptr<clang::MangleContext> mangleContext; |
30 | |
31 | public: |
32 | // TODO(cir): make this protected when target-specific CIRGenCXXABIs are |
33 | // implemented. |
34 | CIRGenCXXABI(CIRGenModule &cgm) |
35 | : cgm(cgm), mangleContext(cgm.getASTContext().createMangleContext()) {} |
36 | virtual ~CIRGenCXXABI(); |
37 | |
38 | void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr); |
39 | |
40 | public: |
41 | clang::ImplicitParamDecl *getThisDecl(CIRGenFunction &cgf) { |
42 | return cgf.cxxabiThisDecl; |
43 | } |
44 | |
45 | /// Emit the ABI-specific prolog for the function |
46 | virtual void emitInstanceFunctionProlog(SourceLocation Loc, |
47 | CIRGenFunction &cgf) = 0; |
48 | |
49 | /// Get the type of the implicit "this" parameter used by a method. May return |
50 | /// zero if no specific type is applicable, e.g. if the ABI expects the "this" |
51 | /// parameter to point to some artificial offset in a complete object due to |
52 | /// vbases being reordered. |
53 | virtual const clang::CXXRecordDecl * |
54 | getThisArgumentTypeForMethod(const clang::CXXMethodDecl *md) { |
55 | return md->getParent(); |
56 | } |
57 | |
58 | /// Build a parameter variable suitable for 'this'. |
59 | void buildThisParam(CIRGenFunction &cgf, FunctionArgList ¶ms); |
60 | |
61 | /// Loads the incoming C++ this pointer as it was passed by the caller. |
62 | mlir::Value loadIncomingCXXThis(CIRGenFunction &cgf); |
63 | |
64 | /// Returns true if the given constructor or destructor is one of the kinds |
65 | /// that the ABI says returns 'this' (only applies when called non-virtually |
66 | /// for destructors). |
67 | /// |
68 | /// There currently is no way to indicate if a destructor returns 'this' when |
69 | /// called virtually, and CIR generation does not support this case. |
70 | virtual bool hasThisReturn(clang::GlobalDecl gd) const { return false; } |
71 | |
72 | virtual bool hasMostDerivedReturn(clang::GlobalDecl gd) const { |
73 | return false; |
74 | } |
75 | |
76 | /// Gets the mangle context. |
77 | clang::MangleContext &getMangleContext() { return *mangleContext; } |
78 | }; |
79 | |
80 | /// Creates and Itanium-family ABI |
81 | CIRGenCXXABI *CreateCIRGenItaniumCXXABI(CIRGenModule &cgm); |
82 | |
83 | } // namespace clang::CIRGen |
84 | |
85 | #endif |
86 | |