<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In all the cases I’ve seen with other compilers, the parent frame pointer is stored at a location above the stack pointer of the catch handler.  I think the
 address of this location needs to be calculated.  I don’t think the location needs to be provided by the handler.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I could be wrong, of course.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">-Andy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> David Majnemer [mailto:david.majnemer@gmail.com]
<br>
<b>Sent:</b> Friday, March 27, 2015 10:05 AM<br>
<b>To:</b> Kaylor, Andrew<br>
<b>Cc:</b> llvm-commits@cs.uiuc.edu<br>
<b>Subject:</b> Re: [llvm] r233354 - WinEH: Create a parent frame alloca for HandlerType xdata tables<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Fri, Mar 27, 2015 at 9:52 AM, Kaylor, Andrew <<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><br>
-Andy<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><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<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">+which holds the address of the parent frame.<br>
+This object is used by Windows native exception handling on non-x86<br>
+platforms where xdata unwind information is used.<br>
<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>
+address // of the parent frame. Required for WinEH.<br>
+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>
+++ 26 23:17:07 2015<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">@@ -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<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">+++ 23:17:07 2015<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">@@ -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><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>