Skip to content

Commit 307c3c6

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Implement JS_EMBEDDED_GLOBAL as an instrution.
Usins an SSA instruction defers the generation of a 'modular expression' until codegen, when other modular expressions are generated. This allows JS_EMBEDDED_GLOBAL nodes to be duplicated. Change-Id: I2fded6c85598e475ab61cbd67a449aae59ecb260 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433460 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 6a24c60 commit 307c3c6

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5983,9 +5983,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
59835983
'JS_EMBEDDED_GLOBAL',
59845984
'second ',
59855985
)!;
5986-
js.Template expr = js.js.expressionTemplateYielding(
5987-
_emitter.generateEmbeddedGlobalAccess(globalName),
5988-
);
59895986

59905987
NativeBehavior nativeBehavior = _elementMap
59915988
.getNativeBehaviorForJsEmbeddedGlobalCall(invocation);
@@ -5995,12 +5992,8 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
59955992
closedWorld,
59965993
);
59975994
push(
5998-
HForeignCode(
5999-
expr,
6000-
ssaType,
6001-
const <HInstruction>[],
6002-
nativeBehavior: nativeBehavior,
6003-
)..sourceInformation = sourceInformation,
5995+
HEmbeddedGlobalGet(globalName, nativeBehavior, ssaType)
5996+
..sourceInformation = sourceInformation,
60045997
);
60055998
}
60065999

pkg/compiler/lib/src/ssa/codegen.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,11 @@ class SsaCodeGenerator implements HVisitor<void>, HBlockInformationVisitor {
27802780
registerForeignTypes(node);
27812781
}
27822782

2783+
@override
2784+
void visitEmbeddedGlobalGet(HEmbeddedGlobalGet node) {
2785+
push(_emitter.generateEmbeddedGlobalAccess(node.name));
2786+
}
2787+
27832788
@override
27842789
void visitCreate(HCreate node) {
27852790
js.Expression jsClassReference = _emitter.constructorAccess(node.element);

pkg/compiler/lib/src/ssa/nodes.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ abstract class HVisitor<R> {
5353
R visitCreate(HCreate node);
5454
R visitCreateBox(HCreateBox node);
5555
R visitDivide(HDivide node);
56+
R visitEmbeddedGlobalGet(HEmbeddedGlobalGet node);
5657
R visitExit(HExit node);
5758
R visitExitTry(HExitTry node);
5859
R visitFieldGet(HFieldGet node);
@@ -504,6 +505,8 @@ class HBaseVisitor<R> extends HGraphVisitor implements HVisitor<R> {
504505
@override
505506
R visitDivide(HDivide node) => visitBinaryArithmetic(node);
506507
@override
508+
R visitEmbeddedGlobalGet(HEmbeddedGlobalGet node) => visitInstruction(node);
509+
@override
507510
R visitExit(HExit node) => visitControlFlow(node);
508511
@override
509512
R visitExitTry(HExitTry node) => visitControlFlow(node);
@@ -1137,6 +1140,7 @@ enum _GvnType {
11371140
charCodeAt,
11381141
arrayFlagsGet,
11391142
arrayFlagsCheck,
1143+
embeddedGlobal,
11401144
}
11411145

11421146
abstract class HInstruction implements SpannableWithEntity {
@@ -5114,3 +5118,41 @@ class HIsLateSentinel extends HInstruction {
51145118
@override
51155119
String toString() => 'HIsLateSentinel()';
51165120
}
5121+
5122+
/// Reads an 'embedded global' to access some kind of metadata or value produced
5123+
/// by the compiler.
5124+
///
5125+
/// This instruction corresponds to the `JS_EMBEDDED_GLOBAL` top level method in
5126+
/// `foreign_helper.dart`. The [name] should be a constant defined in the
5127+
/// `_embedded_names` or `_js_shared_embedded_names` library.
5128+
class HEmbeddedGlobalGet extends HInstruction {
5129+
final String name;
5130+
5131+
factory HEmbeddedGlobalGet(
5132+
String name,
5133+
NativeBehavior nativeBehavior,
5134+
AbstractValue type,
5135+
) {
5136+
final node = HEmbeddedGlobalGet._(name, type);
5137+
node.sideEffects.add(nativeBehavior.sideEffects);
5138+
if (nativeBehavior.useGvn) node.setUseGvn();
5139+
return node;
5140+
}
5141+
5142+
HEmbeddedGlobalGet._(this.name, super.type) : super._noInput();
5143+
5144+
@override
5145+
R accept<R>(HVisitor<R> visitor) => visitor.visitEmbeddedGlobalGet(this);
5146+
5147+
@override
5148+
_GvnType get _gvnType => _GvnType.embeddedGlobal;
5149+
5150+
@override
5151+
bool typeEquals(HInstruction other) => other is HEmbeddedGlobalGet;
5152+
5153+
@override
5154+
bool dataEquals(HEmbeddedGlobalGet other) => name == other.name;
5155+
5156+
@override
5157+
String toString() => 'HEmbeddedGlobalGet($name)';
5158+
}

pkg/compiler/lib/src/ssa/tracer.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ class HInstructionStringifier implements HVisitor<String> {
297297
@override
298298
String visitDivide(HDivide node) => handleInvokeBinary(node, 'Divide');
299299

300+
@override
301+
String visitEmbeddedGlobalGet(HEmbeddedGlobalGet node) {
302+
return 'EmbeddedGlobalGet: "${node.name}"';
303+
}
304+
300305
@override
301306
String visitExit(HExit node) => "Exit";
302307

0 commit comments

Comments
 (0)