[PATCH] D142317: [Support][LLD] Avoid using uninitialized threadIndex.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 14:20:26 PST 2023


avl created this revision.
avl added reviewers: MaskRay, andrewng, ikudrin, peter.smith.
Herald added subscribers: arphaman, hiraditya, arichardson, emaste.
Herald added a project: All.
avl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

llvm::parallel::getThreadIndex() is used to get unique index of threads
used with llvm::parallelFor(). Unique threads indexes are assigned in
constructor of ThreadPoolExecutor. The llvm::parallelFor() uses threads
created by ThreadPoolExecutor as well as main thread. The index for the main
thread is not assigned:

  parallel::TaskGroup TG;
  for (; Begin + TaskSize < End; Begin += TaskSize) {
    TG.spawn([=, &Fn] {
      for (size_t I = Begin, E = Begin + TaskSize; I != E; ++I)
        Fn(I);
    });
  }
  for (; Begin != End; ++Begin)    <<<< executed by main thread.
    Fn(Begin);                     <<<<
  return;                          <<<<

This patch assigns index for the main thread and introduces function
which can be used to determine number of threads used by llvm::parallelFor().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142317

Files:
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Writer.cpp
  llvm/include/llvm/Support/Parallel.h
  llvm/lib/Support/Parallel.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142317.491205.patch
Type: text/x-patch
Size: 9719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230122/32245faf/attachment.bin>


More information about the llvm-commits mailing list