blob: 9d9551449813e69736a5ad27804c1d7e92605193 [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.cf.LoadStoreHelper;
import com.android.tools.r8.cf.TypeVerificationHelper;
import com.android.tools.r8.cf.code.CfInvokeDynamic;
import com.android.tools.r8.code.InvokeCustomRange;
import com.android.tools.r8.graph.DexCallSite;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.conversion.CfBuilder;
import com.android.tools.r8.ir.conversion.DexBuilder;
import com.android.tools.r8.ir.optimize.Inliner.Constraint;
import com.android.tools.r8.shaking.Enqueuer.AppInfoWithLiveness;
import java.util.List;
public final class InvokeCustom extends Invoke {
private final DexCallSite callSite;
public InvokeCustom(DexCallSite callSite, Value result, List<Value> arguments) {
super(result, arguments);
assert callSite != null;
this.callSite = callSite;
}
@Override
public DexType getReturnType() {
return callSite.methodProto.returnType;
}
public DexCallSite getCallSite() {
return callSite;
}
@Override
public Type getType() {
return Type.CUSTOM;
}
@Override
protected String getTypeString() {
return "Custom";
}
@Override
public String toString() {
return super.toString() + "; call site: " + callSite.toSourceString();
}
@Override
public void buildDex(DexBuilder builder) {
com.android.tools.r8.code.Instruction instruction;
int argumentRegisters = requiredArgumentRegisters();
builder.requestOutgoingRegisters(argumentRegisters);
if (needsRangedInvoke()) {
assert argumentsConsecutive(builder);
int firstRegister = argumentRegisterValue(0, builder);
instruction = new InvokeCustomRange(firstRegister, argumentRegisters, getCallSite());
} else {
int[] individualArgumentRegisters = new int[5];
int argumentRegistersCount = fillArgumentRegisters(builder, individualArgumentRegisters);
instruction = new com.android.tools.r8.code.InvokeCustom(
argumentRegistersCount,
getCallSite(),
individualArgumentRegisters[0], // C
individualArgumentRegisters[1], // D
individualArgumentRegisters[2], // E
individualArgumentRegisters[3], // F
individualArgumentRegisters[4]); // G
}
addInvokeAndMoveResult(instruction, builder);
}
@Override
public void buildCf(CfBuilder builder) {
builder.add(new CfInvokeDynamic(getCallSite()));
}
@Override
public boolean identicalNonValueNonPositionParts(Instruction other) {
return other.isInvokeCustom() && callSite == other.asInvokeCustom().callSite;
}
@Override
public int compareNonValueParts(Instruction other) {
assert other.isInvokeCustom();
assert false : "Not supported";
return 0;
}
@Override
public boolean isInvokeCustom() {
return true;
}
@Override
public InvokeCustom asInvokeCustom() {
return this;
}
@Override
public Constraint inliningConstraint(AppInfoWithLiveness info, DexType invocationContext) {
return Constraint.NEVER;
}
@Override
public void insertLoadAndStores(InstructionListIterator it, LoadStoreHelper helper) {
// Essentially the same as InvokeMethod but with call site's method proto
// instead of a static called method.
helper.loadInValues(this, it);
if (getCallSite().methodProto.returnType.isVoidType()) {
return;
}
if (outValue == null) {
helper.popOutType(getCallSite().methodProto.returnType, this, it);
} else {
assert outValue.isUsed();
helper.storeOutValue(this, it);
}
}
@Override
public boolean hasInvariantVerificationType() {
return true;
}
@Override
public DexType computeVerificationType(TypeVerificationHelper helper) {
return getCallSite().methodProto.returnType;
}
}