| // Copyright (c) 2022, 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.errors.Unreachable; |
| import com.android.tools.r8.graph.AppView; |
| import com.android.tools.r8.graph.DexType; |
| import com.android.tools.r8.graph.ProgramMethod; |
| import com.android.tools.r8.ir.analysis.type.TypeElement; |
| import com.android.tools.r8.ir.conversion.CfBuilder; |
| import com.android.tools.r8.ir.conversion.DexBuilder; |
| import com.android.tools.r8.ir.optimize.DeadCodeRemover.DeadInstructionResult; |
| import com.android.tools.r8.ir.optimize.Inliner.ConstraintWithTarget; |
| import com.android.tools.r8.ir.optimize.InliningConstraints; |
| |
| /** |
| * A special instruction to load the value of an argument that has been removed as a result of code |
| * optimizations. Only used in R8 between the point of building IR and lens code rewriting. |
| */ |
| public class UnusedArgument extends Instruction { |
| |
| public UnusedArgument(Value outValue) { |
| super(outValue); |
| } |
| |
| @Override |
| public <T> T accept(InstructionVisitor<T> visitor) { |
| return visitor.visit(this); |
| } |
| |
| @Override |
| public void buildCf(CfBuilder builder) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public void buildDex(DexBuilder builder) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public DeadInstructionResult canBeDeadCode(AppView<?> appview, IRCode code) { |
| return DeadInstructionResult.deadIfOutValueIsDead(); |
| } |
| |
| @Override |
| public DexType computeVerificationType(AppView<?> appView, TypeVerificationHelper helper) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public TypeElement evaluate(AppView<?> appView) { |
| return outValue.getType(); |
| } |
| |
| @Override |
| public boolean hasInvariantOutType() { |
| return true; |
| } |
| |
| @Override |
| public boolean identicalNonValueNonPositionParts(Instruction other) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public ConstraintWithTarget inliningConstraint( |
| InliningConstraints inliningConstraints, ProgramMethod context) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public boolean instructionMayTriggerMethodInvocation(AppView<?> appView, ProgramMethod context) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public void insertLoadAndStores(InstructionListIterator it, LoadStoreHelper helper) { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public boolean isUnusedArgument() { |
| return true; |
| } |
| |
| @Override |
| public UnusedArgument asUnusedArgument() { |
| return this; |
| } |
| |
| @Override |
| public int maxInValueRegister() { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public int maxOutValueRegister() { |
| throw new Unreachable(); |
| } |
| |
| @Override |
| public int opcode() { |
| return Opcodes.UNUSED_ARGUMENT; |
| } |
| } |