<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 18, 2015 at 10:31 AM, Andrew Kaylor <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: akaylor<br>
Date: Wed Feb 18 12:31:51 2015<br>
New Revision: 229715<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=229715&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=229715&view=rev</a><br>
Log:<br>
Adding implementation to outline C++ catch handlers for native Windows 64 exception handling.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D7363" target="_blank">http://reviews.llvm.org/D7363</a><br>
<br>
<br>
Added:<br>
    llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll<br>
    llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/Transforms/Utils/Cloning.h<br>
    llvm/trunk/lib/CodeGen/WinEHPrepare.cpp<br>
    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br></blockquote><div><br>Looks like some/all parts of this change have windows line endings - could you fix that? (& update your source control client config to handle this in the future - I forget what the right incantation is, though, but it's been discussed before on the mailing list)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified: llvm/trunk/include/llvm/Transforms/Utils/Cloning.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=229715&r1=229714&r2=229715&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=229715&r1=229714&r2=229715&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Transforms/Utils/Cloning.h (original)<br>
+++ llvm/trunk/include/llvm/Transforms/Utils/Cloning.h Wed Feb 18 12:31:51 2015<br>
@@ -135,6 +135,41 @@ void CloneFunctionInto(Function *NewFunc<br>
                        ValueMapTypeRemapper *TypeMapper = nullptr,<br>
                        ValueMaterializer *Materializer = nullptr);<br>
<br>
+/// A helper class used with CloneAndPruneIntoFromInst to change the default<br>
+/// behavior while instructions are being cloned.<br>
+class CloningDirector {<br>
+public:<br>
+  /// This enumeration describes the way CloneAndPruneIntoFromInst should<br>
+  /// proceed after the CloningDirector has examined an instruction.<br>
+  enum CloningAction {<br>
+    ///< Continue cloning the instruction (default behavior).<br>
+    CloneInstruction,<br>
+    ///< Skip this instruction but continue cloning the current basic block.<br>
+    SkipInstruction,<br>
+    ///< Skip this instruction and stop cloning the current basic block.<br>
+    StopCloningBB<br>
+  };<br>
+<br>
+  CloningDirector() {}<br></blockquote><div><br>^ this looks like the default/implicit ctor - do you need to provide it here for any reason rather than just not specifying it and relying on the implicit default?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  virtual ~CloningDirector() {}<br></blockquote><div><br>This could be "= default" at least, I think. (while still being virtual)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+  /// Subclasses must override this function to customize cloning behavior.<br>
+  virtual CloningAction handleInstruction(ValueToValueMapTy &VMap,<br>
+                                          const Instruction *Inst,<br>
+                                          BasicBlock        *NewBB) = 0;<br></blockquote><div><br>Weird whitespace here - try clang-format?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+};<br>
+<br>
+void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,<br>
+                               const Instruction *StartingInst,<br>
+                               ValueToValueMapTy &VMap,<br>
+                               bool ModuleLevelChanges,<br>
+                               SmallVectorImpl<ReturnInst*> &Returns,<br>
+                               const char *NameSuffix = "",<br>
+                               ClonedCodeInfo *CodeInfo = nullptr,<br>
+                               const DataLayout *DL = nullptr,<br>
+                               CloningDirector *Director = nullptr);<br>
+<br>
+<br>
 /// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,<br>
 /// except that it does some simple constant prop and DCE on the fly.  The<br>
 /// effect of this is to copy significantly less code in cases where (for<br>
