From: Chris Lattner Date: Sun, 26 Aug 2007 23:13:56 +0000 (+0000) Subject: move EmitAggregateCopy into AggExprEmitter X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bfc0c1ae4b505b52b36f572a9641f99e76879cab;p=clang move EmitAggregateCopy into AggExprEmitter git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41472 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGExprAgg.cpp b/CodeGen/CGExprAgg.cpp index 17e11a1fe4..8ae6f695e8 100644 --- a/CodeGen/CGExprAgg.cpp +++ b/CodeGen/CGExprAgg.cpp @@ -27,11 +27,13 @@ using namespace CodeGen; namespace { class VISIBILITY_HIDDEN AggExprEmitter : public StmtVisitor { CodeGenFunction &CGF; + llvm::LLVMBuilder &Builder; llvm::Value *DestPtr; bool VolatileDest; public: AggExprEmitter(CodeGenFunction &cgf, llvm::Value *destPtr, bool volatileDest) - : CGF(cgf), DestPtr(destPtr), VolatileDest(volatileDest) { + : CGF(cgf), Builder(CGF.Builder), + DestPtr(destPtr), VolatileDest(volatileDest) { } //===--------------------------------------------------------------------===// @@ -43,6 +45,8 @@ public: /// then loads the result into DestPtr. void EmitAggLoadOfLValue(const Expr *E); + void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, + QualType EltTy); //===--------------------------------------------------------------------===// // Visitor Methods @@ -76,6 +80,34 @@ public: // Utilities //===----------------------------------------------------------------------===// +void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr, + llvm::Value *SrcPtr, QualType Ty) { + assert(!Ty->isComplexType() && "Shouldn't happen for complex"); + + // Aggregate assignment turns into llvm.memcpy. + const llvm::Type *BP = llvm::PointerType::get(llvm::Type::Int8Ty); + if (DestPtr->getType() != BP) + DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); + if (SrcPtr->getType() != BP) + SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); + + // Get size and alignment info for this aggregate. + std::pair TypeInfo = + CGF.getContext().getTypeInfo(Ty, SourceLocation()); + + // FIXME: Handle variable sized types. + const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth); + + llvm::Value *MemCpyOps[4] = { + DestPtr, SrcPtr, + llvm::ConstantInt::get(IntPtr, TypeInfo.first), + llvm::ConstantInt::get(llvm::Type::Int32Ty, TypeInfo.second) + }; + + Builder.CreateCall(CGF.CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4); +} + + /// EmitAggLoadOfLValue - Given an expression with aggregate type that /// represents a value lvalue, this method emits the address of the lvalue, /// then loads the result into DestPtr. @@ -89,7 +121,7 @@ void AggExprEmitter::EmitAggLoadOfLValue(const Expr *E) { // FIXME: If the source is volatile, we must read from it. return; - CGF.EmitAggregateCopy(DestPtr, SrcPtr, E->getType()); + EmitAggregateCopy(DestPtr, SrcPtr, E->getType()); } //===----------------------------------------------------------------------===// @@ -121,7 +153,7 @@ void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) { llvm::BasicBlock *ContBlock = new llvm::BasicBlock("cond.cont"); llvm::Value *Cond = CGF.EvaluateExprAsBool(E->getCond()); - CGF.Builder.CreateCondBr(Cond, LHSBlock, RHSBlock); + Builder.CreateCondBr(Cond, LHSBlock, RHSBlock); CGF.EmitBlock(LHSBlock); @@ -129,14 +161,14 @@ void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) { assert(E->getLHS() && "Must have LHS for aggregate value"); Visit(E->getLHS()); - CGF.Builder.CreateBr(ContBlock); - LHSBlock = CGF.Builder.GetInsertBlock(); + Builder.CreateBr(ContBlock); + LHSBlock = Builder.GetInsertBlock(); CGF.EmitBlock(RHSBlock); Visit(E->getRHS()); - CGF.Builder.CreateBr(ContBlock); - RHSBlock = CGF.Builder.GetInsertBlock(); + Builder.CreateBr(ContBlock); + RHSBlock = Builder.GetInsertBlock(); CGF.EmitBlock(ContBlock); } @@ -155,32 +187,3 @@ void CodeGenFunction::EmitAggExpr(const Expr *E, llvm::Value *DestPtr, AggExprEmitter(*this, DestPtr, VolatileDest).Visit(const_cast(E)); } - - -// FIXME: Handle volatility! -void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr, - llvm::Value *SrcPtr, QualType Ty) { - assert(!Ty->isComplexType() && "Shouldn't happen for complex"); - - // Aggregate assignment turns into llvm.memcpy. - const llvm::Type *BP = llvm::PointerType::get(llvm::Type::Int8Ty); - if (DestPtr->getType() != BP) - DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); - if (SrcPtr->getType() != BP) - SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); - - // Get size and alignment info for this aggregate. - std::pair TypeInfo = - getContext().getTypeInfo(Ty, SourceLocation()); - - // FIXME: Handle variable sized types. - const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth); - - llvm::Value *MemCpyOps[4] = { - DestPtr, SrcPtr, - llvm::ConstantInt::get(IntPtr, TypeInfo.first), - llvm::ConstantInt::get(llvm::Type::Int32Ty, TypeInfo.second) - }; - - Builder.CreateCall(CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4); -} diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h index 43fa98c18d..3b8d7a20af 100644 --- a/CodeGen/CodeGenFunction.h +++ b/CodeGen/CodeGenFunction.h @@ -180,9 +180,10 @@ public: /// CodeGenFunction - This class organizes the per-function state that is used /// while generating LLVM code. class CodeGenFunction { +public: CodeGenModule &CGM; // Per-module state. TargetInfo &Target; -public: + typedef std::pair ComplexPairTy; llvm::LLVMBuilder Builder; @@ -328,11 +329,10 @@ public: llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); //===--------------------------------------------------------------------===// - // Aggregate Expression Emission + // Expression Emission //===--------------------------------------------------------------------===// - - void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, - QualType EltTy); + + // Expressions are broken into three classes: scalar, complex, aggregate. /// EmitScalarExpr - Emit the computation of the specified expression of /// LLVM scalar type, returning the result.