<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 27, 2015 at 9:52 AM, Kaylor, Andrew <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">This doesn't look the way I would have expected it to.<br>
<br>
Why are you creating an alloca for the parent frame pointer?  I would have expected the intrinisic to return a pointer to the stack offset where the parent frame pointer needs to be stored and the catch handler to store it directly there.<br></blockquote><div><br></div><div>The parent frame pointer needs to be stored to the catch handlers stack at an offset known to the compiler.  It seems quite natural to represent this as an alloca whose address is escaped to a builtin.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-Andy<br>
<div><div class="h5"><br>
-----Original Message-----<br>
From: <a href="mailto:llvm-commits-bounces@cs.uiuc.edu">llvm-commits-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvm-commits-bounces@cs.uiuc.edu">llvm-commits-bounces@cs.uiuc.edu</a>] On Behalf Of David Majnemer<br>
Sent: Thursday, March 26, 2015 9:17 PM<br>
To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
Subject: [llvm] r233354 - WinEH: Create a parent frame alloca for HandlerType xdata tables<br>
<br>
Author: majnemer<br>
Date: Thu Mar 26 23:17:07 2015<br>
New Revision: 233354<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=233354&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=233354&view=rev</a><br>
Log:<br>
WinEH: Create a parent frame alloca for HandlerType xdata tables<br>
<br>
We don't have any logic to emit those tables yet, so the SDAG lowering of this intrinsic is just a stub.  We can see the intrinsic in the prepared IR, though.<br>
<br>
Modified:<br>
    llvm/trunk/docs/ExceptionHandling.rst<br>
    llvm/trunk/include/llvm/IR/Intrinsics.td<br>
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
    llvm/trunk/lib/CodeGen/WinEHPrepare.cpp<br>
    llvm/trunk/lib/IR/Verifier.cpp<br>
    llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll<br>
<br>
Modified: llvm/trunk/docs/ExceptionHandling.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ExceptionHandling.rst?rev=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ExceptionHandling.rst?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/docs/ExceptionHandling.rst (original)<br>
+++ llvm/trunk/docs/ExceptionHandling.rst Thu Mar 26 23:17:07 2015<br>
@@ -551,6 +551,17 @@ This object is used by Windows native ex  where xdata unwind information is used. It is typically an 8 byte chunk of  memory treated as two 32-bit integers.<br>
<br>
+``llvm.eh.parentframe``<br>
+----------------------<br>
+<br>
+.. code-block:: llvm<br>
+<br>
+  void @llvm.eh.parentframe(i8*)<br>
+<br>
+This intrinsic designates the provided static alloca as the object<br>
</div></div>+which holds the address of the parent frame.<br>
<span class="">+This object is used by Windows native exception handling on non-x86<br>
</span>+platforms where xdata unwind information is used.<br>
<span class=""><br>
 SJLJ Intrinsics<br>
 ---------------<br>
