Address HPackedSwitch issues raised after merge

There were some stylistic comments about the merged files.  Fix those.

Add a test that PackedSwitch can be removed by DCE.

Change-Id: Idf45833956e9b58051f942a52b06a1e416606e2e
Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc
index e19e74f..7ae405a 100644
--- a/compiler/optimizing/builder.cc
+++ b/compiler/optimizing/builder.cc
@@ -1693,8 +1693,14 @@
   } else {
     // Chained cmp-and-branch, starting from starting_key.
     for (size_t i = 1; i <= num_entries; i++) {
-      BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value,
-                            starting_key + i - 1, table.GetEntryAt(i), dex_pc);
+      BuildSwitchCaseHelper(instruction,
+                            i,
+                            i == num_entries,
+                            table,
+                            value,
+                            starting_key + i - 1,
+                            table.GetEntryAt(i),
+                            dex_pc);
     }
   }
 }
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 6b0ccf8..26df241 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -2409,7 +2409,9 @@
 // will be the block containing the next Dex opcode.
 class HPackedSwitch : public HTemplateInstruction<1> {
  public:
-  HPackedSwitch(int32_t start_value, uint32_t num_entries, HInstruction* input,
+  HPackedSwitch(int32_t start_value,
+                uint32_t num_entries,
+                HInstruction* input,
                 uint32_t dex_pc = kNoDexPc)
     : HTemplateInstruction(SideEffects::None(), dex_pc),
       start_value_(start_value),
@@ -2430,8 +2432,8 @@
   DECLARE_INSTRUCTION(PackedSwitch);
 
  private:
-  int32_t start_value_;
-  uint32_t num_entries_;
+  const int32_t start_value_;
+  const uint32_t num_entries_;
 
   DISALLOW_COPY_AND_ASSIGN(HPackedSwitch);
 };
diff --git a/test/485-checker-dce-switch/expected.txt b/test/485-checker-dce-switch/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/485-checker-dce-switch/expected.txt
diff --git a/test/485-checker-dce-switch/info.txt b/test/485-checker-dce-switch/info.txt
new file mode 100644
index 0000000..6653526
--- /dev/null
+++ b/test/485-checker-dce-switch/info.txt
@@ -0,0 +1 @@
+Tests that DCE can remove a packed switch.
diff --git a/test/485-checker-dce-switch/src/Main.java b/test/485-checker-dce-switch/src/Main.java
new file mode 100644
index 0000000..019d876
--- /dev/null
+++ b/test/485-checker-dce-switch/src/Main.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+
+  public static int $inline$method() {
+    return 5;
+  }
+
+  /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination_final (before)
+  /// CHECK-DAG:                      PackedSwitch
+
+  /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination_final (after)
+  /// CHECK-DAG:    <<Const100:i\d+>> IntConstant 100
+  /// CHECK-DAG:                      Return [<<Const100>>]
+
+  /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination_final (after)
+  /// CHECK-NOT:                      PackedSwitch
+
+  public static int wholeSwitchDead(int j) {
+    int i = $inline$method();
+    int l = 100;
+    if (i > 100) {
+      switch(j) {
+        case 1:
+          i++;
+          break;
+        case 2:
+          i = 99;
+          break;
+        case 3:
+          i = 100;
+          break;
+        case 4:
+          i = -100;
+          break;
+        case 5:
+          i = 7;
+          break;
+        case 6:
+          i = -9;
+          break;
+      }
+      l += i;
+    }
+
+    return l;
+  }
+
+  /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination_final (before)
+  /// CHECK-DAG:                      PackedSwitch
+
+  /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination_final (after)
+  /// CHECK-DAG:     <<Const7:i\d+>>  IntConstant 7
+  /// CHECK-DAG:                      Return [<<Const7>>]
+
+  /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination_final (after)
+  /// CHECK-NOT:                      PackedSwitch
+
+  public static int constantSwitch_InRange() {
+    int i = $inline$method();
+    switch(i) {
+      case 1:
+        i++;
+        break;
+      case 2:
+        i = 99;
+        break;
+      case 3:
+        i = 100;
+        break;
+      case 4:
+        i = -100;
+        break;
+      case 5:
+        i = 7;
+        break;
+      case 6:
+        i = -9;
+        break;
+    }
+
+    return i;
+  }
+
+  /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination_final (before)
+  /// CHECK-DAG:                      PackedSwitch
+
+  /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination_final (after)
+  /// CHECK-DAG:     <<Const15:i\d+>> IntConstant 15
+  /// CHECK-DAG:                      Return [<<Const15>>]
+
+  /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination_final (after)
+  /// CHECK-NOT:                      PackedSwitch
+
+  public static int constantSwitch_AboveRange() {
+    int i = $inline$method() + 10;
+    switch(i) {
+      case 1:
+        i++;
+        break;
+      case 2:
+        i = 99;
+        break;
+      case 3:
+        i = 100;
+        break;
+      case 4:
+        i = -100;
+        break;
+      case 5:
+        i = 7;
+        break;
+      case 6:
+        i = -9;
+        break;
+    }
+
+    return i;
+  }
+
+  /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination_final (before)
+  /// CHECK-DAG:                      PackedSwitch
+
+  /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination_final (after)
+  /// CHECK-DAG:     <<ConstM5:i\d+>> IntConstant -5
+  /// CHECK-DAG:                      Return [<<ConstM5>>]
+
+  /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination_final (after)
+  /// CHECK-NOT:                      PackedSwitch
+
+  public static int constantSwitch_BelowRange() {
+    int i = $inline$method() - 10;
+    switch(i) {
+      case 1:
+        i++;
+        break;
+      case 2:
+        i = 99;
+        break;
+      case 3:
+        i = 100;
+        break;
+      case 4:
+        i = -100;
+        break;
+      case 5:
+        i = 7;
+        break;
+      case 6:
+        i = -9;
+        break;
+    }
+
+    return i;
+  }
+
+  public static void main(String[] args) throws Exception {
+    int ret_val = wholeSwitchDead(10);
+    if (ret_val != 100) {
+      throw new Error("Incorrect return value from wholeSwitchDead:" + ret_val);
+    }
+
+    ret_val = constantSwitch_InRange();
+    if (ret_val != 7) {
+      throw new Error("Incorrect return value from constantSwitch_InRange:" + ret_val);
+    }
+
+    ret_val = constantSwitch_AboveRange();
+    if (ret_val != 15) {
+      throw new Error("Incorrect return value from constantSwitch_AboveRange:" + ret_val);
+    }
+
+    ret_val = constantSwitch_BelowRange();
+    if (ret_val != -5) {
+      throw new Error("Incorrect return value from constantSwitch_BelowRange:" + ret_val);
+    }
+  }
+}