Delete CodeItemIterator
Replace uses with DexInstructionIterator.
Bug: 63756964
Test: test-art-host-gtest
Change-Id: I28c839c372edcb60583867355d46b14f8752d41b
diff --git a/compiler/dex/dex_to_dex_compiler.cc b/compiler/dex/dex_to_dex_compiler.cc
index a94dbe9..cc452fc 100644
--- a/compiler/dex/dex_to_dex_compiler.cc
+++ b/compiler/dex/dex_to_dex_compiler.cc
@@ -112,9 +112,10 @@
void DexCompiler::Compile() {
DCHECK_EQ(dex_to_dex_compilation_level_, DexToDexCompilationLevel::kOptimize);
- for (CodeItemIterator it(*unit_.GetCodeItem()); !it.Done(); it.Advance()) {
- Instruction* inst = const_cast<Instruction*>(&it.CurrentInstruction());
- const uint32_t dex_pc = it.CurrentDexPc();
+ IterationRange<DexInstructionIterator> instructions = unit_.GetCodeItem()->Instructions();
+ for (DexInstructionIterator it = instructions.begin(); it != instructions.end(); ++it) {
+ const uint32_t dex_pc = it.DexPc();
+ Instruction* inst = const_cast<Instruction*>(&it.Inst());
switch (inst->Opcode()) {
case Instruction::RETURN_VOID:
CompileReturnVoid(inst, dex_pc);
@@ -125,7 +126,7 @@
if (inst->Opcode() == Instruction::NOP) {
// We turned the CHECK_CAST into two NOPs, avoid visiting the second NOP twice since this
// would add 2 quickening info entries.
- it.Advance();
+ ++it;
}
break;
@@ -362,8 +363,8 @@
if (kIsDebugBuild) {
// Double check that the counts line up with the size of the quicken info.
size_t quicken_count = 0;
- for (CodeItemIterator it(*code_item); !it.Done(); it.Advance()) {
- if (QuickenInfoTable::NeedsIndexForInstruction(&it.CurrentInstruction())) {
+ for (const DexInstructionPcPair& pair : code_item->Instructions()) {
+ if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) {
++quicken_count;
}
}
diff --git a/compiler/optimizing/block_builder.cc b/compiler/optimizing/block_builder.cc
index d7def77..595dd4d 100644
--- a/compiler/optimizing/block_builder.cc
+++ b/compiler/optimizing/block_builder.cc
@@ -76,9 +76,10 @@
// Iterate over all instructions and find branching instructions. Create blocks for
// the locations these instructions branch to.
- for (CodeItemIterator it(code_item_); !it.Done(); it.Advance()) {
- uint32_t dex_pc = it.CurrentDexPc();
- const Instruction& instruction = it.CurrentInstruction();
+ IterationRange<DexInstructionIterator> instructions = code_item_.Instructions();
+ for (const DexInstructionPcPair& pair : instructions) {
+ const uint32_t dex_pc = pair.DexPc();
+ const Instruction& instruction = pair.Inst();
if (instruction.IsBranch()) {
number_of_branches_++;
@@ -105,13 +106,13 @@
}
if (instruction.CanFlowThrough()) {
- if (it.IsLast()) {
+ DexInstructionIterator next(std::next(DexInstructionIterator(pair)));
+ if (next == instructions.end()) {
// In the normal case we should never hit this but someone can artificially forge a dex
// file to fall-through out the method code. In this case we bail out compilation.
return false;
- } else {
- MaybeCreateBlockAt(dex_pc + it.CurrentInstruction().SizeInCodeUnits());
}
+ MaybeCreateBlockAt(next.DexPc());
}
}
@@ -126,8 +127,9 @@
bool is_throwing_block = false;
// Calculate the qucikening index here instead of CreateBranchTargets since it's easier to
// calculate in dex_pc order.
- for (CodeItemIterator it(code_item_); !it.Done(); it.Advance()) {
- uint32_t dex_pc = it.CurrentDexPc();
+ for (const DexInstructionPcPair& pair : code_item_.Instructions()) {
+ const uint32_t dex_pc = pair.DexPc();
+ const Instruction& instruction = pair.Inst();
// Check if this dex_pc address starts a new basic block.
HBasicBlock* next_block = GetBlockAt(dex_pc);
@@ -144,7 +146,7 @@
graph_->AddBlock(block);
}
// Make sure to increment this before the continues.
- if (QuickenInfoTable::NeedsIndexForInstruction(&it.CurrentInstruction())) {
+ if (QuickenInfoTable::NeedsIndexForInstruction(&instruction)) {
++quicken_index;
}
@@ -153,8 +155,6 @@
continue;
}
- const Instruction& instruction = it.CurrentInstruction();
-
if (!is_throwing_block && IsThrowingDexInstruction(instruction)) {
DCHECK(!ContainsElement(throwing_blocks_, block));
is_throwing_block = true;
@@ -185,9 +185,9 @@
continue;
}
+ // Go to the next instruction in case we read dex PC below.
if (instruction.CanFlowThrough()) {
- uint32_t next_dex_pc = dex_pc + instruction.SizeInCodeUnits();
- block->AddSuccessor(GetBlockAt(next_dex_pc));
+ block->AddSuccessor(GetBlockAt(std::next(DexInstructionIterator(pair)).DexPc()));
}
// The basic block ends here. Do not add any more instructions.
@@ -229,7 +229,7 @@
}
}
- const Instruction& first = GetDexInstructionAt(code_item_, catch_block->GetDexPc());
+ const Instruction& first = code_item_.InstructionAt(catch_block->GetDexPc());
if (first.Opcode() == Instruction::MOVE_EXCEPTION) {
// Verifier guarantees that if a catch block begins with MOVE_EXCEPTION then
// it has no live normal predecessors.
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index 0f0be20..8e9b818 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -321,19 +321,19 @@
quicken_index = block_builder_->GetQuickenIndex(block_dex_pc);
}
- for (CodeItemIterator it(code_item_, block_dex_pc); !it.Done(); it.Advance()) {
+ for (const DexInstructionPcPair& pair : code_item_.Instructions(block_dex_pc)) {
if (current_block_ == nullptr) {
// The previous instruction ended this block.
break;
}
- uint32_t dex_pc = it.CurrentDexPc();
+ const uint32_t dex_pc = pair.DexPc();
if (dex_pc != block_dex_pc && FindBlockStartingAt(dex_pc) != nullptr) {
// This dex_pc starts a new basic block.
break;
}
- if (current_block_->IsTryBlock() && IsThrowingDexInstruction(it.CurrentInstruction())) {
+ if (current_block_->IsTryBlock() && IsThrowingDexInstruction(pair.Inst())) {
PropagateLocalsToCatchBlocks();
}
@@ -341,11 +341,11 @@
AppendInstruction(new (allocator_) HNativeDebugInfo(dex_pc));
}
- if (!ProcessDexInstruction(it.CurrentInstruction(), dex_pc, quicken_index)) {
+ if (!ProcessDexInstruction(pair.Inst(), dex_pc, quicken_index)) {
return false;
}
- if (QuickenInfoTable::NeedsIndexForInstruction(&it.CurrentInstruction())) {
+ if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) {
++quicken_index;
}
}
@@ -382,16 +382,15 @@
dex_file_->DecodeDebugPositionInfo(&code_item_, Callback::Position, locations);
// Instruction-specific tweaks.
IterationRange<DexInstructionIterator> instructions = code_item_.Instructions();
- for (DexInstructionIterator it = instructions.begin(); it != instructions.end(); ++it) {
- switch (it->Opcode()) {
+ for (const DexInstructionPcPair& inst : instructions) {
+ switch (inst->Opcode()) {
case Instruction::MOVE_EXCEPTION: {
// Stop in native debugger after the exception has been moved.
// The compiler also expects the move at the start of basic block so
// we do not want to interfere by inserting native-debug-info before it.
- locations->ClearBit(it.DexPc());
- DexInstructionIterator next = it;
- ++next;
- DCHECK(next != it);
+ locations->ClearBit(inst.DexPc());
+ DexInstructionIterator next = std::next(DexInstructionIterator(inst));
+ DCHECK(next.DexPc() != inst.DexPc());
if (next != instructions.end()) {
locations->SetBit(next.DexPc());
}