forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
04cb01cf10
commit
beeed0994e
|
@ -10,9 +10,9 @@
|
||||||
#include "CoroInternal.h"
|
#include "CoroInternal.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/InstIterator.h"
|
#include "llvm/IR/InstIterator.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#include "llvm/IR/PassManager.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
@ -23,19 +23,10 @@ namespace {
|
||||||
struct Lowerer : coro::LowererBase {
|
struct Lowerer : coro::LowererBase {
|
||||||
IRBuilder<> Builder;
|
IRBuilder<> Builder;
|
||||||
Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
|
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) {
|
static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
|
||||||
Builder.SetInsertPoint(SubFn);
|
Builder.SetInsertPoint(SubFn);
|
||||||
Value *FrameRaw = SubFn->getFrame();
|
Value *FrameRaw = SubFn->getFrame();
|
||||||
|
@ -53,9 +44,10 @@ static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
|
||||||
SubFn->replaceAllUsesWith(Load);
|
SubFn->replaceAllUsesWith(Load);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lowerer::lower(Function &F) {
|
bool Lowerer::lower(Function &F) {
|
||||||
bool IsPrivateAndUnprocessed =
|
bool IsPrivateAndUnprocessed =
|
||||||
F.hasFnAttribute(CORO_PRESPLIT_ATTR) && F.hasLocalLinkage();
|
F.hasFnAttribute(CORO_PRESPLIT_ATTR) && F.hasLocalLinkage();
|
||||||
|
bool Changed = false;
|
||||||
|
|
||||||
for (Instruction &I : llvm::make_early_inc_range(instructions(F))) {
|
for (Instruction &I : llvm::make_early_inc_range(instructions(F))) {
|
||||||
if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
|
if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
|
||||||
|
@ -110,11 +102,11 @@ void Lowerer::lower(Function &F) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
II->eraseFromParent();
|
II->eraseFromParent();
|
||||||
|
Changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After replacement were made we can cleanup the function body a little.
|
return Changed;
|
||||||
simplifyCFG(F);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool declaresCoroCleanupIntrinsics(const Module &M) {
|
static bool declaresCoroCleanupIntrinsics(const Module &M) {
|
||||||
|
@ -130,9 +122,16 @@ PreservedAnalyses CoroCleanupPass::run(Module &M,
|
||||||
if (!declaresCoroCleanupIntrinsics(M))
|
if (!declaresCoroCleanupIntrinsics(M))
|
||||||
return PreservedAnalyses::all();
|
return PreservedAnalyses::all();
|
||||||
|
|
||||||
|
FunctionAnalysisManager &FAM =
|
||||||
|
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
||||||
|
|
||||||
|
FunctionPassManager FPM;
|
||||||
|
FPM.addPass(SimplifyCFGPass());
|
||||||
|
|
||||||
Lowerer L(M);
|
Lowerer L(M);
|
||||||
for (auto &F : M)
|
for (auto &F : M)
|
||||||
L.lower(F);
|
if (L.lower(F))
|
||||||
|
FPM.run(F, FAM);
|
||||||
|
|
||||||
return PreservedAnalyses::none();
|
return PreservedAnalyses::none();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
#include "llvm/IR/IntrinsicInst.h"
|
||||||
#include "llvm/IR/LLVMContext.h"
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/Type.h"
|
#include "llvm/IR/Type.h"
|
||||||
#include "llvm/IR/Value.h"
|
#include "llvm/IR/Value.h"
|
||||||
|
|
Loading…
Reference in New Issue