Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 1 | //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 9 | #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H |
| 10 | #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 11 | |
Benjamin Kramer | 2664a86 | 2017-01-30 15:39:18 +0000 | [diff] [blame] | 12 | #include "clang/AST/CharUnits.h" |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 13 | #include "clang/AST/Type.h" |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 14 | #include "llvm/IR/CallingConv.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Type.h" |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 17 | namespace llvm { |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 18 | class Value; |
Benjamin Kramer | 9cd050a | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 19 | class LLVMContext; |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 20 | class DataLayout; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 21 | class Type; |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 24 | namespace clang { |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 25 | class ASTContext; |
Richard Smith | f667ad5 | 2017-08-26 01:04:35 +0000 | [diff] [blame] | 26 | class CodeGenOptions; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 27 | class TargetInfo; |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 28 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 29 | namespace CodeGen { |
| 30 | class ABIArgInfo; |
| 31 | class Address; |
| 32 | class CGCXXABI; |
| 33 | class CGFunctionInfo; |
| 34 | class CodeGenFunction; |
| 35 | class CodeGenTypes; |
| 36 | class SwiftABIInfo; |
| 37 | |
| 38 | namespace swiftcall { |
| 39 | class SwiftAggLowering; |
| 40 | } |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 41 | |
Chris Lattner | 4b8585e | 2010-07-28 23:46:15 +0000 | [diff] [blame] | 42 | // 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 Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 46 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 47 | |
| 48 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 49 | /// passed or returned from functions. |
| 50 | class ABIInfo { |
| 51 | public: |
Chris Lattner | 2b03797 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 52 | CodeGen::CodeGenTypes &CGT; |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 53 | protected: |
| 54 | llvm::CallingConv::ID RuntimeCC; |
| 55 | public: |
| 56 | ABIInfo(CodeGen::CodeGenTypes &cgt) |
Rafael Espindola | f4ec803 | 2018-03-20 22:02:57 +0000 | [diff] [blame] | 57 | : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {} |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 58 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 59 | virtual ~ABIInfo(); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 60 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 61 | virtual bool supportsSwift() const { return false; } |
| 62 | |
Mark Lacey | 3825e83 | 2013-10-06 01:33:34 +0000 | [diff] [blame] | 63 | CodeGen::CGCXXABI &getCXXABI() const; |
Chris Lattner | 2b03797 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 64 | ASTContext &getContext() const; |
| 65 | llvm::LLVMContext &getVMContext() const; |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 66 | const llvm::DataLayout &getDataLayout() const; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 67 | const TargetInfo &getTarget() const; |
Richard Smith | f667ad5 | 2017-08-26 01:04:35 +0000 | [diff] [blame] | 68 | const CodeGenOptions &getCodeGenOpts() const; |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 69 | |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 70 | /// Return the calling convention to use for system runtime |
| 71 | /// functions. |
| 72 | llvm::CallingConv::ID getRuntimeCC() const { |
| 73 | return RuntimeCC; |
| 74 | } |
| 75 | |
Chris Lattner | 22326a1 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 76 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 77 | |
| 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 Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 81 | // 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 McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 85 | virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, |
| 86 | CodeGen::Address VAListAddr, |
| 87 | QualType Ty) const = 0; |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 88 | |
Nirav Dave | 9a8f97e | 2016-02-22 16:48:42 +0000 | [diff] [blame] | 89 | bool isAndroid() const; |
| 90 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 91 | /// 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 Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 97 | 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 McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 105 | /// 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 McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 114 | |
| 115 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 116 | }; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 117 | |
| 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 McCall | 56331e2 | 2018-01-07 06:28:49 +0000 | [diff] [blame] | 129 | virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types, |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 130 | bool asReturnValue) const = 0; |
| 131 | |
| 132 | virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, |
| 133 | llvm::Type *eltTy, |
| 134 | unsigned elts) const; |
| 135 | |
Arnold Schwaighofer | b0f2c33 | 2016-12-01 18:07:38 +0000 | [diff] [blame] | 136 | virtual bool isSwiftErrorInRegister() const = 0; |
| 137 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 138 | static bool classof(const ABIInfo *info) { |
| 139 | return info->supportsSwift(); |
| 140 | } |
| 141 | }; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 142 | } // end namespace CodeGen |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 143 | } // end namespace clang |
| 144 | |
| 145 | #endif |