This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Support for the if-clause on the combined directive 'target parallel'.
ClosedPublic

Authored by arpith-jacob on Jan 16 2017, 2:28 PM.

Details

Summary

The if-clause on the combined directive potentially applies to both the
'target' and the 'parallel' regions. Codegen'ing the if-clause on the
combined directive requires additional support because the expression in
the clause must be captured by the 'target' capture statement but not
the 'parallel' capture statement. Note that this situation arises for
other clauses such as num_threads.

The OMPIfClause class inherits OMPClauseWithPreInit to support capturing
of expressions in the clause. A member CaptureRegion is added to
OMPClauseWithPreInit to indicate the innermost captured statement (in this
case 'target' but not 'parallel') that captures these expressions.

To ensure correct codegen of captured expressions in the presence of
'parallel' combined with 'target', OMPParallelScope was added to 'parallel'
codegen.

Diff Detail

Repository
rL LLVM

Event Timeline

arpith-jacob created this revision.Jan 16 2017, 2:28 PM
ABataev added inline comments.Jan 17 2017, 5:46 AM
lib/CodeGen/CGStmtOpenMP.cpp
84–115 ↗(On Diff #84597)

Could you join it with OMPLexicalScope somehow? I don't like the idea of adding a different kind of scope for parallel and other directives.
Or follow the solution for OMPLoopScope, rather than for OMPLexicalScope.

arpith-jacob added inline comments.Jan 17 2017, 11:08 AM
lib/CodeGen/CGStmtOpenMP.cpp
84–115 ↗(On Diff #84597)

Hi Alexey, thanks for looking at this patch.

We need a different kind of scope for 'parallel', however, we don't need a different scope for any other directive so the code additions should be limited. Here is my idea for merging it with OMPLexicalScope to reduce code duplication.

I can make OMPParallelScope derive from OMPLexicalScope. I'll make emitPreInitStmt a virtual class that can be overridden.

class OMPParallelScope final : public OMPLexicalScope {
  void emitPreInitStmt(CodeGenFunction &CGF, const OMPExecutableDirective &S) override {
    OpenMPDirectiveKind Kind = S.getDirectiveKind();
    if (!isOpenMPTargetExecutionDirective(Kind) &&
        isOpenMPParallelDirective(Kind))
        OMPParallelScope::emitPreInitStmt(CGF, S);
  }
...
}

Does that look ok?

arpith-jacob added inline comments.Jan 17 2017, 11:10 AM
lib/CodeGen/CGStmtOpenMP.cpp
84–115 ↗(On Diff #84597)

Sorry, the code should read:

class OMPParallelScope final : public OMPLexicalScope {

void emitPreInitStmt(CodeGenFunction &CGF, const OMPExecutableDirective &S) override {
  OpenMPDirectiveKind Kind = S.getDirectiveKind();
  if (!isOpenMPTargetExecutionDirective(Kind) &&
      isOpenMPParallelDirective(Kind))
      //**OMPLexicalScope**//::emitPreInitStmt(CGF, S);
}

...
}

Another correction. We'll have to create a similar scope OMPTeamsScope that inherits from OMPLexicalScope for target-teams combined directives.

Inherit from OMPLexical scope with an added argument to reduce code duplication.

This revision is now accepted and ready to land.Jan 18 2017, 6:54 AM
This revision was automatically updated to reflect the committed changes.