diff options
Diffstat (limited to 'compiler/optimizing')
-rw-r--r-- | compiler/optimizing/code_sinking.cc | 4 | ||||
-rw-r--r-- | compiler/optimizing/nodes.cc | 29 | ||||
-rw-r--r-- | compiler/optimizing/nodes.h | 8 |
3 files changed, 22 insertions, 19 deletions
diff --git a/compiler/optimizing/code_sinking.cc b/compiler/optimizing/code_sinking.cc index b1d14132c4..9ba5416697 100644 --- a/compiler/optimizing/code_sinking.cc +++ b/compiler/optimizing/code_sinking.cc @@ -409,8 +409,8 @@ void CodeSinking::SinkCodeToUncommonBranch(HBasicBlock* end_block) { HBasicBlock* common_dominator = finder.Get(); // Step (2): iterate over the worklist to find sinking candidates. - ArenaBitVector instructions_that_can_move( - &allocator, number_of_instructions, /* expandable= */ false); + BitVectorView<size_t> instructions_that_can_move = + ArenaBitVector::CreateFixedSize(&allocator, number_of_instructions); ScopedArenaVector<ScopedArenaVector<HInstruction*>> instructions_to_move( graph_->GetBlocks().size(), ScopedArenaVector<HInstruction*>(allocator.Adapter(kArenaAllocMisc)), diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 9b5cc50e93..752e8b10d1 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -61,14 +61,14 @@ inline int32_t HGraph::AllocateInstructionId() { return current_instruction_id_++; } -void HGraph::FindBackEdges(ArenaBitVector* visited) { +void HGraph::FindBackEdges(/*out*/ BitVectorView<size_t> visited) { // "visited" must be empty on entry, it's an output argument for all visited (i.e. live) blocks. - DCHECK_EQ(visited->GetHighestBitSet(), -1); + DCHECK(!visited.IsAnyBitSet()); // Allocate memory from local ScopedArenaAllocator. ScopedArenaAllocator allocator(GetArenaStack()); // Nodes that we're currently visiting, indexed by block id. - BitVectorView visiting = + BitVectorView<size_t> visiting = ArenaBitVector::CreateFixedSize(&allocator, blocks_.size(), kArenaAllocGraphBuilder); // Number of successors visited from a given node, indexed by block id. ScopedArenaVector<size_t> successors_visited(blocks_.size(), @@ -78,7 +78,7 @@ void HGraph::FindBackEdges(ArenaBitVector* visited) { ScopedArenaVector<HBasicBlock*> worklist(allocator.Adapter(kArenaAllocGraphBuilder)); constexpr size_t kDefaultWorklistSize = 8; worklist.reserve(kDefaultWorklistSize); - visited->SetBit(entry_block_->GetBlockId()); + visited.SetBit(entry_block_->GetBlockId()); visiting.SetBit(entry_block_->GetBlockId()); worklist.push_back(entry_block_); @@ -94,8 +94,8 @@ void HGraph::FindBackEdges(ArenaBitVector* visited) { if (visiting.IsBitSet(successor_id)) { DCHECK(ContainsElement(worklist, successor)); successor->AddBackEdge(current); - } else if (!visited->IsBitSet(successor_id)) { - visited->SetBit(successor_id); + } else if (!visited.IsBitSet(successor_id)) { + visited.SetBit(successor_id); visiting.SetBit(successor_id); worklist.push_back(successor); } @@ -150,7 +150,8 @@ static void RemoveAsUser(HInstruction* instruction) { RemoveEnvironmentUses(instruction); } -void HGraph::RemoveDeadBlocksInstructionsAsUsersAndDisconnect(const ArenaBitVector& visited) const { +void HGraph::RemoveDeadBlocksInstructionsAsUsersAndDisconnect( + BitVectorView<const size_t> visited) const { for (size_t i = 0; i < blocks_.size(); ++i) { if (!visited.IsBitSet(i)) { HBasicBlock* block = blocks_[i]; @@ -165,7 +166,7 @@ void HGraph::RemoveDeadBlocksInstructionsAsUsersAndDisconnect(const ArenaBitVect } // Remove non-catch phi uses, and disconnect the block. - block->DisconnectFromSuccessors(&visited); + block->DisconnectFromSuccessors(visited); } } } @@ -188,7 +189,7 @@ static void RemoveCatchPhiUsesOfDeadInstruction(HInstruction* insn) { } } -void HGraph::RemoveDeadBlocks(const ArenaBitVector& visited) { +void HGraph::RemoveDeadBlocks(BitVectorView<const size_t> visited) { DCHECK(reverse_post_order_.empty()) << "We shouldn't have dominance information."; for (size_t i = 0; i < blocks_.size(); ++i) { if (!visited.IsBitSet(i)) { @@ -215,10 +216,11 @@ GraphAnalysisResult HGraph::BuildDominatorTree() { // Allocate memory from local ScopedArenaAllocator. ScopedArenaAllocator allocator(GetArenaStack()); - ArenaBitVector visited(&allocator, blocks_.size(), false, kArenaAllocGraphBuilder); + BitVectorView<size_t> visited = + ArenaBitVector::CreateFixedSize(&allocator, blocks_.size(), kArenaAllocGraphBuilder); // (1) Find the back edges in the graph doing a DFS traversal. - FindBackEdges(&visited); + FindBackEdges(visited); // (2) Remove instructions and phis from blocks not visited during // the initial DFS as users from other instructions, so that @@ -2505,13 +2507,14 @@ void HBasicBlock::DisconnectAndDelete() { graph_->DeleteDeadEmptyBlock(this); } -void HBasicBlock::DisconnectFromSuccessors(const ArenaBitVector* visited) { +void HBasicBlock::DisconnectFromSuccessors(BitVectorView<const size_t> visited) { + DCHECK_IMPLIES(visited.SizeInBits() != 0u, visited.SizeInBits() == graph_->GetBlocks().size()); for (HBasicBlock* successor : successors_) { // Delete this block from the list of predecessors. size_t this_index = successor->GetPredecessorIndexOf(this); successor->predecessors_.erase(successor->predecessors_.begin() + this_index); - if (visited != nullptr && !visited->IsBitSet(successor->GetBlockId())) { + if (visited.SizeInBits() != 0u && !visited.IsBitSet(successor->GetBlockId())) { // `successor` itself is dead. Therefore, there is no need to update its phis. continue; } diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index e59dcf26c1..772828d9ef 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -289,7 +289,7 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { void ComputeDominanceInformation(); void ClearDominanceInformation(); void ClearLoopInformation(); - void FindBackEdges(ArenaBitVector* visited); + void FindBackEdges(/*out*/ BitVectorView<size_t> visited); GraphAnalysisResult BuildDominatorTree(); GraphAnalysisResult RecomputeDominatorTree(); void SimplifyCFG(); @@ -545,8 +545,8 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { bool IsUsefulOptimizing() const { return useful_optimizing_; } private: - void RemoveDeadBlocksInstructionsAsUsersAndDisconnect(const ArenaBitVector& visited) const; - void RemoveDeadBlocks(const ArenaBitVector& visited); + void RemoveDeadBlocksInstructionsAsUsersAndDisconnect(BitVectorView<const size_t> visited) const; + void RemoveDeadBlocks(BitVectorView<const size_t> visited); template <class InstructionType, typename ValueType> InstructionType* CreateConstant(ValueType value, @@ -1133,7 +1133,7 @@ class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { // Disconnects `this` from all its successors and updates their phis, if the successors have them. // If `visited` is provided, it will use the information to know if a successor is reachable and // skip updating those phis. - void DisconnectFromSuccessors(const ArenaBitVector* visited = nullptr); + void DisconnectFromSuccessors(BitVectorView<const size_t> visited = {}); // Removes the catch phi uses of the instructions in `this`, and then remove the instruction // itself. If `building_dominator_tree` is true, it will not remove the instruction as user, since |