[PATCH] D69828: [WIP][OpenMP] Lower taskwait using OpenMP IR Builder

Roger Ferrer Ibanez via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 15:21:12 PST 2019


rogfer01 created this revision.
rogfer01 added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, guansong, hiraditya.
Herald added a project: LLVM.

Experiment (for now) lowering `taskwait` using the `OpenMPIRBuilder` introduced in D69785 <https://reviews.llvm.org/D69785>.

This is WIP because this will need to be updated once D69785 <https://reviews.llvm.org/D69785> settles.

Also for `taskwait` inside `untied` tasks we should be reusing the available `global_tid` instead of calling `__kmpc_global_thread_num` again.

Other than that, code generation is the same.

Note, however, that the untied case emitted by `emitUntiedSwitch` is still done using the old codegen: I think we want to keep the two approaches clearly apart until we can fully replace the old codegen with `OpenMPIRBuilder`.


https://reviews.llvm.org/D69828

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/IR/OpenMPIRBuilder.h
  llvm/include/llvm/IR/OpenMPKinds.def
  llvm/lib/IR/OpenMPIRBuilder.cpp


Index: llvm/lib/IR/OpenMPIRBuilder.cpp
===================================================================
--- llvm/lib/IR/OpenMPIRBuilder.cpp
+++ llvm/lib/IR/OpenMPIRBuilder.cpp
@@ -215,3 +215,16 @@
     (void)Cmp;
   }
 }
+
+void OpenMPIRBuilder::emitOMPTaskwait(const LocationDescription &Loc) {
+  assert(Loc.IP.getBlock() && "No insertion point provided!");
+  Builder.restoreIP(Loc.IP);
+
+  // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
+  // global_tid);
+  Constant *SrcLocStr = getSrcLocStr(Loc);
+  Value *Args[] = {getIdent(SrcLocStr), getThreadID(getIdent(SrcLocStr))};
+
+  // Ignore return result until untied tasks are supported.
+  Builder.CreateCall(getRuntimeFunction(OMPRTL___kmpc_omp_taskwait), Args);
+}
Index: llvm/include/llvm/IR/OpenMPKinds.def
===================================================================
--- llvm/include/llvm/IR/OpenMPKinds.def
+++ llvm/include/llvm/IR/OpenMPKinds.def
@@ -152,6 +152,7 @@
 __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32)
 __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32)
 __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr)
+__OMP_RTL(__kmpc_omp_taskwait, false, Int32, IdentPtr, Int32)
 
 #undef __OMP_RTL
 #undef OMP_RTL
Index: llvm/include/llvm/IR/OpenMPIRBuilder.h
===================================================================
--- llvm/include/llvm/IR/OpenMPIRBuilder.h
+++ llvm/include/llvm/IR/OpenMPIRBuilder.h
@@ -70,6 +70,12 @@
   void emitOMPBarrier(const LocationDescription &Loc, DirektiveKind DK,
                       bool CheckCancelFlag = true);
 
+  /// Generator for '#omp taskwait'
+  ///
+  /// \param Loc The location where the taskwait directive was encountered.
+  ///
+  void emitOMPTaskwait(const LocationDescription& Loc);
+
   ///}
 
 private:
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6349,11 +6349,9 @@
                                        SourceLocation Loc) {
   if (!CGF.HaveInsertPoint())
     return;
-  // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
-  // global_tid);
-  llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)};
-  // Ignore return result until untied tasks are supported.
-  CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskwait), Args);
+
+  CGF.CGM.getOpenMPIRBuilder().emitOMPTaskwait({CGF.Builder.saveIP()});
+
   if (auto *Region = dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo))
     Region->emitUntiedSwitch(CGF);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69828.227790.patch
Type: text/x-patch
Size: 2633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191104/a32f485a/attachment.bin>


More information about the llvm-commits mailing list