2016-12-05 10:47:38 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
#include "src/compiler/bytecode-analysis.h"
|
|
|
|
#include "src/interpreter/bytecode-array-builder.h"
|
|
|
|
#include "src/interpreter/bytecode-array-iterator.h"
|
|
|
|
#include "src/interpreter/bytecode-decoder.h"
|
|
|
|
#include "src/interpreter/bytecode-label.h"
|
|
|
|
#include "src/interpreter/control-flow-builders.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2018-03-22 12:46:53 +00:00
|
|
|
#include "test/unittests/interpreter/bytecode-utils.h"
|
2016-12-05 10:47:38 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
using ToBooleanMode = interpreter::BytecodeArrayBuilder::ToBooleanMode;
|
|
|
|
|
2016-12-05 10:47:38 +00:00
|
|
|
class BytecodeAnalysisTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
2018-09-17 11:30:48 +00:00
|
|
|
BytecodeAnalysisTest() = default;
|
|
|
|
~BytecodeAnalysisTest() override = default;
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
static void SetUpTestCase() {
|
2017-04-11 11:01:28 +00:00
|
|
|
CHECK_NULL(save_flags_);
|
|
|
|
save_flags_ = new SaveFlags();
|
|
|
|
i::FLAG_ignition_elide_noneffectful_bytecodes = false;
|
2016-12-05 10:47:38 +00:00
|
|
|
i::FLAG_ignition_reo = false;
|
|
|
|
|
|
|
|
TestWithIsolateAndZone::SetUpTestCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestCase() {
|
|
|
|
TestWithIsolateAndZone::TearDownTestCase();
|
2017-04-11 11:01:28 +00:00
|
|
|
delete save_flags_;
|
|
|
|
save_flags_ = nullptr;
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 12:47:45 +00:00
|
|
|
std::string ToLivenessString(const BytecodeLivenessState* liveness) const {
|
|
|
|
const BitVector& bit_vector = liveness->bit_vector();
|
|
|
|
|
2016-12-05 10:47:38 +00:00
|
|
|
std::string out;
|
2016-12-08 12:47:45 +00:00
|
|
|
out.resize(bit_vector.length());
|
|
|
|
for (int i = 0; i < bit_vector.length(); ++i) {
|
|
|
|
if (bit_vector.Contains(i)) {
|
2016-12-05 10:47:38 +00:00
|
|
|
out[i] = 'L';
|
|
|
|
} else {
|
|
|
|
out[i] = '.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnsureLivenessMatches(
|
|
|
|
Handle<BytecodeArray> bytecode,
|
|
|
|
const std::vector<std::pair<std::string, std::string>>&
|
|
|
|
expected_liveness) {
|
|
|
|
BytecodeAnalysis analysis(bytecode, zone(), true);
|
2016-12-15 13:24:19 +00:00
|
|
|
analysis.Analyze(BailoutId::None());
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
interpreter::BytecodeArrayIterator iterator(bytecode);
|
|
|
|
for (auto liveness : expected_liveness) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::setw(4) << iterator.current_offset() << " : ";
|
|
|
|
iterator.PrintTo(ss);
|
|
|
|
|
|
|
|
EXPECT_EQ(liveness.first, ToLivenessString(analysis.GetInLivenessFor(
|
|
|
|
iterator.current_offset())))
|
|
|
|
<< " at bytecode " << ss.str();
|
|
|
|
|
|
|
|
EXPECT_EQ(liveness.second, ToLivenessString(analysis.GetOutLivenessFor(
|
|
|
|
iterator.current_offset())))
|
|
|
|
<< " at bytecode " << ss.str();
|
|
|
|
|
|
|
|
iterator.Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(iterator.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-04-11 11:01:28 +00:00
|
|
|
static SaveFlags* save_flags_;
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysisTest);
|
|
|
|
};
|
|
|
|
|
2017-04-11 11:01:28 +00:00
|
|
|
SaveFlags* BytecodeAnalysisTest::save_flags_ = nullptr;
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, EmptyBlock) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, SimpleLoad) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L...", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, StoreThenLoad) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("...L", "L...");
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L...", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, DiamondLoad) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
interpreter::Register reg_2(2);
|
|
|
|
|
|
|
|
interpreter::BytecodeLabel ld1_label;
|
|
|
|
interpreter::BytecodeLabel end_label;
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, &ld1_label);
|
2016-12-05 10:47:38 +00:00
|
|
|
expected_liveness.emplace_back("LLLL", "LLL.");
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L.L.", "..L.");
|
|
|
|
|
|
|
|
builder.Jump(&end_label);
|
|
|
|
expected_liveness.emplace_back("..L.", "..L.");
|
|
|
|
|
|
|
|
builder.Bind(&ld1_label);
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_1);
|
|
|
|
expected_liveness.emplace_back(".LL.", "..L.");
|
|
|
|
|
|
|
|
builder.Bind(&end_label);
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_2);
|
|
|
|
expected_liveness.emplace_back("..L.", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, DiamondLookupsAndBinds) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
interpreter::Register reg_2(2);
|
|
|
|
|
|
|
|
interpreter::BytecodeLabel ld1_label;
|
|
|
|
interpreter::BytecodeLabel end_label;
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back(".LLL", "LLLL");
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, &ld1_label);
|
2016-12-05 10:47:38 +00:00
|
|
|
expected_liveness.emplace_back("LLLL", "LLL.");
|
|
|
|
|
|
|
|
{
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L...", "...L");
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_2);
|
|
|
|
expected_liveness.emplace_back("...L", "..L.");
|
|
|
|
|
|
|
|
builder.Jump(&end_label);
|
|
|
|
expected_liveness.emplace_back("..L.", "..L.");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Bind(&ld1_label);
|
|
|
|
{
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_1);
|
|
|
|
expected_liveness.emplace_back(".LL.", "..L.");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Bind(&end_label);
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_2);
|
|
|
|
expected_liveness.emplace_back("..L.", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, SimpleLoop) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
interpreter::Register reg_2(2);
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Kill r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("..LL", "L.L.");
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
{
|
2017-07-12 13:06:09 +00:00
|
|
|
interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr);
|
2017-05-15 16:31:05 +00:00
|
|
|
loop_builder.LoopHeader();
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
builder.LoadUndefined();
|
|
|
|
expected_liveness.emplace_back("L.L.", "L.LL");
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean,
|
|
|
|
loop_builder.break_labels()->New());
|
2016-12-05 10:47:38 +00:00
|
|
|
expected_liveness.emplace_back("L.LL", "L.L.");
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L...", "L..L");
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Kill r2.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.StoreAccumulatorInRegister(reg_2);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L..L", "L.L.");
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
loop_builder.BindContinueTarget();
|
|
|
|
loop_builder.JumpToHeader(0);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L.L.", "L.L.");
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r2.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_2);
|
|
|
|
expected_liveness.emplace_back("..L.", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, TryCatch) {
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
interpreter::Register reg_context(2);
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Kill r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back(".LLL", "LLL.");
|
|
|
|
|
2017-11-09 09:42:03 +00:00
|
|
|
interpreter::TryCatchBuilder try_builder(&builder, nullptr, nullptr,
|
|
|
|
HandlerTable::CAUGHT);
|
2016-12-05 10:47:38 +00:00
|
|
|
try_builder.BeginTry(reg_context);
|
|
|
|
{
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("LLL.", ".LLL");
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Kill r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back(".LLL", ".LL.");
|
|
|
|
|
|
|
|
builder.CallRuntime(Runtime::kThrow);
|
|
|
|
expected_liveness.emplace_back(".LL.", ".LLL");
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
// Star can't throw, so doesn't take handler liveness
|
|
|
|
expected_liveness.emplace_back("...L", "...L");
|
|
|
|
}
|
|
|
|
try_builder.EndTry();
|
|
|
|
expected_liveness.emplace_back("...L", "...L");
|
|
|
|
|
|
|
|
// Catch
|
|
|
|
{
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_1);
|
|
|
|
expected_liveness.emplace_back(".L..", "...L");
|
|
|
|
}
|
|
|
|
try_builder.EndCatch();
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, DiamondInLoop) {
|
2017-08-15 15:17:58 +00:00
|
|
|
// For a logic diamond inside a loop, the liveness down one path of the
|
|
|
|
// diamond should eventually propagate up the other path when the loop is
|
|
|
|
// reprocessed.
|
|
|
|
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
|
|
|
|
{
|
2017-07-12 13:06:09 +00:00
|
|
|
interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr);
|
2017-05-15 16:31:05 +00:00
|
|
|
loop_builder.LoopHeader();
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
builder.LoadUndefined();
|
|
|
|
expected_liveness.emplace_back("L...", "L..L");
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean,
|
|
|
|
loop_builder.break_labels()->New());
|
2016-12-05 10:47:38 +00:00
|
|
|
expected_liveness.emplace_back("L..L", "L..L");
|
|
|
|
|
|
|
|
interpreter::BytecodeLabel ld1_label;
|
|
|
|
interpreter::BytecodeLabel end_label;
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean, &ld1_label);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L..L", "L...");
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
builder.Jump(&end_label);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L...", "L...");
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.Bind(&ld1_label);
|
|
|
|
{
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L...", "L...");
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.Bind(&end_label);
|
|
|
|
|
|
|
|
loop_builder.BindContinueTarget();
|
|
|
|
loop_builder.JumpToHeader(0);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("L...", "L...");
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
builder.LoadUndefined();
|
|
|
|
expected_liveness.emplace_back("....", "...L");
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeAnalysisTest, KillingLoopInsideLoop) {
|
2017-08-15 15:17:58 +00:00
|
|
|
// For a loop inside a loop, the inner loop has to be processed after the
|
|
|
|
// outer loop has been processed, to ensure that it can propagate the
|
|
|
|
// information in its header. Consider
|
|
|
|
//
|
|
|
|
// 0: do {
|
|
|
|
// 1: acc = r0;
|
|
|
|
// 2: acc = r1;
|
|
|
|
// 3: do {
|
|
|
|
// 4: r0 = acc;
|
|
|
|
// 5: break;
|
|
|
|
// 6: } while(true);
|
|
|
|
// 7: } while(true);
|
|
|
|
//
|
|
|
|
// r0 should should be dead at 3 and 6, while r1 is live throughout. On the
|
|
|
|
// initial pass, r1 is dead from 3-7. On the outer loop pass, it becomes live
|
|
|
|
// in 3 and 7 (but not 4-6 because 6 only reads liveness from 3). Only after
|
|
|
|
// the inner loop pass does it become live in 4-6. It's necessary, however, to
|
|
|
|
// still process the inner loop when processing the outer loop, to ensure that
|
|
|
|
// r1 becomes live in 3 (via 5), but r0 stays dead (because of 4).
|
|
|
|
|
2017-11-15 14:36:57 +00:00
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
2016-12-05 10:47:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
|
|
|
|
{
|
2017-07-12 13:06:09 +00:00
|
|
|
interpreter::LoopBuilder loop_builder(&builder, nullptr, nullptr);
|
2017-05-15 16:31:05 +00:00
|
|
|
loop_builder.LoopHeader();
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r0.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("LL..", ".L..");
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Gen r1.
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.LoadAccumulatorWithRegister(reg_1);
|
|
|
|
expected_liveness.emplace_back(".L..", ".L.L");
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean,
|
|
|
|
loop_builder.break_labels()->New());
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back(".L.L", ".L..");
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
{
|
2017-07-12 13:06:09 +00:00
|
|
|
interpreter::LoopBuilder inner_loop_builder(&builder, nullptr, nullptr);
|
2017-05-15 16:31:05 +00:00
|
|
|
inner_loop_builder.LoopHeader();
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
// Kill r0.
|
|
|
|
builder.LoadUndefined();
|
|
|
|
expected_liveness.emplace_back(".L..", ".L.L");
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back(".L.L", "LL.L");
|
|
|
|
|
2017-04-05 15:40:27 +00:00
|
|
|
builder.JumpIfTrue(ToBooleanMode::kConvertToBoolean,
|
|
|
|
inner_loop_builder.break_labels()->New());
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back("LL.L", "LL..");
|
2016-12-05 10:47:38 +00:00
|
|
|
|
|
|
|
inner_loop_builder.BindContinueTarget();
|
|
|
|
inner_loop_builder.JumpToHeader(1);
|
2017-08-15 15:17:58 +00:00
|
|
|
expected_liveness.emplace_back(".L..", ".L..");
|
2016-12-05 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loop_builder.BindContinueTarget();
|
|
|
|
loop_builder.JumpToHeader(0);
|
|
|
|
expected_liveness.emplace_back("LL..", "LL..");
|
|
|
|
}
|
|
|
|
|
2017-08-15 15:17:58 +00:00
|
|
|
builder.LoadUndefined();
|
|
|
|
expected_liveness.emplace_back("....", "...L");
|
2016-12-05 10:47:38 +00:00
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:46:53 +00:00
|
|
|
TEST_F(BytecodeAnalysisTest, SuspendPoint) {
|
|
|
|
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
|
|
|
|
std::vector<std::pair<std::string, std::string>> expected_liveness;
|
|
|
|
|
|
|
|
interpreter::Register reg_0(0);
|
|
|
|
interpreter::Register reg_1(1);
|
|
|
|
interpreter::Register reg_gen(2);
|
|
|
|
interpreter::BytecodeJumpTable* gen_jump_table =
|
|
|
|
builder.AllocateJumpTable(1, 0);
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_gen);
|
|
|
|
expected_liveness.emplace_back("L..L", "L.LL");
|
|
|
|
|
|
|
|
// Note: technically, r0 should be dead here since the resume will write it,
|
|
|
|
// but in practice the bytecode analysis doesn't bother to special case it,
|
|
|
|
// since the generator switch is close to the top of the function anyway.
|
|
|
|
builder.SwitchOnGeneratorState(reg_gen, gen_jump_table);
|
|
|
|
expected_liveness.emplace_back("L.LL", "L.LL");
|
|
|
|
|
|
|
|
builder.StoreAccumulatorInRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("..LL", "L.LL");
|
|
|
|
|
|
|
|
// Reg 1 is never read, so should be dead.
|
|
|
|
builder.StoreAccumulatorInRegister(reg_1);
|
|
|
|
expected_liveness.emplace_back("L.LL", "L.LL");
|
|
|
|
|
|
|
|
builder.SuspendGenerator(
|
|
|
|
reg_gen, interpreter::BytecodeUtils::NewRegisterList(0, 3), 0);
|
|
|
|
expected_liveness.emplace_back("L.LL", "L.L.");
|
|
|
|
|
|
|
|
builder.Bind(gen_jump_table, 0);
|
|
|
|
|
|
|
|
builder.ResumeGenerator(reg_gen,
|
|
|
|
interpreter::BytecodeUtils::NewRegisterList(0, 1));
|
|
|
|
expected_liveness.emplace_back("L.L.", "L...");
|
|
|
|
|
|
|
|
builder.LoadAccumulatorWithRegister(reg_0);
|
|
|
|
expected_liveness.emplace_back("L...", "...L");
|
|
|
|
|
|
|
|
builder.Return();
|
|
|
|
expected_liveness.emplace_back("...L", "....");
|
|
|
|
|
|
|
|
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
|
|
|
|
|
|
|
|
EnsureLivenessMatches(bytecode, expected_liveness);
|
|
|
|
}
|
|
|
|
|
2016-12-05 10:47:38 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|