[llvm] beeed09 - [Coroutines] Use PassManager instead of Legacy PassManager internally

Chuanqi Xu via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 22:15:35 PDT 2022


Author: Chuanqi Xu
Date: 2022-05-10T13:15:11+08:00
New Revision: beeed0994eff7397d692a050cfdad9f4de7b75db

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

LOG: [Coroutines] Use PassManager instead of Legacy PassManager internally

This is a following cleanup for the previous work D123918. I missed
serveral places which still use legacy pass managers. This patch tries
to remove them.

Added: 
    

Modified: 
    llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
    llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
index 6795bac967801..56ba250ee5ac2 100644
--- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -10,9 +10,9 @@
 #include "CoroInternal.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstIterator.h"
-#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
-#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
 
 using namespace llvm;
 
@@ -23,19 +23,10 @@ namespace {
 struct Lowerer : coro::LowererBase {
   IRBuilder<> Builder;
   Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
-  void lower(Function &F);
+  bool lower(Function &F);
 };
 }
 
-static void simplifyCFG(Function &F) {
-  llvm::legacy::FunctionPassManager FPM(F.getParent());
-  FPM.add(createCFGSimplificationPass());
-
-  FPM.doInitialization();
-  FPM.run(F);
-  FPM.doFinalization();
-}
-
 static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
   Builder.SetInsertPoint(SubFn);
   Value *FrameRaw = SubFn->getFrame();
@@ -53,9 +44,10 @@ static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
   SubFn->replaceAllUsesWith(Load);
 }
 
-void Lowerer::lower(Function &F) {
+bool Lowerer::lower(Function &F) {
   bool IsPrivateAndUnprocessed =
       F.hasFnAttribute(CORO_PRESPLIT_ATTR) && F.hasLocalLinkage();
+  bool Changed = false;
 
   for (Instruction &I : llvm::make_early_inc_range(instructions(F))) {
     if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
@@ -110,11 +102,11 @@ void Lowerer::lower(Function &F) {
         break;
       }
       II->eraseFromParent();
+      Changed = true;
     }
   }
 
-  // After replacement were made we can cleanup the function body a little.
-  simplifyCFG(F);
+  return Changed;
 }
 
 static bool declaresCoroCleanupIntrinsics(const Module &M) {
@@ -130,9 +122,16 @@ PreservedAnalyses CoroCleanupPass::run(Module &M,
   if (!declaresCoroCleanupIntrinsics(M))
     return PreservedAnalyses::all();
 
+  FunctionAnalysisManager &FAM =
+      MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+
+  FunctionPassManager FPM;
+  FPM.addPass(SimplifyCFGPass());
+
   Lowerer L(M);
   for (auto &F : M)
-    L.lower(F);
+    if (L.lower(F))
+      FPM.run(F, FAM);
 
   return PreservedAnalyses::none();
 }

diff  --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 25869ada9db3b..c04ac0a4c36b8 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -51,7 +51,6 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"


        


More information about the llvm-commits mailing list