Move LIR conversion into LirConverter

This also introduces a new LIR rewriting pass. This brings the LIR fully up to date by rewriting it with the current graph lens, but without converting the LIR to the output format. This allows building IR from the resulting LIR, which is a prerequisite for being able to build IR and apply the LensCodeRewriter in the final round of vertical class merging.

Bug: b/315445393
Change-Id: I2a0b13069d1a7c9b0b57af28947faa448e8ad028
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index 4507e1e..45b7c53 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -37,6 +37,7 @@
 import com.android.tools.r8.horizontalclassmerging.HorizontalClassMerger;
 import com.android.tools.r8.inspector.internal.InspectorImpl;
 import com.android.tools.r8.ir.conversion.IRConverter;
+import com.android.tools.r8.ir.conversion.LirConverter;
 import com.android.tools.r8.ir.conversion.MethodConversionOptions;
 import com.android.tools.r8.ir.conversion.MethodConversionOptions.MutableMethodConversionOptions;
 import com.android.tools.r8.ir.conversion.PrimaryR8IRConverter;
@@ -508,7 +509,7 @@
               initialRuntimeTypeCheckInfoBuilder.build(appView.graphLens()));
 
       // TODO(b/225838009): Horizontal merging currently assumes pre-phase CF conversion.
-      appView.testing().enterLirSupportedPhase(appView, executorService);
+      LirConverter.enterLirSupportedPhase(appView, executorService);
 
       new ProtoNormalizer(appViewWithLiveness).run(executorService, timing);
 
@@ -715,8 +716,11 @@
         SyntheticFinalization.finalizeWithClassHierarchy(appView, executorService, timing);
       }
 
+      // Rewrite LIR with lens to allow building IR from LIR in class mergers.
+      LirConverter.rewriteLirWithLens(appView, timing, executorService);
+
       // TODO(b/225838009): Move further down.
