[wasm_builder] Remove array.new_data handling in global sections
As of 2025/05/14, `array.new_data` is not a constant instruction, so can't be used in a global initializer. Also, data count section needs to appear right before the code section. Without `array.new_data` we don't need to generate it before the global section. Remove the code related to handling `array.new_data` in global sections. When `array.new_data` becomes constant, we can generate the data count section in its new place always, without having to specially handle it when it's used in a global section. Change-Id: If11824e171d7f21848e82c102f0a4e8257f02c6f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366341 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
committed by
Commit Queue
parent
de68b22e84
commit
0307423810
@@ -10,8 +10,7 @@ class GlobalBuilder extends ir.Global with IndexableBuilder<ir.DefinedGlobal> {
|
||||
|
||||
GlobalBuilder(ModuleBuilder module, super.index, super.type,
|
||||
[super.globalName])
|
||||
: initializer =
|
||||
InstructionsBuilder(module, [type.type], isGlobalInitializer: true);
|
||||
: initializer = InstructionsBuilder(module, [type.type]);
|
||||
|
||||
@override
|
||||
ir.DefinedGlobal forceBuild() =>
|
||||
|
||||
@@ -104,9 +104,6 @@ class InstructionsBuilder with Builder<ir.Instructions> {
|
||||
/// Locals declared in this body, including parameters.
|
||||
final List<ir.Local> locals = [];
|
||||
|
||||
/// Is this the initializer of a global variable?
|
||||
final bool isGlobalInitializer;
|
||||
|
||||
/// Whether a textual trace of the instruction stream should be recorded when
|
||||
/// emitting instructions (provided asserts are enabled).
|
||||
///
|
||||
@@ -143,8 +140,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
|
||||
final Map<ir.Instruction, StackTrace>? _stackTraces;
|
||||
|
||||
/// Create a new instruction sequence.
|
||||
InstructionsBuilder(this.module, List<ir.ValueType> outputs,
|
||||
{this.isGlobalInitializer = false})
|
||||
InstructionsBuilder(this.module, List<ir.ValueType> outputs)
|
||||
: _stackTraces = module.watchPoints.isNotEmpty ? {} : null {
|
||||
_labelStack.add(Expression(const [], outputs));
|
||||
}
|
||||
@@ -1076,7 +1072,6 @@ class InstructionsBuilder with Builder<ir.Instructions> {
|
||||
[ir.RefType.def(arrayType, nullable: false)],
|
||||
trace: ['array.new_data', arrayType, data.index]));
|
||||
_add(ir.ArrayNewData(arrayType, data));
|
||||
if (isGlobalInitializer) module.dataReferencedFromGlobalInitializer = true;
|
||||
}
|
||||
|
||||
/// Emit an `array.copy` instruction.
|
||||
|
||||
@@ -17,7 +17,6 @@ class ModuleBuilder with Builder<ir.Module> {
|
||||
final dataSegments = DataSegmentsBuilder();
|
||||
late final globals = GlobalsBuilder(this);
|
||||
final exports = ExportsBuilder();
|
||||
bool dataReferencedFromGlobalInitializer = false;
|
||||
|
||||
/// Create a new, initially empty, module.
|
||||
///
|
||||
@@ -47,7 +46,6 @@ class ModuleBuilder with Builder<ir.Module> {
|
||||
.followedBy(finalMemories.imported)
|
||||
.followedBy(finalGlobals.imported)
|
||||
.toList(),
|
||||
watchPoints,
|
||||
dataReferencedFromGlobalInitializer);
|
||||
watchPoints);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ class Module implements Serializable {
|
||||
final DataSegments dataSegments;
|
||||
final List<Import> imports;
|
||||
final List<int> watchPoints;
|
||||
final bool dataReferencedFromGlobalInitializer;
|
||||
|
||||
Module(
|
||||
this.functions,
|
||||
@@ -29,8 +28,7 @@ class Module implements Serializable {
|
||||
this.types,
|
||||
this.dataSegments,
|
||||
this.imports,
|
||||
this.watchPoints,
|
||||
this.dataReferencedFromGlobalInitializer);
|
||||
this.watchPoints);
|
||||
|
||||
/// Serialize a module to its binary representation.
|
||||
@override
|
||||
@@ -46,16 +44,11 @@ class Module implements Serializable {
|
||||
TableSection(tables.defined, watchPoints).serialize(s);
|
||||
MemorySection(memories.defined, watchPoints).serialize(s);
|
||||
TagSection(tags.defined, watchPoints).serialize(s);
|
||||
if (dataReferencedFromGlobalInitializer) {
|
||||
DataCountSection(dataSegments.defined, watchPoints).serialize(s);
|
||||
}
|
||||
GlobalSection(globals.defined, watchPoints).serialize(s);
|
||||
ExportSection(exports.exported, watchPoints).serialize(s);
|
||||
StartSection(functions.start, watchPoints).serialize(s);
|
||||
ElementSection(tables.defined, watchPoints).serialize(s);
|
||||
if (!dataReferencedFromGlobalInitializer) {
|
||||
DataCountSection(dataSegments.defined, watchPoints).serialize(s);
|
||||
}
|
||||
DataCountSection(dataSegments.defined, watchPoints).serialize(s);
|
||||
CodeSection(functions.defined, watchPoints).serialize(s);
|
||||
DataSection(dataSegments.defined, watchPoints).serialize(s);
|
||||
if (functions.namedCount > 0 || types.namedCount > 0) {
|
||||
|
||||
Reference in New Issue
Block a user