Add IsFinished arg to EmitBlock.
 - Indicates that caller is done with the block and it can be dropped
   if it has no predecessors. Useful for callers who need to make
   landing pads but which may not be reached.

No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59207 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index a66b6fe..ad081c9 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -157,9 +157,15 @@
   return EmitAnyExpr(cast<Expr>(LastStmt), AggLoc);
 }
 
-void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) {
+void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
   // Fall out of the current block (if necessary).
   EmitBranch(BB);
+
+  if (IsFinished && BB->use_empty()) {
+    delete BB;
+    return;
+  }
+
   CurFn->getBasicBlockList().push_back(BB);
   Builder.SetInsertPoint(BB);
 }
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 21d8f4f..50b35bd 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -237,7 +237,12 @@
   /// insert point, adding a fall-through branch from the current
   /// insert block if necessary. It is legal to call this function
   /// even if there is no current insertion point.
-  void EmitBlock(llvm::BasicBlock *BB);
+  ///
+  /// IsFinished - If true, indicates that the caller has finished
+  /// emitting branches to the given block and does not expect to emit
+  /// code into it. This means the block can be ignored if it is
+  /// unreachable.
+  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
 
   /// EmitBranch - Emit a branch to the specified basic block from the
   /// current insert block, taking care to avoid creation of branches