This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP50]Codegen for reduction clauses with 'task' modifier.
ClosedPublic

Authored by ABataev on Apr 28 2020, 12:44 PM.

Details

Summary

Added codegen for reduction clause with task modifier.

#pragma omp ... reduction(task, +: a)
{
#pragma omp ... in_reduction(+: a)
}

is translated into something like this:

#pragma omp ... reduction(+:a)
{
  struct red_input_t {
    void *reduce_shar;
    void *reduce_orig;
    size_t reduce_size;
    void *reduce_init;
    void *reduce_fini;
    void *reduce_comb;
    unsigned flags;
  } r_var;
  r_var.reduce_shar = &a;
  r_var.reduce_orig = &original a;
  r_var.reduce_size = sizeof(a);
  r_var.reduce_init = [](void* l,void*){return *(int*)l=0;};
  r_var.reduce_fini = nullptr;
  r_var.reduce_comb = [](void* l,void* r){return *(int*)l += *(int)r;};
  void *tg = __kmpc_taskred_modifier_init(<loc_addr>,<gtid>,
    <flag - 0 for parallel, 1 for worksharing>,
    <1 - number of reduction elements>,
    &r_var);
  {
  #pragma omp ... in_reduction(+: a) firstprivate(tg)
  ...
  }
  __kmpc_task_reduction_modifier_fini(<loc_addr>,<gtid>,
    <flag - 0 for parallel, 1 for worksharing>);
}

Diff Detail

Event Timeline

ABataev created this revision.Apr 28 2020, 12:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2020, 12:44 PM
ABataev updated this revision to Diff 260736.Apr 28 2020, 12:48 PM

Remove non-required code.

jdoerfert accepted this revision.Apr 30 2020, 12:53 PM

Some nits noted below. Can be done prior to commit.

clang/lib/CodeGen/CGOpenMPRuntime.cpp
2376

This reminds me, we should replace this code with a generator. I'll look into it.

6887

Nit: Unclear if the ternary operator is really needed.

clang/lib/CodeGen/CGOpenMPRuntime.h
2246

__kmpc_task_reduction_modifier_init, same elsewhere.

2260

__kmpc_task_reduction_modifier_fini, same elsewhere

This revision is now accepted and ready to land.Apr 30 2020, 12:53 PM
This revision was automatically updated to reflect the committed changes.