mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-27 21:50:40 +00:00
Try to appease MSVC, NFCI.
This time by lifting the lambda's in `createNodeFromSelectLikePHI` to the file scope. Looks like there are differences in capture rules between clang and MSVC? git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249222 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8da370d30b
commit
7db865a9ea
@ -3742,45 +3742,10 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||
const Loop *L = LI.getLoopFor(PN->getParent());
|
||||
|
||||
// Try to match a control flow sequence that branches out at BI and merges
|
||||
// back at Merge into a "C ? LHS : RHS" select pattern. Return true on a
|
||||
// successful match.
|
||||
auto BrPHIToSelect = [&](BranchInst *BI, PHINode *Merge, Value *&C,
|
||||
Value *&LHS, Value *&RHS) {
|
||||
C = BI->getCondition();
|
||||
|
||||
BasicBlockEdge LeftEdge(BI->getParent(), BI->getSuccessor(0));
|
||||
BasicBlockEdge RightEdge(BI->getParent(), BI->getSuccessor(1));
|
||||
|
||||
if (!LeftEdge.isSingleEdge())
|
||||
return false;
|
||||
|
||||
assert(RightEdge.isSingleEdge() && "Follows from LeftEdge.isSingleEdge()");
|
||||
|
||||
Use &LeftUse = Merge->getOperandUse(0);
|
||||
Use &RightUse = Merge->getOperandUse(1);
|
||||
|
||||
if (DT.dominates(LeftEdge, LeftUse) && DT.dominates(RightEdge, RightUse)) {
|
||||
LHS = LeftUse;
|
||||
RHS = RightUse;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DT.dominates(LeftEdge, RightUse) && DT.dominates(RightEdge, LeftUse)) {
|
||||
LHS = RightUse;
|
||||
RHS = LeftUse;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Checks if the SCEV S is available at BB. S is considered available at BB
|
||||
// if S can be materialized at BB without introducing a fault.
|
||||
auto IsAvailableOnEntry = [&](const SCEV *S, BasicBlock *BB) {
|
||||
static bool IsAvailableOnEntry(const Loop *L, DominatorTree &DT, const SCEV *S,
|
||||
BasicBlock *BB) {
|
||||
struct CheckAvailable {
|
||||
bool TraversalDone = false;
|
||||
bool Available = true;
|
||||
@ -3826,8 +3791,7 @@ const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||
if (isa<Argument>(V))
|
||||
return false;
|
||||
|
||||
if (isa<Instruction>(V) &&
|
||||
this->DT.dominates(cast<Instruction>(V), BB))
|
||||
if (isa<Instruction>(V) && DT.dominates(cast<Instruction>(V), BB))
|
||||
return false;
|
||||
|
||||
return setUnavailable();
|
||||
@ -3844,14 +3808,50 @@ const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||
bool isDone() { return TraversalDone; }
|
||||
};
|
||||
|
||||
CheckAvailable CA(L, BB, this->DT);
|
||||
CheckAvailable CA(L, BB, DT);
|
||||
SCEVTraversal<CheckAvailable> ST(CA);
|
||||
|
||||
ST.visitAll(S);
|
||||
return CA.Available;
|
||||
};
|
||||
}
|
||||
|
||||
// Try to match a control flow sequence that branches out at BI and merges back
|
||||
// at Merge into a "C ? LHS : RHS" select pattern. Return true on a successful
|
||||
// match.
|
||||
static bool BrPHIToSelect(DominatorTree &DT, BranchInst *BI, PHINode *Merge,
|
||||
Value *&C, Value *&LHS, Value *&RHS) {
|
||||
C = BI->getCondition();
|
||||
|
||||
BasicBlockEdge LeftEdge(BI->getParent(), BI->getSuccessor(0));
|
||||
BasicBlockEdge RightEdge(BI->getParent(), BI->getSuccessor(1));
|
||||
|
||||
if (!LeftEdge.isSingleEdge())
|
||||
return false;
|
||||
|
||||
assert(RightEdge.isSingleEdge() && "Follows from LeftEdge.isSingleEdge()");
|
||||
|
||||
Use &LeftUse = Merge->getOperandUse(0);
|
||||
Use &RightUse = Merge->getOperandUse(1);
|
||||
|
||||
if (DT.dominates(LeftEdge, LeftUse) && DT.dominates(RightEdge, RightUse)) {
|
||||
LHS = LeftUse;
|
||||
RHS = RightUse;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DT.dominates(LeftEdge, RightUse) && DT.dominates(RightEdge, LeftUse)) {
|
||||
LHS = RightUse;
|
||||
RHS = LeftUse;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||
if (PN->getNumIncomingValues() == 2) {
|
||||
const Loop *L = LI.getLoopFor(PN->getParent());
|
||||
|
||||
// Try to match
|
||||
//
|
||||
// br %cond, label %left, label %right
|
||||
@ -3870,9 +3870,10 @@ const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||
auto *BI = dyn_cast<BranchInst>(IDom->getTerminator());
|
||||
Value *Cond = nullptr, *LHS = nullptr, *RHS = nullptr;
|
||||
|
||||
if (BI && BI->isConditional() && BrPHIToSelect(BI, PN, Cond, LHS, RHS) &&
|
||||
IsAvailableOnEntry(getSCEV(LHS), PN->getParent()) &&
|
||||
IsAvailableOnEntry(getSCEV(RHS), PN->getParent()))
|
||||
if (BI && BI->isConditional() &&
|
||||
BrPHIToSelect(DT, BI, PN, Cond, LHS, RHS) &&
|
||||
IsAvailableOnEntry(L, DT, getSCEV(LHS), PN->getParent()) &&
|
||||
IsAvailableOnEntry(L, DT, getSCEV(RHS), PN->getParent()))
|
||||
return createNodeForSelectOrPHI(PN, Cond, LHS, RHS);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user