11
11
//
12
12
// ===----------------------------------------------------------------------===//
13
13
14
+ #include " llvm/CodeGen/SjLjEHPrepare.h"
14
15
#include " llvm/ADT/SetVector.h"
15
16
#include " llvm/ADT/SmallPtrSet.h"
16
17
#include " llvm/ADT/SmallVector.h"
31
32
#include " llvm/Transforms/Utils/Local.h"
32
33
using namespace llvm ;
33
34
34
- #define DEBUG_TYPE " sjljehprepare "
35
+ #define DEBUG_TYPE " sjlj-eh-prepare "
35
36
36
37
STATISTIC (NumInvokes, " Number of invokes replaced" );
37
38
STATISTIC (NumSpilled, " Number of registers live across unwind edges" );
38
39
39
40
namespace {
40
- class SjLjEHPrepare : public FunctionPass {
41
+ class SjLjEHPrepareImpl {
41
42
IntegerType *DataTy = nullptr ;
42
43
Type *doubleUnderDataTy = nullptr ;
43
44
Type *doubleUnderJBufTy = nullptr ;
@@ -55,16 +56,9 @@ class SjLjEHPrepare : public FunctionPass {
55
56
const TargetMachine *TM = nullptr ;
56
57
57
58
public:
58
- static char ID; // Pass identification, replacement for typeid
59
- explicit SjLjEHPrepare (const TargetMachine *TM = nullptr )
60
- : FunctionPass(ID), TM(TM) {}
61
- bool doInitialization (Module &M) override ;
62
- bool runOnFunction (Function &F) override ;
63
-
64
- void getAnalysisUsage (AnalysisUsage &AU) const override {}
65
- StringRef getPassName () const override {
66
- return " SJLJ Exception Handling preparation" ;
67
- }
59
+ explicit SjLjEHPrepareImpl (const TargetMachine *TM = nullptr ) : TM(TM) {}
60
+ bool doInitialization (Module &M);
61
+ bool runOnFunction (Function &F);
68
62
69
63
private:
70
64
bool setupEntryBlockAndCallSites (Function &F);
@@ -74,8 +68,32 @@ class SjLjEHPrepare : public FunctionPass {
74
68
void lowerAcrossUnwindEdges (Function &F, ArrayRef<InvokeInst *> Invokes);
75
69
void insertCallSiteStore (Instruction *I, int Number);
76
70
};
71
+
72
+ class SjLjEHPrepare : public FunctionPass {
73
+ SjLjEHPrepareImpl Impl;
74
+
75
+ public:
76
+ static char ID; // Pass identification, replacement for typeid
77
+ explicit SjLjEHPrepare (const TargetMachine *TM = nullptr )
78
+ : FunctionPass(ID), Impl(TM) {}
79
+ bool doInitialization (Module &M) override { return Impl.doInitialization (M); }
80
+ bool runOnFunction (Function &F) override { return Impl.runOnFunction (F); };
81
+
82
+ StringRef getPassName () const override {
83
+ return " SJLJ Exception Handling preparation" ;
84
+ }
85
+ };
86
+
77
87
} // end anonymous namespace
78
88
89
+ PreservedAnalyses SjLjEHPreparePass::run (Function &F,
90
+ FunctionAnalysisManager &FAM) {
91
+ SjLjEHPrepareImpl Impl (TM);
92
+ Impl.doInitialization (*F.getParent ());
93
+ bool Changed = Impl.runOnFunction (F);
94
+ return Changed ? PreservedAnalyses::none () : PreservedAnalyses::all ();
95
+ }
96
+
79
97
char SjLjEHPrepare::ID = 0 ;
80
98
INITIALIZE_PASS (SjLjEHPrepare, DEBUG_TYPE, " Prepare SjLj exceptions" ,
81
99
false , false )
@@ -87,7 +105,7 @@ FunctionPass *llvm::createSjLjEHPreparePass(const TargetMachine *TM) {
87
105
88
106
// doInitialization - Set up decalarations and types needed to process
89
107
// exceptions.
90
- bool SjLjEHPrepare ::doInitialization (Module &M) {
108
+ bool SjLjEHPrepareImpl ::doInitialization (Module &M) {
91
109
// Build the function context structure.
92
110
// builtin_setjmp uses a five word jbuf
93
111
Type *VoidPtrTy = PointerType::getUnqual (M.getContext ());
@@ -104,12 +122,12 @@ bool SjLjEHPrepare::doInitialization(Module &M) {
104
122
doubleUnderJBufTy // __jbuf
105
123
);
106
124
107
- return true ;
125
+ return false ;
108
126
}
109
127
110
128
// / insertCallSiteStore - Insert a store of the call-site value to the
111
129
// / function context
112
- void SjLjEHPrepare ::insertCallSiteStore (Instruction *I, int Number) {
130
+ void SjLjEHPrepareImpl ::insertCallSiteStore (Instruction *I, int Number) {
113
131
IRBuilder<> Builder (I);
114
132
115
133
// Get a reference to the call_site field.
@@ -140,8 +158,8 @@ static void MarkBlocksLiveIn(BasicBlock *BB,
140
158
141
159
// / substituteLPadValues - Substitute the values returned by the landingpad
142
160
// / instruction with those returned by the personality function.
143
- void SjLjEHPrepare ::substituteLPadValues (LandingPadInst *LPI, Value *ExnVal,
144
- Value *SelVal) {
161
+ void SjLjEHPrepareImpl ::substituteLPadValues (LandingPadInst *LPI, Value *ExnVal,
162
+ Value *SelVal) {
145
163
SmallVector<Value *, 8 > UseWorkList (LPI->users ());
146
164
while (!UseWorkList.empty ()) {
147
165
Value *Val = UseWorkList.pop_back_val ();
@@ -175,8 +193,9 @@ void SjLjEHPrepare::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
175
193
176
194
// / setupFunctionContext - Allocate the function context on the stack and fill
177
195
// / it with all of the data that we know at this point.
178
- Value *SjLjEHPrepare::setupFunctionContext (Function &F,
179
- ArrayRef<LandingPadInst *> LPads) {
196
+ Value *
197
+ SjLjEHPrepareImpl::setupFunctionContext (Function &F,
198
+ ArrayRef<LandingPadInst *> LPads) {
180
199
BasicBlock *EntryBB = &F.front ();
181
200
182
201
// Create an alloca for the incoming jump buffer ptr and the new jump buffer
@@ -233,7 +252,7 @@ Value *SjLjEHPrepare::setupFunctionContext(Function &F,
233
252
// / specially, we lower each arg to a copy instruction in the entry block. This
234
253
// / ensures that the argument value itself cannot be live out of the entry
235
254
// / block.
236
- void SjLjEHPrepare ::lowerIncomingArguments (Function &F) {
255
+ void SjLjEHPrepareImpl ::lowerIncomingArguments (Function &F) {
237
256
BasicBlock::iterator AfterAllocaInsPt = F.begin ()->begin ();
238
257
while (isa<AllocaInst>(AfterAllocaInsPt) &&
239
258
cast<AllocaInst>(AfterAllocaInsPt)->isStaticAlloca ())
@@ -264,8 +283,8 @@ void SjLjEHPrepare::lowerIncomingArguments(Function &F) {
264
283
265
284
// / lowerAcrossUnwindEdges - Find all variables which are alive across an unwind
266
285
// / edge and spill them.
267
- void SjLjEHPrepare ::lowerAcrossUnwindEdges (Function &F,
268
- ArrayRef<InvokeInst *> Invokes) {
286
+ void SjLjEHPrepareImpl ::lowerAcrossUnwindEdges (Function &F,
287
+ ArrayRef<InvokeInst *> Invokes) {
269
288
// Finally, scan the code looking for instructions with bad live ranges.
270
289
for (BasicBlock &BB : F) {
271
290
for (Instruction &Inst : BB) {
@@ -358,7 +377,7 @@ void SjLjEHPrepare::lowerAcrossUnwindEdges(Function &F,
358
377
// / setupEntryBlockAndCallSites - Setup the entry block by creating and filling
359
378
// / the function context and marking the call sites with the appropriate
360
379
// / values. These values are used by the DWARF EH emitter.
361
- bool SjLjEHPrepare ::setupEntryBlockAndCallSites (Function &F) {
380
+ bool SjLjEHPrepareImpl ::setupEntryBlockAndCallSites (Function &F) {
362
381
SmallVector<ReturnInst *, 16 > Returns;
363
382
SmallVector<InvokeInst *, 16 > Invokes;
364
383
SmallSetVector<LandingPadInst *, 16 > LPads;
@@ -479,7 +498,7 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) {
479
498
return true ;
480
499
}
481
500
482
- bool SjLjEHPrepare ::runOnFunction (Function &F) {
501
+ bool SjLjEHPrepareImpl ::runOnFunction (Function &F) {
483
502
Module &M = *F.getParent ();
484
503
RegisterFn = M.getOrInsertFunction (
485
504
" _Unwind_SjLj_Register" , Type::getVoidTy (M.getContext ()),
0 commit comments