2009-02-03 09:05:53 +08:00
|
|
|
//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_ABIINFO_H
|
|
|
|
#define CLANG_CODEGEN_ABIINFO_H
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Type.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-03 13:31:23 +08:00
|
|
|
namespace llvm {
|
2009-06-06 06:08:42 +08:00
|
|
|
class Value;
|
2009-08-12 01:46:57 +08:00
|
|
|
class LLVMContext;
|
2012-10-09 00:25:52 +08:00
|
|
|
class DataLayout;
|
2009-02-03 13:31:23 +08:00
|
|
|
}
|
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
namespace clang {
|
2009-02-03 14:51:18 +08:00
|
|
|
class ASTContext;
|
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
class CGFunctionInfo;
|
2009-02-11 05:44:36 +08:00
|
|
|
class CodeGenFunction;
|
2010-07-29 10:01:43 +08:00
|
|
|
class CodeGenTypes;
|
2009-02-03 14:51:18 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 07:46:15 +08:00
|
|
|
// FIXME: All of this stuff should be part of the target interface
|
|
|
|
// somehow. It is currently here because it is not clear how to factor
|
|
|
|
// the targets to support this, since the Targets currently live in a
|
|
|
|
// layer below types n'stuff.
|
2009-02-03 09:05:53 +08:00
|
|
|
|
|
|
|
/// ABIArgInfo - Helper class to encapsulate information about how a
|
|
|
|
/// specific C type should be passed to or returned from a function.
|
|
|
|
class ABIArgInfo {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
2010-07-30 12:02:24 +08:00
|
|
|
/// Direct - Pass the argument directly using the normal converted LLVM
|
|
|
|
/// type, or by coercing to another specified type stored in
|
|
|
|
/// 'CoerceToType'). If an offset is specified (in UIntData), then the
|
|
|
|
/// argument passed is offset by some number of bytes in the memory
|
2012-01-07 08:25:33 +08:00
|
|
|
/// representation. A dummy argument is emitted before the real argument
|
|
|
|
/// if the specified type stored in "PaddingType" is not zero.
|
2010-07-30 12:02:24 +08:00
|
|
|
Direct,
|
|
|
|
|
|
|
|
/// Extend - Valid only for integer argument types. Same as 'direct'
|
|
|
|
/// but also emit a zero/sign extension attribute.
|
|
|
|
Extend,
|
|
|
|
|
|
|
|
/// Indirect - Pass the argument indirectly via a hidden pointer
|
|
|
|
/// with the specified alignment (0 indicates default alignment).
|
|
|
|
Indirect,
|
|
|
|
|
|
|
|
/// Ignore - Ignore the argument (treat as void). Useful for void and
|
|
|
|
/// empty structs.
|
|
|
|
Ignore,
|
|
|
|
|
|
|
|
/// Expand - Only valid for aggregate argument types. The structure should
|
|
|
|
/// be expanded into consecutive arguments for its constituent fields.
|
|
|
|
/// Currently expand is only allowed on structures whose fields
|
|
|
|
/// are all scalar types or are themselves expandable types.
|
|
|
|
Expand,
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-03 14:30:17 +08:00
|
|
|
KindFirst=Direct, KindLast=Expand
|
2009-02-03 09:05:53 +08:00
|
|
|
};
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
private:
|
|
|
|
Kind TheKind;
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *TypeData;
|
2012-10-24 09:59:00 +08:00
|
|
|
llvm::Type *PaddingType;
|
2009-02-03 09:05:53 +08:00
|
|
|
unsigned UIntData;
|
2010-09-17 04:42:02 +08:00
|
|
|
bool BoolData0;
|
|
|
|
bool BoolData1;
|
2012-07-31 10:44:24 +08:00
|
|
|
bool InReg;
|
2012-10-24 09:59:00 +08:00
|
|
|
bool PaddingInReg;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2012-07-31 10:44:24 +08:00
|
|
|
ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
|
2012-10-24 09:59:00 +08:00
|
|
|
bool PIR, llvm::Type* P)
|
2012-01-07 08:25:33 +08:00
|
|
|
: TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
|
2012-10-24 09:59:00 +08:00
|
|
|
BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
|
2009-09-16 23:53:40 +08:00
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
public:
|
2009-02-03 14:30:17 +08:00
|
|
|
ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
|
2009-02-03 13:31:23 +08:00
|
|
|
|
2012-01-07 08:25:33 +08:00
|
|
|
static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
|
|
|
|
llvm::Type *Padding = 0) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
|
2012-07-31 10:44:24 +08:00
|
|
|
}
|
2012-10-19 13:04:37 +08:00
|
|
|
static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
|
2009-02-03 14:17:37 +08:00
|
|
|
}
|
2011-07-10 01:41:47 +08:00
|
|
|
static ABIArgInfo getExtend(llvm::Type *T = 0) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
|
2012-07-31 10:44:24 +08:00
|
|
|
}
|
|
|
|
static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
|
2009-06-06 17:36:29 +08:00
|
|
|
}
|
2009-02-03 09:05:53 +08:00
|
|
|
static ABIArgInfo getIgnore() {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
|
2009-02-03 09:05:53 +08:00
|
|
|
}
|
2010-09-17 04:42:02 +08:00
|
|
|
static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
|
|
|
|
, bool Realign = false) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false, 0);
|
2012-07-31 10:44:24 +08:00
|
|
|
}
|
|
|
|
static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
|
|
|
|
, bool Realign = false) {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
|
2009-02-03 09:05:53 +08:00
|
|
|
}
|
|
|
|
static ABIArgInfo getExpand() {
|
2012-10-24 09:59:00 +08:00
|
|
|
return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
|
|
|
|
}
|
|
|
|
static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
|
|
|
|
llvm::Type *Padding) {
|
|
|
|
return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
|
|
|
|
Padding);
|
2009-02-03 09:05:53 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-03 09:05:53 +08:00
|
|
|
Kind getKind() const { return TheKind; }
|
2009-02-03 14:17:37 +08:00
|
|
|
bool isDirect() const { return TheKind == Direct; }
|
2009-06-06 17:36:29 +08:00
|
|
|
bool isExtend() const { return TheKind == Extend; }
|
2009-02-03 09:05:53 +08:00
|
|
|
bool isIgnore() const { return TheKind == Ignore; }
|
2009-02-05 16:00:50 +08:00
|
|
|
bool isIndirect() const { return TheKind == Indirect; }
|
2009-02-03 09:05:53 +08:00
|
|
|
bool isExpand() const { return TheKind == Expand; }
|
2009-06-06 06:08:42 +08:00
|
|
|
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
bool canHaveCoerceToType() const {
|
|
|
|
return TheKind == Direct || TheKind == Extend;
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
// Direct/Extend accessors
|
2010-07-30 12:02:24 +08:00
|
|
|
unsigned getDirectOffset() const {
|
|
|
|
assert((isDirect() || isExtend()) && "Not a direct or extend kind");
|
|
|
|
return UIntData;
|
|
|
|
}
|
2012-01-07 08:25:33 +08:00
|
|
|
|
|
|
|
llvm::Type *getPaddingType() const {
|
|
|
|
return PaddingType;
|
|
|
|
}
|
|
|
|
|
2012-10-24 09:59:00 +08:00
|
|
|
bool getPaddingInReg() const {
|
|
|
|
return PaddingInReg;
|
|
|
|
}
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *getCoerceToType() const {
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
assert(canHaveCoerceToType() && "Invalid kind!");
|
2009-02-03 09:05:53 +08:00
|
|
|
return TypeData;
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
void setCoerceToType(llvm::Type *T) {
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
assert(canHaveCoerceToType() && "Invalid kind!");
|
|
|
|
TypeData = T;
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2012-07-31 10:44:24 +08:00
|
|
|
bool getInReg() const {
|
|
|
|
assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
|
|
|
|
return InReg;
|
|
|
|
}
|
|
|
|
|
2009-09-16 23:53:40 +08:00
|
|
|
// Indirect accessors
|
2009-02-05 16:00:50 +08:00
|
|
|
unsigned getIndirectAlign() const {
|
|
|
|
assert(TheKind == Indirect && "Invalid kind!");
|
2009-02-03 09:05:53 +08:00
|
|
|
return UIntData;
|
|
|
|
}
|
2009-02-05 07:24:38 +08:00
|
|
|
|
2009-09-16 23:53:40 +08:00
|
|
|
bool getIndirectByVal() const {
|
|
|
|
assert(TheKind == Indirect && "Invalid kind!");
|
2010-09-17 04:42:02 +08:00
|
|
|
return BoolData0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getIndirectRealign() const {
|
|
|
|
assert(TheKind == Indirect && "Invalid kind!");
|
|
|
|
return BoolData1;
|
2009-09-16 23:53:40 +08:00
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-02-05 07:24:38 +08:00
|
|
|
void dump() const;
|
2009-02-03 09:05:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// ABIInfo - Target specific hooks for defining how a type should be
|
|
|
|
/// passed or returned from functions.
|
|
|
|
class ABIInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
CodeGen::CodeGenTypes &CGT;
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
|
2009-02-03 09:05:53 +08:00
|
|
|
virtual ~ABIInfo();
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
ASTContext &getContext() const;
|
|
|
|
llvm::LLVMContext &getVMContext() const;
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &getDataLayout() const;
|
2009-02-03 14:51:18 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
|
2009-02-11 05:44:36 +08:00
|
|
|
|
|
|
|
/// EmitVAArg - Emit the target dependent code to load a value of
|
|
|
|
/// \arg Ty from the va_list pointed to by \arg VAListAddr.
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2009-02-11 05:44:36 +08:00
|
|
|
// FIXME: This is a gaping layering violation if we wanted to drop
|
|
|
|
// the ABI information any lower than CodeGen. Of course, for
|
|
|
|
// VAArg handling it has to be at this level; there is no way to
|
|
|
|
// abstract this out.
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGen::CodeGenFunction &CGF) const = 0;
|
2009-02-03 09:05:53 +08:00
|
|
|
};
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|