2017-09-23 07:46:57 +08:00
|
|
|
//===- DwarfEHPrepare - Prepare exception handling for code generation ----===//
|
2009-05-23 04:36:31 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-05-23 04:36:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass mulches exception handling code into a form adapted to code
|
2010-03-27 07:41:30 +08:00
|
|
|
// generation. Required if using dwarf exception handling.
|
2009-05-23 04:36:31 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-10 06:45:16 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2015-03-10 06:45:16 +08:00
|
|
|
#include "llvm/Analysis/CFG.h"
|
2021-01-02 01:27:09 +08:00
|
|
|
#include "llvm/Analysis/DomTreeUpdater.h"
|
2015-12-03 07:06:39 +08:00
|
|
|
#include "llvm/Analysis/EHPersonalities.h"
|
2015-03-10 06:45:16 +08:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include "llvm/CodeGen/RuntimeLibcalls.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2015-03-10 06:45:16 +08:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include "llvm/IR/Type.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2009-05-23 04:36:31 +08:00
|
|
|
#include "llvm/Pass.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
2017-09-23 07:46:57 +08:00
|
|
|
#include <cstddef>
|
|
|
|
|
2009-05-23 04:36:31 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "dwarfehprepare"
|
|
|
|
|
2011-11-08 07:36:48 +08:00
|
|
|
STATISTIC(NumResumesLowered, "Number of resume calls lowered");
|
2009-05-23 04:36:31 +08:00
|
|
|
|
|
|
|
namespace {
|
2017-09-23 07:46:57 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
class DwarfEHPrepare {
|
|
|
|
CodeGenOpt::Level OptLevel;
|
|
|
|
|
2021-01-01 22:57:14 +08:00
|
|
|
// RewindFunction - _Unwind_Resume or the target equivalent.
|
2021-01-02 00:06:44 +08:00
|
|
|
FunctionCallee &RewindFunction;
|
2009-05-23 04:36:31 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
Function &F;
|
|
|
|
const TargetLowering &TLI;
|
2021-01-02 01:27:09 +08:00
|
|
|
DomTreeUpdater *DTU;
|
2021-01-02 00:06:44 +08:00
|
|
|
const TargetTransformInfo *TTI;
|
2015-03-10 06:45:16 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
/// Return the exception object from the value passed into
|
|
|
|
/// the 'resume' instruction (typically an aggregate). Clean up any dead
|
|
|
|
/// instructions, including the 'resume' instruction.
|
2021-01-01 22:57:14 +08:00
|
|
|
Value *GetExceptionObject(ResumeInst *RI);
|
2021-01-02 00:06:44 +08:00
|
|
|
|
|
|
|
/// Replace resumes that are not reachable from a cleanup landing pad with
|
|
|
|
/// unreachable and then simplify those blocks.
|
2021-01-01 22:57:14 +08:00
|
|
|
size_t
|
2021-01-02 00:06:44 +08:00
|
|
|
pruneUnreachableResumes(SmallVectorImpl<ResumeInst *> &Resumes,
|
2021-01-01 22:57:14 +08:00
|
|
|
SmallVectorImpl<LandingPadInst *> &CleanupLPads);
|
2010-06-12 10:34:29 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
/// Convert the ResumeInsts that are still present
|
|
|
|
/// into calls to the appropriate _Unwind_Resume function.
|
|
|
|
bool InsertUnwindResumeCalls();
|
2014-09-15 04:36:28 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
public:
|
|
|
|
DwarfEHPrepare(CodeGenOpt::Level OptLevel_, FunctionCallee &RewindFunction_,
|
2021-01-02 01:27:09 +08:00
|
|
|
Function &F_, const TargetLowering &TLI_, DomTreeUpdater *DTU_,
|
2021-01-02 00:06:44 +08:00
|
|
|
const TargetTransformInfo *TTI_)
|
|
|
|
: OptLevel(OptLevel_), RewindFunction(RewindFunction_), F(F_), TLI(TLI_),
|
2021-01-02 01:27:09 +08:00
|
|
|
DTU(DTU_), TTI(TTI_) {}
|
2015-03-10 06:45:16 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
bool run();
|
2021-01-01 22:57:14 +08:00
|
|
|
};
|
2017-09-23 07:46:57 +08:00
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
} // namespace
|
2009-05-23 04:36:31 +08:00
|
|
|
|
2012-05-18 01:59:51 +08:00
|
|
|
Value *DwarfEHPrepare::GetExceptionObject(ResumeInst *RI) {
|
2012-01-28 09:17:56 +08:00
|
|
|
Value *V = RI->getOperand(0);
|
2014-04-14 08:51:57 +08:00
|
|
|
Value *ExnObj = nullptr;
|
2012-01-28 09:17:56 +08:00
|
|
|
InsertValueInst *SelIVI = dyn_cast<InsertValueInst>(V);
|
2014-04-14 08:51:57 +08:00
|
|
|
LoadInst *SelLoad = nullptr;
|
|
|
|
InsertValueInst *ExcIVI = nullptr;
|
2012-01-28 09:17:56 +08:00
|
|
|
bool EraseIVIs = false;
|
|
|
|
|
|
|
|
if (SelIVI) {
|
|
|
|
if (SelIVI->getNumIndices() == 1 && *SelIVI->idx_begin() == 1) {
|
|
|
|
ExcIVI = dyn_cast<InsertValueInst>(SelIVI->getOperand(0));
|
|
|
|
if (ExcIVI && isa<UndefValue>(ExcIVI->getOperand(0)) &&
|
|
|
|
ExcIVI->getNumIndices() == 1 && *ExcIVI->idx_begin() == 0) {
|
2012-05-18 01:59:51 +08:00
|
|
|
ExnObj = ExcIVI->getOperand(1);
|
2012-01-28 09:17:56 +08:00
|
|
|
SelLoad = dyn_cast<LoadInst>(SelIVI->getOperand(1));
|
|
|
|
EraseIVIs = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExnObj)
|
|
|
|
ExnObj = ExtractValueInst::Create(RI->getOperand(0), 0, "exn.obj", RI);
|
|
|
|
|
|
|
|
RI->eraseFromParent();
|
|
|
|
|
|
|
|
if (EraseIVIs) {
|
2015-01-29 21:26:50 +08:00
|
|
|
if (SelIVI->use_empty())
|
2012-01-28 09:17:56 +08:00
|
|
|
SelIVI->eraseFromParent();
|
2015-01-29 21:26:50 +08:00
|
|
|
if (ExcIVI->use_empty())
|
2012-01-28 09:17:56 +08:00
|
|
|
ExcIVI->eraseFromParent();
|
2015-01-29 21:26:50 +08:00
|
|
|
if (SelLoad && SelLoad->use_empty())
|
2012-01-28 09:17:56 +08:00
|
|
|
SelLoad->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExnObj;
|
|
|
|
}
|
|
|
|
|
2015-03-10 06:45:16 +08:00
|
|
|
size_t DwarfEHPrepare::pruneUnreachableResumes(
|
2021-01-02 00:06:44 +08:00
|
|
|
SmallVectorImpl<ResumeInst *> &Resumes,
|
2015-03-10 06:45:16 +08:00
|
|
|
SmallVectorImpl<LandingPadInst *> &CleanupLPads) {
|
2021-01-02 01:27:09 +08:00
|
|
|
assert(DTU && "Should have DomTreeUpdater here.");
|
|
|
|
|
2015-03-10 06:45:16 +08:00
|
|
|
BitVector ResumeReachable(Resumes.size());
|
|
|
|
size_t ResumeIndex = 0;
|
|
|
|
for (auto *RI : Resumes) {
|
|
|
|
for (auto *LP : CleanupLPads) {
|
2021-01-02 01:27:09 +08:00
|
|
|
if (isPotentiallyReachable(LP, RI, nullptr, &DTU->getDomTree())) {
|
2015-03-10 06:45:16 +08:00
|
|
|
ResumeReachable.set(ResumeIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++ResumeIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If everything is reachable, there is no change.
|
|
|
|
if (ResumeReachable.all())
|
|
|
|
return Resumes.size();
|
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
LLVMContext &Ctx = F.getContext();
|
2015-03-10 06:45:16 +08:00
|
|
|
|
|
|
|
// 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();
|
2021-01-28 18:45:53 +08:00
|
|
|
simplifyCFG(BB, *TTI, DTU);
|
2015-03-10 06:45:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Resumes.resize(ResumesLeft);
|
|
|
|
return ResumesLeft;
|
|
|
|
}
|
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
bool DwarfEHPrepare::InsertUnwindResumeCalls() {
|
2021-01-01 22:57:14 +08:00
|
|
|
SmallVector<ResumeInst *, 16> Resumes;
|
|
|
|
SmallVector<LandingPadInst *, 16> CleanupLPads;
|
2021-01-02 00:06:44 +08:00
|
|
|
for (BasicBlock &BB : F) {
|
2015-01-29 21:26:50 +08:00
|
|
|
if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
|
2011-08-26 07:48:11 +08:00
|
|
|
Resumes.push_back(RI);
|
2015-06-18 04:52:32 +08:00
|
|
|
if (auto *LP = BB.getLandingPadInst())
|
2015-03-10 06:45:16 +08:00
|
|
|
if (LP->isCleanup())
|
|
|
|
CleanupLPads.push_back(LP);
|
2011-08-26 07:48:11 +08:00
|
|
|
}
|
2011-08-18 03:48:49 +08:00
|
|
|
|
|
|
|
if (Resumes.empty())
|
2013-06-01 00:30:36 +08:00
|
|
|
return false;
|
2011-08-18 03:48:49 +08:00
|
|
|
|
[WebAssembly] Add Wasm personality and isScopedEHPersonality()
Summary:
- Add wasm personality function
- Re-categorize the existing `isFuncletEHPersonality()` function into
two different functions: `isFuncletEHPersonality()` and
`isScopedEHPersonality(). This becomes necessary as wasm EH uses scoped
EH instructions (catchswitch, catchpad/ret, and cleanuppad/ret) but not
outlined funclets.
- Changed some callsites of `isFuncletEHPersonality()` to
`isScopedEHPersonality()` if they are related to scoped EH IR-level
stuff.
Reviewers: majnemer, dschuff, rnk
Subscribers: jfb, sbc100, jgravelle-google, eraman, JDevlieghere, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D45559
llvm-svn: 332667
2018-05-18 04:52:03 +08:00
|
|
|
// Check the personality, don't do anything if it's scope-based.
|
2021-01-02 00:06:44 +08:00
|
|
|
EHPersonality Pers = classifyEHPersonality(F.getPersonalityFn());
|
[WebAssembly] Add Wasm personality and isScopedEHPersonality()
Summary:
- Add wasm personality function
- Re-categorize the existing `isFuncletEHPersonality()` function into
two different functions: `isFuncletEHPersonality()` and
`isScopedEHPersonality(). This becomes necessary as wasm EH uses scoped
EH instructions (catchswitch, catchpad/ret, and cleanuppad/ret) but not
outlined funclets.
- Changed some callsites of `isFuncletEHPersonality()` to
`isScopedEHPersonality()` if they are related to scoped EH IR-level
stuff.
Reviewers: majnemer, dschuff, rnk
Subscribers: jfb, sbc100, jgravelle-google, eraman, JDevlieghere, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D45559
llvm-svn: 332667
2018-05-18 04:52:03 +08:00
|
|
|
if (isScopedEHPersonality(Pers))
|
2015-06-18 04:52:32 +08:00
|
|
|
return false;
|
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
LLVMContext &Ctx = F.getContext();
|
2015-03-10 06:45:16 +08:00
|
|
|
|
2020-05-22 01:40:43 +08:00
|
|
|
size_t ResumesLeft = Resumes.size();
|
|
|
|
if (OptLevel != CodeGenOpt::None)
|
2021-01-02 00:06:44 +08:00
|
|
|
ResumesLeft = pruneUnreachableResumes(Resumes, CleanupLPads);
|
2020-05-22 01:40:43 +08:00
|
|
|
|
2015-03-10 06:45:16 +08:00
|
|
|
if (ResumesLeft == 0)
|
|
|
|
return true; // We pruned them all.
|
|
|
|
|
|
|
|
// Find the rewind function if we didn't already.
|
2011-08-18 03:48:49 +08:00
|
|
|
if (!RewindFunction) {
|
2021-01-01 22:57:14 +08:00
|
|
|
FunctionType *FTy =
|
|
|
|
FunctionType::get(Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false);
|
2021-01-02 00:06:44 +08:00
|
|
|
const char *RewindName = TLI.getLibcallName(RTLIB::UNWIND_RESUME);
|
|
|
|
RewindFunction = F.getParent()->getOrInsertFunction(RewindName, FTy);
|
2011-08-18 03:48:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the basic block where the _Unwind_Resume call will live.
|
2015-03-10 06:45:16 +08:00
|
|
|
if (ResumesLeft == 1) {
|
2012-01-28 09:17:56 +08:00
|
|
|
// Instead of creating a new BB and PHI node, just append the call to
|
|
|
|
// _Unwind_Resume to the end of the single resume block.
|
|
|
|
ResumeInst *RI = Resumes.front();
|
|
|
|
BasicBlock *UnwindBB = RI->getParent();
|
2012-05-18 01:59:51 +08:00
|
|
|
Value *ExnObj = GetExceptionObject(RI);
|
2012-01-28 09:17:56 +08:00
|
|
|
|
|
|
|
// Call the _Unwind_Resume function.
|
|
|
|
CallInst *CI = CallInst::Create(RewindFunction, ExnObj, "", UnwindBB);
|
2021-01-02 00:06:44 +08:00
|
|
|
CI->setCallingConv(TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME));
|
2012-01-28 09:17:56 +08:00
|
|
|
|
|
|
|
// We never expect _Unwind_Resume to return.
|
2020-12-23 15:50:36 +08:00
|
|
|
CI->setDoesNotReturn();
|
2012-01-28 09:17:56 +08:00
|
|
|
new UnreachableInst(Ctx, UnwindBB);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-02 01:27:09 +08:00
|
|
|
std::vector<DominatorTree::UpdateType> Updates;
|
|
|
|
Updates.reserve(Resumes.size());
|
|
|
|
|
2021-01-02 00:06:44 +08:00
|
|
|
BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &F);
|
2021-01-01 22:57:14 +08:00
|
|
|
PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesLeft, "exn.obj",
|
|
|
|
UnwindBB);
|
2011-08-18 03:48:49 +08:00
|
|
|
|
|
|
|
// Extract the exception object from the ResumeInst and add it to the PHI node
|
|
|
|
// that feeds the _Unwind_Resume call.
|
2015-01-29 21:26:50 +08:00
|
|
|
for (ResumeInst *RI : Resumes) {
|
2012-01-28 09:17:56 +08:00
|
|
|
BasicBlock *Parent = RI->getParent();
|
|
|
|
BranchInst::Create(UnwindBB, Parent);
|
2021-01-02 01:27:09 +08:00
|
|
|
Updates.push_back({DominatorTree::Insert, Parent, UnwindBB});
|
2012-01-28 09:10:01 +08:00
|
|
|
|
2012-05-18 01:59:51 +08:00
|
|
|
Value *ExnObj = GetExceptionObject(RI);
|
2012-01-28 09:17:56 +08:00
|
|
|
PN->addIncoming(ExnObj, Parent);
|
2012-01-20 08:53:28 +08:00
|
|
|
|
2011-11-08 07:36:48 +08:00
|
|
|
++NumResumesLowered;
|
2011-08-18 03:48:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the function.
|
|
|
|
CallInst *CI = CallInst::Create(RewindFunction, PN, "", UnwindBB);
|
2021-01-02 00:06:44 +08:00
|
|
|
CI->setCallingConv(TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME));
|
2011-08-18 03:48:49 +08:00
|
|
|
|
|
|
|
// We never expect _Unwind_Resume to return.
|
2020-12-23 15:50:36 +08:00
|
|
|
CI->setDoesNotReturn();
|
2011-08-18 03:48:49 +08:00
|
|
|
new UnreachableInst(Ctx, UnwindBB);
|
2021-01-02 01:27:09 +08:00
|
|
|
|
2021-01-28 18:45:53 +08:00
|
|
|
if (DTU)
|
2021-01-04 21:42:13 +08:00
|
|
|
DTU->applyUpdates(Updates);
|
2021-01-02 01:27:09 +08:00
|
|
|
|
2011-08-18 03:48:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-02 01:27:09 +08:00
|
|
|
bool DwarfEHPrepare::run() {
|
|
|
|
bool Changed = InsertUnwindResumeCalls();
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool prepareDwarfEH(CodeGenOpt::Level OptLevel,
|
|
|
|
FunctionCallee &RewindFunction, Function &F,
|
|
|
|
const TargetLowering &TLI, DominatorTree *DT,
|
|
|
|
const TargetTransformInfo *TTI) {
|
2021-01-28 18:45:53 +08:00
|
|
|
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
|
2021-01-02 01:27:09 +08:00
|
|
|
|
|
|
|
return DwarfEHPrepare(OptLevel, RewindFunction, F, TLI, DT ? &DTU : nullptr,
|
|
|
|
TTI)
|
|
|
|
.run();
|
2021-01-02 10:42:58 +08:00
|
|
|
}
|
2021-01-02 00:06:44 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DwarfEHPrepareLegacyPass : public FunctionPass {
|
|
|
|
// RewindFunction - _Unwind_Resume or the target equivalent.
|
|
|
|
FunctionCallee RewindFunction = nullptr;
|
|
|
|
|
|
|
|
CodeGenOpt::Level OptLevel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid.
|
|
|
|
|
|
|
|
DwarfEHPrepareLegacyPass(CodeGenOpt::Level OptLevel = CodeGenOpt::Default)
|
|
|
|
: FunctionPass(ID), OptLevel(OptLevel) {}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
const TargetMachine &TM =
|
|
|
|
getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
|
|
|
|
const TargetLowering &TLI = *TM.getSubtargetImpl(F)->getTargetLowering();
|
|
|
|
DominatorTree *DT = nullptr;
|
|
|
|
const TargetTransformInfo *TTI = nullptr;
|
2021-01-28 18:45:53 +08:00
|
|
|
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
|
|
|
|
DT = &DTWP->getDomTree();
|
2021-01-02 00:06:44 +08:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
2021-01-28 18:45:53 +08:00
|
|
|
if (!DT)
|
|
|
|
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
2021-01-02 00:06:44 +08:00
|
|
|
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
|
|
|
}
|
2021-01-02 01:27:09 +08:00
|
|
|
return prepareDwarfEH(OptLevel, RewindFunction, F, TLI, DT, TTI);
|
2021-01-02 00:06:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<TargetPassConfig>();
|
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
|
|
|
}
|
2021-01-28 18:45:53 +08:00
|
|
|
AU.addPreserved<DominatorTreeWrapperPass>();
|
2021-01-02 00:06:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef getPassName() const override {
|
|
|
|
return "Exception handling preparation";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char DwarfEHPrepareLegacyPass::ID = 0;
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
|
|
|
|
"Prepare DWARF exceptions", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
|
|
|
|
"Prepare DWARF exceptions", false, false)
|
|
|
|
|
|
|
|
FunctionPass *llvm::createDwarfEHPass(CodeGenOpt::Level OptLevel) {
|
|
|
|
return new DwarfEHPrepareLegacyPass(OptLevel);
|
2009-05-23 04:36:31 +08:00
|
|
|
}
|