move EmitLoadOfComplex/EmitStoreOfComplex into ComplexExprEmitter.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41236 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGAggExpr.cpp b/CodeGen/CGAggExpr.cpp
index 93f78a4..f643f6f 100644
--- a/CodeGen/CGAggExpr.cpp
+++ b/CodeGen/CGAggExpr.cpp
@@ -160,14 +160,7 @@
// FIXME: Handle volatility!
void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
llvm::Value *SrcPtr, QualType Ty) {
- // Don't use memcpy for complex numbers.
- // FIXME: split complex number handling out of here.
- if (Ty->isComplexType()) {
- llvm::Value *Real, *Imag;
- EmitLoadOfComplex(SrcPtr, Real, Imag);
- EmitStoreOfComplex(Real, Imag, DestPtr);
- return;
- }
+ assert(!Ty->isComplexType() && "Shouldn't happen for complex");
// Aggregate assignment turns into llvm.memcpy.
const llvm::Type *BP = llvm::PointerType::get(llvm::Type::Int8Ty);
diff --git a/CodeGen/CGComplexExpr.cpp b/CodeGen/CGComplexExpr.cpp
index c7296fc..2045169 100644
--- a/CodeGen/CGComplexExpr.cpp
+++ b/CodeGen/CGComplexExpr.cpp
@@ -42,8 +42,17 @@
/// EmitLoadOfLValue - Given an expression with complex type that represents a
/// value l-value, this method emits the address of the l-value, then loads
/// and returns the result.
- ComplexPairTy EmitLoadOfLValue(const Expr *E);
+ ComplexPairTy EmitLoadOfLValue(const Expr *E) {
+ return EmitLoadOfComplex(CGF.EmitLValue(E).getAddress());
+ }
+ /// EmitLoadOfComplex - Given a pointer to a complex value, emit code to load
+ /// the real and imaginary pieces.
+ ComplexPairTy EmitLoadOfComplex(llvm::Value *SrcPtr);
+
+ /// EmitStoreOfComplex - Store the specified real/imag parts into the
+ /// specified value pointer.
+ void EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *ResPtr);
//===--------------------------------------------------------------------===//
// Visitor Methods
@@ -89,19 +98,37 @@
// Utilities
//===----------------------------------------------------------------------===//
-/// EmitLoadOfLValue - Given an expression with complex type that represents a
-/// value l-value, this method emits the address of the l-value, then loads
-/// and returns the result.
-ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(const Expr *E) {
- LValue LV = CGF.EmitLValue(E);
- assert(LV.isSimple() && "Can't have complex bitfield, vector, etc");
+/// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
+/// load the real and imaginary pieces, returning them as Real/Imag.
+ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr) {
+ 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 = CGF.Builder.CreateGEP(SrcPtr, Zero, Zero, "realp");
+ llvm::Value *ImagPtr = CGF.Builder.CreateGEP(SrcPtr, Zero, One, "imagp");
- // Load the real/imag values.
- llvm::Value *Real, *Imag;
- CGF.EmitLoadOfComplex(LV.getAddress(), Real, Imag);
+ // FIXME: Handle volatility.
+ // FIXME: It would be nice to make this "Ptr->getName()+real"
+ llvm::Value *Real = CGF.Builder.CreateLoad(RealPtr, "real");
+ llvm::Value *Imag = CGF.Builder.CreateLoad(ImagPtr, "imag");
return ComplexPairTy(Real, Imag);
}
+/// EmitStoreOfComplex - Store the specified real/imag parts into the
+/// specified value pointer.
+void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy V, llvm::Value *Ptr) {
+ llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+ llvm::Constant *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
+ llvm::Value *RealPtr = CGF.Builder.CreateGEP(Ptr, Zero, Zero, "real");
+ llvm::Value *ImagPtr = CGF.Builder.CreateGEP(Ptr, Zero, One, "imag");
+
+ // FIXME: Handle volatility.
+ CGF.Builder.CreateStore(V.first, RealPtr);
+ CGF.Builder.CreateStore(V.second, ImagPtr);
+}
+
+
+
//===----------------------------------------------------------------------===//
// Visitor Methods
//===----------------------------------------------------------------------===//
@@ -148,7 +175,7 @@
// Store into it.
// FIXME: Volatility!
- CGF.EmitStoreOfComplex(Val.first, Val.second, LHS.getAddress());
+ EmitStoreOfComplex(Val, LHS.getAddress());
return Val;
}
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 6cb4e86..ee7b47e 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -40,36 +40,6 @@
return ConvertScalarValueToBool(EmitExpr(E), E->getType());
}
-/// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
-/// load the real and imaginary pieces, returning them as Real/Imag.
-void CodeGenFunction::EmitLoadOfComplex(llvm::Value *SrcPtr,
- llvm::Value *&Real, llvm::Value *&Imag){
- 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(SrcPtr, Zero, Zero, "realp");
- llvm::Value *ImagPtr = Builder.CreateGEP(SrcPtr, 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");
-}
-
-/// EmitStoreOfComplex - Store the specified real/imag parts into the
-/// specified value pointer.
-void CodeGenFunction::EmitStoreOfComplex(llvm::Value *Real, llvm::Value *Imag,
- llvm::Value *ResPtr) {
- llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
- llvm::Constant *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
- llvm::Value *RealPtr = Builder.CreateGEP(ResPtr, Zero, Zero, "real");
- llvm::Value *ImagPtr = Builder.CreateGEP(ResPtr, Zero, One, "imag");
-
- // FIXME: Handle volatility.
- Builder.CreateStore(Real, RealPtr);
- Builder.CreateStore(Imag, ImagPtr);
-}
-
//===--------------------------------------------------------------------===//
// Conversions
//===--------------------------------------------------------------------===//
diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h
index 5ece5cd..a0a3c61 100644
--- a/CodeGen/CodeGenFunction.h
+++ b/CodeGen/CodeGenFunction.h
@@ -248,16 +248,6 @@
llvm::Value *EvaluateExprAsBool(const Expr *E);
- /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
- /// load the real and imaginary pieces, returning them as Real/Imag.
- void EmitLoadOfComplex(llvm::Value *SrcPtr, llvm::Value *&Real,
- llvm::Value *&Imag);
-
- /// EmitStoreOfComplex - Store the specified real/imag parts into the
- /// specified value pointer.
- void EmitStoreOfComplex(llvm::Value *Real, llvm::Value *Imag,
- llvm::Value *ResPtr);
-
//===--------------------------------------------------------------------===//
// Conversions
//===--------------------------------------------------------------------===//