forked from OSchip/llvm-project
[PM] Port LowerInvoke to the new pass manager
llvm-svn: 278531
This commit is contained in:
parent
88661f55c3
commit
31b8399beb
|
@ -205,7 +205,7 @@ void initializeLowerEmuTLSPass(PassRegistry&);
|
|||
void initializeLowerExpectIntrinsicPass(PassRegistry&);
|
||||
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&);
|
||||
void initializeLowerIntrinsicsPass(PassRegistry&);
|
||||
void initializeLowerInvokePass(PassRegistry&);
|
||||
void initializeLowerInvokeLegacyPassPass(PassRegistry&);
|
||||
void initializeLowerSwitchPass(PassRegistry&);
|
||||
void initializeLowerTypeTestsPass(PassRegistry&);
|
||||
void initializeMIRPrintingPassPass(PassRegistry&);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//===- LowerInvoke.h - Eliminate Invoke instructions ----------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This transformation is designed for use by code generators which do not yet
|
||||
// support stack unwinding. This pass converts 'invoke' instructions to 'call'
|
||||
// instructions, so that any exception-handling 'landingpad' blocks become dead
|
||||
// code (which can be removed by running the '-simplifycfg' pass afterwards).
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
|
||||
#define LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class LowerInvokePass : public PassInfoMixin<LowerInvokePass> {
|
||||
public:
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
|
|
@ -119,6 +119,7 @@
|
|||
#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
|
||||
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||
#include "llvm/Transforms/Utils/LoopSimplify.h"
|
||||
#include "llvm/Transforms/Utils/LowerInvoke.h"
|
||||
#include "llvm/Transforms/Utils/Mem2Reg.h"
|
||||
#include "llvm/Transforms/Utils/MemorySSA.h"
|
||||
#include "llvm/Transforms/Utils/NameAnonFunctions.h"
|
||||
|
|
|
@ -151,6 +151,7 @@ FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
|
|||
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
||||
FUNCTION_PASS("gvn", GVN())
|
||||
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
|
||||
FUNCTION_PASS("lowerinvoke", LowerInvokePass())
|
||||
FUNCTION_PASS("mem2reg", PromotePass())
|
||||
FUNCTION_PASS("memcpyopt", MemCpyOptPass())
|
||||
FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Utils/LowerInvoke.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
|
@ -28,36 +29,29 @@ using namespace llvm;
|
|||
STATISTIC(NumInvokes, "Number of invokes replaced");
|
||||
|
||||
namespace {
|
||||
class LowerInvoke : public FunctionPass {
|
||||
class LowerInvokeLegacyPass : public FunctionPass {
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
explicit LowerInvoke() : FunctionPass(ID) {
|
||||
initializeLowerInvokePass(*PassRegistry::getPassRegistry());
|
||||
explicit LowerInvokeLegacyPass() : FunctionPass(ID) {
|
||||
initializeLowerInvokeLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
bool runOnFunction(Function &F) override;
|
||||
};
|
||||
}
|
||||
|
||||
char LowerInvoke::ID = 0;
|
||||
INITIALIZE_PASS(LowerInvoke, "lowerinvoke",
|
||||
char LowerInvokeLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(LowerInvokeLegacyPass, "lowerinvoke",
|
||||
"Lower invoke and unwind, for unwindless code generators",
|
||||
false, false)
|
||||
|
||||
char &llvm::LowerInvokePassID = LowerInvoke::ID;
|
||||
|
||||
// Public Interface To the LowerInvoke pass.
|
||||
FunctionPass *llvm::createLowerInvokePass() {
|
||||
return new LowerInvoke();
|
||||
}
|
||||
|
||||
bool LowerInvoke::runOnFunction(Function &F) {
|
||||
static bool runImpl(Function &F) {
|
||||
bool Changed = false;
|
||||
for (BasicBlock &BB : F)
|
||||
if (InvokeInst *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
|
||||
SmallVector<Value*,16> CallArgs(II->op_begin(), II->op_end() - 3);
|
||||
SmallVector<Value *, 16> CallArgs(II->op_begin(), II->op_end() - 3);
|
||||
// Insert a normal call instruction...
|
||||
CallInst *NewCall = CallInst::Create(II->getCalledValue(),
|
||||
CallArgs, "", II);
|
||||
CallInst *NewCall =
|
||||
CallInst::Create(II->getCalledValue(), CallArgs, "", II);
|
||||
NewCall->takeName(II);
|
||||
NewCall->setCallingConv(II->getCallingConv());
|
||||
NewCall->setAttributes(II->getAttributes());
|
||||
|
@ -73,7 +67,28 @@ bool LowerInvoke::runOnFunction(Function &F) {
|
|||
// Remove the invoke instruction now.
|
||||
BB.getInstList().erase(II);
|
||||
|
||||
++NumInvokes; Changed = true;
|
||||
++NumInvokes;
|
||||
Changed = true;
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool LowerInvokeLegacyPass::runOnFunction(Function &F) {
|
||||
return runImpl(F);
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
char &LowerInvokePassID = LowerInvokeLegacyPass::ID;
|
||||
|
||||
// Public Interface To the LowerInvoke pass.
|
||||
FunctionPass *createLowerInvokePass() { return new LowerInvokeLegacyPass(); }
|
||||
|
||||
PreservedAnalyses LowerInvokePass::run(Function &F,
|
||||
FunctionAnalysisManager &AM) {
|
||||
bool Changed = runImpl(F);
|
||||
if (!Changed)
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ void llvm::initializeTransformUtils(PassRegistry &Registry) {
|
|||
initializeInstNamerPass(Registry);
|
||||
initializeLCSSAWrapperPassPass(Registry);
|
||||
initializeLoopSimplifyPass(Registry);
|
||||
initializeLowerInvokePass(Registry);
|
||||
initializeLowerInvokeLegacyPassPass(Registry);
|
||||
initializeLowerSwitchPass(Registry);
|
||||
initializeNameAnonFunctionLegacyPassPass(Registry);
|
||||
initializePromoteLegacyPassPass(Registry);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -lowerinvoke -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='lowerinvoke' -S | FileCheck %s
|
||||
|
||||
declare i32 @external_func(i64 %arg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue