[Polly] [OptDiag] Updating Polly Diagnostics Remarks

Utilizing newer LLVM diagnostic remark API in order to enable use of
opt-viewer tool. Polly Diagnostic Remarks also now appear in YAML
remark file.

In this patch, I've added the OptimizationRemarkEmitter into certain
classes where remarks are being emitted and update the remark emit calls
itself. I also provide each remark a BasicBlock or Instruction from where
it is being called, in order to compute the hotness of the remark.

Patch by Tarun Rajendran!

Differential Revision: https://reviews.llvm.org/D35399

llvm-svn: 308233
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 27dfc93..199306a 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -284,8 +284,8 @@
 
 ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
                              ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
-                             AliasAnalysis &AA)
-    : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA) {
+                             AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
+    : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {
 
   if (!PollyProcessUnprofitable && LI.empty())
     return;
@@ -1579,7 +1579,7 @@
   for (auto &DIt : DetectionContextMap) {
     auto &DC = DIt.getSecond();
     if (DC.Log.hasErrors())
-      emitRejectionRemarks(DIt.getFirst(), DC.Log);
+      emitRejectionRemarks(DIt.getFirst(), DC.Log, ORE);
   }
 }
 
@@ -1728,7 +1728,8 @@
   auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
   auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
   auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
-  Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA));
+  auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
+  Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA, ORE));
   return false;
 }
 
@@ -1736,6 +1737,7 @@
   AU.addRequired<LoopInfoWrapperPass>();
   AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
   AU.addRequired<DominatorTreeWrapperPass>();
+  AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
   // We also need AA and RegionInfo when we are verifying analysis.
   AU.addRequiredTransitive<AAResultsWrapperPass>();
   AU.addRequiredTransitive<RegionInfoPass>();
@@ -1767,7 +1769,8 @@
   auto &AA = FAM.getResult<AAManager>(F);
   auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
   auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
-  return {F, DT, SE, LI, RI, AA};
+  auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+  return {F, DT, SE, LI, RI, AA, ORE};
 }
 
 PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F,
@@ -1792,5 +1795,6 @@
 INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
+INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass);
 INITIALIZE_PASS_END(ScopDetectionWrapperPass, "polly-detect",
                     "Polly - Detect static control parts (SCoPs)", false, false)