start splitting out aggregate value computation from EmitExpr into EmitAggExpr.
aggregate value and scalar expression computation are very different, this
gets them away from each other. This causes a temporary regression on some
complex number examples.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41014 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 8937eaf..896db31 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -47,10 +47,12 @@
llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
llvm::Constant *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
+ // FIXME: It would be nice to make this "Ptr->getName()+realp"
llvm::Value *RealPtr = Builder.CreateGEP(Ptr, Zero, Zero, "realp");
llvm::Value *ImagPtr = Builder.CreateGEP(Ptr, Zero, One, "imagp");
// FIXME: Handle volatility.
+ // FIXME: It would be nice to make this "Ptr->getName()+real"
Real = Builder.CreateLoad(RealPtr, "real");
Imag = Builder.CreateLoad(ImagPtr, "imag");
}
@@ -272,11 +274,8 @@
if (EltTy->isFirstClassType())
return RValue::get(Builder.CreateLoad(Ptr, "tmp"));
- if (ExprType->isFunctionType())
- return RValue::get(Ptr);
-
- // Otherwise, we have an aggregate lvalue.
- return RValue::getAggregate(Ptr);
+ assert(ExprType->isFunctionType() && "Unknown scalar value");
+ return RValue::get(Ptr);
}
if (LV.isVectorElt()) {
@@ -376,48 +375,16 @@
}
llvm::Value *DstAddr = Dst.getAddress();
- if (Src.isScalar()) {
- // 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);
- return;
- }
+ 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();
- // Don't use memcpy for complex numbers.
- if (Ty->isComplexType()) {
- llvm::Value *Real, *Imag;
- EmitLoadOfComplex(Src, Real, Imag);
- EmitStoreOfComplex(Real, Imag, Dst.getAddress());
- return;
- }
-
- // Aggregate assignment turns into llvm.memcpy.
- const llvm::Type *SBP = llvm::PointerType::get(llvm::Type::Int8Ty);
- llvm::Value *SrcAddr = Src.getAggregateAddr();
-
- if (DstAddr->getType() != SBP)
- DstAddr = Builder.CreateBitCast(DstAddr, SBP, "tmp");
- if (SrcAddr->getType() != SBP)
- SrcAddr = Builder.CreateBitCast(SrcAddr, SBP, "tmp");
-
- unsigned Align = 1; // FIXME: Compute type alignments.
- unsigned Size = 1234; // FIXME: Compute type sizes.
-
- // FIXME: Handle variable sized types.
- const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth);
- llvm::Value *SizeVal = llvm::ConstantInt::get(IntPtr, Size);
-
- llvm::Value *MemCpyOps[4] = {
- DstAddr, SrcAddr, SizeVal,llvm::ConstantInt::get(llvm::Type::Int32Ty, Align)
- };
-
- Builder.CreateCall(CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4);
+ if (AddrTy != SrcTy)
+ DstAddr = Builder.CreateBitCast(DstAddr, llvm::PointerType::get(SrcTy),
+ "storetmp");
+ Builder.CreateStore(Src.getVal(), DstAddr);
}
void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst,
@@ -585,7 +552,8 @@
//===--------------------------------------------------------------------===//
RValue CodeGenFunction::EmitExpr(const Expr *E) {
- assert(E && "Null expression?");
+ assert(E && !hasAggregateLLVMType(E->getType()) &&
+ "Invalid scalar expression to emit");
switch (E->getStmtClass()) {
default:
@@ -641,7 +609,6 @@
case Expr::ChooseExprClass:
return EmitChooseExpr(cast<ChooseExpr>(E));
}
-
}
RValue CodeGenFunction::EmitIntegerLiteral(const IntegerLiteral *E) {
@@ -1401,8 +1368,8 @@
// Store the value into the LHS.
EmitStoreThroughLValue(RHS, LHS, E->getType());
-
- // Return the converted RHS.
+
+ // Return the RHS.
return RHS;
}
@@ -1420,8 +1387,6 @@
llvm::Value *Cond = EvaluateExprAsBool(E->getCond());
Builder.CreateCondBr(Cond, LHSBlock, RHSBlock);
- // FIXME: Implement this for aggregate values.
-
EmitBlock(LHSBlock);
// Handle the GNU extension for missing LHS.
llvm::Value *LHSValue = E->getLHS() ? EmitExpr(E->getLHS()).getVal() : Cond;