Daniel Dunbar | d283e63 | 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 | e92e0ab | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 13 | namespace llvm { |
| 14 | class Type; |
| 15 | } |
| 16 | |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 17 | namespace clang { |
Daniel Dunbar | 749e36b | 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 | d283e63 | 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 | b1a60c0 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 37 | Direct, /// Pass the argument directly using the normal |
Daniel Dunbar | 88dde9b | 2009-02-05 08:00:50 +0000 | [diff] [blame^] | 38 | /// converted LLVM type. Complex and structure types |
| 39 | /// are passed using first class aggregates. |
| 40 | |
| 41 | Indirect, /// Pass the argument indirectly via a hidden pointer |
| 42 | /// with the specified alignment (0 indicates default |
| 43 | /// alignment). |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 51 | Expand, /// Only valid for aggregate argument types. The |
| 52 | /// structure should be expanded into consecutive |
| 53 | /// arguments for its constituent fields. Currently |
| 54 | /// expand is only allowed on structures whose fields |
| 55 | /// are all scalar types or are themselves expandable |
| 56 | /// types. |
| 57 | |
Daniel Dunbar | eec0262 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 58 | KindFirst=Direct, KindLast=Expand |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | private: |
| 62 | Kind TheKind; |
| 63 | const llvm::Type *TypeData; |
| 64 | unsigned UIntData; |
| 65 | |
| 66 | ABIArgInfo(Kind K, const llvm::Type *TD=0, |
| 67 | unsigned UI=0) : TheKind(K), |
| 68 | TypeData(TD), |
Daniel Dunbar | e6d233a | 2009-02-05 01:01:30 +0000 | [diff] [blame] | 69 | UIntData(UI) {} |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 70 | public: |
Daniel Dunbar | eec0262 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 71 | ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {} |
Daniel Dunbar | e92e0ab | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 72 | |
Daniel Dunbar | b1a60c0 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 73 | static ABIArgInfo getDirect() { |
| 74 | return ABIArgInfo(Direct); |
| 75 | } |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 76 | static ABIArgInfo getIgnore() { |
| 77 | return ABIArgInfo(Ignore); |
| 78 | } |
| 79 | static ABIArgInfo getCoerce(const llvm::Type *T) { |
| 80 | return ABIArgInfo(Coerce, T); |
| 81 | } |
Daniel Dunbar | 88dde9b | 2009-02-05 08:00:50 +0000 | [diff] [blame^] | 82 | static ABIArgInfo getIndirect(unsigned Alignment) { |
| 83 | return ABIArgInfo(Indirect, 0, Alignment); |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 84 | } |
| 85 | static ABIArgInfo getExpand() { |
| 86 | return ABIArgInfo(Expand); |
| 87 | } |
| 88 | |
| 89 | Kind getKind() const { return TheKind; } |
Daniel Dunbar | b1a60c0 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 90 | bool isDirect() const { return TheKind == Direct; } |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 91 | bool isIgnore() const { return TheKind == Ignore; } |
| 92 | bool isCoerce() const { return TheKind == Coerce; } |
Daniel Dunbar | 88dde9b | 2009-02-05 08:00:50 +0000 | [diff] [blame^] | 93 | bool isIndirect() const { return TheKind == Indirect; } |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 94 | bool isExpand() const { return TheKind == Expand; } |
| 95 | |
| 96 | // Coerce accessors |
| 97 | const llvm::Type *getCoerceToType() const { |
| 98 | assert(TheKind == Coerce && "Invalid kind!"); |
| 99 | return TypeData; |
| 100 | } |
| 101 | |
| 102 | // ByVal accessors |
Daniel Dunbar | 88dde9b | 2009-02-05 08:00:50 +0000 | [diff] [blame^] | 103 | unsigned getIndirectAlign() const { |
| 104 | assert(TheKind == Indirect && "Invalid kind!"); |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 105 | return UIntData; |
| 106 | } |
Daniel Dunbar | 9f4874e | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 107 | |
| 108 | void dump() const; |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 112 | /// passed or returned from functions. |
| 113 | class ABIInfo { |
| 114 | public: |
| 115 | virtual ~ABIInfo(); |
Daniel Dunbar | 749e36b | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 116 | |
| 117 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI, |
| 118 | ASTContext &Ctx) const = 0; |
Daniel Dunbar | d283e63 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 119 | }; |
| 120 | } // end namespace clang |
| 121 | |
| 122 | #endif |