diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp index 0d25de464f9f6..5878386aeb934 100644 --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -1056,7 +1056,7 @@ void TypeMerger::mergeTypesWithGHash() { // position. Because the table does not rehash, the position will not change // under insertion. After insertion is done, the value of the cell can be read // to retrieve the final PDB type index. - parallelForEachN(0, ctx.tpiSourceList.size(), [&](size_t tpiSrcIdx) { + parallelFor(0, ctx.tpiSourceList.size(), [&](size_t tpiSrcIdx) { TpiSource *source = ctx.tpiSourceList[tpiSrcIdx]; source->indexMapStorage.resize(source->ghashes.size()); for (uint32_t i = 0, e = source->ghashes.size(); i < e; i++) { diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index 8323626623948..49546ea8bdc20 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -233,10 +233,10 @@ void ICF::forEachClass(std::function fn) { size_t boundaries[numShards + 1]; boundaries[0] = 0; boundaries[numShards] = chunks.size(); - parallelForEachN(1, numShards, [&](size_t i) { + parallelFor(1, numShards, [&](size_t i) { boundaries[i] = findBoundary((i - 1) * step, chunks.size()); }); - parallelForEachN(1, numShards + 1, [&](size_t i) { + parallelFor(1, numShards + 1, [&](size_t i) { if (boundaries[i - 1] < boundaries[i]) { forEachClassRange(boundaries[i - 1], boundaries[i], fn); } diff --git a/lld/COFF/LLDMapFile.cpp b/lld/COFF/LLDMapFile.cpp index 639b186dbb6f9..af15af5accf11 100644 --- a/lld/COFF/LLDMapFile.cpp +++ b/lld/COFF/LLDMapFile.cpp @@ -75,7 +75,7 @@ static SymbolMapTy getSectionSyms(ArrayRef syms) { static DenseMap getSymbolStrings(ArrayRef syms) { std::vector str(syms.size()); - parallelForEachN((size_t)0, syms.size(), [&](size_t i) { + parallelFor((size_t)0, syms.size(), [&](size_t i) { raw_string_ostream os(str[i]); writeHeader(os, syms[i]->getRVA(), 0, 0); os << indent16 << toString(*syms[i]); diff --git a/lld/COFF/MapFile.cpp b/lld/COFF/MapFile.cpp index ace614da866bc..2da50af303872 100644 --- a/lld/COFF/MapFile.cpp +++ b/lld/COFF/MapFile.cpp @@ -141,7 +141,7 @@ static void getSymbols(const COFFLinkerContext &ctx, static DenseMap getSymbolStrings(const COFFLinkerContext &ctx, ArrayRef syms) { std::vector str(syms.size()); - parallelForEachN((size_t)0, syms.size(), [&](size_t i) { + parallelFor((size_t)0, syms.size(), [&](size_t i) { raw_string_ostream os(str[i]); Defined *sym = syms[i]; diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index f4e4389b41fc4..77d32db6718a1 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -422,11 +422,11 @@ void ICF::forEachClass(llvm::function_ref fn) { boundaries[0] = 0; boundaries[numShards] = sections.size(); - parallelForEachN(1, numShards, [&](size_t i) { + parallelFor(1, numShards, [&](size_t i) { boundaries[i] = findBoundary((i - 1) * step, sections.size()); }); - parallelForEachN(1, numShards + 1, [&](size_t i) { + parallelFor(1, numShards + 1, [&](size_t i) { if (boundaries[i - 1] < boundaries[i]) forEachClassRange(boundaries[i - 1], boundaries[i], fn); }); diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp index 048d41b8d0eeb..bcd897a83a82a 100644 --- a/lld/ELF/MapFile.cpp +++ b/lld/ELF/MapFile.cpp @@ -92,7 +92,7 @@ static SymbolMapTy getSectionSyms(ArrayRef syms) { static DenseMap getSymbolStrings(ArrayRef syms) { auto strs = std::make_unique(syms.size()); - parallelForEachN(0, syms.size(), [&](size_t i) { + parallelFor(0, syms.size(), [&](size_t i) { raw_string_ostream os(strs[i]); OutputSection *osec = syms[i]->getOutputSection(); uint64_t vma = syms[i]->getVA(); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 44d3d3c7ca28f..bc940c7e65462 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -350,7 +350,7 @@ template void OutputSection::maybeCompress() { // concatenated with the next shard. auto shardsOut = std::make_unique[]>(numShards); auto shardsAdler = std::make_unique(numShards); - parallelForEachN(0, numShards, [&](size_t i) { + parallelFor(0, numShards, [&](size_t i) { shardsOut[i] = deflateShard(shardsIn[i], level, i != numShards - 1 ? Z_SYNC_FLUSH : Z_FINISH); shardsAdler[i] = adler32(1, shardsIn[i].data(), shardsIn[i].size()); @@ -409,7 +409,7 @@ template void OutputSection::writeTo(uint8_t *buf) { buf[0] = 0x78; // CMF buf[1] = 0x01; // FLG: best speed - parallelForEachN(0, compressed.numShards, [&](size_t i) { + parallelFor(0, compressed.numShards, [&](size_t i) { memcpy(buf + offsets[i], compressed.shards[i].data(), compressed.shards[i].size()); }); @@ -425,7 +425,7 @@ template void OutputSection::writeTo(uint8_t *buf) { if (nonZeroFiller) fill(buf, sections.empty() ? size : sections[0]->outSecOff, filler); - parallelForEachN(0, sections.size(), [&](size_t i) { + parallelFor(0, sections.size(), [&](size_t i) { InputSection *isec = sections[i]; if (auto *s = dyn_cast(isec)) s->writeTo(buf + isec->outSecOff); @@ -623,7 +623,7 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) { assert(config->writeAddends && config->checkDynamicRelocs); assert(type == SHT_REL || type == SHT_RELA); SmallVector sections = getInputSections(*this); - parallelForEachN(0, sections.size(), [&](size_t i) { + parallelFor(0, sections.size(), [&](size_t i) { // When linking with -r or --emit-relocs we might also call this function // for input .rel[a]. sections which we simply pass through to the // output. We skip over those and only look at the synthetic relocation diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 2f16ddcd5b972..091e038365274 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2841,7 +2841,7 @@ static SmallVector createSymbols( // Instantiate GdbSymbols while uniqufying them by name. auto symbols = std::make_unique[]>(numShards); - parallelForEachN(0, concurrency, [&](size_t threadId) { + parallelFor(0, concurrency, [&](size_t threadId) { uint32_t i = 0; for (ArrayRef entries : nameAttrs) { for (const NameAttrEntry &ent : entries) { @@ -2921,7 +2921,7 @@ template GdbIndexSection *GdbIndexSection::create() { SmallVector chunks(files.size()); SmallVector, 0> nameAttrs(files.size()); - parallelForEachN(0, files.size(), [&](size_t i) { + parallelFor(0, files.size(), [&](size_t i) { // To keep memory usage low, we don't want to keep cached DWARFContext, so // avoid getDwarf() here. ObjFile *file = cast>(files[i]); @@ -3287,8 +3287,8 @@ void MergeTailSection::finalizeContents() { } void MergeNoTailSection::writeTo(uint8_t *buf) { - parallelForEachN(0, numShards, - [&](size_t i) { shards[i].write(buf + shardOffsets[i]); }); + parallelFor(0, numShards, + [&](size_t i) { shards[i].write(buf + shardOffsets[i]); }); } // This function is very hot (i.e. it can take several seconds to finish) @@ -3312,7 +3312,7 @@ void MergeNoTailSection::finalizeContents() { numShards)); // Add section pieces to the builders. - parallelForEachN(0, concurrency, [&](size_t threadId) { + parallelFor(0, concurrency, [&](size_t threadId) { for (MergeInputSection *sec : sections) { for (size_t i = 0, e = sec->pieces.size(); i != e; ++i) { if (!sec->pieces[i].live) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 649958b747986..5e2cf0713c406 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2915,7 +2915,7 @@ computeHash(llvm::MutableArrayRef hashBuf, std::unique_ptr hashes(new uint8_t[hashesSize]); // Compute hash values. - parallelForEachN(0, chunks.size(), [&](size_t i) { + parallelFor(0, chunks.size(), [&](size_t i) { hashFn(hashes.get() + i * hashBuf.size(), chunks[i]); }); diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp index 6d10262826e54..515fa7fbbf546 100644 --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -270,10 +270,10 @@ void ICF::forEachClass(llvm::function_ref func) { size_t boundaries[shards + 1]; boundaries[0] = 0; boundaries[shards] = icfInputs.size(); - parallelForEachN(1, shards, [&](size_t i) { + parallelFor(1, shards, [&](size_t i) { boundaries[i] = findBoundary((i - 1) * step, icfInputs.size()); }); - parallelForEachN(1, shards + 1, [&](size_t i) { + parallelFor(1, shards + 1, [&](size_t i) { if (boundaries[i - 1] < boundaries[i]) { forEachClassRange(boundaries[i - 1], boundaries[i], func); } diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp index a4a0065c28165..974d823a4fab1 100644 --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -75,7 +75,7 @@ static std::pair getSymbols() { static DenseMap getSymbolStrings(ArrayRef syms) { std::vector str(syms.size()); - parallelForEachN(0, syms.size(), [&](size_t i) { + parallelFor(0, syms.size(), [&](size_t i) { raw_string_ostream os(str[i]); Defined *sym = syms[i]; diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index 5822d668b4c06..2c4a469578de2 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -326,7 +326,7 @@ void UnwindInfoSectionImpl::prepareRelocations(ConcatInputSection *isec) { // is no source address to make a relative location meaningful. void UnwindInfoSectionImpl::relocateCompactUnwind( std::vector &cuEntries) { - parallelForEachN(0, symbolsVec.size(), [&](size_t i) { + parallelFor(0, symbolsVec.size(), [&](size_t i) { CompactUnwindEntry &cu = cuEntries[i]; const Defined *d = symbolsVec[i].second; cu.functionAddress = d->getVA(); diff --git a/lld/wasm/MapFile.cpp b/lld/wasm/MapFile.cpp index 9dbab5046e23a..0e63fda6acd61 100644 --- a/lld/wasm/MapFile.cpp +++ b/lld/wasm/MapFile.cpp @@ -75,7 +75,7 @@ static SymbolMapTy getSectionSyms(ArrayRef syms) { static DenseMap getSymbolStrings(ArrayRef syms) { std::vector str(syms.size()); - parallelForEachN(0, syms.size(), [&](size_t i) { + parallelFor(0, syms.size(), [&](size_t i) { raw_string_ostream os(str[i]); auto *chunk = syms[i]->getChunk(); if (chunk == nullptr) diff --git a/llvm/include/llvm/Support/Parallel.h b/llvm/include/llvm/Support/Parallel.h index 04caf5eac961d..ff113f9b44c48 100644 --- a/llvm/include/llvm/Support/Parallel.h +++ b/llvm/include/llvm/Support/Parallel.h @@ -193,11 +193,11 @@ void parallelSort(RandomAccessIterator Start, RandomAccessIterator End, llvm::sort(Start, End, Comp); } -void parallelForEachN(size_t Begin, size_t End, function_ref Fn); +void parallelFor(size_t Begin, size_t End, function_ref Fn); template void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn) { - parallelForEachN(0, End - Begin, [&](size_t I) { Fn(Begin[I]); }); + parallelFor(0, End - Begin, [&](size_t I) { Fn(Begin[I]); }); } template Records) { // Hash every name in parallel. - parallelForEachN(0, Records.size(), [&](size_t I) { + parallelFor(0, Records.size(), [&](size_t I) { Records[I].setBucketIdx(hashStringV1(Records[I].Name) % IPHR_HASH); }); @@ -232,7 +232,7 @@ void GSIHashStreamBuilder::finalizeBuckets( // bucket can properly early-out when it detects the record won't be found. // The algorithm used here corresponds to the function // caseInsensitiveComparePchPchCchCch in the reference implementation. - parallelForEachN(0, IPHR_HASH, [&](size_t I) { + parallelFor(0, IPHR_HASH, [&](size_t I) { auto B = HashRecords.begin() + BucketStarts[I]; auto E = HashRecords.begin() + BucketCursors[I]; if (B == E) diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp index 85426847c28c9..798d7124e7e94 100644 --- a/llvm/lib/Support/Parallel.cpp +++ b/llvm/lib/Support/Parallel.cpp @@ -175,8 +175,8 @@ void TaskGroup::spawn(std::function F) { } // namespace llvm #endif // LLVM_ENABLE_THREADS -void llvm::parallelForEachN(size_t Begin, size_t End, - llvm::function_ref Fn) { +void llvm::parallelFor(size_t Begin, size_t End, + llvm::function_ref Fn) { // If we have zero or one items, then do not incur the overhead of spinning up // a task group. They are surprisingly expensive, and because they do not // support nested parallelism, a single entry task group can block parallel diff --git a/llvm/unittests/Support/ParallelTest.cpp b/llvm/unittests/Support/ParallelTest.cpp index f4bd10b57f89e..bbf27dfab437e 100644 --- a/llvm/unittests/Support/ParallelTest.cpp +++ b/llvm/unittests/Support/ParallelTest.cpp @@ -40,7 +40,7 @@ TEST(Parallel, parallel_for) { // writing. uint32_t range[2050]; std::fill(range, range + 2050, 1); - parallelForEachN(0, 2049, [&range](size_t I) { ++range[I]; }); + parallelFor(0, 2049, [&range](size_t I) { ++range[I]; }); uint32_t expected[2049]; std::fill(expected, expected + 2049, 2); diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md index 5bb6ed572c398..dbb503e018d6a 100644 --- a/mlir/docs/Diagnostics.md +++ b/mlir/docs/Diagnostics.md @@ -381,7 +381,7 @@ ParallelDiagnosticHandler handler(context); // Process a list of operations in parallel. std::vector opsToProcess = ...; -llvm::parallelForEachN(0, opsToProcess.size(), [&](size_t i) { +llvm::parallelFor(0, opsToProcess.size(), [&](size_t i) { // Notify the handler that we are processing the i'th operation. handler.setOrderIDForThread(i); auto *op = opsToProcess[i]; diff --git a/mlir/include/mlir/IR/Threading.h b/mlir/include/mlir/IR/Threading.h index dd99039e298ac..4dc067667ea40 100644 --- a/mlir/include/mlir/IR/Threading.h +++ b/mlir/include/mlir/IR/Threading.h @@ -138,8 +138,7 @@ void parallelForEach(MLIRContext *context, RangeT &&range, FuncT &&func) { /// not have multi-threading enabled, this function always processes elements /// sequentially. template -void parallelForEachN(MLIRContext *context, size_t begin, size_t end, - FuncT &&func) { +void parallelFor(MLIRContext *context, size_t begin, size_t end, FuncT &&func) { parallelForEach(context, llvm::seq(begin, end), std::forward(func)); }