aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/DwarfEHPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/DwarfEHPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/DwarfEHPrepare.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/DwarfEHPrepare.cpp b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
index 32c94de7280c..a44aaf33c6a4 100644
--- a/llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/DwarfEHPrepare.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
@@ -54,7 +55,7 @@ STATISTIC(NumUnwind, "Number of functions with unwind");
namespace {
class DwarfEHPrepare {
- CodeGenOpt::Level OptLevel;
+ CodeGenOptLevel OptLevel;
Function &F;
const TargetLowering &TLI;
@@ -78,7 +79,7 @@ class DwarfEHPrepare {
bool InsertUnwindResumeCalls();
public:
- DwarfEHPrepare(CodeGenOpt::Level OptLevel_, Function &F_,
+ DwarfEHPrepare(CodeGenOptLevel OptLevel_, Function &F_,
const TargetLowering &TLI_, DomTreeUpdater *DTU_,
const TargetTransformInfo *TTI_, const Triple &TargetTriple_)
: OptLevel(OptLevel_), F(F_), TLI(TLI_), DTU(DTU_), TTI(TTI_),
@@ -194,7 +195,7 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
LLVMContext &Ctx = F.getContext();
size_t ResumesLeft = Resumes.size();
- if (OptLevel != CodeGenOpt::None) {
+ if (OptLevel != CodeGenOptLevel::None) {
ResumesLeft = pruneUnreachableResumes(Resumes, CleanupLPads);
#if LLVM_ENABLE_STATS
unsigned NumRemainingLPs = 0;
@@ -227,8 +228,8 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
DoesRewindFunctionNeedExceptionObject = false;
} else {
RewindName = TLI.getLibcallName(RTLIB::UNWIND_RESUME);
- FTy =
- FunctionType::get(Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false);
+ FTy = FunctionType::get(Type::getVoidTy(Ctx), PointerType::getUnqual(Ctx),
+ false);
RewindFunctionCallingConv = TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME);
DoesRewindFunctionNeedExceptionObject = true;
}
@@ -269,8 +270,8 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
llvm::SmallVector<Value *, 1> RewindFunctionArgs;
BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &F);
- PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesLeft, "exn.obj",
- UnwindBB);
+ PHINode *PN = PHINode::Create(PointerType::getUnqual(Ctx), ResumesLeft,
+ "exn.obj", UnwindBB);
// Extract the exception object from the ResumeInst and add it to the PHI node
// that feeds the _Unwind_Resume call.
@@ -309,7 +310,7 @@ bool DwarfEHPrepare::run() {
return Changed;
}
-static bool prepareDwarfEH(CodeGenOpt::Level OptLevel, Function &F,
+static bool prepareDwarfEH(CodeGenOptLevel OptLevel, Function &F,
const TargetLowering &TLI, DominatorTree *DT,
const TargetTransformInfo *TTI,
const Triple &TargetTriple) {
@@ -324,12 +325,12 @@ namespace {
class DwarfEHPrepareLegacyPass : public FunctionPass {
- CodeGenOpt::Level OptLevel;
+ CodeGenOptLevel OptLevel;
public:
static char ID; // Pass identification, replacement for typeid.
- DwarfEHPrepareLegacyPass(CodeGenOpt::Level OptLevel = CodeGenOpt::Default)
+ DwarfEHPrepareLegacyPass(CodeGenOptLevel OptLevel = CodeGenOptLevel::Default)
: FunctionPass(ID), OptLevel(OptLevel) {}
bool runOnFunction(Function &F) override {
@@ -340,7 +341,7 @@ public:
const TargetTransformInfo *TTI = nullptr;
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
DT = &DTWP->getDomTree();
- if (OptLevel != CodeGenOpt::None) {
+ if (OptLevel != CodeGenOptLevel::None) {
if (!DT)
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
@@ -351,7 +352,7 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetPassConfig>();
AU.addRequired<TargetTransformInfoWrapperPass>();
- if (OptLevel != CodeGenOpt::None) {
+ if (OptLevel != CodeGenOptLevel::None) {
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
}
@@ -365,6 +366,27 @@ public:
} // end anonymous namespace
+PreservedAnalyses DwarfEHPreparePass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ const auto &TLI = *TM->getSubtargetImpl(F)->getTargetLowering();
+ auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
+ const TargetTransformInfo *TTI = nullptr;
+ auto OptLevel = TM->getOptLevel();
+ if (OptLevel != CodeGenOptLevel::None) {
+ if (!DT)
+ DT = &FAM.getResult<DominatorTreeAnalysis>(F);
+ TTI = &FAM.getResult<TargetIRAnalysis>(F);
+ }
+ bool Changed =
+ prepareDwarfEH(OptLevel, F, TLI, DT, TTI, TM->getTargetTriple());
+
+ if (!Changed)
+ return PreservedAnalyses::all();
+ PreservedAnalyses PA;
+ PA.preserve<DominatorTreeAnalysis>();
+ return PA;
+}
+
char DwarfEHPrepareLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
@@ -375,6 +397,6 @@ INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_END(DwarfEHPrepareLegacyPass, DEBUG_TYPE,
"Prepare DWARF exceptions", false, false)
-FunctionPass *llvm::createDwarfEHPass(CodeGenOpt::Level OptLevel) {
+FunctionPass *llvm::createDwarfEHPass(CodeGenOptLevel OptLevel) {
return new DwarfEHPrepareLegacyPass(OptLevel);
}