[llvm] [Parallel] Ensure getThreadIndex()==0 for sequential tasks (PR #109084)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 12:57:26 PDT 2024
================
@@ -217,13 +194,18 @@ TaskGroup::~TaskGroup() {
void TaskGroup::spawn(std::function<void()> F, bool Sequential) {
#if LLVM_ENABLE_THREADS
if (Parallel) {
+ if (Sequential) {
+ // Act as worker thread 0.
+ threadIndex = 0;
----------------
aganea wrote:
@MaskRay I meant this whole sequential flag could be solved by including the for... loop in the task at the call site, when serial=true, no? (in elf::scanRelocations) That way you get a valid `threadIndex` and the items are executed sequentially.
```
bool serial = ...
parallel::TaskGroup tg;
auto outerFn = [&]() {
for (ELFFileBase *f : ctx.objectFiles) {
auto fn = [f]() {
RelocationScanner scanner;
for (InputSectionBase *s : f->getSections()) {
if (s && s->kind() == SectionBase::Regular && s->isLive() &&
(s->flags & SHF_ALLOC) &&
!(s->type == SHT_ARM_EXIDX && config->emachine == EM_ARM))
scanner.template scanSection<ELFT>(*s);
}
};
if (serial)
fn();
else
tg.spawn(fn);
}
};
if (serial)
tg.spawn(outerFn);
else
outerFn();
```
https://github.com/llvm/llvm-project/pull/109084
More information about the llvm-commits
mailing list