@@ -1816,11 +1816,10 @@ static Value *emitTaskDependencies(
18161816 return DepArray;
18171817}
18181818
1819- OpenMPIRBuilder::InsertPointOrErrorTy
1820- OpenMPIRBuilder::createTask (const LocationDescription &Loc,
1821- InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB,
1822- bool Tied, Value *Final, Value *IfCondition,
1823- SmallVector<DependData> Dependencies) {
1819+ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask (
1820+ const LocationDescription &Loc, InsertPointTy AllocaIP,
1821+ BodyGenCallbackTy BodyGenCB, bool Tied, Value *Final, Value *IfCondition,
1822+ SmallVector<DependData> Dependencies, Value *EventHandle) {
18241823
18251824 if (!updateToLocation (Loc))
18261825 return InsertPointTy ();
@@ -1866,7 +1865,8 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18661865 Builder, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
18671866
18681867 OI.PostOutlineCB = [this , Ident, Tied, Final, IfCondition, Dependencies,
1869- TaskAllocaBB, ToBeDeleted](Function &OutlinedFn) mutable {
1868+ EventHandle, TaskAllocaBB,
1869+ ToBeDeleted](Function &OutlinedFn) mutable {
18701870 // Replace the Stale CI by appropriate RTL function call.
18711871 assert (OutlinedFn.getNumUses () == 1 &&
18721872 " there must be a single user for the outlined function" );
@@ -1930,6 +1930,20 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
19301930 TaskAllocFn, {/* loc_ref=*/ Ident, /* gtid=*/ ThreadID, /* flags=*/ Flags,
19311931 /* sizeof_task=*/ TaskSize, /* sizeof_shared=*/ SharedsSize,
19321932 /* task_func=*/ &OutlinedFn});
1933+ // Emit detach clause initialization.
1934+ // evt = (typeof(evt))__kmpc_task_allow_completion_event(loc, tid,
1935+ // task_descriptor);
1936+ if (EventHandle) {
1937+ Function *TaskDetachFn = getOrCreateRuntimeFunctionPtr (
1938+ OMPRTL___kmpc_task_allow_completion_event);
1939+ llvm::Value *EventVal =
1940+ Builder.CreateCall (TaskDetachFn, {Ident, ThreadID, TaskData});
1941+ llvm::Value *EventHandleAddr =
1942+ Builder.CreatePointerBitCastOrAddrSpaceCast (EventHandle,
1943+ Builder.getPtrTy (0 ));
1944+ EventVal = Builder.CreatePtrToInt (EventVal, Builder.getInt64Ty ());
1945+ Builder.CreateStore (EventVal, EventHandleAddr);
1946+ }
19331947
19341948 // Copy the arguments for outlined function
19351949 if (HasShareds) {
0 commit comments