[Polly] Make NewPM's IslAstAnalysis more similar to the legacy IslAstInfoWrapperPass.

In particular, print the ast with -debug-only=polly-ast, print a
per-scop header with print<polly-ast> and force-add the analysis with
-polly-code-generation=ast.
GitOrigin-RevId: 08bab4b0302106803d7cd7c4504dd63c296c40a0
diff --git a/lib/CodeGen/IslAst.cpp b/lib/CodeGen/IslAst.cpp
index 94367bd..d846df1 100644
--- a/lib/CodeGen/IslAst.cpp
+++ b/lib/CodeGen/IslAst.cpp
@@ -663,10 +663,40 @@
   return Payload ? Payload->Build : nullptr;
 }
 
+static std::unique_ptr<IslAstInfo> runIslAst(
+    Scop &Scop,
+    function_ref<const Dependences &(Dependences::AnalysisLevel)> GetDeps) {
+  // Skip SCoPs in case they're already handled by PPCGCodeGeneration.
+  if (Scop.isToBeSkipped())
+    return {};
+
+  ScopsProcessed++;
+
+  const Dependences &D = GetDeps(Dependences::AL_Statement);
+
+  if (D.getSharedIslCtx() != Scop.getSharedIslCtx()) {
+    LLVM_DEBUG(
+        dbgs() << "Got dependence analysis for different SCoP/isl_ctx\n");
+    return {};
+  }
+
+  std::unique_ptr<IslAstInfo> Ast = std::make_unique<IslAstInfo>(Scop, D);
+
+  LLVM_DEBUG({
+    if (Ast)
+      Ast->print(dbgs());
+  });
+
+  return Ast;
+}
+
 IslAstInfo IslAstAnalysis::run(Scop &S, ScopAnalysisManager &SAM,
                                ScopStandardAnalysisResults &SAR) {
-  return {S, SAM.getResult<DependenceAnalysis>(S, SAR).getDependences(
-                 Dependences::AL_Statement)};
+  auto GetDeps = [&](Dependences::AnalysisLevel Lvl) -> const Dependences & {
+    return SAM.getResult<DependenceAnalysis>(S, SAR).getDependences(Lvl);
+  };
+
+  return std::move(*runIslAst(S, GetDeps).release());
 }
 
 static __isl_give isl_printer *cbPrintUser(__isl_take isl_printer *P,
@@ -785,25 +815,12 @@
 void IslAstInfoWrapperPass::releaseMemory() { Ast.reset(); }
 
 bool IslAstInfoWrapperPass::runOnScop(Scop &Scop) {
-  // Skip SCoPs in case they're already handled by PPCGCodeGeneration.
-  if (Scop.isToBeSkipped())
-    return false;
+  auto GetDeps = [this](Dependences::AnalysisLevel Lvl) -> const Dependences & {
+    return getAnalysis<DependenceInfo>().getDependences(Lvl);
+  };
 
-  ScopsProcessed++;
+  Ast = runIslAst(Scop, GetDeps);
 
-  const Dependences &D =
-      getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement);
-
-  if (D.getSharedIslCtx() != Scop.getSharedIslCtx()) {
-    LLVM_DEBUG(
-        dbgs() << "Got dependence analysis for different SCoP/isl_ctx\n");
-    Ast.reset();
-    return false;
-  }
-
-  Ast.reset(new IslAstInfo(Scop, D));
-
-  LLVM_DEBUG(printScop(dbgs(), Scop));
   return false;
 }
 
@@ -817,6 +834,8 @@
 }
 
 void IslAstInfoWrapperPass::printScop(raw_ostream &OS, Scop &S) const {
+  OS << "Printing analysis 'Polly - Generate an AST of the SCoP (isl)'"
+     << S.getName() << "' in function '" << S.getFunction().getName() << "':\n";
   if (Ast)
     Ast->print(OS);
 }
diff --git a/lib/Support/RegisterPasses.cpp b/lib/Support/RegisterPasses.cpp
index a16bab8..1c72b63 100644
--- a/lib/Support/RegisterPasses.cpp
+++ b/lib/Support/RegisterPasses.cpp
@@ -497,11 +497,15 @@
 
   if (Target == TARGET_CPU || Target == TARGET_HYBRID) {
     switch (CodeGeneration) {
+    case CODEGEN_AST:
+      SPM.addPass(
+          RequireAnalysisPass<IslAstAnalysis, Scop, ScopAnalysisManager,
+                              ScopStandardAnalysisResults &, SPMUpdater &>());
+      break;
     case CODEGEN_FULL:
       SPM.addPass(polly::CodeGenerationPass());
       break;
-    case CODEGEN_AST:
-    default: // Does it actually make sense to distinguish IslAst codegen?
+    default:
       break;
     }
   }