# [PATCH] [OPENMP] Codegen for 'omp barrier' directive.

Alexey Bataev a.bataev at hotmail.com
Wed Dec 3 00:41:20 PST 2014

================
Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:640
@@ -642,3 +639,3 @@
OpenMPLocationFlags Flags) {
-  // Build call __kmpc_barrier(loc, thread_id)
+  // Build call __kmpc_cancel_barrier(loc, thread_id);
llvm::Value *Args[] = {EmitOpenMPUpdateLocation(CGF, Loc, Flags),
----------------
rjmccall wrote:
> Does this runtime function always exist, or is it contingent on having a sufficiently new OpenMP runtime?  If the latter, you should introduce the concept of a target OpenMP runtime version, patterned on the target Objective-C runtime version.
>
> Also, please describe in a comment why we're using this function rather than the other, since apparently both "work" in some sense.
Yes, it exists always. In OpenMP 3.1 it works just the same way as a regular kmpc_barrier() (actually, kmpc_cancel_barrier just calls it). But it adds processing of cancellation directives introduced in OpenMP 4.0.

================
Comment at: lib/CodeGen/CGOpenMPRuntime.h:96
@@ +95,3 @@
+    /// \brief Implicit barrier in 'for' directive.
+    OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
+    /// \brief Implicit barrier in 'sections' directive.
----------------
rjmccall wrote:
> Is this supposed to be the same value as OMP_IDENT_BARRIER_IMPL?  If so, is there a better way to define these constants that makes their structure more obvious?
Yes, these values are just copied from runtime header file. We need to modify runtime to modify these values

================
Comment at: lib/CodeGen/CGOpenMPRuntime.h:238
@@ +237,3 @@
+  virtual void EmitOMPBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
+                                  OpenMPLocationFlags Flags);
+
----------------
rjmccall wrote:
> Don't make two functions with the same name that differ only in an enum vs. bool argument.
Ok, I'll rename one of them

http://reviews.llvm.org/D6447