blob: 0c3a076da0b5801cd00a3e12849421b27cc6ba9a [file] [log] [blame]
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +00001//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +00009#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000011
Benjamin Kramer2664a862017-01-30 15:39:18 +000012#include "clang/AST/CharUnits.h"
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;
Richard Smithf667ad52017-08-26 01:04:35 +000026 class CodeGenOptions;
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;
55 public:
56 ABIInfo(CodeGen::CodeGenTypes &cgt)
Rafael Espindolaf4ec8032018-03-20 22:02:57 +000057 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000058
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000059 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000060
John McCall12f23522016-04-04 18:33:08 +000061 virtual bool supportsSwift() const { return false; }
62
Mark Lacey3825e832013-10-06 01:33:34 +000063 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000064 ASTContext &getContext() const;
65 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000066 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000067 const TargetInfo &getTarget() const;
Richard Smithf667ad52017-08-26 01:04:35 +000068 const CodeGenOptions &getCodeGenOpts() const;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000069
John McCall882987f2013-02-28 19:01:20 +000070 /// Return the calling convention to use for system runtime
71 /// functions.
72 llvm::CallingConv::ID getRuntimeCC() const {
73 return RuntimeCC;
74 }
75
Chris Lattner22326a12010-07-29 02:31:05 +000076 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000077
78 /// EmitVAArg - Emit the target dependent code to load a value of
79 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000080
Daniel Dunbare46506e2009-02-10 21:44:36 +000081 // FIXME: This is a gaping layering violation if we wanted to drop
82 // the ABI information any lower than CodeGen. Of course, for
83 // VAArg handling it has to be at this level; there is no way to
84 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000085 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
86 CodeGen::Address VAListAddr,
87 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000088
Nirav Dave9a8f97e2016-02-22 16:48:42 +000089 bool isAndroid() const;
90
Charles Davisc7d5c942015-09-17 20:55:33 +000091 /// Emit the target dependent code to load a value of
92 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
93 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
94 CodeGen::Address VAListAddr,
95 QualType Ty) const;
96
Reid Klecknere9f6a712014-10-31 17:10:41 +000097 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
98
99 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
100 uint64_t Members) const;
101
102 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
103 uint64_t &Members) const;
104
John McCall7f416cc2015-09-08 08:05:57 +0000105 /// A convenience method to return an indirect ABIArgInfo with an
106 /// expected alignment equal to the ABI alignment of the given type.
107 CodeGen::ABIArgInfo
108 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
109 bool Realign = false,
110 llvm::Type *Padding = nullptr) const;
111
112 CodeGen::ABIArgInfo
113 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
John McCall12f23522016-04-04 18:33:08 +0000114
115
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000116 };
John McCall12f23522016-04-04 18:33:08 +0000117
118 /// A refining implementation of ABIInfo for targets that support swiftcall.
119 ///
120 /// If we find ourselves wanting multiple such refinements, they'll probably
121 /// be independent refinements, and we should probably find another way
122 /// to do it than simple inheritance.
123 class SwiftABIInfo : public ABIInfo {
124 public:
125 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
126
127 bool supportsSwift() const final override { return true; }
128
John McCall56331e22018-01-07 06:28:49 +0000129 virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
John McCall12f23522016-04-04 18:33:08 +0000130 bool asReturnValue) const = 0;
131
132 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
133 llvm::Type *eltTy,
134 unsigned elts) const;
135
Arnold Schwaighoferb0f2c332016-12-01 18:07:38 +0000136 virtual bool isSwiftErrorInRegister() const = 0;
137
John McCall12f23522016-04-04 18:33:08 +0000138 static bool classof(const ABIInfo *info) {
139 return info->supportsSwift();
140 }
141 };
John McCall12f23522016-04-04 18:33:08 +0000142} // end namespace CodeGen
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000143} // end namespace clang
144
145#endif