From 29fc008c9689e9036a3f5e3bd186bbfb5de3cb82 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Tue, 18 Aug 2015 17:17:38 +0100 Subject: [PATCH] ART: Revert storing of exceptional predecessors After change of the approach for try/catch register allocation, it is no longer necessary to record instructions which might throw into a catch block. Change-Id: I7ef12ed06c49a35280029810975fa2a50fe4a424 --- compiler/optimizing/graph_checker.cc | 75 +----------------------------------- compiler/optimizing/nodes.cc | 7 ---- compiler/optimizing/nodes.h | 21 ---------- compiler/optimizing/ssa_builder.cc | 4 +- 4 files changed, 2 insertions(+), 105 deletions(-) diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc index e4bc9e68e..5406a0ccf 100644 --- a/compiler/optimizing/graph_checker.cc +++ b/compiler/optimizing/graph_checker.cc @@ -89,7 +89,7 @@ void GraphChecker::VisitBasicBlock(HBasicBlock* block) { block->GetBlockId())); } - // Ensure that the only Return(Void) and Throw jump to Exit. An exiting + // Ensure that only Return(Void) and Throw jump to Exit. An exiting // TryBoundary may be between a Throw and the Exit if the Throw is in a try. if (block->IsExitBlock()) { for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) { @@ -355,39 +355,6 @@ void GraphChecker::VisitInstanceOf(HInstanceOf* instruction) { void SSAChecker::VisitBasicBlock(HBasicBlock* block) { super_type::VisitBasicBlock(block); - // Ensure that only catch blocks have exceptional predecessors, and if they do - // these are instructions which throw into them. - if (block->IsCatchBlock()) { - for (size_t i = 0, e = block->GetExceptionalPredecessors().Size(); i < e; ++i) { - HInstruction* thrower = block->GetExceptionalPredecessors().Get(i); - HBasicBlock* try_block = thrower->GetBlock(); - if (!thrower->CanThrow()) { - AddError(StringPrintf("Exceptional predecessor %s:%d of catch block %d does not throw.", - thrower->DebugName(), - thrower->GetId(), - block->GetBlockId())); - } else if (!try_block->IsInTry()) { - AddError(StringPrintf("Exceptional predecessor %s:%d of catch block %d " - "is not in a try block.", - thrower->DebugName(), - thrower->GetId(), - block->GetBlockId())); - } else if (!try_block->GetTryEntry()->HasExceptionHandler(*block)) { - AddError(StringPrintf("Catch block %d is not an exception handler of " - "its exceptional predecessor %s:%d.", - block->GetBlockId(), - thrower->DebugName(), - thrower->GetId())); - } - } - } else { - if (!block->GetExceptionalPredecessors().IsEmpty()) { - AddError(StringPrintf("Normal block %d has %zu exceptional predecessors.", - block->GetBlockId(), - block->GetExceptionalPredecessors().Size())); - } - } - // Ensure that catch blocks are not normal successors, and normal blocks are // never exceptional successors. const size_t num_normal_successors = block->NumberOfNormalSuccessors(); @@ -572,7 +539,6 @@ void SSAChecker::CheckLoop(HBasicBlock* loop_header) { void SSAChecker::VisitInstruction(HInstruction* instruction) { super_type::VisitInstruction(instruction); - HBasicBlock* block = instruction->GetBlock(); // Ensure an instruction dominates all its uses. for (HUseIterator use_it(instruction->GetUses()); @@ -604,24 +570,6 @@ void SSAChecker::VisitInstruction(HInstruction* instruction) { } } } - - // Ensure that throwing instructions in try blocks are listed as exceptional - // predecessors in their exception handlers. - if (instruction->CanThrow() && block->IsInTry()) { - for (HExceptionHandlerIterator handler_it(*block->GetTryEntry()); - !handler_it.Done(); - handler_it.Advance()) { - if (!handler_it.Current()->GetExceptionalPredecessors().Contains(instruction)) { - AddError(StringPrintf("Instruction %s:%d is in try block %d and can throw " - "but its exception handler %d does not list it in " - "its exceptional predecessors.", - instruction->DebugName(), - instruction->GetId(), - block->GetBlockId(), - handler_it.Current()->GetBlockId())); - } - } - } } static Primitive::Type PrimitiveKind(Primitive::Type type) { @@ -669,27 +617,6 @@ void SSAChecker::VisitPhi(HPhi* phi) { if (phi->IsCatchPhi()) { // The number of inputs of a catch phi corresponds to the total number of // throwing instructions caught by this catch block. - const GrowableArray& predecessors = - phi->GetBlock()->GetExceptionalPredecessors(); - if (phi->InputCount() != predecessors.Size()) { - AddError(StringPrintf( - "Phi %d in catch block %d has %zu inputs, " - "but catch block %d has %zu exceptional predecessors.", - phi->GetId(), phi->GetBlock()->GetBlockId(), phi->InputCount(), - phi->GetBlock()->GetBlockId(), predecessors.Size())); - } else { - for (size_t i = 0, e = phi->InputCount(); i < e; ++i) { - HInstruction* input = phi->InputAt(i); - HInstruction* thrower = predecessors.Get(i); - if (!input->StrictlyDominates(thrower)) { - AddError(StringPrintf( - "Input %d at index %zu of phi %d from catch block %d does not " - "dominate the throwing instruction %s:%d.", - input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(), - thrower->DebugName(), thrower->GetId())); - } - } - } } else { // Ensure the number of inputs of a non-catch phi is the same as the number // of its predecessors. diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index b6a198021..f2b63ae67 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -564,13 +564,6 @@ bool HBasicBlock::Dominates(HBasicBlock* other) const { return false; } -void HBasicBlock::AddExceptionalPredecessor(HInstruction* exceptional_predecessor) { - DCHECK(exceptional_predecessor->CanThrow()); - DCHECK(exceptional_predecessor->GetBlock()->IsInTry()); - DCHECK(exceptional_predecessor->GetBlock()->GetTryEntry()->HasExceptionHandler(*this)); - exceptional_predecessors_.Add(exceptional_predecessor); -} - static void UpdateInputsUsers(HInstruction* instruction) { for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { instruction->InputAt(i)->AddUseAt(instruction, i); diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 0df5d6dd2..f09e958d2 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -567,7 +567,6 @@ class HBasicBlock : public ArenaObject { explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) : graph_(graph), predecessors_(graph->GetArena(), kDefaultNumberOfPredecessors), - exceptional_predecessors_(graph->GetArena(), kDefaultNumberOfExceptionalPredecessors), successors_(graph->GetArena(), kDefaultNumberOfSuccessors), loop_information_(nullptr), dominator_(nullptr), @@ -582,10 +581,6 @@ class HBasicBlock : public ArenaObject { return predecessors_; } - const GrowableArray& GetExceptionalPredecessors() const { - return exceptional_predecessors_; - } - const GrowableArray& GetSuccessors() const { return successors_; } @@ -654,8 +649,6 @@ class HBasicBlock : public ArenaObject { HInstruction* GetLastPhi() const { return phis_.last_instruction_; } const HInstructionList& GetPhis() const { return phis_; } - void AddExceptionalPredecessor(HInstruction* exceptional_predecessor); - void AddSuccessor(HBasicBlock* block) { successors_.Add(block); block->predecessors_.Add(this); @@ -695,10 +688,6 @@ class HBasicBlock : public ArenaObject { predecessors_.Delete(block); } - void RemoveExceptionalPredecessor(HInstruction* instruction) { - exceptional_predecessors_.Delete(instruction); - } - void RemoveSuccessor(HBasicBlock* block) { successors_.Delete(block); } @@ -735,15 +724,6 @@ class HBasicBlock : public ArenaObject { return -1; } - size_t GetExceptionalPredecessorIndexOf(HInstruction* exceptional_predecessor) const { - for (size_t i = 0, e = exceptional_predecessors_.Size(); i < e; ++i) { - if (exceptional_predecessors_.Get(i) == exceptional_predecessor) { - return i; - } - } - return -1; - } - size_t GetSuccessorIndexOf(HBasicBlock* successor) const { for (size_t i = 0, e = successors_.Size(); i < e; ++i) { if (successors_.Get(i) == successor) { @@ -904,7 +884,6 @@ class HBasicBlock : public ArenaObject { private: HGraph* graph_; GrowableArray predecessors_; - GrowableArray exceptional_predecessors_; GrowableArray successors_; HInstructionList instructions_; HInstructionList phis_; diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc index 2c34e4dd0..ff2e6ad82 100644 --- a/compiler/optimizing/ssa_builder.cc +++ b/compiler/optimizing/ssa_builder.cc @@ -570,9 +570,7 @@ void SsaBuilder::VisitInstruction(HInstruction* instruction) { if (instruction->GetBlock()->IsInTry() && instruction->CanThrow()) { HTryBoundary* try_block = instruction->GetBlock()->GetTryEntry(); for (HExceptionHandlerIterator it(*try_block); !it.Done(); it.Advance()) { - HBasicBlock* handler = it.Current(); - handler->AddExceptionalPredecessor(instruction); - GrowableArray* handler_locals = GetLocalsFor(handler); + GrowableArray* handler_locals = GetLocalsFor(it.Current()); for (size_t i = 0, e = current_locals_->Size(); i < e; ++i) { HInstruction* local_value = current_locals_->Get(i); if (local_value != nullptr) { -- 2.11.0