[llvm] a7abe6e - [LegacyPassManager] Simplify PMStack pop

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 13:52:06 PST 2019


Author: Fangrui Song
Date: 2019-11-28T13:48:26-08:00
New Revision: a7abe6eac061a999e88d651e4857872f5ec52e5d

URL: https://github.com/llvm/llvm-project/commit/a7abe6eac061a999e88d651e4857872f5ec52e5d
DIFF: https://github.com/llvm/llvm-project/commit/a7abe6eac061a999e88d651e4857872f5ec52e5d.diff

LOG: [LegacyPassManager] Simplify PMStack pop

Added: 
    

Modified: 
    llvm/lib/IR/LegacyPassManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index 8fe59912f20a..f3c13728d0cb 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -1776,16 +1776,10 @@ LLVM_DUMP_METHOD void PMStack::dump() const {
 void ModulePass::assignPassManager(PMStack &PMS,
                                    PassManagerType PreferredType) {
   // Find Module Pass Manager
-  while (!PMS.empty()) {
-    PassManagerType TopPMType = PMS.top()->getPassManagerType();
-    if (TopPMType == PreferredType)
-      break; // We found desired pass manager
-    else if (TopPMType > PMT_ModulePassManager)
-      PMS.pop();    // Pop children pass managers
-    else
-      break;
-  }
-  assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
+  PassManagerType T;
+  while ((T = PMS.top()->getPassManagerType()) > PMT_ModulePassManager &&
+         T != PreferredType)
+    PMS.pop();
   PMS.top()->add(this);
 }
 
@@ -1793,21 +1787,15 @@ void ModulePass::assignPassManager(PMStack &PMS,
 /// in the PM Stack and add self into that manager.
 void FunctionPass::assignPassManager(PMStack &PMS,
                                      PassManagerType PreferredType) {
-
   // Find Function Pass Manager
-  while (!PMS.empty()) {
-    if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
-      PMS.pop();
-    else
-      break;
-  }
+  while (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
+    PMS.pop();
 
   // Create new Function Pass Manager if needed.
   FPPassManager *FPP;
   if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
     FPP = (FPPassManager *)PMS.top();
   } else {
-    assert(!PMS.empty() && "Unable to create Function Pass Manager");
     PMDataManager *PMD = PMS.top();
 
     // [1] Create new Function Pass Manager


        


More information about the llvm-commits mailing list