class LiveRangesTest : public CommonCompilerTest, public OptimizingUnitTestHelper { protected: // Define a shortcut for the `kLivenessPositionsPerInstruction`. static constexpr size_t kLppi = kLivenessPositionsPerInstruction;
HGraph* LiveRangesTest::BuildGraph(const std::vector<uint16_t>& data) {
HGraph* graph = CreateCFG(data);
compiler_options_ = CommonCompilerTest::CreateCompilerOptions(kRuntimeISA, "default"); // Suspend checks implementation may change in the future, and this test relies // on how instructions are ordered.
RemoveSuspendChecks(graph); // `Inline` conditions into ifs.
PrepareForRegisterAllocation(graph, *compiler_options_).Run(); return graph;
}
// Test for the 4 constant.
LiveInterval* interval = liveness.GetInstructionFromSsaIndex(1)->GetLiveInterval();
LiveRange* range = interval->GetFirstRange();
ASSERT_EQ(2u * kLppi, range->GetStart()); // Last use is the phi at the return block so instruction is live until // the end of the then block.
ASSERT_EQ(9u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the 0 constant.
interval = liveness.GetInstructionFromSsaIndex(0)->GetLiveInterval(); // The then branch is a hole for this constant, therefore its interval has 2 ranges. // First range starts from the definition and ends at the if block.
range = interval->GetFirstRange();
ASSERT_EQ(1u * kLppi, range->GetStart()); // 14 is the end of the if block.
ASSERT_EQ(7u * kLppi, range->GetEnd()); // Second range is the else block.
range = range->GetNext();
ASSERT_EQ(9u * kLppi, range->GetStart()); // Last use is the phi at the return block.
ASSERT_EQ(11u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the phi.
interval = liveness.GetInstructionFromSsaIndex(2)->GetLiveInterval();
range = interval->GetFirstRange();
ASSERT_EQ(11u * kLppi, liveness.GetInstructionFromSsaIndex(2)->GetLifetimePosition());
ASSERT_EQ(11u * kLppi, range->GetStart());
ASSERT_EQ(12u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
}
// Test for the 0 constant.
LiveInterval* interval = graph->GetIntConstant(0)->GetLiveInterval();
LiveRange* range = interval->GetFirstRange();
ASSERT_EQ(1u * kLppi, range->GetStart()); // Last use is the loop phi so instruction is live until // the end of the pre loop header.
ASSERT_EQ(7u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the 4 constant.
interval = graph->GetIntConstant(4)->GetLiveInterval();
range = interval->GetFirstRange(); // The instruction is live until the end of the loop.
ASSERT_EQ(3u * kLppi, range->GetStart());
ASSERT_EQ(12u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the 5 constant.
interval = graph->GetIntConstant(5)->GetLiveInterval();
range = interval->GetFirstRange(); // The instruction is live until the return instruction after the loop.
ASSERT_EQ(2u * kLppi, range->GetStart());
ASSERT_EQ(13u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the phi.
interval = liveness.GetInstructionFromSsaIndex(3)->GetLiveInterval();
range = interval->GetFirstRange(); // Instruction is input of non-materialized Equal and hence live until If.
ASSERT_EQ(7u * kLppi, range->GetStart());
ASSERT_EQ(9u * kLppi + kLivenessPositionOfNormalUse, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
}
// Test for the 0 constant.
HIntConstant* constant = liveness.GetInstructionFromSsaIndex(0)->AsIntConstant();
LiveInterval* interval = constant->GetLiveInterval();
LiveRange* range = interval->GetFirstRange();
ASSERT_EQ(1u * kLppi, range->GetStart()); // Last use is the loop phi so instruction is live until // the end of the pre loop header.
ASSERT_EQ(5u * kLppi, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
// Test for the loop phi.
HPhi* phi = liveness.GetInstructionFromSsaIndex(1)->AsPhi();
interval = phi->GetLiveInterval();
range = interval->GetFirstRange();
ASSERT_EQ(5u * kLppi, range->GetStart());
ASSERT_EQ(9u * kLppi + kLivenessPositionOfNormalUse, range->GetEnd());
range = range->GetNext();
ASSERT_TRUE(range != nullptr);
ASSERT_EQ(11u * kLppi, range->GetStart());
ASSERT_EQ(12u * kLppi, range->GetEnd());
// Test for the add instruction.
HAdd* add = liveness.GetInstructionFromSsaIndex(2)->AsAdd();
interval = add->GetLiveInterval();
range = interval->GetFirstRange();
ASSERT_EQ(36u, range->GetStart());
ASSERT_EQ(44u, range->GetEnd());
ASSERT_TRUE(range->GetNext() == nullptr);
}
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.