-      PrimaryR8IRConverter.finalizeLirToOutputFormat(appView, timing, executorService);
+      LirConverter.finalizeLirToOutputFormat(appView, timing, executorService);
 
       // Read any -applymapping input to allow for repackaging to not relocate the classes.
       timing.begin("read -applymapping file");
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/LirConverter.java b/src/main/java/com/android/tools/r8/ir/conversion/LirConverter.java
new file mode 100644
index 0000000..ecf769b
--- /dev/null
+++ b/src/main/java/com/android/tools/r8/ir/conversion/LirConverter.java
@@ -0,0 +1,268 @@
+// Copyright (c) 2024, 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.AppInfoWithClassHierarchy;
+import com.android.tools.r8.graph.AppView;
+import com.android.tools.r8.graph.Code;
+import com.android.tools.r8.graph.ProgramMethod;
+import com.android.tools.r8.graph.bytecodemetadata.BytecodeMetadataProvider;
+import com.android.tools.r8.graph.lens.GraphLens;
+import com.android.tools.r8.graph.lens.NonIdentityGraphLens;
+import com.android.tools.r8.ir.code.IRCode;
+import com.android.tools.r8.ir.conversion.passes.FilledNewArrayRewriter;
+import com.android.tools.r8.ir.optimize.ConstantCanonicalizer;
+import com.android.tools.r8.ir.optimize.DeadCodeRemover;
+import com.android.tools.r8.lightir.IR2LirConverter;
+import com.android.tools.r8.lightir.LirCode;
+import com.android.tools.r8.lightir.LirStrategy;
+import com.android.tools.r8.optimize.MemberRebindingIdentityLens;
+import com.android.tools.r8.utils.ObjectUtils;
+import com.android.tools.r8.utils.ThreadUtils;
+import com.android.tools.r8.utils.Timing;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+
+public class LirConverter {
+
+  public static void enterLirSupportedPhase(
+      AppView<AppInfoWithClassHierarchy> appView, ExecutorService executorService)
+      throws ExecutionException {
+    assert appView.testing().canUseLir(appView);
+    assert appView.testing().isPreLirPhase();
+    appView.testing().enterLirSupportedPhase();
+    // Convert code objects to LIR.
+    ThreadUtils.processItems(
+        appView.appInfo().classes(),
+        clazz -> {
+          // TODO(b/225838009): Also convert instance initializers to LIR, by adding support for
+          //  computing the inlining constraint for LIR and using that in the class mergers, and
+          //  class initializers, by updating the concatenation of clinits in horizontal class
+          //  merging.
+          clazz.forEachProgramMethodMatching(
+              method ->
+                  method.hasCode()
+                      && !method.isInitializer()
+                      && !appView.isCfByteCodePassThrough(method),
+              method -> {
+                IRCode code = method.buildIR(appView, MethodConversionOptions.forLirPhase(appView));
+                LirCode<Integer> lirCode =
+                    IR2LirConverter.translate(
+                        code,
+                        BytecodeMetadataProvider.empty(),
+                        LirStrategy.getDefaultStrategy().getEncodingStrategy(),
+                        appView.options());
+                // TODO(b/312890994): Setting a custom code lens is only needed until we convert
+                //  code objects to LIR before we create the first code object with a custom code
+                //  lens (horizontal class merging).
+                GraphLens codeLens = method.getDefinition().getCode().getCodeLens(appView);
+                if (codeLens != appView.codeLens()) {
+                  lirCode =
+                      new LirCode<>(lirCode) {
+                        @Override
+                        public GraphLens getCodeLens(AppView<?> appView) {
+                          return codeLens;
+                        }
+                      };
+                }
+                method.setCode(lirCode, appView);
+              });
+        },
+        appView.options().getThreadingModule(),
+        executorService);
+    // Conversion to LIR via IR will allocate type elements.
+    // They are not needed after construction so remove them again.
+    appView.dexItemFactory().clearTypeElementsCache();
+  }
+
+  public static void rewriteLirWithLens(
+      AppView<? extends AppInfoWithClassHierarchy> appView,
+      Timing timing,
+      ExecutorService executorService)
+      throws ExecutionException {
+    assert appView.testing().canUseLir(appView);
+    assert appView.testing().isSupportedLirPhase();
+    assert !appView.getSyntheticItems().hasPendingSyntheticClasses();
+
+    GraphLens graphLens = appView.graphLens();
+    assert graphLens.isNonIdentityLens();
+    assert appView.codeLens().isAppliedLens();
+
+    MemberRebindingIdentityLens memberRebindingIdentityLens =
+        graphLens.asNonIdentityLens().find(GraphLens::isMemberRebindingIdentityLens);
+    assert memberRebindingIdentityLens != null;
+    if (graphLens == memberRebindingIdentityLens
+        && memberRebindingIdentityLens.getPrevious().isAppliedLens()) {
+      // Nothing to rewrite.
+      return;
+    }
+
+    timing.begin("LIR->LIR@" + graphLens.getClass().getTypeName());
+    rewriteLirWithUnappliedLens(appView, executorService);
+    timing.end();
+
+    // At this point all code has been mapped according to the graph lens.
+    updateCodeLens(appView);
+  }
+
+  private static void rewriteLirWithUnappliedLens(
+      AppView<? extends AppInfoWithClassHierarchy> appView, ExecutorService executorService)
+      throws ExecutionException {
+    LensCodeRewriterUtils rewriterUtils = new LensCodeRewriterUtils(appView, true);
+    ThreadUtils.processItems(
+        appView.appInfo().classes(),
+        clazz ->
+            clazz.forEachProgramMethodMatching(
+                m ->
+                    m.hasCode()
+                        && !m.getCode().isSharedCodeObject()
+                        && !appView.isCfByteCodePassThrough(m),
+                m -> rewriteLirMethodWithLens(m, appView, rewriterUtils)),
+        appView.options().getThreadingModule(),
+        executorService);
+
+    // Clear the reference type cache after conversion to reduce memory pressure.
+    appView.dexItemFactory().clearTypeElementsCache();
+  }
+
+  private static void rewriteLirMethodWithLens(
+      ProgramMethod method,
+      AppView<? extends AppInfoWithClassHierarchy> appView,
+      LensCodeRewriterUtils rewriterUtils) {
+    Code code = method.getDefinition().getCode();
+    if (!code.isLirCode()) {
+      assert false;
+      return;
+    }
+    LirCode<Integer> lirCode = code.asLirCode();
+    LirCode<Integer> rewrittenLirCode =
+        lirCode.rewriteWithSimpleLens(method, appView, rewriterUtils);
+    if (ObjectUtils.notIdentical(lirCode, rewrittenLirCode)) {
+      method.setCode(rewrittenLirCode, appView);
+    }
+  }
+
+  public static void finalizeLirToOutputFormat(
+      AppView<? extends AppInfoWithClassHierarchy> appView,
+      Timing timing,
+      ExecutorService executorService)
+      throws ExecutionException {
+    assert appView.testing().canUseLir(appView);
+    assert appView.testing().isSupportedLirPhase();
+    assert !appView.getSyntheticItems().hasPendingSyntheticClasses();
+    appView.testing().exitLirSupportedPhase();
+    LensCodeRewriterUtils rewriterUtils = new LensCodeRewriterUtils(appView, true);
+    DeadCodeRemover deadCodeRemover = new DeadCodeRemover(appView);
+    String output = appView.options().isGeneratingClassFiles() ? "CF" : "DEX";
+    timing.begin("LIR->IR->" + output);
+    ThreadUtils.processItems(
+        appView.appInfo().classes(),
+        clazz ->
+            clazz.forEachProgramMethod(
+                m -> finalizeLirMethodToOutputFormat(m, deadCodeRemover, appView, rewriterUtils)),
+        appView.options().getThreadingModule(),
+        executorService);
+    timing.end();
+    // Clear the reference type cache after conversion to reduce memory pressure.
+    appView.dexItemFactory().clearTypeElementsCache();
+    // At this point all code has been mapped according to the graph lens.
+    updateCodeLens(appView);
+  }
+
+  private static void updateCodeLens(AppView<? extends AppInfoWithClassHierarchy> appView) {
+    final NonIdentityGraphLens lens = appView.graphLens().asNonIdentityLens();
+    if (lens == null) {
+      assert false;
+      return;
+    }
+
+    // If the current graph lens is the member rebinding identity lens then code lens is simply
+    // the previous lens. This is the same structure as the more complicated case below but where
+    // there is no need to rewrite any previous pointers.
+    if (lens.isMemberRebindingIdentityLens()) {
+      appView.setCodeLens(lens.getPrevious());
+      return;
+    }
+
+    // Otherwise search out where the lens pointing to the member rebinding identity lens.
+    NonIdentityGraphLens lensAfterMemberRebindingIdentityLens =
+        lens.find(p -> p.getPrevious().isMemberRebindingIdentityLens());
+    if (lensAfterMemberRebindingIdentityLens == null) {
+      // With the current compiler structure we expect to always find the lens.
+      assert false;
+      appView.setCodeLens(lens);
+      return;
+    }
+
+    GraphLens codeLens = appView.codeLens();
+    MemberRebindingIdentityLens memberRebindingIdentityLens =
+        lensAfterMemberRebindingIdentityLens.getPrevious().asMemberRebindingIdentityLens();
+
+    // We are assuming that the member rebinding identity lens is always installed after the current
+    // applied lens/code lens and also that there should not be a rebinding lens from the compilers
+    // first phase (this subroutine is only used after IR conversion for now).
+    assert memberRebindingIdentityLens
+        == lens.findPrevious(
+            p -> p == memberRebindingIdentityLens || p == codeLens || p.isMemberRebindingLens());
+
+    // Rewrite the graph lens effects from 'lens' and up to the member rebinding identity lens.
+    MemberRebindingIdentityLens rewrittenMemberRebindingLens =
+        memberRebindingIdentityLens.toRewrittenMemberRebindingIdentityLens(
+            appView, lens, memberRebindingIdentityLens, lens);
+
+    // The current previous pointers for the graph lenses are:
+    //   lens -> ... -> lensAfterMemberRebindingIdentityLens -> memberRebindingIdentityLens -> g
+    // we rewrite them now to:
+    //   rewrittenMemberRebindingLens -> lens -> ... -> lensAfterMemberRebindingIdentityLens -> g
+
+    // The above will construct the new member rebinding lens such that it points to the new
+    // code-lens point already.
+    assert rewrittenMemberRebindingLens.getPrevious() == lens;
+
+    // Update the previous pointer on the new code lens to jump over the old member rebinding
+    // identity lens.
+    lensAfterMemberRebindingIdentityLens.setPrevious(memberRebindingIdentityLens.getPrevious());
+
+    // The applied lens can now be updated and the rewritten member rebinding lens installed as
+    // the current "unapplied lens".
+    appView.setCodeLens(lens);
+    appView.setGraphLens(rewrittenMemberRebindingLens);
+  }
+
+  private static void finalizeLirMethodToOutputFormat(
+      ProgramMethod method,
+      DeadCodeRemover deadCodeRemover,
+      AppView<? extends AppInfoWithClassHierarchy> appView,
+      LensCodeRewriterUtils rewriterUtils) {
+    Code code = method.getDefinition().getCode();
+    if (!(code instanceof LirCode)) {
+      return;
+    }
+    Timing onThreadTiming = Timing.empty();
+    LirCode<Integer> lirCode = code.asLirCode();
+    LirCode<Integer> rewrittenLirCode =
+        lirCode.rewriteWithSimpleLens(method, appView, rewriterUtils);
+    if (ObjectUtils.notIdentical(lirCode, rewrittenLirCode)) {
+      method.setCode(rewrittenLirCode, appView);
+    }
+    IRCode irCode = method.buildIR(appView, MethodConversionOptions.forPostLirPhase(appView));
+    FilledNewArrayRewriter filledNewArrayRewriter = new FilledNewArrayRewriter(appView);
+    boolean changed = filledNewArrayRewriter.run(irCode, onThreadTiming).hasChanged().toBoolean();
+    if (appView.options().isGeneratingDex() && changed) {
+      ConstantCanonicalizer constantCanonicalizer =
+          new ConstantCanonicalizer(appView, method, irCode);
+      constantCanonicalizer.canonicalize();
+    }
+    // Processing is done and no further uses of the meta-data should arise.
+    BytecodeMetadataProvider noMetadata = BytecodeMetadataProvider.empty();
+    // During processing optimization info may cause previously live code to become dead.
+    // E.g., we may now have knowledge that an invoke does not have side effects.
+    // Thus, we re-run the dead-code remover now as it is assumed complete by CF/DEX finalization.
+    deadCodeRemover.run(irCode, onThreadTiming);
+    MethodConversionOptions conversionOptions = irCode.getConversionOptions();
+    assert !conversionOptions.isGeneratingLir();
+    IRFinalizer<?> finalizer = conversionOptions.getFinalizer(deadCodeRemover, appView);
+    method.setCode(finalizer.finalizeCode(irCode, noMetadata, onThreadTiming), appView);
+  }
+}
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/PrimaryR8IRConverter.java b/src/main/java/com/android/tools/r8/ir/conversion/PrimaryR8IRConverter.java
index 16d82e6..3dd62c9 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/PrimaryR8IRConverter.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/PrimaryR8IRConverter.java
@@ -6,28 +6,17 @@
 
 import com.android.tools.r8.graph.AppInfoWithClassHierarchy;
 import com.android.tools.r8.graph.AppView;
