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