Skip to content

Commit

Permalink
[HardwareLoops] NFC - move loop with irreducible control flow checkin…
Browse files Browse the repository at this point in the history
…g logic to HarewareLoopInfo.

llvm-svn: 364415
Chen Zheng committed Jun 26, 2019
1 parent 6876de9 commit aa99952
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ struct HardwareLoopInfo {
bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI,
DominatorTree &DT, bool ForceNestedLoop = false,
bool ForceHardwareLoopPHI = false);
bool canAnalyze(LoopInfo &LI);
};

/// This pass provides access to the codegen interfaces that are needed
@@ -473,8 +474,7 @@ class TargetTransformInfo {

/// Query the target whether it would be profitable to convert the given loop
/// into a hardware loop.
bool isHardwareLoopProfitable(Loop *L, LoopInfo &LI,
ScalarEvolution &SE,
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
AssumptionCache &AC,
TargetLibraryInfo *LibInfo,
HardwareLoopInfo &HWLoopInfo) const;
18 changes: 11 additions & 7 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
@@ -42,6 +42,16 @@ struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
};
}

bool HardwareLoopInfo::canAnalyze(LoopInfo &LI) {
// If the loop has irreducible control flow, it can not be converted to
// Hardware loop.
LoopBlocksRPO RPOT(L);
RPOT.perform(&LI);
if (containsIrreducibleCFG<const BasicBlock *>(RPOT, LI))
return false;
return true;
}

bool HardwareLoopInfo::isHardwareLoopCandidate(ScalarEvolution &SE,
LoopInfo &LI, DominatorTree &DT,
bool ForceNestedLoop,
@@ -218,14 +228,8 @@ bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
}

bool TargetTransformInfo::isHardwareLoopProfitable(
Loop *L, LoopInfo &LI, ScalarEvolution &SE, AssumptionCache &AC,
Loop *L, 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<const BasicBlock *>(RPOT, LI))
return false;
return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
}

5 changes: 4 additions & 1 deletion llvm/lib/CodeGen/HardwareLoops.cpp
Original file line number Diff line number Diff line change
@@ -198,7 +198,10 @@ bool HardwareLoops::TryConvertLoop(Loop *L) {
return true; // Stop search.

HardwareLoopInfo HWLoopInfo(L);
if (TTI->isHardwareLoopProfitable(L, *LI, *SE, *AC, LibInfo, HWLoopInfo) ||
if (!HWLoopInfo.canAnalyze(*LI))
return false;

if (TTI->isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo) ||
ForceHardwareLoops) {

// Allow overriding of the counter width and loop decrement value.

0 comments on commit aa99952

Please sign in to comment.