<br>
Modified: llvm/trunk/lib/CodeGen/WinEHPrepare.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=229715&r1=229714&r2=229715&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=229715&r1=229714&r2=229715&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Wed Feb 18 12:31:51 2015<br>
@@ -1,102 +1,395 @@<br>
-//===-- WinEHPrepare - Prepare exception handling for code generation ---===//<br>
-//<br>
-//                     The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-//<br>
-// This pass lowers LLVM IR exception handling into something closer to what the<br>
-// backend wants. It snifs the personality function to see which kind of<br>
-// preparation is necessary. If the personality function uses the Itanium LSDA,<br>
-// this pass delegates to the DWARF EH preparation pass.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#include "llvm/CodeGen/Passes.h"<br>
-#include "llvm/Analysis/LibCallSemantics.h"<br>
-#include "llvm/IR/Function.h"<br>
-#include "llvm/IR/IRBuilder.h"<br>
-#include "llvm/IR/Instructions.h"<br>
-#include "llvm/Pass.h"<br>
-#include <memory><br>
-<br>
-using namespace llvm;<br>
-<br>
-#define DEBUG_TYPE "winehprepare"<br>
-<br>
-namespace {<br>
-class WinEHPrepare : public FunctionPass {<br>
-  std::unique_ptr<FunctionPass> DwarfPrepare;<br>
-<br>
-public:<br>
-  static char ID; // Pass identification, replacement for typeid.<br>
-  WinEHPrepare(const TargetMachine *TM = nullptr)<br>
-      : FunctionPass(ID), DwarfPrepare(createDwarfEHPass(TM)) {}<br>
-<br>
-  bool runOnFunction(Function &Fn) override;<br>
-<br>
-  bool doFinalization(Module &M) override;<br>
-<br>
-  void getAnalysisUsage(AnalysisUsage &AU) const override;<br>
-<br>
-  const char *getPassName() const override {<br>
-    return "Windows exception handling preparation";<br>
-  }<br>
-};<br>
-} // end anonymous namespace<br>
-<br>
-char WinEHPrepare::ID = 0;<br>
-INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare",<br>
-                   "Prepare Windows exceptions", false, false)<br>
-<br>
-FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {<br>
-  return new WinEHPrepare(TM);<br>
-}<br>
-<br>
-static bool isMSVCPersonality(EHPersonality Pers) {<br>
-  return Pers == EHPersonality::MSVC_Win64SEH ||<br>
-         Pers == EHPersonality::MSVC_CXX;<br>
-}<br>
-<br>
-bool WinEHPrepare::runOnFunction(Function &Fn) {<br>
-  SmallVector<LandingPadInst *, 4> LPads;<br>
-  SmallVector<ResumeInst *, 4> Resumes;<br>
-  for (BasicBlock &BB : Fn) {<br>
-    if (auto *LP = BB.getLandingPadInst())<br>
-      LPads.push_back(LP);<br>
-    if (auto *Resume = dyn_cast<ResumeInst>(BB.getTerminator()))<br>
-      Resumes.push_back(Resume);<br>
-  }<br>
-<br>
-  // No need to prepare functions that lack landing pads.<br>
-  if (LPads.empty())<br>
-    return false;<br>
-<br>
-  // Classify the personality to see what kind of preparation we need.<br>
-  EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());<br>
-<br>
-  // Delegate through to the DWARF pass if this is unrecognized.<br>
-  if (!isMSVCPersonality(Pers))<br>
-    return DwarfPrepare->runOnFunction(Fn);<br>
-<br>
-  // FIXME: Cleanups are unimplemented. Replace them with unreachable.<br>
-  if (Resumes.empty())<br>
-    return false;<br>
-<br>
-  for (ResumeInst *Resume : Resumes) {<br>
-    IRBuilder<>(Resume).CreateUnreachable();<br>
-    Resume->eraseFromParent();<br>
-  }<br>
-<br>
-  return true;<br>
-}<br>
-<br>
-bool WinEHPrepare::doFinalization(Module &M) {<br>
-  return DwarfPrepare->doFinalization(M);<br>
-}<br>
-<br>
-void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {<br>
-  DwarfPrepare->getAnalysisUsage(AU);<br>
-}<br>
+//===-- WinEHPrepare - Prepare exception handling for code generation ---===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This pass lowers LLVM IR exception handling into something closer to what the<br>
+// backend wants. It snifs the personality function to see which kind of<br>
+// preparation is necessary. If the personality function uses the Itanium LSDA,<br>
+// this pass delegates to the DWARF EH preparation pass.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/CodeGen/Passes.h"<br>
+#include "llvm/Analysis/LibCallSemantics.h"<br>
+#include "llvm/IR/Function.h"<br>
+#include "llvm/IR/IRBuilder.h"<br>
+#include "llvm/IR/Instructions.h"<br>
+#include "llvm/IR/IntrinsicInst.h"<br>
+#include "llvm/IR/Module.h"<br>
+#include "llvm/IR/PatternMatch.h"<br>
+#include "llvm/Pass.h"<br>
+#include "llvm/Transforms/Utils/Cloning.h"<br>
+#include "llvm/Transforms/Utils/Local.h"<br>
+#include <memory><br>
+<br>
+using namespace llvm;<br>
+using namespace llvm::PatternMatch;<br>
+<br>
+#define DEBUG_TYPE "winehprepare"<br>
+<br>
+namespace {<br>
+class WinEHPrepare : public FunctionPass {<br>
+  std::unique_ptr<FunctionPass> DwarfPrepare;<br>
+<br>
+public:<br>
+  static char ID; // Pass identification, replacement for typeid.<br>
+  WinEHPrepare(const TargetMachine *TM = nullptr)<br>
+      : FunctionPass(ID), DwarfPrepare(createDwarfEHPass(TM)) {}<br>
+<br>
+  bool runOnFunction(Function &Fn) override;<br>
+<br>
+  bool doFinalization(Module &M) override;<br>
+<br>
+  void getAnalysisUsage(AnalysisUsage &AU) const override;<br>
+<br>
+  const char *getPassName() const override {<br>
+    return "Windows exception handling preparation";<br>
+  }<br>
+<br>
+private:<br>
+  bool prepareCPPEHHandlers(Function &F,<br>
+                            SmallVectorImpl<LandingPadInst *> &LPads);<br>
+  bool outlineCatchHandler(Function *SrcFn, Constant *SelectorType,<br>
+                           LandingPadInst *LPad, StructType *EHDataStructTy);<br>
+};<br>
+<br>
+class WinEHCatchDirector : public CloningDirector {<br>
+public:<br>
+  WinEHCatchDirector(LandingPadInst *LPI, Function *CatchFn, Value *Selector,<br>
+                     Value *EHObj)<br>
+      : LPI(LPI), CatchFn(CatchFn),<br>
+        CurrentSelector(Selector->stripPointerCasts()), EHObj(EHObj),<br>
+        SelectorIDType(Type::getInt32Ty(LPI->getContext())),<br>
+        Int8PtrType(Type::getInt8PtrTy(LPI->getContext())) {}<br>
+  virtual ~WinEHCatchDirector() {}<br></blockquote><div><br>Not sure why this didn't get a -Winconsistent-missing-override, but in any case the whole dtor could be omitted, it'll default to the right thing (because the base dtor is already virtual, so far as I can tell).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+  CloningAction handleInstruction(ValueToValueMapTy &VMap,<br>
+                                  const Instruction *Inst,<br>
+                                  BasicBlock *NewBB) override;<br>
+<br>
+private:<br>
+  LandingPadInst *LPI;<br>
+  Function *CatchFn;<br></blockquote><div><br>-Wunused-private-field (I've committed a fix for this, and removed the ctor parameter that was initializing it)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  Value *CurrentSelector;<br>
+  Value *EHObj;<br>
+  Type *SelectorIDType;<br>
+  Type *Int8PtrType;<br>
+<br>
+  const Value *ExtractedEHPtr;<br>
+  const Value *ExtractedSelector;<br>
+  const Value *EHPtrStoreAddr;<br>
+  const Value *SelectorStoreAddr;<br>
+  const Value *EHObjStoreAddr;<br></blockquote><div><br>Also unused and I've committed a fix to remove it.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+};<br>
+} // end anonymous namespace<br>
+<br>
+char WinEHPrepare::ID = 0;<br>
+INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare", "Prepare Windows exceptions",<br>
+                   false, false)<br>
+<br>
+FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {<br>
+  return new WinEHPrepare(TM);<br>
+}<br>
+<br>
+static bool isMSVCPersonality(EHPersonality Pers) {<br>
+  return Pers == EHPersonality::MSVC_Win64SEH ||<br>
+         Pers == EHPersonality::MSVC_CXX;<br>
+}<br>
+<br>
+bool WinEHPrepare::runOnFunction(Function &Fn) {<br>
+  SmallVector<LandingPadInst *, 4> LPads;<br>
+  SmallVector<ResumeInst *, 4> Resumes;<br>
+  for (BasicBlock &BB : Fn) {<br>
+    if (auto *LP = BB.getLandingPadInst())<br>
+      LPads.push_back(LP);<br>
+    if (auto *Resume = dyn_cast<ResumeInst>(BB.getTerminator()))<br>
+      Resumes.push_back(Resume);<br>
+  }<br>
+<br>
+  // No need to prepare functions that lack landing pads.<br>
+  if (LPads.empty())<br>
+    return false;<br>
+<br>
+  // Classify the personality to see what kind of preparation we need.<br>
+  EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());<br>
+<br>
+  // Delegate through to the DWARF pass if this is unrecognized.<br>
+  if (!isMSVCPersonality(Pers))<br>
+    return DwarfPrepare->runOnFunction(Fn);<br>
+<br>
+  // FIXME: This only returns true if the C++ EH handlers were outlined.<br>
+  //        When that code is complete, it should always return whatever<br>
+  //        prepareCPPEHHandlers returns.<br>
+  if (Pers == EHPersonality::MSVC_CXX && prepareCPPEHHandlers(Fn, LPads))<br>
+    return true;<br>
+<br>
+  // FIXME: SEH Cleanups are unimplemented. Replace them with unreachable.<br>
+  if (Resumes.empty())<br>
+    return false;<br>
+<br>
+  for (ResumeInst *Resume : Resumes) {<br>
+    IRBuilder<>(Resume).CreateUnreachable();<br>
+    Resume->eraseFromParent();<br>
+  }<br>
+<br>
+  return true;<br>
+}<br>
+<br>
+bool WinEHPrepare::doFinalization(Module &M) {<br>
+  return DwarfPrepare->doFinalization(M);<br>
+}<br>
+<br>
+void WinEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {<br>
+  DwarfPrepare->getAnalysisUsage(AU);<br>
+}<br>
+<br>
+bool WinEHPrepare::prepareCPPEHHandlers(<br>
+    Function &F, SmallVectorImpl<LandingPadInst *> &LPads) {<br>
+  // FIXME: Find all frame variable references in the handlers<br>
+  //        to populate the structure elements.<br>
+  SmallVector<Type *, 2> AllocStructTys;<br>
+  AllocStructTys.push_back(Type::getInt32Ty(F.getContext()));   // EH state<br>
+  AllocStructTys.push_back(Type::getInt8PtrTy(F.getContext())); // EH object<br>
+  StructType *EHDataStructTy =<br>
+      StructType::create(F.getContext(), AllocStructTys,<br>
+                         "struct." + F.getName().str() + ".ehdata");<br>
+  bool HandlersOutlined = false;<br>
+<br>
+  for (LandingPadInst *LPad : LPads) {<br>
+    // Look for evidence that this landingpad has already been processed.<br>
+    bool LPadHasActionList = false;<br>
+    BasicBlock *LPadBB = LPad->getParent();<br>
+    for (Instruction &Inst : LPadBB->getInstList()) {<br>
+      // FIXME: Make this an intrinsic.<br>
+      if (auto *Call = dyn_cast<CallInst>(&Inst))<br>
+        if (Call->getCalledFunction()->getName() == "llvm.eh.actions") {<br>
+          LPadHasActionList = true;<br>
+          break;<br>
+        }<br>
+    }<br>
+<br>
+    // If we've already outlined the handlers for this landingpad,<br>
+    // there's nothing more to do here.<br>
+    if (LPadHasActionList)<br>
+      continue;<br>
+<br>
+    for (unsigned Idx = 0, NumClauses = LPad->getNumClauses(); Idx < NumClauses;<br>
+         ++Idx) {<br>
+      if (LPad->isCatch(Idx))<br>
+        HandlersOutlined =<br>
+            outlineCatchHandler(&F, LPad->getClause(Idx), LPad, EHDataStructTy);<br>
+    } // End for each clause<br>
+  }   // End for each landingpad<br>
+<br>
+  return HandlersOutlined;<br>
+}<br>
+<br>
+bool WinEHPrepare::outlineCatchHandler(Function *SrcFn, Constant *SelectorType,<br>
+                                       LandingPadInst *LPad,<br>
+                                       StructType *EHDataStructTy) {<br>
+  Module *M = SrcFn->getParent();<br>
+  LLVMContext &Context = M->getContext();<br>
+<br>
+  // Create a new function to receive the handler contents.<br>
+  Type *Int8PtrType = Type::getInt8PtrTy(Context);<br>
+  std::vector<Type *> ArgTys;<br>
+  ArgTys.push_back(Int8PtrType);<br>
+  ArgTys.push_back(Int8PtrType);<br>
+  FunctionType *FnType = FunctionType::get(Int8PtrType, ArgTys, false);<br>
+  Function *CatchHandler = Function::Create(<br>
+      FnType, GlobalVariable::ExternalLinkage, SrcFn->getName() + ".catch", M);<br>
+<br>
+  // Generate a standard prolog to setup the frame recovery structure.<br>
+  IRBuilder<> Builder(Context);<br>
+  BasicBlock *Entry = BasicBlock::Create(Context, "catch.entry");<br>
+  CatchHandler->getBasicBlockList().push_front(Entry);<br>
+  Builder.SetInsertPoint(Entry);<br>
+  Builder.SetCurrentDebugLocation(LPad->getDebugLoc());<br>
+<br>
+  // The outlined handler will be called with the parent's frame pointer as<br>
+  // its second argument. To enable the handler to access variables from<br>
+  // the parent frame, we use that pointer to get locate a special block<br>
+  // of memory that was allocated using llvm.eh.allocateframe for this<br>
+  // purpose.  During the outlining process we will determine which frame<br>
+  // variables are used in handlers and create a structure that maps these<br>
+  // variables into the frame allocation block.<br>
+  //<br>
+  // The frame allocation block also contains an exception state variable<br>
+  // used by the runtime and a pointer to the exception object pointer<br>
+  // which will be filled in by the runtime for use in the handler.<br>
+  Function *RecoverFrameFn =<br>
+      Intrinsic::getDeclaration(M, Intrinsic::framerecover);<br>
+  Value *RecoverArgs[] = {Builder.CreateBitCast(SrcFn, Int8PtrType, ""),<br>
+                          &(CatchHandler->getArgumentList().back())};<br>
+  CallInst *EHAlloc =<br>
+      Builder.CreateCall(RecoverFrameFn, RecoverArgs, "eh.alloc");<br>
+  Value *EHData =<br>
+      Builder.CreateBitCast(EHAlloc, EHDataStructTy->getPointerTo(), "ehdata");<br>
+  Value *EHObjPtr =<br>
+      Builder.CreateConstInBoundsGEP2_32(EHData, 0, 1, "eh.obj.ptr");<br>
+<br>
+  // This will give us a raw pointer to the exception object, which<br>
+  // corresponds to the formal parameter of the catch statement.  If the<br>
+  // handler uses this object, we will generate code during the outlining<br>
+  // process to cast the pointer to the appropriate type and deference it<br>
+  // as necessary.  The un-outlined landing pad code represents the<br>
+  // exception object as the result of the llvm.eh.begincatch call.<br>
+  Value *EHObj = Builder.CreateLoad(EHObjPtr, false, "eh.obj");<br>
+<br>
+  ValueToValueMapTy VMap;<br>
+<br>
+  // FIXME: Map other values referenced in the filter handler.<br>
+<br>
+  WinEHCatchDirector Director(LPad, CatchHandler, SelectorType, EHObj);<br>
+<br>
+  SmallVector<ReturnInst *, 8> Returns;<br>
+  ClonedCodeInfo InlinedFunctionInfo;<br>
+<br>
+  BasicBlock::iterator II = LPad;<br>
+<br>
+  CloneAndPruneIntoFromInst(CatchHandler, SrcFn, ++II, VMap,<br>
+                            /*ModuleLevelChanges=*/false, Returns, "",<br>
+                            &InlinedFunctionInfo,<br>
+                            SrcFn->getParent()->getDataLayout(), &Director);<br>
+<br>
+  // Move all the instructions in the first cloned block into our entry block.<br>
+  BasicBlock *FirstClonedBB = std::next(Function::iterator(Entry));<br>
+  Entry->getInstList().splice(Entry->end(), FirstClonedBB->getInstList());<br>
+  FirstClonedBB->eraseFromParent();<br>
+<br>
+  return true;<br>
+}<br>
+<br>
+CloningDirector::CloningAction WinEHCatchDirector::handleInstruction(<br>
+    ValueToValueMapTy &VMap, const Instruction *Inst, BasicBlock *NewBB) {<br>
+  // Intercept instructions which extract values from the landing pad aggregate.<br>
+  if (auto *Extract = dyn_cast<ExtractValueInst>(Inst)) {<br>
+    if (Extract->getAggregateOperand() == LPI) {<br>
+      assert(Extract->getNumIndices() == 1 &&<br>
+             "Unexpected operation: extracting both landing pad values");<br>
+      assert((*(Extract->idx_begin()) == 0 || *(Extract->idx_begin()) == 1) &&<br>
+             "Unexpected operation: extracting an unknown landing pad element");<br>
+<br>
+      if (*(Extract->idx_begin()) == 0) {<br>
+        // Element 0 doesn't directly corresponds to anything in the WinEH scheme.<br>
+        // It will be stored to a memory location, then later loaded and finally<br>
+        // the loaded value will be used as the argument to an llvm.eh.begincatch<br>
+        // call.  We're tracking it here so that we can skip the store and load.<br>
+        ExtractedEHPtr = Inst;<br>
+      } else {<br>
+        // Element 1 corresponds to the filter selector.  We'll map it to 1 for<br>
+        // matching purposes, but it will also probably be stored to memory and<br>
+        // reloaded, so we need to track the instuction so that we can map the<br>
+        // loaded value too.<br>
+        VMap[Inst] = ConstantInt::get(SelectorIDType, 1);<br>
+        ExtractedSelector = Inst;<br>
+      }<br>
+<br>
+      // Tell the caller not to clone this instruction.<br>
+      return CloningDirector::SkipInstruction;<br>
+    }<br>
+    // Other extract value instructions just get cloned.<br>
+    return CloningDirector::CloneInstruction;<br>
+  }<br>
+<br>
+  if (auto *Store = dyn_cast<StoreInst>(Inst)) {<br>
+    // Look for and suppress stores of the extracted landingpad values.<br>
+    const Value *StoredValue = Store->getValueOperand();<br>
+    if (StoredValue == ExtractedEHPtr) {<br>
+      EHPtrStoreAddr = Store->getPointerOperand();<br>
+      return CloningDirector::SkipInstruction;<br>
+    }<br>
+    if (StoredValue == ExtractedSelector) {<br>
+      SelectorStoreAddr = Store->getPointerOperand();<br>
+      return CloningDirector::SkipInstruction;<br>
+    }<br>
+<br>
+    // Any other store just gets cloned.<br>
+    return CloningDirector::CloneInstruction;<br>
+  }<br>
+<br>
+  if (auto *Load = dyn_cast<LoadInst>(Inst)) {<br>
+    // Look for loads of (previously suppressed) landingpad values.<br>
+    // The EHPtr load can be ignored (it should only be used as<br>
+    // an argument to llvm.eh.begincatch), but the selector value<br>
+    // needs to be mapped to a constant value of 1 to be used to<br>
+    // simplify the branching to always flow to the current handler.<br>
+    const Value *LoadAddr = Load->getPointerOperand();<br>
+    if (LoadAddr == EHPtrStoreAddr) {<br>
+      VMap[Inst] = UndefValue::get(Int8PtrType);<br>
+      return CloningDirector::SkipInstruction;<br>
+    }<br>
+    if (LoadAddr == SelectorStoreAddr) {<br>
+      VMap[Inst] = ConstantInt::get(SelectorIDType, 1);<br>
+      return CloningDirector::SkipInstruction;<br>
+    }<br>
+<br>
+    // Any other loads just get cloned.<br>
+    return CloningDirector::CloneInstruction;<br>
+  }<br>
+<br>
+  if (match(Inst, m_Intrinsic<Intrinsic::eh_begincatch>())) {<br>
+    // The argument to the call is some form of the first element of the<br>
+    // landingpad aggregate value, but that doesn't matter.  It isn't used<br>
+    // here.<br>
+    // The return value of this instruction, however, is used to access the<br>
+    // EH object pointer.  We have generated an instruction to get that value<br>
+    // from the EH alloc block, so we can just map to that here.<br>
+    VMap[Inst] = EHObj;<br>
+    return CloningDirector::SkipInstruction;<br>
+  }<br>
+  if (match(Inst, m_Intrinsic<Intrinsic::eh_endcatch>())) {<br>
+    auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);<br>
+    // It might be interesting to track whether or not we are inside a catch<br>
+    // function, but that might make the algorithm more brittle than it needs<br>
+    // to be.<br>
+<br>
+    // The end catch call can occur in one of two places: either in a<br>
+    // landingpad<br>
+    // block that is part of the catch handlers exception mechanism, or at the<br>
+    // end of the catch block.  If it occurs in a landing pad, we must skip it<br>
+    // and continue so that the landing pad gets cloned.<br>
+    // FIXME: This case isn't fully supported yet and shouldn't turn up in any<br>
+    //        of the test cases until it is.<br>
+    if (IntrinCall->getParent()->isLandingPad())<br>
+      return CloningDirector::SkipInstruction;<br>
+<br>
+    // If an end catch occurs anywhere else the next instruction should be an<br>
+    // unconditional branch instruction that we want to replace with a return<br>
+    // to the the address of the branch target.<br>
+    const BasicBlock *EndCatchBB = IntrinCall->getParent();<br>
+    const TerminatorInst *Terminator = EndCatchBB->getTerminator();<br>
+    const BranchInst *Branch = dyn_cast<BranchInst>(Terminator);<br>
+    assert(Branch && Branch->isUnconditional());<br>
+    assert(std::next(BasicBlock::const_iterator(IntrinCall)) ==<br>
+            BasicBlock::const_iterator(Branch));<br>
+<br>
+    ReturnInst::Create(NewBB->getContext(),<br>
+                        BlockAddress::get(Branch->getSuccessor(0)), NewBB);<br>
+<br>
+    // We just added a terminator to the cloned block.<br>
+    // Tell the caller to stop processing the current basic block so that<br>
+    // the branch instruction will be skipped.<br>
+    return CloningDirector::StopCloningBB;<br>
+  }<br>
+  if (match(Inst, m_Intrinsic<Intrinsic::eh_typeid_for>())) {<br>
+    auto *IntrinCall = dyn_cast<IntrinsicInst>(Inst);<br>
+    Value *Selector = IntrinCall->getArgOperand(0)->stripPointerCasts();<br>
+    // This causes a replacement that will collapse the landing pad CFG based<br>
+    // on the filter function we intend to match.<br>
+    if (Selector == CurrentSelector)<br>
+      VMap[Inst] = ConstantInt::get(SelectorIDType, 1);<br>
+    else<br>
+      VMap[Inst] = ConstantInt::get(SelectorIDType, 0);<br>
+    // Tell the caller not to clone this instruction.<br>
+    return CloningDirector::SkipInstruction;<br>
+  }<br>
+<br>
+  // Continue with the default cloning behavior.<br>
+  return CloningDirector::CloneInstruction;<br>
+}<br>
<br>
Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=229715&r1=229714&r2=229715&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=229715&r1=229714&r2=229715&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Wed Feb 18 12:31:51 2015<br>
@@ -260,21 +260,26 @@ namespace {<br>
     const char *NameSuffix;<br>
     ClonedCodeInfo *CodeInfo;<br>
     const DataLayout *DL;<br>
+    CloningDirector *Director;<br>
+<br>
   public:<br>
     PruningFunctionCloner(Function *newFunc, const Function *oldFunc,<br>
                           ValueToValueMapTy &valueMap,<br>
                           bool moduleLevelChanges,<br>
                           const char *nameSuffix,<br>
                           ClonedCodeInfo *codeInfo,<br>
-                          const DataLayout *DL)<br>
+                          const DataLayout *DL,<br>
+                          CloningDirector *Director)<br>
     : NewFunc(newFunc), OldFunc(oldFunc),<br>
       VMap(valueMap), ModuleLevelChanges(moduleLevelChanges),<br>
