2007-06-01 18:02:12 +00:00
|
|
|
//===--- CGExpr.cpp - Emit LLVM Code from Expressions ---------------------===//
|
|
|
|
|
//
|
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
|
//
|
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// This contains code to emit Expr nodes as LLVM code.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
2007-06-20 04:44:43 +00:00
|
|
|
#include "CodeGenModule.h"
|
2007-06-01 18:02:12 +00:00
|
|
|
#include "clang/AST/AST.h"
|
2007-08-20 18:05:56 +00:00
|
|
|
#include "clang/Lex/IdentifierTable.h"
|
2007-06-01 18:02:12 +00:00
|
|
|
#include "llvm/Constants.h"
|
|
|
|
|
#include "llvm/DerivedTypes.h"
|
2007-06-06 04:54:52 +00: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 05:43:05 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2007-06-01 18:02:12 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
|
2007-06-02 19:33:17 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
// Miscellaneous Helper Methods
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
2007-06-22 21:44:33 +00: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-05 20:53:16 +00:00
|
|
|
|
|
|
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|
|
|
|
|
/// expression and compare the result against zero, returning an Int1Ty value.
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) {
|
2007-08-24 00:01:20 +00:00
|
|
|
return ConvertScalarValueToBool(EmitAnyExpr(E), E->getType());
|
2007-06-05 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
// Conversions
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
/// EmitConversion - Convert the value specied by Val, whose type is ValTy, to
|
|
|
|
|
/// the type specified by DstTy, following the rules of C99 6.3.
|
|
|
|
|
RValue CodeGenFunction::EmitConversion(RValue Val, QualType ValTy,
|
2007-06-22 19:05:19 +00:00
|
|
|
QualType DstTy) {
|
2007-06-05 20:53:16 +00:00
|
|
|
ValTy = ValTy.getCanonicalType();
|
|
|
|
|
DstTy = DstTy.getCanonicalType();
|
|
|
|
|
if (ValTy == DstTy) return Val;
|
2007-06-06 04:39:08 +00:00
|
|
|
|
|
|
|
|
// Handle conversions to bool first, they are special: comparisons against 0.
|
|
|
|
|
if (const BuiltinType *DestBT = dyn_cast<BuiltinType>(DstTy))
|
|
|
|
|
if (DestBT->getKind() == BuiltinType::Bool)
|
|
|
|
|
return RValue::get(ConvertScalarValueToBool(Val, ValTy));
|
2007-06-05 20:53:16 +00:00
|
|
|
|
2007-06-06 04:39:08 +00:00
|
|
|
// Handle pointer conversions next: pointers can only be converted to/from
|
|
|
|
|
// other pointers and integers.
|
2007-06-06 04:05:39 +00:00
|
|
|
if (isa<PointerType>(DstTy)) {
|
2007-06-22 19:05:19 +00:00
|
|
|
const llvm::Type *DestTy = ConvertType(DstTy);
|
2007-06-06 04:05:39 +00:00
|
|
|
|
2007-08-10 16:33:59 +00:00
|
|
|
if (Val.getVal()->getType() == DestTy)
|
|
|
|
|
return Val;
|
|
|
|
|
|
2007-06-06 04:05:39 +00:00
|
|
|
// The source value may be an integer, or a pointer.
|
|
|
|
|
assert(Val.isScalar() && "Can only convert from integer or pointer");
|
|
|
|
|
if (isa<llvm::PointerType>(Val.getVal()->getType()))
|
|
|
|
|
return RValue::get(Builder.CreateBitCast(Val.getVal(), DestTy, "conv"));
|
|
|
|
|
assert(ValTy->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
|
2007-07-13 03:25:53 +00:00
|
|
|
return RValue::get(Builder.CreateIntToPtr(Val.getVal(), DestTy, "conv"));
|
2007-06-06 04:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isa<PointerType>(ValTy)) {
|
2007-06-06 04:05:39 +00:00
|
|
|
// Must be an ptr to int cast.
|
2007-06-22 19:05:19 +00:00
|
|
|
const llvm::Type *DestTy = ConvertType(DstTy);
|
2007-06-06 04:05:39 +00:00
|
|
|
assert(isa<llvm::IntegerType>(DestTy) && "not ptr->int?");
|
|
|
|
|
return RValue::get(Builder.CreateIntToPtr(Val.getVal(), DestTy, "conv"));
|
2007-06-05 20:53:16 +00:00
|
|
|
}
|
2007-06-06 04:39:08 +00:00
|
|
|
|
|
|
|
|
// Finally, we have the arithmetic types: real int/float and complex
|
|
|
|
|
// int/float. Handle real->real conversions first, they are the most
|
|
|
|
|
// common.
|
|
|
|
|
if (Val.isScalar() && DstTy->isRealType()) {
|
|
|
|
|
// We know that these are representable as scalars in LLVM, convert to LLVM
|
|
|
|
|
// types since they are easier to reason about.
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *SrcVal = Val.getVal();
|
2007-06-22 19:05:19 +00:00
|
|
|
const llvm::Type *DestTy = ConvertType(DstTy);
|
2007-06-06 04:39:08 +00:00
|
|
|
if (SrcVal->getType() == DestTy) return Val;
|
|
|
|
|
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *Result;
|
2007-06-06 04:39:08 +00:00
|
|
|
if (isa<llvm::IntegerType>(SrcVal->getType())) {
|
|
|
|
|
bool InputSigned = ValTy->isSignedIntegerType();
|
|
|
|
|
if (isa<llvm::IntegerType>(DestTy))
|
|
|
|
|
Result = Builder.CreateIntCast(SrcVal, DestTy, InputSigned, "conv");
|
|
|
|
|
else if (InputSigned)
|
|
|
|
|
Result = Builder.CreateSIToFP(SrcVal, DestTy, "conv");
|
|
|
|
|
else
|
|
|
|
|
Result = Builder.CreateUIToFP(SrcVal, DestTy, "conv");
|
|
|
|
|
} else {
|
|
|
|
|
assert(SrcVal->getType()->isFloatingPoint() && "Unknown real conversion");
|
|
|
|
|
if (isa<llvm::IntegerType>(DestTy)) {
|
|
|
|
|
if (DstTy->isSignedIntegerType())
|
|
|
|
|
Result = Builder.CreateFPToSI(SrcVal, DestTy, "conv");
|
|
|
|
|
else
|
|
|
|
|
Result = Builder.CreateFPToUI(SrcVal, DestTy, "conv");
|
|
|
|
|
} else {
|
|
|
|
|
assert(DestTy->isFloatingPoint() && "Unknown real conversion");
|
|
|
|
|
if (DestTy->getTypeID() < SrcVal->getType()->getTypeID())
|
|
|
|
|
Result = Builder.CreateFPTrunc(SrcVal, DestTy, "conv");
|
|
|
|
|
else
|
|
|
|
|
Result = Builder.CreateFPExt(SrcVal, DestTy, "conv");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return RValue::get(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(0 && "FIXME: We don't support complex conversions yet!");
|
2007-06-05 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// ConvertScalarValueToBool - Convert the specified expression value to a
|
2007-06-02 19:33:17 +00:00
|
|
|
/// boolean (i1) truth value. This is equivalent to "Val == 0".
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *CodeGenFunction::ConvertScalarValueToBool(RValue Val, QualType Ty){
|
2007-06-02 19:33:17 +00:00
|
|
|
Ty = Ty.getCanonicalType();
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *Result;
|
2007-06-02 19:33:17 +00:00
|
|
|
if (const BuiltinType *BT = dyn_cast<BuiltinType>(Ty)) {
|
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
|
default: assert(0 && "Unknown scalar value");
|
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
|
Result = Val.getVal();
|
|
|
|
|
// Bool is already evaluated right.
|
|
|
|
|
assert(Result->getType() == llvm::Type::Int1Ty &&
|
|
|
|
|
"Unexpected bool value type!");
|
|
|
|
|
return Result;
|
2007-06-03 07:25:34 +00:00
|
|
|
case BuiltinType::Char_S:
|
|
|
|
|
case BuiltinType::Char_U:
|
2007-06-02 19:33:17 +00:00
|
|
|
case BuiltinType::SChar:
|
|
|
|
|
case BuiltinType::UChar:
|
|
|
|
|
case BuiltinType::Short:
|
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
|
case BuiltinType::Int:
|
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
|
case BuiltinType::Long:
|
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
|
// Code below handles simple integers.
|
|
|
|
|
break;
|
|
|
|
|
case BuiltinType::Float:
|
|
|
|
|
case BuiltinType::Double:
|
|
|
|
|
case BuiltinType::LongDouble: {
|
|
|
|
|
// Compare against 0.0 for fp scalars.
|
|
|
|
|
Result = Val.getVal();
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(Result->getType());
|
2007-06-02 19:33:17 +00:00
|
|
|
// FIXME: llvm-gcc produces a une comparison: validate this is right.
|
|
|
|
|
Result = Builder.CreateFCmpUNE(Result, Zero, "tobool");
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-24 00:01:20 +00:00
|
|
|
} else if (isa<ComplexType>(Ty)) {
|
|
|
|
|
assert(0 && "implement complex -> bool");
|
|
|
|
|
|
2007-06-22 20:56:16 +00:00
|
|
|
} else {
|
2007-08-24 00:01:20 +00:00
|
|
|
assert((isa<PointerType>(Ty) ||
|
|
|
|
|
(isa<TagType>(Ty) &&
|
|
|
|
|
cast<TagType>(Ty)->getDecl()->getKind() == Decl::Enum)) &&
|
|
|
|
|
"Unknown Type");
|
|
|
|
|
// Code below handles this case fine.
|
2007-06-02 19:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Usual case for integers, pointers, and enums: compare against zero.
|
|
|
|
|
Result = Val.getVal();
|
2007-06-02 19:47:04 +00:00
|
|
|
|
|
|
|
|
// Because of the type rules of C, we often end up computing a logical value,
|
|
|
|
|
// then zero extending it to int, then wanting it as a logical value again.
|
|
|
|
|
// Optimize this common case.
|
2007-06-15 23:05:46 +00:00
|
|
|
if (llvm::ZExtInst *ZI = dyn_cast<llvm::ZExtInst>(Result)) {
|
2007-06-02 19:47:04 +00:00
|
|
|
if (ZI->getOperand(0)->getType() == llvm::Type::Int1Ty) {
|
|
|
|
|
Result = ZI->getOperand(0);
|
|
|
|
|
ZI->eraseFromParent();
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(Result->getType());
|
2007-06-02 19:33:17 +00:00
|
|
|
return Builder.CreateICmpNE(Result, Zero, "tobool");
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-02 19:47:04 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-02 05:24:33 +00:00
|
|
|
// LValue Expression Emission
|
2007-06-02 19:47:04 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-02 05:24:33 +00:00
|
|
|
|
2007-06-05 20:53:16 +00: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 05:24:33 +00:00
|
|
|
LValue CodeGenFunction::EmitLValue(const Expr *E) {
|
|
|
|
|
switch (E->getStmtClass()) {
|
|
|
|
|
default:
|
2007-06-05 20:53:16 +00:00
|
|
|
fprintf(stderr, "Unimplemented lvalue expr!\n");
|
2007-06-02 05:24:33 +00:00
|
|
|
E->dump();
|
2007-07-10 21:17:59 +00:00
|
|
|
return LValue::MakeAddr(llvm::UndefValue::get(
|
2007-06-02 05:24:33 +00:00
|
|
|
llvm::PointerType::get(llvm::Type::Int32Ty)));
|
|
|
|
|
|
|
|
|
|
case Expr::DeclRefExprClass: return EmitDeclRefLValue(cast<DeclRefExpr>(E));
|
2007-06-05 03:59:43 +00:00
|
|
|
case Expr::ParenExprClass:return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
|
2007-07-21 05:21:51 +00:00
|
|
|
case Expr::PreDefinedExprClass:
|
|
|
|
|
return EmitPreDefinedLValue(cast<PreDefinedExpr>(E));
|
2007-06-06 04:54:52 +00:00
|
|
|
case Expr::StringLiteralClass:
|
|
|
|
|
return EmitStringLiteralLValue(cast<StringLiteral>(E));
|
2007-06-05 20:53:16 +00:00
|
|
|
|
|
|
|
|
case Expr::UnaryOperatorClass:
|
|
|
|
|
return EmitUnaryOpLValue(cast<UnaryOperator>(E));
|
2007-06-08 23:31:14 +00:00
|
|
|
case Expr::ArraySubscriptExprClass:
|
|
|
|
|
return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
|
2007-08-03 17:31:20 +00:00
|
|
|
case Expr::OCUVectorElementExprClass:
|
|
|
|
|
return EmitOCUVectorElementExpr(cast<OCUVectorElementExpr>(E));
|
2007-06-02 05:24:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 20:53:16 +00: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-29 16:31:29 +00:00
|
|
|
RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
|
2007-07-10 21:17:59 +00:00
|
|
|
if (LV.isSimple()) {
|
|
|
|
|
llvm::Value *Ptr = LV.getAddress();
|
|
|
|
|
const llvm::Type *EltTy =
|
|
|
|
|
cast<llvm::PointerType>(Ptr->getType())->getElementType();
|
|
|
|
|
|
|
|
|
|
// Simple scalar l-value.
|
|
|
|
|
if (EltTy->isFirstClassType())
|
|
|
|
|
return RValue::get(Builder.CreateLoad(Ptr, "tmp"));
|
|
|
|
|
|
2007-08-11 00:04:45 +00:00
|
|
|
assert(ExprType->isFunctionType() && "Unknown scalar value");
|
|
|
|
|
return RValue::get(Ptr);
|
2007-07-10 21:17:59 +00:00
|
|
|
}
|
2007-06-22 18:48:09 +00:00
|
|
|
|
2007-07-10 21:17:59 +00: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 00:16:29 +00: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-03 17:31:20 +00:00
|
|
|
if (LV.isOCUVectorElt())
|
|
|
|
|
return EmitLoadOfOCUElementLValue(LV, ExprType);
|
2007-08-03 16:18:34 +00:00
|
|
|
|
|
|
|
|
assert(0 && "Bitfield ref not impl!");
|
|
|
|
|
}
|
2007-08-03 15:52:31 +00:00
|
|
|
|
2007-08-03 16:18:34 +00: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-03 17:31:20 +00:00
|
|
|
RValue CodeGenFunction::EmitLoadOfOCUElementLValue(LValue LV,
|
2007-08-10 17:10:08 +00:00
|
|
|
QualType ExprType) {
|
2007-08-03 16:18:34 +00:00
|
|
|
llvm::Value *Vec = Builder.CreateLoad(LV.getOCUVectorAddr(), "tmp");
|
|
|
|
|
|
2007-08-03 17:31:20 +00:00
|
|
|
unsigned EncFields = LV.getOCUVectorElts();
|
2007-08-03 16:18:34 +00: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-10 17:10:08 +00:00
|
|
|
const VectorType *ExprVT = ExprType->getAsVectorType();
|
|
|
|
|
if (!ExprVT) {
|
2007-08-03 17:31:20 +00:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(0, EncFields);
|
2007-08-03 16:18:34 +00: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-10 17:10:08 +00:00
|
|
|
unsigned NumResultElts = ExprVT->getNumElements();
|
2007-08-03 16:18:34 +00: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-03 16:09:33 +00:00
|
|
|
for (unsigned i = 0; i != NumResultElts; ++i) {
|
2007-08-03 17:31:20 +00:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-03 16:18:34 +00: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 00:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-03 16:18:34 +00: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 00:16:29 +00:00
|
|
|
}
|
2007-06-22 18:48:09 +00:00
|
|
|
|
2007-08-03 16:18:34 +00: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-03 17:31:20 +00:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-03 16:18:34 +00: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-05 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-03 16:18:34 +00:00
|
|
|
|
2007-06-29 16:31:29 +00:00
|
|
|
RValue CodeGenFunction::EmitLoadOfLValue(const Expr *E) {
|
|
|
|
|
return EmitLoadOfLValue(EmitLValue(E), E->getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-05 20:53:16 +00: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-03 16:28:33 +00: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");
|
|
|
|
|
Vec = Builder.CreateInsertElement(Vec, Src.getVal(),
|
|
|
|
|
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-03 17:31:20 +00:00
|
|
|
if (Dst.isOCUVectorElt())
|
2007-08-03 16:28:33 +00:00
|
|
|
return EmitStoreThroughOCUComponentLValue(Src, Dst, Ty);
|
2007-07-10 21:17:59 +00:00
|
|
|
|
2007-08-03 16:28:33 +00:00
|
|
|
assert(0 && "FIXME: Don't support store to bitfield yet");
|
|
|
|
|
}
|
2007-06-05 20:53:16 +00:00
|
|
|
|
2007-06-22 18:48:09 +00:00
|
|
|
llvm::Value *DstAddr = Dst.getAddress();
|
2007-08-11 00:04:45 +00:00
|
|
|
assert(Src.isScalar() && "Can't emit an agg store with this method");
|
|
|
|
|
// FIXME: Handle volatility etc.
|
|
|
|
|
const llvm::Type *SrcTy = Src.getVal()->getType();
|
|
|
|
|
const llvm::Type *AddrTy =
|
|
|
|
|
cast<llvm::PointerType>(DstAddr->getType())->getElementType();
|
|
|
|
|
|
|
|
|
|
if (AddrTy != SrcTy)
|
|
|
|
|
DstAddr = Builder.CreateBitCast(DstAddr, llvm::PointerType::get(SrcTy),
|
|
|
|
|
"storetmp");
|
|
|
|
|
Builder.CreateStore(Src.getVal(), DstAddr);
|
2007-06-05 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-03 16:28:33 +00:00
|
|
|
void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst,
|
|
|
|
|
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-03 17:31:20 +00:00
|
|
|
unsigned EncFields = Dst.getOCUVectorElts();
|
2007-08-03 16:28:33 +00:00
|
|
|
|
|
|
|
|
llvm::Value *SrcVal = Src.getVal();
|
|
|
|
|
|
2007-08-03 16:37:04 +00: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-03 17:31:20 +00:00
|
|
|
unsigned Idx = OCUVectorElementExpr::getAccessedFieldNo(i, EncFields);
|
2007-08-03 16:37:04 +00: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-03 17:31:20 +00:00
|
|
|
unsigned InIdx = OCUVectorElementExpr::getAccessedFieldNo(0, EncFields);
|
2007-08-03 16:28:33 +00: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 05:24:33 +00:00
|
|
|
|
|
|
|
|
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
|
|
|
|
|
const Decl *D = E->getDecl();
|
2007-06-13 20:44:40 +00:00
|
|
|
if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) {
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Value *V = LocalDeclMap[D];
|
2007-06-02 05:24:33 +00:00
|
|
|
assert(V && "BlockVarDecl not entered in LocalDeclMap?");
|
2007-07-10 21:17:59 +00:00
|
|
|
return LValue::MakeAddr(V);
|
2007-06-20 04:44:43 +00:00
|
|
|
} else if (isa<FunctionDecl>(D) || isa<FileVarDecl>(D)) {
|
2007-07-10 21:17:59 +00:00
|
|
|
return LValue::MakeAddr(CGM.GetAddrOfGlobalDecl(D));
|
2007-06-02 05:24:33 +00:00
|
|
|
}
|
|
|
|
|
assert(0 && "Unimp declref");
|
|
|
|
|
}
|
2007-06-01 18:02:12 +00:00
|
|
|
|
2007-06-05 20:53:16 +00:00
|
|
|
LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
|
|
|
|
|
// __extension__ doesn't affect lvalue-ness.
|
|
|
|
|
if (E->getOpcode() == UnaryOperator::Extension)
|
|
|
|
|
return EmitLValue(E->getSubExpr());
|
|
|
|
|
|
|
|
|
|
assert(E->getOpcode() == UnaryOperator::Deref &&
|
|
|
|
|
"'*' is the only unary operator that produces an lvalue");
|
2007-08-24 05:35:26 +00:00
|
|
|
return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()));
|
2007-06-05 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-06 04:54:52 +00: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();
|
|
|
|
|
|
|
|
|
|
// FIXME: Can cache/reuse these within the module.
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Constant *C=llvm::ConstantArray::get(std::string(StrData, StrData+Len));
|
2007-06-06 04:54:52 +00:00
|
|
|
|
|
|
|
|
// Create a global variable for this.
|
2007-06-15 23:05:46 +00:00
|
|
|
C = new llvm::GlobalVariable(C->getType(), true,
|
|
|
|
|
llvm::GlobalValue::InternalLinkage,
|
2007-06-06 04:54:52 +00:00
|
|
|
C, ".str", CurFn->getParent());
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
|
|
|
|
|
llvm::Constant *Zeros[] = { Zero, Zero };
|
|
|
|
|
C = llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2);
|
2007-07-10 21:17:59 +00:00
|
|
|
return LValue::MakeAddr(C);
|
2007-06-06 04:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-21 05:21:51 +00: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());
|
|
|
|
|
llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
|
|
|
|
|
llvm::Constant *Zeros[] = { Zero, Zero };
|
|
|
|
|
C = llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2);
|
|
|
|
|
return LValue::MakeAddr(C);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 23:31:14 +00:00
|
|
|
LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
|
2007-08-20 16:18:38 +00:00
|
|
|
// The index must always be an integer, which is not an aggregate. Emit it.
|
2007-08-24 05:35:26 +00:00
|
|
|
llvm::Value *Idx = EmitScalarExpr(E->getIdx());
|
2007-06-08 23:31:14 +00:00
|
|
|
|
2007-07-10 21:17:59 +00:00
|
|
|
// If the base is a vector type, then we are forming a vector element lvalue
|
|
|
|
|
// with this subscript.
|
2007-08-20 16:18:38 +00:00
|
|
|
if (E->getLHS()->getType()->isVectorType()) {
|
2007-07-10 21:17:59 +00:00
|
|
|
// Emit the vector as an lvalue to get its address.
|
2007-08-20 16:18:38 +00:00
|
|
|
LValue LHS = EmitLValue(E->getLHS());
|
|
|
|
|
assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
|
2007-07-10 21:17:59 +00:00
|
|
|
// FIXME: This should properly sign/zero/extend or truncate Idx to i32.
|
2007-08-20 16:18:38 +00:00
|
|
|
return LValue::MakeVectorElt(LHS.getAddress(), Idx);
|
2007-07-10 21:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-20 16:18:38 +00:00
|
|
|
// The base must be a pointer, which is not an aggregate. Emit it.
|
2007-08-24 05:35:26 +00:00
|
|
|
llvm::Value *Base = EmitScalarExpr(E->getBase());
|
2007-07-10 21:17:59 +00:00
|
|
|
|
2007-08-20 16:18:38 +00:00
|
|
|
// Extend or truncate the index type to 32 or 64-bits.
|
2007-08-08 17:43:05 +00:00
|
|
|
QualType IdxTy = E->getIdx()->getType();
|
2007-06-08 23:31:14 +00:00
|
|
|
bool IdxSigned = IdxTy->isSignedIntegerType();
|
2007-06-15 23:05:46 +00:00
|
|
|
unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
|
2007-06-08 23:31:14 +00:00
|
|
|
if (IdxBitwidth != LLVMPointerWidth)
|
2007-06-15 23:05:46 +00:00
|
|
|
Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth),
|
2007-06-08 23:31:14 +00:00
|
|
|
IdxSigned, "idxprom");
|
|
|
|
|
|
|
|
|
|
// We know that the pointer points to a type of the correct size, unless the
|
|
|
|
|
// size is a VLA.
|
2007-07-15 23:26:56 +00:00
|
|
|
if (!E->getType()->isConstantSizeType(getContext()))
|
2007-06-08 23:31:14 +00:00
|
|
|
assert(0 && "VLA idx not implemented");
|
2007-07-10 21:17:59 +00:00
|
|
|
return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"));
|
2007-06-08 23:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-02 23:37:31 +00:00
|
|
|
LValue CodeGenFunction::
|
2007-08-03 17:31:20 +00:00
|
|
|
EmitOCUVectorElementExpr(const OCUVectorElementExpr *E) {
|
2007-08-02 23:37:31 +00: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-03 17:31:20 +00:00
|
|
|
return LValue::MakeOCUVectorElt(Base.getAddress(),
|
|
|
|
|
E->getEncodedElementAccess());
|
2007-08-02 23:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-01 18:02:12 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
// Expression Emission
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
2007-08-23 23:43:33 +00:00
|
|
|
/// EmitAnyExpr - Emit an expression of any type: scalar, complex, aggregate,
|
|
|
|
|
/// returning an rvalue corresponding to it. If NeedResult is false, the
|
|
|
|
|
/// result of the expression doesn't need to be generated into memory.
|
|
|
|
|
RValue CodeGenFunction::EmitAnyExpr(const Expr *E, bool NeedResult) {
|
|
|
|
|
if (!hasAggregateLLVMType(E->getType()))
|
2007-08-24 05:35:26 +00:00
|
|
|
return RValue::get(EmitScalarExpr(E));
|
2007-08-23 23:43:33 +00:00
|
|
|
|
|
|
|
|
llvm::Value *DestMem = 0;
|
|
|
|
|
if (NeedResult)
|
|
|
|
|
DestMem = CreateTempAlloca(ConvertType(E->getType()));
|
|
|
|
|
|
|
|
|
|
if (!E->getType()->isComplexType()) {
|
|
|
|
|
EmitAggExpr(E, DestMem, false);
|
|
|
|
|
} else if (NeedResult)
|
|
|
|
|
EmitComplexExprIntoAddr(E, DestMem);
|
|
|
|
|
else
|
|
|
|
|
EmitComplexExpr(E);
|
|
|
|
|
|
|
|
|
|
return RValue::getAggregate(DestMem);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 22:37:10 +00:00
|
|
|
|
2007-06-15 21:34:29 +00:00
|
|
|
RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
|
2007-08-20 18:05:56 +00: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 05:35:26 +00:00
|
|
|
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
|
2007-07-10 22:18:37 +00:00
|
|
|
|
|
|
|
|
// The callee type will always be a pointer to function type, get the function
|
|
|
|
|
// type.
|
2007-08-08 17:43:05 +00:00
|
|
|
QualType CalleeTy = E->getCallee()->getType();
|
2007-07-10 22:18:37 +00:00
|
|
|
CalleeTy = cast<PointerType>(CalleeTy.getCanonicalType())->getPointeeType();
|
|
|
|
|
|
|
|
|
|
// Get information about the argument types.
|
|
|
|
|
FunctionTypeProto::arg_type_iterator ArgTyIt = 0, ArgTyEnd = 0;
|
|
|
|
|
|
|
|
|
|
// Calling unprototyped functions provides no argument info.
|
|
|
|
|
if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(CalleeTy)) {
|
|
|
|
|
ArgTyIt = FTP->arg_type_begin();
|
|
|
|
|
ArgTyEnd = FTP->arg_type_end();
|
|
|
|
|
}
|
2007-06-15 21:34:29 +00:00
|
|
|
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::SmallVector<llvm::Value*, 16> Args;
|
2007-06-15 21:34:29 +00:00
|
|
|
|
2007-08-10 17:02:28 +00:00
|
|
|
// Handle struct-return functions by passing a pointer to the location that
|
|
|
|
|
// we would like to return into.
|
|
|
|
|
if (hasAggregateLLVMType(E->getType())) {
|
|
|
|
|
// Create a temporary alloca to hold the result of the call. :(
|
|
|
|
|
Args.push_back(CreateTempAlloca(ConvertType(E->getType())));
|
|
|
|
|
// FIXME: set the stret attribute on the argument.
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 21:34:29 +00:00
|
|
|
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
|
2007-08-08 17:43:05 +00:00
|
|
|
QualType ArgTy = E->getArg(i)->getType();
|
2007-08-23 23:43:33 +00:00
|
|
|
RValue ArgVal = EmitAnyExpr(E->getArg(i));
|
2007-07-10 22:18:37 +00:00
|
|
|
|
|
|
|
|
// If this argument has prototype information, convert it.
|
|
|
|
|
if (ArgTyIt != ArgTyEnd) {
|
|
|
|
|
ArgVal = EmitConversion(ArgVal, ArgTy, *ArgTyIt++);
|
|
|
|
|
} else {
|
|
|
|
|
// Otherwise, if passing through "..." or to a function with no prototype,
|
|
|
|
|
// perform the "default argument promotions" (C99 6.5.2.2p6), which
|
|
|
|
|
// includes the usual unary conversions, but also promotes float to
|
|
|
|
|
// double.
|
|
|
|
|
if (const BuiltinType *BT =
|
|
|
|
|
dyn_cast<BuiltinType>(ArgTy.getCanonicalType())) {
|
|
|
|
|
if (BT->getKind() == BuiltinType::Float)
|
|
|
|
|
ArgVal = RValue::get(Builder.CreateFPExt(ArgVal.getVal(),
|
|
|
|
|
llvm::Type::DoubleTy,"tmp"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 21:34:29 +00:00
|
|
|
if (ArgVal.isScalar())
|
|
|
|
|
Args.push_back(ArgVal.getVal());
|
|
|
|
|
else // Pass by-address. FIXME: Set attribute bit on call.
|
2007-06-22 18:48:09 +00:00
|
|
|
Args.push_back(ArgVal.getAggregateAddr());
|
2007-06-15 21:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-01 06:24:52 +00:00
|
|
|
llvm::Value *V = Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size());
|
2007-06-15 21:34:29 +00:00
|
|
|
if (V->getType() != llvm::Type::VoidTy)
|
|
|
|
|
V->setName("call");
|
2007-08-10 17:02:28 +00:00
|
|
|
else if (hasAggregateLLVMType(E->getType()))
|
|
|
|
|
// Struct return.
|
|
|
|
|
return RValue::getAggregate(Args[0]);
|
|
|
|
|
|
2007-06-15 21:34:29 +00:00
|
|
|
return RValue::get(V);
|
|
|
|
|
}
|