[all-commits] [llvm/llvm-project] 5fa9d4: [Support/Parallel] Add a special case for 0/1 item...

Chris Lattner via All-commits all-commits at lists.llvm.org
Mon May 3 10:08:24 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5fa9d4163421304255d12498fd672e79893422a4
      https://github.com/llvm/llvm-project/commit/5fa9d4163421304255d12498fd672e79893422a4
  Author: Chris Lattner <clattner at nondot.org>
  Date:   2021-05-03 (Mon, 03 May 2021)

  Changed paths:
    M llvm/include/llvm/Support/Parallel.h

  Log Message:
  -----------
  [Support/Parallel] Add a special case for 0/1 items to llvm::parallel_for_each.

This avoids the non-trivial overhead of creating a TaskGroup in these degenerate
cases, but also exposes parallelism.  It turns out that the default executor
underlying TaskGroup prevents recursive parallelism - so an instance of a task
group being alive will make nested ones become serial.

This is a big issue in MLIR in some dialects, if they have a single instance of
an outer op (e.g. a firrtl.circuit) that has many parallel ops within it (e.g.
a firrtl.module).  This patch side-steps the problem by avoiding creating the
TaskGroup in the unneeded case.  See this issue for more details:
https://github.com/llvm/circt/issues/993

Note that this isn't a really great solution for the general case of nested
parallelism.  A redesign of the TaskGroup stuff would be better, but would be
a much more invasive change.

Differential Revision: https://reviews.llvm.org/D101699




More information about the All-commits mailing list