Daniel Dunbar | 9eb5c6d | 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 | |
| 10 | #ifndef CLANG_CODEGEN_ABIINFO_H |
| 11 | #define CLANG_CODEGEN_ABIINFO_H |
| 12 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 13 | #include "clang/AST/Type.h" |
Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Type.h" |
John McCall | bd7370a | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 15 | #include "llvm/IR/CallingConv.h" |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 17 | namespace llvm { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 18 | class Value; |
Benjamin Kramer | f21efe9 | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 19 | class LLVMContext; |
Micah Villmow | 25a6a84 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 20 | class DataLayout; |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 23 | namespace clang { |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 24 | class ASTContext; |
John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 25 | class TargetInfo; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 26 | |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 27 | namespace CodeGen { |
Mark Lacey | 2363072 | 2013-10-06 01:33:34 +0000 | [diff] [blame] | 28 | class CGCXXABI; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 29 | class CGFunctionInfo; |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 30 | class CodeGenFunction; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 31 | class CodeGenTypes; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | 2eb9cdd | 2010-07-28 23:46:15 +0000 | [diff] [blame] | 34 | // FIXME: All of this stuff should be part of the target interface |
| 35 | // somehow. It is currently here because it is not clear how to factor |
| 36 | // the targets to support this, since the Targets currently live in a |
| 37 | // layer below types n'stuff. |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 38 | |
| 39 | /// ABIArgInfo - Helper class to encapsulate information about how a |
| 40 | /// specific C type should be passed to or returned from a function. |
| 41 | class ABIArgInfo { |
| 42 | public: |
| 43 | enum Kind { |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 44 | /// Direct - Pass the argument directly using the normal converted LLVM |
| 45 | /// type, or by coercing to another specified type stored in |
| 46 | /// 'CoerceToType'). If an offset is specified (in UIntData), then the |
| 47 | /// argument passed is offset by some number of bytes in the memory |
Akira Hatanaka | f0cc208 | 2012-01-07 00:25:33 +0000 | [diff] [blame] | 48 | /// representation. A dummy argument is emitted before the real argument |
| 49 | /// if the specified type stored in "PaddingType" is not zero. |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 50 | Direct, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 52 | /// Extend - Valid only for integer argument types. Same as 'direct' |
| 53 | /// but also emit a zero/sign extension attribute. |
| 54 | Extend, |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 56 | /// Indirect - Pass the argument indirectly via a hidden pointer |
| 57 | /// with the specified alignment (0 indicates default alignment). |
| 58 | Indirect, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 60 | /// Ignore - Ignore the argument (treat as void). Useful for void and |
| 61 | /// empty structs. |
| 62 | Ignore, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 63 | |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 64 | /// Expand - Only valid for aggregate argument types. The structure should |
| 65 | /// be expanded into consecutive arguments for its constituent fields. |
| 66 | /// Currently expand is only allowed on structures whose fields |
| 67 | /// are all scalar types or are themselves expandable types. |
| 68 | Expand, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 69 | |
Daniel Dunbar | 0bcc521 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 70 | KindFirst=Direct, KindLast=Expand |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 71 | }; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 72 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 73 | private: |
| 74 | Kind TheKind; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 75 | llvm::Type *TypeData; |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 76 | llvm::Type *PaddingType; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 77 | unsigned UIntData; |
Daniel Dunbar | cf3b6f2 | 2010-09-16 20:42:02 +0000 | [diff] [blame] | 78 | bool BoolData0; |
| 79 | bool BoolData1; |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 80 | bool InReg; |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 81 | bool PaddingInReg; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 82 | |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 83 | ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR, |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 84 | bool PIR, llvm::Type* P) |
Akira Hatanaka | f0cc208 | 2012-01-07 00:25:33 +0000 | [diff] [blame] | 85 | : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0), |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 86 | BoolData1(B1), InReg(IR), PaddingInReg(PIR) {} |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 87 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 88 | public: |
Daniel Dunbar | 0bcc521 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 89 | ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {} |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 90 | |
Akira Hatanaka | f0cc208 | 2012-01-07 00:25:33 +0000 | [diff] [blame] | 91 | static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0, |
| 92 | llvm::Type *Padding = 0) { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 93 | return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding); |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 94 | } |
Rafael Espindola | 0b4cc95 | 2012-10-19 05:04:37 +0000 | [diff] [blame] | 95 | static ABIArgInfo getDirectInReg(llvm::Type *T = 0) { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 96 | return ABIArgInfo(Direct, T, 0, false, false, true, false, 0); |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 97 | } |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 98 | static ABIArgInfo getExtend(llvm::Type *T = 0) { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 99 | return ABIArgInfo(Extend, T, 0, false, false, false, false, 0); |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 100 | } |
| 101 | static ABIArgInfo getExtendInReg(llvm::Type *T = 0) { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 102 | return ABIArgInfo(Extend, T, 0, false, false, true, false, 0); |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 103 | } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 104 | static ABIArgInfo getIgnore() { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 105 | return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 106 | } |
Daniel Dunbar | cf3b6f2 | 2010-09-16 20:42:02 +0000 | [diff] [blame] | 107 | static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true |
Tim Northover | c264e16 | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 108 | , bool Realign = false |
| 109 | , llvm::Type *Padding = 0) { |
| 110 | return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false, |
| 111 | Padding); |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 112 | } |
| 113 | static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true |
| 114 | , bool Realign = false) { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 115 | return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 116 | } |
| 117 | static ABIArgInfo getExpand() { |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 118 | return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0); |
| 119 | } |
| 120 | static ABIArgInfo getExpandWithPadding(bool PaddingInReg, |
| 121 | llvm::Type *Padding) { |
| 122 | return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg, |
| 123 | Padding); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 124 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 125 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 126 | Kind getKind() const { return TheKind; } |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 127 | bool isDirect() const { return TheKind == Direct; } |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 128 | bool isExtend() const { return TheKind == Extend; } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 129 | bool isIgnore() const { return TheKind == Ignore; } |
Daniel Dunbar | 11e383a | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 130 | bool isIndirect() const { return TheKind == Indirect; } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 131 | bool isExpand() const { return TheKind == Expand; } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 133 | bool canHaveCoerceToType() const { |
| 134 | return TheKind == Direct || TheKind == Extend; |
| 135 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 137 | // Direct/Extend accessors |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 138 | unsigned getDirectOffset() const { |
| 139 | assert((isDirect() || isExtend()) && "Not a direct or extend kind"); |
| 140 | return UIntData; |
| 141 | } |
Akira Hatanaka | f0cc208 | 2012-01-07 00:25:33 +0000 | [diff] [blame] | 142 | |
| 143 | llvm::Type *getPaddingType() const { |
| 144 | return PaddingType; |
| 145 | } |
| 146 | |
Rafael Espindola | e4aeeaa | 2012-10-24 01:59:00 +0000 | [diff] [blame] | 147 | bool getPaddingInReg() const { |
| 148 | return PaddingInReg; |
| 149 | } |
| 150 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 151 | llvm::Type *getCoerceToType() const { |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 152 | assert(canHaveCoerceToType() && "Invalid kind!"); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 153 | return TypeData; |
| 154 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 155 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 156 | void setCoerceToType(llvm::Type *T) { |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 157 | assert(canHaveCoerceToType() && "Invalid kind!"); |
| 158 | TypeData = T; |
| 159 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 160 | |
Rafael Espindola | b48280b | 2012-07-31 02:44:24 +0000 | [diff] [blame] | 161 | bool getInReg() const { |
| 162 | assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!"); |
| 163 | return InReg; |
| 164 | } |
| 165 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 166 | // Indirect accessors |
Daniel Dunbar | 11e383a | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 167 | unsigned getIndirectAlign() const { |
| 168 | assert(TheKind == Indirect && "Invalid kind!"); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 169 | return UIntData; |
| 170 | } |
Daniel Dunbar | 6f7279b | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 171 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 172 | bool getIndirectByVal() const { |
| 173 | assert(TheKind == Indirect && "Invalid kind!"); |
Daniel Dunbar | cf3b6f2 | 2010-09-16 20:42:02 +0000 | [diff] [blame] | 174 | return BoolData0; |
| 175 | } |
| 176 | |
| 177 | bool getIndirectRealign() const { |
| 178 | assert(TheKind == Indirect && "Invalid kind!"); |
| 179 | return BoolData1; |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 180 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 181 | |
Daniel Dunbar | 6f7279b | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 182 | void dump() const; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 186 | /// passed or returned from functions. |
| 187 | class ABIInfo { |
| 188 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 189 | CodeGen::CodeGenTypes &CGT; |
John McCall | bd7370a | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 190 | protected: |
| 191 | llvm::CallingConv::ID RuntimeCC; |
| 192 | public: |
| 193 | ABIInfo(CodeGen::CodeGenTypes &cgt) |
| 194 | : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {} |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 195 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 196 | virtual ~ABIInfo(); |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 197 | |
Mark Lacey | 2363072 | 2013-10-06 01:33:34 +0000 | [diff] [blame] | 198 | CodeGen::CGCXXABI &getCXXABI() const; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 199 | ASTContext &getContext() const; |
| 200 | llvm::LLVMContext &getVMContext() const; |
Micah Villmow | 25a6a84 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 201 | const llvm::DataLayout &getDataLayout() const; |
John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 202 | const TargetInfo &getTarget() const; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 203 | |
John McCall | bd7370a | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 204 | /// Return the calling convention to use for system runtime |
| 205 | /// functions. |
| 206 | llvm::CallingConv::ID getRuntimeCC() const { |
| 207 | return RuntimeCC; |
| 208 | } |
| 209 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 210 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 211 | |
| 212 | /// EmitVAArg - Emit the target dependent code to load a value of |
| 213 | /// \arg Ty from the va_list pointed to by \arg VAListAddr. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 214 | |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 215 | // FIXME: This is a gaping layering violation if we wanted to drop |
| 216 | // the ABI information any lower than CodeGen. Of course, for |
| 217 | // VAArg handling it has to be at this level; there is no way to |
| 218 | // abstract this out. |
| 219 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 220 | CodeGen::CodeGenFunction &CGF) const = 0; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 221 | }; |
| 222 | } // end namespace clang |
| 223 | |
| 224 | #endif |