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

Side by Side Diff: runtime/vm/flow_graph_inliner.cc

Issue 10977075: Don't inline recursive calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
« 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 #include "vm/flow_graph_inliner.h" 5 #include "vm/flow_graph_inliner.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/flow_graph.h" 9 #include "vm/flow_graph.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 10 matching lines...) Expand all
21 DEFINE_FLAG(charp, inlining_filter, NULL, "Inline only in named function"); 21 DEFINE_FLAG(charp, inlining_filter, NULL, "Inline only in named function");
22 DECLARE_FLAG(bool, print_flow_graph); 22 DECLARE_FLAG(bool, print_flow_graph);
23 DECLARE_FLAG(int, deoptimization_counter_threshold); 23 DECLARE_FLAG(int, deoptimization_counter_threshold);
24 24
25 #define TRACE_INLINING(statement) \ 25 #define TRACE_INLINING(statement) \
26 do { \ 26 do { \
27 if (FLAG_trace_inlining) statement; \ 27 if (FLAG_trace_inlining) statement; \
28 } while (false) 28 } while (false)
29 29
30 30
31 // Test if a call is recursive by looking in the deoptimization environment.
32 static bool IsCallRecursive(const Function& function, Definition* call) {
33 Environment* env = call->env();
34 while (env != NULL) {
35 if (function.raw() == env->function().raw()) return true;
36 env = env->outer();
37 }
38 return false;
39 }
40
41
31 class CallSiteInliner : public FlowGraphVisitor { 42 class CallSiteInliner : public FlowGraphVisitor {
32 public: 43 public:
33 explicit CallSiteInliner(FlowGraph* flow_graph) 44 explicit CallSiteInliner(FlowGraph* flow_graph)
34 : FlowGraphVisitor(flow_graph->postorder()), 45 : FlowGraphVisitor(flow_graph->postorder()),
35 caller_graph_(flow_graph), 46 caller_graph_(flow_graph),
36 next_ssa_temp_index_(flow_graph->max_virtual_register_number()), 47 next_ssa_temp_index_(flow_graph->max_virtual_register_number()),
37 inlined_(false) { } 48 inlined_(false) { }
38 49
39 bool TryInlining(const Function& function, 50 bool TryInlining(const Function& function,
40 GrowableArray<Value*>* arguments, 51 GrowableArray<Value*>* arguments,
41 Definition* call) { 52 Definition* call) {
42 TRACE_INLINING(OS::Print(" => %s\n", function.ToCString())); 53 TRACE_INLINING(OS::Print(" => %s\n", function.ToCString()));
43 54
44 // Abort if the inlinable bit on the function is low. 55 // Abort if the inlinable bit on the function is low.
45 if (!function.is_inlinable()) { 56 if (!function.is_inlinable()) {
46 TRACE_INLINING(OS::Print(" Bailout: not inlinable\n")); 57 TRACE_INLINING(OS::Print(" Bailout: not inlinable\n"));
47 return false; 58 return false;
48 } 59 }
49 60
50 // Abort if the callee has optional parameters. 61 // Abort if the callee has optional parameters.
51 if (function.HasOptionalParameters()) { 62 if (function.HasOptionalParameters()) {
52 TRACE_INLINING(OS::Print(" Bailout: optional parameters\n")); 63 TRACE_INLINING(OS::Print(" Bailout: optional parameters\n"));
53 return false; 64 return false;
54 } 65 }
55 66
56 // Assuming no optional parameters the actual/formal count should match. 67 // Assuming no optional parameters the actual/formal count should match.
57 ASSERT(arguments->length() == function.num_fixed_parameters()); 68 ASSERT(arguments->length() == function.num_fixed_parameters());
58 69
70 // Abort if this is a recursive occurrence.
71 if (IsCallRecursive(function, call)) {
72 function.set_is_inlinable(false);
73 TRACE_INLINING(OS::Print(" Bailout: recursive function\n"));
74 return false;
75 }
76
59 // Abort if the callee has an intrinsic translation. 77 // Abort if the callee has an intrinsic translation.
60 if (Intrinsifier::CanIntrinsify(function)) { 78 if (Intrinsifier::CanIntrinsify(function)) {
61 function.set_is_inlinable(false); 79 function.set_is_inlinable(false);
62 TRACE_INLINING(OS::Print(" Bailout: can intrinsify\n")); 80 TRACE_INLINING(OS::Print(" Bailout: can intrinsify\n"));
63 return false; 81 return false;
64 } 82 }
65 83
66 Isolate* isolate = Isolate::Current(); 84 Isolate* isolate = Isolate::Current();
67 // Save and clear IC data. 85 // Save and clear IC data.
68 const Array& prev_ic_data = Array::Handle(isolate->ic_data_array()); 86 const Array& prev_ic_data = Array::Handle(isolate->ic_data_array());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (FLAG_trace_inlining && FLAG_print_flow_graph) { 271 if (FLAG_trace_inlining && FLAG_print_flow_graph) {
254 OS::Print("After Inlining of %s\n", flow_graph_-> 272 OS::Print("After Inlining of %s\n", flow_graph_->
255 parsed_function().function().ToFullyQualifiedCString()); 273 parsed_function().function().ToFullyQualifiedCString());
256 FlowGraphPrinter printer(*flow_graph_); 274 FlowGraphPrinter printer(*flow_graph_);
257 printer.PrintBlocks(); 275 printer.PrintBlocks();
258 } 276 }
259 } 277 }
260 } 278 }
261 279
262 } // namespace dart 280 } // namespace dart
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