[llvm-commits] [llvm] r142221 - in /llvm/trunk: include/llvm/Function.h lib/Analysis/InlineCost.cpp lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/Transforms/Scalar/TailRecursionElimination.cpp lib/VMCore/Function.cpp test/Transforms/TailCallElim/setjmp.ll

Bill Wendling isanbard at gmail.com
Mon Oct 17 11:43:41 PDT 2011


Author: void
Date: Mon Oct 17 13:43:40 2011
New Revision: 142221

URL: http://llvm.org/viewvc/llvm-project?rev=142221&view=rev
Log:
Correct over-zealous removal of hack.

Some code want to check that *any* call within a function has the 'returns
twice' attribute, not just that the current function has one.

Modified:
    llvm/trunk/include/llvm/Function.h
    llvm/trunk/lib/Analysis/InlineCost.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
    llvm/trunk/lib/VMCore/Function.cpp
    llvm/trunk/test/Transforms/TailCallElim/setjmp.ll

Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Mon Oct 17 13:43:40 2011
@@ -425,6 +425,10 @@
   ///
   bool hasAddressTaken(const User** = 0) const;
 
+  /// callsFunctionThatReturnsTwice - Return true if the function has a call to
+  /// setjmp or other function that gcc recognizes as "returning twice".
+  bool callsFunctionThatReturnsTwice() const;
+
 private:
   // Shadow Value::setValueSubclassData with a private forwarding method so that
   // subclasses cannot accidentally use it.

Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Mon Oct 17 13:43:40 2011
@@ -229,7 +229,7 @@
   // _setjmp), never inline it. This is a hack because we depend on the user
   // marking their local variables as volatile if they are live across a setjmp
   // call, and they probably won't do this in callers.
-  callsSetJmp = F->hasFnAttr(Attribute::ReturnsTwice);
+  callsSetJmp = F->callsFunctionThatReturnsTwice();
 
   // Look at the size of the callee.
   for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Mon Oct 17 13:43:40 2011
@@ -374,7 +374,7 @@
   }
 
   // Determine if there is a call to setjmp in the machine function.
-  MF->setCallsSetJmp(Fn.hasFnAttr(Attribute::ReturnsTwice));
+  MF->setCallsSetJmp(Fn.callsFunctionThatReturnsTwice());
 
   // Replace forward-declared registers with the registers containing
   // the desired value.

Modified: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Mon Oct 17 13:43:40 2011
@@ -213,7 +213,7 @@
   // Finally, if this function contains no non-escaping allocas, or calls
   // setjmp, mark all calls in the function as eligible for tail calls
   //(there is no stack memory for them to access).
-  if (!FunctionContainsEscapingAllocas && !F.hasFnAttr(Attribute::ReturnsTwice))
+  if (!FunctionContainsEscapingAllocas && !F.callsFunctionThatReturnsTwice())
     for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
         if (CallInst *CI = dyn_cast<CallInst>(I)) {

Modified: llvm/trunk/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Function.cpp (original)
+++ llvm/trunk/lib/VMCore/Function.cpp Mon Oct 17 13:43:40 2011
@@ -411,4 +411,19 @@
   return false;
 }
 
+/// callsFunctionThatReturnsTwice - Return true if the function has a call to
+/// setjmp or other function that gcc recognizes as "returning twice".
+bool Function::callsFunctionThatReturnsTwice() const {
+  for (const_inst_iterator
+         I = inst_begin(this), E = inst_end(this); I != E; ++I) {
+    const CallInst* callInst = dyn_cast<CallInst>(&*I);
+    if (!callInst)
+      continue;
+    if (callInst->canReturnTwice())
+      return true;
+  }
+
+  return false;
+}
+
 // vim: sw=2 ai

Modified: llvm/trunk/test/Transforms/TailCallElim/setjmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/setjmp.ll?rev=142221&r1=142220&r2=142221&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/TailCallElim/setjmp.ll (original)
+++ llvm/trunk/test/Transforms/TailCallElim/setjmp.ll Mon Oct 17 13:43:40 2011
@@ -1,5 +1,4 @@
 ; RUN: opt < %s -tailcallelim -S | FileCheck %s
-; XFAIL: *
 
 ; Test that we don't tail call in a functions that calls returns_twice
 ; functions.





More information about the llvm-commits mailing list