blob: a2d80ed78cadc8619508636a415fbe6c8420e378 [file] [log] [blame]
Daniel Dunbard283e632009-02-03 01:05:53 +00001//===----- 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 Dunbare92e0ab2009-02-03 05:31:23 +000013namespace llvm {
14 class Type;
15}
16
Daniel Dunbard283e632009-02-03 01:05:53 +000017namespace clang {
Daniel Dunbar749e36b2009-02-03 06:51:18 +000018 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 Dunbard283e632009-02-03 01:05:53 +000026 /* 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 Dunbarb1a60c02009-02-03 06:17:37 +000037 Direct, /// Pass the argument directly using the normal
38 /// converted LLVM type.
39
Daniel Dunbard283e632009-02-03 01:05:53 +000040 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 Dunbareec02622009-02-03 06:30:17 +000063 KindFirst=Direct, KindLast=Expand
Daniel Dunbard283e632009-02-03 01:05:53 +000064 };
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 Dunbareec02622009-02-03 06:30:17 +000076 ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000077
Daniel Dunbarb1a60c02009-02-03 06:17:37 +000078 static ABIArgInfo getDirect() {
79 return ABIArgInfo(Direct);
80 }
Daniel Dunbard283e632009-02-03 01:05:53 +000081 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 Dunbarb1a60c02009-02-03 06:17:37 +000098 bool isDirect() const { return TheKind == Direct; }
Daniel Dunbard283e632009-02-03 01:05:53 +000099 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();
Daniel Dunbar749e36b2009-02-03 06:51:18 +0000123
124 virtual void computeInfo(CodeGen::CGFunctionInfo &FI,
125 ASTContext &Ctx) const = 0;
Daniel Dunbard283e632009-02-03 01:05:53 +0000126 };
127} // end namespace clang
128
129#endif