// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be the return block.
TEST_F(GraphTest, IfSuccessorSimpleJoinBlock1) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* if_true = CreateGotoBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
// Ensure we still have the same if true block.
ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), if_true);
// Ensure the critical edge has been removed.
HBasicBlock* false_block = if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor();
ASSERT_NE(false_block, return_block);
// Ensure the new block branches to the join block.
ASSERT_EQ(false_block->GetSuccessors()[0], return_block);
}
// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be the return block.
TEST_F(GraphTest, IfSuccessorSimpleJoinBlock2) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* if_false = CreateGotoBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
// Ensure we still have the same if true block.
ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), if_false);
// Ensure the critical edge has been removed.
HBasicBlock* true_block = if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor();
ASSERT_NE(true_block, return_block);
// Ensure the new block branches to the join block.
ASSERT_EQ(true_block->GetSuccessors()[0], return_block);
}
// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be the loop header.
TEST_F(GraphTest, IfSuccessorMultipleBackEdges1) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
// Ensure we still have the same if false block.
ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor(), return_block);
// Ensure there is only one back edge.
ASSERT_EQ(if_block->GetPredecessors().size(), 2u);
ASSERT_EQ(if_block->GetPredecessors()[0], entry_block->GetSingleSuccessor());
ASSERT_NE(if_block->GetPredecessors()[1], if_block);
// Ensure the new block is the back edge.
ASSERT_EQ(if_block->GetPredecessors()[1],
if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor());
}
// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be the loop header.
TEST_F(GraphTest, IfSuccessorMultipleBackEdges2) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
// Ensure we still have the same if true block.
ASSERT_EQ(if_block->GetLastInstruction()->AsIf()->IfTrueSuccessor(), return_block);
// Ensure there is only one back edge.
ASSERT_EQ(if_block->GetPredecessors().size(), 2u);
ASSERT_EQ(if_block->GetPredecessors()[0], entry_block->GetSingleSuccessor());
ASSERT_NE(if_block->GetPredecessors()[1], if_block);
// Ensure the new block is the back edge.
ASSERT_EQ(if_block->GetPredecessors()[1],
if_block->GetLastInstruction()->AsIf()->IfFalseSuccessor());
}
// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the true block to be a loop header with multiple pre headers.
TEST_F(GraphTest, IfSuccessorMultiplePreHeaders1) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* first_if_block = CreateIfBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* loop_block = CreateGotoBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
HIf* if_instr = if_block->GetLastInstruction()->AsIf(); // Ensure we still have the same if false block.
ASSERT_EQ(if_instr->IfFalseSuccessor(), return_block);
// Ensure there is only one pre header..
ASSERT_EQ(loop_block->GetPredecessors().size(), 2u);
// Ensure the new block is the successor of the true block.
ASSERT_EQ(if_instr->IfTrueSuccessor()->GetSuccessors().size(), 1u);
ASSERT_EQ(if_instr->IfTrueSuccessor()->GetSuccessors()[0],
loop_block->GetLoopInformation()->GetPreHeader());
}
// Test that the successors of an if block stay consistent after a SimplifyCFG. // This test sets the false block to be a loop header with multiple pre headers.
TEST_F(GraphTest, IfSuccessorMultiplePreHeaders2) {
HGraph* graph = CreateGraph();
HBasicBlock* entry_block = CreateEntryBlock();
HBasicBlock* first_if_block = CreateIfBlock();
HBasicBlock* if_block = CreateIfBlock();
HBasicBlock* loop_block = CreateGotoBlock();
HBasicBlock* return_block = CreateReturnBlock();
HBasicBlock* exit_block = AddExitBlock();
HIf* if_instr = if_block->GetLastInstruction()->AsIf(); // Ensure we still have the same if true block.
ASSERT_EQ(if_instr->IfTrueSuccessor(), return_block);
// Ensure there is only one pre header..
ASSERT_EQ(loop_block->GetPredecessors().size(), 2u);
// Ensure the new block is the successor of the false block.
ASSERT_EQ(if_instr->IfFalseSuccessor()->GetSuccessors().size(), 1u);
ASSERT_EQ(if_instr->IfFalseSuccessor()->GetSuccessors()[0],
loop_block->GetLoopInformation()->GetPreHeader());
}
// Test at the beginning of the block.
HInstruction* first_instruction = new (GetAllocator()) HIntConstant(4);
block->InsertInstructionBefore(first_instruction, got);
// Test in the middle of the block.
HInstruction* second_instruction = new (GetAllocator()) HIntConstant(4);
block->InsertInstructionBefore(second_instruction, got);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.