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

Unified Diff: src/compiler/ppc/instruction-selector-ppc.cc

Issue 1019803005: [turbofan] Factor out common switch-related code in instruction selectors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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/mips64/instruction-selector-mips64.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/ppc/instruction-selector-ppc.cc
diff --git a/src/compiler/ppc/instruction-selector-ppc.cc b/src/compiler/ppc/instruction-selector-ppc.cc
index 8a384f6fafa91b862a792cb375438fc46db74de1..ae4c97a9ee5ad79329da5dadcfa29dd4da72a44a 100644
--- a/src/compiler/ppc/instruction-selector-ppc.cc
+++ b/src/compiler/ppc/instruction-selector-ppc.cc
@@ -1249,62 +1249,31 @@ void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
}
-void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch,
- BasicBlock** case_branches,
- int32_t* case_values, size_t case_count,
- int32_t min_value, int32_t max_value) {
+void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) {
PPCOperandGenerator g(this);
InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
- InstructionOperand default_operand = g.Label(default_branch);
- // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value}
- // is 2^31-1, so don't assume that it's non-zero below.
- size_t value_range =
- 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
-
- // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
- // instruction.
- size_t table_space_cost = 4 + value_range;
+ // Emit either ArchTableSwitch or ArchLookupSwitch.
+ size_t table_space_cost = 4 + sw.value_range;
size_t table_time_cost = 3;
- size_t lookup_space_cost = 3 + 2 * case_count;
- size_t lookup_time_cost = case_count;
- if (case_count > 0 &&
+ size_t lookup_space_cost = 3 + 2 * sw.case_count;
+ size_t lookup_time_cost = sw.case_count;
+ if (sw.case_count > 0 &&
table_space_cost + 3 * table_time_cost <=
lookup_space_cost + 3 * lookup_time_cost &&
- min_value > std::numeric_limits<int32_t>::min()) {
+ sw.min_value > std::numeric_limits<int32_t>::min()) {
InstructionOperand index_operand = value_operand;
- if (min_value) {
+ if (sw.min_value) {
index_operand = g.TempRegister();
Emit(kPPC_Sub32, index_operand, value_operand,
- g.TempImmediate(min_value));
- }
- size_t input_count = 2 + value_range;
- auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
- inputs[0] = index_operand;
- std::fill(&inputs[1], &inputs[input_count], default_operand);
- for (size_t index = 0; index < case_count; ++index) {
- size_t value = case_values[index] - min_value;
- BasicBlock* branch = case_branches[index];
- DCHECK_LE(0u, value);
- DCHECK_LT(value + 2, input_count);
- inputs[value + 2] = g.Label(branch);
+ g.TempImmediate(sw.min_value));
}
- Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
- return;
+ // Generate a table lookup.
+ return EmitTableSwitch(sw, index_operand);
}
// Generate a sequence of conditional jumps.
- size_t input_count = 2 + case_count * 2;
- auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
- inputs[0] = value_operand;
- inputs[1] = default_operand;
- for (size_t index = 0; index < case_count; ++index) {
- int32_t value = case_values[index];
- BasicBlock* branch = case_branches[index];
- inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
- inputs[index * 2 + 2 + 1] = g.Label(branch);
- }
- Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
+ return EmitLookupSwitch(sw, value_operand);
}
« no previous file with comments | « src/compiler/mips64/instruction-selector-mips64.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698