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; |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 56 | llvm::CallingConv::ID BuiltinCC; |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 57 | public: |
| 58 | ABIInfo(CodeGen::CodeGenTypes &cgt) |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 59 | : CGT(cgt), |
| 60 | RuntimeCC(llvm::CallingConv::C), |
| 61 | BuiltinCC(llvm::CallingConv::C) {} |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 62 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 63 | virtual ~ABIInfo(); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 64 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 65 | virtual bool supportsSwift() const { return false; } |
| 66 | |
Mark Lacey | 3825e83 | 2013-10-06 01:33:34 +0000 | [diff] [blame] | 67 | CodeGen::CGCXXABI &getCXXABI() const; |
Chris Lattner | 2b03797 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 68 | ASTContext &getContext() const; |
| 69 | llvm::LLVMContext &getVMContext() const; |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 70 | const llvm::DataLayout &getDataLayout() const; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 71 | const TargetInfo &getTarget() const; |
Richard Smith | f667ad5 | 2017-08-26 01:04:35 +0000 | [diff] [blame^] | 72 | const CodeGenOptions &getCodeGenOpts() const; |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 73 | |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 74 | /// Return the calling convention to use for system runtime |
| 75 | /// functions. |
| 76 | llvm::CallingConv::ID getRuntimeCC() const { |
| 77 | return RuntimeCC; |
| 78 | } |
| 79 | |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 80 | /// Return the calling convention to use for compiler builtins |
| 81 | llvm::CallingConv::ID getBuiltinCC() const { |
| 82 | return BuiltinCC; |
| 83 | } |
| 84 | |
Chris Lattner | 22326a1 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 85 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 86 | |
| 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 Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 89 | |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 90 | // 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 McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 94 | virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, |
| 95 | CodeGen::Address VAListAddr, |
| 96 | QualType Ty) const = 0; |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 97 | |
Nirav Dave | 9a8f97e | 2016-02-22 16:48:42 +0000 | [diff] [blame] | 98 | bool isAndroid() const; |
| 99 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 100 | /// 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 Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 106 | virtual bool isHomogeneousAggregateBaseType(QualType Ty) const; |
| 107 | |
| 108 | virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, |
| 109 | uint64_t Members) const; |
| 110 | |
Petar Jovanovic | 1a3f965 | 2015-05-26 21:07:19 +0000 | [diff] [blame] | 111 | virtual bool shouldSignExtUnsignedType(QualType Ty) const; |
| 112 | |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 113 | bool isHomogeneousAggregate(QualType Ty, const Type *&Base, |
| 114 | uint64_t &Members) const; |
| 115 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 116 | /// 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 McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 125 | |
| 126 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 127 | }; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 128 | |
| 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 Schwaighofer | b0f2c33 | 2016-12-01 18:07:38 +0000 | [diff] [blame] | 148 | virtual bool isSwiftErrorInRegister() const = 0; |
| 149 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 150 | static bool classof(const ABIInfo *info) { |
| 151 | return info->supportsSwift(); |
| 152 | } |
| 153 | }; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 154 | } // end namespace CodeGen |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 155 | } // end namespace clang |
| 156 | |
| 157 | #endif |