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
48 /// Extend - Valid only for integer argument types. Same as 'direct'
49 /// but also emit a zero/sign extension attribute.
52 /// Indirect - Pass the argument indirectly via a hidden pointer
53 /// with the specified alignment (0 indicates default alignment).
56 /// Ignore - Ignore the argument (treat as void). Useful for void and
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.
66 KindFirst=Direct, KindLast=Expand
76 ABIArgInfo(Kind K, llvm::Type *TD=0,
77 unsigned UI=0, bool B0 = false, bool B1 = false)
78 : TheKind(K), TypeData(TD), UIntData(UI), BoolData0(B0), BoolData1(B1) {}
81 ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
83 static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0) {
84 return ABIArgInfo(Direct, T, Offset);
86 static ABIArgInfo getExtend(llvm::Type *T = 0) {
87 return ABIArgInfo(Extend, T, 0);
89 static ABIArgInfo getIgnore() {
90 return ABIArgInfo(Ignore);
92 static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
93 , bool Realign = false) {
94 return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign);
96 static ABIArgInfo getExpand() {
97 return ABIArgInfo(Expand);
100 Kind getKind() const { return TheKind; }
101 bool isDirect() const { return TheKind == Direct; }
102 bool isExtend() const { return TheKind == Extend; }
103 bool isIgnore() const { return TheKind == Ignore; }
104 bool isIndirect() const { return TheKind == Indirect; }
105 bool isExpand() const { return TheKind == Expand; }
107 bool canHaveCoerceToType() const {
108 return TheKind == Direct || TheKind == Extend;
111 // Direct/Extend accessors
112 unsigned getDirectOffset() const {
113 assert((isDirect() || isExtend()) && "Not a direct or extend kind");
116 llvm::Type *getCoerceToType() const {
117 assert(canHaveCoerceToType() && "Invalid kind!");
121 void setCoerceToType(llvm::Type *T) {
122 assert(canHaveCoerceToType() && "Invalid kind!");
126 // Indirect accessors
127 unsigned getIndirectAlign() const {
128 assert(TheKind == Indirect && "Invalid kind!");
132 bool getIndirectByVal() const {
133 assert(TheKind == Indirect && "Invalid kind!");
137 bool getIndirectRealign() const {
138 assert(TheKind == Indirect && "Invalid kind!");
145 /// ABIInfo - Target specific hooks for defining how a type should be
146 /// passed or returned from functions.
149 CodeGen::CodeGenTypes &CGT;
151 ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
154 ASTContext &getContext() const;
155 llvm::LLVMContext &getVMContext() const;
156 const llvm::TargetData &getTargetData() const;
158 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
160 /// EmitVAArg - Emit the target dependent code to load a value of
161 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
163 // FIXME: This is a gaping layering violation if we wanted to drop
164 // the ABI information any lower than CodeGen. Of course, for
165 // VAArg handling it has to be at this level; there is no way to
166 // abstract this out.
167 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
168 CodeGen::CodeGenFunction &CGF) const = 0;
170 } // end namespace clang