From 5bd39d6f6ed416d31600d474d453f7c801e45cad Mon Sep 17 00:00:00 2001 From: Chen Zheng Date: Wed, 26 Jun 2019 09:12:52 +0000 Subject: [PATCH] [HardwareLoops] NFC - move loop with irreducible control flow checking logic to isHardwareLoopProfitable() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364397 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/TargetTransformInfo.h | 3 ++- lib/Analysis/TargetTransformInfo.cpp | 10 +++++++++- lib/CodeGen/HardwareLoops.cpp | 10 +--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/llvm/Analysis/TargetTransformInfo.h b/include/llvm/Analysis/TargetTransformInfo.h index 48ef2170fb8..c5dbd956bea 100644 --- a/include/llvm/Analysis/TargetTransformInfo.h +++ b/include/llvm/Analysis/TargetTransformInfo.h @@ -473,7 +473,8 @@ public: /// Query the target whether it would be profitable to convert the given loop /// into a hardware loop. - bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, + bool isHardwareLoopProfitable(Loop *L, LoopInfo &LI, + ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const; diff --git a/lib/Analysis/TargetTransformInfo.cpp b/lib/Analysis/TargetTransformInfo.cpp index 8f729dbfb73..5fde3443457 100644 --- a/lib/Analysis/TargetTransformInfo.cpp +++ b/lib/Analysis/TargetTransformInfo.cpp @@ -18,6 +18,8 @@ #include "llvm/IR/PatternMatch.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Analysis/CFG.h" +#include "llvm/Analysis/LoopIterator.h" #include using namespace llvm; @@ -216,8 +218,14 @@ bool TargetTransformInfo::isLoweredToCall(const Function *F) const { } bool TargetTransformInfo::isHardwareLoopProfitable( - Loop *L, ScalarEvolution &SE, AssumptionCache &AC, + Loop *L, LoopInfo &LI, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const { + // If the loop has irreducible control flow, it can not be converted to + // Hardware loop. + LoopBlocksRPO RPOT(L); + RPOT.perform(&LI); + if (containsIrreducibleCFG(RPOT, LI)) + return false; return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo); } diff --git a/lib/CodeGen/HardwareLoops.cpp b/lib/CodeGen/HardwareLoops.cpp index 43594915383..3d900e3b7f5 100644 --- a/lib/CodeGen/HardwareLoops.cpp +++ b/lib/CodeGen/HardwareLoops.cpp @@ -20,9 +20,7 @@ #include "llvm/PassSupport.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AssumptionCache.h" -#include "llvm/Analysis/CFG.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/LoopIterator.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/TargetTransformInfo.h" @@ -199,14 +197,8 @@ bool HardwareLoops::TryConvertLoop(Loop *L) { if (TryConvertLoop(*I)) return true; // Stop search. - // Bail out if the loop has irreducible control flow. - LoopBlocksRPO RPOT(L); - RPOT.perform(LI); - if (containsIrreducibleCFG(RPOT, *LI)) - return false; - HardwareLoopInfo HWLoopInfo(L); - if (TTI->isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo) || + if (TTI->isHardwareLoopProfitable(L, *LI, *SE, *AC, LibInfo, HWLoopInfo) || ForceHardwareLoops) { // Allow overriding of the counter width and loop decrement value.