| 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 C++ code generation targeting the Itanium C++ ABI. The class |
| 10 | // in this file generates structures that follow the Itanium C++ ABI, which is |
| 11 | // documented at: |
| 12 | // https://itanium-cxx-abi.github.io/cxx-abi/abi.html |
| 13 | // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html |
| 14 | // |
| 15 | // It also supports the closely-related ARM ABI, documented at: |
| 16 | // https://developer.arm.com/documentation/ihi0041/g/ |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
| 20 | #include "CIRGenCXXABI.h" |
| 21 | #include "CIRGenFunction.h" |
| 22 | |
| 23 | #include "clang/AST/GlobalDecl.h" |
| 24 | #include "llvm/Support/ErrorHandling.h" |
| 25 | |
| 26 | using namespace clang; |
| 27 | using namespace clang::CIRGen; |
| 28 | |
| 29 | namespace { |
| 30 | |
| 31 | class CIRGenItaniumCXXABI : public CIRGenCXXABI { |
| 32 | public: |
| 33 | CIRGenItaniumCXXABI(CIRGenModule &cgm) : CIRGenCXXABI(cgm) { |
| 34 | assert(!cir::MissingFeatures::cxxabiUseARMMethodPtrABI()); |
| 35 | assert(!cir::MissingFeatures::cxxabiUseARMGuardVarABI()); |
| 36 | } |
| 37 | |
| 38 | void emitInstanceFunctionProlog(SourceLocation Loc, |
| 39 | CIRGenFunction &CGF) override; |
| 40 | }; |
| 41 | |
| 42 | } // namespace |
| 43 | |
| 44 | void CIRGenItaniumCXXABI::emitInstanceFunctionProlog(SourceLocation loc, |
| 45 | CIRGenFunction &cgf) { |
| 46 | // Naked functions have no prolog. |
| 47 | if (cgf.curFuncDecl && cgf.curFuncDecl->hasAttr<NakedAttr>()) { |
| 48 | cgf.cgm.errorNYI(cgf.curFuncDecl->getLocation(), |
| 49 | "emitInstanceFunctionProlog: Naked" ); |
| 50 | } |
| 51 | |
| 52 | /// Initialize the 'this' slot. In the Itanium C++ ABI, no prologue |
| 53 | /// adjustments are required, because they are all handled by thunks. |
| 54 | setCXXABIThisValue(cgf, loadIncomingCXXThis(cgf)); |
| 55 | |
| 56 | /// Classic codegen has code here to initialize the 'vtt' slot if |
| 57 | // getStructorImplicitParamDecl(cgf) returns a non-null value, but in the |
| 58 | // current implementation (of classic codegen) it never does. |
| 59 | assert(!cir::MissingFeatures::cxxabiStructorImplicitParam()); |
| 60 | |
| 61 | /// If this is a function that the ABI specifies returns 'this', initialize |
| 62 | /// the return slot to this' at the start of the function. |
| 63 | /// |
| 64 | /// Unlike the setting of return types, this is done within the ABI |
| 65 | /// implementation instead of by clients of CIRGenCXXBI because: |
| 66 | /// 1) getThisValue is currently protected |
| 67 | /// 2) in theory, an ABI could implement 'this' returns some other way; |
| 68 | /// HasThisReturn only specifies a contract, not the implementation |
| 69 | if (hasThisReturn(gd: cgf.curGD)) { |
| 70 | cgf.cgm.errorNYI(cgf.curFuncDecl->getLocation(), |
| 71 | "emitInstanceFunctionProlog: hasThisReturn" ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | CIRGenCXXABI *clang::CIRGen::CreateCIRGenItaniumCXXABI(CIRGenModule &cgm) { |
| 76 | switch (cgm.getASTContext().getCXXABIKind()) { |
| 77 | case TargetCXXABI::GenericItanium: |
| 78 | case TargetCXXABI::GenericAArch64: |
| 79 | return new CIRGenItaniumCXXABI(cgm); |
| 80 | |
| 81 | case TargetCXXABI::AppleARM64: |
| 82 | // The general Itanium ABI will do until we implement something that |
| 83 | // requires special handling. |
| 84 | assert(!cir::MissingFeatures::cxxabiAppleARM64CXXABI()); |
| 85 | return new CIRGenItaniumCXXABI(cgm); |
| 86 | |
| 87 | default: |
| 88 | llvm_unreachable("bad or NYI ABI kind" ); |
| 89 | } |
| 90 | } |
| 91 | |