Daniel Dunbar | 6d6b0d3 | 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 | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 13 | #include "clang/AST/Type.h" |
Chris Lattner | cccaad9 | 2010-06-29 19:21:36 +0000 | [diff] [blame] | 14 | #include "llvm/Type.h" |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 15 | |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 16 | namespace llvm { |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 17 | class Value; |
Benjamin Kramer | 9cd050a | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 18 | class LLVMContext; |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 21 | namespace clang { |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 22 | class ASTContext; |
| 23 | |
| 24 | // FIXME: This is a layering issue if we want to move ABIInfo |
| 25 | // down. Fortunately CGFunctionInfo has no real tie to CodeGen. |
| 26 | namespace CodeGen { |
| 27 | class CGFunctionInfo; |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 28 | class CodeGenFunction; |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Chris Lattner | 4b8585e | 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 | 6d6b0d3 | 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 { |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 41 | Direct, /// Pass the argument directly using the normal |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 42 | /// converted LLVM type. Complex and structure types |
| 43 | /// are passed using first class aggregates. |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 44 | |
Anton Korobeynikov | 18adbf5 | 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 | b8b1c67 | 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 | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 51 | |
Daniel Dunbar | 6d6b0d3 | 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 | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 54 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 55 | Coerce, /// Only valid for aggregate return types, the argument |
| 56 | /// should be accessed by coercion to a provided type. |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 57 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 58 | Expand, /// Only valid for aggregate argument types. The |
| 59 | /// structure should be expanded into consecutive |
| 60 | /// arguments for its constituent fields. Currently |
| 61 | /// expand is only allowed on structures whose fields |
| 62 | /// are all scalar types or are themselves expandable |
| 63 | /// types. |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 64 | |
Daniel Dunbar | 0136282 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 65 | KindFirst=Direct, KindLast=Expand |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 66 | }; |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 67 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 68 | private: |
| 69 | Kind TheKind; |
Chris Lattner | cccaad9 | 2010-06-29 19:21:36 +0000 | [diff] [blame] | 70 | llvm::PATypeHolder TypeData; |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 71 | unsigned UIntData; |
Anders Carlsson | 20759ad | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 72 | bool BoolData; |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 73 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 74 | ABIArgInfo(Kind K, const llvm::Type *TD=0, |
Anders Carlsson | 20759ad | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 75 | unsigned UI=0, bool B = false) |
| 76 | : TheKind(K), TypeData(TD), UIntData(UI), BoolData(B) {} |
| 77 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 78 | public: |
Daniel Dunbar | 0136282 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 79 | ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {} |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 80 | |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 81 | static ABIArgInfo getDirect() { |
| 82 | return ABIArgInfo(Direct); |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 83 | } |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 84 | static ABIArgInfo getExtend() { |
| 85 | return ABIArgInfo(Extend); |
| 86 | } |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 87 | static ABIArgInfo getIgnore() { |
| 88 | return ABIArgInfo(Ignore); |
| 89 | } |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 90 | static ABIArgInfo getCoerce(const llvm::Type *T) { |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 91 | return ABIArgInfo(Coerce, T); |
| 92 | } |
Anders Carlsson | 20759ad | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 93 | static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true) { |
| 94 | return ABIArgInfo(Indirect, 0, Alignment, ByVal); |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 95 | } |
| 96 | static ABIArgInfo getExpand() { |
| 97 | return ABIArgInfo(Expand); |
| 98 | } |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 99 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 100 | Kind getKind() const { return TheKind; } |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 101 | bool isDirect() const { return TheKind == Direct; } |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 102 | bool isExtend() const { return TheKind == Extend; } |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 103 | bool isIgnore() const { return TheKind == Ignore; } |
| 104 | bool isCoerce() const { return TheKind == Coerce; } |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 105 | bool isIndirect() const { return TheKind == Indirect; } |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 106 | bool isExpand() const { return TheKind == Expand; } |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 107 | |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 108 | // Coerce accessors |
| 109 | const llvm::Type *getCoerceToType() const { |
| 110 | assert(TheKind == Coerce && "Invalid kind!"); |
| 111 | return TypeData; |
| 112 | } |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 113 | |
Anders Carlsson | 20759ad | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 114 | // Indirect accessors |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 115 | unsigned getIndirectAlign() const { |
| 116 | assert(TheKind == Indirect && "Invalid kind!"); |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 117 | return UIntData; |
| 118 | } |
Daniel Dunbar | 56e7552 | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 119 | |
Anders Carlsson | 20759ad | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 120 | bool getIndirectByVal() const { |
| 121 | assert(TheKind == Indirect && "Invalid kind!"); |
| 122 | return BoolData; |
| 123 | } |
| 124 | |
Daniel Dunbar | 56e7552 | 2009-02-04 23:24:38 +0000 | [diff] [blame] | 125 | void dump() const; |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 129 | /// passed or returned from functions. |
| 130 | class ABIInfo { |
| 131 | public: |
| 132 | virtual ~ABIInfo(); |
Daniel Dunbar | 32931eb | 2009-02-03 06:51:18 +0000 | [diff] [blame] | 133 | |
| 134 | virtual void computeInfo(CodeGen::CGFunctionInfo &FI, |
Owen Anderson | 170229f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 135 | ASTContext &Ctx, |
Chris Lattner | 1d7c9f7 | 2010-06-29 01:08:48 +0000 | [diff] [blame] | 136 | llvm::LLVMContext &VMContext, |
| 137 | // This is the preferred type for argument lowering |
| 138 | // which can be used to generate better IR. |
| 139 | const llvm::Type *const *PrefTypes = 0, |
| 140 | unsigned NumPrefTypes = 0) const = 0; |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 141 | |
| 142 | /// EmitVAArg - Emit the target dependent code to load a value of |
| 143 | /// \arg Ty from the va_list pointed to by \arg VAListAddr. |
Anton Korobeynikov | 244360d | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 144 | |
Daniel Dunbar | e46506e | 2009-02-10 21:44:36 +0000 | [diff] [blame] | 145 | // FIXME: This is a gaping layering violation if we wanted to drop |
| 146 | // the ABI information any lower than CodeGen. Of course, for |
| 147 | // VAArg handling it has to be at this level; there is no way to |
| 148 | // abstract this out. |
| 149 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 150 | CodeGen::CodeGenFunction &CGF) const = 0; |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 151 | }; |
| 152 | } // end namespace clang |
| 153 | |
| 154 | #endif |