diff options
author | David Brazdil <dbrazdil@google.com> | 2015-01-27 17:12:29 +0000 |
---|---|---|
committer | David Brazdil <dbrazdil@google.com> | 2015-01-27 17:12:29 +0000 |
commit | ea55b934cff1280318f5514039549799227cfa3d (patch) | |
tree | 835aec3eab728ecc8afe1d5a96858aca272e2250 /compiler | |
parent | 8c776cd9186e68c23b0983415ae14798e5ea5ab3 (diff) | |
download | art-ea55b934cff1280318f5514039549799227cfa3d.tar.gz art-ea55b934cff1280318f5514039549799227cfa3d.tar.bz2 art-ea55b934cff1280318f5514039549799227cfa3d.zip |
ART: Further refactor use lists
Change-Id: I9e3219575a508ca5141d851bfcaf848302480c32
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/optimizing/graph_visualizer.cc | 12 | ||||
-rw-r--r-- | compiler/optimizing/live_ranges_test.cc | 2 | ||||
-rw-r--r-- | compiler/optimizing/nodes.h | 15 | ||||
-rw-r--r-- | 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 c606bd7a29..ef461d9ac5 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<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 2097ea6ad8..92742f9a06 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 cac78f602c..2cc021cccf 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<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 @@ class HInstruction : public ArenaObject<kArenaAllocMisc> { 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 cf90bf7e88..5dbdc74924 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 |