Commit 3b6773ba authored by mythria's avatar mythria Committed by Commit bot

[Interpreter] Removes ToBoolean bytecode.

ToBoolean was used with conditional jumps. An earlier cl
(https://codereview.chromium.org/1426913002/) merges jumps
and ToBoolean into a single bytecode. So, we no longer need
ToBoolean bytecode.

BUG=v8:4280
LOG=N

Review URL: https://codereview.chromium.org/1507683005

Cr-Commit-Position: refs/heads/master@{#32707}
parent 8ad016d3
......@@ -1092,12 +1092,6 @@ void BytecodeGraphBuilder::BuildCastOperator(
}
void BytecodeGraphBuilder::VisitToBoolean(
const interpreter::BytecodeArrayIterator& iterator) {
BuildCastOperator(javascript()->ToBoolean(ToBooleanHint::kAny), iterator);
}
void BytecodeGraphBuilder::VisitToName(
const interpreter::BytecodeArrayIterator& iterator) {
BuildCastOperator(javascript()->ToName(), iterator);
......
......@@ -593,8 +593,6 @@ bool BytecodeArrayBuilder::NeedToBooleanCast() {
}
PreviousBytecodeHelper previous_bytecode(*this);
switch (previous_bytecode.GetBytecode()) {
case Bytecode::kToBoolean:
UNREACHABLE();
// If the previous bytecode puts a boolean in the accumulator return true.
case Bytecode::kLdaTrue:
case Bytecode::kLdaFalse:
......@@ -617,38 +615,6 @@ bool BytecodeArrayBuilder::NeedToBooleanCast() {
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() {
if (!LastBytecodeInSameBlock()) {
Output(Bytecode::kToBoolean);
return *this;
}
// If the previous bytecode puts a boolean in the accumulator
// there is no need to emit an instruction.
if (NeedToBooleanCast()) {
PreviousBytecodeHelper previous_bytecode(*this);
switch (previous_bytecode.GetBytecode()) {
// If the previous bytecode is a constant evaluate it and return false.
case Bytecode::kLdaZero: {
LoadFalse();
break;
}
case Bytecode::kLdaSmi8: {
LoadBooleanConstant(previous_bytecode.GetOperand(0) != 0);
break;
}
case Bytecode::kLdaConstant: {
Handle<Object> object = previous_bytecode.GetConstantForIndexOperand(0);
LoadBooleanConstant(object->BooleanValue());
break;
}
default:
Output(Bytecode::kToBoolean);
}
}
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() {
Output(Bytecode::kToObject);
return *this;
......
......@@ -150,7 +150,6 @@ namespace interpreter {
V(TestIn, OperandType::kReg8) \
\
/* Cast operators */ \
V(ToBoolean, OperandType::kNone) \
V(ToName, OperandType::kNone) \
V(ToNumber, OperandType::kNone) \
V(ToObject, OperandType::kNone) \
......
......@@ -1074,17 +1074,6 @@ void Interpreter::DoTestInstanceOf(compiler::InterpreterAssembler* assembler) {
}
// ToBoolean
//
// Cast the object referenced by the accumulator to a boolean.
void Interpreter::DoToBoolean(compiler::InterpreterAssembler* assembler) {
Node* accumulator = __ GetAccumulator();
Node* result = __ CallRuntime(Runtime::kInterpreterToBoolean, accumulator);
__ SetAccumulator(result);
__ Dispatch();
}
// ToName
//
// Cast the object referenced by the accumulator to a name.
......
......@@ -1562,43 +1562,6 @@ static void LoadAny(BytecodeArrayBuilder* builder,
}
TEST(InterpreterToBoolean) {
HandleAndZoneScope handles;
i::Factory* factory = handles.main_isolate()->factory();
std::pair<Handle<Object>, bool> object_type_tuples[] = {
std::make_pair(factory->undefined_value(), false),
std::make_pair(factory->null_value(), false),
std::make_pair(factory->false_value(), false),
std::make_pair(factory->true_value(), true),
std::make_pair(factory->NewNumber(9.1), true),
std::make_pair(factory->NewNumberFromInt(0), false),
std::make_pair(
Handle<Object>::cast(factory->NewStringFromStaticChars("hello")),
true),
std::make_pair(
Handle<Object>::cast(factory->NewStringFromStaticChars("")), false),
};
for (size_t i = 0; i < arraysize(object_type_tuples); i++) {
BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
Register r0(0);
builder.set_locals_count(0);
builder.set_context_count(0);
builder.set_parameter_count(0);
LoadAny(&builder, factory, object_type_tuples[i].first);
builder.CastAccumulatorToBoolean();
builder.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
InterpreterTester tester(handles.main_isolate(), bytecode_array);
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK(return_value->IsBoolean());
CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second);
}
}
TEST(InterpreterUnaryNotNonBoolean) {
HandleAndZoneScope handles;
i::Factory* factory = handles.main_isolate()->factory();
......
......@@ -159,7 +159,6 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Emit cast operator invocations.
builder.CastAccumulatorToNumber()
.CastAccumulatorToBoolean()
.CastAccumulatorToJSObject()
.CastAccumulatorToName();
......@@ -658,68 +657,6 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
CHECK(iterator.done());
}
TEST_F(BytecodeArrayBuilderTest, ToBoolean) {
BytecodeArrayBuilder builder(isolate(), zone());
builder.set_parameter_count(0);
builder.set_locals_count(0);
builder.set_context_count(0);
// Check ToBoolean emitted at start of a basic block.
builder.CastAccumulatorToBoolean();
// Check ToBoolean emitted preceding bytecode is non-boolean.
builder.LoadNull().CastAccumulatorToBoolean();
// Check ToBoolean omitted if preceding bytecode is boolean.
builder.LoadFalse().CastAccumulatorToBoolean();
// Check ToBoolean emitted if it is at the start of a basic block caused by a
// bound label.
BytecodeLabel label;
builder.LoadFalse()
.Bind(&label)
.CastAccumulatorToBoolean();
// Check ToBoolean emitted if it is at the start of a basic block caused by a
// jump.
builder.LoadFalse()
.JumpIfTrue(&label)
.CastAccumulatorToBoolean();
builder.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaNull);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
iterator.Advance();
CHECK(iterator.done());
}
} // namespace interpreter
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment