Skip to content

Commit

Permalink
[Flang][OpenMP][MLIR][Lower] Update lowering to use wrapper ops
Browse files Browse the repository at this point in the history
This patch introduces the following changes:
  - Complete OpenMP directive sets to include masked and taskloop-related ones.
  - Refactor clause processing to store related operands in structures. These
are combined into construct-specific operand structures using a mixin pattern
and simplify keeping track of operand lists used for creating OpenMP
operations and reduces argument lists.
  - Update the lowering to MLIR of loop constructs to follow the wrapper +
canonical loop approach. This includes some changes to privatization that need
testing.
  - Add lowering for the omp.canonical_loop operation, based on omp.wsloop.
  - Significant refactor of OpenMP construct lowering, separating composite
constructs into their own "gen" functions and handling combined loop constructs
in a more scalable way. Updated genOMP functions to follow the same set of
patterns to make it more understandable. Split clause processing calls from
code generation for operations in preparation for reusing the same code when
dealing with composite constructs.
  - Add basic support for taskloop, for completeness sake.
  - Document missing clauses.
  - Move some code from OpenMP.cpp to ClauseProcessor.cpp and call it there
to simplify calls to certain process methods that were always followed by the
same post-processing.
  - Add and populate "composite" attribute on wrapper operations.
  - Add empty constructors for wrapper operations.
  - Update `LoopWrapperInterface` to avoid compilation problems.
  - Update `Task*` operation's names to follow the same capitalization
convention.
  - Changes to SCF to OpenMP conversion to produce a wrapper omp.wsloop with a
nested omp.canonical_loop rather than an invalid omp.wsloop.
  - Document missing verifier checks on wrapper operations.
  - Make temporary changes to OpenMP to LLVM IR translation to make this
compilable.

All these changes are still WIP, as they haven't been tested.
  • Loading branch information
skatrak committed Mar 14, 2024
1 parent 0553a46 commit 1e47d70
Show file tree
Hide file tree
Showing 17 changed files with 2,503 additions and 1,775 deletions.
172 changes: 96 additions & 76 deletions flang/include/flang/Semantics/openmp-directive-sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,80 @@ namespace llvm::omp {
// - all<Directive>Set: All standalone or combined uses of the directive.

static const OmpDirectiveSet topParallelSet{
Directive::OMPD_parallel,
Directive::OMPD_parallel_do,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_parallel_do,
Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_masked_taskloop,
Directive::OMPD_parallel_master_taskloop_simd,
Directive::OMPD_parallel_master_taskloop,
Directive::OMPD_parallel_sections,
Directive::OMPD_parallel_workshare,
Directive::OMPD_parallel,
};

static const OmpDirectiveSet allParallelSet{
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_parallel,
Directive::OMPD_parallel_do,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_parallel_sections,
Directive::OMPD_parallel_workshare,
Directive::OMPD_target_parallel,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
OmpDirectiveSet{
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_parallel_do,
} | topParallelSet,
};

static const OmpDirectiveSet topDoSet{
Directive::OMPD_do,
Directive::OMPD_do_simd,
Directive::OMPD_do,
};

static const OmpDirectiveSet allDoSet{
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_parallel_do,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_do,
Directive::OMPD_do_simd,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
OmpDirectiveSet{
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_parallel_do,
} | topDoSet,
};

static const OmpDirectiveSet topTaskloopSet{
Directive::OMPD_taskloop,
Directive::OMPD_taskloop_simd,
Directive::OMPD_taskloop,
};

static const OmpDirectiveSet allTaskloopSet{topTaskloopSet};
static const OmpDirectiveSet allTaskloopSet{
OmpDirectiveSet{
Directive::OMPD_masked_taskloop_simd,
Directive::OMPD_masked_taskloop,
Directive::OMPD_master_taskloop_simd,
Directive::OMPD_master_taskloop,
Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_masked_taskloop,
Directive::OMPD_parallel_master_taskloop_simd,
Directive::OMPD_parallel_master_taskloop,
} | topTaskloopSet,
};

static const OmpDirectiveSet topTargetSet{
Directive::OMPD_target,
Directive::OMPD_target_parallel,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel,
Directive::OMPD_target_simd,
Directive::OMPD_target_teams,
Directive::OMPD_target_teams_distribute,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_parallel_do,
Directive::OMPD_target_teams_distribute_simd,
Directive::OMPD_target_teams_distribute,
Directive::OMPD_target_teams,
Directive::OMPD_target,
};

static const OmpDirectiveSet allTargetSet{topTargetSet};
Expand All @@ -95,61 +107,61 @@ static const OmpDirectiveSet topSimdSet{
};

static const OmpDirectiveSet allSimdSet{
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_simd,
Directive::OMPD_do_simd,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_simd,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_simd,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_simd,
Directive::OMPD_taskloop_simd,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_simd,
OmpDirectiveSet{
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_simd,
Directive::OMPD_do_simd,
Directive::OMPD_masked_taskloop_simd,
Directive::OMPD_master_taskloop_simd,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_master_taskloop_simd,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_simd,
Directive::OMPD_target_teams_distribute_parallel_do_simd,
Directive::OMPD_target_teams_distribute_simd,
Directive::OMPD_taskloop_simd,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_simd,
} | topSimdSet,
};

static const OmpDirectiveSet topTeamsSet{
Directive::OMPD_teams,
Directive::OMPD_teams_distribute,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_parallel_do_simd,
Directive::OMPD_teams_distribute_parallel_do,
Directive::OMPD_teams_distribute_simd,
Directive::OMPD_teams_distribute,
Directive::OMPD_teams,
};

static const OmpDirectiveSet allTeamsSet{
llvm::omp::OMPD_target_teams,
llvm::omp::OMPD_target_teams_distribute,
llvm::omp::OMPD_target_teams_distribute_parallel_do,
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_target_teams_distribute_simd,
llvm::omp::OMPD_teams,
llvm::omp::OMPD_teams_distribute,
llvm::omp::OMPD_teams_distribute_parallel_do,
llvm::omp::OMPD_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_teams_distribute_simd,
OmpDirectiveSet{
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_target_teams_distribute_parallel_do,
llvm::omp::OMPD_target_teams_distribute_simd,
llvm::omp::OMPD_target_teams_distribute,
llvm::omp::OMPD_target_teams,
} | topTeamsSet,
};

static const OmpDirectiveSet topDistributeSet{
Directive::OMPD_distribute,
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_distribute_parallel_do_simd,
Directive::OMPD_distribute_parallel_do,
Directive::OMPD_distribute_simd,
Directive::OMPD_distribute,
};

static const OmpDirectiveSet allDistributeSet{
llvm::omp::OMPD_distribute,
llvm::omp::OMPD_distribute_parallel_do,
llvm::omp::OMPD_distribute_parallel_do_simd,
llvm::omp::OMPD_distribute_simd,
llvm::omp::OMPD_target_teams_distribute,
llvm::omp::OMPD_target_teams_distribute_parallel_do,
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_target_teams_distribute_simd,
llvm::omp::OMPD_teams_distribute,
llvm::omp::OMPD_teams_distribute_parallel_do,
llvm::omp::OMPD_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_teams_distribute_simd,
OmpDirectiveSet{
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_target_teams_distribute_parallel_do,
llvm::omp::OMPD_target_teams_distribute_simd,
llvm::omp::OMPD_target_teams_distribute,
llvm::omp::OMPD_teams_distribute_parallel_do_simd,
llvm::omp::OMPD_teams_distribute_parallel_do,
llvm::omp::OMPD_teams_distribute_simd,
llvm::omp::OMPD_teams_distribute,
} | topDistributeSet,
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -188,8 +200,16 @@ static const OmpDirectiveSet loopConstructSet{
Directive::OMPD_distribute,
Directive::OMPD_do_simd,
Directive::OMPD_do,
Directive::OMPD_masked_taskloop,
Directive::OMPD_masked_taskloop_simd,
Directive::OMPD_master_taskloop,
Directive::OMPD_master_taskloop_simd,
Directive::OMPD_parallel_do_simd,
Directive::OMPD_parallel_do,
Directive::OMPD_parallel_masked_taskloop,
Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_master_taskloop,
Directive::OMPD_parallel_master_taskloop_simd,
Directive::OMPD_simd,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_parallel_do,
Expand Down
Loading

0 comments on commit 1e47d70

Please sign in to comment.