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