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
1 change: 1 addition & 0 deletions src/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FILE(GLOB ir_HEADERS *.h)
set(ir_SOURCES
abstract.cpp
ExpressionAnalyzer.cpp
ExpressionManipulator.cpp
constraint.cpp
Expand Down
64 changes: 64 additions & 0 deletions src/ir/abstract.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2026 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ir/abstract.h"
#include "wasm.h"

namespace wasm::Abstract {

std::ostream& operator<<(std::ostream& o, Op op) {

#define HANDLE(x) \
case x: \
return o << #x;

switch (op) {
HANDLE(Abs)
HANDLE(Neg)
HANDLE(Popcnt)
HANDLE(Add)
HANDLE(Sub)
HANDLE(Mul)
HANDLE(DivU)
HANDLE(DivS)
HANDLE(RemU)
HANDLE(RemS)
HANDLE(Shl)
HANDLE(ShrU)
HANDLE(ShrS)
HANDLE(RotL)
HANDLE(RotR)
HANDLE(And)
HANDLE(Or)
HANDLE(Xor)
HANDLE(CopySign)
HANDLE(EqZ)
HANDLE(Eq)
HANDLE(Ne)
HANDLE(LtS)
HANDLE(LtU)
HANDLE(LeS)
HANDLE(LeU)
HANDLE(GtS)
HANDLE(GtU)
HANDLE(GeS)
HANDLE(GeU)
default:
WASM_UNREACHABLE("bad abstract op");
}
}

} // namespace wasm::Abstract
2 changes: 2 additions & 0 deletions src/ir/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ inline bool isRelationalAntisymmetric(Op op) {
}
}

std::ostream& operator<<(std::ostream& o, Op op);

} // namespace wasm::Abstract

#endif // wasm_ir_abstract_h
13 changes: 11 additions & 2 deletions src/ir/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,16 @@ std::optional<LocalConstraint> LocalConstraint::parse(Expression* curr) {

if (auto* binary = curr->dynCast<Binary>()) {
// The operation must be one we recognize.
for (auto op : {Abstract::Eq, Abstract::Ne}) {
for (auto op : {Abstract::Eq,
Abstract::Ne,
Abstract::LtS,
Abstract::LtU,
Abstract::LeS,
Abstract::LeU,
Abstract::GtS,
Abstract::GtU,
Abstract::GeS,
Abstract::GeU}) {
Comment on lines +237 to +246

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of guess-and-check to see if the binary operation is one we support, can we instead have a function in abstract.h to switch over binary->op and return the corresponding Abstract op, if any? Then we can very efficiently skip operations that don't correspond to any abstract op.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can measure this and look for an optimization. Maybe as an NFC followup?

(The challenge is avoiding code duplication - the current way avoids writing the mapping of opcodes twice.)

if (Abstract::getBinary(binary->type, op) == binary->op) {
return parseBinaryArguments(op, binary->left, binary->right);
}
Expand Down Expand Up @@ -421,7 +430,7 @@ void BasicBlockConstraintMap::eraseStaleRefs(Index index) {
}

std::ostream& operator<<(std::ostream& o, const Constraint& c) {
o << "Constraint{" << int(c.op) << ", ";
o << "Constraint{" << c.op << ", ";
if (auto* cc = std::get_if<Literal>(&c.term)) {
o << *cc;
} else if (auto* i = std::get_if<Index>(&c.term)) {
Expand Down
Loading
Loading