Fix inlining of methods with static field accesses.
Bug:
Change-Id: Ie86127a4440bb8273038235f4e5722563c55e82e
diff --git a/src/main/java/com/android/tools/r8/ir/code/FieldInstruction.java b/src/main/java/com/android/tools/r8/ir/code/FieldInstruction.java
index 0b8d876..065d3df 100644
--- a/src/main/java/com/android/tools/r8/ir/code/FieldInstruction.java
+++ b/src/main/java/com/android/tools/r8/ir/code/FieldInstruction.java
@@ -41,11 +41,13 @@
return field;
}
+ abstract DexEncodedField lookupTarget(DexType type, AppInfo appInfo);
+
@Override
public Constraint inliningConstraint(AppInfo info, DexType holder) {
// Resolve the field if possible and decide whether the instruction can inlined.
DexType fieldHolder = field.getHolder();
- DexEncodedField target = info.lookupInstanceTarget(fieldHolder, field);
+ DexEncodedField target = lookupTarget(fieldHolder, info);
DexClass fieldClass = info.definitionFor(fieldHolder);
if ((target != null) && (fieldClass != null) && !fieldClass.isLibraryClass()) {
DexAccessFlags flags = target.accessFlags;
diff --git a/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java b/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
index f38614f..1d9e853 100644
--- a/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
+++ b/src/main/java/com/android/tools/r8/ir/code/InstanceGet.java
@@ -13,7 +13,10 @@
import com.android.tools.r8.code.IgetWide;
import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.Unreachable;
+import com.android.tools.r8.graph.AppInfo;
+import com.android.tools.r8.graph.DexEncodedField;
import com.android.tools.r8.graph.DexField;
+import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.DexBuilder;
public class InstanceGet extends FieldInstruction {
@@ -95,6 +98,11 @@
}
@Override
+ DexEncodedField lookupTarget(DexType type, AppInfo appInfo) {
+ return appInfo.lookupInstanceTarget(type, field);
+ }
+
+ @Override
public boolean isInstanceGet() {
return true;
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/InstancePut.java b/src/main/java/com/android/tools/r8/ir/code/InstancePut.java
index 7ec8eaf..2642de1 100644
--- a/src/main/java/com/android/tools/r8/ir/code/InstancePut.java
+++ b/src/main/java/com/android/tools/r8/ir/code/InstancePut.java
@@ -13,7 +13,10 @@
import com.android.tools.r8.code.IputWide;
import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.Unreachable;
+import com.android.tools.r8.graph.AppInfo;
+import com.android.tools.r8.graph.DexEncodedField;
import com.android.tools.r8.graph.DexField;
+import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.DexBuilder;
import java.util.List;
@@ -96,6 +99,11 @@
}
@Override
+ DexEncodedField lookupTarget(DexType type, AppInfo appInfo) {
+ return appInfo.lookupInstanceTarget(type, field);
+ }
+
+ @Override
public boolean isInstancePut() {
return true;
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/StaticGet.java b/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
index ad340c2..bb79d5e 100644
--- a/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
+++ b/src/main/java/com/android/tools/r8/ir/code/StaticGet.java
@@ -12,7 +12,10 @@
import com.android.tools.r8.code.SgetWide;
import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.Unreachable;
+import com.android.tools.r8.graph.AppInfo;
+import com.android.tools.r8.graph.DexEncodedField;
import com.android.tools.r8.graph.DexField;
+import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.DexBuilder;
public class StaticGet extends FieldInstruction {
@@ -91,6 +94,11 @@
}
@Override
+ DexEncodedField lookupTarget(DexType type, AppInfo appInfo) {
+ return appInfo.lookupStaticTarget(type, field);
+ }
+
+ @Override
public String toString() {
return super.toString() + "; field: " + field.toSourceString();
}
diff --git a/src/main/java/com/android/tools/r8/ir/code/StaticPut.java b/src/main/java/com/android/tools/r8/ir/code/StaticPut.java
index e8a1fed..6736d7e 100644
--- a/src/main/java/com/android/tools/r8/ir/code/StaticPut.java
+++ b/src/main/java/com/android/tools/r8/ir/code/StaticPut.java
@@ -12,7 +12,10 @@
import com.android.tools.r8.code.SputWide;
import com.android.tools.r8.dex.Constants;
import com.android.tools.r8.errors.Unreachable;
+import com.android.tools.r8.graph.AppInfo;
+import com.android.tools.r8.graph.DexEncodedField;
import com.android.tools.r8.graph.DexField;
+import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.DexBuilder;
public class StaticPut extends FieldInstruction {
@@ -93,6 +96,11 @@
}
@Override
+ DexEncodedField lookupTarget(DexType type, AppInfo appInfo) {
+ return appInfo.lookupStaticTarget(type, field);
+ }
+
+ @Override
public String toString() {
return super.toString() + "; field: " + field.toSourceString();
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/Inliner.java b/src/main/java/com/android/tools/r8/ir/optimize/Inliner.java
index 4ede5a8..a2b3ba2 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/Inliner.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/Inliner.java
@@ -302,9 +302,9 @@
continue;
}
// Ensure the container is compatible with the target.
- if (!forceInline
- && !result.target.isPublicInlining()
- && (method.method.getHolder() != result.target.method.getHolder())) {
+ if (!forceInline
+ && !result.target.isPublicInlining()
+ && (method.method.getHolder() != result.target.method.getHolder())) {
continue;
}
DexType downcast = null;