mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Reland r229944: EH: Prune unreachable resume instructions during Dwarf EH preparation
Fix the double-deletion of AnalysisResolver when delegating through to Dwarf EH preparation by creating one from scratch. Hopefully the new pass manager simplifies this. This reverts commit r229952. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231719 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9e065f52fc
commit
4c27f8d49e
@ -612,13 +612,13 @@ namespace llvm {
|
|||||||
ModulePass *createForwardControlFlowIntegrityPass();
|
ModulePass *createForwardControlFlowIntegrityPass();
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
/// This initializer registers TargetMachine constructor, so the pass being
|
/// Target machine pass initializer for passes with dependencies. Use with
|
||||||
/// initialized can use target dependent interfaces. Please do not move this
|
/// INITIALIZE_TM_PASS_END.
|
||||||
/// macro to be together with INITIALIZE_PASS, which is a complete target
|
#define INITIALIZE_TM_PASS_BEGIN INITIALIZE_PASS_BEGIN
|
||||||
/// independent initializer, and we don't want to make libScalarOpts depend
|
|
||||||
/// on libCodeGen.
|
/// Target machine pass initializer for passes with dependencies. Use with
|
||||||
#define INITIALIZE_TM_PASS(passName, arg, name, cfg, analysis) \
|
/// INITIALIZE_TM_PASS_BEGIN.
|
||||||
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
|
#define INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis) \
|
||||||
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
|
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
|
||||||
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis, \
|
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis, \
|
||||||
PassInfo::TargetMachineCtor_t(callTargetMachineCtor< passName >)); \
|
PassInfo::TargetMachineCtor_t(callTargetMachineCtor< passName >)); \
|
||||||
@ -629,4 +629,13 @@ namespace llvm {
|
|||||||
CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
|
CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This initializer registers TargetMachine constructor, so the pass being
|
||||||
|
/// initialized can use target dependent interfaces. Please do not move this
|
||||||
|
/// macro to be together with INITIALIZE_PASS, which is a complete target
|
||||||
|
/// independent initializer, and we don't want to make libScalarOpts depend
|
||||||
|
/// on libCodeGen.
|
||||||
|
#define INITIALIZE_TM_PASS(passName, arg, name, cfg, analysis) \
|
||||||
|
INITIALIZE_TM_PASS_BEGIN(passName, arg, name, cfg, analysis) \
|
||||||
|
INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,9 +24,10 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
|||||||
initializeBranchFolderPassPass(Registry);
|
initializeBranchFolderPassPass(Registry);
|
||||||
initializeCodeGenPreparePass(Registry);
|
initializeCodeGenPreparePass(Registry);
|
||||||
initializeDeadMachineInstructionElimPass(Registry);
|
initializeDeadMachineInstructionElimPass(Registry);
|
||||||
|
initializeDwarfEHPreparePass(Registry);
|
||||||
initializeEarlyIfConverterPass(Registry);
|
initializeEarlyIfConverterPass(Registry);
|
||||||
initializeExpandPostRAPass(Registry);
|
|
||||||
initializeExpandISelPseudosPass(Registry);
|
initializeExpandISelPseudosPass(Registry);
|
||||||
|
initializeExpandPostRAPass(Registry);
|
||||||
initializeFinalizeMachineBundlesPass(Registry);
|
initializeFinalizeMachineBundlesPass(Registry);
|
||||||
initializeGCMachineCodeAnalysisPass(Registry);
|
initializeGCMachineCodeAnalysisPass(Registry);
|
||||||
initializeGCModuleInfoPass(Registry);
|
initializeGCModuleInfoPass(Registry);
|
||||||
@ -36,31 +37,34 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
|||||||
initializeLiveStacksPass(Registry);
|
initializeLiveStacksPass(Registry);
|
||||||
initializeLiveVariablesPass(Registry);
|
initializeLiveVariablesPass(Registry);
|
||||||
initializeLocalStackSlotPassPass(Registry);
|
initializeLocalStackSlotPassPass(Registry);
|
||||||
|
initializeLowerIntrinsicsPass(Registry);
|
||||||
initializeMachineBlockFrequencyInfoPass(Registry);
|
initializeMachineBlockFrequencyInfoPass(Registry);
|
||||||
initializeMachineBlockPlacementPass(Registry);
|
initializeMachineBlockPlacementPass(Registry);
|
||||||
initializeMachineBlockPlacementStatsPass(Registry);
|
initializeMachineBlockPlacementStatsPass(Registry);
|
||||||
initializeMachineCopyPropagationPass(Registry);
|
|
||||||
initializeMachineCombinerPass(Registry);
|
|
||||||
initializeMachineCSEPass(Registry);
|
initializeMachineCSEPass(Registry);
|
||||||
|
initializeMachineCombinerPass(Registry);
|
||||||
|
initializeMachineCopyPropagationPass(Registry);
|
||||||
initializeMachineDominatorTreePass(Registry);
|
initializeMachineDominatorTreePass(Registry);
|
||||||
initializeMachinePostDominatorTreePass(Registry);
|
initializeMachineFunctionPrinterPassPass(Registry);
|
||||||
initializeMachineLICMPass(Registry);
|
initializeMachineLICMPass(Registry);
|
||||||
initializeMachineLoopInfoPass(Registry);
|
initializeMachineLoopInfoPass(Registry);
|
||||||
initializeMachineModuleInfoPass(Registry);
|
initializeMachineModuleInfoPass(Registry);
|
||||||
|
initializeMachinePostDominatorTreePass(Registry);
|
||||||
initializeMachineSchedulerPass(Registry);
|
initializeMachineSchedulerPass(Registry);
|
||||||
initializeMachineSinkingPass(Registry);
|
initializeMachineSinkingPass(Registry);
|
||||||
initializeMachineVerifierPassPass(Registry);
|
initializeMachineVerifierPassPass(Registry);
|
||||||
initializeOptimizePHIsPass(Registry);
|
initializeOptimizePHIsPass(Registry);
|
||||||
|
initializePEIPass(Registry);
|
||||||
initializePHIEliminationPass(Registry);
|
initializePHIEliminationPass(Registry);
|
||||||
initializePeepholeOptimizerPass(Registry);
|
initializePeepholeOptimizerPass(Registry);
|
||||||
initializePostMachineSchedulerPass(Registry);
|
initializePostMachineSchedulerPass(Registry);
|
||||||
initializePostRASchedulerPass(Registry);
|
initializePostRASchedulerPass(Registry);
|
||||||
initializeProcessImplicitDefsPass(Registry);
|
initializeProcessImplicitDefsPass(Registry);
|
||||||
initializePEIPass(Registry);
|
|
||||||
initializeRegisterCoalescerPass(Registry);
|
initializeRegisterCoalescerPass(Registry);
|
||||||
initializeSlotIndexesPass(Registry);
|
initializeSlotIndexesPass(Registry);
|
||||||
initializeStackProtectorPass(Registry);
|
|
||||||
initializeStackColoringPass(Registry);
|
initializeStackColoringPass(Registry);
|
||||||
|
initializeStackMapLivenessPass(Registry);
|
||||||
|
initializeStackProtectorPass(Registry);
|
||||||
initializeStackSlotColoringPass(Registry);
|
initializeStackSlotColoringPass(Registry);
|
||||||
initializeTailDuplicatePassPass(Registry);
|
initializeTailDuplicatePassPass(Registry);
|
||||||
initializeTargetPassConfigPass(Registry);
|
initializeTargetPassConfigPass(Registry);
|
||||||
@ -70,9 +74,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
|||||||
initializeUnreachableMachineBlockElimPass(Registry);
|
initializeUnreachableMachineBlockElimPass(Registry);
|
||||||
initializeVirtRegMapPass(Registry);
|
initializeVirtRegMapPass(Registry);
|
||||||
initializeVirtRegRewriterPass(Registry);
|
initializeVirtRegRewriterPass(Registry);
|
||||||
initializeLowerIntrinsicsPass(Registry);
|
initializeWinEHPreparePass(Registry);
|
||||||
initializeMachineFunctionPrinterPassPass(Registry);
|
|
||||||
initializeStackMapLivenessPass(Registry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLVMInitializeCodeGen(LLVMPassRegistryRef R) {
|
void LLVMInitializeCodeGen(LLVMPassRegistryRef R) {
|
||||||
|
@ -13,13 +13,18 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/CodeGen/Passes.h"
|
#include "llvm/CodeGen/Passes.h"
|
||||||
|
#include "llvm/ADT/BitVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
#include "llvm/Analysis/CFG.h"
|
||||||
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||||
|
#include "llvm/IR/Dominators.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Target/TargetLowering.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||||
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#define DEBUG_TYPE "dwarfehprepare"
|
#define DEBUG_TYPE "dwarfehprepare"
|
||||||
@ -33,18 +38,28 @@ namespace {
|
|||||||
// RewindFunction - _Unwind_Resume or the target equivalent.
|
// RewindFunction - _Unwind_Resume or the target equivalent.
|
||||||
Constant *RewindFunction;
|
Constant *RewindFunction;
|
||||||
|
|
||||||
|
DominatorTree *DT;
|
||||||
|
const TargetLowering *TLI;
|
||||||
|
|
||||||
bool InsertUnwindResumeCalls(Function &Fn);
|
bool InsertUnwindResumeCalls(Function &Fn);
|
||||||
Value *GetExceptionObject(ResumeInst *RI);
|
Value *GetExceptionObject(ResumeInst *RI);
|
||||||
|
size_t
|
||||||
|
pruneUnreachableResumes(Function &Fn,
|
||||||
|
SmallVectorImpl<ResumeInst *> &Resumes,
|
||||||
|
SmallVectorImpl<LandingPadInst *> &CleanupLPads);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid.
|
static char ID; // Pass identification, replacement for typeid.
|
||||||
|
|
||||||
// INITIALIZE_TM_PASS requires a default constructor, but it isn't used in
|
// INITIALIZE_TM_PASS requires a default constructor, but it isn't used in
|
||||||
// practice.
|
// practice.
|
||||||
DwarfEHPrepare() : FunctionPass(ID), TM(nullptr), RewindFunction(nullptr) {}
|
DwarfEHPrepare()
|
||||||
|
: FunctionPass(ID), TM(nullptr), RewindFunction(nullptr), DT(nullptr),
|
||||||
|
TLI(nullptr) {}
|
||||||
|
|
||||||
DwarfEHPrepare(const TargetMachine *TM)
|
DwarfEHPrepare(const TargetMachine *TM)
|
||||||
: FunctionPass(ID), TM(TM), RewindFunction(nullptr) {}
|
: FunctionPass(ID), TM(TM), RewindFunction(nullptr), DT(nullptr),
|
||||||
|
TLI(nullptr) {}
|
||||||
|
|
||||||
bool runOnFunction(Function &Fn) override;
|
bool runOnFunction(Function &Fn) override;
|
||||||
|
|
||||||
@ -53,6 +68,8 @@ namespace {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
||||||
|
|
||||||
const char *getPassName() const override {
|
const char *getPassName() const override {
|
||||||
return "Exception handling preparation";
|
return "Exception handling preparation";
|
||||||
}
|
}
|
||||||
@ -60,13 +77,22 @@ namespace {
|
|||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
char DwarfEHPrepare::ID = 0;
|
char DwarfEHPrepare::ID = 0;
|
||||||
INITIALIZE_TM_PASS(DwarfEHPrepare, "dwarfehprepare", "Prepare DWARF exceptions",
|
INITIALIZE_TM_PASS_BEGIN(DwarfEHPrepare, "dwarfehprepare",
|
||||||
false, false)
|
"Prepare DWARF exceptions", false, false)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
||||||
|
INITIALIZE_TM_PASS_END(DwarfEHPrepare, "dwarfehprepare",
|
||||||
|
"Prepare DWARF exceptions", false, false)
|
||||||
|
|
||||||
FunctionPass *llvm::createDwarfEHPass(const TargetMachine *TM) {
|
FunctionPass *llvm::createDwarfEHPass(const TargetMachine *TM) {
|
||||||
return new DwarfEHPrepare(TM);
|
return new DwarfEHPrepare(TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DwarfEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||||
|
AU.addRequired<DominatorTreeWrapperPass>();
|
||||||
|
}
|
||||||
|
|
||||||
/// GetExceptionObject - Return the exception object from the value passed into
|
/// GetExceptionObject - Return the exception object from the value passed into
|
||||||
/// the 'resume' instruction (typically an aggregate). Clean up any dead
|
/// the 'resume' instruction (typically an aggregate). Clean up any dead
|
||||||
/// instructions, including the 'resume' instruction.
|
/// instructions, including the 'resume' instruction.
|
||||||
@ -107,21 +133,71 @@ Value *DwarfEHPrepare::GetExceptionObject(ResumeInst *RI) {
|
|||||||
return ExnObj;
|
return ExnObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replace resumes that are not reachable from a cleanup landing pad with
|
||||||
|
/// unreachable and then simplify those blocks.
|
||||||
|
size_t DwarfEHPrepare::pruneUnreachableResumes(
|
||||||
|
Function &Fn, SmallVectorImpl<ResumeInst *> &Resumes,
|
||||||
|
SmallVectorImpl<LandingPadInst *> &CleanupLPads) {
|
||||||
|
BitVector ResumeReachable(Resumes.size());
|
||||||
|
size_t ResumeIndex = 0;
|
||||||
|
for (auto *RI : Resumes) {
|
||||||
|
for (auto *LP : CleanupLPads) {
|
||||||
|
if (isPotentiallyReachable(LP, RI, DT)) {
|
||||||
|
ResumeReachable.set(ResumeIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++ResumeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If everything is reachable, there is no change.
|
||||||
|
if (ResumeReachable.all())
|
||||||
|
return Resumes.size();
|
||||||
|
|
||||||
|
const TargetTransformInfo &TTI =
|
||||||
|
getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
|
||||||
|
LLVMContext &Ctx = Fn.getContext();
|
||||||
|
|
||||||
|
// Otherwise, insert unreachable instructions and call simplifycfg.
|
||||||
|
size_t ResumesLeft = 0;
|
||||||
|
for (size_t I = 0, E = Resumes.size(); I < E; ++I) {
|
||||||
|
ResumeInst *RI = Resumes[I];
|
||||||
|
if (ResumeReachable[I]) {
|
||||||
|
Resumes[ResumesLeft++] = RI;
|
||||||
|
} else {
|
||||||
|
BasicBlock *BB = RI->getParent();
|
||||||
|
new UnreachableInst(Ctx, RI);
|
||||||
|
RI->eraseFromParent();
|
||||||
|
SimplifyCFG(BB, TTI, 1, TLI->getDataLayout());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Resumes.resize(ResumesLeft);
|
||||||
|
return ResumesLeft;
|
||||||
|
}
|
||||||
|
|
||||||
/// InsertUnwindResumeCalls - Convert the ResumeInsts that are still present
|
/// InsertUnwindResumeCalls - Convert the ResumeInsts that are still present
|
||||||
/// into calls to the appropriate _Unwind_Resume function.
|
/// into calls to the appropriate _Unwind_Resume function.
|
||||||
bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
|
bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
|
||||||
SmallVector<ResumeInst*, 16> Resumes;
|
SmallVector<ResumeInst*, 16> Resumes;
|
||||||
|
SmallVector<LandingPadInst*, 16> CleanupLPads;
|
||||||
for (BasicBlock &BB : Fn) {
|
for (BasicBlock &BB : Fn) {
|
||||||
if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
|
if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
|
||||||
Resumes.push_back(RI);
|
Resumes.push_back(RI);
|
||||||
|
if (auto *LP = BB.getLandingPadInst())
|
||||||
|
if (LP->isCleanup())
|
||||||
|
CleanupLPads.push_back(LP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Resumes.empty())
|
if (Resumes.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Find the rewind function if we didn't already.
|
|
||||||
const TargetLowering *TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
|
|
||||||
LLVMContext &Ctx = Fn.getContext();
|
LLVMContext &Ctx = Fn.getContext();
|
||||||
|
|
||||||
|
size_t ResumesLeft = pruneUnreachableResumes(Fn, Resumes, CleanupLPads);
|
||||||
|
if (ResumesLeft == 0)
|
||||||
|
return true; // We pruned them all.
|
||||||
|
|
||||||
|
// Find the rewind function if we didn't already.
|
||||||
if (!RewindFunction) {
|
if (!RewindFunction) {
|
||||||
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
|
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
|
||||||
Type::getInt8PtrTy(Ctx), false);
|
Type::getInt8PtrTy(Ctx), false);
|
||||||
@ -130,9 +206,7 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the basic block where the _Unwind_Resume call will live.
|
// Create the basic block where the _Unwind_Resume call will live.
|
||||||
unsigned ResumesSize = Resumes.size();
|
if (ResumesLeft == 1) {
|
||||||
|
|
||||||
if (ResumesSize == 1) {
|
|
||||||
// Instead of creating a new BB and PHI node, just append the call to
|
// Instead of creating a new BB and PHI node, just append the call to
|
||||||
// _Unwind_Resume to the end of the single resume block.
|
// _Unwind_Resume to the end of the single resume block.
|
||||||
ResumeInst *RI = Resumes.front();
|
ResumeInst *RI = Resumes.front();
|
||||||
@ -149,7 +223,7 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &Fn);
|
BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &Fn);
|
||||||
PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesSize,
|
PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesLeft,
|
||||||
"exn.obj", UnwindBB);
|
"exn.obj", UnwindBB);
|
||||||
|
|
||||||
// Extract the exception object from the ResumeInst and add it to the PHI node
|
// Extract the exception object from the ResumeInst and add it to the PHI node
|
||||||
@ -175,6 +249,10 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
|
|||||||
|
|
||||||
bool DwarfEHPrepare::runOnFunction(Function &Fn) {
|
bool DwarfEHPrepare::runOnFunction(Function &Fn) {
|
||||||
assert(TM && "DWARF EH preparation requires a target machine");
|
assert(TM && "DWARF EH preparation requires a target machine");
|
||||||
|
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||||
|
TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
|
||||||
bool Changed = InsertUnwindResumeCalls(Fn);
|
bool Changed = InsertUnwindResumeCalls(Fn);
|
||||||
|
DT = nullptr;
|
||||||
|
TLI = nullptr;
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#include "llvm/ADT/MapVector.h"
|
#include "llvm/ADT/MapVector.h"
|
||||||
#include "llvm/ADT/TinyPtrVector.h"
|
#include "llvm/ADT/TinyPtrVector.h"
|
||||||
#include "llvm/Analysis/LibCallSemantics.h"
|
#include "llvm/Analysis/LibCallSemantics.h"
|
||||||
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||||
|
#include "llvm/IR/Dominators.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
@ -168,8 +170,13 @@ public:
|
|||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
char WinEHPrepare::ID = 0;
|
char WinEHPrepare::ID = 0;
|
||||||
INITIALIZE_TM_PASS(WinEHPrepare, "winehprepare", "Prepare Windows exceptions",
|
INITIALIZE_TM_PASS_BEGIN(WinEHPrepare, "winehprepare",
|
||||||
false, false)
|
"Prepare Windows exceptions", false, false)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(DwarfEHPrepare)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
||||||
|
INITIALIZE_TM_PASS_END(WinEHPrepare, "winehprepare",
|
||||||
|
"Prepare Windows exceptions", false, false)
|
||||||
|
|
||||||
FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {
|
FunctionPass *llvm::createWinEHPass(const TargetMachine *TM) {
|
||||||
return new WinEHPrepare(TM);
|
return new WinEHPrepare(TM);
|
||||||
@ -198,8 +205,23 @@ bool WinEHPrepare::runOnFunction(Function &Fn) {
|
|||||||
EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());
|
EHPersonality Pers = classifyEHPersonality(LPads.back()->getPersonalityFn());
|
||||||
|
|
||||||
// Delegate through to the DWARF pass if this is unrecognized.
|
// Delegate through to the DWARF pass if this is unrecognized.
|
||||||
if (!isMSVCPersonality(Pers))
|
if (!isMSVCPersonality(Pers)) {
|
||||||
|
if (!DwarfPrepare->getResolver()) {
|
||||||
|
// Build an AnalysisResolver with the analyses needed by DwarfEHPrepare.
|
||||||
|
// It will take ownership of the AnalysisResolver.
|
||||||
|
assert(getResolver());
|
||||||
|
auto *AR = new AnalysisResolver(getResolver()->getPMDataManager());
|
||||||
|
AR->addAnalysisImplsPair(
|
||||||
|
&TargetTransformInfoWrapperPass::ID,
|
||||||
|
getResolver()->findImplPass(&TargetTransformInfoWrapperPass::ID));
|
||||||
|
AR->addAnalysisImplsPair(
|
||||||
|
&DominatorTreeWrapperPass::ID,
|
||||||
|
getResolver()->findImplPass(&DominatorTreeWrapperPass::ID));
|
||||||
|
DwarfPrepare->setResolver(AR);
|
||||||
|
}
|
||||||
|
|
||||||
return DwarfPrepare->runOnFunction(Fn);
|
return DwarfPrepare->runOnFunction(Fn);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: This only returns true if the C++ EH handlers were outlined.
|
// FIXME: This only returns true if the C++ EH handlers were outlined.
|
||||||
// When that code is complete, it should always return whatever
|
// When that code is complete, it should always return whatever
|
||||||
|
@ -27,6 +27,7 @@ lpad: ; preds = %entry
|
|||||||
; CHECK-EL: bne $5
|
; CHECK-EL: bne $5
|
||||||
|
|
||||||
%exn.val = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
%exn.val = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
cleanup
|
||||||
catch i8* bitcast (i8** @_ZTId to i8*)
|
catch i8* bitcast (i8** @_ZTId to i8*)
|
||||||
%exn = extractvalue { i8*, i32 } %exn.val, 0
|
%exn = extractvalue { i8*, i32 } %exn.val, 0
|
||||||
%sel = extractvalue { i8*, i32 } %exn.val, 1
|
%sel = extractvalue { i8*, i32 } %exn.val, 1
|
||||||
|
@ -7,12 +7,13 @@
|
|||||||
@int_typeinfo = global i8 0
|
@int_typeinfo = global i8 0
|
||||||
|
|
||||||
declare void @might_throw()
|
declare void @might_throw()
|
||||||
|
declare void @cleanup()
|
||||||
|
|
||||||
define i32 @simple_catch() {
|
define i32 @simple_cleanup_catch() {
|
||||||
invoke void @might_throw()
|
invoke void @might_throw()
|
||||||
to label %cont unwind label %lpad
|
to label %cont unwind label %lpad
|
||||||
|
|
||||||
; CHECK: define i32 @simple_catch()
|
; CHECK-LABEL: define i32 @simple_cleanup_catch()
|
||||||
; CHECK: invoke void @might_throw()
|
; CHECK: invoke void @might_throw()
|
||||||
|
|
||||||
cont:
|
cont:
|
||||||
@ -22,15 +23,18 @@ cont:
|
|||||||
|
|
||||||
lpad:
|
lpad:
|
||||||
%ehvals = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
%ehvals = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
cleanup
|
||||||
catch i8* @int_typeinfo
|
catch i8* @int_typeinfo
|
||||||
%ehptr = extractvalue { i8*, i32 } %ehvals, 0
|
%ehptr = extractvalue { i8*, i32 } %ehvals, 0
|
||||||
%ehsel = extractvalue { i8*, i32 } %ehvals, 1
|
%ehsel = extractvalue { i8*, i32 } %ehvals, 1
|
||||||
|
call void @cleanup()
|
||||||
%int_sel = call i32 @llvm.eh.typeid.for(i8* @int_typeinfo)
|
%int_sel = call i32 @llvm.eh.typeid.for(i8* @int_typeinfo)
|
||||||
%int_match = icmp eq i32 %ehsel, %int_sel
|
%int_match = icmp eq i32 %ehsel, %int_sel
|
||||||
br i1 %int_match, label %catch_int, label %eh.resume
|
br i1 %int_match, label %catch_int, label %eh.resume
|
||||||
|
|
||||||
; CHECK: lpad:
|
; CHECK: lpad:
|
||||||
; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
; CHECK: call void @cleanup()
|
||||||
; CHECK: call i32 @llvm.eh.typeid.for
|
; CHECK: call i32 @llvm.eh.typeid.for
|
||||||
; CHECK: br i1
|
; CHECK: br i1
|
||||||
|
|
||||||
@ -41,11 +45,114 @@ catch_int:
|
|||||||
; CHECK: ret i32 1
|
; CHECK: ret i32 1
|
||||||
|
|
||||||
eh.resume:
|
eh.resume:
|
||||||
resume { i8*, i32 } %ehvals
|
%tmp_ehvals = insertvalue { i8*, i32 } undef, i8* %ehptr, 0
|
||||||
|
%new_ehvals = insertvalue { i8*, i32 } %tmp_ehvals, i32 %ehsel, 1
|
||||||
|
resume { i8*, i32 } %new_ehvals
|
||||||
|
|
||||||
; CHECK: eh.resume:
|
; CHECK: eh.resume:
|
||||||
; CHECK: call void @_Unwind_Resume(i8* %{{.*}})
|
; CHECK-NEXT: call void @_Unwind_Resume(i8* %ehptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
define i32 @catch_no_resume() {
|
||||||
|
invoke void @might_throw()
|
||||||
|
to label %cont unwind label %lpad
|
||||||
|
|
||||||
|
cont:
|
||||||
|
ret i32 0
|
||||||
|
|
||||||
|
lpad:
|
||||||
|
%ehvals = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
catch i8* @int_typeinfo
|
||||||
|
%ehptr = extractvalue { i8*, i32 } %ehvals, 0
|
||||||
|
%ehsel = extractvalue { i8*, i32 } %ehvals, 1
|
||||||
|
%int_sel = call i32 @llvm.eh.typeid.for(i8* @int_typeinfo)
|
||||||
|
%int_match = icmp eq i32 %ehsel, %int_sel
|
||||||
|
br i1 %int_match, label %catch_int, label %eh.resume
|
||||||
|
|
||||||
|
catch_int:
|
||||||
|
ret i32 1
|
||||||
|
|
||||||
|
eh.resume:
|
||||||
|
%tmp_ehvals = insertvalue { i8*, i32 } undef, i8* %ehptr, 0
|
||||||
|
%new_ehvals = insertvalue { i8*, i32 } %tmp_ehvals, i32 %ehsel, 1
|
||||||
|
resume { i8*, i32 } %new_ehvals
|
||||||
|
}
|
||||||
|
|
||||||
|
; Check that we can prune the unreachable resume instruction.
|
||||||
|
|
||||||
|
; CHECK-LABEL: define i32 @catch_no_resume() {
|
||||||
|
; CHECK: invoke void @might_throw()
|
||||||
|
; CHECK: ret i32 0
|
||||||
|
; CHECK: lpad:
|
||||||
|
; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
; CHECK-NOT: br i1
|
||||||
|
; CHECK: ret i32 1
|
||||||
|
; CHECK-NOT: call void @_Unwind_Resume
|
||||||
|
; CHECK: {{^[}]}}
|
||||||
|
|
||||||
|
|
||||||
|
define i32 @catch_cleanup_merge() {
|
||||||
|
invoke void @might_throw()
|
||||||
|
to label %inner_invoke unwind label %outer_lpad
|
||||||
|
inner_invoke:
|
||||||
|
invoke void @might_throw()
|
||||||
|
to label %cont unwind label %inner_lpad
|
||||||
|
cont:
|
||||||
|
ret i32 0
|
||||||
|
|
||||||
|
outer_lpad:
|
||||||
|
%ehvals1 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
catch i8* @int_typeinfo
|
||||||
|
br label %catch.dispatch
|
||||||
|
|
||||||
|
inner_lpad:
|
||||||
|
%ehvals2 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
cleanup
|
||||||
|
catch i8* @int_typeinfo
|
||||||
|
call void @cleanup()
|
||||||
|
br label %catch.dispatch
|
||||||
|
|
||||||
|
catch.dispatch:
|
||||||
|
%ehvals = phi { i8*, i32 } [ %ehvals1, %outer_lpad ], [ %ehvals2, %inner_lpad ]
|
||||||
|
%ehptr = extractvalue { i8*, i32 } %ehvals, 0
|
||||||
|
%ehsel = extractvalue { i8*, i32 } %ehvals, 1
|
||||||
|
%int_sel = call i32 @llvm.eh.typeid.for(i8* @int_typeinfo)
|
||||||
|
%int_match = icmp eq i32 %ehsel, %int_sel
|
||||||
|
br i1 %int_match, label %catch_int, label %eh.resume
|
||||||
|
|
||||||
|
catch_int:
|
||||||
|
ret i32 1
|
||||||
|
|
||||||
|
eh.resume:
|
||||||
|
%tmp_ehvals = insertvalue { i8*, i32 } undef, i8* %ehptr, 0
|
||||||
|
%new_ehvals = insertvalue { i8*, i32 } %tmp_ehvals, i32 %ehsel, 1
|
||||||
|
resume { i8*, i32 } %new_ehvals
|
||||||
|
}
|
||||||
|
|
||||||
|
; We can't prune this merge because one landingpad is a cleanup pad.
|
||||||
|
|
||||||
|
; CHECK-LABEL: define i32 @catch_cleanup_merge()
|
||||||
|
; CHECK: invoke void @might_throw()
|
||||||
|
; CHECK: invoke void @might_throw()
|
||||||
|
; CHECK: ret i32 0
|
||||||
|
;
|
||||||
|
; CHECK: outer_lpad:
|
||||||
|
; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
; CHECK: br label %catch.dispatch
|
||||||
|
;
|
||||||
|
; CHECK: inner_lpad:
|
||||||
|
; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
|
||||||
|
; CHECK: call void @cleanup()
|
||||||
|
; CHECK: br label %catch.dispatch
|
||||||
|
;
|
||||||
|
; CHECK: catch.dispatch:
|
||||||
|
; CHECK: call i32 @llvm.eh.typeid.for
|
||||||
|
; CHECK: br i1
|
||||||
|
; CHECK: catch_int:
|
||||||
|
; CHECK: ret i32 1
|
||||||
|
; CHECK: eh.resume:
|
||||||
|
; CHECK-NEXT: call void @_Unwind_Resume(i8* %ehptr)
|
||||||
|
|
||||||
declare i32 @__gxx_personality_v0(...)
|
declare i32 @__gxx_personality_v0(...)
|
||||||
declare i32 @llvm.eh.typeid.for(i8*)
|
declare i32 @llvm.eh.typeid.for(i8*)
|
||||||
|
@ -37,6 +37,7 @@ entry:
|
|||||||
|
|
||||||
lpad:
|
lpad:
|
||||||
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
||||||
|
cleanup
|
||||||
catch i8* bitcast (i8** @_ZTIi to i8*)
|
catch i8* bitcast (i8** @_ZTIi to i8*)
|
||||||
br label %eh.resume
|
br label %eh.resume
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ try.cont:
|
|||||||
|
|
||||||
lpad:
|
lpad:
|
||||||
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
||||||
|
cleanup
|
||||||
catch i8* bitcast (void ()* @filt0 to i8*)
|
catch i8* bitcast (void ()* @filt0 to i8*)
|
||||||
catch i8* bitcast (void ()* @filt1 to i8*)
|
catch i8* bitcast (void ()* @filt1 to i8*)
|
||||||
%sel = extractvalue { i8*, i32 } %0, 1
|
%sel = extractvalue { i8*, i32 } %0, 1
|
||||||
|
@ -78,6 +78,7 @@ cont:
|
|||||||
; CHECK: bl __cxa_end_catch
|
; CHECK: bl __cxa_end_catch
|
||||||
lpad:
|
lpad:
|
||||||
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
%0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
|
||||||
|
cleanup
|
||||||
catch i8* bitcast (i8** @_ZTIi to i8*)
|
catch i8* bitcast (i8** @_ZTIi to i8*)
|
||||||
catch i8* bitcast (i8** @_ZTId to i8*)
|
catch i8* bitcast (i8** @_ZTId to i8*)
|
||||||
%1 = extractvalue { i8*, i32 } %0, 0
|
%1 = extractvalue { i8*, i32 } %0, 0
|
||||||
@ -110,13 +111,14 @@ Exit:
|
|||||||
; CHECK: .long [[PRE_G]]-[[START]]
|
; CHECK: .long [[PRE_G]]-[[START]]
|
||||||
; CHECK: .long [[POST_G]]-[[PRE_G]]
|
; CHECK: .long [[POST_G]]-[[PRE_G]]
|
||||||
; CHECK: .long [[LANDING]]-[[START]]
|
; CHECK: .long [[LANDING]]-[[START]]
|
||||||
; CHECK: .byte 3
|
; CHECK: .byte 5
|
||||||
; CHECK: .long [[POST_G]]-[[START]]
|
; CHECK: .long [[POST_G]]-[[START]]
|
||||||
; CHECK: .long [[END]]-[[POST_G]]
|
; CHECK: .long [[END]]-[[POST_G]]
|
||||||
; CHECK: .long 0
|
; CHECK: .long 0
|
||||||
; CHECK: .byte 0
|
; CHECK: .byte 0
|
||||||
; CHECK: .byte 1
|
|
||||||
; CHECK: .byte 0
|
; CHECK: .byte 0
|
||||||
|
; CHECK: .byte 1
|
||||||
|
; CHECK: .byte 125
|
||||||
; CHECK: .byte 2
|
; CHECK: .byte 2
|
||||||
; CHECK: .byte 125
|
; CHECK: .byte 125
|
||||||
; CHECK: .long _ZTIi
|
; CHECK: .long _ZTIi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user