Skip to content

Commit

Permalink
Support multi-memory in all memory ops and in apply/resolve-names (#1962
Browse files Browse the repository at this point in the history
)
  • Loading branch information
keithw authored Aug 15, 2022
1 parent 3bf73a8 commit 8c50fd5
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 256 deletions.
12 changes: 12 additions & 0 deletions src/apply-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class NameApplier : public ExprVisitor::DelegateNop {
Result OnDelegateExpr(TryExpr*) override;
Result OnThrowExpr(ThrowExpr*) override;
Result OnRethrowExpr(RethrowExpr*) override;
Result OnSimdLoadLaneExpr(SimdLoadLaneExpr*) override;
Result OnSimdStoreLaneExpr(SimdStoreLaneExpr*) override;

private:
void PushLabel(const std::string& label);
Expand Down Expand Up @@ -463,6 +465,16 @@ Result NameApplier::OnLocalTeeExpr(LocalTeeExpr* expr) {
return Result::Ok;
}

Result NameApplier::OnSimdLoadLaneExpr(SimdLoadLaneExpr* expr) {
CHECK_RESULT(UseNameForMemoryVar(&expr->memidx));
return Result::Ok;
}

Result NameApplier::OnSimdStoreLaneExpr(SimdStoreLaneExpr* expr) {
CHECK_RESULT(UseNameForMemoryVar(&expr->memidx));
return Result::Ok;
}

Result NameApplier::VisitFunc(Index func_index, Func* func) {
current_func_ = func;
if (func->decl.has_func_type) {
Expand Down
48 changes: 32 additions & 16 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,28 @@ class BinaryReaderIR : public BinaryReaderNop {

Result OnOpcode(Opcode opcode) override;
Result OnAtomicLoadExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicStoreExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicRmwExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicRmwCmpxchgExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicWaitExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicFenceExpr(uint32_t consistency_model) override;
Result OnAtomicNotifyExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnBinaryExpr(Opcode opcode) override;
Expand Down Expand Up @@ -262,9 +268,11 @@ class BinaryReaderIR : public BinaryReaderNop {
uint64_t value) override;
Result OnSimdShuffleOpExpr(Opcode opcode, v128 value) override;
Result OnLoadSplatExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnLoadZeroExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;

Expand Down Expand Up @@ -737,49 +745,55 @@ Result BinaryReaderIR::OnOpcode(Opcode opcode) {
}

Result BinaryReaderIR::OnAtomicLoadExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicLoadExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicLoadExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnAtomicStoreExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicStoreExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicStoreExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnAtomicRmwExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicRmwExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicRmwExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnAtomicRmwCmpxchgExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicRmwCmpxchgExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicRmwCmpxchgExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnAtomicWaitExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicWaitExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicWaitExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnAtomicFenceExpr(uint32_t consistency_model) {
return AppendExpr(MakeUnique<AtomicFenceExpr>(consistency_model));
}

Result BinaryReaderIR::OnAtomicNotifyExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<AtomicNotifyExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<AtomicNotifyExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnBinaryExpr(Opcode opcode) {
Expand Down Expand Up @@ -1193,17 +1207,19 @@ Result BinaryReaderIR::OnSimdShuffleOpExpr(Opcode opcode, v128 value) {
}

Result BinaryReaderIR::OnLoadSplatExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<LoadSplatExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<LoadSplatExpr>(
opcode, Var(memidx, GetLocation()), 1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnLoadZeroExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) {
return AppendExpr(
MakeUnique<LoadZeroExpr>(opcode, 1 << alignment_log2, offset));
return AppendExpr(MakeUnique<LoadZeroExpr>(opcode, Var(memidx, GetLocation()),
1 << alignment_log2, offset));
}

Result BinaryReaderIR::OnElemSegmentCount(Index count) {
Expand Down
23 changes: 11 additions & 12 deletions src/binary-reader-logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,7 @@ Result BinaryReaderLogging::OnCodeMetadata(Offset code_offset,
return reader_->name(opcode); \
}

#define DEFINE_LOAD_STORE_OPCODE(name) \
Result BinaryReaderLogging::name(Opcode opcode, Address alignment_log2, \
Address offset) { \
LOGF(#name "(opcode: \"%s\" (%u), align log2: %" PRIaddress \
", offset: %" PRIaddress ")\n", \
opcode.GetName(), opcode.GetCode(), alignment_log2, offset); \
return reader_->name(opcode, alignment_log2, offset); \
}

#define DEFINE_MEMORY_LOAD_STORE_OPCODE(name) \
#define DEFINE_LOAD_STORE_OPCODE(name) \
Result BinaryReaderLogging::name(Opcode opcode, Index memidx, \
Address alignment_log2, Address offset) { \
LOGF(#name "(opcode: \"%s\" (%u), memidx: %" PRIindex \
Expand Down Expand Up @@ -816,7 +807,7 @@ DEFINE0(OnElseExpr)
DEFINE0(OnEndExpr)
DEFINE_INDEX_DESC(OnGlobalGetExpr, "index")
DEFINE_INDEX_DESC(OnGlobalSetExpr, "index")
DEFINE_MEMORY_LOAD_STORE_OPCODE(OnLoadExpr);
DEFINE_LOAD_STORE_OPCODE(OnLoadExpr);
DEFINE_INDEX_DESC(OnLocalGetExpr, "index")
DEFINE_INDEX_DESC(OnLocalSetExpr, "index")
DEFINE_INDEX_DESC(OnLocalTeeExpr, "index")
Expand Down Expand Up @@ -845,7 +836,7 @@ DEFINE_INDEX_INDEX(OnReturnCallIndirectExpr, "sig_index", "table_index")
DEFINE0(OnReturnExpr)
DEFINE_LOAD_STORE_OPCODE(OnLoadSplatExpr);
DEFINE_LOAD_STORE_OPCODE(OnLoadZeroExpr);
DEFINE_MEMORY_LOAD_STORE_OPCODE(OnStoreExpr);
DEFINE_LOAD_STORE_OPCODE(OnStoreExpr);
DEFINE_INDEX_DESC(OnThrowExpr, "tag_index")
DEFINE0(OnUnreachableExpr)
DEFINE_OPCODE(OnUnaryExpr)
Expand Down Expand Up @@ -945,6 +936,14 @@ Result BinaryReaderLogging::OnOpcodeUint32Uint32Uint32(uint32_t value,
return reader_->OnOpcodeUint32Uint32Uint32(value, value2, value3);
}

Result BinaryReaderLogging::OnOpcodeUint32Uint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3,
uint32_t value4) {
return reader_->OnOpcodeUint32Uint32Uint32Uint32(value, value2, value3,
value4);
}

Result BinaryReaderLogging::OnOpcodeUint64(uint64_t value) {
return reader_->OnOpcodeUint64(value);
}
Expand Down
12 changes: 12 additions & 0 deletions src/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,30 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnOpcodeUint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3) override;
Result OnOpcodeUint32Uint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3,
uint32_t value4) override;
Result OnOpcodeUint64(uint64_t value) override;
Result OnOpcodeF32(uint32_t value) override;
Result OnOpcodeF64(uint64_t value) override;
Result OnOpcodeV128(v128 value) override;
Result OnOpcodeBlockSig(Type sig_type) override;
Result OnOpcodeType(Type type) override;
Result OnAtomicLoadExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicStoreExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicRmwExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicRmwCmpxchgExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnBinaryExpr(Opcode opcode) override;
Expand Down Expand Up @@ -225,10 +233,12 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnTernaryExpr(Opcode opcode) override;
Result OnUnreachableExpr() override;
Result OnAtomicWaitExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnAtomicFenceExpr(uint32_t consistency_model) override;
Result OnAtomicNotifyExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result EndFunctionBody(Index index) override;
Expand All @@ -246,9 +256,11 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
uint64_t value) override;
Result OnSimdShuffleOpExpr(Opcode opcode, v128 value) override;
Result OnLoadSplatExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;
Result OnLoadZeroExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override;

Expand Down
16 changes: 14 additions & 2 deletions src/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,37 +190,47 @@ class BinaryReaderNop : public BinaryReaderDelegate {
uint32_t value3) override {
return Result::Ok;
}
Result OnOpcodeUint32Uint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3,
uint32_t value4) override {
return Result::Ok;
}
Result OnOpcodeUint64(uint64_t value) override { return Result::Ok; }
Result OnOpcodeF32(uint32_t value) override { return Result::Ok; }
Result OnOpcodeF64(uint64_t value) override { return Result::Ok; }
Result OnOpcodeV128(v128 value) override { return Result::Ok; }
Result OnOpcodeBlockSig(Type sig_type) override { return Result::Ok; }
Result OnOpcodeType(Type type) override { return Result::Ok; }
Result OnAtomicLoadExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
}
Result OnAtomicStoreExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
}
Result OnAtomicRmwExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
}
Result OnAtomicRmwCmpxchgExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
}
Result OnAtomicWaitExpr(Opcode, Address, Address) override {
Result OnAtomicWaitExpr(Opcode, Index, Address, Address) override {
return Result::Ok;
}
Result OnAtomicFenceExpr(uint32_t) override { return Result::Ok; }
Result OnAtomicNotifyExpr(Opcode, Address, Address) override {
Result OnAtomicNotifyExpr(Opcode, Index, Address, Address) override {
return Result::Ok;
}
Result OnBinaryExpr(Opcode opcode) override { return Result::Ok; }
Expand Down Expand Up @@ -332,11 +342,13 @@ class BinaryReaderNop : public BinaryReaderDelegate {
return Result::Ok;
}
Result OnLoadSplatExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
}
Result OnLoadZeroExpr(Opcode opcode,
Index memidx,
Address alignment_log2,
Address offset) override {
return Result::Ok;
Expand Down
16 changes: 16 additions & 0 deletions src/binary-reader-objdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase {
Result OnOpcodeUint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3) override;
Result OnOpcodeUint32Uint32Uint32Uint32(uint32_t value,
uint32_t value2,
uint32_t value3,
uint32_t value4) override;
Result OnOpcodeUint64(uint64_t value) override;
Result OnOpcodeF32(uint32_t value) override;
Result OnOpcodeF64(uint64_t value) override;
Expand Down Expand Up @@ -829,6 +833,18 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32Uint32Uint32(
return Result::Ok;
}

Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32Uint32Uint32Uint32(
uint32_t value,
uint32_t value2,
uint32_t value3,
uint32_t value4) {
if (!in_function_body) {
return Result::Ok;
}
LogOpcode("%u %u %u %u", value, value2, value3, value4);
return Result::Ok;
}

Result BinaryReaderObjdumpDisassemble::OnOpcodeUint64(uint64_t value) {
if (!in_function_body) {
return Result::Ok;
Expand Down
5 changes: 1 addition & 4 deletions src/binary-reader-opcnt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ void OpcodeInfo::Write(Stream& stream) {
}

case Kind::Uint32Uint32:
WriteArray<uint32_t>(
stream, [&stream](uint32_t value) { stream.Writef("%u", value); });
break;

case Kind::Uint32Uint32Uint32:
case Kind::Uint32Uint32Uint32Uint32:
WriteArray<uint32_t>(
stream, [&stream](uint32_t value) { stream.Writef("%u", value); });
break;
Expand Down
1 change: 1 addition & 0 deletions src/binary-reader-opcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OpcodeInfo {
Float64,
Uint32Uint32,
Uint32Uint32Uint32,
Uint32Uint32Uint32Uint32,
BlockSig,
BrTable,
V128,
Expand Down
Loading

0 comments on commit 8c50fd5

Please sign in to comment.