OSDN Git Service

[TRE] Simplify canTRE() a bit using all_of(). NFCI.
authorDavide Italiano <davide@freebsd.org>
Tue, 18 Jul 2017 15:42:59 +0000 (15:42 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 18 Jul 2017 15:42:59 +0000 (15:42 +0000)
This has a ~11 years old FIXME, which may not be true today.
We might consider removing this code altogether.

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

lib/Transforms/Scalar/TailRecursionElimination.cpp

index 9397b87..90c5c24 100644 (file)
@@ -68,6 +68,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
@@ -90,16 +91,10 @@ STATISTIC(NumAccumAdded, "Number of accumulators introduced");
 /// If it contains any dynamic allocas, returns false.
 static bool canTRE(Function &F) {
   // Because of PR962, we don't TRE dynamic allocas.
-  for (auto &BB : F) {
-    for (auto &I : BB) {
-      if (AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
-        if (!AI->isStaticAlloca())
-          return false;
-      }
-    }
-  }
-
-  return true;
+  return llvm::all_of(instructions(F), [](Instruction &I) {
+    auto *AI = dyn_cast<AllocaInst>(&I);
+    return !AI || AI->isStaticAlloca();
+  });
 }
 
 namespace {