Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,40 +383,6 @@ jobs:
- name: build
run: cmake --build out

# Duplicates build-asan. Please keep in sync
build-cxx20:
name: c++20
# Make sure we can still build on older Ubuntu
runs-on: ubuntu-22.04
env:
CC: "gcc"
CXX: "g++"
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: actions/checkout@v4
with:
submodules: true
- name: install ninja
run: sudo apt-get install ninja-build
- name: install v8
run: |
npm install jsvu -g
jsvu --os=default --engines=v8
- name: install Python dev dependencies
run: pip3 install -r requirements-dev.txt
- name: cmake
run: |
mkdir -p out
cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20
- name: build
run: cmake --build out
- name: test
run: |
python check.py --binaryen-bin=out/bin lit
python check.py --binaryen-bin=out/bin gtest

# Ensures we can build in no-asserts mode (just building).
build-noasserts:
name: noasserts
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(GNUInstallDirs)
# The C++ standard whose features are required to build Binaryen.
# Keep in sync with scripts/test/shared.py cxx_standard
# The if condition allows embedding in a project with a higher default C++ standard set
set(REQUIRED_CXX_STANDARD 17)
set(REQUIRED_CXX_STANDARD 20)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${REQUIRED_CXX_STANDARD})
elseif(CMAKE_CXX_STANDARD LESS ${REQUIRED_CXX_STANDARD})
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ After that you can build with CMake:
cmake . && make
```

A C++17 compiler is required. On macOS, you need to install `cmake`, for example, via `brew install cmake`. Note that you can also use `ninja` as your generator: `cmake -G Ninja . && ninja`.
A C++20 compiler is required. On macOS, you need to install `cmake`, for
example, via `brew install cmake`. Note that you can also use `ninja` as your
generator: `cmake -G Ninja . && ninja`.

To avoid the gtest dependency, you can pass `-DBUILD_TESTS=OFF` to cmake.

Expand Down
2 changes: 1 addition & 1 deletion scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# The C++ standard whose features are required to build Binaryen.
# Keep in sync with CMakeLists.txt CXX_STANDARD
cxx_standard = 17
cxx_standard = 20


def parse_args(args):
Expand Down
6 changes: 3 additions & 3 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5816,7 +5816,7 @@ void BinaryenClearPassArguments(void) { globalPassOptions.arguments.clear(); }

bool BinaryenHasPassToSkip(const char* pass) {
assert(pass);
return globalPassOptions.passesToSkip.count(pass);
return globalPassOptions.passesToSkip.contains(pass);
}

void BinaryenAddPassToSkip(const char* pass) {
Expand Down Expand Up @@ -5873,7 +5873,7 @@ void BinaryenModuleRunPasses(BinaryenModuleRef module,
passRunner.options = globalPassOptions;
for (BinaryenIndex i = 0; i < numPasses; i++) {
passRunner.add(passes[i],
globalPassOptions.arguments.count(passes[i]) > 0
globalPassOptions.arguments.contains(passes[i])
? globalPassOptions.arguments[passes[i]]
: std::optional<std::string>());
}
Expand Down Expand Up @@ -6125,7 +6125,7 @@ void BinaryenFunctionRunPasses(BinaryenFunctionRef func,
passRunner.options = globalPassOptions;
for (BinaryenIndex i = 0; i < numPasses; i++) {
passRunner.add(passes[i],
globalPassOptions.arguments.count(passes[i]) > 0
globalPassOptions.arguments.contains(passes[i])
? globalPassOptions.arguments[passes[i]]
: std::optional<std::string>());
}
Expand Down
8 changes: 4 additions & 4 deletions src/cfg/Relooper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace CFG {

template<class T, class U>
static bool contains(const T& container, const U& contained) {
return !!container.count(contained);
return container.contains(contained);
}

// Rendering utilities
Expand Down Expand Up @@ -667,7 +667,7 @@ struct Optimizer : public RelooperRecursor {
// Add a branch to the target (which may be the unchanged original) in
// the set of new branches. If it's a replacement, it may collide, and
// we need to merge.
if (NewBranchesOut.count(Replacement)) {
if (NewBranchesOut.contains(Replacement)) {
#if RELOOPER_OPTIMIZER_DEBUG
std::cout << " merge\n";
#endif
Expand Down Expand Up @@ -915,7 +915,7 @@ struct Optimizer : public RelooperRecursor {
return false;
}
for (auto& [ABlock, ABranch] : A->BranchesOut) {
if (B->BranchesOut.count(ABlock) == 0) {
if (!B->BranchesOut.contains(ABlock)) {
return false;
}
auto* BBranch = B->BranchesOut[ABlock];
Expand Down Expand Up @@ -1578,7 +1578,7 @@ void Relooper::Calculate(Block* Entry) {
// jumped to forward, without using the label variable
bool Checked = false;
for (auto* Entry : *Entries) {
if (InitialEntries.count(Entry)) {
if (InitialEntries.contains(Entry)) {
Checked = true;
break;
}
Expand Down
14 changes: 7 additions & 7 deletions src/cfg/cfg-traversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ struct CFGWalker : public PostWalker<SubType, VisitorType> {
queue.erase(iter);
alive.insert(curr);
for (auto* out : curr->out) {
if (!alive.count(out)) {
if (!alive.contains(out)) {
queue.insert(out);
}
}
Expand All @@ -626,21 +626,21 @@ struct CFGWalker : public PostWalker<SubType, VisitorType> {

void unlinkDeadBlocks(std::unordered_set<BasicBlock*> alive) {
for (auto& block : basicBlocks) {
if (!alive.count(block.get())) {
if (!alive.contains(block.get())) {
block->in.clear();
block->out.clear();
continue;
}
block->in.erase(std::remove_if(block->in.begin(),
block->in.end(),
[&alive](BasicBlock* other) {
return !alive.count(other);
return !alive.contains(other);
}),
block->in.end());
block->out.erase(std::remove_if(block->out.begin(),
block->out.end(),
[&alive](BasicBlock* other) {
return !alive.count(other);
return !alive.contains(other);
}),
block->out.end());
}
Expand All @@ -664,17 +664,17 @@ struct CFGWalker : public PostWalker<SubType, VisitorType> {
std::cout << "<==\nCFG [" << message << "]:\n";
generateDebugIds();
for (auto& block : basicBlocks) {
assert(debugIds.count(block.get()) > 0);
assert(debugIds.contains(block.get()));
std::cout << " block " << debugIds[block.get()] << " (" << block.get()
<< "):\n";
block->contents.dump(static_cast<SubType*>(this)->getFunction());
for (auto& in : block->in) {
assert(debugIds.count(in) > 0);
assert(debugIds.contains(in));
assert(std::find(in->out.begin(), in->out.end(), block.get()) !=
in->out.end()); // must be a parallel link back
}
for (auto& out : block->out) {
assert(debugIds.count(out) > 0);
assert(debugIds.contains(out));
std::cout << " out: " << debugIds[out] << "\n";
assert(std::find(out->in.begin(), out->in.end(), block.get()) !=
out->in.end()); // must be a parallel link back
Expand Down
2 changes: 1 addition & 1 deletion src/cfg/liveness-traversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct LivenessWalker : public CFGWalker<SubType, VisitorType, Liveness> {
// keep working while stuff is flowing
std::unordered_set<BasicBlock*> queue;
for (auto& curr : CFGWalker<SubType, VisitorType, Liveness>::basicBlocks) {
if (liveBlocks.count(curr.get()) == 0) {
if (!liveBlocks.contains(curr.get())) {
continue; // ignore dead blocks
}
queue.insert(curr.get());
Expand Down
2 changes: 1 addition & 1 deletion src/ir/ExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ struct Hasher {
// (block $x (br $x))
// (block $y (br $y))
// But if the name is not known to us, hash the absolute one.
if (!internalNames.count(curr)) {
if (!internalNames.contains(curr)) {
rehash(digest, 1);
// Perform the same hashing as a generic name.
visitNonScopeName(curr);
Expand Down
14 changes: 7 additions & 7 deletions src/ir/LocalGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ struct LocalGraphFlower
auto index = get->index;

// We must never repeat work.
assert(!getSetsMap.count(get));
assert(!getSetsMap.contains(get));

// Regardless of what we do below, ensure an entry for this get, so that we
// know we computed it.
Expand Down Expand Up @@ -410,7 +410,7 @@ struct LocalGraphFlower
auto index = set->index;

// We must never repeat work.
assert(!setInfluences.count(set));
assert(!setInfluences.contains(set));

// In theory we could flow the set forward, but to keep things simple we
// reuse the logic for flowing gets backwards: We flow all the gets of the
Expand All @@ -419,7 +419,7 @@ struct LocalGraphFlower
// doing work for local indexes we don't care about.
for (auto* get : getsByIndex[index]) {
// Don't repeat work.
if (!getSetsMap.count(get)) {
if (!getSetsMap.contains(get)) {
computeGetSets(get);
}
}
Expand Down Expand Up @@ -632,7 +632,7 @@ void LocalGraph::computeSSAIndexes() {
}
}

bool LocalGraph::isSSA(Index x) { return SSAIndexes.count(x); }
bool LocalGraph::isSSA(Index x) { return SSAIndexes.contains(x); }

// LazyLocalGraph

Expand Down Expand Up @@ -672,7 +672,7 @@ LazyLocalGraph::~LazyLocalGraph() {

void LazyLocalGraph::computeGetSets(LocalGet* get) const {
// We must never repeat work.
assert(!getSetsMap.count(get));
assert(!getSetsMap.contains(get));

if (!flower) {
makeFlower();
Expand All @@ -682,7 +682,7 @@ void LazyLocalGraph::computeGetSets(LocalGet* get) const {

void LazyLocalGraph::computeSetInfluences(LocalSet* set) const {
// We must never repeat work.
assert(!setInfluences.count(set));
assert(!setInfluences.contains(set));

if (!flower) {
makeFlower();
Expand All @@ -705,7 +705,7 @@ void LazyLocalGraph::computeGetInfluences() const {

bool LazyLocalGraph::computeSSA(Index index) const {
// We must never repeat work.
assert(!SSAIndexes.count(index));
assert(!SSAIndexes.contains(index));

if (!flower) {
makeFlower();
Expand Down
2 changes: 1 addition & 1 deletion src/ir/branch-hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline std::optional<bool> get(Expression* expr, Function* func) {
inline void set(Expression* expr, std::optional<bool> likely, Function* func) {
// When we are writing an empty hint, do not create an empty annotation if one
// did not exist.
if (!likely && !func->codeAnnotations.count(expr)) {
if (!likely && !func->codeAnnotations.contains(expr)) {
return;
}
func->codeAnnotations[expr].branchLikely = likely;
Expand Down
2 changes: 1 addition & 1 deletion src/ir/branch-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class BranchSeekerCache {
}

bool hasBranch(Expression* curr, Name target) {
bool result = getBranches(curr).count(target);
bool result = getBranches(curr).contains(target);
#if BRANCH_UTILS_DEBUG
assert(bresult == BranchSeeker::has(curr, target));
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/ir/debuginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inline void copyOriginalToReplacement(Expression* original,
// if there is no debug info we do want to copy, as a replacement operation
// suggests the new code plays the same role (it is an optimized version of
// the old), but if the code is already annotated, trust that.
if (debugLocations.empty() || debugLocations.count(replacement)) {
if (debugLocations.empty() || debugLocations.contains(replacement)) {
return;
}

Expand Down
13 changes: 7 additions & 6 deletions src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,13 @@ class EffectAnalyzer {
// write-write, write-read, and read-write conflicts on a local prevent
// reordering.
for (auto local : localsWritten) {
if (other.localsRead.count(local) || other.localsWritten.count(local)) {
if (other.localsRead.contains(local) ||
other.localsWritten.contains(local)) {
return true;
}
}
for (auto local : localsRead) {
if (other.localsWritten.count(local)) {
if (other.localsWritten.contains(local)) {
return true;
}
}
Expand All @@ -401,13 +402,13 @@ class EffectAnalyzer {
return true;
}
for (auto global : globalsWritten) {
if (other.mutableGlobalsRead.count(global) ||
other.globalsWritten.count(global)) {
if (other.mutableGlobalsRead.contains(global) ||
other.globalsWritten.contains(global)) {
return true;
}
}
for (auto global : mutableGlobalsRead) {
if (other.globalsWritten.count(global)) {
if (other.globalsWritten.contains(global)) {
return true;
}
}
Expand Down Expand Up @@ -568,7 +569,7 @@ class EffectAnalyzer {
// expression is not inside a try-catch_all. It is hard to figure out
// whether the original try-delegate's body throws or not at this point.
if (curr->name.is()) {
if (self->parent.delegateTargets.count(curr->name) &&
if (self->parent.delegateTargets.contains(curr->name) &&
self->parent.tryDepth == 0) {
self->parent.throws_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ir/local-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ struct LazyLocalGraph : public LocalGraphBase {
if (iter == SSAIndexes.end()) {
auto ret = computeSSA(index);
// The result must have been memoized.
assert(SSAIndexes.count(index));
assert(SSAIndexes.contains(index));
return ret;
}
return iter->second;
Expand Down
Loading
Loading