[PATCH] D63046: [Attributor] Deduce "willreturn" function attribute

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 9 20:12:09 PDT 2019


nicholas added a comment.

> The current algorithm can deduce only for very simple cases.
> 
> - A function doesn't have any loop.
> - A function doesn't have any recursion.

What about functions that exit the program, throw an exception, or longjmp?



================
Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:1109
+
+// Helper function that checks whether a function has any loop.
+bool containsLoop(Function &F) {
----------------
Loop is commonly assumed to mean "natural loop", where there is one block (the header) which dominates the other blocks in the loop (the loop body). What you're looking for here is a more general thing called a cycle (equivalent to looking for a backedge). That also explains why you need your own function and can't reuse LoopInfo.


================
Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:1115-1120
+    Visited.insert(BB);
+    for (auto *SuccBB : successors(BB)) {
+      if (Visited.count(SuccBB))
+        return true;
+    }
+  }
----------------
FYI, with effort, this could be pushed to be more efficient. df_iterator maintains its own copy of Visited, and it does its own scan over the successors of the block, neither of which need to be done twice. Unfortunately the fix is not entirely simple.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63046/new/

https://reviews.llvm.org/D63046





More information about the llvm-commits mailing list