summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-interpreter.h55
-rw-r--r--test/lit/passes/precompute-strings.wast26
2 files changed, 46 insertions, 35 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 47b8d5eb5..46e5c1752 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1904,7 +1904,9 @@ public:
}
Flow visitStringMeasure(StringMeasure* curr) {
// For now we only support JS-style strings.
- assert(curr->op == StringMeasureWTF16View);
+ if (curr->op != StringMeasureWTF16View) {
+ return Flow(NONCONSTANT_FLOW);
+ }
Flow flow = visit(curr->ref);
if (flow.breaking()) {
@@ -1917,8 +1919,8 @@ public:
}
return Literal(int32_t(data->values.size()));
}
- Flow visitStringEncode(StringEncode* curr) { WASM_UNREACHABLE("unimp"); }
- Flow visitStringConcat(StringConcat* curr) { WASM_UNREACHABLE("unimp"); }
+ Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
+ Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) {
NOTE_ENTER("StringEq");
Flow flow = visit(curr->left);
@@ -1987,7 +1989,9 @@ public:
}
Flow visitStringAs(StringAs* curr) {
// For now we only support JS-style strings.
- assert(curr->op == StringAsWTF16);
+ if (curr->op != StringAsWTF16) {
+ return Flow(NONCONSTANT_FLOW);
+ }
Flow flow = visit(curr->ref);
if (flow.breaking()) {
@@ -2004,10 +2008,10 @@ public:
return Literal(data, curr->type.getHeapType());
}
Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
- WASM_UNREACHABLE("unimp");
+ return Flow(NONCONSTANT_FLOW);
}
Flow visitStringWTF16Get(StringWTF16Get* curr) {
- NOTE_ENTER("StringEq");
+ NOTE_ENTER("StringWTF16Get");
Flow ref = visit(curr->ref);
if (ref.breaking()) {
return ref;
@@ -2028,11 +2032,17 @@ public:
}
return Literal(values[i].geti32());
}
- Flow visitStringIterNext(StringIterNext* curr) { WASM_UNREACHABLE("unimp"); }
- Flow visitStringIterMove(StringIterMove* curr) { WASM_UNREACHABLE("unimp"); }
- Flow visitStringSliceWTF(StringSliceWTF* curr) { WASM_UNREACHABLE("unimp"); }
+ Flow visitStringIterNext(StringIterNext* curr) {
+ return Flow(NONCONSTANT_FLOW);
+ }
+ Flow visitStringIterMove(StringIterMove* curr) {
+ return Flow(NONCONSTANT_FLOW);
+ }
+ Flow visitStringSliceWTF(StringSliceWTF* curr) {
+ return Flow(NONCONSTANT_FLOW);
+ }
Flow visitStringSliceIter(StringSliceIter* curr) {
- WASM_UNREACHABLE("unimp");
+ return Flow(NONCONSTANT_FLOW);
}
virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
@@ -2369,31 +2379,6 @@ public:
NOTE_ENTER("Rethrow");
return Flow(NONCONSTANT_FLOW);
}
- Flow visitStringMeasure(StringMeasure* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
- Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
- Flow visitStringEq(StringEq* curr) { return Flow(NONCONSTANT_FLOW); }
- Flow visitStringAs(StringAs* curr) { return Flow(NONCONSTANT_FLOW); }
- Flow visitStringWTF8Advance(StringWTF8Advance* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringWTF16Get(StringWTF16Get* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringIterNext(StringIterNext* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringIterMove(StringIterMove* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringSliceWTF(StringSliceWTF* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
- Flow visitStringSliceIter(StringSliceIter* curr) {
- return Flow(NONCONSTANT_FLOW);
- }
Flow visitRefAs(RefAs* curr) {
// TODO: Remove this once interpretation is implemented.
if (curr->op == ExternInternalize || curr->op == ExternExternalize) {
diff --git a/test/lit/passes/precompute-strings.wast b/test/lit/passes/precompute-strings.wast
new file mode 100644
index 000000000..3436e0069
--- /dev/null
+++ b/test/lit/passes/precompute-strings.wast
@@ -0,0 +1,26 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+
+;; RUN: wasm-opt %s --precompute --fuzz-exec -all -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (func $eq-no (type $0) (result i32)
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ (func $eq-no (export "eq-no") (result i32)
+ (string.eq
+ (string.const "ab")
+ (string.const "cdefg")
+ )
+ )
+
+ ;; CHECK: (func $eq-yes (type $0) (result i32)
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ (func $eq-yes (export "eq-yes") (result i32)
+ (string.eq
+ (string.const "ab")
+ (string.const "ab")
+ )
+ )
+)
+