]> granicus.if.org Git - clang/commitdiff
Teach EmitBlock to put the target block immediately after the current block
authorJohn McCall <rjmccall@apple.com>
Wed, 21 Apr 2010 10:29:06 +0000 (10:29 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 21 Apr 2010 10:29:06 +0000 (10:29 +0000)
(if there's a current block).  The chief advantage of doing this is that it
lets us pick blocks (e.g. EH blocks) to push to the end of the function so
that fallthrough happens consistently --- i.e. it gives us the flexibility
of ordering blocks as we please without having to change the order in which
we generate code.  There are standard (?) optimization passes which can do some
of that for us, but better to generate reasonable code to begin with.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101997 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp

index 07c96d82ca7da477b97c4580a41d2dd89b2d02b2..eb861f469063f4bf6273285a3011d5ba2b38073d 100644 (file)
@@ -225,7 +225,12 @@ void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
     }
   }
 
-  CurFn->getBasicBlockList().push_back(BB);
+  // Place the block after the current block, if possible, or else at
+  // the end of the function.
+  if (Builder.GetInsertBlock())
+    CurFn->getBasicBlockList().insertAfter(Builder.GetInsertBlock(), BB);
+  else
+    CurFn->getBasicBlockList().push_back(BB);
   Builder.SetInsertPoint(BB);
 }