]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/CodeGen/ABIInfo.h
MFV of tzdata2010o, r214716
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / CodeGen / ABIInfo.h
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
13 #include "clang/AST/Type.h"
14 #include "llvm/Type.h"
15
16 namespace llvm {
17   class Value;
18   class LLVMContext;
19   class TargetData;
20 }
21
22 namespace clang {
23   class ASTContext;
24
25   namespace CodeGen {
26     class CGFunctionInfo;
27     class CodeGenFunction;
28     class CodeGenTypes;
29   }
30
31   // FIXME: All of this stuff should be part of the target interface
32   // somehow. It is currently here because it is not clear how to factor
33   // the targets to support this, since the Targets currently live in a
34   // layer below types n'stuff.
35
36   /// ABIArgInfo - Helper class to encapsulate information about how a
37   /// specific C type should be passed to or returned from a function.
38   class ABIArgInfo {
39   public:
40     enum Kind {
41       /// Direct - Pass the argument directly using the normal converted LLVM
42       /// type, or by coercing to another specified type stored in
43       /// 'CoerceToType').  If an offset is specified (in UIntData), then the
44       /// argument passed is offset by some number of bytes in the memory
45       /// representation.
46       Direct,
47
48       /// Extend - Valid only for integer argument types. Same as 'direct'
49       /// but also emit a zero/sign extension attribute.
50       Extend,
51
52       /// Indirect - Pass the argument indirectly via a hidden pointer
53       /// with the specified alignment (0 indicates default alignment).
54       Indirect,
55
56       /// Ignore - Ignore the argument (treat as void). Useful for void and
57       /// empty structs.
58       Ignore,
59
60       /// Expand - Only valid for aggregate argument types. The structure should
61       /// be expanded into consecutive arguments for its constituent fields.
62       /// Currently expand is only allowed on structures whose fields
63       /// are all scalar types or are themselves expandable types.
64       Expand,
65
66       KindFirst=Direct, KindLast=Expand
67     };
68
69   private:
70     Kind TheKind;
71     llvm::PATypeHolder TypeData;
72     unsigned UIntData;
73     bool BoolData;
74
75     ABIArgInfo(Kind K, const llvm::Type *TD=0,
76                unsigned UI=0, bool B = false) 
77       : TheKind(K), TypeData(TD), UIntData(UI), BoolData(B) {}
78
79   public:
80     ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
81
82     static ABIArgInfo getDirect(const llvm::Type *T = 0, unsigned Offset = 0) {
83       return ABIArgInfo(Direct, T, Offset);
84     }
85     static ABIArgInfo getExtend(const llvm::Type *T = 0) {
86       return ABIArgInfo(Extend, T, 0);
87     }
88     static ABIArgInfo getIgnore() {
89       return ABIArgInfo(Ignore);
90     }
91     static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true) {
92       return ABIArgInfo(Indirect, 0, Alignment, ByVal);
93     }
94     static ABIArgInfo getExpand() {
95       return ABIArgInfo(Expand);
96     }
97
98     Kind getKind() const { return TheKind; }
99     bool isDirect() const { return TheKind == Direct; }
100     bool isExtend() const { return TheKind == Extend; }
101     bool isIgnore() const { return TheKind == Ignore; }
102     bool isIndirect() const { return TheKind == Indirect; }
103     bool isExpand() const { return TheKind == Expand; }
104
105     bool canHaveCoerceToType() const {
106       return TheKind == Direct || TheKind == Extend;
107     }
108     
109     // Direct/Extend accessors
110     unsigned getDirectOffset() const {
111       assert((isDirect() || isExtend()) && "Not a direct or extend kind");
112       return UIntData;
113     }
114     const llvm::Type *getCoerceToType() const {
115       assert(canHaveCoerceToType() && "Invalid kind!");
116       return TypeData;
117     }
118     
119     void setCoerceToType(const llvm::Type *T) {
120       assert(canHaveCoerceToType() && "Invalid kind!");
121       TypeData = T;
122     }
123     
124     // Indirect accessors
125     unsigned getIndirectAlign() const {
126       assert(TheKind == Indirect && "Invalid kind!");
127       return UIntData;
128     }
129
130     bool getIndirectByVal() const {
131       assert(TheKind == Indirect && "Invalid kind!");
132       return BoolData;
133     }
134     
135     void dump() const;
136   };
137
138   /// ABIInfo - Target specific hooks for defining how a type should be
139   /// passed or returned from functions.
140   class ABIInfo {
141   public:
142     CodeGen::CodeGenTypes &CGT;
143     
144     ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
145     virtual ~ABIInfo();
146     
147     ASTContext &getContext() const;
148     llvm::LLVMContext &getVMContext() const;
149     const llvm::TargetData &getTargetData() const;
150
151     virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
152
153     /// EmitVAArg - Emit the target dependent code to load a value of
154     /// \arg Ty from the va_list pointed to by \arg VAListAddr.
155
156     // FIXME: This is a gaping layering violation if we wanted to drop
157     // the ABI information any lower than CodeGen. Of course, for
158     // VAArg handling it has to be at this level; there is no way to
159     // abstract this out.
160     virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
161                                    CodeGen::CodeGenFunction &CGF) const = 0;
162   };
163 }  // end namespace clang
164
165 #endif