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" |
Chris Lattner | 958c53c | 2010-06-29 19:21:36 +0000 | [diff] [blame] | 14 | #include "llvm/Type.h" |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 15 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 16 | namespace llvm { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 17 | class Value; |
Benjamin Kramer | f21efe9 | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 18 | class LLVMContext; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 19 | class TargetData; |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 22 | namespace clang { |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 23 | class ASTContext; |
| 24 | |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 25 | namespace CodeGen { |
| 26 | class CGFunctionInfo; |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 27 | class CodeGenFunction; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 28 | class CodeGenTypes; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Chris Lattner | 2eb9cdd | 2010-07-28 23:46:15 +0000 | [diff] [blame] | 31 | // FIXME: All of this stuff should be part of the target interface |
| 32 | // somehow. It is currently here because it is not clear how to factor |
| 33 | // the targets to support this, since the Targets currently live in a |
| 34 | // layer below types n'stuff. |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 35 | |
| 36 | /// ABIArgInfo - Helper class to encapsulate information about how a |
| 37 | /// specific C type should be passed to or returned from a function. |
| 38 | class ABIArgInfo { |
| 39 | public: |
| 40 | enum Kind { |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 41 | Direct, /// Pass the argument directly using the normal converted LLVM |
| 42 | /// type, or by coercing to another specified type |
| 43 | /// (stored in 'CoerceToType'). |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 44 | |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 45 | Extend, /// Valid only for integer argument types. Same as 'direct' |
| 46 | /// but also emit a zero/sign extension attribute. |
| 47 | |
Daniel Dunbar | 11e383a | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 48 | Indirect, /// Pass the argument indirectly via a hidden pointer |
| 49 | /// with the specified alignment (0 indicates default |
| 50 | /// alignment). |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 51 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 52 | Ignore, /// Ignore the argument (treat as void). Useful for |
| 53 | /// void and empty structs. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 1ed7267 | 2010-07-29 06:44:09 +0000 | [diff] [blame] | 55 | Expand, /// Only valid for aggregate argument types. The |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 56 | /// structure should be expanded into consecutive |
| 57 | /// arguments for its constituent fields. Currently |
| 58 | /// expand is only allowed on structures whose fields |
| 59 | /// are all scalar types or are themselves expandable |
| 60 | /// types. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 61 | |
Daniel Dunbar | 0bcc521 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 62 | KindFirst=Direct, KindLast=Expand |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 63 | }; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 64 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 65 | private: |
| 66 | Kind TheKind; |
Chris Lattner | 958c53c | 2010-06-29 19:21:36 +0000 | [diff] [blame] | 67 | llvm::PATypeHolder TypeData; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 68 | unsigned UIntData; |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 69 | bool BoolData; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 70 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 71 | ABIArgInfo(Kind K, const llvm::Type *TD=0, |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 72 | unsigned UI=0, bool B = false) |
| 73 | : TheKind(K), TypeData(TD), UIntData(UI), BoolData(B) {} |
| 74 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 75 | public: |
Daniel Dunbar | 0bcc521 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 76 | ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {} |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 78 | static ABIArgInfo getDirect(const llvm::Type *T = 0) { |
| 79 | return ABIArgInfo(Direct, T); |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 80 | } |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame^] | 81 | static ABIArgInfo getExtend(const llvm::Type *T = 0) { |
| 82 | return ABIArgInfo(Extend, T); |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 83 | } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 84 | static ABIArgInfo getIgnore() { |
| 85 | return ABIArgInfo(Ignore); |
| 86 | } |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 87 | static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true) { |
| 88 | return ABIArgInfo(Indirect, 0, Alignment, ByVal); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 89 | } |
| 90 | static ABIArgInfo getExpand() { |
| 91 | return ABIArgInfo(Expand); |
| 92 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 93 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 94 | Kind getKind() const { return TheKind; } |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 95 | bool isDirect() const { return TheKind == Direct; } |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 96 | bool isExtend() const { return TheKind == Extend; } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 97 | bool isIgnore() const { return TheKind == Ignore; } |
Daniel Dunbar | 11e383a | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 98 | bool isIndirect() const { return TheKind == Indirect; } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 99 | bool isExpand() const { return TheKind == Expand; } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 101 | bool canHaveCoerceToType() const { |
| 102 | return TheKind == Direct || TheKind == Extend; |
| 103 | } |
| 104 | |
| 105 | // Direct/Extend accessors |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 106 | const llvm::Type *getCoerceToType() const { |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 107 | assert(canHaveCoerceToType() && "Invalid kind!"); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 108 | return TypeData; |
| 109 | } |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 110 | |
| 111 | void setCoerceToType(const llvm::Type *T) { |
| 112 | assert(canHaveCoerceToType() && "Invalid kind!"); |
| 113 | TypeData = T; |
| 114 | } |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 115 | // Indirect accessors |
Daniel Dunbar | 11e383a | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 116 | unsigned getIndirectAlign() const { |
| 117 | assert(TheKind == Indirect && "Invalid kind!"); |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 118 | return UIntData; |
| 119 | } |
Daniel Dunbar | 6f7279b | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 120 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 121 | bool getIndirectByVal() const { |
| 122 | assert(TheKind == Indirect && "Invalid kind!"); |
| 123 | return BoolData; |
| 124 | } |
| 125 | |
Daniel Dunbar | 6f7279b | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 126 | void dump() const; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 130 | /// passed or returned from functions. |
| 131 | class ABIInfo { |
| 132 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 133 | CodeGen::CodeGenTypes &CGT; |
| 134 | |
| 135 | ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {} |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 136 | virtual ~ABIInfo(); |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 137 | |
| 138 | ASTContext &getContext() const; |
| 139 | llvm::LLVMContext &getVMContext() const; |
| 140 | const llvm::TargetData &getTargetData() const; |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 141 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 142 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 143 | |
| 144 | /// EmitVAArg - Emit the target dependent code to load a value of |
| 145 | /// \arg Ty from the va_list pointed to by \arg VAListAddr. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 146 | |
Daniel Dunbar | b53e3e7 | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 147 | // FIXME: This is a gaping layering violation if we wanted to drop |
| 148 | // the ABI information any lower than CodeGen. Of course, for |
| 149 | // VAArg handling it has to be at this level; there is no way to |
| 150 | // abstract this out. |
| 151 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 152 | CodeGen::CodeGenFunction &CGF) const = 0; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 153 | }; |
| 154 | } // end namespace clang |
| 155 | |
| 156 | #endif |