Correct over-zealous removal of hack.
authorBill Wendling <isanbard@gmail.com>
Mon, 17 Oct 2011 18:43:40 +0000 (18:43 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 17 Oct 2011 18:43:40 +0000 (18:43 +0000)
Some code want to check that *any* call within a function has the 'returns
twice' attribute, not just that the current function has one.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142221 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4386249f5f2d33e39e2946cdd961125d18838db0..678651bbf1f8d75a3eb7292f82d429097a265d3d 100644 (file)
@@ -425,6 +425,10 @@ public:
   ///
   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.
index 65db33cdc4d1c90c2aa5119cd79c6206404cf3f1..40ac9a211af23178a03902b01766ec6a88416407 100644 (file)
@@ -229,7 +229,7 @@ void CodeMetrics::analyzeFunction(Function *F, const TargetData *TD) {
   // _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)
index 2db91ea40b634cfbe2d6cb778ef87646a0fdca11..68b9146adfe1ad96d41f8d34ef4905dd41ae4957 100644 (file)
@@ -374,7 +374,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
   }
 
   // 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.
index 1022485a948560f10240b612705572fa13d68c71..e21eb9dca270097ab13fdcfecb20a671940d1cfe 100644 (file)
@@ -213,7 +213,7 @@ bool TailCallElim::runOnFunction(Function &F) {
   // 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)) {
index 975ec83b4df8d07ce2f9f087369207c9456c0f6a..a6128b0cad734077bd319615237638d29dfc25b4 100644 (file)
@@ -411,4 +411,19 @@ bool Function::hasAddressTaken(const User* *PutOffender) const {
   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
index ae06927a3d8a49f91143ce0d323ca403af54b1ef..4ce6ac7965e9995dd53be9fd439d016973f5ef83 100644 (file)
@@ -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.