From 16a42183aff1275ad238bf5fb2e6416ecebc16cd Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 19 Feb 2025 09:55:20 +0000 Subject: Introduce `BitVectorView<>`. Initially implement only simple bit getter and setters and use the new class to avoid overheads of `ArenaBitVector` in a few places. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 331194861 Change-Id: Ie29dfcd02286770e07131e43b65e6e9fb044a924 --- compiler/optimizing/dead_code_elimination.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'compiler/optimizing/dead_code_elimination.cc') diff --git a/compiler/optimizing/dead_code_elimination.cc b/compiler/optimizing/dead_code_elimination.cc index b8cd39e77f..9955982309 100644 --- a/compiler/optimizing/dead_code_elimination.cc +++ b/compiler/optimizing/dead_code_elimination.cc @@ -29,21 +29,21 @@ namespace art HIDDEN { -static void MarkReachableBlocks(HGraph* graph, ArenaBitVector* visited) { +static void MarkReachableBlocks(HGraph* graph, BitVectorView visited) { // Use local allocator for allocating memory. ScopedArenaAllocator allocator(graph->GetArenaStack()); ScopedArenaVector worklist(allocator.Adapter(kArenaAllocDCE)); constexpr size_t kDefaultWorlistSize = 8; worklist.reserve(kDefaultWorlistSize); - visited->SetBit(graph->GetEntryBlock()->GetBlockId()); + visited.SetBit(graph->GetEntryBlock()->GetBlockId()); worklist.push_back(graph->GetEntryBlock()); while (!worklist.empty()) { HBasicBlock* block = worklist.back(); worklist.pop_back(); int block_id = block->GetBlockId(); - DCHECK(visited->IsBitSet(block_id)); + DCHECK(visited.IsBitSet(block_id)); ArrayRef live_successors(block->GetSuccessors()); HInstruction* last_instruction = block->GetLastInstruction(); @@ -83,8 +83,8 @@ static void MarkReachableBlocks(HGraph* graph, ArenaBitVector* visited) { for (HBasicBlock* successor : live_successors) { // Add only those successors that have not been visited yet. - if (!visited->IsBitSet(successor->GetBlockId())) { - visited->SetBit(successor->GetBlockId()); + if (!visited.IsBitSet(successor->GetBlockId())) { + visited.SetBit(successor->GetBlockId()); worklist.push_back(successor); } } @@ -799,8 +799,8 @@ bool HDeadCodeElimination::RemoveEmptyIfs() { // 5 // where 2, 3, and 4 are single HGoto blocks, and block 5 has Phis. ScopedArenaAllocator allocator(graph_->GetArenaStack()); - ArenaBitVector visited_blocks( - &allocator, graph_->GetBlocks().size(), /*expandable=*/ false, kArenaAllocDCE); + BitVectorView visited_blocks = + ArenaBitVector::CreateFixedSize(&allocator, graph_->GetBlocks().size(), kArenaAllocDCE); HBasicBlock* merge_true = true_block; visited_blocks.SetBit(merge_true->GetBlockId()); while (merge_true->IsSingleGoto()) { @@ -822,8 +822,8 @@ bool HDeadCodeElimination::RemoveEmptyIfs() { // Data structures to help remove now-dead instructions. ScopedArenaQueue maybe_remove(allocator.Adapter(kArenaAllocDCE)); - ArenaBitVector visited( - &allocator, graph_->GetCurrentInstructionId(), /*expandable=*/ false, kArenaAllocDCE); + BitVectorView visited = ArenaBitVector::CreateFixedSize( + &allocator, graph_->GetCurrentInstructionId(), kArenaAllocDCE); maybe_remove.push(if_instr->InputAt(0)); visited.SetBit(if_instr->GetId()); @@ -874,9 +874,10 @@ bool HDeadCodeElimination::RemoveDeadBlocks(bool force_recomputation, ScopedArenaAllocator allocator(graph_->GetArenaStack()); // Classify blocks as reachable/unreachable. - ArenaBitVector live_blocks(&allocator, graph_->GetBlocks().size(), false, kArenaAllocDCE); + BitVectorView live_blocks = + ArenaBitVector::CreateFixedSize(&allocator, graph_->GetBlocks().size(), kArenaAllocDCE); - MarkReachableBlocks(graph_, &live_blocks); + MarkReachableBlocks(graph_, live_blocks); bool removed_one_or_more_blocks = false; bool rerun_dominance_and_loop_analysis = false; -- cgit v1.2.3-59-g8ed1b