forked from OSchip/llvm-project
implement support for struct and complex returns.
llvm-svn: 39674
This commit is contained in:
parent
e9a6453ded
commit
54fb19efaa
|
@ -266,10 +266,10 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
|
|||
RetVal = EmitConversion(RetVal, RV->getType(), FnRetTy);
|
||||
|
||||
if (RetVal.isScalar()) {
|
||||
// FIXME: Pass return loc in!
|
||||
Builder.CreateRet(RetVal.getVal());
|
||||
} else {
|
||||
assert(0 && "FIXME: aggregate return unimp");
|
||||
llvm::Value *SRetPtr = CurFn->arg_begin();
|
||||
EmitStoreThroughLValue(RetVal, LValue::getAddr(SRetPtr), FnRetTy);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,11 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
|
|||
return CGM.getTypes().ConvertType(T);
|
||||
}
|
||||
|
||||
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
|
||||
return !T->isRealType() && !T->isPointerType();
|
||||
}
|
||||
|
||||
|
||||
void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
|
||||
LLVMIntTy = ConvertType(getContext().IntTy);
|
||||
LLVMPointerWidth = Target.getPointerWidth(SourceLocation());
|
||||
|
@ -62,8 +67,15 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
|
|||
llvm::Value *Undef = llvm::UndefValue::get(llvm::Type::Int32Ty);
|
||||
AllocaInsertPt = Builder.CreateBitCast(Undef,llvm::Type::Int32Ty, "allocapt");
|
||||
|
||||
// Emit allocs for param decls.
|
||||
// Emit allocs for param decls. Give the LLVM Argument nodes names.
|
||||
llvm::Function::arg_iterator AI = CurFn->arg_begin();
|
||||
|
||||
// Name the struct return argument.
|
||||
if (hasAggregateLLVMType(FD->getResultType())) {
|
||||
AI->setName("agg.result");
|
||||
++AI;
|
||||
}
|
||||
|
||||
for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i, ++AI) {
|
||||
assert(AI != CurFn->arg_end() && "Argument mismatch!");
|
||||
EmitParmDecl(*FD->getParamDecl(i), AI);
|
||||
|
|
|
@ -153,6 +153,10 @@ public:
|
|||
|
||||
const llvm::Type *ConvertType(QualType T);
|
||||
|
||||
/// hasAggregateLLVMType - Return true if the specified AST type will map into
|
||||
/// an aggregate LLVM type or is void.
|
||||
static bool hasAggregateLLVMType(QualType T);
|
||||
|
||||
/// getBasicBlockForLabel - Return the LLVM basicblock that the specified
|
||||
/// label maps to.
|
||||
llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
|
||||
|
|
|
@ -108,6 +108,13 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
|||
// FIXME: Convert argument types.
|
||||
bool isVarArg;
|
||||
std::vector<const llvm::Type*> ArgTys;
|
||||
|
||||
// Struct return passes the struct byref.
|
||||
if (!ResultType->isFirstClassType()) {
|
||||
ArgTys.push_back(llvm::PointerType::get(ResultType));
|
||||
ResultType = llvm::Type::VoidTy;
|
||||
}
|
||||
|
||||
if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(&FP)) {
|
||||
DecodeArgumentTypes(*FTP, ArgTys);
|
||||
isVarArg = FTP->isVariadic();
|
||||
|
|
Loading…
Reference in New Issue