blob: feed3833f24a2413eab068689eadf2b8aa86423b [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;
56 public:
57 ABIInfo(CodeGen::CodeGenTypes &cgt)
Rafael Espindolaf4ec8032018-03-20 22:02:57 +000058 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000059
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +000060 virtual ~ABIInfo();
Michael J. Spencerf5a1fbc2010-10-19 06:39:39 +000061
John McCall12f23522016-04-04 18:33:08 +000062 virtual bool supportsSwift() const { return false; }
63
Mark Lacey3825e832013-10-06 01:33:34 +000064 CodeGen::CGCXXABI &getCXXABI() const;
Chris Lattner2b037972010-07-29 02:01:43 +000065 ASTContext &getContext() const;
66 llvm::LLVMContext &getVMContext() const;
Micah Villmowdd31ca12012-10-08 16:25:52 +000067 const llvm::DataLayout &getDataLayout() const;
John McCallc8e01702013-04-16 22:48:15 +000068 const TargetInfo &getTarget() const;
Richard Smithf667ad52017-08-26 01:04:35 +000069 const CodeGenOptions &getCodeGenOpts() 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
Chris Lattner22326a12010-07-29 02:31:05 +000077 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
Daniel Dunbare46506e2009-02-10 21:44:36 +000078
79 /// EmitVAArg - Emit the target dependent code to load a value of
80 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
Anton Korobeynikov244360d2009-06-05 22:08:42 +000081
Daniel Dunbare46506e2009-02-10 21:44:36 +000082 // FIXME: This is a gaping layering violation if we wanted to drop
83 // the ABI information any lower than CodeGen. Of course, for
84 // VAArg handling it has to be at this level; there is no way to
85 // abstract this out.
John McCall7f416cc2015-09-08 08:05:57 +000086 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
87 CodeGen::Address VAListAddr,
88 QualType Ty) const = 0;
Reid Klecknere9f6a712014-10-31 17:10:41 +000089
Nirav Dave9a8f97e2016-02-22 16:48:42 +000090 bool isAndroid() const;
91
Charles Davisc7d5c942015-09-17 20:55:33 +000092 /// Emit the target dependent code to load a value of
93 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
94 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
95 CodeGen::Address VAListAddr,
96 QualType Ty) const;
97
Reid Klecknere9f6a712014-10-31 17:10:41 +000098 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
99
100 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
101 uint64_t Members) const;
102
103 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
104 uint64_t &Members) const;
105
John McCall7f416cc2015-09-08 08:05:57 +0000106 /// A convenience method to return an indirect ABIArgInfo with an
107 /// expected alignment equal to the ABI alignment of the given type.
108 CodeGen::ABIArgInfo
109 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
110 bool Realign = false,
111 llvm::Type *Padding = nullptr) const;
112
113 CodeGen::ABIArgInfo
114 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
John McCall12f23522016-04-04 18:33:08 +0000115
116
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000117 };
John McCall12f23522016-04-04 18:33:08 +0000118
119 /// A refining implementation of ABIInfo for targets that support swiftcall.
120 ///
121 /// If we find ourselves wanting multiple such refinements, they'll probably
122 /// be independent refinements, and we should probably find another way
123 /// to do it than simple inheritance.
124 class SwiftABIInfo : public ABIInfo {
125 public:
126 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
127
128 bool supportsSwift() const final override { return true; }
129
John McCall56331e22018-01-07 06:28:49 +0000130 virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
John McCall12f23522016-04-04 18:33:08 +0000131 bool asReturnValue) const = 0;
132
133 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
134 llvm::Type *eltTy,
135 unsigned elts) const;
136
Arnold Schwaighoferb0f2c332016-12-01 18:07:38 +0000137 virtual bool isSwiftErrorInRegister() const = 0;
138
John McCall12f23522016-04-04 18:33:08 +0000139 static bool classof(const ABIInfo *info) {
140 return info->supportsSwift();
141 }
142 };
John McCall12f23522016-04-04 18:33:08 +0000143} // end namespace CodeGen
Daniel Dunbar6d6b0d32009-02-03 01:05:53 +0000144} // end namespace clang
145
146#endif