-import com.android.tools.r8.graph.Code;
 import com.android.tools.r8.graph.DexApplication;
 import com.android.tools.r8.graph.DexEncodedMethod;
 import com.android.tools.r8.graph.DexProgramClass;
-import com.android.tools.r8.graph.ProgramMethod;
 import com.android.tools.r8.graph.PrunedItems;
-import com.android.tools.r8.graph.bytecodemetadata.BytecodeMetadataProvider;
 import com.android.tools.r8.graph.lens.GraphLens;
-import com.android.tools.r8.graph.lens.NonIdentityGraphLens;
 import com.android.tools.r8.ir.analysis.fieldaccess.TrivialFieldAccessReprocessor;
-import com.android.tools.r8.ir.code.IRCode;
-import com.android.tools.r8.ir.conversion.passes.FilledNewArrayRewriter;
-import com.android.tools.r8.ir.optimize.ConstantCanonicalizer;
-import com.android.tools.r8.ir.optimize.DeadCodeRemover;
 import com.android.tools.r8.ir.optimize.info.MethodResolutionOptimizationInfoAnalysis;
 import com.android.tools.r8.ir.optimize.info.OptimizationFeedbackDelayed;
-import com.android.tools.r8.lightir.LirCode;
-import com.android.tools.r8.optimize.MemberRebindingIdentityLens;
 import com.android.tools.r8.optimize.argumentpropagation.ArgumentPropagator;
 import com.android.tools.r8.optimize.compose.ComposableOptimizationPass;
 import com.android.tools.r8.shaking.AppInfoWithLiveness;