-      NameSuffix(nameSuffix), CodeInfo(codeInfo), DL(DL) {<br>
+      NameSuffix(nameSuffix), CodeInfo(codeInfo), DL(DL),<br>
+      Director(Director) {<br>
     }<br>
<br>
     /// CloneBlock - The specified block is found to be reachable, clone it and<br>
     /// anything that it can reach.<br>
-    void CloneBlock(const BasicBlock *BB,<br>
+    void CloneBlock(const BasicBlock *BB,<br>
+                    BasicBlock::const_iterator StartingInst,<br>
                     std::vector<const BasicBlock*> &ToClone);<br>
   };<br>
 }<br>
@@ -282,6 +287,7 @@ namespace {<br>
 /// CloneBlock - The specified block is found to be reachable, clone it and<br>
 /// anything that it can reach.<br>
 void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,<br>
+                                       BasicBlock::const_iterator StartingInst,<br>
                                        std::vector<const BasicBlock*> &ToClone){<br>
   WeakVH &BBEntry = VMap[BB];<br>
<br>
@@ -307,14 +313,31 @@ void PruningFunctionCloner::CloneBlock(c<br>
                                             const_cast<BasicBlock*>(BB));<br>
     VMap[OldBBAddr] = BlockAddress::get(NewFunc, NewBB);<br>
   }<br>