<br>
Modified: llvm/trunk/include/llvm/IR/Intrinsics.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.td?rev=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.td?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/Intrinsics.td (original)<br>
+++ llvm/trunk/include/llvm/IR/Intrinsics.td Thu Mar 26 23:17:07 2015<br>
@@ -425,6 +425,10 @@ def int_eh_actions : Intrinsic<[llvm_ptr  // for WinEH.<br>
 def int_eh_unwindhelp : Intrinsic<[], [llvm_ptr_ty], []>;<br>
<br>
+// Designates the provided static alloca as the object which holds the<br>
</span>+address // of the parent frame. Required for WinEH.<br>
<span class="">+def int_eh_parentframe : Intrinsic<[], [llvm_ptrptr_ty], []>;<br>
+<br>
 // __builtin_unwind_init is an undocumented GCC intrinsic that causes all  // callee-saved registers to be saved and restored (regardless of whether they  // are used) in the calling function. It is used by libgcc_eh.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Thu Mar<br>
</span>+++ 26 23:17:07 2015<br>
<div><div class="h5">@@ -5446,13 +5446,23 @@ SelectionDAGBuilder::visitIntrinsicCall(<br>
   case Intrinsic::eh_begincatch:<br>
   case Intrinsic::eh_endcatch:<br>
     llvm_unreachable("begin/end catch intrinsics not lowered in codegen");<br>
+  case Intrinsic::eh_parentframe: {<br>
+    AllocaInst *Slot =<br>
+        cast<AllocaInst>(I.getArgOperand(0)->stripPointerCasts());<br>
+    assert(FuncInfo.StaticAllocaMap.count(Slot) &&<br>
+           "can only use static allocas with llvm.eh.parentframe");<br>
+    int FI = FuncInfo.StaticAllocaMap[Slot];<br>
+    // TODO: Save this in the not-yet-existent WinEHFuncInfo struct.<br>
+    (void)FI;<br>
+    return nullptr;<br>
+  }<br>
   case Intrinsic::eh_unwindhelp: {<br>
     AllocaInst *Slot =<br>
         cast<AllocaInst>(I.getArgOperand(0)->stripPointerCasts());<br>
     assert(FuncInfo.StaticAllocaMap.count(Slot) &&<br>
            "can only use static allocas with llvm.eh.unwindhelp");<br>
     int FI = FuncInfo.StaticAllocaMap[Slot];<br>
-    // TODO: Save this in the not-yet-existant WinEHFuncInfo struct.<br>
+    // TODO: Save this in the not-yet-existent WinEHFuncInfo struct.<br>
     (void)FI;<br>
     return nullptr;<br>
   }<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=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Thu Mar 26 23:17:07 2015<br>
@@ -695,6 +695,16 @@ bool WinEHPrepare::outlineHandler(Action<br>
   if (!LPadMap.isInitialized())<br>
     LPadMap.mapLandingPad(LPad);<br>
   if (auto *CatchAction = dyn_cast<CatchHandler>(Action)) {<br>
+    // Insert an alloca for the object which holds the address of the parent's<br>
+    // frame pointer.  The stack offset of this object needs to be encoded in<br>
+    // xdata.<br>
+    AllocaInst *ParentFrame = new AllocaInst(Int8PtrType, "parentframe", Entry);<br>
+    Builder.CreateStore(&Handler->getArgumentList().back(), ParentFrame,<br>
+                        /*isStore=*/true);<br>
+    Function *ParentFrameFn =<br>
+        Intrinsic::getDeclaration(M, Intrinsic::eh_parentframe);<br>
+    Builder.CreateCall(ParentFrameFn, ParentFrame);<br>
+<br>
     Constant *Sel = CatchAction->getSelector();<br>
     Director.reset(new WinEHCatchDirector(Handler, Sel, VarInfo, LPadMap));<br>
     LPadMap.remapSelector(VMap, ConstantInt::get(Type::getInt32Ty(Context), 1));<br>
<br>
Modified: llvm/trunk/lib/IR/Verifier.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/Verifier.cpp (original)<br>
+++ llvm/trunk/lib/IR/Verifier.cpp Thu Mar 26 23:17:07 2015<br>
@@ -2909,6 +2909,13 @@ void Verifier::visitIntrinsicFunctionCal<br>
     break;<br>
   }<br>
<br>
+  case Intrinsic::eh_parentframe: {<br>
+    auto *AI = dyn_cast<AllocaInst>(CI.getArgOperand(0)->stripPointerCasts());<br>
+    Assert(AI && AI->isStaticAlloca(),<br>
+           "llvm.eh.parentframe requires a static alloca", &CI);<br>
+    break;<br>
+  }<br>
+<br>
   case Intrinsic::eh_unwindhelp: {<br>
     auto *AI = dyn_cast<AllocaInst>(CI.getArgOperand(0)->stripPointerCasts());<br>
     Assert(AI && AI->isStaticAlloca(),<br>
<br>
Modified: llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll?rev=233354&r1=233353&r2=233354&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll?rev=233354&r1=233353&r2=233354&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll (original)<br>
+++ llvm/trunk/test/CodeGen/WinEH/cppeh-catch-unwind.ll Thu Mar 26<br>
</div></div>+++ 23:17:07 2015<br>
<div class="HOEnZb"><div class="h5">@@ -180,6 +180,9 @@ eh.resume:<br>
<br>
 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {  ; CHECK: entry:<br>
+; CHECK:   [[PARENTFRAME:\%.+]] = alloca i8*<br>
+; CHECK:   store volatile i8* %1, i8** [[PARENTFRAME]]<br>
+; CHECK:   call void @llvm.eh.parentframe(i8** [[PARENTFRAME]])<br>
 ; CHECK:   [[RECOVER_TMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)<br>
 ; CHECK:   [[TMP1_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP1]] to i32*<br>
 ; CHECK:   call void @"\01?handle_exception@@YAXXZ"()<br>
@@ -196,6 +199,9 @@ eh.resume:<br>
<br>
 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) {  ; CHECK: entry:<br>
+; CHECK:   [[PARENTFRAME:\%.+]] = alloca i8*<br>
+; CHECK:   store volatile i8* %1, i8** [[PARENTFRAME]]<br>
+; CHECK:   call void @llvm.eh.parentframe(i8** [[PARENTFRAME]])<br>
 ; CHECK:   [[RECOVER_TMP0:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)<br>
 ; CHECK:   [[TMP0_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP0]] to i32*<br>
 ; CHECK:   invoke void @"\01?handle_exception@@YAXXZ"()<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>
</div></div></blockquote></div><br></div></div>