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

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

Issue 10827181: Collect call site information and use that for estimating parameter types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 4 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) 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 } 132 }
133 133
134 class SsaBuilderTask extends CompilerTask { 134 class SsaBuilderTask extends CompilerTask {
135 final Interceptors interceptors; 135 final Interceptors interceptors;
136 final Map<Node, ClosureData> closureDataCache; 136 final Map<Node, ClosureData> closureDataCache;
137 final CodeEmitterTask emitter; 137 final CodeEmitterTask emitter;
138 // Loop tracking information. 138 // Loop tracking information.
139 final Set<FunctionElement> functionsCalledInLoop; 139 final Set<FunctionElement> functionsCalledInLoop;
140 final Map<SourceString, Selector> selectorsCalledInLoop; 140 final Map<SourceString, Selector> selectorsCalledInLoop;
141 final JavaScriptBackend backend;
141 142
142 String get name() => 'SSA builder'; 143 String get name() => 'SSA builder';
143 144
144 SsaBuilderTask(JavaScriptBackend backend) 145 SsaBuilderTask(JavaScriptBackend backend)
145 : interceptors = new Interceptors(backend.compiler), 146 : interceptors = new Interceptors(backend.compiler),
146 closureDataCache = new HashMap<Node, ClosureData>(), 147 closureDataCache = new HashMap<Node, ClosureData>(),
147 emitter = backend.emitter, 148 emitter = backend.emitter,
148 functionsCalledInLoop = new Set<FunctionElement>(), 149 functionsCalledInLoop = new Set<FunctionElement>(),
149 selectorsCalledInLoop = new Map<SourceString, Selector>(), 150 selectorsCalledInLoop = new Map<SourceString, Selector>(),
151 backend = backend,
150 super(backend.compiler); 152 super(backend.compiler);
151 153
152 HGraph build(WorkItem work) { 154 HGraph build(WorkItem work) {
153 return measure(() { 155 return measure(() {
154 FunctionElement element = work.element; 156 FunctionElement element = work.element;
155 HInstruction.idCounter = 0; 157 HInstruction.idCounter = 0;
156 SsaBuilder builder = new SsaBuilder(this, work); 158 SsaBuilder builder = new SsaBuilder(this, work);
157 HGraph graph; 159 HGraph graph;
158 ElementKind kind = element.kind; 160 ElementKind kind = element.kind;
159 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 161 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
160 graph = compileConstructor(builder, work); 162 graph = compileConstructor(builder, work);
161 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || 163 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY ||
162 kind === ElementKind.FUNCTION || 164 kind === ElementKind.FUNCTION ||
163 kind === ElementKind.GETTER || 165 kind === ElementKind.GETTER ||
164 kind === ElementKind.SETTER) { 166 kind === ElementKind.SETTER) {
165 graph = builder.buildMethod(work.element); 167 graph = builder.buildMethod(work.element);
166 } 168 }
167 assert(graph.isValid()); 169 assert(graph.isValid());
168 bool inLoop = functionsCalledInLoop.contains(element); 170 bool inLoop = functionsCalledInLoop.contains(element);
169 if (!inLoop) { 171 if (!inLoop) {
170 Selector selector = selectorsCalledInLoop[element.name]; 172 Selector selector = selectorsCalledInLoop[element.name];
171 inLoop = selector !== null && selector.applies(element, compiler); 173 inLoop = selector !== null && selector.applies(element, compiler);
172 } 174 }
173 graph.calledInLoop = inLoop; 175 graph.calledInLoop = inLoop;
176
177 // If there is an estimate of the parameter types assume these types when
178 // compiling.
179 List<HType> parameterTypes =
180 backend.optimisticParameterTypesWithRecompilationOnTypeChange(
181 element);
182 if (parameterTypes != null) {
183 FunctionSignature signature = element.computeSignature(compiler);
184 int i = 0;
185 signature.forEachParameter((Element param) {
186 builder.parameters[param].guaranteedType = parameterTypes[i++];
187 });
188 }
189
174 if (compiler.tracer.enabled) { 190 if (compiler.tracer.enabled) {
175 String name; 191 String name;
176 if (element.enclosingElement !== null && 192 if (element.enclosingElement !== null &&
177 element.enclosingElement.kind == ElementKind.CLASS) { 193 element.enclosingElement.kind == ElementKind.CLASS) {
178 String className = element.enclosingElement.name.slowToString(); 194 String className = element.enclosingElement.name.slowToString();
179 String memberName = element.name.slowToString(); 195 String memberName = element.name.slowToString();
180 name = "$className.$memberName"; 196 name = "$className.$memberName";
181 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { 197 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
182 name = "$name (body)"; 198 name = "$name (body)";
183 } 199 }
(...skipping 3401 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 new HSubGraphBlockInformation(elseBranch.graph)); 3601 new HSubGraphBlockInformation(elseBranch.graph));
3586 3602
3587 HBasicBlock conditionStartBlock = conditionBranch.block; 3603 HBasicBlock conditionStartBlock = conditionBranch.block;
3588 conditionStartBlock.setBlockFlow(info, joinBlock); 3604 conditionStartBlock.setBlockFlow(info, joinBlock);
3589 SubGraph conditionGraph = conditionBranch.graph; 3605 SubGraph conditionGraph = conditionBranch.graph;
3590 HIf branch = conditionGraph.end.last; 3606 HIf branch = conditionGraph.end.last;
3591 assert(branch is HIf); 3607 assert(branch is HIf);
3592 branch.blockInformation = conditionStartBlock.blockFlow; 3608 branch.blockInformation = conditionStartBlock.blockFlow;
3593 } 3609 }
3594 } 3610 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698