blob: 5a0d3cf4a8018f605695c937e8ee9e7d277bb357 [file] [log] [blame]
// Copyright (c) 2020, 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.analysis.inlining;
import com.android.tools.r8.ir.code.InvokeMethod;
import com.android.tools.r8.ir.code.Value;
import it.unimi.dsi.fastutil.ints.IntList;
/** Constraint that is satisfied if a specific argument is always null. */
public class NullSimpleInliningConstraint extends SimpleInliningArgumentConstraint {
private NullSimpleInliningConstraint(int argumentIndex) {
super(argumentIndex);
}
static NullSimpleInliningConstraint create(
int argumentIndex, SimpleInliningConstraintFactory witness) {
assert witness != null;
return new NullSimpleInliningConstraint(argumentIndex);
}
@Override
public boolean isNull() {
return true;
}
@Override
public boolean isSatisfied(InvokeMethod invoke) {
// Take the root value to also deal with the following case, which may happen in dead code,
// where v1 is actually guaranteed to be null, despite the value's type being non-null:
// v0 <- ConstNumber 0
// v1 <- AssumeNotNull v0
Value argumentRoot = getArgument(invoke).getAliasedValue();
assert argumentRoot.getType().isReferenceType();
return argumentRoot.getType().isDefinitelyNull();
}
@Override
public SimpleInliningConstraint fixupAfterRemovingThisParameter(
SimpleInliningConstraintFactory factory) {
assert getArgumentIndex() > 0;
return factory.createNullConstraint(getArgumentIndex() - 1);
}
@Override
public SimpleInliningConstraint rewrittenWithUnboxedArguments(
IntList unboxedArgumentIndices, SimpleInliningConstraintFactory factory) {
if (unboxedArgumentIndices.contains(getArgumentIndex())) {
return factory.createNumberConstraint(getArgumentIndex(), 0);
}
return this;
}
}