Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: src/interpreter/bytecode-array-builder.cc

Issue 1426913002: [Interpreter] Merges ToBoolean and JumpIfTrue/False bytecodes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Last patch was not complete. Forgot few changes. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-array-builder.cc
diff --git a/src/interpreter/bytecode-array-builder.cc b/src/interpreter/bytecode-array-builder.cc
index 2ce9d51377571c58f027bc3e3f07ff983e4e0eee..03330ea2c7b5885abdd7094531d518feb15a2588 100644
--- a/src/interpreter/bytecode-array-builder.cc
+++ b/src/interpreter/bytecode-array-builder.cc
@@ -450,33 +450,43 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) {
}
+bool BytecodeArrayBuilder::IsAccumulatorBoolean() {
+ if (!LastBytecodeInSameBlock()) {
+ // If the previous bytecode was from a different block return false.
+ return false;
+ }
+
+ // If the previous bytecode puts a boolean in
+ // the accumulator return true.
rmcilroy 2015/10/30 10:36:00 nit - put comment on one line (or as much of it as
mythria 2015/10/30 11:44:47 Done.
+ switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) {
+ case Bytecode::kToBoolean:
+ UNREACHABLE();
+ case Bytecode::kLdaTrue:
+ case Bytecode::kLdaFalse:
+ case Bytecode::kLogicalNot:
+ case Bytecode::kTestEqual:
+ case Bytecode::kTestNotEqual:
+ case Bytecode::kTestEqualStrict:
+ case Bytecode::kTestNotEqualStrict:
+ case Bytecode::kTestLessThan:
+ case Bytecode::kTestLessThanOrEqual:
+ case Bytecode::kTestGreaterThan:
+ case Bytecode::kTestGreaterThanOrEqual:
+ case Bytecode::kTestInstanceOf:
+ case Bytecode::kTestIn:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() {
- if (LastBytecodeInSameBlock()) {
- // If the previous bytecode puts a boolean in the accumulator
- // there is no need to emit an instruction.
- switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) {
- case Bytecode::kToBoolean:
- UNREACHABLE();
- case Bytecode::kLdaTrue:
- case Bytecode::kLdaFalse:
- case Bytecode::kLogicalNot:
- case Bytecode::kTestEqual:
- case Bytecode::kTestNotEqual:
- case Bytecode::kTestEqualStrict:
- case Bytecode::kTestNotEqualStrict:
- case Bytecode::kTestLessThan:
- case Bytecode::kTestLessThanOrEqual:
- case Bytecode::kTestGreaterThan:
- case Bytecode::kTestGreaterThanOrEqual:
- case Bytecode::kTestInstanceOf:
- case Bytecode::kTestIn:
- return *this;
- default:
- // Fall through to output kToBoolean.
- break;
- }
+ // If the previous bytecode puts a boolean in the accumulator
+ // there is no need to emit an instruction.
+ if (!IsAccumulatorBoolean()) {
+ Output(Bytecode::kToBoolean);
}
- Output(Bytecode::kToBoolean);
return *this;
}
@@ -573,8 +583,29 @@ void BytecodeArrayBuilder::PatchJump(
}
+// static
+Bytecode BytecodeArrayBuilder::GetJumpWithToBoolean(Bytecode jump_bytecode) {
+ switch (jump_bytecode) {
+ case Bytecode::kJump:
+ return Bytecode::kJump;
+ case Bytecode::kJumpIfTrue:
+ return Bytecode::kJumpIfToBooleanTrue;
+ case Bytecode::kJumpIfFalse:
+ return Bytecode::kJumpIfToBooleanFalse;
+ default:
+ UNREACHABLE();
+ }
rmcilroy 2015/10/30 10:36:00 You probably need to return return static_cast<Byt
mythria 2015/10/30 11:44:47 Done.
+}
+
+
BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode,
BytecodeLabel* label) {
+ // Check if the value in accumulator is boolean, if not choose an
+ // appropriate JumpIfToBoolean bytecode.
+ if (!IsAccumulatorBoolean()) {
+ jump_bytecode = GetJumpWithToBoolean(jump_bytecode);
+ }
+
int delta;
if (label->is_bound()) {
// Label has been bound already so this is a backwards jump.
@@ -619,18 +650,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(BytecodeLabel* label) {
}
-BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanTrue(
- BytecodeLabel* label) {
- return OutputJump(Bytecode::kJumpIfToBooleanTrue, label);
-}
-
-
-BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse(
- BytecodeLabel* label) {
- return OutputJump(Bytecode::kJumpIfToBooleanFalse, label);
-}
-
-
BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() {
Output(Bytecode::kThrow);
exit_seen_in_block_ = true;

Powered by Google App Engine
This is Rietveld 408576698