-import com.android.tools.r8.utils.ThreadUtils;
 import com.android.tools.r8.utils.Timing;
 import com.android.tools.r8.utils.collections.ProgramMethodSet;
 import java.io.IOException;
@@ -239,139 +228,6 @@
     return appView.appInfo().app();
   }
 
-  public static void finalizeLirToOutputFormat(
-      AppView<? extends AppInfoWithClassHierarchy> appView,
-      Timing timing,
-      ExecutorService executorService)
-      throws ExecutionException {
-    appView.testing().exitLirSupportedPhase();
-    if (!appView.testing().canUseLir(appView)) {
-      return;
-    }
-    LensCodeRewriterUtils rewriterUtils = new LensCodeRewriterUtils(appView, true);
-    DeadCodeRemover deadCodeRemover = new DeadCodeRemover(appView);
-    String output = appView.options().isGeneratingClassFiles() ? "CF" : "DEX";
-    timing.begin("LIR->IR->" + output);
-    ThreadUtils.processItems(
-        appView.appInfo().classes(),
-        clazz ->
-            clazz.forEachProgramMethod(
-                m -> finalizeLirMethodToOutputFormat(m, deadCodeRemover, appView, rewriterUtils)),
-        appView.options().getThreadingModule(),
-        executorService);
-    appView
-        .getSyntheticItems()
-        .getPendingSyntheticClasses()
-        .forEach(
-            clazz ->
-                clazz.forEachProgramMethod(
-                    m ->
-                        finalizeLirMethodToOutputFormat(
-                            m, deadCodeRemover, appView, rewriterUtils)));
-    timing.end();
-    // Clear the reference type cache after conversion to reduce memory pressure.
-    appView.dexItemFactory().clearTypeElementsCache();
-    // At this point all code has been mapped according to the graph lens.
-    updateCodeLens(appView);
-  }
-
-  private static void updateCodeLens(AppView<? extends AppInfoWithClassHierarchy> appView) {
-    final NonIdentityGraphLens lens = appView.graphLens().asNonIdentityLens();
-    if (lens == null) {
-      assert false;
-      return;
-    }
-
-    // If the current graph lens is the member rebinding identity lens then code lens is simply
-    // the previous lens. This is the same structure as the more complicated case below but where
-    // there is no need to rewrite any previous pointers.
-    if (lens.isMemberRebindingIdentityLens()) {
-      appView.setCodeLens(lens.getPrevious());
-      return;
-    }
-
-    // Otherwise search out where the lens pointing to the member rebinding identity lens.
-    NonIdentityGraphLens lensAfterMemberRebindingIdentityLens =
-        lens.find(p -> p.getPrevious().isMemberRebindingIdentityLens());
-    if (lensAfterMemberRebindingIdentityLens == null) {
-      // With the current compiler structure we expect to always find the lens.
-      assert false;
-      appView.setCodeLens(lens);
-      return;
-    }
-
-    GraphLens codeLens = appView.codeLens();
-    MemberRebindingIdentityLens memberRebindingIdentityLens =
-        lensAfterMemberRebindingIdentityLens.getPrevious().asMemberRebindingIdentityLens();
-
-    // We are assuming that the member rebinding identity lens is always installed after the current
-    // applied lens/code lens and also that there should not be a rebinding lens from the compilers
-    // first phase (this subroutine is only used after IR conversion for now).
-    assert memberRebindingIdentityLens
-        == lens.findPrevious(
-            p -> p == memberRebindingIdentityLens || p == codeLens || p.isMemberRebindingLens());
-
-    // Rewrite the graph lens effects from 'lens' and up to the member rebinding identity lens.
-    MemberRebindingIdentityLens rewrittenMemberRebindingLens =
-        memberRebindingIdentityLens.toRewrittenMemberRebindingIdentityLens(
-            appView, lens, memberRebindingIdentityLens, lens);
-
-    // The current previous pointers for the graph lenses are:
-    //   lens -> ... -> lensAfterMemberRebindingIdentityLens -> memberRebindingIdentityLens -> g
-    // we rewrite them now to:
-    //   rewrittenMemberRebindingLens -> lens -> ... -> lensAfterMemberRebindingIdentityLens -> g
-
-    // The above will construct the new member rebinding lens such that it points to the new
-    // code-lens point already.
-    assert rewrittenMemberRebindingLens.getPrevious() == lens;
-
-    // Update the previous pointer on the new code lens to jump over the old member rebinding
-    // identity lens.
-    lensAfterMemberRebindingIdentityLens.setPrevious(memberRebindingIdentityLens.getPrevious());
-
-    // The applied lens can now be updated and the rewritten member rebinding lens installed as
-    // the current "unapplied lens".
-    appView.setCodeLens(lens);
-    appView.setGraphLens(rewrittenMemberRebindingLens);
-  }
-
-  @SuppressWarnings("ReferenceEquality")
-  private static void finalizeLirMethodToOutputFormat(
-      ProgramMethod method,
-      DeadCodeRemover deadCodeRemover,
-      AppView<?> appView,
-      LensCodeRewriterUtils rewriterUtils) {
-    Code code = method.getDefinition().getCode();
-    if (!(code instanceof LirCode)) {
-      return;
-    }
-    Timing onThreadTiming = Timing.empty();
-    LirCode<Integer> lirCode = code.asLirCode();
-    LirCode<Integer> rewrittenLirCode =
-        lirCode.rewriteWithSimpleLens(method, appView, rewriterUtils);
-    if (lirCode != rewrittenLirCode) {
-      method.setCode(rewrittenLirCode, appView);
-    }
-    IRCode irCode = method.buildIR(appView, MethodConversionOptions.forPostLirPhase(appView));
-    FilledNewArrayRewriter filledNewArrayRewriter = new FilledNewArrayRewriter(appView);
-    boolean changed = filledNewArrayRewriter.run(irCode, onThreadTiming).hasChanged().toBoolean();
-    if (appView.options().isGeneratingDex() && changed) {
-      ConstantCanonicalizer constantCanonicalizer =
-          new ConstantCanonicalizer(appView, method, irCode);
-      constantCanonicalizer.canonicalize();
-    }
-    // Processing is done and no further uses of the meta-data should arise.
-    BytecodeMetadataProvider noMetadata = BytecodeMetadataProvider.empty();
-    // During processing optimization info may cause previously live code to become dead.
-    // E.g., we may now have knowledge that an invoke does not have side effects.
-    // Thus, we re-run the dead-code remover now as it is assumed complete by CF/DEX finalization.
-    deadCodeRemover.run(irCode, onThreadTiming);
-    MethodConversionOptions conversionOptions = irCode.getConversionOptions();
-    assert !conversionOptions.isGeneratingLir();
-    IRFinalizer<?> finalizer = conversionOptions.getFinalizer(deadCodeRemover, appView);
-    method.setCode(finalizer.finalizeCode(irCode, noMetadata, onThreadTiming), appView);
-  }
-
   private void clearDexMethodCompilationState() {
     appView.appInfo().classes().forEach(this::clearDexMethodCompilationState);
   }
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
index 011fbfb..0dc92d1 100644
--- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java
+++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -65,14 +65,11 @@
 import com.android.tools.r8.graph.DexType;
 import com.android.tools.r8.graph.ProgramMethod;
 import com.android.tools.r8.graph.analysis.ResourceAccessAnalysis;
