From fe57faa2e0349418dda38e77ef1c0ac29db75f4d Mon Sep 17 00:00:00 2001 From: Mark Mendell Date: Fri, 18 Sep 2015 09:26:15 -0400 Subject: [optimizing] Add basic PackedSwitch support Add HPackedSwitch, and generate it from the builder. Code generators convert this to a series of compare/branch tests. Better implementation in the code generators as a real jump table will follow as separate CLs. Change-Id: If14736fa4d62809b6ae95280148c55682e856911 Signed-off-by: Mark Mendell --- compiler/optimizing/dead_code_elimination.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'compiler/optimizing/dead_code_elimination.cc') diff --git a/compiler/optimizing/dead_code_elimination.cc b/compiler/optimizing/dead_code_elimination.cc index 7d509a22a6..345ff72148 100644 --- a/compiler/optimizing/dead_code_elimination.cc +++ b/compiler/optimizing/dead_code_elimination.cc @@ -41,6 +41,21 @@ static void MarkReachableBlocks(HBasicBlock* block, ArenaBitVector* visited) { DCHECK(condition->AsIntConstant()->IsZero()); MarkReachableBlocks(if_instruction->IfFalseSuccessor(), visited); } + } else if (last_instruction->IsPackedSwitch() && + last_instruction->AsPackedSwitch()->InputAt(0)->IsIntConstant()) { + HPackedSwitch* switch_instruction = last_instruction->AsPackedSwitch(); + int32_t switch_value = switch_instruction->InputAt(0)->AsIntConstant()->GetValue(); + int32_t start_value = switch_instruction->GetStartValue(); + int32_t last_value = start_value + switch_instruction->GetNumEntries(); + for (int32_t case_value = start_value; case_value <= last_value; case_value++) { + if (case_value == last_value) { + MarkReachableBlocks(switch_instruction->GetDefaultBlock(), visited); + } + if (case_value == switch_value) { + MarkReachableBlocks(block->GetSuccessor(case_value - start_value), visited); + break; + } + } } else { for (HBasicBlock* successor : block->GetSuccessors()) { MarkReachableBlocks(successor, visited); -- cgit v1.2.3-59-g8ed1b