From ea55b934cff1280318f5514039549799227cfa3d Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Tue, 27 Jan 2015 17:12:29 +0000 Subject: [PATCH] ART: Further refactor use lists Change-Id: I9e3219575a508ca5141d851bfcaf848302480c32 --- compiler/optimizing/graph_visualizer.cc | 12 +++++++++--- compiler/optimizing/live_ranges_test.cc | 2 +- compiler/optimizing/nodes.h | 15 +++------------ compiler/optimizing/nodes_test.cc | 6 ++---- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc index c606bd7a2..ef461d9ac 100644 --- a/compiler/optimizing/graph_visualizer.cc +++ b/compiler/optimizing/graph_visualizer.cc @@ -223,10 +223,16 @@ class HGraphVisualizerPrinter : public HGraphVisitor { 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 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 2097ea6ad..92742f9a0 100644 --- a/compiler/optimizing/live_ranges_test.cc +++ b/compiler/optimizing/live_ranges_test.cc @@ -432,7 +432,7 @@ TEST(LiveRangesTest, CFG4) { 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 cac78f602..2cc021ccc 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -623,7 +623,7 @@ class HUseList : public ValueObject { // Adds a new entry at the beginning of the use list and returns // the newly created node. HUseListNode* AddUse(T user, size_t index, ArenaAllocator* arena) { - HUseListNode* new_node = new(arena) HUseListNode(user, index); + HUseListNode* new_node = new (arena) HUseListNode(user, index); if (IsEmpty()) { first_ = new_node; } else { @@ -863,21 +863,12 @@ class HInstruction : public ArenaObject { void RemoveUser(HInstruction* user, size_t index); void RemoveEnvironmentUser(HUseListNode* use); - HUseList& GetUses() { return uses_; } - HUseList& GetEnvUses() { return env_uses_; } + const HUseList& GetUses() { return uses_; } + const HUseList& 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 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 cf90bf7e8..5dbdc7492 100644 --- a/compiler/optimizing/nodes_test.cc +++ b/compiler/optimizing/nodes_test.cc @@ -81,13 +81,12 @@ TEST(Node, InsertInstruction) { 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 @@ TEST(Node, AddInstruction) { 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 -- 2.11.0