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

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

Issue 11975049: Allowing inlining of static getters and methods in a different library. Also report an error if a g… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 part of ssa; 5 part of ssa;
6 6
7 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 * Documentation wanted -- johnniwinther 1158 * Documentation wanted -- johnniwinther
1159 */ 1159 */
1160 bool tryInlineMethod(Element element, 1160 bool tryInlineMethod(Element element,
1161 Selector selector, 1161 Selector selector,
1162 Link<Node> arguments) { 1162 Link<Node> arguments) {
1163 if (compiler.disableInlining) return false; 1163 if (compiler.disableInlining) return false;
1164 // Ensure that [element] is an implementation element. 1164 // Ensure that [element] is an implementation element.
1165 element = element.implementation; 1165 element = element.implementation;
1166 // TODO(floitsch): we should be able to inline inside lazy initializers. 1166 // TODO(floitsch): we should be able to inline inside lazy initializers.
1167 if (!currentElement.isFunction()) return false; 1167 if (!currentElement.isFunction()) return false;
1168 // TODO(floitsch): we should be able to inline getters, setters and
1169 // constructor bodies.
1170 if (!element.isFunction()) return false;
1171 // TODO(floitsch): find a cleaner way to know if the element is a function 1168 // TODO(floitsch): find a cleaner way to know if the element is a function
1172 // containing nodes. 1169 // containing nodes.
1173 // [PartialFunctionElement]s are [FunctionElement]s that have [Node]s. 1170 // [PartialFunctionElement]s are [FunctionElement]s that have [Node]s.
1174 if (element is !PartialFunctionElement) return false; 1171 if (element is !PartialFunctionElement) return false;
1175 if (inliningStack.length > MAX_INLINING_DEPTH) return false; 1172 if (inliningStack.length > MAX_INLINING_DEPTH) return false;
1176 // Don't inline recursive calls. We use the same elements for the inlined 1173 // Don't inline recursive calls. We use the same elements for the inlined
1177 // functions and would thus clobber our local variables. 1174 // functions and would thus clobber our local variables.
1178 // Use [:element.declaration:] since [work.element] is always a declaration. 1175 // Use [:element.declaration:] since [work.element] is always a declaration.
1179 if (work.element == element.declaration) return false; 1176 if (work.element == element.declaration) return false;
1180 for (int i = 0; i < inliningStack.length; i++) { 1177 for (int i = 0; i < inliningStack.length; i++) {
1181 if (inliningStack[i].function == element) return false; 1178 if (inliningStack[i].function == element) return false;
1182 } 1179 }
1183 // TODO(ngeoffray): Inlining currently does not work in the presence of
1184 // private calls.
1185 if (currentLibrary != element.getLibrary()) return false;
1186 PartialFunctionElement function = element; 1180 PartialFunctionElement function = element;
1187 int sourceSize = 1181 int sourceSize =
1188 function.endToken.charOffset - function.beginToken.charOffset; 1182 function.endToken.charOffset - function.beginToken.charOffset;
1189 if (sourceSize > MAX_INLINING_SOURCE_SIZE) return false; 1183 if (sourceSize > MAX_INLINING_SOURCE_SIZE) return false;
1190 if (!selector.applies(function, compiler)) return false; 1184 if (!selector.applies(function, compiler)) return false;
1191 FunctionExpression functionExpression = function.parseNode(compiler); 1185 FunctionExpression functionExpression = function.parseNode(compiler);
1192 TreeElements newElements = 1186 TreeElements newElements =
1193 compiler.enqueuer.resolution.getCachedElements(function); 1187 compiler.enqueuer.resolution.getCachedElements(function);
1194 if (newElements == null) { 1188 if (newElements == null) {
1195 compiler.internalError("Element not resolved: $function"); 1189 compiler.internalError("Element not resolved: $function");
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 if (element.isField() && !element.isAssignable()) { 2462 if (element.isField() && !element.isAssignable()) {
2469 // A static final or const. Get its constant value and inline it if 2463 // A static final or const. Get its constant value and inline it if
2470 // the value can be compiled eagerly. 2464 // the value can be compiled eagerly.
2471 value = compileVariable(element); 2465 value = compileVariable(element);
2472 } 2466 }
2473 if (value != null) { 2467 if (value != null) {
2474 stack.add(graph.addConstant(value)); 2468 stack.add(graph.addConstant(value));
2475 } else if (element.isField() && isLazilyInitialized(element)) { 2469 } else if (element.isField() && isLazilyInitialized(element)) {
2476 push(new HLazyStatic(element)); 2470 push(new HLazyStatic(element));
2477 } else { 2471 } else {
2472 if (element.isGetter()) {
2473 Selector selector = elements.getSelector(send);
2474 if (tryInlineMethod(element, selector, const Link<Node>())) {
2475 return;
2476 }
2477 }
2478 // TODO(5346): Try to avoid the need for calling [declaration] before 2478 // TODO(5346): Try to avoid the need for calling [declaration] before
2479 // creating an [HStatic]. 2479 // creating an [HStatic].
2480 push(new HStatic(element.declaration)); 2480 push(new HStatic(element.declaration));
2481 if (element.isGetter()) { 2481 if (element.isGetter()) {
2482 push(new HInvokeStatic(<HInstruction>[pop()])); 2482 push(new HInvokeStatic(<HInstruction>[pop()]));
2483 } 2483 }
2484 } 2484 }
2485 } else if (Elements.isInstanceSend(send, elements)) { 2485 } else if (Elements.isInstanceSend(send, elements)) {
2486 HInstruction receiver = generateInstanceSendReceiver(send); 2486 HInstruction receiver = generateInstanceSendReceiver(send);
2487 generateInstanceGetterWithCompiledReceiver(send, receiver); 2487 generateInstanceGetterWithCompiledReceiver(send, receiver);
(...skipping 2607 matching lines...) Expand 10 before | Expand all | Expand 10 after
5095 new HSubGraphBlockInformation(elseBranch.graph)); 5095 new HSubGraphBlockInformation(elseBranch.graph));
5096 5096
5097 HBasicBlock conditionStartBlock = conditionBranch.block; 5097 HBasicBlock conditionStartBlock = conditionBranch.block;
5098 conditionStartBlock.setBlockFlow(info, joinBlock); 5098 conditionStartBlock.setBlockFlow(info, joinBlock);
5099 SubGraph conditionGraph = conditionBranch.graph; 5099 SubGraph conditionGraph = conditionBranch.graph;
5100 HIf branch = conditionGraph.end.last; 5100 HIf branch = conditionGraph.end.last;
5101 assert(branch is HIf); 5101 assert(branch is HIf);
5102 branch.blockInformation = conditionStartBlock.blockFlow; 5102 branch.blockInformation = conditionStartBlock.blockFlow;
5103 } 5103 }
5104 } 5104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698