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 | |
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; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 26 | class TargetInfo; |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 27 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 28 | namespace CodeGen { |
| 29 | class ABIArgInfo; |
| 30 | class Address; |
| 31 | class CGCXXABI; |
| 32 | class CGFunctionInfo; |
| 33 | class CodeGenFunction; |
| 34 | class CodeGenTypes; |
| 35 | class SwiftABIInfo; |
| 36 | |
| 37 | namespace swiftcall { |
| 38 | class SwiftAggLowering; |
| 39 | } |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 40 | |
Chris Lattner | 4b8585e | 2010-07-28 23:46:15 +0000 | [diff] [blame] | 41 | // FIXME: All of this stuff should be part of the target interface |
| 42 | // somehow. It is currently here because it is not clear how to factor |
| 43 | // the targets to support this, since the Targets currently live in a |
| 44 | // layer below types n'stuff. |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 45 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 46 | |
| 47 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 48 | /// passed or returned from functions. |
| 49 | class ABIInfo { |
| 50 | public: |
Chris Lattner | 2b03797 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 51 | CodeGen::CodeGenTypes &CGT; |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 52 | protected: |
| 53 | llvm::CallingConv::ID RuntimeCC; |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 54 | llvm::CallingConv::ID BuiltinCC; |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 55 | public: |
| 56 | ABIInfo(CodeGen::CodeGenTypes &cgt) |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 57 | : CGT(cgt), |
| 58 | RuntimeCC(llvm::CallingConv::C), |
| 59 | BuiltinCC(llvm::CallingConv::C) {} |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 60 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 61 | virtual ~ABIInfo(); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 62 | |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 63 | virtual bool supportsSwift() const { return false; } |
| 64 | |
Mark Lacey | 3825e83 | 2013-10-06 01:33:34 +0000 | [diff] [blame] | 65 | CodeGen::CGCXXABI &getCXXABI() const; |
Chris Lattner | 2b03797 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 66 | ASTContext &getContext() const; |
| 67 | llvm::LLVMContext &getVMContext() const; |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 68 | const llvm::DataLayout &getDataLayout() const; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 69 | const TargetInfo &getTarget() 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 | |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 77 | /// Return the calling convention to use for compiler builtins |
| 78 | llvm::CallingConv::ID getBuiltinCC() const { |
| 79 | return BuiltinCC; |
| 80 | } |
| 81 | |
Chris Lattner | 22326a1 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 82 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 83 | |
| 84 | /// EmitVAArg - Emit the target dependent code to load a value of |
| 85 | /// \arg Ty from the va_list pointed to by \arg VAListAddr. |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 86 | |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 87 | // FIXME: This is a gaping layering violation if we wanted to drop |
| 88 | // the ABI information any lower than CodeGen. Of course, for |
| 89 | // VAArg handling it has to be at this level; there is no way to |
| 90 | // abstract this out. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 91 | virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, |
| 92 | CodeGen::Address VAListAddr, |
| 93 | QualType Ty) const = 0; |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 94 | |
Nirav Dave | 9a8f97e | 2016-02-22 16:48:42 +0000 | [diff] [blame] | 95 | bool isAndroid() const; |
| 96 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 97 | /// Emit the target dependent code to load a value of |
| 98 | /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr. |
| 99 | virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, |
| 100 | CodeGen::Address VAListAddr, |
| 101 | QualType Ty) const; |
| 102 | |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 103 | virtual bool isHomogeneousAggregateBaseType(QualType Ty) const; |
| 104 | |
| 105 | virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, |
| 106 | uint64_t Members) const; |
| 107 | |
Petar Jovanovic | 1a3f965 | 2015-05-26 21:07:19 +0000 | [diff] [blame] | 108 | virtual bool shouldSignExtUnsignedType(QualType Ty) const; |
| 109 | |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 110 | bool isHomogeneousAggregate(QualType Ty, const Type *&Base, |
| 111 | uint64_t &Members) const; |
| 112 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 113 | /// A convenience method to return an indirect ABIArgInfo with an |
| 114 | /// expected alignment equal to the ABI alignment of the given type. |
| 115 | CodeGen::ABIArgInfo |
| 116 | getNaturalAlignIndirect(QualType Ty, bool ByRef = true, |
| 117 | bool Realign = false, |
| 118 | llvm::Type *Padding = nullptr) const; |
| 119 | |
| 120 | CodeGen::ABIArgInfo |
| 121 | getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 122 | |
| 123 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 124 | }; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 125 | |
| 126 | /// A refining implementation of ABIInfo for targets that support swiftcall. |
| 127 | /// |
| 128 | /// If we find ourselves wanting multiple such refinements, they'll probably |
| 129 | /// be independent refinements, and we should probably find another way |
| 130 | /// to do it than simple inheritance. |
| 131 | class SwiftABIInfo : public ABIInfo { |
| 132 | public: |
| 133 | SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {} |
| 134 | |
| 135 | bool supportsSwift() const final override { return true; } |
| 136 | |
| 137 | virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize, |
| 138 | ArrayRef<llvm::Type*> types, |
| 139 | bool asReturnValue) const = 0; |
| 140 | |
| 141 | virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, |
| 142 | llvm::Type *eltTy, |
| 143 | unsigned elts) const; |
| 144 | |
| 145 | static bool classof(const ABIInfo *info) { |
| 146 | return info->supportsSwift(); |
| 147 | } |
| 148 | }; |
| 149 | |
| 150 | } // end namespace CodeGen |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 151 | } // end namespace clang |
| 152 | |
| 153 | #endif |