Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit ae27059

Browse files
committed
Refactor the load of the exception pointer and the exception selector from their
storage slot into helper functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139826 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4fdf97b commit ae27059

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

lib/CodeGen/CGException.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ llvm::Value *CodeGenFunction::getEHSelectorSlot() {
367367
return EHSelectorSlot;
368368
}
369369

370+
llvm::Value *CodeGenFunction::getExceptionFromSlot() {
371+
return Builder.CreateLoad(getExceptionSlot(), "exn");
372+
}
373+
374+
llvm::Value *CodeGenFunction::getSelectorFromSlot() {
375+
return Builder.CreateLoad(getEHSelectorSlot(), "sel");
376+
}
377+
370378
void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) {
371379
if (!E->getSubExpr()) {
372380
if (getInvokeDest()) {
@@ -483,9 +491,7 @@ static void emitFilterDispatchBlock(CodeGenFunction &CGF,
483491
// here because the filter triggered.
484492
if (filterScope.getNumFilters()) {
485493
// Load the selector value.
486-
llvm::Value *selector =
487-
CGF.Builder.CreateLoad(CGF.getEHSelectorSlot(), "selector");
488-
494+
llvm::Value *selector = CGF.getSelectorFromSlot();
489495
llvm::BasicBlock *unexpectedBB = CGF.createBasicBlock("ehspec.unexpected");
490496

491497
llvm::Value *zero = CGF.Builder.getInt32(0);
@@ -500,7 +506,7 @@ static void emitFilterDispatchBlock(CodeGenFunction &CGF,
500506
// because __cxa_call_unexpected magically filters exceptions
501507
// according to the last landing pad the exception was thrown
502508
// into. Seriously.
503-
llvm::Value *exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
509+
llvm::Value *exn = CGF.getExceptionFromSlot();
504510
CGF.Builder.CreateCall(getUnexpectedFn(CGF), exn)
505511
->setDoesNotReturn();
506512
CGF.Builder.CreateUnreachable();
@@ -899,7 +905,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
899905
const VarDecl &CatchParam,
900906
llvm::Value *ParamAddr) {
901907
// Load the exception from where the landing pad saved it.
902-
llvm::Value *Exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot(), "exn");
908+
llvm::Value *Exn = CGF.getExceptionFromSlot();
903909

904910
CanQualType CatchType =
905911
CGF.CGM.getContext().getCanonicalType(CatchParam.getType());
@@ -1074,7 +1080,7 @@ static void BeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *S) {
10741080

10751081
VarDecl *CatchParam = S->getExceptionDecl();
10761082
if (!CatchParam) {
1077-
llvm::Value *Exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot(), "exn");
1083+
llvm::Value *Exn = CGF.getExceptionFromSlot();
10781084
CallBeginCatch(CGF, Exn, true);
10791085
return;
10801086
}
@@ -1116,8 +1122,7 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
11161122
CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
11171123

11181124
// Load the selector value.
1119-
llvm::Value *selector =
1120-
CGF.Builder.CreateLoad(CGF.getEHSelectorSlot(), "selector");
1125+
llvm::Value *selector = CGF.getSelectorFromSlot();
11211126

11221127
// Test against each of the exception types we claim to catch.
11231128
for (unsigned i = 0, e = catchScope.getNumHandlers(); ; ++i) {
@@ -1423,13 +1428,13 @@ void CodeGenFunction::FinallyInfo::exit(CodeGenFunction &CGF) {
14231428

14241429
// If there's a begin-catch function, call it.
14251430
if (BeginCatchFn) {
1426-
exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
1431+
exn = CGF.getExceptionFromSlot();
14271432
CGF.Builder.CreateCall(BeginCatchFn, exn)->setDoesNotThrow();
14281433
}
14291434

14301435
// If we need to remember the exception pointer to rethrow later, do so.
14311436
if (SavedExnVar) {
1432-
if (!exn) exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
1437+
if (!exn) exn = CGF.getExceptionFromSlot();
14331438
CGF.Builder.CreateStore(exn, SavedExnVar);
14341439
}
14351440

@@ -1519,10 +1524,10 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock() {
15191524
StringRef RethrowName = Personality.getCatchallRethrowFnName();
15201525
if (!RethrowName.empty()) {
15211526
Builder.CreateCall(getCatchallRethrowFn(*this, RethrowName),
1522-
Builder.CreateLoad(getExceptionSlot()))
1527+
getExceptionFromSlot())
15231528
->setDoesNotReturn();
15241529
} else {
1525-
llvm::Value *Exn = Builder.CreateLoad(getExceptionSlot());
1530+
llvm::Value *Exn = getExceptionFromSlot();
15261531

15271532
switch (CleanupHackLevel) {
15281533
case CHL_MandatoryCatchall:
@@ -1534,7 +1539,7 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock() {
15341539
break;
15351540
case CHL_MandatoryCleanup: {
15361541
// In mandatory-cleanup mode, we should use llvm.eh.resume.
1537-
llvm::Value *Selector = Builder.CreateLoad(getEHSelectorSlot());
1542+
llvm::Value *Selector = getSelectorFromSlot();
15381543
Builder.CreateCall2(CGM.getIntrinsic(llvm::Intrinsic::eh_resume),
15391544
Exn, Selector)
15401545
->setDoesNotReturn();

lib/CodeGen/CGObjCRuntime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
221221
CatchHandler &Handler = Handlers[I];
222222

223223
CGF.EmitBlock(Handler.Block);
224-
llvm::Value *RawExn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
224+
llvm::Value *RawExn = CGF.getExceptionFromSlot();
225225

226226
// Enter the catch.
227227
llvm::Value *Exn = RawExn;

lib/CodeGen/CodeGenFunction.h

+5
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,11 @@ class CodeGenFunction : public CodeGenTypeCache {
11211121
llvm::Value *getExceptionSlot();
11221122
llvm::Value *getEHSelectorSlot();
11231123

1124+
/// Returns the contents of the function's exception object and selector
1125+
/// slots.
1126+
llvm::Value *getExceptionFromSlot();
1127+
llvm::Value *getSelectorFromSlot();
1128+
11241129
llvm::Value *getNormalCleanupDestSlot();
11251130

11261131
llvm::BasicBlock *getUnreachableBlock() {

0 commit comments

Comments
 (0)