summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/nodes.cc
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-06-06 11:24:33 +0100
committerNicolas Geoffray <ngeoffray@google.com>2014-06-09 08:59:02 +0100
commitec7e4727e99aa1416398ac5a684f5024817a25c7 (patch)
tree3ad51887c890b5cbebf1ae8e4afec8d93b485168 /compiler/optimizing/nodes.cc
parent7a6b77f9a694ea4569fbf44493fdcaeea237a8be (diff)
downloadart-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.cc')
-rw-r--r--compiler/optimizing/nodes.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 752466b..2a97fad 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -35,7 +35,7 @@ void HGraph::RemoveDeadBlocks(const ArenaBitVector& visited) const {
if (!visited.IsBitSet(i)) {
HBasicBlock* block = blocks_.Get(i);
for (size_t j = 0; j < block->GetSuccessors().Size(); ++j) {
- block->GetSuccessors().Get(j)->RemovePredecessor(block, false);
+ block->GetSuccessors().Get(j)->RemovePredecessor(block);
}
for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
block->RemovePhi(it.Current()->AsPhi());
@@ -143,8 +143,7 @@ void HGraph::SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor) {
HBasicBlock* new_block = new (arena_) HBasicBlock(this);
AddBlock(new_block);
new_block->AddInstruction(new (arena_) HGoto());
- block->RemoveSuccessor(successor);
- block->AddSuccessor(new_block);
+ block->ReplaceSuccessor(successor, new_block);
new_block->AddSuccessor(successor);
if (successor->IsLoopHeader()) {
// If we split at a back edge boundary, make the new block the back edge.
@@ -168,8 +167,7 @@ void HGraph::SimplifyLoop(HBasicBlock* header) {
new_back_edge->AddInstruction(new (arena_) HGoto());
for (size_t pred = 0, e = info->GetBackEdges().Size(); pred < e; ++pred) {
HBasicBlock* back_edge = info->GetBackEdges().Get(pred);
- header->RemovePredecessor(back_edge);
- back_edge->AddSuccessor(new_back_edge);
+ back_edge->ReplaceSuccessor(header, new_back_edge);
}
info->ClearBackEdges();
info->AddBackEdge(new_back_edge);
@@ -190,9 +188,8 @@ void HGraph::SimplifyLoop(HBasicBlock* header) {
for (size_t pred = 0; pred < header->GetPredecessors().Size(); ++pred) {
HBasicBlock* predecessor = header->GetPredecessors().Get(pred);
if (predecessor != back_edge) {
- header->RemovePredecessor(predecessor);
+ predecessor->ReplaceSuccessor(header, pre_header);
pred--;
- predecessor->AddSuccessor(pre_header);
}
}
pre_header->AddSuccessor(header);
@@ -294,12 +291,20 @@ bool HBasicBlock::Dominates(HBasicBlock* other) const {
void HBasicBlock::InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor) {
DCHECK(cursor->AsPhi() == nullptr);
DCHECK(instruction->AsPhi() == nullptr);
+ DCHECK_EQ(instruction->GetId(), -1);
+ DCHECK_NE(cursor->GetId(), -1);
+ DCHECK_EQ(cursor->GetBlock(), this);
+ DCHECK(!instruction->IsControlFlow());
instruction->next_ = cursor;
instruction->previous_ = cursor->previous_;
cursor->previous_ = instruction;
if (GetFirstInstruction() == cursor) {
instructions_.first_instruction_ = instruction;
+ } else {
+ instruction->previous_->next_ = instruction;
}
+ instruction->SetBlock(this);
+ instruction->SetId(GetGraph()->GetNextInstructionId());
}
static void Add(HInstructionList* instruction_list,