1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 18:40:59 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-26 13:34:15 +09:00
parent 69d93fbe66
commit 5dc2ab3905
2 changed files with 40 additions and 7 deletions

36
main.cc
View File

@ -249,6 +249,41 @@ int main(int argc, char **argv) {
{
MyTimer t("bin_sections", before_copy);
#if 1
typedef std::vector<std::vector<InputSection *>> T;
auto fn = [&](const tbb::blocked_range<int> &range, const T &init) {
T vec = init;
for (int i = range.begin(); i < range.end(); i++) {
ObjectFile *file = files[i];
for (InputSection *isec : file->sections) {
if (!isec)
continue;
OutputSection *osec = isec->output_section;
vec[osec->idx].push_back(isec);
}
}
return vec;
};
auto reduce = [](const T &x, const T &y) {
T ret(x.size());
for (int i = 0; i < x.size(); i++)
ret[i] = x[i];
for (int i = 0; i < x.size(); i++)
ret[i].insert(ret[i].end(), y[i].begin(), y[i].end());
return ret;
};
std::vector<std::vector<InputSection *>> vec =
tbb::parallel_reduce(tbb::blocked_range<int>(0, files.size()),
T(OutputSection::all_instances.size()),
fn, reduce);
for (int i = 0; i < vec.size(); i++)
OutputSection::all_instances[i]->chunks = std::move(vec[i]);
#else
for (ObjectFile *file : files) {
for (InputSection *isec : file->sections) {
if (!isec)
@ -257,6 +292,7 @@ int main(int argc, char **argv) {
osec->chunks.push_back(isec);
}
}
#endif
}
{

11
mold.h
View File

@ -17,6 +17,7 @@
#include "tbb/concurrent_unordered_set.h"
#include "tbb/concurrent_vector.h"
#include "tbb/parallel_for_each.h"
#include "tbb/parallel_reduce.h"
#include "tbb/parallel_sort.h"
#include "tbb/partitioner.h"
#include "tbb/task_group.h"
@ -113,13 +114,6 @@ static void for_each(T &arr, Callable callback) {
//
namespace tbb {
template<>
struct tbb_hash<StringRef> {
size_t operator()(const StringRef& k) const {
return llvm::hash_value(k);
}
};
template<>
struct tbb_hash_compare<StringRef> {
static size_t hash(const StringRef& k) {
@ -293,6 +287,7 @@ public:
this->name = name;
shdr.sh_flags = flags;
shdr.sh_type = type;
idx = all_instances.size();
all_instances.push_back(this);
}
@ -311,6 +306,8 @@ public:
}
std::vector<InputSection *> chunks;
uint32_t idx;
static std::vector<OutputSection *> all_instances;
};