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

Side by Side Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 780403003: Remove trivial dead stores during dead code elimination (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 abstract class OptimizationPhase { 7 abstract class OptimizationPhase {
8 String get name; 8 String get name;
9 void visitGraph(HGraph graph); 9 void visitGraph(HGraph graph);
10 } 10 }
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 node, node.receiver, graph.addConstantInt(0, backend.compiler)); 975 node, node.receiver, graph.addConstantInt(0, backend.compiler));
976 } 976 }
977 } 977 }
978 978
979 class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase { 979 class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
980 final String name = "SsaDeadCodeEliminator"; 980 final String name = "SsaDeadCodeEliminator";
981 981
982 final Compiler compiler; 982 final Compiler compiler;
983 final SsaOptimizerTask optimizer; 983 final SsaOptimizerTask optimizer;
984 SsaLiveBlockAnalyzer analyzer; 984 SsaLiveBlockAnalyzer analyzer;
985 Map<HInstruction, bool> trivialDeadStoreReceivers = <HInstruction, bool>{};
floitsch 2014/12/10 20:33:04 Do you think a Map is warranted? maybe just a mapl
sra1 2014/12/10 23:08:47 Done.
985 bool eliminatedSideEffects = false; 986 bool eliminatedSideEffects = false;
986 SsaDeadCodeEliminator(this.compiler, this.optimizer); 987 SsaDeadCodeEliminator(this.compiler, this.optimizer);
987 988
988 HInstruction zapInstructionCache; 989 HInstruction zapInstructionCache;
989 HInstruction get zapInstruction { 990 HInstruction get zapInstruction {
990 if (zapInstructionCache == null) { 991 if (zapInstructionCache == null) {
991 // A constant with no type does not pollute types at phi nodes. 992 // A constant with no type does not pollute types at phi nodes.
992 ConstantValue constant = 993 ConstantValue constant =
993 new DummyConstantValue(const TypeMask.nonNullEmpty()); 994 new DummyConstantValue(const TypeMask.nonNullEmpty());
994 zapInstructionCache = analyzer.graph.addConstant(constant, compiler); 995 zapInstructionCache = analyzer.graph.addConstant(constant, compiler);
(...skipping 20 matching lines...) Expand all
1015 // just jumps to a single predecessor, visit this predecessor. 1016 // just jumps to a single predecessor, visit this predecessor.
1016 assert(current.block.successors.length == 1); 1017 assert(current.block.successors.length == 1);
1017 current = current.block.successors[0].first; 1018 current = current.block.successors[0].first;
1018 } else { 1019 } else {
1019 current = current.next; 1020 current = current.next;
1020 } 1021 }
1021 } while (current != null); 1022 } while (current != null);
1022 return false; 1023 return false;
1023 } 1024 }
1024 1025
1026 bool isTrivialDeadStoreReceiver(HInstruction instruction) {
1027 // For an allocation, if all the loads are dead (awaiting removal after
1028 // SsaLoadElimination) and the only other uses are stores, then the
1029 // allocation does not escape which makes all the stores dead too.
1030 bool isDeadUse(HInstruction use) {
1031 if (use is HFieldSet) {
1032 // The use must be the receiver. If the use is also the argument, i.e.
floitsch 2014/12/10 20:33:04 Even if the use...
sra1 2014/12/10 23:08:47 Done.
1033 // a.x = a, the store is still dead if all other uses are dead.
1034 if (use.getDartReceiver(compiler) == instruction) return true;
1035 } else if (use is HFieldGet) {
1036 assert(use.getDartReceiver(compiler) == instruction);
1037 if (isDeadCode(use)) return true;
1038 }
1039 return false;
1040 }
1041 return instruction is HForeignNew
1042 && trivialDeadStoreReceivers.putIfAbsent(instruction,
1043 () => instruction.usedBy.every(isDeadUse));
1044 }
1045
1046 bool isTrivialDeadStore(HInstruction instruction) {
1047 return instruction is HFieldSet
1048 && isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler));
1049 }
1050
1025 bool isDeadCode(HInstruction instruction) { 1051 bool isDeadCode(HInstruction instruction) {
1026 if (!instruction.usedBy.isEmpty) return false; 1052 if (!instruction.usedBy.isEmpty) return false;
1053 if (isTrivialDeadStore(instruction)) return true;
1027 if (instruction.sideEffects.hasSideEffects()) return false; 1054 if (instruction.sideEffects.hasSideEffects()) return false;
1028 if (instruction.canThrow() 1055 if (instruction.canThrow()
1029 && instruction.onlyThrowsNSM() 1056 && instruction.onlyThrowsNSM()
1030 && hasFollowingThrowingNSM(instruction)) { 1057 && hasFollowingThrowingNSM(instruction)) {
1031 return true; 1058 return true;
1032 } 1059 }
1033 return !instruction.canThrow() 1060 return !instruction.canThrow()
1034 && instruction is !HParameterValue 1061 && instruction is !HParameterValue
1035 && instruction is !HLocalSet; 1062 && instruction is !HLocalSet;
1036 } 1063 }
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 2187
2161 keyedValues.forEach((receiver, values) { 2188 keyedValues.forEach((receiver, values) {
2162 result.keyedValues[receiver] = 2189 result.keyedValues[receiver] =
2163 new Map<HInstruction, HInstruction>.from(values); 2190 new Map<HInstruction, HInstruction>.from(values);
2164 }); 2191 });
2165 2192
2166 result.nonEscapingReceivers.addAll(nonEscapingReceivers); 2193 result.nonEscapingReceivers.addAll(nonEscapingReceivers);
2167 return result; 2194 return result;
2168 } 2195 }
2169 } 2196 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698