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

Side by Side Diff: src/compiler/raw-machine-assembler.cc

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addrssed comments. Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/compiler/raw-machine-assembler.h ('k') | src/compiler/schedule.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/compiler/pipeline.h" 6 #include "src/compiler/pipeline.h"
7 #include "src/compiler/raw-machine-assembler.h" 7 #include "src/compiler/raw-machine-assembler.h"
8 #include "src/compiler/scheduler.h" 8 #include "src/compiler/scheduler.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 void RawMachineAssembler::Branch(Node* condition, Label* true_val, 70 void RawMachineAssembler::Branch(Node* condition, Label* true_val,
71 Label* false_val) { 71 Label* false_val) {
72 DCHECK(current_block_ != schedule()->end()); 72 DCHECK(current_block_ != schedule()->end());
73 Node* branch = NewNode(common()->Branch(), condition); 73 Node* branch = NewNode(common()->Branch(), condition);
74 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val)); 74 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
75 current_block_ = NULL; 75 current_block_ = NULL;
76 } 76 }
77 77
78 78
79 void RawMachineAssembler::Switch(Node* index, Label** succ_labels, 79 void RawMachineAssembler::Switch(Node* index, Label* default_label,
80 size_t succ_count) { 80 int32_t* case_values, Label** case_labels,
81 size_t case_count) {
81 DCHECK_NE(schedule()->end(), current_block_); 82 DCHECK_NE(schedule()->end(), current_block_);
82 Node* sw = NewNode(common()->Switch(succ_count), index); 83 size_t succ_count = case_count + 1;
84 Node* switch_node = NewNode(common()->Switch(succ_count), index);
83 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count); 85 BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
84 for (size_t index = 0; index < succ_count; ++index) { 86 for (size_t index = 0; index < case_count; ++index) {
85 succ_blocks[index] = Use(succ_labels[index]); 87 int32_t case_value = case_values[index];
88 BasicBlock* case_block = Use(case_labels[index]);
89 Node* case_node =
90 graph()->NewNode(common()->IfValue(case_value), switch_node);
91 schedule()->AddNode(case_block, case_node);
92 succ_blocks[index] = case_block;
86 } 93 }
87 schedule()->AddSwitch(CurrentBlock(), sw, succ_blocks, succ_count); 94 BasicBlock* default_block = Use(default_label);
95 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
96 schedule()->AddNode(default_block, default_node);
97 succ_blocks[case_count] = default_block;
98 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
88 current_block_ = nullptr; 99 current_block_ = nullptr;
89 } 100 }
90 101
91 102
92 void RawMachineAssembler::Return(Node* value) { 103 void RawMachineAssembler::Return(Node* value) {
93 schedule()->AddReturn(CurrentBlock(), value); 104 schedule()->AddReturn(CurrentBlock(), value);
94 current_block_ = NULL; 105 current_block_ = NULL;
95 } 106 }
96 107
97 108
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 Node* node = graph()->NewNode(op, input_count, inputs, incomplete); 183 Node* node = graph()->NewNode(op, input_count, inputs, incomplete);
173 BasicBlock* block = op->opcode() == IrOpcode::kParameter ? schedule()->start() 184 BasicBlock* block = op->opcode() == IrOpcode::kParameter ? schedule()->start()
174 : CurrentBlock(); 185 : CurrentBlock();
175 schedule()->AddNode(block, node); 186 schedule()->AddNode(block, node);
176 return node; 187 return node;
177 } 188 }
178 189
179 } // namespace compiler 190 } // namespace compiler
180 } // namespace internal 191 } // namespace internal
181 } // namespace v8 192 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/raw-machine-assembler.h ('k') | src/compiler/schedule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698