1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- 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 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H 10 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H 11 12 #include "clang/AST/CharUnits.h" 13 #include "clang/AST/Type.h" 14 #include "llvm/IR/CallingConv.h" 15 #include "llvm/IR/Type.h" 16 17 namespace llvm { 18 class Value; 19 class LLVMContext; 20 class DataLayout; 21 class Type; 22 } 23 24 namespace clang { 25 class ASTContext; 26 class CodeGenOptions; 27 class TargetInfo; 28 29 namespace CodeGen { 30 class ABIArgInfo; 31 class Address; 32 class CGCXXABI; 33 class CGFunctionInfo; 34 class CodeGenFunction; 35 class CodeGenTypes; 36 class SwiftABIInfo; 37 38 // FIXME: All of this stuff should be part of the target interface 39 // somehow. It is currently here because it is not clear how to factor 40 // the targets to support this, since the Targets currently live in a 41 // layer below types n'stuff. 42 43 44 /// ABIInfo - Target specific hooks for defining how a type should be 45 /// passed or returned from functions. 46 class ABIInfo { 47 public: 48 CodeGen::CodeGenTypes &CGT; 49 protected: 50 llvm::CallingConv::ID RuntimeCC; 51 public: 52 ABIInfo(CodeGen::CodeGenTypes &cgt) 53 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {} 54 55 virtual ~ABIInfo(); 56 57 virtual bool supportsSwift() const { return false; } 58 59 virtual bool allowBFloatArgsAndRet() const { return false; } 60 61 CodeGen::CGCXXABI &getCXXABI() const; 62 ASTContext &getContext() const; 63 llvm::LLVMContext &getVMContext() const; 64 const llvm::DataLayout &getDataLayout() const; 65 const TargetInfo &getTarget() const; 66 const CodeGenOptions &getCodeGenOpts() const; 67 68 /// Return the calling convention to use for system runtime 69 /// functions. 70 llvm::CallingConv::ID getRuntimeCC() const { 71 return RuntimeCC; 72 } 73 74 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; 75 76 /// EmitVAArg - Emit the target dependent code to load a value of 77 /// \arg Ty from the va_list pointed to by \arg VAListAddr. 78 79 // FIXME: This is a gaping layering violation if we wanted to drop 80 // the ABI information any lower than CodeGen. Of course, for 81 // VAArg handling it has to be at this level; there is no way to 82 // abstract this out. 83 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, 84 CodeGen::Address VAListAddr, 85 QualType Ty) const = 0; 86 87 bool isAndroid() const; 88 89 /// Emit the target dependent code to load a value of 90 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr. 91 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, 92 CodeGen::Address VAListAddr, 93 QualType Ty) const; 94 95 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const; 96 97 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, 98 uint64_t Members) const; 99 virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const; 100 101 bool isHomogeneousAggregate(QualType Ty, const Type *&Base, 102 uint64_t &Members) const; 103 104 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The 105 // only difference is that this considers bit-precise integer types as well. 106 bool isPromotableIntegerTypeForABI(QualType Ty) const; 107 108 /// A convenience method to return an indirect ABIArgInfo with an 109 /// expected alignment equal to the ABI alignment of the given type. 110 CodeGen::ABIArgInfo 111 getNaturalAlignIndirect(QualType Ty, bool ByVal = true, 112 bool Realign = false, 113 llvm::Type *Padding = nullptr) const; 114 115 CodeGen::ABIArgInfo 116 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const; 117 118 119 }; 120 121 /// A refining implementation of ABIInfo for targets that support swiftcall. 122 /// 123 /// If we find ourselves wanting multiple such refinements, they'll probably 124 /// be independent refinements, and we should probably find another way 125 /// to do it than simple inheritance. 126 class SwiftABIInfo : public ABIInfo { 127 public: 128 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {} 129 130 bool supportsSwift() const final { return true; } 131 132 virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types, 133 bool asReturnValue) const = 0; 134 135 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, 136 llvm::Type *eltTy, 137 unsigned elts) const; 138 139 virtual bool isSwiftErrorInRegister() const = 0; 140 141 static bool classof(const ABIInfo *info) { 142 return info->supportsSwift(); 143 } 144 }; 145 } // end namespace CodeGen 146 } // end namespace clang 147 148 #endif 149