diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2014-06-06 11:24:33 +0100 |
---|---|---|
committer | Nicolas Geoffray <ngeoffray@google.com> | 2014-06-09 08:59:02 +0100 |
commit | ec7e4727e99aa1416398ac5a684f5024817a25c7 (patch) | |
tree | 3ad51887c890b5cbebf1ae8e4afec8d93b485168 /compiler/optimizing/nodes.h | |
parent | 7a6b77f9a694ea4569fbf44493fdcaeea237a8be (diff) | |
download | art-ec7e4727e99aa1416398ac5a684f5024817a25c7.zip art-ec7e4727e99aa1416398ac5a684f5024817a25c7.tar.gz art-ec7e4727e99aa1416398ac5a684f5024817a25c7.tar.bz2 |
Fix some bugs in graph construction/simplification methods.
Also fix a brano during SSA construction. The code should
not have been commented out. Added a test to cover what the code
intends.
Change-Id: Ia00ae79dcf75eb0d412f07649d73e7f94dbfb6f0
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r-- | compiler/optimizing/nodes.h | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index b1c8016..68848de 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -283,18 +283,16 @@ class HBasicBlock : public ArenaObject { block->predecessors_.Add(this); } - void RemovePredecessor(HBasicBlock* block, bool remove_in_successor = true) { - predecessors_.Delete(block); - if (remove_in_successor) { - block->successors_.Delete(this); - } + void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { + size_t successor_index = GetSuccessorIndexOf(existing); + DCHECK_NE(successor_index, static_cast<size_t>(-1)); + existing->RemovePredecessor(this); + new_block->predecessors_.Add(this); + successors_.Put(successor_index, new_block); } - void RemoveSuccessor(HBasicBlock* block, bool remove_in_predecessor = true) { - successors_.Delete(block); - if (remove_in_predecessor) { - block->predecessors_.Delete(this); - } + void RemovePredecessor(HBasicBlock* block) { + predecessors_.Delete(block); } void ClearAllPredecessors() { @@ -315,6 +313,15 @@ class HBasicBlock : public ArenaObject { return -1; } + size_t GetSuccessorIndexOf(HBasicBlock* successor) { + for (size_t i = 0, e = successors_.Size(); i < e; ++i) { + if (successors_.Get(i) == successor) { + return i; + } + } + return -1; + } + void AddInstruction(HInstruction* instruction); void RemoveInstruction(HInstruction* instruction); void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); @@ -455,6 +462,7 @@ class HInstruction : public ArenaObject { virtual void SetRawInputAt(size_t index, HInstruction* input) = 0; virtual bool NeedsEnvironment() const { return false; } + virtual bool IsControlFlow() const { return false; } void AddUseAt(HInstruction* user, size_t index) { uses_ = new (block_->GetGraph()->GetArena()) HUseListNode<HInstruction>(user, index, uses_); @@ -733,7 +741,9 @@ class HTemplateInstruction: public HInstruction { // instruction that branches to the exit block. class HReturnVoid : public HTemplateInstruction<0> { public: - HReturnVoid() { } + HReturnVoid() {} + + virtual bool IsControlFlow() const { return true; } DECLARE_INSTRUCTION(ReturnVoid); @@ -749,6 +759,8 @@ class HReturn : public HTemplateInstruction<1> { SetRawInputAt(0, value); } + virtual bool IsControlFlow() const { return true; } + DECLARE_INSTRUCTION(Return); private: @@ -760,7 +772,9 @@ class HReturn : public HTemplateInstruction<1> { // exit block. class HExit : public HTemplateInstruction<0> { public: - HExit() { } + HExit() {} + + virtual bool IsControlFlow() const { return true; } DECLARE_INSTRUCTION(Exit); @@ -771,12 +785,14 @@ class HExit : public HTemplateInstruction<0> { // Jumps from one block to another. class HGoto : public HTemplateInstruction<0> { public: - HGoto() { } + HGoto() {} HBasicBlock* GetSuccessor() const { return GetBlock()->GetSuccessors().Get(0); } + virtual bool IsControlFlow() const { return true; } + DECLARE_INSTRUCTION(Goto); private: @@ -799,6 +815,8 @@ class HIf : public HTemplateInstruction<1> { return GetBlock()->GetSuccessors().Get(1); } + virtual bool IsControlFlow() const { return true; } + DECLARE_INSTRUCTION(If); private: |