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; // Currently allowed only for Direct.
78 ABIArgInfo(Kind K, llvm::Type *TD=0, unsigned UI=0,
79 bool B0 = false, bool B1 = false, llvm::Type* P = 0)
80 : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
84 ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
86 static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
87 llvm::Type *Padding = 0) {
88 return ABIArgInfo(Direct, T, Offset, false, false, Padding);
90 static ABIArgInfo getExtend(llvm::Type *T = 0) {
91 return ABIArgInfo(Extend, T, 0);
93 static ABIArgInfo getIgnore() {
94 return ABIArgInfo(Ignore);
96 static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
97 , bool Realign = false) {
98 return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign);
100 static ABIArgInfo getExpand() {
101 return ABIArgInfo(Expand);
104 Kind getKind() const { return TheKind; }
105 bool isDirect() const { return TheKind == Direct; }
106 bool isExtend() const { return TheKind == Extend; }
107 bool isIgnore() const { return TheKind == Ignore; }
108 bool isIndirect() const { return TheKind == Indirect; }
109 bool isExpand() const { return TheKind == Expand; }
111 bool canHaveCoerceToType() const {
112 return TheKind == Direct || TheKind == Extend;
115 // Direct/Extend accessors
116 unsigned getDirectOffset() const {
117 assert((isDirect() || isExtend()) && "Not a direct or extend kind");
121 llvm::Type *getPaddingType() const {
125 llvm::Type *getCoerceToType() const {
126 assert(canHaveCoerceToType() && "Invalid kind!");
130 void setCoerceToType(llvm::Type *T) {
131 assert(canHaveCoerceToType() && "Invalid kind!");
135 // Indirect accessors
136 unsigned getIndirectAlign() const {
137 assert(TheKind == Indirect && "Invalid kind!");
141 bool getIndirectByVal() const {
142 assert(TheKind == Indirect && "Invalid kind!");
146 bool getIndirectRealign() const {
147 assert(TheKind == Indirect && "Invalid kind!");
154 /// ABIInfo - Target specific hooks for defining how a type should be
155 /// passed or returned from functions.
158 CodeGen::CodeGenTypes &CGT;
160 ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
163 ASTContext &getContext() const;
164 llvm::LLVMContext &getVMContext() const;
165 const llvm::TargetData &getTargetData() const;
167 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
169 /// EmitVAArg - Emit the target dependent code to load a value of
170 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
172 // FIXME: This is a gaping layering violation if we wanted to drop
173 // the ABI information any lower than CodeGen. Of course, for
174 // VAArg handling it has to be at this level; there is no way to
175 // abstract this out.
176 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
177 CodeGen::CodeGenFunction &CGF) const = 0;
179 } // end namespace clang