Skip to content

Commit

Permalink
wip: removed tbb use
Browse files Browse the repository at this point in the history
  • Loading branch information
fzakaria committed Jul 7, 2023
1 parent 3af1033 commit 1c942ae
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
6 changes: 6 additions & 0 deletions third_party/mold/README.cosmo
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ SOURCE
Date: Mon Jun 19 12:35:20 2023 +0900

Format

CHANGES
* removed tbb by including a fake implementation
* made the parallel_for effectively single-threaded
* changed tbb:enumerable_thread_specific to thread_local
* removed rust demangle support
16 changes: 8 additions & 8 deletions third_party/mold/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "third_party/libcxx/cassert"
#include "third_party/libcxx/cstdio"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/unordered_map"
#include "libc/calls/calls.h"
#include "libc/calls/struct/flock.h"
#include "libc/calls/weirdtypes.h"
Expand Down Expand Up @@ -44,8 +45,6 @@
#include "libc/intrin/newbie.h"
#include "libc/sock/select.h"
#include "libc/sysv/consts/endian.h"
// MISSING #include <tbb/concurrent_vector.h>
// MISSING #include <tbb/enumerable_thread_specific.h>
#include "third_party/libcxx/vector"

#ifdef _WIN32
Expand Down Expand Up @@ -758,21 +757,22 @@ class ZstdCompressor : public Compressor {
// Counter is used to collect statistics numbers.
class Counter {
public:
Counter(std::string_view name, i64 value = 0) : name(name), values(value) {
Counter(std::string_view name, i64 value = 0) : name(name) {
static std::mutex mu;
std::scoped_lock lock(mu);
instances.push_back(this);
values[this] = value;
}

Counter &operator++(int) {
if (enabled) [[unlikely]]
values.local()++;
values[this]++;
return *this;
}

Counter &operator+=(int delta) {
if (enabled) [[unlikely]]
values.local() += delta;
values[this] += delta;
return *this;
}

Expand All @@ -784,7 +784,7 @@ class Counter {
i64 get_value();

std::string_view name;
tbb::enumerable_thread_specific<i64> values;
static thread_local std::unordered_map<Counter*, i64> values;

static inline std::vector<Counter *> instances;
};
Expand All @@ -797,7 +797,7 @@ struct TimerRecord {

std::string name;
TimerRecord *parent;
tbb::concurrent_vector<TimerRecord *> children;
std::vector<TimerRecord *> children;
i64 start;
i64 end;
i64 user;
Expand All @@ -806,7 +806,7 @@ struct TimerRecord {
};

void
print_timer_records(tbb::concurrent_vector<std::unique_ptr<TimerRecord>> &);
print_timer_records(std::vector<std::unique_ptr<TimerRecord>> &);

template <typename Context>
class Timer {
Expand Down
6 changes: 3 additions & 3 deletions third_party/mold/compress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include "third_party/mold/common.h"

// MISSING #include <tbb/parallel_for_each.h>
// MISSING #include <zlib.h>
// MISSING #include <zstd.h>
#include "third_party/mold/fake_tbb.h"
#include "third_party/zlib/zlib.h"
#include "third_party/zstd/zstd.h"

#define CHECK(fn) \
do { \
Expand Down
6 changes: 3 additions & 3 deletions third_party/mold/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ std::string_view demangle(std::string_view name) {
// Try to demangle as a Rust symbol. Since legacy-style Rust symbols
// are also valid as a C++ mangled name, we need to call this before
// cpp_demangle.
p = rust_demangle(std::string(name).c_str(), 0);
if (p)
return p;
// p = rust_demangle(std::string(name).c_str(), 0);
// if (p)
// return p;

// Try to demangle as a C++ symbol.
if (std::optional<std::string_view> s = cpp_demangle(name))
Expand Down
4 changes: 2 additions & 2 deletions third_party/mold/elf/input-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "third_party/mold/elf/mold.h"

#include "third_party/libcxx/limits"
// MISSING #include <zlib.h>
// MISSING #include <zstd.h>
#include "third_party/zlib/zlib.h"
#include "third_party/zstd/zstd.h"

namespace mold::elf {

Expand Down
8 changes: 8 additions & 0 deletions third_party/mold/fake_tbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ namespace tbb {
void parallel_for_each(Range& rng, const Body& body) {
}

template<typename Range, typename Body>
void parallel_for( const Range& range, const Body& body ) {
}

template <typename Index, typename Function>
void parallel_for(Index first, Index last, const Function& f) {
}

}
#endif
10 changes: 7 additions & 3 deletions third_party/mold/mold.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

PKGS += THIRD_PARTY_MOLD

private CPPFLAGS += -std=c++20

THIRD_PARTY_MOLD_ARTIFACTS += THIRD_PARTY_MOLD_A
THIRD_PARTY_MOLD = $(THIRD_PARTY_MOLD_A_DEPS) $(THIRD_PARTY_MOLD_A)
THIRD_PARTY_MOLD_A = o/$(MODE)/third_party/mold/mold.a
Expand All @@ -15,7 +13,9 @@ THIRD_PARTY_MOLD_OBJS = $(THIRD_PARTY_MOLD_SRCS:%.cc=o/$(MODE)/%.o)

THIRD_PARTY_MOLD_A_DIRECTDEPS = \
THIRD_PARTY_LIBCXX \
THIRD_PARTY_XXHASH
THIRD_PARTY_ZSTD \
THIRD_PARTY_XXHASH \
THIRD_PARTY_ZLIB

THIRD_PARTY_MOLD_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_MOLD_A_DIRECTDEPS),$($(x))))
Expand Down Expand Up @@ -43,6 +43,10 @@ $(THIRD_PARTY_MOLD_A).pkg: \
$(THIRD_PARTY_MOLD_OBJS) \
$(foreach x,$(THIRD_PARTY_MOLD_A_DIRECTDEPS),$($(x)_A).pkg)

$(THIRD_PARTY_MOLD_A_OBJS): private \
CPPFLAGS += \
-std=c++20

o/$(MODE)/third_party/mold/mold.com.dbg: \
$(THIRD_PARTY_MOLD) \
o/$(MODE)/third_party/awk/main.o \
Expand Down

0 comments on commit 1c942ae

Please sign in to comment.