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"
35 class CodeGenFunction;
40 class SwiftAggLowering;
43 // FIXME: All of this stuff should be part of the target interface
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.
49 /// ABIInfo - Target specific hooks for defining how a type should be
50 /// passed or returned from functions.
53 CodeGen::CodeGenTypes &CGT;
55 llvm::CallingConv::ID RuntimeCC;
56 llvm::CallingConv::ID BuiltinCC;
58 ABIInfo(CodeGen::CodeGenTypes &cgt)
60 RuntimeCC(llvm::CallingConv::C),
61 BuiltinCC(llvm::CallingConv::C) {}
65 virtual bool supportsSwift() const { return false; }
67 CodeGen::CGCXXABI &getCXXABI() const;
68 ASTContext &getContext() const;
69 llvm::LLVMContext &getVMContext() const;
70 const llvm::DataLayout &getDataLayout() const;
71 const TargetInfo &getTarget() const;
72 const CodeGenOptions &getCodeGenOpts() const;
74 /// Return the calling convention to use for system runtime
76 llvm::CallingConv::ID getRuntimeCC() const {
80 /// Return the calling convention to use for compiler builtins
81 llvm::CallingConv::ID getBuiltinCC() const {
85 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
87 /// EmitVAArg - Emit the target dependent code to load a value of
88 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
90 // FIXME: This is a gaping layering violation if we wanted to drop
91 // the ABI information any lower than CodeGen. Of course, for
92 // VAArg handling it has to be at this level; there is no way to
94 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
95 CodeGen::Address VAListAddr,
96 QualType Ty) const = 0;
98 bool isAndroid() const;
100 /// Emit the target dependent code to load a value of
101 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
102 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
103 CodeGen::Address VAListAddr,
106 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
108 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
109 uint64_t Members) const;
111 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
113 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
114 uint64_t &Members) const;
116 /// A convenience method to return an indirect ABIArgInfo with an
117 /// expected alignment equal to the ABI alignment of the given type.
119 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
120 bool Realign = false,
121 llvm::Type *Padding = nullptr) const;
124 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
129 /// A refining implementation of ABIInfo for targets that support swiftcall.
131 /// If we find ourselves wanting multiple such refinements, they'll probably
132 /// be independent refinements, and we should probably find another way
133 /// to do it than simple inheritance.
134 class SwiftABIInfo : public ABIInfo {
136 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
138 bool supportsSwift() const final override { return true; }
140 virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
141 ArrayRef<llvm::Type*> types,
142 bool asReturnValue) const = 0;
144 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
146 unsigned elts) const;
148 virtual bool isSwiftErrorInRegister() const = 0;
150 static bool classof(const ABIInfo *info) {
151 return info->supportsSwift();
154 } // end namespace CodeGen
155 } // end namespace clang