1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_CODEGEN_ABIINFO_H
11 #define CLANG_CODEGEN_ABIINFO_H
13 #include "clang/AST/Type.h"
14 #include "llvm/Type.h"
27 class CodeGenFunction;
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.
36 /// ABIArgInfo - Helper class to encapsulate information about how a
37 /// specific C type should be passed to or returned from a function.
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. A dummy argument is emitted before the real argument
46 /// if the specified type stored in "PaddingType" is not zero.
49 /// Extend - Valid only for integer argument types. Same as 'direct'
50 /// but also emit a zero/sign extension attribute.
53 /// Indirect - Pass the argument indirectly via a hidden pointer
54 /// with the specified alignment (0 indicates default alignment).
57 /// Ignore - Ignore the argument (treat as void). Useful for void and
61 /// Expand - Only valid for aggregate argument types. The structure should
62 /// be expanded into consecutive arguments for its constituent fields.
63 /// Currently expand is only allowed on structures whose fields
64 /// are all scalar types or are themselves expandable types.
67 KindFirst=Direct, KindLast=Expand
73 llvm::Type *PaddingType;
80 ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
81 bool PIR, llvm::Type* P)
82 : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
83 BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
86 ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
88 static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
89 llvm::Type *Padding = 0) {
90 return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
92 static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
93 return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
95 static ABIArgInfo getExtend(llvm::Type *T = 0) {
96 return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
98 static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
99 return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
101 static ABIArgInfo getIgnore() {
102 return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
104 static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
105 , bool Realign = false) {
106 return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false, 0);
108 static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
109 , bool Realign = false) {
110 return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
112 static ABIArgInfo getExpand() {
113 return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
115 static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
116 llvm::Type *Padding) {
117 return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
121 Kind getKind() const { return TheKind; }
122 bool isDirect() const { return TheKind == Direct; }
123 bool isExtend() const { return TheKind == Extend; }
124 bool isIgnore() const { return TheKind == Ignore; }
125 bool isIndirect() const { return TheKind == Indirect; }
126 bool isExpand() const { return TheKind == Expand; }
128 bool canHaveCoerceToType() const {
129 return TheKind == Direct || TheKind == Extend;
132 // Direct/Extend accessors
133 unsigned getDirectOffset() const {
134 assert((isDirect() || isExtend()) && "Not a direct or extend kind");
138 llvm::Type *getPaddingType() const {
142 bool getPaddingInReg() const {
146 llvm::Type *getCoerceToType() const {
147 assert(canHaveCoerceToType() && "Invalid kind!");
151 void setCoerceToType(llvm::Type *T) {
152 assert(canHaveCoerceToType() && "Invalid kind!");
156 bool getInReg() const {
157 assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
161 // Indirect accessors
162 unsigned getIndirectAlign() const {
163 assert(TheKind == Indirect && "Invalid kind!");
167 bool getIndirectByVal() const {
168 assert(TheKind == Indirect && "Invalid kind!");
172 bool getIndirectRealign() const {
173 assert(TheKind == Indirect && "Invalid kind!");
180 /// ABIInfo - Target specific hooks for defining how a type should be
181 /// passed or returned from functions.
184 CodeGen::CodeGenTypes &CGT;
186 ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
189 ASTContext &getContext() const;
190 llvm::LLVMContext &getVMContext() const;
191 const llvm::DataLayout &getDataLayout() const;
193 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
195 /// EmitVAArg - Emit the target dependent code to load a value of
196 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
198 // FIXME: This is a gaping layering violation if we wanted to drop
199 // the ABI information any lower than CodeGen. Of course, for
200 // VAArg handling it has to be at this level; there is no way to
201 // abstract this out.
202 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
203 CodeGen::CodeGenFunction &CGF) const = 0;
205 } // end namespace clang