| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/factory.h" | 7 #include "src/factory.h" |
| 8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
| 9 #include "src/interpreter/bytecode-register-optimizer.h" | 9 #include "src/interpreter/bytecode-register-optimizer.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Sanity tests. | 63 // Sanity tests. |
| 64 | 64 |
| 65 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForFlush) { | 65 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForFlush) { |
| 66 Initialize(1, 1); | 66 Initialize(1, 1); |
| 67 Register temp = NewTemporary(); | 67 Register temp = NewTemporary(); |
| 68 optimizer()->DoStar(temp, BytecodeSourceInfo()); | 68 optimizer()->DoStar(temp, BytecodeSourceInfo()); |
| 69 CHECK_EQ(write_count(), 0); | 69 CHECK_EQ(write_count(), 0); |
| 70 optimizer()->Flush(); | 70 optimizer()->Flush(); |
| 71 CHECK_EQ(write_count(), 1); | 71 CHECK_EQ(write_count(), 1); |
| 72 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 72 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
| 73 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); | 73 CHECK_EQ(output()->at(0).operand(0), static_cast<uint32_t>(temp.ToOperand())); |
| 74 } | 74 } |
| 75 | 75 |
| 76 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) { | 76 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) { |
| 77 Initialize(1, 1); | 77 Initialize(1, 1); |
| 78 Register temp = NewTemporary(); | 78 Register temp = NewTemporary(); |
| 79 optimizer()->DoStar(temp, BytecodeSourceInfo()); | 79 optimizer()->DoStar(temp, BytecodeSourceInfo()); |
| 80 CHECK_EQ(write_count(), 0); | 80 CHECK_EQ(write_count(), 0); |
| 81 optimizer()->PrepareForBytecode(Bytecode::kJump); | 81 optimizer()->PrepareForBytecode(Bytecode::kJump); |
| 82 CHECK_EQ(write_count(), 1); | 82 CHECK_EQ(write_count(), 1); |
| 83 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 83 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
| 84 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); | 84 CHECK_EQ(output()->at(0).operand(0), static_cast<uint32_t>(temp.ToOperand())); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Basic Register Optimizations | 87 // Basic Register Optimizations |
| 88 | 88 |
| 89 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) { | 89 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) { |
| 90 Initialize(3, 1); | 90 Initialize(3, 1); |
| 91 Register parameter = Register::FromParameterIndex(1, 3); | 91 Register parameter = Register::FromParameterIndex(1, 3); |
| 92 optimizer()->DoLdar(parameter, BytecodeSourceInfo()); | 92 optimizer()->DoLdar(parameter, BytecodeSourceInfo()); |
| 93 CHECK_EQ(write_count(), 0); | 93 CHECK_EQ(write_count(), 0); |
| 94 Register temp = NewTemporary(); | 94 Register temp = NewTemporary(); |
| 95 optimizer()->DoStar(temp, BytecodeSourceInfo()); | 95 optimizer()->DoStar(temp, BytecodeSourceInfo()); |
| 96 BytecodeNode node1(Bytecode::kStar, NewTemporary().ToOperand()); | 96 BytecodeNode node1(Bytecode::kStar, NewTemporary().ToOperand()); |
| 97 ReleaseTemporaries(temp); | 97 ReleaseTemporaries(temp); |
| 98 CHECK_EQ(write_count(), 0); | 98 CHECK_EQ(write_count(), 0); |
| 99 optimizer()->PrepareForBytecode(Bytecode::kReturn); | 99 optimizer()->PrepareForBytecode(Bytecode::kReturn); |
| 100 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdar); | 100 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdar); |
| 101 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); | 101 CHECK_EQ(output()->at(0).operand(0), |
| 102 static_cast<uint32_t>(parameter.ToOperand())); |
| 102 } | 103 } |
| 103 | 104 |
| 104 TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) { | 105 TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) { |
| 105 Initialize(3, 1); | 106 Initialize(3, 1); |
| 106 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); | 107 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); |
| 107 Register temp0 = NewTemporary(); | 108 Register temp0 = NewTemporary(); |
| 108 Register temp1 = NewTemporary(); | 109 Register temp1 = NewTemporary(); |
| 109 optimizer()->DoStar(temp1, BytecodeSourceInfo()); | 110 optimizer()->DoStar(temp1, BytecodeSourceInfo()); |
| 110 CHECK_EQ(write_count(), 0); | 111 CHECK_EQ(write_count(), 0); |
| 111 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); | 112 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); |
| 112 CHECK_EQ(write_count(), 1); | 113 CHECK_EQ(write_count(), 1); |
| 113 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 114 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
| 114 CHECK_EQ(output()->at(0).operand(0), temp1.ToOperand()); | 115 CHECK_EQ(output()->at(0).operand(0), |
| 116 static_cast<uint32_t>(temp1.ToOperand())); |
| 115 optimizer()->DoMov(temp1, temp0, BytecodeSourceInfo()); | 117 optimizer()->DoMov(temp1, temp0, BytecodeSourceInfo()); |
| 116 CHECK_EQ(write_count(), 1); | 118 CHECK_EQ(write_count(), 1); |
| 117 ReleaseTemporaries(temp1); | 119 ReleaseTemporaries(temp1); |
| 118 CHECK_EQ(write_count(), 1); | 120 CHECK_EQ(write_count(), 1); |
| 119 optimizer()->DoLdar(temp0, BytecodeSourceInfo()); | 121 optimizer()->DoLdar(temp0, BytecodeSourceInfo()); |
| 120 CHECK_EQ(write_count(), 1); | 122 CHECK_EQ(write_count(), 1); |
| 121 optimizer()->PrepareForBytecode(Bytecode::kReturn); | 123 optimizer()->PrepareForBytecode(Bytecode::kReturn); |
| 122 CHECK_EQ(write_count(), 2); | 124 CHECK_EQ(write_count(), 2); |
| 123 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); | 125 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); |
| 124 CHECK_EQ(output()->at(1).operand(0), temp1.ToOperand()); | 126 CHECK_EQ(output()->at(1).operand(0), |
| 127 static_cast<uint32_t>(temp1.ToOperand())); |
| 125 } | 128 } |
| 126 | 129 |
| 127 TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterNotFlushed) { | 130 TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterNotFlushed) { |
| 128 Initialize(3, 1); | 131 Initialize(3, 1); |
| 129 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); | 132 optimizer()->PrepareForBytecode(Bytecode::kLdaSmi); |
| 130 Register temp0 = NewTemporary(); | 133 Register temp0 = NewTemporary(); |
| 131 Register temp1 = NewTemporary(); | 134 Register temp1 = NewTemporary(); |
| 132 optimizer()->DoStar(temp0, BytecodeSourceInfo()); | 135 optimizer()->DoStar(temp0, BytecodeSourceInfo()); |
| 133 CHECK_EQ(write_count(), 0); | 136 CHECK_EQ(write_count(), 0); |
| 134 optimizer()->DoStar(temp1, BytecodeSourceInfo()); | 137 optimizer()->DoStar(temp1, BytecodeSourceInfo()); |
| 135 CHECK_EQ(write_count(), 0); | 138 CHECK_EQ(write_count(), 0); |
| 136 ReleaseTemporaries(temp1); | 139 ReleaseTemporaries(temp1); |
| 137 optimizer()->Flush(); | 140 optimizer()->Flush(); |
| 138 CHECK_EQ(write_count(), 1); | 141 CHECK_EQ(write_count(), 1); |
| 139 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 142 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
| 140 CHECK_EQ(output()->at(0).operand(0), temp0.ToOperand()); | 143 CHECK_EQ(output()->at(0).operand(0), |
| 144 static_cast<uint32_t>(temp0.ToOperand())); |
| 141 } | 145 } |
| 142 | 146 |
| 143 TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) { | 147 TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) { |
| 144 Initialize(3, 1); | 148 Initialize(3, 1); |
| 145 Register parameter = Register::FromParameterIndex(1, 3); | 149 Register parameter = Register::FromParameterIndex(1, 3); |
| 146 optimizer()->DoLdar(parameter, BytecodeSourceInfo()); | 150 optimizer()->DoLdar(parameter, BytecodeSourceInfo()); |
| 147 CHECK_EQ(write_count(), 0); | 151 CHECK_EQ(write_count(), 0); |
| 148 Register local = Register(0); | 152 Register local = Register(0); |
| 149 optimizer()->DoStar(local, BytecodeSourceInfo()); | 153 optimizer()->DoStar(local, BytecodeSourceInfo()); |
| 150 CHECK_EQ(write_count(), 1); | 154 CHECK_EQ(write_count(), 1); |
| 151 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kMov); | 155 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kMov); |
| 152 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); | 156 CHECK_EQ(output()->at(0).operand(0), |
| 153 CHECK_EQ(output()->at(0).operand(1), local.ToOperand()); | 157 static_cast<uint32_t>(parameter.ToOperand())); |
| 158 CHECK_EQ(output()->at(0).operand(1), |
| 159 static_cast<uint32_t>(local.ToOperand())); |
| 154 | 160 |
| 155 optimizer()->PrepareForBytecode(Bytecode::kReturn); | 161 optimizer()->PrepareForBytecode(Bytecode::kReturn); |
| 156 CHECK_EQ(write_count(), 2); | 162 CHECK_EQ(write_count(), 2); |
| 157 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); | 163 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); |
| 158 CHECK_EQ(output()->at(1).operand(0), local.ToOperand()); | 164 CHECK_EQ(output()->at(1).operand(0), |
| 165 static_cast<uint32_t>(local.ToOperand())); |
| 159 } | 166 } |
| 160 | 167 |
| 161 TEST_F(BytecodeRegisterOptimizerTest, SingleTemporaryNotMaterializedForInput) { | 168 TEST_F(BytecodeRegisterOptimizerTest, SingleTemporaryNotMaterializedForInput) { |
| 162 Initialize(3, 1); | 169 Initialize(3, 1); |
| 163 Register parameter = Register::FromParameterIndex(1, 3); | 170 Register parameter = Register::FromParameterIndex(1, 3); |
| 164 Register temp0 = NewTemporary(); | 171 Register temp0 = NewTemporary(); |
| 165 Register temp1 = NewTemporary(); | 172 Register temp1 = NewTemporary(); |
| 166 optimizer()->DoMov(parameter, temp0, BytecodeSourceInfo()); | 173 optimizer()->DoMov(parameter, temp0, BytecodeSourceInfo()); |
| 167 optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo()); | 174 optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo()); |
| 168 CHECK_EQ(write_count(), 0); | 175 CHECK_EQ(write_count(), 0); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo()); | 193 optimizer()->DoMov(parameter, temp1, BytecodeSourceInfo()); |
| 187 CHECK_EQ(write_count(), 0); | 194 CHECK_EQ(write_count(), 0); |
| 188 | 195 |
| 189 optimizer()->PrepareForBytecode(Bytecode::kCallJSRuntime); | 196 optimizer()->PrepareForBytecode(Bytecode::kCallJSRuntime); |
| 190 RegisterList reg_list = | 197 RegisterList reg_list = |
| 191 optimizer()->GetInputRegisterList(RegisterList(temp0.index(), 2)); | 198 optimizer()->GetInputRegisterList(RegisterList(temp0.index(), 2)); |
| 192 CHECK_EQ(temp0.index(), reg_list.first_register().index()); | 199 CHECK_EQ(temp0.index(), reg_list.first_register().index()); |
| 193 CHECK_EQ(2, reg_list.register_count()); | 200 CHECK_EQ(2, reg_list.register_count()); |
| 194 CHECK_EQ(write_count(), 2); | 201 CHECK_EQ(write_count(), 2); |
| 195 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 202 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
| 196 CHECK_EQ(output()->at(0).operand(0), temp0.ToOperand()); | 203 CHECK_EQ(output()->at(0).operand(0), |
| 204 static_cast<uint32_t>(temp0.ToOperand())); |
| 197 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kMov); | 205 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kMov); |
| 198 CHECK_EQ(output()->at(1).operand(0), parameter.ToOperand()); | 206 CHECK_EQ(output()->at(1).operand(0), |
| 199 CHECK_EQ(output()->at(1).operand(1), temp1.ToOperand()); | 207 static_cast<uint32_t>(parameter.ToOperand())); |
| 208 CHECK_EQ(output()->at(1).operand(1), |
| 209 static_cast<uint32_t>(temp1.ToOperand())); |
| 200 } | 210 } |
| 201 | 211 |
| 202 } // namespace interpreter | 212 } // namespace interpreter |
| 203 } // namespace internal | 213 } // namespace internal |
| 204 } // namespace v8 | 214 } // namespace v8 |
| OLD | NEW |