blob: ac31dfdaf3e4bc4524bcf1ae1aff8ba2ca28b305 [file] [log] [blame]
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +00001//===----- 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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000012
Anton Korobeynikov244360d2009-06-05 22:08:42 +000013#include "clang/AST/Type.h"
John McCall882987f2013-02-28 19:01:20 +000014#include "llvm/IR/CallingConv.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000015#include "llvm/IR/Type.h"
Anton Korobeynikov244360d2009-06-05 22:08:42 +000016
Daniel Dunbar313321e2009-02-03 05:31:23 +000017namespace llvm {
Anton Korobeynikov244360d2009-06-05 22:08:42 +000018 class Value;
Benjamin Kramer9cd050a2009-08-11 17:46:57 +000019 class LLVMContext;
Micah Villmowdd31ca12012-10-08 16:25:52 +000020 class DataLayout;
John McCall12f23522016-04-04 18:33:08 +000021 class Type;
Daniel Dunbar313321e2009-02-03 05:31:23 +000022}
23
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000024namespace clang {
Daniel Dunbar32931eb2009-02-03 06:51:18 +000025 class ASTContext;
John McCallc8e01702013-04-16 22:48:15 +000026 class TargetInfo;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000027
John McCall12f23522016-04-04 18:33:08 +000028namespace CodeGen {
29 class ABIArgInfo;
30 class Address;
31 class CGCXXABI;
32 class CGFunctionInfo;
33 class CodeGenFunction;
34 class CodeGenTypes;
35 class SwiftABIInfo;
36
37namespace swiftcall {
38 class SwiftAggLowering;
39}
Daniel Dunbar32931eb2009-02-03 06:51:18 +000040
Chris Lattner4b8585e2010-07-28 23:46:15 +000041 // FIXME: All of this stuff should be part of the target interface
42 // somehow. It is currently here because it is not clear how to factor
43 // the targets to support this, since the Targets currently live in a
44 // layer below types n'stuff.
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000045
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000046
47 /// ABIInfo - Target specific hooks for defining how a type should be
48 /// passed or returned from functions.
49 class ABIInfo {
50 public:
Chris Lattner2b037972010-07-29 02:01:43 +000051 CodeGen::CodeGenTypes &CGT;
John McCall882987f2013-02-28 19:01:20 +000052 protected:
53 llvm::CallingConv::ID RuntimeCC;
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000054 llvm::CallingConv::ID BuiltinCC;
John McCall882987f2013-02-28 19:01:20 +000055 public:
56 ABIInfo(CodeGen::CodeGenTypes &cgt)
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000057 : CGT(cgt),
58 RuntimeCC(llvm::CallingConv::C),
59 BuiltinCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000060
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000061 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000062
John McCall12f23522016-04-04 18:33:08 +000063 virtual bool supportsSwift() const { return false; }
64
Mark Lacey3825e832013-10-06 01:33:34 +000065 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000066 ASTContext &getContext() const;
67 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000068 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000069 const TargetInfo &getTarget() const;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000070
John McCall882987f2013-02-28 19:01:20 +000071 /// Return the calling convention to use for system runtime
72 /// functions.
73 llvm::CallingConv::ID getRuntimeCC() const {
74 return RuntimeCC;
75 }
76
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000077 /// Return the calling convention to use for compiler builtins
78 llvm::CallingConv::ID getBuiltinCC() const {
79 return BuiltinCC;
80 }
81
Chris Lattner22326a12010-07-29 02:31:05 +000082 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000083
84 /// EmitVAArg - Emit the target dependent code to load a value of
85 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000086
Daniel Dunbare46506e2009-02-10 21:44:36 +000087 // FIXME: This is a gaping layering violation if we wanted to drop
88 // the ABI information any lower than CodeGen. Of course, for
89 // VAArg handling it has to be at this level; there is no way to
90 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000091 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
92 CodeGen::Address VAListAddr,
93 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000094
Nirav Dave9a8f97e2016-02-22 16:48:42 +000095 bool isAndroid() const;
96
Charles Davisc7d5c942015-09-17 20:55:33 +000097 /// Emit the target dependent code to load a value of
98 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
99 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
100 CodeGen::Address VAListAddr,
101 QualType Ty) const;
102
Reid Klecknere9f6a712014-10-31 17:10:41 +0000103 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
104
105 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
106 uint64_t Members) const;
107
Petar Jovanovic1a3f9652015-05-26 21:07:19 +0000108 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
109
Reid Klecknere9f6a712014-10-31 17:10:41 +0000110 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
111 uint64_t &Members) const;
112
John McCall7f416cc2015-09-08 08:05:57 +0000113 /// A convenience method to return an indirect ABIArgInfo with an
114 /// expected alignment equal to the ABI alignment of the given type.
115 CodeGen::ABIArgInfo
116 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
117 bool Realign = false,
118 llvm::Type *Padding = nullptr) const;
119
120 CodeGen::ABIArgInfo
121 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
John McCall12f23522016-04-04 18:33:08 +0000122
123
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000124 };
John McCall12f23522016-04-04 18:33:08 +0000125
126 /// A refining implementation of ABIInfo for targets that support swiftcall.
127 ///
128 /// If we find ourselves wanting multiple such refinements, they'll probably
129 /// be independent refinements, and we should probably find another way
130 /// to do it than simple inheritance.
131 class SwiftABIInfo : public ABIInfo {
132 public:
133 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
134
135 bool supportsSwift() const final override { return true; }
136
137 virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
138 ArrayRef<llvm::Type*> types,
139 bool asReturnValue) const = 0;
140
141 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
142 llvm::Type *eltTy,
143 unsigned elts) const;
144
Arnold Schwaighoferb0f2c332016-12-01 18:07:38 +0000145 virtual bool isSwiftErrorInRegister() const = 0;
146
John McCall12f23522016-04-04 18:33:08 +0000147 static bool classof(const ABIInfo *info) {
148 return info->supportsSwift();
149 }
150 };
151
152} // end namespace CodeGen
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000153} // end namespace clang
154
155#endif