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 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 13 | namespace llvm { |
| 14 | class Type; |
| 15 | } |
| 16 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 17 | namespace clang { |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 18 | class ASTContext; |
| 19 | |
| 20 | // FIXME: This is a layering issue if we want to move ABIInfo |
| 21 | // down. Fortunately CGFunctionInfo has no real tie to CodeGen. |
| 22 | namespace CodeGen { |
| 23 | class CGFunctionInfo; |
| 24 | } |
| 25 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 26 | /* FIXME: All of this stuff should be part of the target interface |
| 27 | somehow. It is currently here because it is not clear how to factor |
| 28 | the targets to support this, since the Targets currently live in a |
| 29 | layer below types n'stuff. |
| 30 | */ |
| 31 | |
| 32 | /// ABIArgInfo - Helper class to encapsulate information about how a |
| 33 | /// specific C type should be passed to or returned from a function. |
| 34 | class ABIArgInfo { |
| 35 | public: |
| 36 | enum Kind { |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 37 | Direct, /// Pass the argument directly using the normal |
| 38 | /// converted LLVM type. |
| 39 | |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 40 | StructRet, /// Only valid for return values. The return value |
| 41 | /// should be passed through a pointer to a caller |
| 42 | /// allocated location passed as an implicit first |
| 43 | /// argument to the function. |
| 44 | |
| 45 | Ignore, /// Ignore the argument (treat as void). Useful for |
| 46 | /// void and empty structs. |
| 47 | |
| 48 | Coerce, /// Only valid for aggregate return types, the argument |
| 49 | /// should be accessed by coercion to a provided type. |
| 50 | |
| 51 | ByVal, /// Only valid for aggregate argument types. The |
| 52 | /// structure should be passed "byval" with the |
| 53 | /// specified alignment (0 indicates default |
| 54 | /// alignment). |
| 55 | |
| 56 | Expand, /// Only valid for aggregate argument types. The |
| 57 | /// structure should be expanded into consecutive |
| 58 | /// arguments for its constituent fields. Currently |
| 59 | /// expand is only allowed on structures whose fields |
| 60 | /// are all scalar types or are themselves expandable |
| 61 | /// types. |
| 62 | |
Daniel Dunbar | 0bcc521 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 63 | KindFirst=Direct, KindLast=Expand |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | private: |
| 67 | Kind TheKind; |
| 68 | const llvm::Type *TypeData; |
| 69 | unsigned UIntData; |
| 70 | |
| 71 | ABIArgInfo(Kind K, const llvm::Type *TD=0, |
| 72 | unsigned UI=0) : TheKind(K), |
| 73 | TypeData(TD), |
| 74 | UIntData(0) {} |
| 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 | |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 78 | static ABIArgInfo getDirect() { |
| 79 | return ABIArgInfo(Direct); |
| 80 | } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 81 | static ABIArgInfo getStructRet() { |
| 82 | return ABIArgInfo(StructRet); |
| 83 | } |
| 84 | static ABIArgInfo getIgnore() { |
| 85 | return ABIArgInfo(Ignore); |
| 86 | } |
| 87 | static ABIArgInfo getCoerce(const llvm::Type *T) { |
| 88 | return ABIArgInfo(Coerce, T); |
| 89 | } |
| 90 | static ABIArgInfo getByVal(unsigned Alignment) { |
| 91 | return ABIArgInfo(ByVal, 0, Alignment); |
| 92 | } |
| 93 | static ABIArgInfo getExpand() { |
| 94 | return ABIArgInfo(Expand); |
| 95 | } |
| 96 | |
| 97 | Kind getKind() const { return TheKind; } |
Daniel Dunbar | 46327aa | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 98 | bool isDirect() const { return TheKind == Direct; } |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 99 | bool isStructRet() const { return TheKind == StructRet; } |
| 100 | bool isIgnore() const { return TheKind == Ignore; } |
| 101 | bool isCoerce() const { return TheKind == Coerce; } |
| 102 | bool isByVal() const { return TheKind == ByVal; } |
| 103 | bool isExpand() const { return TheKind == Expand; } |
| 104 | |
| 105 | // Coerce accessors |
| 106 | const llvm::Type *getCoerceToType() const { |
| 107 | assert(TheKind == Coerce && "Invalid kind!"); |
| 108 | return TypeData; |
| 109 | } |
| 110 | |
| 111 | // ByVal accessors |
| 112 | unsigned getByValAlignment() const { |
| 113 | assert(TheKind == ByVal && "Invalid kind!"); |
| 114 | return UIntData; |
| 115 | } |
Daniel Dunbar | 6f7279b | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 116 | |
| 117 | void dump() const; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 121 | /// passed or returned from functions. |
| 122 | class ABIInfo { |
| 123 | public: |
| 124 | virtual ~ABIInfo(); |
Daniel Dunbar | 6bad265 | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 125 | |
| 126 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI, |
| 127 | ASTContext &Ctx) const = 0; |
Daniel Dunbar | 9eb5c6d | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 128 | }; |
| 129 | } // end namespace clang |
| 130 | |
| 131 | #endif |