[dart2wasm] Allocate boxed bools once

When boxing bool values use cached values for true and false and avoid
allocating new boxes for bools.

Converts code like the following to allocate a boxed bool object, e.g.
in `dartifyRaw`:

    ;; bool value on stack
    local.set $var6         ;; save bool value
    i32.const 3             ;; class id
    local.get $var6         ;; get bool value
    struct.new $BoxedBool

Into:

    ;; bool value on stack
    if
      global.get $global922
    else
      global.get $global924
    end

Change-Id: Iec19d6d0d42bfe39804a6487a7ed6b53bf63b5a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382382
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Ömer Sinan Ağacan
2024-09-05 11:24:10 +00:00
committed by Ömer Ağacan
parent d7a39788d4
commit d7a283de26
+13 -1
View File
@@ -875,8 +875,20 @@ class Translator with KernelNodes {
}
} else if (to is w.RefType) {
// Boxing
ClassInfo info = classInfo[boxedClasses[from]!]!;
Class cls = boxedClasses[from]!;
ClassInfo info = classInfo[cls]!;
assert(info.struct.isSubtypeOf(to.heapType));
if (cls == boxedBoolClass) {
final constantType = w.RefType(info.struct, nullable: false);
b.if_([], [constantType]);
constants.instantiateConstant(b, BoolConstant(true), constantType);
b.else_();
constants.instantiateConstant(b, BoolConstant(false), constantType);
b.end();
return;
}
w.Local temp = b.addLocal(from);
b.local_set(temp);
b.i32_const(info.classId);