Skip to content

optimize in for low memory device #2535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion include/wabt/binary-reader-ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Result ReadBinaryIr(const char* filename,
Errors*,
Module* out_module);

} // namespace wabt
class OpcodeRawExpr;
Result ExtractOpcodeRawExpr(OpcodeRawExpr& expr,
Module& module,
const ReadBinaryOptions& options);

} // namespace wabt

#endif /* WABT_BINARY_READER_IR_H_ */
1 change: 1 addition & 0 deletions include/wabt/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnDropExpr() override;
Result OnElseExpr() override;
Result OnEndExpr() override;
Result OnSkipFunctionBodyExpr(std::vector<uint8_t>& opcode_buffer) override;
Result OnF32ConstExpr(uint32_t value_bits) override;
Result OnF64ConstExpr(uint64_t value_bits) override;
Result OnV128ConstExpr(v128 value_bits) override;
Expand Down
3 changes: 3 additions & 0 deletions include/wabt/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnDropExpr() override { return Result::Ok; }
Result OnElseExpr() override { return Result::Ok; }
Result OnEndExpr() override { return Result::Ok; }
Result OnSkipFunctionBodyExpr(std::vector<uint8_t>& opcode_buffer) override {
return Result::Ok;
}
Result OnF32ConstExpr(uint32_t value_bits) override { return Result::Ok; }
Result OnF64ConstExpr(uint64_t value_bits) override { return Result::Ok; }
Result OnV128ConstExpr(v128 value_bits) override { return Result::Ok; }
Expand Down
8 changes: 8 additions & 0 deletions include/wabt/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class BinaryReaderDelegate {
virtual Result OnDropExpr() = 0;
virtual Result OnElseExpr() = 0;
virtual Result OnEndExpr() = 0;
virtual Result OnSkipFunctionBodyExpr(
std::vector<uint8_t>& opcode_buffer) = 0;
virtual Result OnF32ConstExpr(uint32_t value_bits) = 0;
virtual Result OnF64ConstExpr(uint64_t value_bits) = 0;
virtual Result OnV128ConstExpr(v128 value_bits) = 0;
Expand Down Expand Up @@ -511,6 +513,12 @@ Result ReadBinary(const void* data,
BinaryReaderDelegate* reader,
const ReadBinaryOptions& options);

Result ExtractFunctionBody(const void* data,
size_t size,
Location& loc,
BinaryReaderDelegate* delegate,
const ReadBinaryOptions& options);

size_t ReadU32Leb128(const uint8_t* ptr,
const uint8_t* end,
uint32_t* out_value);
Expand Down
5 changes: 5 additions & 0 deletions include/wabt/binary-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ struct WriteBinaryOptions {

Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions&);

class OpcodeRawExpr;
Result PackOpcodeRawExpr(OpcodeRawExpr& expr,
Module& module,
const WriteBinaryOptions& options);

void WriteType(Stream* stream, Type type, const char* desc = nullptr);

void WriteStr(Stream* stream,
Expand Down
2 changes: 1 addition & 1 deletion include/wabt/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ enum class LabelType {
Try,
TryTable,
Catch,

ExtractFunc,
First = Func,
Last = Catch,
};
Expand Down
3 changes: 3 additions & 0 deletions include/wabt/expr-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ExprVisitor {
Try,
TryTable,
Catch,
OpcodeRaw
};

Result HandleDefaultState(Expr*);
Expand Down Expand Up @@ -141,6 +142,7 @@ class ExprVisitor::Delegate {
virtual Result OnSimdShuffleOpExpr(SimdShuffleOpExpr*) = 0;
virtual Result OnLoadSplatExpr(LoadSplatExpr*) = 0;
virtual Result OnLoadZeroExpr(LoadZeroExpr*) = 0;
virtual Result OnOpcodeRawExpr(OpcodeRawExpr*) = 0;
};

class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Expand Down Expand Up @@ -222,6 +224,7 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result OnSimdShuffleOpExpr(SimdShuffleOpExpr*) override { return Result::Ok; }
Result OnLoadSplatExpr(LoadSplatExpr*) override { return Result::Ok; }
Result OnLoadZeroExpr(LoadZeroExpr*) override { return Result::Ok; }
Result OnOpcodeRawExpr(OpcodeRawExpr*) override { return Result::Ok; }
};

} // namespace wabt
Expand Down
19 changes: 18 additions & 1 deletion include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ enum class ExprType {
Unreachable,

First = AtomicLoad,
Last = Unreachable
Last = Unreachable,
OpCodeRaw = Last + 1, // virtual type
Copy link
Collaborator

Choose a reason for hiding this comment

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

correct us if we're wrong, but you should be able to put it into the enum as normal, between Nop and RefIsNull. you'll need to update the matching array in uh ir.cc (and maybe other places) but the alternative would be to make the code reject OpCodeRaw everywhere else.

also, how about calling this UndecodedOpcodes (between Unary and Unreachable)?

};

const char* GetExprTypeName(ExprType type);
Expand Down Expand Up @@ -839,6 +840,22 @@ class AtomicFenceExpr : public ExprMixin<ExprType::AtomicFence> {
uint32_t consistency_model;
};

class OpcodeRawExpr : public ExprMixin<ExprType::OpCodeRaw> {
public:
explicit OpcodeRawExpr(std::vector<uint8_t>&& in_opcode_buffer,
FuncSignature& in_func_sig,
const Location& loc = Location())
: ExprMixin<ExprType::OpCodeRaw>(loc),
opcode_buffer(std::move(in_opcode_buffer)),
is_extracted(false),
func_sig(&in_func_sig) {}

std::vector<uint8_t> opcode_buffer;
bool is_extracted;
ExprList extracted_exprs;
const FuncSignature* func_sig;
};

struct Tag {
explicit Tag(std::string_view name) : name(name) {}

Expand Down
Loading
Loading