| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/jump-threading.h" | 5 #include "src/compiler/jump-threading.h" |
| 6 #include "src/compiler/code-generator-impl.h" | 6 #include "src/compiler/code-generator-impl.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 namespace internal { | 9 namespace internal { |
| 10 namespace compiler { | 10 namespace compiler { |
| 11 | 11 |
| 12 typedef BasicBlock::RpoNumber RpoNumber; | |
| 13 | |
| 14 #define TRACE(x) \ | 12 #define TRACE(x) \ |
| 15 if (FLAG_trace_turbo_jt) PrintF x | 13 if (FLAG_trace_turbo_jt) PrintF x |
| 16 | 14 |
| 17 struct JumpThreadingState { | 15 struct JumpThreadingState { |
| 18 bool forwarded; | 16 bool forwarded; |
| 19 ZoneVector<RpoNumber>& result; | 17 ZoneVector<RpoNumber>& result; |
| 20 ZoneStack<RpoNumber>& stack; | 18 ZoneStack<RpoNumber>& stack; |
| 21 | 19 |
| 22 void Clear(size_t count) { result.assign(count, unvisited()); } | 20 void Clear(size_t count) { result.assign(count, unvisited()); } |
| 23 void PushIfUnvisited(RpoNumber num) { | 21 void PushIfUnvisited(RpoNumber num) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 61 |
| 64 // Iterate over the blocks forward, pushing the blocks onto the stack. | 62 // Iterate over the blocks forward, pushing the blocks onto the stack. |
| 65 for (auto const block : code->instruction_blocks()) { | 63 for (auto const block : code->instruction_blocks()) { |
| 66 RpoNumber current = block->rpo_number(); | 64 RpoNumber current = block->rpo_number(); |
| 67 state.PushIfUnvisited(current); | 65 state.PushIfUnvisited(current); |
| 68 | 66 |
| 69 // Process the stack, which implements DFS through empty blocks. | 67 // Process the stack, which implements DFS through empty blocks. |
| 70 while (!state.stack.empty()) { | 68 while (!state.stack.empty()) { |
| 71 InstructionBlock* block = code->InstructionBlockAt(state.stack.top()); | 69 InstructionBlock* block = code->InstructionBlockAt(state.stack.top()); |
| 72 // Process the instructions in a block up to a non-empty instruction. | 70 // Process the instructions in a block up to a non-empty instruction. |
| 73 TRACE(("jt [%d] B%d RPO%d\n", static_cast<int>(stack.size()), | 71 TRACE(("jt [%d] B%d\n", static_cast<int>(stack.size()), |
| 74 block->id().ToInt(), block->rpo_number().ToInt())); | 72 block->rpo_number().ToInt())); |
| 75 bool fallthru = true; | 73 bool fallthru = true; |
| 76 RpoNumber fw = block->rpo_number(); | 74 RpoNumber fw = block->rpo_number(); |
| 77 for (int i = block->code_start(); i < block->code_end(); ++i) { | 75 for (int i = block->code_start(); i < block->code_end(); ++i) { |
| 78 Instruction* instr = code->InstructionAt(i); | 76 Instruction* instr = code->InstructionAt(i); |
| 79 if (instr->IsGapMoves() && GapInstruction::cast(instr)->IsRedundant()) { | 77 if (instr->IsGapMoves() && GapInstruction::cast(instr)->IsRedundant()) { |
| 80 // skip redundant gap moves. | 78 // skip redundant gap moves. |
| 81 TRACE((" nop gap\n")); | 79 TRACE((" nop gap\n")); |
| 82 continue; | 80 continue; |
| 83 } else if (instr->IsSourcePosition()) { | 81 } else if (instr->IsSourcePosition()) { |
| 84 // skip source positions. | 82 // skip source positions. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 113 } | 111 } |
| 114 | 112 |
| 115 #ifdef DEBUG | 113 #ifdef DEBUG |
| 116 for (RpoNumber num : result) { | 114 for (RpoNumber num : result) { |
| 117 CHECK(num.IsValid()); | 115 CHECK(num.IsValid()); |
| 118 } | 116 } |
| 119 #endif | 117 #endif |
| 120 | 118 |
| 121 if (FLAG_trace_turbo_jt) { | 119 if (FLAG_trace_turbo_jt) { |
| 122 for (int i = 0; i < static_cast<int>(result.size()); i++) { | 120 for (int i = 0; i < static_cast<int>(result.size()); i++) { |
| 123 TRACE(("RPO%d B%d ", i, | 121 TRACE(("B%d ", i)); |
| 124 code->InstructionBlockAt(RpoNumber::FromInt(i))->id().ToInt())); | |
| 125 int to = result[i].ToInt(); | 122 int to = result[i].ToInt(); |
| 126 if (i != to) { | 123 if (i != to) { |
| 127 TRACE(("-> B%d\n", | 124 TRACE(("-> B%d\n", to)); |
| 128 code->InstructionBlockAt(RpoNumber::FromInt(to))->id().ToInt())); | |
| 129 } else { | 125 } else { |
| 130 TRACE(("\n")); | 126 TRACE(("\n")); |
| 131 } | 127 } |
| 132 } | 128 } |
| 133 } | 129 } |
| 134 | 130 |
| 135 return state.forwarded; | 131 return state.forwarded; |
| 136 } | 132 } |
| 137 | 133 |
| 138 | 134 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (block->IsDeferred()) { | 185 if (block->IsDeferred()) { |
| 190 block->set_ao_number(RpoNumber::FromInt(ao)); | 186 block->set_ao_number(RpoNumber::FromInt(ao)); |
| 191 if (!skip[block->rpo_number().ToInt()]) ao++; | 187 if (!skip[block->rpo_number().ToInt()]) ao++; |
| 192 } | 188 } |
| 193 } | 189 } |
| 194 } | 190 } |
| 195 | 191 |
| 196 } // namespace compiler | 192 } // namespace compiler |
| 197 } // namespace internal | 193 } // namespace internal |
| 198 } // namespace v8 | 194 } // namespace v8 |
| OLD | NEW |