code: public void stage2Passes() {
      checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?");
      checkState(!hasErrors());
      checkState(!options.getInstrumentForCoverageOnly());
      JSModule weakModule = moduleGraph.getModuleByName(JSModule.WEAK_MODULE_NAME);
      if (weakModule != null) {
        for (CompilerInput i : moduleGraph.getAllInputs()) {
          if (i.getSourceFile().isWeak()) {
            checkState(
                i.getModule() == weakModule, "Expected all weak files to be in the weak module.");
          }
        }
      }
      runInCompilerThread(
          () -> {
            if (options.shouldOptimize()) {
              performOptimizations();
            }
            return null;
          });
    }
docs: Perform compiler passes for stage 2 of compilation.
  
  <p>Stage 2 consists primarily of optimization passes.
  
  <p>{@code stage1Passes()} must be called before this method is called.
  
  <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
  warnings and errors to stderr. See the invocation in {@link #compile} for a good example.