[llvm] r341253 - [NFC] Optionally pass a function to emitInstrCountChangedRemark

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 13:54:37 PDT 2018


Author: paquette
Date: Fri Aug 31 13:54:37 2018
New Revision: 341253

URL: http://llvm.org/viewvc/llvm-project?rev=341253&view=rev
Log:
[NFC] Optionally pass a function to emitInstrCountChangedRemark

In basic block, loop, and function passes, we already have a function that
we can use to emit optimization remarks. We can use that instead of searching
the module for the first suitable function (that is, one that contains at
least one basic block.)

Modified:
    llvm/trunk/include/llvm/IR/LegacyPassManagers.h
    llvm/trunk/lib/Analysis/LoopPass.cpp
    llvm/trunk/lib/IR/LegacyPassManager.cpp

Modified: llvm/trunk/include/llvm/IR/LegacyPassManagers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LegacyPassManagers.h?rev=341253&r1=341252&r2=341253&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/LegacyPassManagers.h (original)
+++ llvm/trunk/include/llvm/IR/LegacyPassManagers.h Fri Aug 31 13:54:37 2018
@@ -410,8 +410,10 @@ public:
 
   /// Emit a remark signifying that the number of IR instructions in the module
   /// changed.
+  /// \p F is optionally passed by passes which run on Functions, and thus
+  /// always know whether or not a non-empty function is available.
   void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta,
-                                   unsigned CountBefore);
+                                   unsigned CountBefore, Function *F = nullptr);
 
 protected:
   // Top level manager.

Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=341253&r1=341252&r2=341253&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Fri Aug 31 13:54:37 2018
@@ -226,7 +226,7 @@ bool LPPassManager::runOnFunction(Functi
           if (NewSize != FunctionSize) {
             int64_t Delta = static_cast<int64_t>(NewSize) -
                             static_cast<int64_t>(FunctionSize);
-            emitInstrCountChangedRemark(P, M, Delta, InstrCount);
+            emitInstrCountChangedRemark(P, M, Delta, InstrCount, &F);
             InstrCount = static_cast<int64_t>(InstrCount) + Delta;
             FunctionSize = NewSize;
           }

Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=341253&r1=341252&r2=341253&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Fri Aug 31 13:54:37 2018
@@ -143,7 +143,8 @@ unsigned PMDataManager::initSizeRemarkIn
 
 void PMDataManager::emitInstrCountChangedRemark(Pass *P, Module &M,
                                                 int64_t Delta,
-                                                unsigned CountBefore) {
+                                                unsigned CountBefore,
+                                                Function *F) {
   // If it's a pass manager, don't emit a remark. (This hinges on the assumption
   // that the only passes that return non-null with getAsPMDataManager are pass
   // managers.) The reason we have to do this is to avoid emitting remarks for
@@ -151,19 +152,22 @@ void PMDataManager::emitInstrCountChange
   if (P->getAsPMDataManager())
     return;
 
-  // We need a function containing at least one basic block in order to output
-  // remarks. Since it's possible that the first function in the module doesn't
-  // actually contain a basic block, we have to go and find one that's suitable
-  // for emitting remarks.
-  auto It = std::find_if(M.begin(), M.end(),
-                         [](const Function &Fn) { return !Fn.empty(); });
+  // Do we have a function we can use to emit a remark?
+  if (F == nullptr) {
+    // We need a function containing at least one basic block in order to output
+    // remarks. Since it's possible that the first function in the module
+    // doesn't actually contain a basic block, we have to go and find one that's
+    // suitable for emitting remarks.
+    auto It = std::find_if(M.begin(), M.end(),
+                          [](const Function &Fn) { return !Fn.empty(); });
+
+    // Didn't find a function. Quit.
+    if (It == M.end())
+      return;
 
-  // Didn't find a function. Quit.
-  if (It == M.end())
-    return;
-
-  // We found a function containing at least one basic block.
-  Function *F = &*It;
+    // We found a function containing at least one basic block.
+    F = &*It;
+  }
   int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
   BasicBlock &BB = *F->begin();
   OptimizationRemarkAnalysis R("size-info", "IRSizeChange",
@@ -1306,7 +1310,7 @@ bool BBPassManager::runOnFunction(Functi
           if (NewSize != BBSize) {
             int64_t Delta =
                 static_cast<int64_t>(NewSize) - static_cast<int64_t>(BBSize);
-            emitInstrCountChangedRemark(BP, M, Delta, InstrCount);
+            emitInstrCountChangedRemark(BP, M, Delta, InstrCount, &F);
             InstrCount = static_cast<int64_t>(InstrCount) + Delta;
             BBSize = NewSize;
           }
@@ -1543,7 +1547,7 @@ bool FPPassManager::runOnFunction(Functi
         if (NewSize != FunctionSize) {
           int64_t Delta = static_cast<int64_t>(NewSize) -
                           static_cast<int64_t>(FunctionSize);
-          emitInstrCountChangedRemark(FP, M, Delta, InstrCount);
+          emitInstrCountChangedRemark(FP, M, Delta, InstrCount, &F);
           InstrCount = static_cast<int64_t>(InstrCount) + Delta;
           FunctionSize = NewSize;
         }




More information about the llvm-commits mailing list