2007-06-02 02:02:12 +08:00
|
|
|
//===--- CGExpr.cpp - Emit LLVM Code from Expressions ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-02 02:02:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code to emit Expr nodes as LLVM code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
2007-06-20 12:44:43 +08:00
|
|
|
#include "CodeGenModule.h"
|
2007-06-02 02:02:12 +08:00
|
|
|
#include "clang/AST/AST.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
2007-06-06 12:54:52 +08:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/GlobalVariable.h"
|
Add a hack (mirroring llvm-gcc) to pointer difference
codegen to compile:
int test(int *A, int *B) {
return A-B;
}
into:
_test:
movl 4(%esp), %eax
subl 8(%esp), %eax
sarl $2, %eax
ret
instead of:
_test:
movl 4(%esp), %eax
subl 8(%esp), %eax
movl %eax, %ecx
sarl $31, %ecx
shrl $30, %ecx
addl %ecx, %eax
sarl $2, %eax
ret
llvm-svn: 39902
2007-07-16 13:43:05 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2007-06-02 02:02:12 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2007-06-03 03:33:17 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Miscellaneous Helper Methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2007-06-23 05:44:33 +08:00
|
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
|
|
/// block.
|
|
|
|
llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(const llvm::Type *Ty,
|
|
|
|
const char *Name) {
|
|
|
|
return new llvm::AllocaInst(Ty, 0, Name, AllocaInsertPt);
|
|
|
|
}
|
2007-06-06 04:53:16 +08:00
|
|
|
|
|
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|
|
|
|
/// expression and compare the result against zero, returning an Int1Ty value.
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) {
|
2007-08-27 00:46:58 +08:00
|
|
|
QualType BoolTy = getContext().BoolTy;
|
|
|
|
if (!E->getType()->isComplexType())
|
|
|
|
return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy);
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2007-08-27 00:46:58 +08:00
|
|
|
return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(),BoolTy);
|
2007-06-03 03:33:17 +08:00
|
|
|
}
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
/// EmitAnyExpr - Emit code to compute the specified expression which can have
|
|
|
|
/// any type. The result is returned as an RValue struct. If this is an
|
|
|
|
/// aggregate expression, the aggloc/agglocvolatile arguments indicate where
|
|
|
|
/// the result should be returned.
|
|
|
|
RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc,
|
|
|
|
bool isAggLocVolatile) {
|
|
|
|
if (!hasAggregateLLVMType(E->getType()))
|
|
|
|
return RValue::get(EmitScalarExpr(E));
|
|
|
|
else if (E->getType()->isComplexType())
|
|
|
|
return RValue::getComplex(EmitComplexExpr(E));
|
|
|
|
|
|
|
|
EmitAggExpr(E, AggLoc, isAggLocVolatile);
|
|
|
|
return RValue::getAggregate(AggLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-03 03:47:04 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-02 13:24:33 +08:00
|
|
|
// LValue Expression Emission
|
2007-06-03 03:47:04 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-02 13:24:33 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLValue - Emit code to compute a designator that specifies the location
|
|
|
|
/// of the expression.
|
|
|
|
///
|
|
|
|
/// This can return one of two things: a simple address or a bitfield
|
|
|
|
/// reference. In either case, the LLVM Value* in the LValue structure is
|
|
|
|
/// guaranteed to be an LLVM pointer type.
|
|
|
|
///
|
|
|
|
/// If this returns a bitfield reference, nothing about the pointee type of
|
|
|
|
/// the LLVM value is known: For example, it may not be a pointer to an
|
|
|
|
/// integer.
|
|
|
|
///
|
|
|
|
/// If this returns a normal address, and if the lvalue's C type is fixed
|
|
|
|
/// size, this method guarantees that the returned pointer type will point to
|
|
|
|
/// an LLVM type of the same size of the lvalue's type. If the lvalue has a
|
|
|
|
/// variable length type, this is not possible.
|
|
|
|
///
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue CodeGenFunction::EmitLValue(const Expr *E) {
|
|
|
|
switch (E->getStmtClass()) {
|
2007-08-26 13:06:40 +08:00
|
|
|
default: {
|
2007-12-02 09:49:16 +08:00
|
|
|
WarnUnsupported(E, "l-value expression");
|
2007-12-17 09:11:20 +08:00
|
|
|
llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
|
2007-08-26 13:06:40 +08:00
|
|
|
return LValue::MakeAddr(llvm::UndefValue::get(Ty));
|
|
|
|
}
|
2007-06-02 13:24:33 +08:00
|
|
|
|
2007-12-29 13:02:41 +08:00
|
|
|
case Expr::CallExprClass: return EmitCallExprLValue(cast<CallExpr>(E));
|
2007-06-02 13:24:33 +08:00
|
|
|
case Expr::DeclRefExprClass: return EmitDeclRefLValue(cast<DeclRefExpr>(E));
|
2007-06-05 11:59:43 +08:00
|
|
|
case Expr::ParenExprClass:return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
|
2007-07-21 13:21:51 +08:00
|
|
|
case Expr::PreDefinedExprClass:
|
|
|
|
return EmitPreDefinedLValue(cast<PreDefinedExpr>(E));
|
2007-06-06 12:54:52 +08:00
|
|
|
case Expr::StringLiteralClass:
|
|
|
|
return EmitStringLiteralLValue(cast<StringLiteral>(E));
|
2007-06-06 04:53:16 +08:00
|
|
|
|
|
|
|
case Expr::UnaryOperatorClass:
|
|
|
|
return EmitUnaryOpLValue(cast<UnaryOperator>(E));
|
2007-06-09 07:31:14 +08:00
|
|
|
case Expr::ArraySubscriptExprClass:
|
|
|
|
return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
|
2007-08-04 01:31:20 +08:00
|
|
|
case Expr::OCUVectorElementExprClass:
|
|
|
|
return EmitOCUVectorElementExpr(cast<OCUVectorElementExpr>(E));
|
2007-10-24 04:28:39 +08:00
|
|
|
case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
|
2007-06-02 13:24:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLoadOfLValue - Given an expression that represents a value lvalue,
|
|
|
|
/// this method emits the address of the lvalue, then loads the result as an
|
|
|
|
/// rvalue, returning the rvalue.
|
2007-06-30 00:31:29 +08:00
|
|
|
RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
|
2007-07-11 05:17:59 +08:00
|
|
|
if (LV.isSimple()) {
|
|
|
|
llvm::Value *Ptr = LV.getAddress();
|
|
|
|
const llvm::Type *EltTy =
|
|
|
|
cast<llvm::PointerType>(Ptr->getType())->getElementType();
|
|
|
|
|
|
|
|
// Simple scalar l-value.
|
2008-01-30 15:01:17 +08:00
|
|
|
if (EltTy->isFirstClassType()) {
|
|
|
|
llvm::Value *V = Builder.CreateLoad(Ptr, "tmp");
|
|
|
|
|
|
|
|
// Bool can have different representation in memory than in registers.
|
|
|
|
if (ExprType->isBooleanType()) {
|
|
|
|
if (V->getType() != llvm::Type::Int1Ty)
|
|
|
|
V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool");
|
|
|
|
}
|
|
|
|
|
|
|
|
return RValue::get(V);
|
|
|
|
}
|
2007-07-11 05:17:59 +08:00
|
|
|
|
2007-08-11 08:04:45 +08:00
|
|
|
assert(ExprType->isFunctionType() && "Unknown scalar value");
|
|
|
|
return RValue::get(Ptr);
|
2007-07-11 05:17:59 +08:00
|
|
|
}
|
2007-06-23 02:48:09 +08:00
|
|
|
|
2007-07-11 05:17:59 +08:00
|
|
|
if (LV.isVectorElt()) {
|
|
|
|
llvm::Value *Vec = Builder.CreateLoad(LV.getVectorAddr(), "tmp");
|
|
|
|
return RValue::get(Builder.CreateExtractElement(Vec, LV.getVectorIdx(),
|
|
|
|
"vecext"));
|
|
|
|
}
|
implement lvalue to rvalue conversion for ocuvector components. We can now compile stuff
like this:
typedef __attribute__(( ocu_vector_type(4) )) float float4;
float4 test1(float4 V) {
return V.wzyx+V;
}
to:
_test1:
pshufd $27, %xmm0, %xmm1
addps %xmm0, %xmm1
movaps %xmm1, %xmm0
ret
and:
_test1:
mfspr r2, 256
oris r3, r2, 4096
mtspr 256, r3
li r3, lo16(LCPI1_0)
lis r4, ha16(LCPI1_0)
lvx v3, r4, r3
vperm v3, v2, v2, v3
vaddfp v2, v3, v2
mtspr 256, r2
blr
llvm-svn: 40771
2007-08-03 08:16:29 +08:00
|
|
|
|
|
|
|
// If this is a reference to a subset of the elements of a vector, either
|
|
|
|
// shuffle the input or extract/insert them as appropriate.
|
2007-08-04 01:31:20 +08:00
|
|
|
if (LV.isOCUVectorElt())
|
|
|
|
return EmitLoadOfOCUElementLValue(LV, ExprType);
|
2008-01-23 04:17:04 +08:00
|
|
|
|
|
|
|
if (LV.isBitfield())
|
|
|
|
return EmitLoadOfBitfieldLValue(LV, ExprType);
|
|
|
|
|
|
|
|
assert(0 && "Unknown LValue type!");
|
2007-09-17 03:23:47 +08:00
|
|
|
//an invalid RValue, but the assert will
|
|
|
|
//ensure that this point is never reached
|
|
|
|
return RValue();
|
2007-08-04 00:18:34 +08:00
|
|
|
}
|
2007-08-03 23:52:31 +08:00
|
|
|
|
2008-01-23 04:17:04 +08:00
|
|
|
RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV,
|
|
|
|
QualType ExprType) {
|
|
|
|
llvm::Value *Ptr = LV.getBitfieldAddr();
|
|
|
|
const llvm::Type *EltTy =
|
|
|
|
cast<llvm::PointerType>(Ptr->getType())->getElementType();
|
|
|
|
unsigned EltTySize = EltTy->getPrimitiveSizeInBits();
|
|
|
|
unsigned short BitfieldSize = LV.getBitfieldSize();
|
|
|
|
unsigned short EndBit = LV.getBitfieldStartBit() + BitfieldSize;
|
|
|
|
|
|
|
|
llvm::Value *V = Builder.CreateLoad(Ptr, "tmp");
|
|
|
|
|
|
|
|
llvm::Value *ShAmt = llvm::ConstantInt::get(EltTy, EltTySize - EndBit);
|
|
|
|
V = Builder.CreateShl(V, ShAmt, "tmp");
|
|
|
|
|
|
|
|
ShAmt = llvm::ConstantInt::get(EltTy, EltTySize - BitfieldSize);
|
|
|
|
V = LV.isBitfieldSigned() ?
|
|
|
|
Builder.CreateAShr(V, ShAmt, "tmp") :
|
|
|
|
Builder.CreateLShr(V, ShAmt, "tmp");
|
|
|
|
return RValue::get(V);
|
|
|
|
}
|
|
|
|
|
2007-08-04 00:18:34 +08:00
|
|
|
// If this is a reference to a subset of the elements of a vector, either
|
|
|
|
// shuffle the input or extract/insert them as appropriate.
|
2007-08-04 01:31:20 +08:00
|
|
|
RValue CodeGenFunction::EmitLoadOfOCUElementLValue(LValue LV,
|
2007-08-11 01:10:08 +08:00
|
|
|
QualType ExprType) {
|
2007-08-04 00:18:34 +08:00
|
|
|
llvm::Value *Vec = Builder.CreateLoad(LV.getOCUVectorAddr(), "tmp");
|
|
|
|
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned EncFields = LV.getOCUVectorElts();
|
2007-08-04 00:18:34 +08:00
|
|
|
|
|
|
|
// If the result of the expression is a non-vector type, we must be
|
|
|
|
// extracting a single element. Just codegen as an extractelement.
|
2007-08-11 01:10:08 +08:00
|
|
|
const VectorType *ExprVT = ExprType->getAsVectorType();
|
|
|
|
if (!ExprVT) {
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(0, EncFields);
|
2007-08-04 00:18:34 +08:00
|
|
|
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
|
|
|
|
return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the source and destination have the same number of elements, use a
|
|
|
|
// vector shuffle instead of insert/extracts.
|
2007-08-11 01:10:08 +08:00
|
|
|
unsigned NumResultElts = ExprVT->getNumElements();
|
2007-08-04 00:18:34 +08:00
|
|
|
unsigned NumSourceElts =
|
|
|
|
cast<llvm::VectorType>(Vec->getType())->getNumElements();
|
|
|
|
|
|
|
|
if (NumResultElts == NumSourceElts) {
|
|
|
|
llvm::SmallVector<llvm::Constant*, 4> Mask;
|
In the common case where we are shuffling a vector, emit an
llvm vector shuffle instead of a bunch of insert/extract operations.
For: vec4 = vec4.yyyy; // splat
Emit:
%tmp1 = shufflevector <4 x float> %tmp, <4 x float> undef, <4 x i32> < i32 1, i32 1, i32 1, i32 1 >
instead of:
%tmp1 = extractelement <4 x float> %tmp, i32 1
%tmp2 = insertelement <4 x float> undef, float %tmp1, i32 0
%tmp3 = extractelement <4 x float> %tmp, i32 1
%tmp4 = insertelement <4 x float> %tmp2, float %tmp3, i32 1
%tmp5 = extractelement <4 x float> %tmp, i32 1
%tmp6 = insertelement <4 x float> %tmp4, float %tmp5, i32 2
%tmp7 = extractelement <4 x float> %tmp, i32 1
%tmp8 = insertelement <4 x float> %tmp6, float %tmp7, i32 3
llvm-svn: 40779
2007-08-04 00:09:33 +08:00
|
|
|
for (unsigned i = 0; i != NumResultElts; ++i) {
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-04 00:18:34 +08:00
|
|
|
Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx));
|
implement lvalue to rvalue conversion for ocuvector components. We can now compile stuff
like this:
typedef __attribute__(( ocu_vector_type(4) )) float float4;
float4 test1(float4 V) {
return V.wzyx+V;
}
to:
_test1:
pshufd $27, %xmm0, %xmm1
addps %xmm0, %xmm1
movaps %xmm1, %xmm0
ret
and:
_test1:
mfspr r2, 256
oris r3, r2, 4096
mtspr 256, r3
li r3, lo16(LCPI1_0)
lis r4, ha16(LCPI1_0)
lvx v3, r4, r3
vperm v3, v2, v2, v3
vaddfp v2, v3, v2
mtspr 256, r2
blr
llvm-svn: 40771
2007-08-03 08:16:29 +08:00
|
|
|
}
|
|
|
|
|
2007-08-04 00:18:34 +08:00
|
|
|
llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
|
|
|
|
Vec = Builder.CreateShuffleVector(Vec,
|
|
|
|
llvm::UndefValue::get(Vec->getType()),
|
|
|
|
MaskV, "tmp");
|
|
|
|
return RValue::get(Vec);
|
implement lvalue to rvalue conversion for ocuvector components. We can now compile stuff
like this:
typedef __attribute__(( ocu_vector_type(4) )) float float4;
float4 test1(float4 V) {
return V.wzyx+V;
}
to:
_test1:
pshufd $27, %xmm0, %xmm1
addps %xmm0, %xmm1
movaps %xmm1, %xmm0
ret
and:
_test1:
mfspr r2, 256
oris r3, r2, 4096
mtspr 256, r3
li r3, lo16(LCPI1_0)
lis r4, ha16(LCPI1_0)
lvx v3, r4, r3
vperm v3, v2, v2, v3
vaddfp v2, v3, v2
mtspr 256, r2
blr
llvm-svn: 40771
2007-08-03 08:16:29 +08:00
|
|
|
}
|
2007-06-23 02:48:09 +08:00
|
|
|
|
2007-08-04 00:18:34 +08:00
|
|
|
// Start out with an undef of the result type.
|
|
|
|
llvm::Value *Result = llvm::UndefValue::get(ConvertType(ExprType));
|
|
|
|
|
|
|
|
// Extract/Insert each element of the result.
|
|
|
|
for (unsigned i = 0; i != NumResultElts; ++i) {
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-04 00:18:34 +08:00
|
|
|
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
|
|
|
|
Elt = Builder.CreateExtractElement(Vec, Elt, "tmp");
|
|
|
|
|
|
|
|
llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
|
|
|
|
Result = Builder.CreateInsertElement(Result, Elt, OutIdx, "tmp");
|
|
|
|
}
|
|
|
|
|
|
|
|
return RValue::get(Result);
|
2007-06-06 04:53:16 +08:00
|
|
|
}
|
|
|
|
|
2007-08-04 00:18:34 +08:00
|
|
|
|
2007-06-30 00:31:29 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitStoreThroughLValue - Store the specified rvalue into the specified
|
|
|
|
/// lvalue, where both are guaranteed to the have the same type, and that type
|
|
|
|
/// is 'Ty'.
|
|
|
|
void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
|
|
|
|
QualType Ty) {
|
2007-08-04 00:28:33 +08:00
|
|
|
if (!Dst.isSimple()) {
|
|
|
|
if (Dst.isVectorElt()) {
|
|
|
|
// Read/modify/write the vector, inserting the new element.
|
|
|
|
// FIXME: Volatility.
|
|
|
|
llvm::Value *Vec = Builder.CreateLoad(Dst.getVectorAddr(), "tmp");
|
2007-09-01 06:49:20 +08:00
|
|
|
Vec = Builder.CreateInsertElement(Vec, Src.getScalarVal(),
|
2007-08-04 00:28:33 +08:00
|
|
|
Dst.getVectorIdx(), "vecins");
|
|
|
|
Builder.CreateStore(Vec, Dst.getVectorAddr());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is an update of elements of a vector, insert them as appropriate.
|
2007-08-04 01:31:20 +08:00
|
|
|
if (Dst.isOCUVectorElt())
|
2007-08-04 00:28:33 +08:00
|
|
|
return EmitStoreThroughOCUComponentLValue(Src, Dst, Ty);
|
2008-01-23 06:36:45 +08:00
|
|
|
|
|
|
|
if (Dst.isBitfield())
|
|
|
|
return EmitStoreThroughBitfieldLValue(Src, Dst, Ty);
|
|
|
|
|
2008-01-23 06:38:35 +08:00
|
|
|
assert(0 && "Unknown LValue type");
|
2007-08-04 00:28:33 +08:00
|
|
|
}
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2007-06-23 02:48:09 +08:00
|
|
|
llvm::Value *DstAddr = Dst.getAddress();
|
2007-08-11 08:04:45 +08:00
|
|
|
assert(Src.isScalar() && "Can't emit an agg store with this method");
|
|
|
|
// FIXME: Handle volatility etc.
|
2007-09-01 06:49:20 +08:00
|
|
|
const llvm::Type *SrcTy = Src.getScalarVal()->getType();
|
2007-12-17 09:11:20 +08:00
|
|
|
const llvm::PointerType *DstPtr = cast<llvm::PointerType>(DstAddr->getType());
|
|
|
|
const llvm::Type *AddrTy = DstPtr->getElementType();
|
|
|
|
unsigned AS = DstPtr->getAddressSpace();
|
2007-08-11 08:04:45 +08:00
|
|
|
|
|
|
|
if (AddrTy != SrcTy)
|
2007-12-17 09:11:20 +08:00
|
|
|
DstAddr = Builder.CreateBitCast(DstAddr,
|
|
|
|
llvm::PointerType::get(SrcTy, AS),
|
2007-08-11 08:04:45 +08:00
|
|
|
"storetmp");
|
2007-09-01 06:49:20 +08:00
|
|
|
Builder.CreateStore(Src.getScalarVal(), DstAddr);
|
2007-06-06 04:53:16 +08:00
|
|
|
}
|
|
|
|
|
2008-01-23 06:36:45 +08:00
|
|
|
void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
|
|
|
|
QualType Ty) {
|
|
|
|
unsigned short StartBit = Dst.getBitfieldStartBit();
|
|
|
|
unsigned short BitfieldSize = Dst.getBitfieldSize();
|
|
|
|
llvm::Value *Ptr = Dst.getBitfieldAddr();
|
|
|
|
const llvm::Type *EltTy =
|
|
|
|
cast<llvm::PointerType>(Ptr->getType())->getElementType();
|
|
|
|
unsigned EltTySize = EltTy->getPrimitiveSizeInBits();
|
|
|
|
|
|
|
|
llvm::Value *NewVal = Src.getScalarVal();
|
|
|
|
llvm::Value *OldVal = Builder.CreateLoad(Ptr, "tmp");
|
|
|
|
|
|
|
|
llvm::Value *ShAmt = llvm::ConstantInt::get(EltTy, StartBit);
|
|
|
|
NewVal = Builder.CreateShl(NewVal, ShAmt, "tmp");
|
|
|
|
|
|
|
|
llvm::Constant *Mask = llvm::ConstantInt::get(
|
|
|
|
llvm::APInt::getBitsSet(EltTySize, StartBit,
|
2008-02-13 05:49:34 +08:00
|
|
|
StartBit + BitfieldSize));
|
2008-01-23 06:36:45 +08:00
|
|
|
|
|
|
|
// Mask out any bits that shouldn't be set in the result.
|
|
|
|
NewVal = Builder.CreateAnd(NewVal, Mask, "tmp");
|
|
|
|
|
|
|
|
// Next, mask out the bits this bit-field should include from the old value.
|
|
|
|
Mask = llvm::ConstantExpr::getNot(Mask);
|
|
|
|
OldVal = Builder.CreateAnd(OldVal, Mask, "tmp");
|
|
|
|
|
|
|
|
// Finally, merge the two together and store it.
|
|
|
|
NewVal = Builder.CreateOr(OldVal, NewVal, "tmp");
|
|
|
|
|
|
|
|
Builder.CreateStore(NewVal, Ptr);
|
|
|
|
}
|
|
|
|
|
2007-10-31 04:59:40 +08:00
|
|
|
void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst,
|
2007-08-04 00:28:33 +08:00
|
|
|
QualType Ty) {
|
|
|
|
// This access turns into a read/modify/write of the vector. Load the input
|
|
|
|
// value now.
|
|
|
|
llvm::Value *Vec = Builder.CreateLoad(Dst.getOCUVectorAddr(), "tmp");
|
|
|
|
// FIXME: Volatility.
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned EncFields = Dst.getOCUVectorElts();
|
2007-08-04 00:28:33 +08:00
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
llvm::Value *SrcVal = Src.getScalarVal();
|
2007-08-04 00:28:33 +08:00
|
|
|
|
2007-08-04 00:37:04 +08:00
|
|
|
if (const VectorType *VTy = Ty->getAsVectorType()) {
|
|
|
|
unsigned NumSrcElts = VTy->getNumElements();
|
|
|
|
|
|
|
|
// Extract/Insert each element.
|
|
|
|
for (unsigned i = 0; i != NumSrcElts; ++i) {
|
|
|
|
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
|
|
|
|
Elt = Builder.CreateExtractElement(SrcVal, Elt, "tmp");
|
|
|
|
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned Idx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-04 00:37:04 +08:00
|
|
|
llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Idx);
|
|
|
|
Vec = Builder.CreateInsertElement(Vec, Elt, OutIdx, "tmp");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the Src is a scalar (not a vector) it must be updating one element.
|
2007-08-04 01:31:20 +08:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(0, EncFields);
|
2007-08-04 00:28:33 +08:00
|
|
|
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
|
|
|
|
Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp");
|
|
|
|
}
|
|
|
|
|
|
|
|
Builder.CreateStore(Vec, Dst.getOCUVectorAddr());
|
|
|
|
}
|
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
|
|
|
|
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
|
2007-09-14 05:41:19 +08:00
|
|
|
const ValueDecl *D = E->getDecl();
|
2007-06-14 04:44:40 +08:00
|
|
|
if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) {
|
2008-02-17 06:30:38 +08:00
|
|
|
const VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
if (VD->getStorageClass() == VarDecl::Extern)
|
|
|
|
return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
|
|
|
|
else {
|
|
|
|
llvm::Value *V = LocalDeclMap[D];
|
|
|
|
assert(V && "BlockVarDecl not entered in LocalDeclMap?");
|
|
|
|
return LValue::MakeAddr(V);
|
|
|
|
}
|
2007-12-02 15:09:19 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false));
|
|
|
|
} else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
|
2007-12-18 16:16:44 +08:00
|
|
|
return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(FVD, false));
|
2007-06-02 13:24:33 +08:00
|
|
|
}
|
|
|
|
assert(0 && "Unimp declref");
|
2007-09-17 03:23:47 +08:00
|
|
|
//an invalid LValue, but the assert will
|
|
|
|
//ensure that this point is never reached.
|
|
|
|
return LValue();
|
2007-06-02 13:24:33 +08:00
|
|
|
}
|
2007-06-02 02:02:12 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
|
|
|
|
// __extension__ doesn't affect lvalue-ness.
|
|
|
|
if (E->getOpcode() == UnaryOperator::Extension)
|
|
|
|
return EmitLValue(E->getSubExpr());
|
|
|
|
|
2007-10-31 06:53:42 +08:00
|
|
|
switch (E->getOpcode()) {
|
|
|
|
default: assert(0 && "Unknown unary operator lvalue!");
|
|
|
|
case UnaryOperator::Deref:
|
|
|
|
return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()));
|
|
|
|
case UnaryOperator::Real:
|
|
|
|
case UnaryOperator::Imag:
|
|
|
|
LValue LV = EmitLValue(E->getSubExpr());
|
2008-03-19 13:19:41 +08:00
|
|
|
unsigned Idx = E->getOpcode() == UnaryOperator::Imag;
|
|
|
|
return LValue::MakeAddr(Builder.CreateStructGEP(LV.getAddress(),
|
|
|
|
Idx, "idx"));
|
2007-10-31 06:53:42 +08:00
|
|
|
}
|
2007-06-06 04:53:16 +08:00
|
|
|
}
|
|
|
|
|
2007-06-06 12:54:52 +08:00
|
|
|
LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) {
|
|
|
|
assert(!E->isWide() && "FIXME: Wide strings not supported yet!");
|
|
|
|
const char *StrData = E->getStrData();
|
|
|
|
unsigned Len = E->getByteLength();
|
2007-11-28 13:34:05 +08:00
|
|
|
std::string StringLiteral(StrData, StrData+Len);
|
|
|
|
return LValue::MakeAddr(CGM.GetAddrOfConstantString(StringLiteral));
|
2007-06-06 12:54:52 +08:00
|
|
|
}
|
|
|
|
|
2007-07-21 13:21:51 +08:00
|
|
|
LValue CodeGenFunction::EmitPreDefinedLValue(const PreDefinedExpr *E) {
|
|
|
|
std::string FunctionName(CurFuncDecl->getName());
|
|
|
|
std::string GlobalVarName;
|
|
|
|
|
|
|
|
switch (E->getIdentType()) {
|
|
|
|
default:
|
|
|
|
assert(0 && "unknown pre-defined ident type");
|
|
|
|
case PreDefinedExpr::Func:
|
|
|
|
GlobalVarName = "__func__.";
|
|
|
|
break;
|
|
|
|
case PreDefinedExpr::Function:
|
|
|
|
GlobalVarName = "__FUNCTION__.";
|
|
|
|
break;
|
|
|
|
case PreDefinedExpr::PrettyFunction:
|
|
|
|
// FIXME:: Demangle C++ method names
|
|
|
|
GlobalVarName = "__PRETTY_FUNCTION__.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalVarName += CurFuncDecl->getName();
|
|
|
|
|
|
|
|
// FIXME: Can cache/reuse these within the module.
|
|
|
|
llvm::Constant *C=llvm::ConstantArray::get(FunctionName);
|
|
|
|
|
|
|
|
// Create a global variable for this.
|
|
|
|
C = new llvm::GlobalVariable(C->getType(), true,
|
|
|
|
llvm::GlobalValue::InternalLinkage,
|
|
|
|
C, GlobalVarName, CurFn->getParent());
|
|
|
|
return LValue::MakeAddr(C);
|
|
|
|
}
|
|
|
|
|
2007-06-09 07:31:14 +08:00
|
|
|
LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
|
2007-08-21 00:18:38 +08:00
|
|
|
// The index must always be an integer, which is not an aggregate. Emit it.
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *Idx = EmitScalarExpr(E->getIdx());
|
2007-06-09 07:31:14 +08:00
|
|
|
|
2007-07-11 05:17:59 +08:00
|
|
|
// If the base is a vector type, then we are forming a vector element lvalue
|
|
|
|
// with this subscript.
|
2007-08-21 00:18:38 +08:00
|
|
|
if (E->getLHS()->getType()->isVectorType()) {
|
2007-07-11 05:17:59 +08:00
|
|
|
// Emit the vector as an lvalue to get its address.
|
2007-08-21 00:18:38 +08:00
|
|
|
LValue LHS = EmitLValue(E->getLHS());
|
|
|
|
assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
|
2007-07-11 05:17:59 +08:00
|
|
|
// FIXME: This should properly sign/zero/extend or truncate Idx to i32.
|
2007-08-21 00:18:38 +08:00
|
|
|
return LValue::MakeVectorElt(LHS.getAddress(), Idx);
|
2007-07-11 05:17:59 +08:00
|
|
|
}
|
|
|
|
|
2007-08-21 00:18:38 +08:00
|
|
|
// The base must be a pointer, which is not an aggregate. Emit it.
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *Base = EmitScalarExpr(E->getBase());
|
2007-07-11 05:17:59 +08:00
|
|
|
|
2007-08-21 00:18:38 +08:00
|
|
|
// Extend or truncate the index type to 32 or 64-bits.
|
2007-08-09 01:43:05 +08:00
|
|
|
QualType IdxTy = E->getIdx()->getType();
|
2007-06-09 07:31:14 +08:00
|
|
|
bool IdxSigned = IdxTy->isSignedIntegerType();
|
2007-06-16 07:05:46 +08:00
|
|
|
unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
|
2007-06-09 07:31:14 +08:00
|
|
|
if (IdxBitwidth != LLVMPointerWidth)
|
2007-06-16 07:05:46 +08:00
|
|
|
Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth),
|
2007-06-09 07:31:14 +08:00
|
|
|
IdxSigned, "idxprom");
|
|
|
|
|
|
|
|
// We know that the pointer points to a type of the correct size, unless the
|
|
|
|
// size is a VLA.
|
2008-02-15 20:20:59 +08:00
|
|
|
if (!E->getType()->isConstantSizeType())
|
2007-06-09 07:31:14 +08:00
|
|
|
assert(0 && "VLA idx not implemented");
|
2007-07-11 05:17:59 +08:00
|
|
|
return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"));
|
2007-06-09 07:31:14 +08:00
|
|
|
}
|
|
|
|
|
2007-08-03 07:37:31 +08:00
|
|
|
LValue CodeGenFunction::
|
2007-08-04 01:31:20 +08:00
|
|
|
EmitOCUVectorElementExpr(const OCUVectorElementExpr *E) {
|
2007-08-03 07:37:31 +08:00
|
|
|
// Emit the base vector as an l-value.
|
|
|
|
LValue Base = EmitLValue(E->getBase());
|
|
|
|
assert(Base.isSimple() && "Can only subscript lvalue vectors here!");
|
|
|
|
|
2007-08-04 01:31:20 +08:00
|
|
|
return LValue::MakeOCUVectorElt(Base.getAddress(),
|
|
|
|
E->getEncodedElementAccess());
|
2007-08-03 07:37:31 +08:00
|
|
|
}
|
|
|
|
|
2007-10-24 04:28:39 +08:00
|
|
|
LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
|
2007-12-12 05:33:16 +08:00
|
|
|
bool isUnion = false;
|
2007-10-25 06:26:28 +08:00
|
|
|
Expr *BaseExpr = E->getBase();
|
|
|
|
llvm::Value *BaseValue = NULL;
|
2007-12-03 02:52:07 +08:00
|
|
|
|
|
|
|
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
|
2007-12-12 05:33:16 +08:00
|
|
|
if (E->isArrow()) {
|
2007-12-03 02:52:07 +08:00
|
|
|
BaseValue = EmitScalarExpr(BaseExpr);
|
2007-12-12 05:33:16 +08:00
|
|
|
const PointerType *PTy =
|
|
|
|
cast<PointerType>(BaseExpr->getType().getCanonicalType());
|
|
|
|
if (PTy->getPointeeType()->isUnionType())
|
|
|
|
isUnion = true;
|
|
|
|
}
|
2007-12-03 02:52:07 +08:00
|
|
|
else {
|
2007-10-25 06:26:28 +08:00
|
|
|
LValue BaseLV = EmitLValue(BaseExpr);
|
2007-12-03 02:52:07 +08:00
|
|
|
// FIXME: this isn't right for bitfields.
|
2007-10-25 06:26:28 +08:00
|
|
|
BaseValue = BaseLV.getAddress();
|
2007-12-12 05:33:16 +08:00
|
|
|
if (BaseExpr->getType()->isUnionType())
|
|
|
|
isUnion = true;
|
2007-12-03 02:52:07 +08:00
|
|
|
}
|
2007-10-24 04:28:39 +08:00
|
|
|
|
|
|
|
FieldDecl *Field = E->getMemberDecl();
|
2008-02-09 16:50:58 +08:00
|
|
|
return EmitLValueForField(BaseValue, Field, isUnion);
|
|
|
|
}
|
2007-10-24 04:28:39 +08:00
|
|
|
|
2008-02-09 16:50:58 +08:00
|
|
|
LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
|
|
|
|
FieldDecl* Field,
|
|
|
|
bool isUnion)
|
|
|
|
{
|
|
|
|
llvm::Value *V;
|
|
|
|
unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
|
2008-02-08 03:29:53 +08:00
|
|
|
|
2008-03-19 13:19:41 +08:00
|
|
|
if (!Field->isBitField()) {
|
|
|
|
V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
|
|
|
|
} else {
|
|
|
|
const llvm::Type *FieldTy = ConvertType(Field->getType());
|
|
|
|
const llvm::PointerType *BaseTy =
|
2008-02-08 03:29:53 +08:00
|
|
|
cast<llvm::PointerType>(BaseValue->getType());
|
|
|
|
unsigned AS = BaseTy->getAddressSpace();
|
|
|
|
BaseValue = Builder.CreateBitCast(BaseValue,
|
|
|
|
llvm::PointerType::get(FieldTy, AS),
|
|
|
|
"tmp");
|
|
|
|
V = Builder.CreateGEP(BaseValue,
|
|
|
|
llvm::ConstantInt::get(llvm::Type::Int32Ty, idx),
|
|
|
|
"tmp");
|
|
|
|
}
|
2008-03-19 13:19:41 +08:00
|
|
|
|
2007-10-27 03:42:18 +08:00
|
|
|
// Match union field type.
|
2008-02-08 03:29:53 +08:00
|
|
|
if (isUnion) {
|
2007-10-27 03:42:18 +08:00
|
|
|
const llvm::Type * FieldTy = ConvertType(Field->getType());
|
2007-10-31 04:59:40 +08:00
|
|
|
const llvm::PointerType * BaseTy =
|
|
|
|
cast<llvm::PointerType>(BaseValue->getType());
|
2007-10-27 03:42:18 +08:00
|
|
|
if (FieldTy != BaseTy->getElementType()) {
|
2007-12-29 12:06:57 +08:00
|
|
|
unsigned AS = BaseTy->getAddressSpace();
|
2007-12-17 09:11:20 +08:00
|
|
|
V = Builder.CreateBitCast(V,
|
2007-12-29 12:06:57 +08:00
|
|
|
llvm::PointerType::get(FieldTy, AS),
|
2007-12-17 09:11:20 +08:00
|
|
|
"tmp");
|
2007-10-27 03:42:18 +08:00
|
|
|
}
|
|
|
|
}
|
2008-01-23 04:17:04 +08:00
|
|
|
|
2008-03-19 13:19:41 +08:00
|
|
|
if (!Field->isBitField())
|
2008-01-23 04:17:04 +08:00
|
|
|
return LValue::MakeAddr(V);
|
2008-03-19 13:19:41 +08:00
|
|
|
|
|
|
|
CodeGenTypes::BitFieldInfo bitFieldInfo =
|
|
|
|
CGM.getTypes().getBitFieldInfo(Field);
|
|
|
|
return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size,
|
|
|
|
Field->getType()->isSignedIntegerType());
|
2007-10-24 04:28:39 +08:00
|
|
|
}
|
|
|
|
|
2007-06-02 02:02:12 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2007-08-21 06:37:10 +08:00
|
|
|
|
2007-06-16 05:34:29 +08:00
|
|
|
RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
|
2007-08-21 02:05:56 +08:00
|
|
|
if (const ImplicitCastExpr *IcExpr =
|
|
|
|
dyn_cast<const ImplicitCastExpr>(E->getCallee()))
|
|
|
|
if (const DeclRefExpr *DRExpr =
|
|
|
|
dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr()))
|
|
|
|
if (const FunctionDecl *FDecl =
|
|
|
|
dyn_cast<const FunctionDecl>(DRExpr->getDecl()))
|
|
|
|
if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID())
|
|
|
|
return EmitBuiltinExpr(builtinID, E);
|
|
|
|
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
|
2008-01-30 09:32:06 +08:00
|
|
|
return EmitCallExpr(Callee, E->getCallee()->getType(),
|
|
|
|
E->arg_begin(), E->getNumArgs());
|
2008-01-18 01:46:27 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 09:32:06 +08:00
|
|
|
RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr, Expr *const *Args,
|
|
|
|
unsigned NumArgs) {
|
2008-01-18 01:46:27 +08:00
|
|
|
llvm::Value *Callee = EmitScalarExpr(FnExpr);
|
2008-01-30 09:32:06 +08:00
|
|
|
return EmitCallExpr(Callee, FnExpr->getType(), Args, NumArgs);
|
2007-08-31 12:44:06 +08:00
|
|
|
}
|
|
|
|
|
2007-12-29 13:02:41 +08:00
|
|
|
LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
|
|
|
|
// Can only get l-value for call expression returning aggregate type
|
|
|
|
RValue RV = EmitCallExpr(E);
|
|
|
|
return LValue::MakeAddr(RV.getAggregateAddr());
|
|
|
|
}
|
|
|
|
|
2008-01-18 01:46:27 +08:00
|
|
|
RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
|
2008-01-30 09:32:06 +08:00
|
|
|
Expr *const *ArgExprs, unsigned NumArgs) {
|
2007-07-11 06:18:37 +08:00
|
|
|
// The callee type will always be a pointer to function type, get the function
|
|
|
|
// type.
|
2008-01-18 01:46:27 +08:00
|
|
|
FnType = cast<PointerType>(FnType.getCanonicalType())->getPointeeType();
|
|
|
|
QualType ResultType = cast<FunctionType>(FnType)->getResultType();
|
2008-01-30 09:32:06 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::SmallVector<llvm::Value*, 16> Args;
|
2007-06-16 05:34:29 +08:00
|
|
|
|
2007-08-11 01:02:28 +08:00
|
|
|
// Handle struct-return functions by passing a pointer to the location that
|
|
|
|
// we would like to return into.
|
2008-01-18 01:46:27 +08:00
|
|
|
if (hasAggregateLLVMType(ResultType)) {
|
2007-08-11 01:02:28 +08:00
|
|
|
// Create a temporary alloca to hold the result of the call. :(
|
2008-01-18 01:46:27 +08:00
|
|
|
Args.push_back(CreateTempAlloca(ConvertType(ResultType)));
|
2007-08-11 01:02:28 +08:00
|
|
|
// FIXME: set the stret attribute on the argument.
|
|
|
|
}
|
|
|
|
|
2008-01-18 01:46:27 +08:00
|
|
|
for (unsigned i = 0, e = NumArgs; i != e; ++i) {
|
|
|
|
QualType ArgTy = ArgExprs[i]->getType();
|
2008-02-09 16:50:58 +08:00
|
|
|
|
2007-08-27 06:55:13 +08:00
|
|
|
if (!hasAggregateLLVMType(ArgTy)) {
|
|
|
|
// Scalar argument is passed by-value.
|
2008-01-18 01:46:27 +08:00
|
|
|
Args.push_back(EmitScalarExpr(ArgExprs[i]));
|
2007-08-27 06:55:13 +08:00
|
|
|
} else if (ArgTy->isComplexType()) {
|
|
|
|
// Make a temporary alloca to pass the argument.
|
|
|
|
llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy));
|
2008-01-18 01:46:27 +08:00
|
|
|
EmitComplexExprIntoAddr(ArgExprs[i], DestMem, false);
|
2007-08-27 06:55:13 +08:00
|
|
|
Args.push_back(DestMem);
|
|
|
|
} else {
|
|
|
|
llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy));
|
2008-01-18 01:46:27 +08:00
|
|
|
EmitAggExpr(ArgExprs[i], DestMem, false);
|
2007-08-27 06:55:13 +08:00
|
|
|
Args.push_back(DestMem);
|
2007-07-11 06:18:37 +08:00
|
|
|
}
|
2007-06-16 05:34:29 +08:00
|
|
|
}
|
|
|
|
|
2008-03-09 11:09:36 +08:00
|
|
|
llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
|
|
|
|
if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee))
|
|
|
|
CI->setCallingConv(F->getCallingConv());
|
|
|
|
if (CI->getType() != llvm::Type::VoidTy)
|
|
|
|
CI->setName("call");
|
2008-01-18 01:46:27 +08:00
|
|
|
else if (ResultType->isComplexType())
|
2007-09-01 06:49:20 +08:00
|
|
|
return RValue::getComplex(LoadComplexFromAddr(Args[0], false));
|
2008-01-18 01:46:27 +08:00
|
|
|
else if (hasAggregateLLVMType(ResultType))
|
2007-08-11 01:02:28 +08:00
|
|
|
// Struct return.
|
|
|
|
return RValue::getAggregate(Args[0]);
|
2007-12-01 01:56:23 +08:00
|
|
|
else {
|
|
|
|
// void return.
|
2008-01-18 01:46:27 +08:00
|
|
|
assert(ResultType->isVoidType() && "Should only have a void expr here");
|
2008-03-09 11:09:36 +08:00
|
|
|
CI = 0;
|
2007-12-01 01:56:23 +08:00
|
|
|
}
|
2007-08-11 01:02:28 +08:00
|
|
|
|
2008-03-09 11:09:36 +08:00
|
|
|
return RValue::get(CI);
|
2007-06-16 05:34:29 +08:00
|
|
|
}
|