blob: f5d95bf3e22bc5de00aafcca8dda83a65e266f01 [file] [log] [blame]
// Copyright (c) 2018, 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.errors.Unreachable;
import com.android.tools.r8.graph.AppInfo;
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.ir.analysis.type.TypeLatticeElement;
import com.android.tools.r8.ir.conversion.CfBuilder;
import com.android.tools.r8.ir.conversion.DexBuilder;
import com.android.tools.r8.ir.optimize.Inliner.ConstraintWithTarget;
import com.android.tools.r8.ir.optimize.InliningConstraints;
public class Assume extends Instruction {
private final static String ERROR_MESSAGE = "This fake IR should be removed after inlining.";
final Instruction origin;
public Assume(Value dest, Value src, Instruction origin) {
super(dest, src);
assert !src.isNeverNull();
this.origin = origin;
}
@Override
public <T> T accept(InstructionVisitor<T> visitor) {
return visitor.visit(this);
}
public Value dest() {
return outValue;
}
public Value src() {
return inValues.get(0);
}
public Instruction origin() {
return origin;
}
@Override
public boolean isNonNull() {
return true;
}
@Override
public Assume asNonNull() {
return this;
}
@Override
public boolean isIntroducingAnAlias() {
return true;
}
@Override
public boolean couldIntroduceAnAlias() {
return true;
}
@Override
public Value getAliasForOutValue() {
return src();
}
@Override
public void buildDex(DexBuilder builder) {
throw new Unreachable(ERROR_MESSAGE);
}
@Override
public void buildCf(CfBuilder builder) {
throw new Unreachable(ERROR_MESSAGE);
}
@Override
public int maxInValueRegister() {
throw new Unreachable(ERROR_MESSAGE);
}
@Override
public int maxOutValueRegister() {
throw new Unreachable(ERROR_MESSAGE);
}
@Override
public boolean isOutConstant() {
return false;
}
@Override
public boolean identicalNonValueNonPositionParts(Instruction other) {
return other.isNonNull();
}
@Override
public ConstraintWithTarget inliningConstraint(
InliningConstraints inliningConstraints, DexType invocationContext) {
return inliningConstraints.forNonNull();
}
@Override
public TypeLatticeElement evaluate(AppView<? extends AppInfo> appView) {
assert src().getTypeLattice().isReference();
return src().getTypeLattice().asReferenceTypeLatticeElement().asNotNull();
}
@Override
public boolean hasInvariantOutType() {
return false;
}
@Override
public void insertLoadAndStores(InstructionListIterator it, LoadStoreHelper helper) {
throw new Unreachable(ERROR_MESSAGE);
}
}