ART: Further refactor use lists

Change-Id: I9e3219575a508ca5141d851bfcaf848302480c32
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index c606bd7..ef461d9 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -223,10 +223,16 @@
     const char* kEndInstructionMarker = "<|@";
     for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
       HInstruction* instruction = it.Current();
-      AddIndent();
       int bci = 0;
-      output_ << bci << " " << instruction->ExpensiveComputeNumberOfUses()
-              << " " << GetTypeId(instruction->GetType()) << instruction->GetId() << " ";
+      size_t num_uses = 0;
+      for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
+           !use_it.Done();
+           use_it.Advance()) {
+        ++num_uses;
+      }
+      AddIndent();
+      output_ << bci << " " << num_uses << " "
+              << GetTypeId(instruction->GetType()) << instruction->GetId() << " ";
       PrintInstruction(instruction);
       output_ << kEndInstructionMarker << std::endl;
     }
diff --git a/compiler/optimizing/live_ranges_test.cc b/compiler/optimizing/live_ranges_test.cc
index 2097ea6..92742f9 100644
--- a/compiler/optimizing/live_ranges_test.cc
+++ b/compiler/optimizing/live_ranges_test.cc
@@ -432,7 +432,7 @@
   ASSERT_TRUE(range->GetNext() == nullptr);
 
   HPhi* phi = liveness.GetInstructionFromSsaIndex(4)->AsPhi();
-  ASSERT_EQ(phi->ExpensiveComputeNumberOfUses(), 1u);
+  ASSERT_TRUE(phi->GetUses().HasOnlyOneUse());
   interval = phi->GetLiveInterval();
   range = interval->GetFirstRange();
   ASSERT_EQ(26u, range->GetStart());
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index cac78f6..2cc021c 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -623,7 +623,7 @@
   // Adds a new entry at the beginning of the use list and returns
   // the newly created node.
   HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) {
-    HUseListNode<T>* new_node = new(arena) HUseListNode<T>(user, index);
+    HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index);
     if (IsEmpty()) {
       first_ = new_node;
     } else {
@@ -863,21 +863,12 @@
   void RemoveUser(HInstruction* user, size_t index);
   void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use);
 
-  HUseList<HInstruction*>& GetUses() { return uses_; }
-  HUseList<HEnvironment*>& GetEnvUses() { return env_uses_; }
+  const HUseList<HInstruction*>& GetUses() { return uses_; }
+  const HUseList<HEnvironment*>& GetEnvUses() { return env_uses_; }
 
   bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); }
   bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); }
 
-  size_t ExpensiveComputeNumberOfUses() const {
-    // TODO: Optimize this method if it is used outside of the HGraphVisualizer.
-    size_t result = 0;
-    for (HUseIterator<HInstruction*> it(uses_); !it.Done(); it.Advance()) {
-      ++result;
-    }
-    return result;
-  }
-
   // Does this instruction strictly dominate `other_instruction`?
   // Returns false if this instruction and `other_instruction` are the same.
   // Aborts if this instruction and `other_instruction` are both phis.
diff --git a/compiler/optimizing/nodes_test.cc b/compiler/optimizing/nodes_test.cc
index cf90bf7..5dbdc74 100644
--- a/compiler/optimizing/nodes_test.cc
+++ b/compiler/optimizing/nodes_test.cc
@@ -81,13 +81,12 @@
   entry->AddInstruction(new (&allocator) HExit());
 
   ASSERT_FALSE(parameter1->HasUses());
-  ASSERT_EQ(parameter1->ExpensiveComputeNumberOfUses(), 0u);
 
   HInstruction* to_insert = new (&allocator) HNullCheck(parameter1, 0);
   entry->InsertInstructionBefore(to_insert, parameter2);
 
   ASSERT_TRUE(parameter1->HasUses());
-  ASSERT_EQ(parameter1->ExpensiveComputeNumberOfUses(), 1u);
+  ASSERT_TRUE(parameter1->GetUses().HasOnlyOneUse());
 }
 
 /**
@@ -105,13 +104,12 @@
   entry->AddInstruction(parameter);
 
   ASSERT_FALSE(parameter->HasUses());
-  ASSERT_EQ(parameter->ExpensiveComputeNumberOfUses(), 0u);
 
   HInstruction* to_add = new (&allocator) HNullCheck(parameter, 0);
   entry->AddInstruction(to_add);
 
   ASSERT_TRUE(parameter->HasUses());
-  ASSERT_EQ(parameter->ExpensiveComputeNumberOfUses(), 1u);
+  ASSERT_TRUE(parameter->GetUses().HasOnlyOneUse());
 }
 
 }  // namespace art