@@ -1818,7 +1818,7 @@ static Value *emitTaskDependencies(
18181818OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask (
18191819 const LocationDescription &Loc, InsertPointTy AllocaIP,
18201820 BodyGenCallbackTy BodyGenCB, bool Tied, Value *Final, Value *IfCondition,
1821- SmallVector<DependData> Dependencies, bool Mergeable) {
1821+ SmallVector<DependData> Dependencies, bool Mergeable, Value *EventHandle ) {
18221822
18231823 if (!updateToLocation (Loc))
18241824 return InsertPointTy ();
@@ -1864,7 +1864,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
18641864 Builder, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
18651865
18661866 OI.PostOutlineCB = [this , Ident, Tied, Final, IfCondition, Dependencies,
1867- Mergeable, TaskAllocaBB,
1867+ Mergeable, EventHandle, TaskAllocaBB,
18681868 ToBeDeleted](Function &OutlinedFn) mutable {
18691869 // Replace the Stale CI by appropriate RTL function call.
18701870 assert (OutlinedFn.getNumUses () == 1 &&
@@ -1935,6 +1935,20 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
19351935 /* sizeof_task=*/ TaskSize, /* sizeof_shared=*/ SharedsSize,
19361936 /* task_func=*/ &OutlinedFn});
19371937
1938+ // Emit detach clause initialization.
1939+ // evt = (typeof(evt))__kmpc_task_allow_completion_event(loc, tid,
1940+ // task_descriptor);
1941+ if (EventHandle) {
1942+ Function *TaskDetachFn = getOrCreateRuntimeFunctionPtr (
1943+ OMPRTL___kmpc_task_allow_completion_event);
1944+ llvm::Value *EventVal =
1945+ Builder.CreateCall (TaskDetachFn, {Ident, ThreadID, TaskData});
1946+ llvm::Value *EventHandleAddr =
1947+ Builder.CreatePointerBitCastOrAddrSpaceCast (EventHandle,
1948+ Builder.getPtrTy (0 ));
1949+ EventVal = Builder.CreatePtrToInt (EventVal, Builder.getInt64Ty ());
1950+ Builder.CreateStore (EventVal, EventHandleAddr);
1951+ }
19381952 // Copy the arguments for outlined function
19391953 if (HasShareds) {
19401954 Value *Shareds = StaleCI->getArgOperand (1 );
0 commit comments