Factorize instructionCount usages
- When instructionCount calls are not factorized, the method appears
into the hot spots when running IncrementalDexingBenchmark.
Bug: 74712202
Change-Id: I04c5681c1ac3ce58dca8d34a929abff7d7cce0c8
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
index 20051f9..fbd531c 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java
@@ -327,7 +327,8 @@
targets.put(INITIAL_BLOCK_OFFSET, new BlockInfo());
// Process reachable code paths starting from instruction 0.
- processedInstructions = new boolean[source.instructionCount()];
+ int instCount = source.instructionCount();
+ processedInstructions = new boolean[instCount];
traceBlocksWorklist.add(0);
while (!traceBlocksWorklist.isEmpty()) {
int startOfBlockOffset = traceBlocksWorklist.remove();
@@ -337,17 +338,17 @@
continue;
}
// Process each instruction until the block is closed.
- for (int index = startOfBlockIndex; index < source.instructionCount(); ++index) {
+ for (int index = startOfBlockIndex; index < instCount; ++index) {
markIndexProcessed(index);
int closedAt = source.traceInstruction(index, this);
if (closedAt != -1) {
- if (closedAt + 1 < source.instructionCount()) {
+ if (closedAt + 1 < instCount) {
ensureBlockWithoutEnqueuing(source.instructionOffset(closedAt + 1));
}
break;
}
// If the next instruction starts a block, fall through to it.
- if (index + 1 < source.instructionCount()) {
+ if (index + 1 < instCount) {
int nextOffset = source.instructionOffset(index + 1);
if (targets.get(nextOffset) != null) {
ensureNormalSuccessorBlock(startOfBlockOffset, nextOffset);
@@ -491,7 +492,8 @@
continue;
}
// Build IR for each dex instruction in the block.
- for (int i = item.firstInstructionIndex; i < source.instructionCount(); ++i) {
+ int instCount = source.instructionCount();
+ for (int i = item.firstInstructionIndex; i < instCount; ++i) {
if (currentBlock == null) {
break;
}
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/JarSourceCode.java b/src/main/java/com/android/tools/r8/ir/conversion/JarSourceCode.java
index b584448..e3883f6 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/JarSourceCode.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/JarSourceCode.java
@@ -428,11 +428,12 @@
for (JarStateWorklistItem item = worklist.poll(); item != null; item = worklist.poll()) {
state.restoreState(item.instructionIndex);
// Iterate each of the instructions in the block to compute the outgoing JarState.
- for (int i = item.instructionIndex; i <= instructionCount(); ++i) {
+ int instCount = instructionCount();
+ for (int i = item.instructionIndex; i <= instCount; ++i) {
// If we are at the end of the instruction stream or if we have reached the start
// of a new block, propagate the state to all successors and add the ones
// that changed to the worklist.
- if (i == instructionCount() || (i != item.instructionIndex && CFG.containsKey(i))) {
+ if (i == instCount || (i != item.instructionIndex && CFG.containsKey(i))) {
item.blockInfo.normalSuccessors.iterator().forEachRemaining(offset -> {
if (state.recordStateForTarget(offset)) {
if (offset >= 0) {