| // Copyright (c) 2019, 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.conversion; |
| |
| import com.android.tools.r8.graph.AppView; |
| import com.android.tools.r8.graph.DexEncodedMethod; |
| import com.android.tools.r8.graph.DexType; |
| import com.android.tools.r8.graph.ProgramMethod; |
| import com.android.tools.r8.ir.analysis.inlining.SimpleInliningConstraint; |
| import com.android.tools.r8.ir.analysis.type.ClassTypeElement; |
| import com.android.tools.r8.ir.analysis.type.TypeElement; |
| import com.android.tools.r8.ir.analysis.value.AbstractValue; |
| import com.android.tools.r8.ir.optimize.Inliner.ConstraintWithTarget; |
| import com.android.tools.r8.ir.optimize.classinliner.constraint.ClassInlinerMethodConstraint; |
| import com.android.tools.r8.ir.optimize.enums.classification.EnumUnboxerMethodClassification; |
| import com.android.tools.r8.ir.optimize.info.bridge.BridgeInfo; |
| import com.android.tools.r8.ir.optimize.info.initializer.InstanceInitializerInfoCollection; |
| import com.android.tools.r8.shaking.AppInfoWithLiveness; |
| import com.android.tools.r8.utils.BitSetUtils; |
| import java.util.BitSet; |
| import java.util.Set; |
| |
| public interface MethodOptimizationFeedback { |
| |
| void markForceInline(DexEncodedMethod method); |
| |
| void markInlinedIntoSingleCallSite(DexEncodedMethod method); |
| |
| void markMethodCannotBeKept(DexEncodedMethod method); |
| |
| void methodInitializesClassesOnNormalExit( |
| DexEncodedMethod method, Set<DexType> initializedClasses); |
| |
| void methodReturnsArgument(DexEncodedMethod method, int argument); |
| |
| void methodReturnsAbstractValue( |
| DexEncodedMethod method, AppView<AppInfoWithLiveness> appView, AbstractValue abstractValue); |
| |
| void methodReturnsObjectWithUpperBoundType( |
| DexEncodedMethod method, AppView<?> appView, TypeElement type); |
| |
| void methodReturnsObjectWithLowerBoundType(DexEncodedMethod method, ClassTypeElement type); |
| |
| void methodMayNotHaveSideEffects(DexEncodedMethod method); |
| |
| void methodReturnValueOnlyDependsOnArguments(DexEncodedMethod method); |
| |
| void methodNeverReturnsNormally(ProgramMethod method); |
| |
| void markProcessed(DexEncodedMethod method, ConstraintWithTarget state); |
| |
| void markAsPropagated(DexEncodedMethod method); |
| |
| void markCheckNullReceiverBeforeAnySideEffect(DexEncodedMethod method, boolean mark); |
| |
| void markTriggerClassInitBeforeAnySideEffect(DexEncodedMethod method, boolean mark); |
| |
| void setBridgeInfo(DexEncodedMethod method, BridgeInfo bridgeInfo); |
| |
| void setClassInlinerMethodConstraint( |
| ProgramMethod method, ClassInlinerMethodConstraint classInlinerConstraint); |
| |
| void setEnumUnboxerMethodClassification( |
| ProgramMethod method, EnumUnboxerMethodClassification enumUnboxerMethodClassification); |
| |
| void setInstanceInitializerInfoCollection( |
| DexEncodedMethod method, InstanceInitializerInfoCollection instanceInitializerInfoCollection); |
| |
| void setInitializerEnablingJavaVmAssertions(DexEncodedMethod method); |
| |
| void setNonNullParamOrThrow(DexEncodedMethod method, BitSet facts); |
| |
| void setNonNullParamOnNormalExits(DexEncodedMethod method, BitSet facts); |
| |
| void setSimpleInliningConstraint(ProgramMethod method, SimpleInliningConstraint constraint); |
| |
| void classInitializerMayBePostponed(DexEncodedMethod method); |
| |
| void setUnusedArguments(ProgramMethod method, BitSet unusedArguments); |
| |
| // Unset methods. |
| |
| void unsetAbstractReturnValue(ProgramMethod method); |
| |
| void unsetBridgeInfo(DexEncodedMethod method); |
| |
| void unsetCheckNullReceiverBeforeAnySideEffect(ProgramMethod method); |
| |
| void unsetClassInitializerMayBePostponed(ProgramMethod method); |
| |
| void unsetClassInlinerMethodConstraint(ProgramMethod method); |
| |
| void unsetDynamicLowerBoundReturnType(ProgramMethod method); |
| |
| void unsetDynamicUpperBoundReturnType(ProgramMethod method); |
| |
| void unsetEnumUnboxerMethodClassification(ProgramMethod method); |
| |
| void unsetForceInline(ProgramMethod method); |
| |
| void unsetInitializedClassesOnNormalExit(ProgramMethod method); |
| |
| void unsetInitializerEnablingJavaVmAssertions(ProgramMethod method); |
| |
| void unsetInlinedIntoSingleCallSite(ProgramMethod method); |
| |
| void unsetInstanceInitializerInfoCollection(ProgramMethod method); |
| |
| void unsetMayNotHaveSideEffects(ProgramMethod method); |
| |
| void unsetNeverReturnsNormally(ProgramMethod method); |
| |
| void unsetNonNullParamOnNormalExits(ProgramMethod method); |
| |
| void unsetNonNullParamOrThrow(ProgramMethod method); |
| |
| void unsetReachabilitySensitive(ProgramMethod method); |
| |
| void unsetReturnedArgument(ProgramMethod method); |
| |
| void unsetReturnValueOnlyDependsOnArguments(ProgramMethod method); |
| |
| void unsetSimpleInliningConstraint(ProgramMethod method); |
| |
| void unsetTriggerClassInitBeforeAnySideEffect(ProgramMethod method); |
| |
| void unsetUnusedArguments(ProgramMethod method); |
| |
| default void unsetOptimizationInfoForAbstractMethod(ProgramMethod method) { |
| if (method.getOptimizationInfo().isMutableOptimizationInfo()) { |
| unsetAbstractReturnValue(method); |
| unsetBridgeInfo(method.getDefinition()); |
| unsetCheckNullReceiverBeforeAnySideEffect(method); |
| unsetClassInitializerMayBePostponed(method); |
| unsetClassInlinerMethodConstraint(method); |
| unsetDynamicLowerBoundReturnType(method); |
| unsetDynamicUpperBoundReturnType(method); |
| unsetEnumUnboxerMethodClassification(method); |
| unsetForceInline(method); |
| unsetInitializedClassesOnNormalExit(method); |
| unsetInitializerEnablingJavaVmAssertions(method); |
| unsetInstanceInitializerInfoCollection(method); |
| unsetMayNotHaveSideEffects(method); |
| unsetNeverReturnsNormally(method); |
| unsetNonNullParamOnNormalExits(method); |
| unsetNonNullParamOrThrow(method); |
| unsetReachabilitySensitive(method); |
| unsetReturnedArgument(method); |
| unsetReturnValueOnlyDependsOnArguments(method); |
| unsetSimpleInliningConstraint(method); |
| unsetTriggerClassInitBeforeAnySideEffect(method); |
| unsetUnusedArguments(method); |
| } |
| } |
| |
| default void unsetOptimizationInfoForThrowNullMethod(ProgramMethod method) { |
| unsetOptimizationInfoForAbstractMethod(method); |
| methodNeverReturnsNormally(method); |
| setUnusedArguments( |
| method, BitSetUtils.createFilled(true, method.getDefinition().getNumberOfArguments())); |
| if (method.getDefinition().isInstance()) { |
| markCheckNullReceiverBeforeAnySideEffect(method.getDefinition(), true); |
| } |
| } |
| } |