[cfe-commits] r39674 - in /cfe/cfe/trunk/CodeGen: CGStmt.cpp CodeGenFunction.cpp CodeGenFunction.h CodeGenTypes.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:47:01 PDT 2007
Author: clattner
Date: Wed Jul 11 11:47:00 2007
New Revision: 39674
URL: http://llvm.org/viewvc/llvm-project?rev=39674&view=rev
Log:
implement support for struct and complex returns.
Modified:
cfe/cfe/trunk/CodeGen/CGStmt.cpp
cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
cfe/cfe/trunk/CodeGen/CodeGenFunction.h
cfe/cfe/trunk/CodeGen/CodeGenTypes.cpp
Modified: cfe/cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGStmt.cpp?rev=39674&r1=39673&r2=39674&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGStmt.cpp Wed Jul 11 11:47:00 2007
@@ -266,10 +266,10 @@
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);
}
}
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=39674&r1=39673&r2=39674&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp Wed Jul 11 11:47:00 2007
@@ -43,6 +43,11 @@
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 @@
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);
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39674&r1=39673&r2=39674&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:47:00 2007
@@ -153,6 +153,10 @@
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);
Modified: cfe/cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=39674&r1=39673&r2=39674&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenTypes.cpp Wed Jul 11 11:47:00 2007
@@ -108,6 +108,13 @@
// 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();
More information about the cfe-commits
mailing list