Support SCoPs with multiple exit edges

Regions that have multiple exit edges are very common. A simple if condition
yields e.g. such a region:

        if
      /   \
  then     else
      \   /
      after

Region: if -> after

This regions contains the bbs 'if', 'then', 'else', but not 'after'. It has
two exit edges 'then' -> 'after' and 'else' -> 'after'.

Previously we scheduled the RegionSimplify pass to translate such regions into
simple regions. With this patch, we now support them natively.

Contributed-by: Star Tan <tanmx_star@yeah.net>
llvm-svn: 179159
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index e3e5621..664638c 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -34,6 +34,7 @@
 #include "polly/CodeGen/PTXGenerator.h"
 #include "polly/CodeGen/Utils.h"
 #include "polly/Support/GICHelper.h"
+#include "polly/Support/ScopHelper.h"
 
 #include "llvm/IR/Module.h"
 #include "llvm/ADT/SetVector.h"
@@ -983,7 +984,16 @@
   bool runOnScop(Scop &S) {
     ParallelLoops.clear();
 
-    assert(S.getRegion().isSimple() && "Only simple regions are supported");
+    Region &R = S.getRegion();
+
+    assert (!R.isTopLevelRegion() && "Top level regions are not supported");
+    assert (R.getEnteringBlock() && "Only support regions with a single entry");
+
+    if (!R.getExitingBlock()) {
+      BasicBlock *newExit = createSingleExitEdge(&R, this);
+      for (Region::const_iterator RI = R.begin(), RE = R.end(); RI != RE; ++RI)
+        (*RI)->replaceExitRecursive(newExit);
+    }
 
     BasicBlock *StartBlock = executeScopConditionally(S, this);