mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-15 04:20:27 +00:00
If true / false blocks fallthrough before ifcvt, add unconditional branches to ifcvt'd block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37200 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dcc50a4aee
commit
47d2502072
@ -87,8 +87,6 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
TII = MF.getTarget().getInstrInfo();
|
TII = MF.getTarget().getInstrInfo();
|
||||||
if (!TII) return false;
|
if (!TII) return false;
|
||||||
|
|
||||||
MadeChange = false;
|
|
||||||
|
|
||||||
MF.RenumberBlocks();
|
MF.RenumberBlocks();
|
||||||
unsigned NumBBs = MF.getNumBlockIDs();
|
unsigned NumBBs = MF.getNumBlockIDs();
|
||||||
BBAnalysis.resize(NumBBs);
|
BBAnalysis.resize(NumBBs);
|
||||||
@ -98,6 +96,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
// candidates to perform if-convesion.
|
// candidates to perform if-convesion.
|
||||||
InitialFunctionAnalysis(MF, Candidates);
|
InitialFunctionAnalysis(MF, Candidates);
|
||||||
|
|
||||||
|
MadeChange = false;
|
||||||
for (unsigned i = 0, e = Candidates.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Candidates.size(); i != e; ++i) {
|
||||||
BBInfo &BBI = BBAnalysis[Candidates[i]];
|
BBInfo &BBI = BBAnalysis[Candidates[i]];
|
||||||
switch (BBI.Kind) {
|
switch (BBI.Kind) {
|
||||||
@ -111,6 +110,9 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BBAnalysis.clear();
|
||||||
|
|
||||||
return MadeChange;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +152,10 @@ void IfConverter::AnalyzeBlock(MachineBasicBlock *BB) {
|
|||||||
if (TrueBBI.Kind != ICNotClassfied)
|
if (TrueBBI.Kind != ICNotClassfied)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// TODO: Only handle very simple cases for now.
|
||||||
|
if (TrueBBI.FalseBB || TrueBBI.Cond.size())
|
||||||
|
return;
|
||||||
|
|
||||||
// No false branch. This BB must end with a conditional branch and a
|
// No false branch. This BB must end with a conditional branch and a
|
||||||
// fallthrough.
|
// fallthrough.
|
||||||
if (!BBI.FalseBB)
|
if (!BBI.FalseBB)
|
||||||
@ -168,8 +174,7 @@ void IfConverter::AnalyzeBlock(MachineBasicBlock *BB) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: Only handle very simple cases for now.
|
// TODO: Only handle very simple cases for now.
|
||||||
if (TrueBBI.FalseBB || FalseBBI.FalseBB ||
|
if (FalseBBI.FalseBB || FalseBBI.Cond.size())
|
||||||
TrueBBI.Cond.size() || FalseBBI.Cond.size())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TrueBBI.TrueBB && TrueBBI.TrueBB == BBI.FalseBB) {
|
if (TrueBBI.TrueBB && TrueBBI.TrueBB == BBI.FalseBB) {
|
||||||
@ -309,11 +314,21 @@ bool IfConverter::IfConvertDiamond(BBInfo &BBI) {
|
|||||||
TrueBBI.Size -= TII->RemoveBranch(*BBI.TrueBB);
|
TrueBBI.Size -= TII->RemoveBranch(*BBI.TrueBB);
|
||||||
PredicateBlock(BBI.TrueBB, BBI.Cond);
|
PredicateBlock(BBI.TrueBB, BBI.Cond);
|
||||||
|
|
||||||
|
// Either the 'true' block fallthrough to another block or it ends with a
|
||||||
|
// return. If it's the former, add a conditional branch to its successor.
|
||||||
|
if (!TrueBBI.TrueBB)
|
||||||
|
TII->InsertBranch(*BBI.TrueBB, *BBI.TrueBB->succ_begin(), NULL, BBI.Cond);
|
||||||
|
|
||||||
// Predicate the 'false' block.
|
// Predicate the 'false' block.
|
||||||
std::vector<MachineOperand> NewCond(BBI.Cond);
|
std::vector<MachineOperand> NewCond(BBI.Cond);
|
||||||
TII->ReverseBranchCondition(NewCond);
|
TII->ReverseBranchCondition(NewCond);
|
||||||
PredicateBlock(BBI.FalseBB, NewCond, true);
|
PredicateBlock(BBI.FalseBB, NewCond, true);
|
||||||
|
|
||||||
|
// Either the 'false' block fallthrough to another block or it ends with a
|
||||||
|
// return. If it's the former, add a conditional branch to its successor.
|
||||||
|
if (!FalseBBI.TrueBB)
|
||||||
|
TII->InsertBranch(*BBI.FalseBB, *BBI.FalseBB->succ_begin(), NULL,NewCond);
|
||||||
|
|
||||||
// Merge the 'true' and 'false' blocks by copying the instructions
|
// Merge the 'true' and 'false' blocks by copying the instructions
|
||||||
// from the 'false' block to the 'true' block.
|
// from the 'false' block to the 'true' block.
|
||||||
MergeBlocks(TrueBBI, FalseBBI);
|
MergeBlocks(TrueBBI, FalseBBI);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user