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