<div class="gmail_quote">On 17 January 2011 16:09, Stuart Hastings <span dir="ltr"><<a href="mailto:stuart@apple.com">stuart@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Author: stuart<br>
Date: Mon Jan 17 18:09:27 2011<br>
New Revision: 123704<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=123704&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=123704&view=rev</a><br>
Log:<br>
Remove checking that prevented overlapping CALLSEQ_START/CALLSEQ_END<br>
ranges, add legalizer support for nested calls.  Necessary for ARM<br>
byval support.  Radar 7662569.<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=123704&r1=123703&r2=123704&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=123704&r1=123703&r2=123704&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Mon Jan 17 18:09:27 2011<br>
@@ -66,11 +66,6 @@<br>
   /// against each other, including inserted libcalls.<br>
   SDValue LastCALLSEQ_END;<br>
<br>
-  /// IsLegalizingCall - This member is used *only* for purposes of providing<br>
-  /// helpful assertions that a libcall isn't created while another call is<br>
-  /// being legalized (which could lead to non-serialized call sequences).<br>
-  bool IsLegalizingCall;<br>
-<br>
   enum LegalizeAction {<br>
     Legal,      // The target natively supports this operation.<br>
     Promote,    // This operation should be executed in a larger type.<br>
@@ -225,7 +220,6 @@<br>
<br>
 void SelectionDAGLegalize::LegalizeDAG() {<br>
   LastCALLSEQ_END = DAG.getEntryNode();<br>
-  IsLegalizingCall = false;<br>
<br>
   // The legalize process is inherently a bottom-up recursive process (users<br>
   // legalize their uses before themselves).  Given infinite stack space, we<br>
@@ -1024,6 +1018,7 @@<br>
     }<br>
     break;<br>
   case ISD::CALLSEQ_START: {<br>
+    static int depth = 0;<br></blockquote><div><br></div><div>Hi Stuart, this breaks using llvm from multiple threads. Please don't use non-constant statics.</div><div><br></div><div>Nick</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


     SDNode *CallEnd = FindCallEndFromCallStart(Node);<br>
<br>
     // Recursively Legalize all of the inputs of the call end that do not lead<br>
@@ -1041,7 +1036,7 @@<br>
<br>
     // Merge in the last call to ensure that this call starts after the last<br>
     // call ended.<br>
-    if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) {<br>
+    if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken && depth == 0) {<br>
       Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,<br>
                          Tmp1, LastCALLSEQ_END);<br>
       Tmp1 = LegalizeOp(Tmp1);<br>
@@ -1064,14 +1059,18 @@<br>
     // sequence have been legalized, legalize the call itself.  During this<br>
     // process, no libcalls can/will be inserted, guaranteeing that no calls<br>
     // can overlap.<br>
-    assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!");<br>
+<br>
+    SDValue Saved_LastCALLSEQ_END = LastCALLSEQ_END ;<br>
     // Note that we are selecting this call!<br>
     LastCALLSEQ_END = SDValue(CallEnd, 0);<br>
-    IsLegalizingCall = true;<br>
<br>
+    depth++;<br>
     // Legalize the call, starting from the CALLSEQ_END.<br>
     LegalizeOp(LastCALLSEQ_END);<br>
-    assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!");<br>
+    depth--;<br>
+    assert(depth >= 0 && "Un-matched CALLSEQ_START?");<br>
+    if (depth > 0)<br>
+      LastCALLSEQ_END = Saved_LastCALLSEQ_END;<br>
     return Result;<br>
   }<br>
   case ISD::CALLSEQ_END:<br>
@@ -1110,10 +1109,7 @@<br>
                          Result.getResNo());<br>
       }<br>
     }<br>
-    assert(IsLegalizingCall && "Call sequence imbalance between start/end?");<br>
     // This finishes up call legalization.<br>
-    IsLegalizingCall = false;<br>
-<br>
     // If the CALLSEQ_END node has a flag, remember that we legalized it.<br>
     AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));<br>
     if (Node->getNumValues() == 2)<br>
@@ -1949,7 +1945,6 @@<br>
 // and leave the Hi part unset.<br>
 SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node,<br>
                                             bool isSigned) {<br>
-  assert(!IsLegalizingCall && "Cannot overlap legalization of calls!");<br>
   // The input chain to this libcall is the entry node of the function.<br>
   // Legalizing the call will automatically add the previous call to the<br>
   // dependence.<br>
@@ -1997,7 +1992,6 @@<br>
 SelectionDAGLegalize::ExpandChainLibCall(RTLIB::Libcall LC,<br>
                                          SDNode *Node,<br>
                                          bool isSigned) {<br>
-  assert(!IsLegalizingCall && "Cannot overlap legalization of calls!");<br>
   SDValue InChain = Node->getOperand(0);<br>
<br>
   TargetLowering::ArgListTy Args;<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>