blob: d909144bce29b1e44557b14af4abb248a75944c8 [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.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;
import java.util.function.Function;
public class NonNull extends Instruction {
private final static String ERROR_MESSAGE = "This fake IR should be removed after inlining.";
final Instruction origin;
public NonNull(Value dest, Value src, Instruction origin) {
super(dest, src);
assert !src.isNeverNull();
dest.markNeverNull();
this.origin = origin;
}
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 NonNull asNonNull() {
return this;
}
@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 int compareNonValueParts(Instruction other) {
assert other instanceof NonNull;
return 0;
}
@Override
public ConstraintWithTarget inliningConstraint(
InliningConstraints inliningConstraints, DexType invocationContext) {
return inliningConstraints.forNonNull();
}
@Override
public TypeLatticeElement evaluate(
AppInfo appInfo, Function<Value, TypeLatticeElement> getLatticeElement) {
TypeLatticeElement l = getLatticeElement.apply(src());
if (l.isClassTypeLatticeElement() || l.isArrayTypeLatticeElement()) {
return l.asNonNullable();
}
return l;
}
@Override
public void insertLoadAndStores(InstructionListIterator it, LoadStoreHelper helper) {
throw new Unreachable(ERROR_MESSAGE);
}
}