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