#ifndef wasm_ir_stack_h
#define wasm_ir_stack_h
#include "ir/properties.h"
#include "wasm-type.h"
#include "wasm.h"
namespace wasm {
namespace StackUtils {
void removeNops(Block* block);
bool mayBeUnreachable(Expression* expr);
}
struct StackSignature {
Type params;
Type results;
bool unreachable;
StackSignature()
: params(Type::none), results(Type::none), unreachable(false) {}
StackSignature(Type params, Type results, bool unreachable = false)
: params(params), results(results), unreachable(unreachable) {}
StackSignature(const StackSignature&) = default;
StackSignature& operator=(const StackSignature&) = default;
explicit StackSignature(Expression* expr);
template<class InputIt>
explicit StackSignature(InputIt first, InputIt last)
: params(Type::none), results(Type::none), unreachable(false) {
while (first != last) {
*this += StackSignature(*first++);
}
}
bool composes(const StackSignature& next) const;
bool satisfies(Signature sig) const;
StackSignature& operator+=(const StackSignature& next);
StackSignature operator+(const StackSignature& next) const;
bool operator==(const StackSignature& other) const {
return params == other.params && results == other.results &&
unreachable == other.unreachable;
}
};
struct StackFlow {
struct Location {
Expression* expr;
Index index;
Type type;
bool unreachable;
bool operator==(const Location& other) const {
return expr == other.expr && index == other.index && type == other.type &&
unreachable == other.unreachable;
}
};
using LocationMap = std::unordered_map<Expression*, std::vector<Location>>;
LocationMap srcs;
LocationMap dests;
StackSignature getSignature(Expression* expr);
StackFlow(Block* curr);
};
}
#endif