blob: a639ba1101a49d79c88ef1c292b5d89de377630f [file] [log] [blame]
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.code;
import com.android.tools.r8.code.InvokeInterfaceRange;
import com.android.tools.r8.graph.AppInfo;
import com.android.tools.r8.graph.AppInfoWithSubtyping;
import com.android.tools.r8.graph.DexEncodedMethod;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.ir.conversion.DexBuilder;
import java.util.List;
public class InvokeInterface extends InvokeMethodWithReceiver {
public InvokeInterface(DexMethod target, Value result, List<Value> arguments) {
super(target, result, arguments);
}
@Override
public Type getType() {
return Type.INTERFACE;
}
@Override
protected String getTypeString() {
return "Interface";
}
@Override
public DexEncodedMethod computeSingleTarget(AppInfoWithSubtyping appInfo) {
return appInfo.lookupSingleInterfaceTarget(getInvokedMethod());
}
@Override
public void buildDex(DexBuilder builder) {
com.android.tools.r8.code.Instruction instruction;
int argumentRegisters = requiredArgumentRegisters();
builder.requestOutgoingRegisters(argumentRegisters);
if (needsRangedInvoke(builder)) {
assert argumentsConsecutive(builder);
int firstRegister = argumentRegisterValue(0, builder);
instruction = new InvokeInterfaceRange(firstRegister, argumentRegisters, getInvokedMethod());
} else {
int[] individualArgumentRegisters = new int[5];
int argumentRegistersCount = fillArgumentRegisters(builder, individualArgumentRegisters);
instruction = new com.android.tools.r8.code.InvokeInterface(
argumentRegistersCount,
getInvokedMethod(),
individualArgumentRegisters[0], // C
individualArgumentRegisters[1], // D
individualArgumentRegisters[2], // E
individualArgumentRegisters[3], // F
individualArgumentRegisters[4]); // G
}
addInvokeAndMoveResult(instruction, builder);
}
@Override
public boolean identicalNonValueParts(Instruction other) {
if (!other.isInvokeInterface()) {
return false;
}
return super.identicalNonValueParts(other);
}
@Override
public boolean isInvokeInterface() {
return true;
}
@Override
public InvokeInterface asInvokeInterface() {
return this;
}
@Override
DexEncodedMethod lookupTarget(AppInfo appInfo) {
DexMethod method = getInvokedMethod();
return appInfo.lookupVirtualDefinition(method.holder, method);
}
}