Skip to content

Commit 18b235d

Browse files
committed
Duplicate UnreachableBlock, ExceptionSlot and EHSelectorSlor for each task
1 parent 7f5c702 commit 18b235d

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

clang/lib/CodeGen/CGException.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,34 @@ void CodeGenFunction::EmitAnyExprToExn(const Expr *e, Address addr) {
402402
}
403403

404404
Address CodeGenFunction::getExceptionSlot() {
405+
if (getContext().getLangOpts().OmpSs
406+
&& CGM.getOmpSsRuntime().inTaskBody()) {
407+
Address ESlotAddr = CGM.getOmpSsRuntime().getTaskExceptionSlot();
408+
if (ESlotAddr.isValid())
409+
return ESlotAddr;
410+
llvm::Instruction *I = CreateTempAlloca(Int8PtrTy, "exn.slot");
411+
Address Addr = Address(I, getPointerAlign());
412+
CGM.getOmpSsRuntime().setTaskExceptionSlot(Addr);
413+
return Addr;
414+
}
415+
405416
if (!ExceptionSlot)
406417
ExceptionSlot = CreateTempAlloca(Int8PtrTy, "exn.slot");
407418
return Address(ExceptionSlot, getPointerAlign());
408419
}
409420

410421
Address CodeGenFunction::getEHSelectorSlot() {
422+
if (getContext().getLangOpts().OmpSs
423+
&& CGM.getOmpSsRuntime().inTaskBody()) {
424+
Address EHSSlotAddr = CGM.getOmpSsRuntime().getTaskEHSelectorSlot();
425+
if (EHSSlotAddr.isValid())
426+
return EHSSlotAddr;
427+
llvm::Instruction *I = CreateTempAlloca(Int32Ty, "ehselector.slot");
428+
Address Addr = Address(I, CharUnits::fromQuantity(4));
429+
CGM.getOmpSsRuntime().setTaskEHSelectorSlot(Addr);
430+
return Addr;
431+
}
432+
411433
if (!EHSelectorSlot)
412434
EHSelectorSlot = CreateTempAlloca(Int32Ty, "ehselector.slot");
413435
return Address(EHSelectorSlot, CharUnits::fromQuantity(4));

clang/lib/CodeGen/CGOmpSsRuntime.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,17 @@ llvm::BasicBlock *CGOmpSsRuntime::getTaskTerminateLandingPad() {
907907
return TaskStack.back().TerminateLandingPad;
908908
}
909909

910+
llvm::BasicBlock *CGOmpSsRuntime::getTaskUnreachableBlock() {
911+
return TaskStack.back().UnreachableBlock;
912+
}
913+
914+
Address CGOmpSsRuntime::getTaskExceptionSlot() {
915+
return TaskStack.back().ExceptionSlot;
916+
}
917+
Address CGOmpSsRuntime::getTaskEHSelectorSlot() {
918+
return TaskStack.back().EHSelectorSlot;
919+
}
920+
910921
void CGOmpSsRuntime::setTaskTerminateHandler(llvm::BasicBlock *BB) {
911922
TaskStack.back().TerminateHandler = BB;
912923
}
@@ -915,6 +926,17 @@ void CGOmpSsRuntime::setTaskTerminateLandingPad(llvm::BasicBlock *BB) {
915926
TaskStack.back().TerminateLandingPad = BB;
916927
}
917928

929+
void CGOmpSsRuntime::setTaskUnreachableBlock(llvm::BasicBlock *BB) {
930+
TaskStack.back().UnreachableBlock = BB;
931+
}
932+
933+
void CGOmpSsRuntime::setTaskExceptionSlot(Address Addr) {
934+
TaskStack.back().ExceptionSlot = Addr;
935+
}
936+
void CGOmpSsRuntime::setTaskEHSelectorSlot(Address Addr) {
937+
TaskStack.back().EHSelectorSlot = Addr;
938+
}
939+
918940
// Borrowed brom CodeGenFunction.cpp
919941
static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
920942
if (!BB) return;
@@ -1000,7 +1022,10 @@ void CGOmpSsRuntime::emitTaskCall(CodeGenFunction &CGF,
10001022
llvm::Instruction *TaskAllocaInsertPt = new llvm::BitCastInst(Undef, CGF.Int32Ty, "taskallocapt", Result->getParent());
10011023
TaskStack.push_back({TaskAllocaInsertPt,
10021024
/*TerminateLandingPad=*/nullptr,
1003-
/*TerminateHandler=*/nullptr});
1025+
/*TerminateHandler=*/nullptr,
1026+
/*UnreachableBlock=*/nullptr,
1027+
/*ExceptionSlot=*/Address::invalid(),
1028+
/*EHSelectorSlot=*/Address::invalid()});
10041029

