1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
13 #include "clang/AST/CharUnits.h"
14 #include "clang/AST/Type.h"
15 #include "llvm/IR/CallingConv.h"
16 #include "llvm/IR/Type.h"
34 class CodeGenFunction;
39 class SwiftAggLowering;
42 // FIXME: All of this stuff should be part of the target interface
43 // somehow. It is currently here because it is not clear how to factor
44 // the targets to support this, since the Targets currently live in a
45 // layer below types n'stuff.
48 /// ABIInfo - Target specific hooks for defining how a type should be
49 /// passed or returned from functions.
52 CodeGen::CodeGenTypes &CGT;
54 llvm::CallingConv::ID RuntimeCC;
55 llvm::CallingConv::ID BuiltinCC;
57 ABIInfo(CodeGen::CodeGenTypes &cgt)
59 RuntimeCC(llvm::CallingConv::C),
60 BuiltinCC(llvm::CallingConv::C) {}
64 virtual bool supportsSwift() const { return false; }
66 CodeGen::CGCXXABI &getCXXABI() const;
67 ASTContext &getContext() const;
68 llvm::LLVMContext &getVMContext() const;
69 const llvm::DataLayout &getDataLayout() const;
70 const TargetInfo &getTarget() const;
72 /// Return the calling convention to use for system runtime
74 llvm::CallingConv::ID getRuntimeCC() const {
78 /// Return the calling convention to use for compiler builtins
79 llvm::CallingConv::ID getBuiltinCC() const {
83 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
85 /// EmitVAArg - Emit the target dependent code to load a value of
86 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
88 // FIXME: This is a gaping layering violation if we wanted to drop
89 // the ABI information any lower than CodeGen. Of course, for
90 // VAArg handling it has to be at this level; there is no way to
92 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
93 CodeGen::Address VAListAddr,
94 QualType Ty) const = 0;
96 bool isAndroid() const;
98 /// Emit the target dependent code to load a value of
99 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
100 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
101 CodeGen::Address VAListAddr,
104 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
106 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
107 uint64_t Members) const;
109 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
111 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
112 uint64_t &Members) const;
114 /// A convenience method to return an indirect ABIArgInfo with an
115 /// expected alignment equal to the ABI alignment of the given type.
117 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
118 bool Realign = false,
119 llvm::Type *Padding = nullptr) const;
122 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
127 /// A refining implementation of ABIInfo for targets that support swiftcall.
129 /// If we find ourselves wanting multiple such refinements, they'll probably
130 /// be independent refinements, and we should probably find another way
131 /// to do it than simple inheritance.
132 class SwiftABIInfo : public ABIInfo {
134 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
136 bool supportsSwift() const final override { return true; }
138 virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
139 ArrayRef<llvm::Type*> types,
140 bool asReturnValue) const = 0;
142 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
144 unsigned elts) const;
146 virtual bool isSwiftErrorInRegister() const = 0;
148 static bool classof(const ABIInfo *info) {
149 return info->supportsSwift();
152 } // end namespace CodeGen
153 } // end namespace clang