Make the SSA builder honor the debuggable flag.

This requires to properly type phis that are only
used by environments, and discard phis with incomptable types.
The code generators do not handle these conflicting types. In
the process, ensure a phi has a type that does not depend
on the order of the inputs (for example (char, short) -> short),
and set int for int-like types. We can refine this later.

Change-Id: I60ab601d6d00b1cbf18623ee4ff1795aa28f84a1
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 8b56166..942aa23 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -103,7 +103,7 @@
 // Control-flow graph of a method. Contains a list of basic blocks.
 class HGraph : public ArenaObject<kArenaAllocMisc> {
  public:
-  HGraph(ArenaAllocator* arena, int start_instruction_id = 0)
+  HGraph(ArenaAllocator* arena, bool debuggable = false, int start_instruction_id = 0)
       : arena_(arena),
         blocks_(arena, kDefaultNumberOfBlocks),
         reverse_post_order_(arena, kDefaultNumberOfBlocks),
@@ -114,6 +114,7 @@
         number_of_in_vregs_(0),
         temporaries_vreg_slots_(0),
         has_array_accesses_(false),
+        debuggable_(debuggable),
         current_instruction_id_(start_instruction_id) {}
 
   ArenaAllocator* GetArena() const { return arena_; }
@@ -208,6 +209,8 @@
     has_array_accesses_ = value;
   }
 
+  bool IsDebuggable() const { return debuggable_; }
+
   HNullConstant* GetNullConstant();
 
  private:
@@ -248,6 +251,11 @@
   // Has array accesses. We can totally skip BCE if it's false.
   bool has_array_accesses_;
 
+  // Indicates whether the graph should be compiled in a way that
+  // ensures full debuggability. If false, we can apply more
+  // aggressive optimizations that may limit the level of debugging.
+  const bool debuggable_;
+
   // The current id to assign to a newly added instruction. See HInstruction.id_.
   int32_t current_instruction_id_;
 
@@ -2498,6 +2506,19 @@
     inputs_.SetSize(number_of_inputs);
   }
 
+  // Returns a type equivalent to the given `type`, but that a `HPhi` can hold.
+  static Primitive::Type ToPhiType(Primitive::Type type) {
+    switch (type) {
+      case Primitive::kPrimBoolean:
+      case Primitive::kPrimByte:
+      case Primitive::kPrimShort:
+      case Primitive::kPrimChar:
+        return Primitive::kPrimInt;
+      default:
+        return type;
+    }
+  }
+
   size_t InputCount() const OVERRIDE { return inputs_.Size(); }
 
   void AddInput(HInstruction* input);