blob: 575506da84d46b479b0aeffd5b043f1f9108b78f [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;
Richard Smithf667ad52017-08-26 01:04:35 +000027 class CodeGenOptions;
John McCallc8e01702013-04-16 22:48:15 +000028 class TargetInfo;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000029
John McCall12f23522016-04-04 18:33:08 +000030namespace CodeGen {
31 class ABIArgInfo;
32 class Address;
33 class CGCXXABI;
34 class CGFunctionInfo;
35 class CodeGenFunction;
36 class CodeGenTypes;
37 class SwiftABIInfo;
38
39namespace swiftcall {
40 class SwiftAggLowering;
41}
Daniel Dunbar32931eb2009-02-03 06:51:18 +000042
Chris Lattner4b8585e2010-07-28 23:46:15 +000043 // 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.
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000047
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000048
49 /// ABIInfo - Target specific hooks for defining how a type should be
50 /// passed or returned from functions.
51 class ABIInfo {
52 public:
Chris Lattner2b037972010-07-29 02:01:43 +000053 CodeGen::CodeGenTypes &CGT;
John McCall882987f2013-02-28 19:01:20 +000054 protected:
55 llvm::CallingConv::ID RuntimeCC;
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000056 llvm::CallingConv::ID BuiltinCC;
John McCall882987f2013-02-28 19:01:20 +000057 public:
58 ABIInfo(CodeGen::CodeGenTypes &cgt)
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000059 : CGT(cgt),
60 RuntimeCC(llvm::CallingConv::C),
61 BuiltinCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000062
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000063 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000064
John McCall12f23522016-04-04 18:33:08 +000065 virtual bool supportsSwift() const { return false; }
66
Mark Lacey3825e832013-10-06 01:33:34 +000067 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000068 ASTContext &getContext() const;
69 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000070 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000071 const TargetInfo &getTarget() const;
Richard Smithf667ad52017-08-26 01:04:35 +000072 const CodeGenOptions &getCodeGenOpts() const;
Daniel Dunbar32931eb2009-02-03 06:51:18 +000073
John McCall882987f2013-02-28 19:01:20 +000074 /// Return the calling convention to use for system runtime
75 /// functions.
76 llvm::CallingConv::ID getRuntimeCC() const {
77 return RuntimeCC;
78 }
79
Anton Korobeynikovd90dd792014-12-02 16:04:58 +000080 /// Return the calling convention to use for compiler builtins
81 llvm::CallingConv::ID getBuiltinCC() const {
82 return BuiltinCC;
83 }
84
Chris Lattner22326a12010-07-29 02:31:05 +000085 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000086
87 /// EmitVAArg - Emit the target dependent code to load a value of
88 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000089
Daniel Dunbare46506e2009-02-10 21:44:36 +000090 // 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
93 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000094 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
95 CodeGen::Address VAListAddr,
96 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000097
Nirav Dave9a8f97e2016-02-22 16:48:42 +000098 bool isAndroid() const;
99
Charles Davisc7d5c942015-09-17 20:55:33 +0000100 /// 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,
104 QualType Ty) const;
105
Reid Klecknere9f6a712014-10-31 17:10:41 +0000106 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
107
108 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
109 uint64_t Members) const;
110
Petar Jovanovic1a3f9652015-05-26 21:07:19 +0000111 virtual bool shouldSignExtUnsignedType(QualType Ty) const;
112
Reid Klecknere9f6a712014-10-31 17:10:41 +0000113 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
114 uint64_t &Members) const;
115
John McCall7f416cc2015-09-08 08:05:57 +0000116 /// A convenience method to return an indirect ABIArgInfo with an
117 /// expected alignment equal to the ABI alignment of the given type.
118 CodeGen::ABIArgInfo
119 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
120 bool Realign = false,
121 llvm::Type *Padding = nullptr) const;
122
123 CodeGen::ABIArgInfo
124 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
John McCall12f23522016-04-04 18:33:08 +0000125
126
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000127 };
John McCall12f23522016-04-04 18:33:08 +0000128
129 /// A refining implementation of ABIInfo for targets that support swiftcall.
130 ///
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 {
135 public:
136 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
137
138 bool supportsSwift() const final override { return true; }
139
140 virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,
141 ArrayRef<llvm::Type*> types,
142 bool asReturnValue) const = 0;
143
144 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
145 llvm::Type *eltTy,
146 unsigned elts) const;
147
Arnold Schwaighoferb0f2c332016-12-01 18:07:38 +0000148 virtual bool isSwiftErrorInRegister() const = 0;
149
John McCall12f23522016-04-04 18:33:08 +0000150 static bool classof(const ABIInfo *info) {
151 return info->supportsSwift();
152 }
153 };
John McCall12f23522016-04-04 18:33:08 +0000154} // end namespace CodeGen
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000155} // end namespace clang
156
157#endif