blob: 4b33c4e8065d5e810976762a9b6080bf7c28bbb9 [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
13namespace clang {
14 /* FIXME: All of this stuff should be part of the target interface
15 somehow. It is currently here because it is not clear how to factor
16 the targets to support this, since the Targets currently live in a
17 layer below types n'stuff.
18 */
19
20 /// ABIArgInfo - Helper class to encapsulate information about how a
21 /// specific C type should be passed to or returned from a function.
22 class ABIArgInfo {
23 public:
24 enum Kind {
25 Default,
26 StructRet, /// Only valid for return values. The return value
27 /// should be passed through a pointer to a caller
28 /// allocated location passed as an implicit first
29 /// argument to the function.
30
31 Ignore, /// Ignore the argument (treat as void). Useful for
32 /// void and empty structs.
33
34 Coerce, /// Only valid for aggregate return types, the argument
35 /// should be accessed by coercion to a provided type.
36
37 ByVal, /// Only valid for aggregate argument types. The
38 /// structure should be passed "byval" with the
39 /// specified alignment (0 indicates default
40 /// alignment).
41
42 Expand, /// Only valid for aggregate argument types. The
43 /// structure should be expanded into consecutive
44 /// arguments for its constituent fields. Currently
45 /// expand is only allowed on structures whose fields
46 /// are all scalar types or are themselves expandable
47 /// types.
48
49 KindFirst=Default, KindLast=Expand
50 };
51
52 private:
53 Kind TheKind;
54 const llvm::Type *TypeData;
55 unsigned UIntData;
56
57 ABIArgInfo(Kind K, const llvm::Type *TD=0,
58 unsigned UI=0) : TheKind(K),
59 TypeData(TD),
60 UIntData(0) {}
61 public:
62 static ABIArgInfo getDefault() {
63 return ABIArgInfo(Default);
64 }
65 static ABIArgInfo getStructRet() {
66 return ABIArgInfo(StructRet);
67 }
68 static ABIArgInfo getIgnore() {
69 return ABIArgInfo(Ignore);
70 }
71 static ABIArgInfo getCoerce(const llvm::Type *T) {
72 return ABIArgInfo(Coerce, T);
73 }
74 static ABIArgInfo getByVal(unsigned Alignment) {
75 return ABIArgInfo(ByVal, 0, Alignment);
76 }
77 static ABIArgInfo getExpand() {
78 return ABIArgInfo(Expand);
79 }
80
81 Kind getKind() const { return TheKind; }
82 bool isDefault() const { return TheKind == Default; }
83 bool isStructRet() const { return TheKind == StructRet; }
84 bool isIgnore() const { return TheKind == Ignore; }
85 bool isCoerce() const { return TheKind == Coerce; }
86 bool isByVal() const { return TheKind == ByVal; }
87 bool isExpand() const { return TheKind == Expand; }
88
89 // Coerce accessors
90 const llvm::Type *getCoerceToType() const {
91 assert(TheKind == Coerce && "Invalid kind!");
92 return TypeData;
93 }
94
95 // ByVal accessors
96 unsigned getByValAlignment() const {
97 assert(TheKind == ByVal && "Invalid kind!");
98 return UIntData;
99 }
100 };
101
102 /// ABIInfo - Target specific hooks for defining how a type should be
103 /// passed or returned from functions.
104 class ABIInfo {
105 public:
106 virtual ~ABIInfo();
107
108 virtual ABIArgInfo classifyReturnType(QualType RetTy,
109 ASTContext &Context) const = 0;
110
111 virtual ABIArgInfo classifyArgumentType(QualType Ty,
112 ASTContext &Context) const = 0;
113 };
114} // end namespace clang
115
116#endif