-import com.android.tools.r8.graph.bytecodemetadata.BytecodeMetadataProvider;
-import com.android.tools.r8.graph.lens.GraphLens;
 import com.android.tools.r8.horizontalclassmerging.HorizontallyMergedClasses;
 import com.android.tools.r8.inspector.internal.InspectorImpl;
 import com.android.tools.r8.ir.analysis.proto.ProtoReferences;
 import com.android.tools.r8.ir.analysis.type.TypeElement;
 import com.android.tools.r8.ir.code.IRCode;
-import com.android.tools.r8.ir.conversion.MethodConversionOptions;
 import com.android.tools.r8.ir.desugar.TypeRewriter;
 import com.android.tools.r8.ir.desugar.TypeRewriter.MachineTypeRewriter;
 import com.android.tools.r8.ir.desugar.desugaredlibrary.DesugaredLibrarySpecification;
@@ -80,9 +77,6 @@
 import com.android.tools.r8.ir.desugar.nest.Nest;
 import com.android.tools.r8.ir.optimize.Inliner;
 import com.android.tools.r8.ir.optimize.enums.EnumDataMap;
-import com.android.tools.r8.lightir.IR2LirConverter;
-import com.android.tools.r8.lightir.LirCode;
-import com.android.tools.r8.lightir.LirStrategy;
 import com.android.tools.r8.naming.ClassNameMapper;
 import com.android.tools.r8.naming.MapConsumer;
 import com.android.tools.r8.naming.MapVersion;
