summaryrefslogtreecommitdiff
path: root/compiler/optimizing/dead_code_elimination.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2025-02-19 09:55:20 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-20 04:26:43 -0800
commit16a42183aff1275ad238bf5fb2e6416ecebc16cd (patch)
tree3527e3cbb618a34ae511a9463f987b21755e2bb2 /compiler/optimizing/dead_code_elimination.cc
parentc6aa6f7f1c7ea91b512d98caf493b8ad93e983b2 (diff)
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
Diffstat (limited to 'compiler/optimizing/dead_code_elimination.cc')
-rw-r--r--compiler/optimizing/dead_code_elimination.cc23
1 files changed, 12 insertions, 11 deletions
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<size_t> visited) {
// Use local allocator for allocating memory.
ScopedArenaAllocator allocator(graph->GetArenaStack());
ScopedArenaVector<HBasicBlock*> 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<HBasicBlock* const> 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<size_t> 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<HInstruction*> maybe_remove(allocator.Adapter(kArenaAllocDCE));
- ArenaBitVector visited(
- &allocator, graph_->GetCurrentInstructionId(), /*expandable=*/ false, kArenaAllocDCE);
+ BitVectorView<size_t> 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<size_t> 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;