| // 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.InvokeDirectRange; |
| import com.android.tools.r8.dex.Constants; |
| 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 com.android.tools.r8.ir.optimize.Inliner.InlineAction; |
| import com.android.tools.r8.ir.optimize.InliningOracle; |
| import java.util.List; |
| |
| public class InvokeDirect extends InvokeMethod { |
| |
| public InvokeDirect(DexMethod target, Value result, List<Value> arguments) { |
| super(target, result, arguments); |
| } |
| |
| @Override |
| public Type getType() { |
| return Type.DIRECT; |
| } |
| |
| @Override |
| protected String getTypeString() { |
| return "Direct"; |
| } |
| |
| @Override |
| public DexEncodedMethod computeSingleTarget(AppInfoWithSubtyping appInfo) { |
| return appInfo.lookupDirectTarget(getInvokedMethod()); |
| } |
| |
| @Override |
| public void buildDex(DexBuilder builder) { |
| com.android.tools.r8.code.Instruction instruction; |
| int argumentRegisters = requiredArgumentRegisters(); |
| builder.requestOutgoingRegisters(argumentRegisters); |
| if (argumentRegisters > 5 || hasHighArgumentRegister(builder)) { |
| assert argumentsConsecutive(builder); |
| int firstRegister = argumentRegisterValue(0, builder); |
| instruction = new InvokeDirectRange(firstRegister, argumentRegisters, getInvokedMethod()); |
| } else { |
| int[] individualArgumentRegisters = new int[5]; |
| int argumentRegistersCount = fillArgumentRegisters(builder, individualArgumentRegisters); |
| instruction = new com.android.tools.r8.code.InvokeDirect( |
| argumentRegistersCount, |
| getInvokedMethod(), |
| individualArgumentRegisters[0], // C |
| individualArgumentRegisters[1], // D |
| individualArgumentRegisters[2], // E |
| individualArgumentRegisters[3], // F |
| individualArgumentRegisters[4]); // G |
| } |
| addInvokeAndMoveResult(instruction, builder); |
| } |
| |
| /** |
| * Two invokes of a constructor are only allowed to be considered equal if the object |
| * they are initializing is the same. Art rejects code that has objects created by |
| * different new-instance instructions flow to one constructor invoke. |
| */ |
| public boolean sameConstructorReceiverValue(Invoke other) { |
| if (!getInvokedMethod().name.toString().equals(Constants.INSTANCE_INITIALIZER_NAME)) { |
| return true; |
| } |
| return inValues.get(0) == other.inValues.get(0); |
| } |
| |
| @Override |
| public boolean identicalNonValueParts(Instruction other) { |
| if (!other.isInvokeDirect()) { |
| return false; |
| } |
| return super.identicalNonValueParts(other); |
| } |
| |
| @Override |
| public boolean isInvokeDirect() { |
| return true; |
| } |
| |
| @Override |
| public InvokeDirect asInvokeDirect() { |
| return this; |
| } |
| |
| @Override |
| public InlineAction computeInlining(InliningOracle decider) { |
| return decider.computeForInvokeDirect(this); |
| } |
| } |