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 initializeLowerExpectIntrinsicPass(PassRegistry&);
|
||||||
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&);
|
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&);
|
||||||
void initializeLowerIntrinsicsPass(PassRegistry&);
|
void initializeLowerIntrinsicsPass(PassRegistry&);
|
||||||
void initializeLowerInvokePass(PassRegistry&);
|
void initializeLowerInvokeLegacyPassPass(PassRegistry&);
|
||||||
void initializeLowerSwitchPass(PassRegistry&);
|
void initializeLowerSwitchPass(PassRegistry&);
|
||||||
void initializeLowerTypeTestsPass(PassRegistry&);
|
void initializeLowerTypeTestsPass(PassRegistry&);
|
||||||
void initializeMIRPrintingPassPass(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/BreakCriticalEdges.h"
|
||||||
#include "llvm/Transforms/Utils/LCSSA.h"
|
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||||
#include "llvm/Transforms/Utils/LoopSimplify.h"
|
#include "llvm/Transforms/Utils/LoopSimplify.h"
|
||||||
|
#include "llvm/Transforms/Utils/LowerInvoke.h"
|
||||||
#include "llvm/Transforms/Utils/Mem2Reg.h"
|
#include "llvm/Transforms/Utils/Mem2Reg.h"
|
||||||
#include "llvm/Transforms/Utils/MemorySSA.h"
|
#include "llvm/Transforms/Utils/MemorySSA.h"
|
||||||
#include "llvm/Transforms/Utils/NameAnonFunctions.h"
|
#include "llvm/Transforms/Utils/NameAnonFunctions.h"
|
||||||
|
|
|
@ -151,6 +151,7 @@ FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
|
||||||
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
||||||
FUNCTION_PASS("gvn", GVN())
|
FUNCTION_PASS("gvn", GVN())
|
||||||
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
|
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
|
||||||
|
FUNCTION_PASS("lowerinvoke", LowerInvokePass())
|
||||||
FUNCTION_PASS("mem2reg", PromotePass())
|
FUNCTION_PASS("mem2reg", PromotePass())
|
||||||
FUNCTION_PASS("memcpyopt", MemCpyOptPass())
|
FUNCTION_PASS("memcpyopt", MemCpyOptPass())
|
||||||
FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
|
FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Transforms/Utils/LowerInvoke.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
|
@ -28,36 +29,29 @@ using namespace llvm;
|
||||||
STATISTIC(NumInvokes, "Number of invokes replaced");
|
STATISTIC(NumInvokes, "Number of invokes replaced");
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class LowerInvoke : public FunctionPass {
|
class LowerInvokeLegacyPass : public FunctionPass {
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
explicit LowerInvoke() : FunctionPass(ID) {
|
explicit LowerInvokeLegacyPass() : FunctionPass(ID) {
|
||||||
initializeLowerInvokePass(*PassRegistry::getPassRegistry());
|
initializeLowerInvokeLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
bool runOnFunction(Function &F) override;
|
bool runOnFunction(Function &F) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
char LowerInvoke::ID = 0;
|
char LowerInvokeLegacyPass::ID = 0;
|
||||||
INITIALIZE_PASS(LowerInvoke, "lowerinvoke",
|
INITIALIZE_PASS(LowerInvokeLegacyPass, "lowerinvoke",
|
||||||
"Lower invoke and unwind, for unwindless code generators",
|
"Lower invoke and unwind, for unwindless code generators",
|
||||||
false, false)
|
false, false)
|
||||||
|
|
||||||
char &llvm::LowerInvokePassID = LowerInvoke::ID;
|
static bool runImpl(Function &F) {
|
||||||
|
|
||||||
// Public Interface To the LowerInvoke pass.
|
|
||||||
FunctionPass *llvm::createLowerInvokePass() {
|
|
||||||
return new LowerInvoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LowerInvoke::runOnFunction(Function &F) {
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (BasicBlock &BB : F)
|
for (BasicBlock &BB : F)
|
||||||
if (InvokeInst *II = dyn_cast<InvokeInst>(BB.getTerminator())) {
|
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...
|
// Insert a normal call instruction...
|
||||||
CallInst *NewCall = CallInst::Create(II->getCalledValue(),
|
CallInst *NewCall =
|
||||||
CallArgs, "", II);
|
CallInst::Create(II->getCalledValue(), CallArgs, "", II);
|
||||||
NewCall->takeName(II);
|
NewCall->takeName(II);
|
||||||
NewCall->setCallingConv(II->getCallingConv());
|
NewCall->setCallingConv(II->getCallingConv());
|
||||||
NewCall->setAttributes(II->getAttributes());
|
NewCall->setAttributes(II->getAttributes());
|
||||||
|
@ -73,7 +67,28 @@ bool LowerInvoke::runOnFunction(Function &F) {
|
||||||
// Remove the invoke instruction now.
|
// Remove the invoke instruction now.
|
||||||
BB.getInstList().erase(II);
|
BB.getInstList().erase(II);
|
||||||
|
|
||||||
++NumInvokes; Changed = true;
|
++NumInvokes;
|
||||||
|
Changed = true;
|
||||||
}
|
}
|
||||||
return Changed;
|
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);
|
initializeInstNamerPass(Registry);
|
||||||
initializeLCSSAWrapperPassPass(Registry);
|
initializeLCSSAWrapperPassPass(Registry);
|
||||||
initializeLoopSimplifyPass(Registry);
|
initializeLoopSimplifyPass(Registry);
|
||||||
initializeLowerInvokePass(Registry);
|
initializeLowerInvokeLegacyPassPass(Registry);
|
||||||
initializeLowerSwitchPass(Registry);
|
initializeLowerSwitchPass(Registry);
|
||||||
initializeNameAnonFunctionLegacyPassPass(Registry);
|
initializeNameAnonFunctionLegacyPassPass(Registry);
|
||||||
initializePromoteLegacyPassPass(Registry);
|
initializePromoteLegacyPassPass(Registry);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lowerinvoke -S | FileCheck %s
|
; RUN: opt < %s -lowerinvoke -S | FileCheck %s
|
||||||
|
; RUN: opt < %s -passes='lowerinvoke' -S | FileCheck %s
|
||||||
|
|
||||||
declare i32 @external_func(i64 %arg)
|
declare i32 @external_func(i64 %arg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue