Miscellaneous codegen cleanups.  Mostly, don't create new basic blocks
just to save the current insertion state!  This change significantly
simplifies the IR CFG in exceptions code.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101996 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 7809972..28ef30e 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -111,6 +111,23 @@
                      IsInitializer);
 }
 
+/// EmitAnyExprToMem - Evaluate an expression into a given memory
+/// location.
+void CodeGenFunction::EmitAnyExprToMem(const Expr *E,
+                                       llvm::Value *Location,
+                                       bool IsLocationVolatile,
+                                       bool IsInit) {
+  if (E->getType()->isComplexType())
+    EmitComplexExprIntoAddr(E, Location, IsLocationVolatile);
+  else if (hasAggregateLLVMType(E->getType()))
+    EmitAggExpr(E, Location, IsLocationVolatile, /*Ignore*/ false, IsInit);
+  else {
+    RValue RV = RValue::get(EmitScalarExpr(E, /*Ignore*/ false));
+    LValue LV = LValue::MakeAddr(Location, MakeQualifiers(E->getType()));
+    EmitStoreThroughLValue(RV, LV, E->getType());
+  }
+}
+
 RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
                                                    bool IsInitializer) {
   bool ShouldDestroyTemporaries = false;
@@ -1561,12 +1578,7 @@
   const Expr* InitExpr = E->getInitializer();
   LValue Result = LValue::MakeAddr(DeclPtr, MakeQualifiers(E->getType()));
 
-  if (E->getType()->isComplexType())
-    EmitComplexExprIntoAddr(InitExpr, DeclPtr, false);
-  else if (hasAggregateLLVMType(E->getType()))
-    EmitAnyExpr(InitExpr, DeclPtr, false);
-  else
-    EmitStoreThroughLValue(EmitAnyExpr(InitExpr), Result, E->getType());
+  EmitAnyExprToMem(InitExpr, DeclPtr, /*Volatile*/ false);
 
   return Result;
 }