[Inliner] Port all opt remarks to new streaming API

llvm-svn: 282559
diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index 3ffb754..7aa1e18 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -255,11 +255,6 @@
   return true;
 }
 
-static void emitAnalysis(CallSite CS, OptimizationRemarkEmitter &ORE,
-                         const Twine &Msg) {
-  ORE.emitOptimizationRemarkAnalysis(DEBUG_TYPE, CS.getInstruction(), Msg);
-}
-
 /// Return true if inlining of CS can block the caller from being
 /// inlined which is proved to be more beneficial. \p IC is the
 /// estimated inline cost associated with callsite \p CS.
@@ -341,21 +336,26 @@
 static bool shouldInline(CallSite CS,
                          function_ref<InlineCost(CallSite CS)> GetInlineCost,
                          OptimizationRemarkEmitter &ORE) {
+  using namespace ore;
   InlineCost IC = GetInlineCost(CS);
+  Instruction *Call = CS.getInstruction();
+  Function *Callee = CS.getCalledFunction();
 
   if (IC.isAlways()) {
     DEBUG(dbgs() << "    Inlining: cost=always"
                  << ", Call: " << *CS.getInstruction() << "\n");
-    emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName()) +
-                              " should always be inlined (cost=always)");
+    ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AlwaysInline", Call)
+             << NV("Callee", Callee)
+             << " should always be inlined (cost=always)");
     return true;
   }
 
   if (IC.isNever()) {
     DEBUG(dbgs() << "    NOT Inlining: cost=never"
                  << ", Call: " << *CS.getInstruction() << "\n");
-    emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName() +
-                                " should never be inlined (cost=never)"));
+    ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "NeverInline", Call)
+             << NV("Callee", Callee)
+             << " should never be inlined (cost=never)");
     return false;
   }
 
@@ -364,10 +364,10 @@
     DEBUG(dbgs() << "    NOT Inlining: cost=" << IC.getCost()
                  << ", thres=" << (IC.getCostDelta() + IC.getCost())
                  << ", Call: " << *CS.getInstruction() << "\n");
-    emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName() +
-                                " too costly to inline (cost=") +
-                              Twine(IC.getCost()) + ", threshold=" +
-                              Twine(IC.getCostDelta() + IC.getCost()) + ")");
+    ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "TooCostly", Call)
+             << NV("Callee", Callee) << " too costly to inline (cost="
+             << NV("Cost", IC.getCost()) << ", threshold="
+             << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
     return false;
   }
 
@@ -376,22 +376,22 @@
     DEBUG(dbgs() << "    NOT Inlining: " << *CS.getInstruction()
                  << " Cost = " << IC.getCost()
                  << ", outer Cost = " << TotalSecondaryCost << '\n');
-    emitAnalysis(CS, ORE,
-                 Twine("Not inlining. Cost of inlining " +
-                       CS.getCalledFunction()->getName() +
-                       " increases the cost of inlining " +
-                       CS.getCaller()->getName() + " in other contexts"));
+    ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE,
+                                        "IncreaseCostInOtherContexts", Call)
+             << "Not inlining. Cost of inlining " << NV("Callee", Callee)
+             << " increases the cost of inlining " << NV("Caller", Caller)
+             << " in other contexts");
     return false;
   }
 
   DEBUG(dbgs() << "    Inlining: cost=" << IC.getCost()
                << ", thres=" << (IC.getCostDelta() + IC.getCost())
                << ", Call: " << *CS.getInstruction() << '\n');
-  emitAnalysis(CS, ORE, CS.getCalledFunction()->getName() +
-                            Twine(" can be inlined into ") +
-                            CS.getCaller()->getName() + " with cost=" +
-                            Twine(IC.getCost()) + " (threshold=" +
-                            Twine(IC.getCostDelta() + IC.getCost()) + ")");
+  ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "CanBeInlined", Call)
+           << NV("Callee", Callee) << " can be inlined into "
+           << NV("Caller", Caller) << " with cost=" << NV("Cost", IC.getCost())
+           << " (threshold="
+           << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
   return true;
 }
 
@@ -550,11 +550,12 @@
 
         // If the policy determines that we should inline this function,
         // try to do so.
+        using namespace ore;
         if (!shouldInline(CS, GetInlineCost, ORE)) {
-          ORE.emitOptimizationRemarkMissed(DEBUG_TYPE, DLoc, Block,
-                                           Twine(Callee->getName() +
-                                                 " will not be inlined into " +
-                                                 Caller->getName()));
+          ORE.emit(
+              OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
+              << NV("Callee", Callee) << " will not be inlined into "
+              << NV("Caller", Caller));
           continue;
         }
 
@@ -562,18 +563,18 @@
         if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas,
                                   InlineHistoryID, InsertLifetime, AARGetter,
                                   ImportedFunctionsStats)) {
-          ORE.emitOptimizationRemarkMissed(DEBUG_TYPE, DLoc, Block,
-                                           Twine(Callee->getName() +
-                                                 " will not be inlined into " +
-                                                 Caller->getName()));
+          ORE.emit(
+              OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
+              << NV("Callee", Callee) << " will not be inlined into "
+              << NV("Caller", Caller));
           continue;
         }
         ++NumInlined;
 
         // Report the inline decision.
-        ORE.emitOptimizationRemark(
-            DEBUG_TYPE, DLoc, Block,
-            Twine(Callee->getName() + " inlined into " + Caller->getName()));
+        ORE.emit(OptimizationRemark(DEBUG_TYPE, "Inlined", DLoc, Block)
+                 << NV("Callee", Callee) << " inlined into "
+                 << NV("Caller", Caller));
 
         // If inlining this function gave us any new call sites, throw them
         // onto our worklist to process.  They are useful inline candidates.