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