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

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

Issue 1435283002: [Interpreter] Adds an optimization to remove redundant Ldar/Star. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch Created 5 years, 1 month 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
« no previous file with comments | « src/interpreter/bytecode-array-builder.h ('k') | src/interpreter/bytecode-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-array-builder.cc
diff --git a/src/interpreter/bytecode-array-builder.cc b/src/interpreter/bytecode-array-builder.cc
index f2f5c07251e7dfa8fd3b1d9558efe25fa3c85f44..e57a4fd6ad8853a4b305c4da7864bf0a5a099f0d 100644
--- a/src/interpreter/bytecode-array-builder.cc
+++ b/src/interpreter/bytecode-array-builder.cc
@@ -271,18 +271,18 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::LoadFalse() {
BytecodeArrayBuilder& BytecodeArrayBuilder::LoadAccumulatorWithRegister(
Register reg) {
- // TODO(oth): Avoid loading the accumulator with the register if the
- // previous bytecode stored the accumulator with the same register.
- Output(Bytecode::kLdar, reg.ToOperand());
+ if (!IsRegisterInAccumulator(reg)) {
+ Output(Bytecode::kLdar, reg.ToOperand());
+ }
return *this;
}
BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister(
Register reg) {
- // TODO(oth): Avoid storing the accumulator in the register if the
- // previous bytecode loaded the accumulator with the same register.
- Output(Bytecode::kStar, reg.ToOperand());
+ if (!IsRegisterInAccumulator(reg)) {
+ Output(Bytecode::kStar, reg.ToOperand());
+ }
return *this;
}
@@ -952,12 +952,29 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
return false;
}
+
bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const {
return last_bytecode_start_ < bytecodes()->size() &&
last_bytecode_start_ >= last_block_end_;
}
+bool BytecodeArrayBuilder::IsRegisterInAccumulator(Register reg) {
+ if (!LastBytecodeInSameBlock()) return false;
+ Bytecode previous_bytecode =
+ Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_));
+ if (previous_bytecode == Bytecode::kLdar ||
+ previous_bytecode == Bytecode::kStar) {
+ size_t operand_offset = last_bytecode_start_ +
+ Bytecodes::GetOperandOffset(previous_bytecode, 0);
+ if (reg == Register::FromOperand(bytecodes()->at(operand_offset))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
// static
Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) {
switch (op) {
« no previous file with comments | « src/interpreter/bytecode-array-builder.h ('k') | src/interpreter/bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698