-<br>
<br>
   bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;<br>
-<br>
+<br>
   // Loop over all instructions, and copy them over, DCE'ing as we go.  This<br>
   // loop doesn't include the terminator.<br>
-  for (BasicBlock::const_iterator II = BB->begin(), IE = --BB->end();<br>
+  for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end();<br>
        II != IE; ++II) {<br>
+    // If the "Director" remaps the instruction, don't clone it.<br>
+    if (Director) {<br>
+      CloningDirector::CloningAction Action<br>
+                              = Director->handleInstruction(VMap, II, NewBB);<br>
+      // If the cloning director says stop, we want to stop everything, not<br>
+      // just break out of the loop (which would cause the terminator to be<br>
+      // cloned).  The cloning director is responsible for inserting a proper<br>
+      // terminator into the new basic block in this case.<br>
+      if (Action == CloningDirector::StopCloningBB)<br>
+        return;<br>
+      // If the cloning director says skip, continue to the next instruction.<br>
+      // In this case, the cloning director is responsible for mapping the<br>
+      // skipped instruction to some value that is defined in the new<br>
+      // basic block.<br>
+      if (Action == CloningDirector::SkipInstruction)<br>
+        continue;<br>
+    }<br>
+<br>
     Instruction *NewInst = II->clone();<br>
<br>
     // Eagerly remap operands to the newly cloned instruction, except for PHI<br>
@@ -354,6 +377,18 @@ void PruningFunctionCloner::CloneBlock(c<br>
   // Finally, clone over the terminator.<br>
   const TerminatorInst *OldTI = BB->getTerminator();<br>
   bool TerminatorDone = false;<br>
+  if (Director) {<br>
+    CloningDirector::CloningAction Action<br>
+                           = Director->handleInstruction(VMap, OldTI, NewBB);<br>
+    // If the cloning director says stop, we want to stop everything, not<br>
+    // just break out of the loop (which would cause the terminator to be<br>
+    // cloned).  The cloning director is responsible for inserting a proper<br>
+    // terminator into the new basic block in this case.<br>
+    if (Action == CloningDirector::StopCloningBB)<br>
+      return;<br>
+    assert(Action != CloningDirector::SkipInstruction &&<br>
+           "SkipInstruction is not valid for terminators.");<br>
+  }<br>
   if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {<br>
     if (BI->isConditional()) {<br>
       // If the condition was a known constant in the callee...<br>
@@ -409,39 +444,47 @@ void PruningFunctionCloner::CloneBlock(c<br>
   }<br>
 }<br>
<br>
-/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,<br>
-/// except that it does some simple constant prop and DCE on the fly.  The<br>
-/// effect of this is to copy significantly less code in cases where (for<br>
-/// example) a function call with constant arguments is inlined, and those<br>
-/// constant arguments cause a significant amount of code in the callee to be<br>
-/// dead.  Since this doesn't produce an exact copy of the input, it can't be<br>
-/// used for things like CloneFunction or CloneModule.<br>
-void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,<br>
+/// CloneAndPruneIntoFromInst - This works like CloneAndPruneFunctionInto, except<br>
+/// that it does not clone the entire function. Instead it starts at an<br>
+/// instruction provided by the caller and copies (and prunes) only the code<br>
+/// reachable from that instruction.<br>
+void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,<br>
+                                     const Instruction *StartingInst,<br>
                                      ValueToValueMapTy &VMap,<br>
                                      bool ModuleLevelChanges,<br>
-                                     SmallVectorImpl<ReturnInst*> &Returns,<br>
+                                     SmallVectorImpl<ReturnInst *> &Returns,<br>
                                      const char *NameSuffix,<br>
                                      ClonedCodeInfo *CodeInfo,<br>
                                      const DataLayout *DL,<br>
-                                     Instruction *TheCall) {<br>
+                                     CloningDirector *Director) {<br>
   assert(NameSuffix && "NameSuffix cannot be null!");<br>
-<br>
+<br>
 #ifndef NDEBUG<br>
-  for (Function::const_arg_iterator II = OldFunc->arg_begin(),<br>
-       E = OldFunc->arg_end(); II != E; ++II)<br>
-    assert(VMap.count(II) && "No mapping from source argument specified!");<br>
+  // If the cloning starts at the begining of the function, verify that<br>
+  // the function arguments are mapped.<br>
+  if (!StartingInst)<br>
+    for (Function::const_arg_iterator II = OldFunc->arg_begin(),<br>
+         E = OldFunc->arg_end(); II != E; ++II)<br>
+      assert(VMap.count(II) && "No mapping from source argument specified!");<br>
 #endif<br>
<br>
   PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,<br>
-                            NameSuffix, CodeInfo, DL);<br>
+                            NameSuffix, CodeInfo, DL, Director);<br>
+  const BasicBlock *StartingBB;<br>
+  if (StartingInst)<br>
+    StartingBB = StartingInst->getParent();<br>
+  else {<br>
+    StartingBB = &OldFunc->getEntryBlock();<br>
+    StartingInst = StartingBB->begin();<br>
+  }<br>
<br>
   // Clone the entry block, and anything recursively reachable from it.<br>
   std::vector<const BasicBlock*> CloneWorklist;<br>
-  CloneWorklist.push_back(&OldFunc->getEntryBlock());<br>
+  PFC.CloneBlock(StartingBB, StartingInst, CloneWorklist);<br>
   while (!CloneWorklist.empty()) {<br>
     const BasicBlock *BB = CloneWorklist.back();<br>
     CloneWorklist.pop_back();<br>
-    PFC.CloneBlock(BB, CloneWorklist);<br>
+    PFC.CloneBlock(BB, BB->begin(), CloneWorklist);<br>
   }<br>
<br>
   // Loop over all of the basic blocks in the old function.  If the block was<br>
@@ -569,7 +612,7 @@ void llvm::CloneAndPruneFunctionInto(Fun<br>
   // and zap unconditional fall-through branches.  This happen all the time when<br>
   // specializing code: code specialization turns conditional branches into<br>
   // uncond branches, and this code folds them.<br>
-  Function::iterator Begin = cast<BasicBlock>(VMap[&OldFunc->getEntryBlock()]);<br>
+  Function::iterator Begin = cast<BasicBlock>(VMap[StartingBB]);<br>
   Function::iterator I = Begin;<br>
   while (I != NewFunc->end()) {<br>
     // Check if this block has become dead during inlining or other<br>
@@ -620,9 +663,30 @@ void llvm::CloneAndPruneFunctionInto(Fun<br>
   // Make a final pass over the basic blocks from theh old function to gather<br>
   // any return instructions which survived folding. We have to do this here<br>
   // because we can iteratively remove and merge returns above.<br>
-  for (Function::iterator I = cast<BasicBlock>(VMap[&OldFunc->getEntryBlock()]),<br>
+  for (Function::iterator I = cast<BasicBlock>(VMap[StartingBB]),<br>
                           E = NewFunc->end();<br>
        I != E; ++I)<br>
     if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator()))<br>
       Returns.push_back(RI);<br>
 }<br>
+<br>
+<br>
+/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,<br>
+/// except that it does some simple constant prop and DCE on the fly.  The<br>
+/// effect of this is to copy significantly less code in cases where (for<br>
+/// example) a function call with constant arguments is inlined, and those<br>
+/// constant arguments cause a significant amount of code in the callee to be<br>
+/// dead.  Since this doesn't produce an exact copy of the input, it can't be<br>
+/// used for things like CloneFunction or CloneModule.<br>
+void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,<br>
+                                     ValueToValueMapTy &VMap,<br>
+                                     bool ModuleLevelChanges,<br>
+                                     SmallVectorImpl<ReturnInst*> &Returns,<br>
+                                     const char *NameSuffix,<br>
+                                     ClonedCodeInfo *CodeInfo,<br>
+                                     const DataLayout *DL,<br>
+                                     Instruction *TheCall) {<br>
+  CloneAndPruneIntoFromInst(NewFunc, OldFunc, OldFunc->front().begin(),<br>
+                            VMap, ModuleLevelChanges, Returns, NameSuffix,<br>
+                            CodeInfo, DL, nullptr);<br>
+}<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll?rev=229715&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll?rev=229715&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/cppeh-catch-all.ll Wed Feb 18 12:31:51 2015<br>
@@ -0,0 +1,83 @@<br>
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s<br>
+<br>
+; This test is based on the following code:<br>
+;<br>
+; void test()<br>
+; {<br>
+;   try {<br>
+;     may_throw();<br>
+;   } catch (...) {<br>
+;     handle_exception();<br>
+;   }<br>
+; }<br>
+;<br>
+; Parts of the IR have been hand-edited to simplify the test case.<br>
+; The full IR will be restored when Windows C++ EH support is complete.<br>
+<br>
+; ModuleID = 'catch-all.cpp'<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc"<br>
+<br>
+; Function Attrs: uwtable<br>
+define void @_Z4testv() #0 {<br>
+entry:<br>
+  %exn.slot = alloca i8*<br>
+  %ehselector.slot = alloca i32<br>
+  invoke void @_Z9may_throwv()<br>
+          to label %invoke.cont unwind label %lpad<br>
+<br>
+invoke.cont:                                      ; preds = %entry<br>
+  br label %try.cont<br>
+<br>
+lpad:                                             ; preds = %entry<br>
+  %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)<br>
+          catch i8* null<br>
+  %1 = extractvalue { i8*, i32 } %0, 0<br>
+  store i8* %1, i8** %exn.slot<br>
+  %2 = extractvalue { i8*, i32 } %0, 1<br>
+  store i32 %2, i32* %ehselector.slot<br>
+  br label %catch<br>
+<br>
+catch:                                            ; preds = %lpad<br>
+  %exn = load i8** %exn.slot<br>
+  %3 = call i8* @llvm.eh.begincatch(i8* %exn) #3<br>
+  call void @_Z16handle_exceptionv()<br>
+  br label %invoke.cont2<br>
+<br>
+invoke.cont2:                                     ; preds = %catch<br>
+  call void @llvm.eh.endcatch()<br>
+  br label %try.cont<br>
+<br>
+try.cont:                                         ; preds = %invoke.cont2, %invoke.cont<br>
+  ret void<br>
+}<br>
+<br>
+; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {<br>
+; CHECK: catch.entry:<br>
+; CHECK:   %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)<br>
+; CHECK:   %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*<br>
+; CHECK:   %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1<br>
+; CHECK:   %eh.obj = load i8** %eh.obj.ptr<br>
+; CHECK:   call void @_Z16handle_exceptionv()<br>
+; CHECK:   ret i8* blockaddress(@_Z4testv, %try.cont)<br>
+; CHECK: }<br>
+<br>
+declare void @_Z9may_throwv() #1<br>
+<br>
+declare i32 @__CxxFrameHandler3(...)<br>
+<br>
+declare i8* @llvm.eh.begincatch(i8*)<br>
+<br>
+declare void @_Z16handle_exceptionv() #1<br>
+<br>
+declare void @llvm.eh.endcatch()<br>
+<br>
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #2 = { noinline noreturn nounwind }<br>
+attributes #3 = { nounwind }<br>
+attributes #4 = { noreturn nounwind }<br>
+<br>
+!llvm.ident = !{!0}<br>
+<br>
+!0 = !{!"clang version 3.7.0 (trunk 226027)"}<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll?rev=229715&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll?rev=229715&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/cppeh-catch-scalar.ll Wed Feb 18 12:31:51 2015<br>
@@ -0,0 +1,102 @@<br>
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s<br>
+<br>
+; This test is based on the following code:<br>
+;<br>
+; void test()<br>
+; {<br>
+;   try {<br>
+;     may_throw();<br>
+;   } catch (int) {<br>
+;     handle_int();<br>
+;   }<br>
+; }<br>
+;<br>
+; Parts of the IR have been hand-edited to simplify the test case.<br>
+; The full IR will be restored when Windows C++ EH support is complete.<br>
+<br>
+;ModuleID = 'cppeh-catch-scalar.cpp'<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc"<br>
+<br>
+@_ZTIi = external constant i8*<br>
+<br>
+; Function Attrs: uwtable<br>
+define void @_Z4testv() #0 {<br>
+entry:<br>
+  %exn.slot = alloca i8*<br>
+  %ehselector.slot = alloca i32<br>
+  invoke void @_Z9may_throwv()<br>
+          to label %invoke.cont unwind label %lpad<br>
+<br>
+invoke.cont:                                      ; preds = %entry<br>
+  br label %try.cont<br>
+<br>
+lpad:                                             ; preds = %entry<br>
+  %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)<br>
+          catch i8* bitcast (i8** @_ZTIi to i8*)<br>
+  %1 = extractvalue { i8*, i32 } %0, 0<br>
+  store i8* %1, i8** %exn.slot<br>
+  %2 = extractvalue { i8*, i32 } %0, 1<br>
+  store i32 %2, i32* %ehselector.slot<br>
+  br label %catch.dispatch<br>
+<br>
+catch.dispatch:                                   ; preds = %lpad<br>
+  %sel = load i32* %ehselector.slot<br>
+  %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3<br>
+  %matches = icmp eq i32 %sel, %3<br>
+  br i1 %matches, label %catch, label %eh.resume<br>
+<br>
+catch:                                            ; preds = %catch.dispatch<br>
+  %exn11 = load i8** %exn.slot<br>
+  %4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3<br>
+  %5 = bitcast i8* %4 to i32*<br>
+  call void @_Z10handle_intv()<br>
+  br label %invoke.cont2<br>
+<br>
+invoke.cont2:                                     ; preds = %catch<br>
+  call void @llvm.eh.endcatch() #3<br>
+  br label %try.cont<br>
+<br>
+try.cont:                                         ; preds = %invoke.cont2, %invoke.cont<br>
+  ret void<br>
+<br>
+eh.resume:                                        ; preds = %catch.dispatch<br>
+  %exn3 = load i8** %exn.slot<br>
+  %sel4 = load i32* %ehselector.slot<br>
+  %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0<br>
+  %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1<br>
+  resume { i8*, i32 } %lpad.val5<br>
+}<br>
+<br>
+; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {<br>
+; CHECK: catch.entry:<br>
+; CHECK:   %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)<br>
+; CHECK:   %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*<br>
+; CHECK:   %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1<br>
+; CHECK:   %eh.obj = load i8** %eh.obj.ptr<br>
+; CHECK:   %2 = bitcast i8* %eh.obj to i32*<br>
+; CHECK:   call void @_Z10handle_intv()<br>
+; CHECK:   ret i8* blockaddress(@_Z4testv, %try.cont)<br>
+; CHECK: }<br>
+<br>
+declare void @_Z9may_throwv() #1<br>
+<br>
+declare i32 @__CxxFrameHandler3(...)<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare i32 @llvm.eh.typeid.for(i8*) #2<br>
+<br>
+declare i8* @llvm.eh.begincatch(i8*)<br>
+<br>
+declare void @llvm.eh.endcatch()<br>
+<br>
+declare void @_Z10handle_intv() #1<br>
+<br>
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #2 = { nounwind readnone }<br>
+attributes #3 = { nounwind }<br>
+<br>
+!llvm.ident = !{!0}<br>
+<br>
+!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>