blob: c0be60ef53bc5dc98aa8b17a97684cd7c5cee52c [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
Benjamin Kramer2664a862017-01-30 15:39:18 +000013#include "clang/AST/CharUnits.h"
Anton Korobeynikov244360d2009-06-05 22:08:42 +000014#include "clang/AST/Type.h"
John McCall882987f2013-02-28 19:01:20 +000015#include "llvm/IR/CallingConv.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000016#include "llvm/IR/Type.h"
Anton Korobeynikov244360d2009-06-05 22:08:42 +000017
Daniel Dunbar313321e2009-02-03 05:31:23 +000018namespace llvm {
Anton Korobeynikov244360d2009-06-05 22:08:42 +000019 class Value;
Benjamin Kramer9cd050a2009-08-11 17:46:57 +000020 class LLVMContext;
Micah Villmowdd31ca12012-10-08 16:25:52 +000021 class DataLayout;
John McCall12f23522016-04-04 18:33:08 +000022 class Type;
Daniel Dunbar313321e2009-02-03 05:31:23 +000023}
24
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000025namespace clang {
Daniel Dunbar32931eb2009-02-03 06:51:18 +000026 class ASTContext;
John McCallc8e01702013-04-16 22:48:15 +000027 class TargetInfo;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000028
John McCall12f23522016-04-04 18:33:08 +000029namespace CodeGen {
30 class ABIArgInfo;
31 class Address;
32 class CGCXXABI;
33 class CGFunctionInfo;
34 class CodeGenFunction;
35 class CodeGenTypes;
36 class SwiftABIInfo;
37
38namespace swiftcall {
39 class SwiftAggLowering;
40}
Daniel Dunbar32931eb2009-02-03 06:51:18 +000041
Chris Lattner4b8585e2010-07-28 23:46:15 +000042 // 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.
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000046
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000047
48 /// ABIInfo - Target specific hooks for defining how a type should be
49 /// passed or returned from functions.
50 class ABIInfo {
51 public:
Chris Lattner2b037972010-07-29 02:01:43 +000052 CodeGen::CodeGenTypes &CGT;
John McCall882987f2013-02-28 19:01:20 +000053 protected:
54 llvm::CallingConv::ID RuntimeCC;
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000055 llvm::CallingConv::ID BuiltinCC;
John McCall882987f2013-02-28 19:01:20 +000056 public:
57 ABIInfo(CodeGen::CodeGenTypes &cgt)
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000058 : CGT(cgt),
59 RuntimeCC(llvm::CallingConv::C),
60 BuiltinCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000061
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000062 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000063
John McCall12f23522016-04-04 18:33:08 +000064 virtual bool supportsSwift() const { return false; }
65
Mark Lacey3825e832013-10-06 01:33:34 +000066 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000067 ASTContext &getContext() const;
68 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000069 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000070 const TargetInfo &getTarget() const;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000071
John McCall882987f2013-02-28 19:01:20 +000072 /// Return the calling convention to use for system runtime
73 /// functions.
74 llvm::CallingConv::ID getRuntimeCC() const {
75 return RuntimeCC;
76 }
77
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000078 /// Return the calling convention to use for compiler builtins
79 llvm::CallingConv::ID getBuiltinCC() const {
80 return BuiltinCC;
81 }
82
Chris Lattner22326a12010-07-29 02:31:05 +000083 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000084
85 /// EmitVAArg - Emit the target dependent code to load a value of
86 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000087
Daniel Dunbare46506e2009-02-10 21:44:36 +000088 // 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
91 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000092 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
93 CodeGen::Address VAListAddr,
94 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000095
Nirav Dave9a8f97e2016-02-22 16:48:42 +000096 bool isAndroid() const;
97
Charles Davisc7d5c942015-09-17 20:55:33 +000098 /// 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,
102 QualType Ty) const;
103
Reid Klecknere9f6a712014-10-31 17:10:41 +0000104 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
105
106 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
107 uint64_t Members) const;
108
Petar Jovanovic1a3f9652015-05-26 21:07:19 +0000109 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
110
Reid Klecknere9f6a712014-10-31 17:10:41 +0000111 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
112 uint64_t &Members) const;
113
John McCall7f416cc2015-09-08 08:05:57 +0000114 /// A convenience method to return an indirect ABIArgInfo with an
115 /// expected alignment equal to the ABI alignment of the given type.
116 CodeGen::ABIArgInfo
117 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
118 bool Realign = false,
119 llvm::Type *Padding = nullptr) const;
120
121 CodeGen::ABIArgInfo
122 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
John McCall12f23522016-04-04 18:33:08 +0000123
124
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000125 };
John McCall12f23522016-04-04 18:33:08 +0000126
127 /// A refining implementation of ABIInfo for targets that support swiftcall.
128 ///
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 {
133 public:
134 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
135
136 bool supportsSwift() const final override { return true; }
137
138 virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
139 ArrayRef<llvm::Type*> types,
140 bool asReturnValue) const = 0;
141
142 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
143 llvm::Type *eltTy,
144 unsigned elts) const;
145
Arnold Schwaighoferb0f2c332016-12-01 18:07:38 +0000146 virtual bool isSwiftErrorInRegister() const = 0;
147
John McCall12f23522016-04-04 18:33:08 +0000148 static bool classof(const ABIInfo *info) {
149 return info->supportsSwift();
150 }
151 };
152
153} // end namespace CodeGen
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000154} // end namespace clang
155
156#endif