[OPENMP] Codegen for 'if' clause in 'parallel' directive.
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 13 Oct 2014 06:02:40 +0000 (06:02 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 13 Oct 2014 06:02:40 +0000 (06:02 +0000)
commit0b72dab70eee688e5e69987ab4909b5cb50ba069
treeb4d752a075447a265c9e81ac13a18bafb418704e
parent46bb1befc59697ae537e65575520be18c602069a
[OPENMP] Codegen for 'if' clause in 'parallel' directive.
Adds codegen for 'if' clause. Currently only for 'if' clause used with the 'parallel' directive.
If condition evaluates to true, the code executes parallel version of the code by calling __kmpc_fork_call(loc, 1, microtask, captured_struct/*context*/), where loc - debug location, 1 - number of additional parameters after "microtask" argument, microtask - is outlined finction for the code associated with the 'parallel' directive, captured_struct - list of variables captured in this outlined function.
If condition evaluates to false, the code executes serial version of the code by executing the following code:

global_thread_id.addr = alloca i32
store i32 global_thread_id, global_thread_id.addr
zero.addr = alloca i32
store i32 0, zero.addr
kmpc_serialized_parallel(loc, global_thread_id);
microtask(global_thread_id.addr, zero.addr, captured_struct/*context*/);
kmpc_end_serialized_parallel(loc, global_thread_id);

Where loc - debug location, global_thread_id - global thread id, returned by __kmpc_global_thread_num() call or passed as a first parameter in microtask() call, global_thread_id.addr - address of the variable, where stored global_thread_id value, zero.addr - implicit bound thread id (should be set to 0 for serial call), microtask() and captured_struct are the same as in parallel call.

Also this patch checks if the condition is constant and if it is constant it evaluates its value and then generates either parallel version of the code (if the condition evaluates to true), or the serial version of the code (if the condition evaluates to false).
Differential Revision: http://reviews.llvm.org/D4716

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219597 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/StmtOpenMP.h
lib/AST/Stmt.cpp
lib/CodeGen/CGOpenMPRuntime.cpp
lib/CodeGen/CGOpenMPRuntime.h
lib/CodeGen/CGStmtOpenMP.cpp
test/OpenMP/parallel_if_codegen.cpp [new file with mode: 0644]