From 0d9f17de8f21a10702de1510b73e89d07b3b9bbf Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Wed, 15 Apr 2015 14:17:44 +0100 Subject: Move the linear order to the HGraph. Bug found by Zheng Xu: SsaLivenessAnalysis being a stack allocated object, we should not refer to it in later phases of the compiler. Specifically, the code generator was using the linear order, which was stored in the liveness analysis object. Change-Id: I574641f522b7b86fc43f3914166108efc72edb3b --- compiler/optimizing/nodes.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 5f50494482..b406cbb8a4 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -112,6 +112,7 @@ class HGraph : public ArenaObject { : arena_(arena), blocks_(arena, kDefaultNumberOfBlocks), reverse_post_order_(arena, kDefaultNumberOfBlocks), + linear_order_(arena, kDefaultNumberOfBlocks), entry_block_(nullptr), exit_block_(nullptr), maximum_number_of_out_vregs_(0), @@ -216,6 +217,10 @@ class HGraph : public ArenaObject { return reverse_post_order_; } + const GrowableArray& GetLinearOrder() const { + return linear_order_; + } + bool HasArrayAccesses() const { return has_array_accesses_; } @@ -262,6 +267,9 @@ class HGraph : public ArenaObject { // List of blocks to perform a reverse post order tree traversal. GrowableArray reverse_post_order_; + // List of blocks to perform a linear order tree traversal. + GrowableArray linear_order_; + HBasicBlock* entry_block_; HBasicBlock* exit_block_; @@ -293,6 +301,7 @@ class HGraph : public ArenaObject { ArenaSafeMap cached_int_constants_; ArenaSafeMap cached_long_constants_; + friend class SsaLivenessAnalysis; // For the linear order. ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); DISALLOW_COPY_AND_ASSIGN(HGraph); }; @@ -3628,6 +3637,43 @@ class HPostOrderIterator : public ValueObject { DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); }; +class HLinearPostOrderIterator : public ValueObject { + public: + explicit HLinearPostOrderIterator(const HGraph& graph) + : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().Size()) {} + + bool Done() const { return index_ == 0; } + + HBasicBlock* Current() const { return order_.Get(index_ -1); } + + void Advance() { + --index_; + DCHECK_GE(index_, 0U); + } + + private: + const GrowableArray& order_; + size_t index_; + + DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); +}; + +class HLinearOrderIterator : public ValueObject { + public: + explicit HLinearOrderIterator(const HGraph& graph) + : order_(graph.GetLinearOrder()), index_(0) {} + + bool Done() const { return index_ == order_.Size(); } + HBasicBlock* Current() const { return order_.Get(index_); } + void Advance() { ++index_; } + + private: + const GrowableArray& order_; + size_t index_; + + DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); +}; + // Iterator over the blocks that art part of the loop. Includes blocks part // of an inner loop. The order in which the blocks are iterated is on their // block id. -- cgit v1.2.3-59-g8ed1b