summaryrefslogtreecommitdiff
path: root/compiler/optimizing/block_builder.cc
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2017-11-07 00:08:52 -0800
committer Mathieu Chartier <mathieuc@google.com> 2017-11-07 13:15:41 -0800
commit0021feb36ca7021e2c255e6eaf16b967180290c6 (patch)
tree43f1ce8f6d91630a831d03b51a465d57c2a47119 /compiler/optimizing/block_builder.cc
parent550c0aee52bf8981dfe1d22d3b661d61e80cc7ee (diff)
Delete CodeItemIterator
Replace uses with DexInstructionIterator. Bug: 63756964 Test: test-art-host-gtest Change-Id: I28c839c372edcb60583867355d46b14f8752d41b
Diffstat (limited to 'compiler/optimizing/block_builder.cc')
-rw-r--r--compiler/optimizing/block_builder.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/compiler/optimizing/block_builder.cc b/compiler/optimizing/block_builder.cc
index d7def774fd..595dd4d226 100644
--- a/compiler/optimizing/block_builder.cc
+++ b/compiler/optimizing/block_builder.cc
@@ -76,9 +76,10 @@ bool HBasicBlockBuilder::CreateBranchTargets() {
// 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 @@ bool HBasicBlockBuilder::CreateBranchTargets() {
}
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 @@ void HBasicBlockBuilder::ConnectBasicBlocks() {
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 @@ void HBasicBlockBuilder::ConnectBasicBlocks() {
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 @@ void HBasicBlockBuilder::ConnectBasicBlocks() {
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 @@ void HBasicBlockBuilder::ConnectBasicBlocks() {
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 @@ bool HBasicBlockBuilder::MightHaveLiveNormalPredecessors(HBasicBlock* catch_bloc
}
}
- 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.