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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/raw-machine-assembler.h ('k') | src/compiler/schedule.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/raw-machine-assembler.cc
diff --git a/src/compiler/raw-machine-assembler.cc b/src/compiler/raw-machine-assembler.cc
index 562f77d1445d9385eff6ccc2d0bf8c732940f030..489c2ca6d9c26b0bb002c2224535c6d2b38dc21e 100644
--- a/src/compiler/raw-machine-assembler.cc
+++ b/src/compiler/raw-machine-assembler.cc
@@ -76,15 +76,26 @@ void RawMachineAssembler::Branch(Node* condition, Label* true_val,
}
-void RawMachineAssembler::Switch(Node* index, Label** succ_labels,
- size_t succ_count) {
+void RawMachineAssembler::Switch(Node* index, Label* default_label,
+ int32_t* case_values, Label** case_labels,
+ size_t case_count) {
DCHECK_NE(schedule()->end(), current_block_);
- Node* sw = NewNode(common()->Switch(succ_count), index);
+ size_t succ_count = case_count + 1;
+ Node* switch_node = NewNode(common()->Switch(succ_count), index);
BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
- for (size_t index = 0; index < succ_count; ++index) {
- succ_blocks[index] = Use(succ_labels[index]);
+ for (size_t index = 0; index < case_count; ++index) {
+ int32_t case_value = case_values[index];
+ BasicBlock* case_block = Use(case_labels[index]);
+ Node* case_node =
+ graph()->NewNode(common()->IfValue(case_value), switch_node);
+ schedule()->AddNode(case_block, case_node);
+ succ_blocks[index] = case_block;
}
- schedule()->AddSwitch(CurrentBlock(), sw, succ_blocks, succ_count);
+ BasicBlock* default_block = Use(default_label);
+ Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
+ schedule()->AddNode(default_block, default_node);
+ succ_blocks[case_count] = default_block;
+ schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
current_block_ = nullptr;
}
« 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