[cfe-commits] r41472 - in /cfe/trunk/CodeGen: CGExprAgg.cpp CodeGenFunction.h
Chris Lattner
sabre at nondot.org
Sun Aug 26 16:13:56 PDT 2007
Author: lattner
Date: Sun Aug 26 18:13:56 2007
New Revision: 41472
URL: http://llvm.org/viewvc/llvm-project?rev=41472&view=rev
Log:
move EmitAggregateCopy into AggExprEmitter
Modified:
cfe/trunk/CodeGen/CGExprAgg.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprAgg.cpp?rev=41472&r1=41471&r2=41472&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/CodeGen/CGExprAgg.cpp Sun Aug 26 18:13:56 2007
@@ -27,11 +27,13 @@
namespace {
class VISIBILITY_HIDDEN AggExprEmitter : public StmtVisitor<AggExprEmitter> {
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 @@
/// 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 @@
// 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<uint64_t, unsigned> 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 @@
// 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 @@
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 @@
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 @@
AggExprEmitter(*this, DestPtr, VolatileDest).Visit(const_cast<Expr*>(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<uint64_t, unsigned> 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);
-}
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41472&r1=41471&r2=41472&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Sun Aug 26 18:13:56 2007
@@ -180,9 +180,10 @@
/// 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<llvm::Value *, llvm::Value *> ComplexPairTy;
llvm::LLVMBuilder Builder;
@@ -328,11 +329,10 @@
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.
More information about the cfe-commits
mailing list