mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
Factor out the code for mapping LLVM IR condition opcodes to
ISD condition opcodes into helper functions. llvm-svn: 57726
This commit is contained in:
parent
08d0796cf5
commit
e1e1c5197e
@ -1051,32 +1051,26 @@ static ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindMergedConditions - If Cond is an expression like
|
/// EmitBranchForMergedCondition - Helper method for FindMergedConditions.
|
||||||
void SelectionDAGLowering::FindMergedConditions(Value *Cond,
|
/// This function emits a branch and is used at the leaves of an OR or an
|
||||||
MachineBasicBlock *TBB,
|
/// AND operator tree.
|
||||||
MachineBasicBlock *FBB,
|
///
|
||||||
MachineBasicBlock *CurBB,
|
void
|
||||||
unsigned Opc) {
|
SelectionDAGLowering::EmitBranchForMergedCondition(Value *Cond,
|
||||||
// If this node is not part of the or/and tree, emit it as a branch.
|
MachineBasicBlock *TBB,
|
||||||
Instruction *BOp = dyn_cast<Instruction>(Cond);
|
MachineBasicBlock *FBB,
|
||||||
|
MachineBasicBlock *CurBB) {
|
||||||
|
const BasicBlock *BB = CurBB->getBasicBlock();
|
||||||
|
|
||||||
if (!BOp || !(isa<BinaryOperator>(BOp) || isa<CmpInst>(BOp)) ||
|
// If the leaf of the tree is a comparison, merge the condition into
|
||||||
(unsigned)BOp->getOpcode() != Opc || !BOp->hasOneUse() ||
|
// the caseblock.
|
||||||
BOp->getParent() != CurBB->getBasicBlock() ||
|
if (CmpInst *BOp = dyn_cast<CmpInst>(Cond)) {
|
||||||
!InBlock(BOp->getOperand(0), CurBB->getBasicBlock()) ||
|
// The operands of the cmp have to be in this block. We don't know
|
||||||
!InBlock(BOp->getOperand(1), CurBB->getBasicBlock())) {
|
// how to export them from some other block. If this is the first block
|
||||||
const BasicBlock *BB = CurBB->getBasicBlock();
|
// of the sequence, no exporting is needed.
|
||||||
|
if (CurBB == CurMBB ||
|
||||||
// If the leaf of the tree is a comparison, merge the condition into
|
(isExportableFromCurrentBlock(BOp->getOperand(0), BB) &&
|
||||||
// the caseblock.
|
isExportableFromCurrentBlock(BOp->getOperand(1), BB))) {
|
||||||
if (isa<CmpInst>(Cond) &&
|
|
||||||
// The operands of the cmp have to be in this block. We don't know
|
|
||||||
// how to export them from some other block. If this is the first block
|
|
||||||
// of the sequence, no exporting is needed.
|
|
||||||
(CurBB == CurMBB ||
|
|
||||||
(isExportableFromCurrentBlock(BOp->getOperand(0), BB) &&
|
|
||||||
isExportableFromCurrentBlock(BOp->getOperand(1), BB)))) {
|
|
||||||
BOp = cast<Instruction>(Cond);
|
|
||||||
ISD::CondCode Condition;
|
ISD::CondCode Condition;
|
||||||
if (ICmpInst *IC = dyn_cast<ICmpInst>(Cond)) {
|
if (ICmpInst *IC = dyn_cast<ICmpInst>(Cond)) {
|
||||||
Condition = getICmpCondCode(IC->getPredicate());
|
Condition = getICmpCondCode(IC->getPredicate());
|
||||||
@ -1086,21 +1080,37 @@ void SelectionDAGLowering::FindMergedConditions(Value *Cond,
|
|||||||
Condition = ISD::SETEQ; // silence warning.
|
Condition = ISD::SETEQ; // silence warning.
|
||||||
assert(0 && "Unknown compare instruction");
|
assert(0 && "Unknown compare instruction");
|
||||||
}
|
}
|
||||||
|
|
||||||
CaseBlock CB(Condition, BOp->getOperand(0),
|
CaseBlock CB(Condition, BOp->getOperand(0),
|
||||||
BOp->getOperand(1), NULL, TBB, FBB, CurBB);
|
BOp->getOperand(1), NULL, TBB, FBB, CurBB);
|
||||||
SwitchCases.push_back(CB);
|
SwitchCases.push_back(CB);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Create a CaseBlock record representing this branch.
|
|
||||||
CaseBlock CB(ISD::SETEQ, Cond, ConstantInt::getTrue(),
|
// Create a CaseBlock record representing this branch.
|
||||||
NULL, TBB, FBB, CurBB);
|
CaseBlock CB(ISD::SETEQ, Cond, ConstantInt::getTrue(),
|
||||||
SwitchCases.push_back(CB);
|
NULL, TBB, FBB, CurBB);
|
||||||
|
SwitchCases.push_back(CB);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// FindMergedConditions - If Cond is an expression like
|
||||||
|
void SelectionDAGLowering::FindMergedConditions(Value *Cond,
|
||||||
|
MachineBasicBlock *TBB,
|
||||||
|
MachineBasicBlock *FBB,
|
||||||
|
MachineBasicBlock *CurBB,
|
||||||
|
unsigned Opc) {
|
||||||
|
// If this node is not part of the or/and tree, emit it as a branch.
|
||||||
|
Instruction *BOp = dyn_cast<Instruction>(Cond);
|
||||||
|
if (!BOp || !(isa<BinaryOperator>(BOp) || isa<CmpInst>(BOp)) ||
|
||||||
|
(unsigned)BOp->getOpcode() != Opc || !BOp->hasOneUse() ||
|
||||||
|
BOp->getParent() != CurBB->getBasicBlock() ||
|
||||||
|
!InBlock(BOp->getOperand(0), CurBB->getBasicBlock()) ||
|
||||||
|
!InBlock(BOp->getOperand(1), CurBB->getBasicBlock())) {
|
||||||
|
EmitBranchForMergedCondition(Cond, TBB, FBB, CurBB);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create TmpBB after CurBB.
|
// Create TmpBB after CurBB.
|
||||||
MachineFunction::iterator BBI = CurBB;
|
MachineFunction::iterator BBI = CurBB;
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
|
@ -405,6 +405,9 @@ public:
|
|||||||
void FindMergedConditions(Value *Cond, MachineBasicBlock *TBB,
|
void FindMergedConditions(Value *Cond, MachineBasicBlock *TBB,
|
||||||
MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
|
MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
|
||||||
unsigned Opc);
|
unsigned Opc);
|
||||||
|
void EmitBranchForMergedCondition(Value *Cond, MachineBasicBlock *TBB,
|
||||||
|
MachineBasicBlock *FBB,
|
||||||
|
MachineBasicBlock *CurBB);
|
||||||
bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
|
bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
|
||||||
bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB);
|
bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB);
|
||||||
void ExportFromCurrentBlock(Value *V);
|
void ExportFromCurrentBlock(Value *V);
|
||||||
|
Loading…
Reference in New Issue
Block a user