aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorMads Ager <ager@google.com>2017-06-02 14:44:20 +0200
committerMads Ager <ager@google.com>2017-06-02 14:44:20 +0200
commitea9abace14338023b297c895abfc617bb3995bc0 (patch)
treefeb4bffb2a028f420e819225e54e709ea970babc /src/main/java/com
parent5b123416b15b474bb298c55e2c91d9d993d29dc1 (diff)
downloadr8-ea9abace14338023b297c895abfc617bb3995bc0.tar.gz
Remove the original register field from values.
The only bit that is a little funky here is the mapping to and from negative register values for incomplete phis on exceptional edges. R=sgjesse@google.com, zerny@google.com Change-Id: If4aa465c2ea64f0f7177f3f37fee162e55fe2408
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/BasicBlock.java13
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/ConstNumber.java1
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/FixedRegisterValue.java2
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/IRCode.java2
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/Phi.java9
-rw-r--r--src/main/java/com/android/tools/r8/ir/code/Value.java41
-rw-r--r--src/main/java/com/android/tools/r8/ir/conversion/IRBuilder.java12
-rw-r--r--src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java2
8 files changed, 38 insertions, 44 deletions
diff --git a/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java b/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
index 35cf80828..232e0ff6d 100644
--- a/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
+++ b/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
@@ -19,6 +19,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
@@ -632,8 +633,12 @@ public class BasicBlock {
assert unfilledPredecessorsCount > 0;
if (--unfilledPredecessorsCount == 0) {
assert estimatedPredecessorsCount == predecessors.size();
- for (Phi phi : incompletePhis.values()) {
- phi.addOperands(builder);
+ for (Entry<Integer, Phi> entry : incompletePhis.entrySet()) {
+ int register = entry.getKey();
+ if (register < 0) {
+ register = onThrowValueRegister(register);
+ }
+ entry.getValue().addOperands(builder, register);
}
sealed = true;
incompletePhis.clear();
@@ -1087,7 +1092,7 @@ public class BasicBlock {
newPredecessors.add(newBlock);
if (hasMoveException) {
Value value = new Value(
- valueNumberGenerator.next(), -1, MoveType.OBJECT, move.getDebugInfo());
+ valueNumberGenerator.next(), MoveType.OBJECT, move.getDebugInfo());
values.add(value);
newBlock.add(new MoveException(value));
}
@@ -1105,7 +1110,7 @@ public class BasicBlock {
// Insert a phi for the move-exception value.
if (hasMoveException) {
Phi phi = new Phi(valueNumberGenerator.next(),
- -1, this, MoveType.OBJECT, move.getLocalInfo());
+ this, MoveType.OBJECT, move.getLocalInfo());
phi.addOperands(values);
move.outValue().replaceUsers(phi);
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/ConstNumber.java b/src/main/java/com/android/tools/r8/ir/code/ConstNumber.java
index 8aff14a1e..451832f47 100644
--- a/src/main/java/com/android/tools/r8/ir/code/ConstNumber.java
+++ b/src/main/java/com/android/tools/r8/ir/code/ConstNumber.java
@@ -38,7 +38,6 @@ public class ConstNumber extends ConstInstruction {
Value newValue =
new Value(
code.valueNumberGenerator.next(),
- original.outValue().getOriginalRegister(),
original.outType(),
original.getDebugInfo());
return new ConstNumber(original.type, newValue, original.getRawValue());
diff --git a/src/main/java/com/android/tools/r8/ir/code/FixedRegisterValue.java b/src/main/java/com/android/tools/r8/ir/code/FixedRegisterValue.java
index c63d32343..c5a7bbb87 100644
--- a/src/main/java/com/android/tools/r8/ir/code/FixedRegisterValue.java
+++ b/src/main/java/com/android/tools/r8/ir/code/FixedRegisterValue.java
@@ -10,7 +10,7 @@ public class FixedRegisterValue extends Value {
public FixedRegisterValue(MoveType type, int register) {
// Set local info to null since these values are never representatives of live-ranges.
- super(-1, -1, type, null);
+ super(-1, type, null);
setNeedsRegister(true);
this.register = register;
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/IRCode.java b/src/main/java/com/android/tools/r8/ir/code/IRCode.java
index c905a0f48..3ff062422 100644
--- a/src/main/java/com/android/tools/r8/ir/code/IRCode.java
+++ b/src/main/java/com/android/tools/r8/ir/code/IRCode.java
@@ -349,7 +349,7 @@ public class IRCode {
}
public Value createValue(MoveType moveType, Value.DebugInfo debugInfo) {
- return new Value(valueNumberGenerator.next(), -1, moveType, debugInfo);
+ return new Value(valueNumberGenerator.next(), moveType, debugInfo);
}
public Value createValue(MoveType moveType) {
diff --git a/src/main/java/com/android/tools/r8/ir/code/Phi.java b/src/main/java/com/android/tools/r8/ir/code/Phi.java
index 0d74321fd..5912f0f3d 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Phi.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Phi.java
@@ -34,8 +34,8 @@ public class Phi extends Value {
// computation of the phi until all operands are known.
private MoveType outType = null;
- public Phi(int number, int register, BasicBlock block, MoveType type, DebugLocalInfo local) {
- super(number, register, type, local == null ? null : new DebugInfo(local, null));
+ public Phi(int number, BasicBlock block, MoveType type, DebugLocalInfo local) {
+ super(number, type, local == null ? null : new DebugInfo(local, null));
this.block = block;
block.addPhi(this);
}
@@ -54,7 +54,7 @@ public class Phi extends Value {
return block;
}
- public void addOperands(IRBuilder builder) {
+ public void addOperands(IRBuilder builder, int register) {
// Phi operands are only filled in once to complete the phi. Some phis are incomplete for a
// period of time to break cycles. When the cycle has been resolved they are completed
// exactly once by adding the operands.
@@ -63,8 +63,7 @@ public class Phi extends Value {
for (BasicBlock pred : block.getPredecessors()) {
EdgeType edgeType = pred.getEdgeType(block);
// Since this read has been delayed we must provide the local info for the value.
- Value operand = builder.readRegister(
- getOriginalRegister(), pred, edgeType, type, getLocalInfo());
+ Value operand = builder.readRegister(register, pred, edgeType, type, getLocalInfo());
canBeNull |= operand.canBeNull();
appendOperand(operand);
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/Value.java b/src/main/java/com/android/tools/r8/ir/code/Value.java
index 2b7c6474a..6487631b7 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Value.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Value.java
@@ -53,11 +53,10 @@ public class Value {
}
}
- public static final Value UNDEFINED = new Value(-1, -1, MoveType.OBJECT, null);
+ public static final Value UNDEFINED = new Value(-1, MoveType.OBJECT, null);
protected final int number;
protected MoveType type;
- private int originalRegister;
public Instruction definition = null;
private LinkedList<Instruction> users = new LinkedList<>();
private Set<Instruction> uniqueUsers = null;
@@ -73,10 +72,9 @@ public class Value {
private LongInterval valueRange;
private DebugData debugData;
- public Value(int number, int originalRegister, MoveType type, DebugInfo debugInfo) {
+ public Value(int number, MoveType type, DebugInfo debugInfo) {
this.number = number;
this.type = type;
- this.originalRegister = originalRegister;
this.debugData = debugInfo == null ? null : new DebugData(debugInfo);
}
@@ -92,10 +90,6 @@ public class Value {
return number;
}
- public int getOriginalRegister() {
- return originalRegister;
- }
-
public int requiredRegisters() {
return type.requiredRegisters();
}
@@ -374,26 +368,23 @@ public class Value {
StringBuilder builder = new StringBuilder();
builder.append("v");
builder.append(number);
- builder.append("(");
- if (definition != null && isConstant()) {
- ConstNumber constNumber = getConstInstruction().asConstNumber();
- if (constNumber.outType() == MoveType.SINGLE) {
- builder.append((int) constNumber.getRawValue());
- } else {
- builder.append(constNumber.getRawValue());
+ boolean isConstant = definition != null && isConstant();
+ boolean hasLocalInfo = getLocalInfo() != null;
+ if (isConstant || hasLocalInfo) {
+ builder.append("(");
+ if (isConstant) {
+ ConstNumber constNumber = getConstInstruction().asConstNumber();
+ if (constNumber.outType() == MoveType.SINGLE) {
+ builder.append((int) constNumber.getRawValue());
+ } else {
+ builder.append(constNumber.getRawValue());
+ }
}
- } else {
- if (originalRegister >= 0) {
- builder.append("r");
- builder.append(originalRegister);
- } else {
- builder.append("_");
+ if (hasLocalInfo) {
+ builder.append(", ").append(getLocalInfo());
}
+ builder.append(")");
}
- if (getLocalInfo() != null) {
- builder.append(", ").append(getLocalInfo());
- }
- builder.append(")");
if (valueRange != null) {
builder.append(valueRange);
}
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 b92ff7174..bd8a46909 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
@@ -1379,7 +1379,7 @@ public class IRBuilder {
Value value;
if (!block.isSealed()) {
assert !blocks.isEmpty() : "No write to " + register;
- Phi phi = new Phi(valueNumberGenerator.next(), register, block, type, local);
+ Phi phi = new Phi(valueNumberGenerator.next(), block, type, local);
block.addIncompletePhi(register, phi, readingEdge);
value = phi;
} else if (block.getPredecessors().size() == 1) {
@@ -1388,11 +1388,11 @@ public class IRBuilder {
EdgeType edgeType = pred.getEdgeType(block);
value = readRegister(register, pred, edgeType, type, local);
} else {
- Phi phi = new Phi(valueNumberGenerator.next(), register, block, type, local);
+ Phi phi = new Phi(valueNumberGenerator.next(), block, type, local);
// We need to write the phi before adding operands to break cycles. If the phi is trivial
// and is removed by addOperands, the definition is overwritten and looked up again below.
block.updateCurrentDefinition(register, phi, readingEdge);
- phi.addOperands(this);
+ phi.addOperands(this, register);
// Lookup the value for the register again at this point. Recursive trivial
// phi removal could have simplified what we wanted to return here.
value = block.readCurrentDefinition(register, readingEdge);
@@ -1406,7 +1406,7 @@ public class IRBuilder {
}
public Value readLiteral(NumericType type, long constant) {
- Value value = new Value(valueNumberGenerator.next(), -1, MoveType.fromNumericType(type), null);
+ Value value = new Value(valueNumberGenerator.next(), MoveType.fromNumericType(type), null);
add(new ConstNumber(ConstType.fromNumericType(type), value, constant));
return value;
}
@@ -1415,7 +1415,7 @@ public class IRBuilder {
// See addDebugLocalStart and addDebugLocalEnd.
private Value writeRegister(int register, MoveType type, ThrowingInfo throwing, DebugInfo info) {
checkRegister(register);
- Value value = new Value(valueNumberGenerator.next(), register, type, info);
+ Value value = new Value(valueNumberGenerator.next(), type, info);
currentBlock.writeCurrentDefinition(register, value, throwing);
return value;
}
@@ -1610,7 +1610,7 @@ public class IRBuilder {
MoveType returnType = origReturn.getReturnType();
assert origReturn.getLocalInfo() == null;
phi = new Phi(
- valueNumberGenerator.next(), -1, normalExitBlock, returnValue.outType(), null);
+ valueNumberGenerator.next(), normalExitBlock, returnValue.outType(), null);
normalExitBlock.add(new Return(phi, returnType));
assert returnType == MoveType.fromDexType(method.method.proto.returnType);
}
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
index 3ccf2b35d..a981990ec 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
@@ -1726,7 +1726,7 @@ public class LinearScanRegisterAllocator implements RegisterAllocator {
}
private Value createValue(MoveType type, DebugInfo debugInfo) {
- Value value = new Value(code.valueNumberGenerator.next(), NO_REGISTER, type, debugInfo);
+ Value value = code.createValue(type, debugInfo);
value.setNeedsRegister(true);
return value;
}