Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: lib/compiler/implementation/ssa/nodes.dart

Issue 10383062: Avoid inserting new temporaries because of HTypeConversion nodes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 interface HVisitor<R> { 5 interface HVisitor<R> {
6 R visitAdd(HAdd node); 6 R visitAdd(HAdd node);
7 R visitBitAnd(HBitAnd node); 7 R visitBitAnd(HBitAnd node);
8 R visitBitNot(HBitNot node); 8 R visitBitNot(HBitNot node);
9 R visitBitOr(HBitOr node); 9 R visitBitOr(HBitOr node);
10 R visitBitXor(HBitXor node); 10 R visitBitXor(HBitXor node);
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 validator.visitInstruction(this); 923 validator.visitInstruction(this);
924 return validator.isValid; 924 return validator.isValid;
925 } 925 }
926 926
927 /** 927 /**
928 * The code for computing a bailout environment, and the code 928 * The code for computing a bailout environment, and the code
929 * generation must agree on what does not need to be captured, 929 * generation must agree on what does not need to be captured,
930 * so should always be generated at use site. 930 * so should always be generated at use site.
931 */ 931 */
932 bool isCodeMotionInvariant() => false; 932 bool isCodeMotionInvariant() => false;
933
934 /**
935 * Returns whether this instruction produces the same value as its
936 * input.
937 */
938 bool returnsInput() => false;
Lasse Reichstein Nielsen 2012/05/08 12:39:08 returnsSingleInput? Isn't our behavior here a lit
ngeoffray 2012/05/08 16:09:12 As discussed, to get the dependencies right. The c
939 HInstruction get input() => null;
ngeoffray 2012/05/08 11:17:51 I could instead add a common super class for instr
Lasse Reichstein Nielsen 2012/05/08 12:39:08 What's the "input" getter for? Add comment, especi
floitsch 2012/05/08 13:21:42 I would prefer a common superclass or alternativel
ngeoffray 2012/05/08 16:09:12 I'm now using HCheck as the superclass of all thes
933 } 940 }
934 941
935 class HBoolify extends HInstruction { 942 class HBoolify extends HInstruction {
936 HBoolify(HInstruction value) : super(<HInstruction>[value]); 943 HBoolify(HInstruction value) : super(<HInstruction>[value]);
937 void prepareGvn() { 944 void prepareGvn() {
938 assert(!hasSideEffects()); 945 assert(!hasSideEffects());
939 setUseGvn(); 946 setUseGvn();
940 } 947 }
941 948
942 HType get guaranteedType() => HType.BOOLEAN; 949 HType get guaranteedType() => HType.BOOLEAN;
943 950
944 accept(HVisitor visitor) => visitor.visitBoolify(this); 951 accept(HVisitor visitor) => visitor.visitBoolify(this);
945 int typeCode() => 0; 952 int typeCode() => 0;
946 bool typeEquals(other) => other is HBoolify; 953 bool typeEquals(other) => other is HBoolify;
947 bool dataEquals(HInstruction other) => true; 954 bool dataEquals(HInstruction other) => true;
948 } 955 }
949 956
950 class HCheck extends HInstruction { 957 class HCheck extends HInstruction {
951 HCheck(inputs) : super(inputs); 958 HCheck(inputs) : super(inputs);
952 959
953 // TODO(floitsch): make class abstract instead of adding an abstract method. 960 // TODO(floitsch): make class abstract instead of adding an abstract method.
954 abstract accept(HVisitor visitor); 961 abstract accept(HVisitor visitor);
955 962
963 HInstruction get input() => inputs[0];
956 bool isControlFlow() => true; 964 bool isControlFlow() => true;
965 bool returnsInput() => true;
957 } 966 }
958 967
959 class HTypeGuard extends HInstruction { 968 class HTypeGuard extends HInstruction {
960 final int state; 969 final int state;
961 final HType guardedType; 970 final HType guardedType;
962 bool isOn = false; 971 bool isOn = false;
963 HTypeGuard(this.guardedType, this.state, List<HInstruction> env) : super(env); 972 HTypeGuard(this.guardedType, this.state, List<HInstruction> env) : super(env);
964 973
965 void prepareGvn() { 974 void prepareGvn() {
966 assert(!hasSideEffects()); 975 assert(!hasSideEffects());
967 setUseGvn(); 976 setUseGvn();
968 } 977 }
969 978
970 HInstruction get guarded() => inputs.last(); 979 HInstruction get guarded() => inputs.last();
980 HInstruction get input() => guarded;
971 981
Lasse Reichstein Nielsen 2012/05/08 12:39:08 Could you put the new methods in a somewhat consis
972 HType computeTypeFromInputTypes() { 982 HType computeTypeFromInputTypes() {
973 return isOn ? guardedType : guarded.propagatedType; 983 return isOn ? guardedType : guarded.propagatedType;
974 } 984 }
975 985
976 HType get guaranteedType() => isOn ? guardedType : HType.UNKNOWN; 986 HType get guaranteedType() => isOn ? guardedType : HType.UNKNOWN;
977 987
978 bool isControlFlow() => true; 988 bool isControlFlow() => true;
989 bool returnsInput() => true;
979 990
980 accept(HVisitor visitor) => visitor.visitTypeGuard(this); 991 accept(HVisitor visitor) => visitor.visitTypeGuard(this);
981 int typeCode() => 1; 992 int typeCode() => 1;
982 bool typeEquals(other) => other is HTypeGuard; 993 bool typeEquals(other) => other is HTypeGuard;
983 bool dataEquals(HTypeGuard other) => guardedType == other.guardedType; 994 bool dataEquals(HTypeGuard other) => guardedType == other.guardedType;
984 } 995 }
985 996
986 class HBoundsCheck extends HCheck { 997 class HBoundsCheck extends HCheck {
987 static final int ALWAYS_FALSE = 0; 998 static final int ALWAYS_FALSE = 0;
988 static final int FULL_CHECK = 1; 999 static final int FULL_CHECK = 1;
989 static final int ALWAYS_ABOVE_ZERO = 2; 1000 static final int ALWAYS_ABOVE_ZERO = 2;
990 static final int ALWAYS_TRUE = 3; 1001 static final int ALWAYS_TRUE = 3;
991 /** 1002 /**
992 * Details which tests have been done statically during compilation. 1003 * Details which tests have been done statically during compilation.
993 * Default is that all checks must be performed dynamically. 1004 * Default is that all checks must be performed dynamically.
994 */ 1005 */
995 int staticChecks = FULL_CHECK; 1006 int staticChecks = FULL_CHECK;
996 1007
997 HBoundsCheck(length, index) : super(<HInstruction>[length, index]); 1008 HBoundsCheck(length, index) : super(<HInstruction>[length, index]);
998 1009
999 HInstruction get length() => inputs[0]; 1010 HInstruction get length() => inputs[1];
1000 HInstruction get index() => inputs[1]; 1011 HInstruction get index() => inputs[0];
1001 1012
1002 void prepareGvn() { 1013 void prepareGvn() {
1003 assert(!hasSideEffects()); 1014 assert(!hasSideEffects());
1004 setUseGvn(); 1015 setUseGvn();
1005 } 1016 }
1006 1017
1007 HType get guaranteedType() => HType.INTEGER; 1018 HType get guaranteedType() => HType.INTEGER;
1008 1019
1009 accept(HVisitor visitor) => visitor.visitBoundsCheck(this); 1020 accept(HVisitor visitor) => visitor.visitBoundsCheck(this);
1010 int typeCode() => 2; 1021 int typeCode() => 2;
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 HTypeConversion(HType this.type, 2162 HTypeConversion(HType this.type,
2152 HInstruction input, 2163 HInstruction input,
2153 [bool this.checked = false]) 2164 [bool this.checked = false])
2154 : super(<HInstruction>[input]) { 2165 : super(<HInstruction>[input]) {
2155 sourceElement = input.sourceElement; 2166 sourceElement = input.sourceElement;
2156 } 2167 }
2157 2168
2158 HType get guaranteedType() => type; 2169 HType get guaranteedType() => type;
2159 2170
2160 accept(HVisitor visitor) => visitor.visitTypeConversion(this); 2171 accept(HVisitor visitor) => visitor.visitTypeConversion(this);
2172
2173 HInstruction get input() => inputs[0];
2174 bool returnsInput() => true;
2175 bool hasSideEffects() => checked;
2161 } 2176 }
2162 2177
2163 /** 2178 /**
2164 * Information about a syntactic-like structure that can be attached 2179 * Information about a syntactic-like structure that can be attached
2165 * to a [HBasicBlock]. 2180 * to a [HBasicBlock].
2166 */ 2181 */
2167 interface HBlockInformation { 2182 interface HBlockInformation {
2168 HBasicBlock get start(); 2183 HBasicBlock get start();
2169 HBasicBlock get end(); 2184 HBasicBlock get end();
2170 bool accept(HBlockInformationVisitor visitor); 2185 bool accept(HBlockInformationVisitor visitor);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 this.finallyBlock, 2420 this.finallyBlock,
2406 this.joinBlock); 2421 this.joinBlock);
2407 2422
2408 HBasicBlock get start() => body.start; 2423 HBasicBlock get start() => body.start;
2409 HBasicBlock get end() => 2424 HBasicBlock get end() =>
2410 finallyBlock === null ? catchBlock.end : finallyBlock.end; 2425 finallyBlock === null ? catchBlock.end : finallyBlock.end;
2411 2426
2412 bool accept(HStatementInformationVisitor visitor) => 2427 bool accept(HStatementInformationVisitor visitor) =>
2413 visitor.visitTryInfo(this); 2428 visitor.visitTryInfo(this);
2414 } 2429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698