@@ -133,8 +127,6 @@
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.BiConsumer;
 import java.util.function.BiFunction;
@@ -2200,56 +2192,9 @@
 
     private LirPhase currentPhase = LirPhase.PRE;
 
-    public void enterLirSupportedPhase(AppView<?> appView, ExecutorService executorService)
-        throws ExecutionException {
+    public void enterLirSupportedPhase() {
       assert isPreLirPhase();
       currentPhase = LirPhase.SUPPORTED;
-      if (!canUseLir(appView)) {
-        return;
-      }
-      // Convert code objects to LIR.
-      ThreadUtils.processItems(
-          appView.appInfo().classes(),
-          clazz -> {
-            // TODO(b/225838009): Also convert instance initializers to LIR, by adding support for
-            //  computing the inlining constraint for LIR and using that in the class mergers, and
-            //  class initializers, by updating the concatenation of clinits in horizontal class
-            //  merging.
-            clazz.forEachProgramMethodMatching(
-                method ->
-                    method.hasCode()
-                        && !method.isInitializer()
-                        && !appView.isCfByteCodePassThrough(method),
-                method -> {
-                  IRCode code =
-                      method.buildIR(appView, MethodConversionOptions.forLirPhase(appView));
-                  LirCode<Integer> lirCode =
-                      IR2LirConverter.translate(
-                          code,
-                          BytecodeMetadataProvider.empty(),
-                          LirStrategy.getDefaultStrategy().getEncodingStrategy(),
-                          appView.options());
-                  // TODO(b/312890994): Setting a custom code lens is only needed until we convert
-                  //  code objects to LIR before we create the first code object with a custom code
-                  //  lens (horizontal class merging).
-                  GraphLens codeLens = method.getDefinition().getCode().getCodeLens(appView);
-                  if (codeLens != appView.codeLens()) {
-                    lirCode =
-                        new LirCode<>(lirCode) {
-                          @Override
-                          public GraphLens getCodeLens(AppView<?> appView) {
-                            return codeLens;
-                          }
-                        };
-                  }
-                  method.setCode(lirCode, appView);
-                });
-          },
-          appView.options().getThreadingModule(),
-          executorService);
-      // Conversion to LIR via IR will allocate type elements.
-      // They are not needed after construction so remove them again.
-      appView.dexItemFactory().clearTypeElementsCache();
     }
 
     public void exitLirSupportedPhase() {