blob: d343ffdbbe6da56748c4bd0c9511b718e33cf3ba [file] [log] [blame]
Daniel Dunbar9eb5c6d2009-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 Dunbar88c2fa92009-02-03 05:31:23 +000013namespace llvm {
14 class Type;
15}
16
Daniel Dunbar9eb5c6d2009-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 {
29 Default,
Daniel Dunbar46327aa2009-02-03 06:17:37 +000030
31 Direct, /// Pass the argument directly using the normal
32 /// converted LLVM type.
33
Daniel Dunbar9eb5c6d2009-02-03 01:05:53 +000034 StructRet, /// Only valid for return values. The return value
35 /// should be passed through a pointer to a caller
36 /// allocated location passed as an implicit first
37 /// argument to the function.
38
39 Ignore, /// Ignore the argument (treat as void). Useful for
40 /// void and empty structs.
41
42 Coerce, /// Only valid for aggregate return types, the argument
43 /// should be accessed by coercion to a provided type.
44
45 ByVal, /// Only valid for aggregate argument types. The
46 /// structure should be passed "byval" with the
47 /// specified alignment (0 indicates default
48 /// alignment).
49
50 Expand, /// Only valid for aggregate argument types. The
51 /// structure should be expanded into consecutive
52 /// arguments for its constituent fields. Currently
53 /// expand is only allowed on structures whose fields
54 /// are all scalar types or are themselves expandable
55 /// types.
56
57 KindFirst=Default, KindLast=Expand
58 };
59
60 private:
61 Kind TheKind;
62 const llvm::Type *TypeData;
63 unsigned UIntData;
64
65 ABIArgInfo(Kind K, const llvm::Type *TD=0,
66 unsigned UI=0) : TheKind(K),
67 TypeData(TD),
68 UIntData(0) {}
69 public:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000070 ABIArgInfo() : TheKind(Default), TypeData(0), UIntData(0) {}
71
Daniel Dunbar9eb5c6d2009-02-03 01:05:53 +000072 static ABIArgInfo getDefault() {
73 return ABIArgInfo(Default);
74 }
Daniel Dunbar46327aa2009-02-03 06:17:37 +000075 static ABIArgInfo getDirect() {
76 return ABIArgInfo(Direct);
77 }
Daniel Dunbar9eb5c6d2009-02-03 01:05:53 +000078 static ABIArgInfo getStructRet() {
79 return ABIArgInfo(StructRet);
80 }
81 static ABIArgInfo getIgnore() {
82 return ABIArgInfo(Ignore);
83 }
84 static ABIArgInfo getCoerce(const llvm::Type *T) {
85 return ABIArgInfo(Coerce, T);
86 }
87 static ABIArgInfo getByVal(unsigned Alignment) {
88 return ABIArgInfo(ByVal, 0, Alignment);
89 }
90 static ABIArgInfo getExpand() {
91 return ABIArgInfo(Expand);
92 }
93
94 Kind getKind() const { return TheKind; }
95 bool isDefault() const { return TheKind == Default; }
Daniel Dunbar46327aa2009-02-03 06:17:37 +000096 bool isDirect() const { return TheKind == Direct; }
Daniel Dunbar9eb5c6d2009-02-03 01:05:53 +000097 bool isStructRet() const { return TheKind == StructRet; }
98 bool isIgnore() const { return TheKind == Ignore; }
99 bool isCoerce() const { return TheKind == Coerce; }
100 bool isByVal() const { return TheKind == ByVal; }
101 bool isExpand() const { return TheKind == Expand; }
102
103 // Coerce accessors
104 const llvm::Type *getCoerceToType() const {
105 assert(TheKind == Coerce && "Invalid kind!");
106 return TypeData;
107 }
108
109 // ByVal accessors
110 unsigned getByValAlignment() const {
111 assert(TheKind == ByVal && "Invalid kind!");
112 return UIntData;
113 }
114 };
115
116 /// ABIInfo - Target specific hooks for defining how a type should be
117 /// passed or returned from functions.
118 class ABIInfo {
119 public:
120 virtual ~ABIInfo();
121
122 virtual ABIArgInfo classifyReturnType(QualType RetTy,
123 ASTContext &Context) const = 0;
124
125 virtual ABIArgInfo classifyArgumentType(QualType Ty,
126 ASTContext &Context) const = 0;
127 };
128} // end namespace clang
129
130#endif