Skip to content

Commit b6cc8a7

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Remove HInstruction.isControlFlow
Change-Id: I5c0b5a8cf0b5c499d854fd8ce62e3c9c85b7ad5b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403388 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 93621cc commit b6cc8a7

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

pkg/compiler/lib/src/js/js_debug.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ class LenientPrintingContext extends SimpleJavaScriptPrintingContext {
6767
void error(String message) {
6868
buffer.write('>>$message<<');
6969
}
70+
71+
@override
72+
bool get isDebugContext => true;
7073
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ class SsaCodeGenerator implements HVisitor<void>, HBlockInformationVisitor {
774774
}
775775

776776
if (needsAssignment &&
777-
!instruction.isControlFlow() &&
777+
!instruction.isJsStatement() &&
778778
variableNames.hasName(instruction)) {
779779
visitExpression(instruction);
780780
assignVariable(

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ class SsaInstructionMerger extends HBaseVisitor<void> implements CodegenPhase {
10851085
}
10861086

10871087
void tryGenerateAtUseSite(HInstruction instruction) {
1088-
if (instruction.isControlFlow()) return;
1088+
if (instruction.isJsStatement()) return;
10891089
markAsGenerateAtUseSite(instruction);
10901090
}
10911091

@@ -1289,12 +1289,14 @@ class SsaConditionMerger extends HGraphVisitor implements CodegenPhase {
12891289
bool isSafeToGenerateAtUseSite(HInstruction user, HInstruction input) {
12901290
// HCreate evaluates arguments in order and passes them to a constructor.
12911291
if (user is HCreate) return true;
1292+
12921293
// A [HForeign] instruction uses operators and if we generate [input] at use
12931294
// site, the precedence or evaluation order might be wrong.
12941295
if (user is HForeign) return false;
1295-
// A [HCheck] instruction with control flow uses its input
1296+
1297+
// A [HCheck] instruction that is a statement sometimes uses its input
12961298
// multiple times, so we avoid generating it at use site.
1297-
if (user is HCheck && user.isControlFlow()) return false;
1299+
if (user is HCheck && user.isJsStatement()) return false;
12981300

12991301
// A read-modify-write like `o.field += value` reads the field before
13001302
// evaluating the value, so if we generate [input] at the value, the order

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

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,6 @@ abstract class HInstruction implements SpannableWithEntity {
12351235
/// Can this node throw an exception?
12361236
bool canThrow(AbstractValueDomain domain) => false;
12371237

1238-
/// Does this node potentially affect control flow.
1239-
bool isControlFlow() => false;
1240-
12411238
bool isValue(AbstractValueDomain domain) =>
12421239
domain.isPrimitiveValue(instructionType);
12431240

@@ -1477,6 +1474,12 @@ abstract class HInstruction implements SpannableWithEntity {
14771474

14781475
bool isCodeMotionInvariant() => false;
14791476

1477+
/// Returns `true` when this HInstruction might be compiled to a JavaScript
1478+
/// statement, `false` when always compiled to a JavaScript expression.
1479+
///
1480+
/// Some checks are marked as statements even though the generated code is an
1481+
/// expression. This is done when the value of the generated expression does
1482+
/// not correspond to the value of the check (usually one of its inputs).
14801483
bool isJsStatement() => false;
14811484

14821485
bool dominates(HInstruction other) {
@@ -1782,8 +1785,6 @@ class HBoundsCheck extends HCheck {
17821785
// There can be an additional fourth input which is the index to report to
17831786
// [ioore]. This is used by the expansion of [JSArray.removeLast].
17841787
HInstruction get reportedIndex => inputs.length > 3 ? inputs[3] : index;
1785-
@override
1786-
bool isControlFlow() => true;
17871788

17881789
@override
17891790
R accept<R>(HVisitor<R> visitor) => visitor.visitBoundsCheck(this);
@@ -1806,8 +1807,7 @@ abstract class HConditionalBranch extends HControlFlow {
18061807

18071808
abstract class HControlFlow extends HInstruction {
18081809
HControlFlow() : super._noType();
1809-
@override
1810-
bool isControlFlow() => true;
1810+
18111811
@override
18121812
bool isJsStatement() => true;
18131813

@@ -2357,10 +2357,6 @@ class HFieldSet extends HFieldAccess {
23572357
@override
23582358
R accept<R>(HVisitor<R> visitor) => visitor.visitFieldSet(this);
23592359

2360-
// HFieldSet is an expression if it has a user.
2361-
@override
2362-
bool isJsStatement() => usedBy.isEmpty;
2363-
23642360
@override
23652361
String toString() => "FieldSet(element=$element,type=$instructionType)";
23662362
}
@@ -2489,8 +2485,6 @@ class HReadModifyWrite extends HInstruction implements HLateInstruction {
24892485
@override
24902486
R accept<R>(HVisitor<R> visitor) => visitor.visitReadModifyWrite(this);
24912487

2492-
@override
2493-
bool isJsStatement() => isAssignOp;
24942488
@override
24952489
String toString() => "ReadModifyWrite $jsOp $opKind $element";
24962490
}
@@ -2538,8 +2532,6 @@ class HLocalSet extends HLocalAccess {
25382532

25392533
HLocalValue get local => inputs[0] as HLocalValue;
25402534
HInstruction get value => inputs[1];
2541-
@override
2542-
bool isJsStatement() => true;
25432535
}
25442536

25452537
/// Invocation of a native or JS-interop method.
@@ -2699,6 +2691,7 @@ class HForeignCode extends HForeign {
26992691

27002692
@override
27012693
bool isJsStatement() => isStatement;
2694+
27022695
@override
27032696
bool canThrow(AbstractValueDomain domain) {
27042697
if (inputs.isNotEmpty) {
@@ -3648,8 +3641,6 @@ class HStaticStore extends HInstruction {
36483641
bool typeEquals(other) => other is HStaticStore;
36493642
@override
36503643
bool dataEquals(HStaticStore other) => element == other.element;
3651-
@override
3652-
bool isJsStatement() => usedBy.isEmpty;
36533644
}
36543645

36553646
class HLiteralList extends HInstruction {
@@ -3833,8 +3824,6 @@ class HPrimitiveCheck extends HCheck {
38333824

38343825
@override
38353826
bool isJsStatement() => true;
3836-
@override
3837-
bool isControlFlow() => true;
38383827

38393828
@override
38403829
_GvnType get _gvnType => _GvnType.primitiveCheck;
@@ -3919,8 +3908,6 @@ class HNullCheck extends HCheck {
39193908
HNullCheck(super.input, super.type, {this.sticky = false})
39203909
: super._oneInput();
39213910

3922-
@override
3923-
bool isControlFlow() => true;
39243911
@override
39253912
bool isJsStatement() => true;
39263913

@@ -3973,9 +3960,6 @@ abstract class HLateCheck extends HCheck {
39733960
throw StateError('HLateCheck.name: no name');
39743961
}
39753962

3976-
@override
3977-
bool isControlFlow() => true;
3978-
39793963
@override
39803964
bool isCodeMotionInvariant() => false;
39813965
}
@@ -4111,8 +4095,7 @@ class HTypeKnown extends HCheck {
41114095

41124096
@override
41134097
bool isJsStatement() => false;
4114-
@override
4115-
bool isControlFlow() => false;
4098+
41164099
@override
41174100
bool canThrow(AbstractValueDomain domain) => false;
41184101

@@ -5017,7 +5000,7 @@ class HArrayFlagsCheck extends HCheck {
50175000
AbstractValue inputType,
50185001
AbstractValueDomain domain,
50195002
) {
5020-
// TODO(sra): Depening on the checked flags, the output is fixed-length or
5003+
// TODO(sra): Depending on the checked flags, the output is fixed-length or
50215004
// unmodifiable. Refine the type to the degree an AbstractValue can express
50225005
// that.
50235006
return inputType;
@@ -5036,8 +5019,6 @@ class HArrayFlagsCheck extends HCheck {
50365019
@override
50375020
R accept<R>(HVisitor<R> visitor) => visitor.visitArrayFlagsCheck(this);
50385021

5039-
@override
5040-
bool isControlFlow() => true;
50415022
@override
50425023
bool isJsStatement() => true;
50435024

0 commit comments

Comments
 (0)