[PATCH] Work-in-progress omnibus patch for native Windows C++ EH outlining

Reid Kleckner rnk at google.com
Wed Feb 25 15:03:50 PST 2015


Some early feedback, I still need to look at mapLandingPadBlocks.

It looks like your analysis runs once per landing pad, so chained EH actions will still get visited twice. We might want to consider an up-front analysis on the whole function.


REPOSITORY
  rL LLVM

================
Comment at: include/llvm/Transforms/Utils/Cloning.h:148-149
@@ -148,1 +147,4 @@
+    StopCloningBB,
+    ///< Don't clone the terminator but clone the current block's successors.
+    CloneSuccessors
   };
----------------
Can SkipInstruction do this also?

================
Comment at: lib/CodeGen/WinEHPrepare.cpp:443-457
@@ -234,8 +442,17 @@
 
-  // FIXME: We will replace the landingpad bodies with llvm.eh.actions
-  //        calls and indirect branches here and then delete blocks
-  //        which are no longer reachable.  That will get rid of the
-  //        handlers that we have outlined.  There is code below
-  //        that looks for allocas with no uses in the parent function.
-  //        That will only happen after the pruning is implemented.
+  // Go through the blocks in the function and delete any that are no longer reachable.
+  BasicBlock *Entry = &F.getEntryBlock();
+  Function::iterator BBI = F.begin();
+  while (BBI != F.end()) {
+    // Check if this block has become dead during inlining or other
+    // simplifications. Note that the first block will appear dead, as it has
+    // not yet been wired up properly.
+    if (cast<BasicBlock>(BBI) != Entry && (pred_empty(BBI) ||
+                       BBI->getSinglePredecessor() == BBI)) {
+      BasicBlock *DeadBB = BBI++;
+      DeleteDeadBlock(DeadBB);
+      continue;
+    }
+    ++BBI;
+  }
 
----------------
This can be just removeUnreachableBlocks(F). If we need more cleanup power, we can consider making simplifyFunctionCFG from lib/Transforms/Scalar/SimplifyCFGPass.cpp a utility.

================
Comment at: lib/CodeGen/WinEHPrepare.cpp:1003-1009
@@ +1002,9 @@
+
+// This function parses a landing pad to see if all it does is resume.
+// If so, it would be called from within another landing pad for
+// exception handling, but since it does nothing any invoke that leads
+// to this landing pad can be replaced with a call and an unconditional
+// branch to the normal destination.  Any exceptions that occur within the
+// called function will be handled by the normal runtime exception handling
+// process.
+static bool isLandingPadEmptyResume(const BasicBlock *LPadBB) {
----------------
Based on the comment, I think SimplifyCFG knows how to do this already. If you run SimplifyCFG() on each landing pad BB, you'll get the same behavior with none of this code.

You may need to run some other cleanup utility on the block first, though.

================
Comment at: lib/CodeGen/WinEHPrepare.cpp:1317
@@ +1316,3 @@
+
+  // FIXME: Wrap this with DEBUG
+  DEBUG(dbgs() << "Mapping landing pad: " << BB->getName() << "\n");
----------------
Looks like you did that. :)

http://reviews.llvm.org/D7886

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list