ABIInfo.h revision 6bad2658b48264629db595f944a3fbe07f61b4e9
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 13namespace llvm { 14 class Type; 15} 16 17namespace clang { 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 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 { 37 Direct, /// Pass the argument directly using the normal 38 /// converted LLVM type. 39 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 63 KindFirst=Direct, KindLast=Expand 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: 76 ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {} 77 78 static ABIArgInfo getDirect() { 79 return ABIArgInfo(Direct); 80 } 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; } 98 bool isDirect() const { return TheKind == Direct; } 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 } 116 }; 117 118 /// ABIInfo - Target specific hooks for defining how a type should be 119 /// passed or returned from functions. 120 class ABIInfo { 121 public: 122 virtual ~ABIInfo(); 123 124 virtual void computeInfo(CodeGen::CGFunctionInfo &FI, 125 ASTContext &Ctx) const = 0; 126 }; 127} // end namespace clang 128 129#endif 130