summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp21
-rw-r--r--src/wasm/wasm-s-parser.cpp6
-rw-r--r--src/wasm/wasm-stack.cpp14
-rw-r--r--src/wasm/wasm.cpp6
4 files changed, 47 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index e616493af..f3160c461 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2967,6 +2967,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
if (maybeVisitSIMDLoadStoreLane(curr, opcode)) {
break;
}
+ if (maybeVisitPrefetch(curr, opcode)) {
+ break;
+ }
throwError("invalid code after SIMD prefix: " + std::to_string(opcode));
break;
}
@@ -5372,6 +5375,24 @@ bool WasmBinaryBuilder::maybeVisitSIMDLoadStoreLane(Expression*& out,
return true;
}
+bool WasmBinaryBuilder::maybeVisitPrefetch(Expression*& out, uint32_t code) {
+ PrefetchOp op;
+ switch (code) {
+ case BinaryConsts::PrefetchT:
+ op = PrefetchTemporal;
+ break;
+ case BinaryConsts::PrefetchNT:
+ op = PrefetchNontemporal;
+ break;
+ default:
+ return false;
+ }
+ Address align, offset;
+ readMemoryAccess(align, offset);
+ out = Builder(wasm).makePrefetch(op, offset, align, popNonVoidExpression());
+ return true;
+}
+
void WasmBinaryBuilder::visitSelect(Select* curr, uint8_t code) {
BYN_TRACE("zz node: Select, code " << int32_t(code) << std::endl);
if (code == BinaryConsts::SelectWithType) {
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 20e99436a..20ab4f3d2 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1662,6 +1662,12 @@ SExpressionWasmBuilder::makeSIMDLoadStoreLane(Element& s,
return ret;
}
+Expression* SExpressionWasmBuilder::makePrefetch(Element& s, PrefetchOp op) {
+ Address offset, align;
+ size_t i = parseMemAttributes(s, offset, align, /*defaultAlign*/ 1);
+ return Builder(wasm).makePrefetch(op, offset, align, parseExpression(s[i]));
+}
+
Expression* SExpressionWasmBuilder::makeMemoryInit(Element& s) {
auto ret = allocator.alloc<MemoryInit>();
ret->segment = atoi(s[1]->str().c_str());
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 776928b88..b31aaf4d4 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -694,6 +694,20 @@ void BinaryInstWriter::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
o << curr->index;
}
+void BinaryInstWriter::visitPrefetch(Prefetch* curr) {
+ o << int8_t(BinaryConsts::SIMDPrefix);
+ switch (curr->op) {
+ case PrefetchTemporal:
+ o << U32LEB(BinaryConsts::PrefetchT);
+ break;
+ case PrefetchNontemporal:
+ o << U32LEB(BinaryConsts::PrefetchNT);
+ break;
+ }
+ assert(curr->align);
+ emitMemoryAccess(curr->align, /*(unused) bytes=*/0, curr->offset);
+}
+
void BinaryInstWriter::visitMemoryInit(MemoryInit* curr) {
o << int8_t(BinaryConsts::MiscPrefix);
o << U32LEB(BinaryConsts::MemoryInit);
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 264f2bf83..fb523e254 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -174,6 +174,8 @@ const char* getExpressionName(Expression* curr) {
return "simd_load";
case Expression::Id::SIMDLoadStoreLaneId:
return "simd_load_store_lane";
+ case Expression::Id::PrefetchId:
+ return "prefetch";
case Expression::Id::MemoryInitId:
return "memory.init";
case Expression::Id::DataDropId:
@@ -656,6 +658,10 @@ bool SIMDLoadStoreLane::isStore() {
WASM_UNREACHABLE("unexpected op");
}
+void Prefetch::finalize() {
+ type = ptr->type == Type::unreachable ? Type::unreachable : Type::none;
+}
+
Const* Const::set(Literal value_) {
value = value_;
type = value.type;