10051030
// The point of exit cannot be a branch out of the structured block.
10061031
// longjmp() and throw() must not violate the entry/exit criteria.
@@ -1015,8 +1040,7 @@ void CGOmpSsRuntime::emitTaskCall(CodeGenFunction &CGF,
10151040
// EmitIfUsed(*this, EHResumeBlock);
10161041
EmitIfUsed(CGF, TaskStack.back().TerminateLandingPad);
10171042
EmitIfUsed(CGF, TaskStack.back().TerminateHandler);
1018-
// TODO: do we need this?
1019-
// EmitIfUsed(*this, UnreachableBlock);
1043+
EmitIfUsed(CGF, TaskStack.back().UnreachableBlock);
10201044

10211045
CGF.Builder.CreateCall(ExitCallee, Result);
10221046

clang/lib/CodeGen/CGOmpSsRuntime.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ class CGOmpSsRuntime {
8181
private:
8282
struct TaskContext {
8383
llvm::AssertingVH<llvm::Instruction> InsertPt;
84-
llvm::BasicBlock *TerminateLandingPad = nullptr;
85-
llvm::BasicBlock *TerminateHandler = nullptr;
84+
llvm::BasicBlock *TerminateLandingPad;
85+
llvm::BasicBlock *TerminateHandler;
86+
llvm::BasicBlock *UnreachableBlock;
87+
Address ExceptionSlot;
88+
Address EHSelectorSlot;
8689
};
8790

8891
SmallVector<TaskContext, 2> TaskStack;
@@ -107,14 +110,27 @@ class CGOmpSsRuntime {
107110
bool inTaskBody();
108111
// returns the innermost nested task InsertPt instruction
109112
llvm::AssertingVH<llvm::Instruction> getTaskInsertPt();
110-
// returns the innermost nested task TerminateHandler instruction
113+
// returns the innermost nested task TerminateHandler BB
111114
llvm::BasicBlock *getTaskTerminateHandler();
112-
// returns the innermost nested task TerminateLandingPad instruction
115+
// returns the innermost nested task TerminateLandingPad BB
113116
llvm::BasicBlock *getTaskTerminateLandingPad();
117+
// returns the innermost nested task UnreachableBlock BB
118+
llvm::BasicBlock *getTaskUnreachableBlock();
119+
// returns the innermost nested task ExceptionSlot instruction
120+
Address getTaskExceptionSlot();
121+
// returns the innermost nested task ExceptionSlot instruction
122+
Address getTaskEHSelectorSlot();
123+
114124
// sets the innermost nested task TerminateHandler instruction
115125
void setTaskTerminateHandler(llvm::BasicBlock *BB);
116126
// sets the innermost nested task TerminateLandingPad instruction
117127
void setTaskTerminateLandingPad(llvm::BasicBlock *BB);
128+
// sets the innermost nested task UnreachableBlock instruction
129+
void setTaskUnreachableBlock(llvm::BasicBlock *BB);
130+
// sets the innermost nested task ExceptionSlot address
131+
void setTaskExceptionSlot(Address Addr);
132+
// sets the innermost nested task EHSelectorSlot address
133+
void setTaskEHSelectorSlot(Address Addr);
118134

119135
/// Emit code for 'taskwait' directive.
120136
virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CGBuilder.h"
1717
#include "CGDebugInfo.h"
1818
#include "CGLoopInfo.h"
19+
#include "CGOmpSsRuntime.h"
1920
#include "CGValue.h"
2021
#include "CodeGenModule.h"
2122
#include "CodeGenPGO.h"
@@ -1770,6 +1771,19 @@ class CodeGenFunction : public CodeGenTypeCache {
17701771
Address getNormalCleanupDestSlot();
17711772

17721773
llvm::BasicBlock *getUnreachableBlock() {
1774+
if (getContext().getLangOpts().OmpSs
1775+
&& CGM.getOmpSsRuntime().inTaskBody()) {
1776+
llvm::BasicBlock *UBlock = CGM.getOmpSsRuntime().getTaskUnreachableBlock();
1777+
if (UBlock)
1778+
return UBlock;
1779+
1780+
UBlock = createBasicBlock("unreachable");
1781+
new llvm::UnreachableInst(getLLVMContext(), UBlock);
1782+
1783+
CGM.getOmpSsRuntime().setTaskUnreachableBlock(UBlock);
1784+
return UBlock;
1785+
1786+
}
17731787
if (!UnreachableBlock) {
17741788
UnreachableBlock = createBasicBlock("unreachable");
17751789
new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);

0 commit comments

Comments
 (0)