OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_JS_INLINING_HEURISTIC_H_ | 5 #ifndef V8_COMPILER_JS_INLINING_HEURISTIC_H_ |
6 #define V8_COMPILER_JS_INLINING_HEURISTIC_H_ | 6 #define V8_COMPILER_JS_INLINING_HEURISTIC_H_ |
7 | 7 |
8 #include "src/compiler/js-inlining.h" | 8 #include "src/compiler/js-inlining.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace compiler { | 12 namespace compiler { |
13 | 13 |
14 class JSInliningHeuristic final : public AdvancedReducer { | 14 class JSInliningHeuristic final : public AdvancedReducer { |
15 public: | 15 public: |
16 enum Mode { kGeneralInlining, kRestrictedInlining, kStressInlining }; | 16 enum Mode { kGeneralInlining, kRestrictedInlining, kStressInlining }; |
17 JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone, | 17 JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone, |
18 CompilationInfo* info, JSGraph* jsgraph) | 18 CompilationInfo* info, JSGraph* jsgraph) |
19 : AdvancedReducer(editor), | 19 : AdvancedReducer(editor), |
20 mode_(mode), | 20 mode_(mode), |
21 inliner_(editor, local_zone, info, jsgraph), | 21 inliner_(editor, local_zone, info, jsgraph), |
22 candidates_(local_zone), | 22 candidates_(local_zone), |
23 seen_(local_zone), | 23 seen_(local_zone), |
24 info_(info) {} | 24 jsgraph_(jsgraph) {} |
25 | 25 |
26 Reduction Reduce(Node* node) final; | 26 Reduction Reduce(Node* node) final; |
27 | 27 |
28 // Processes the list of candidates gathered while the reducer was running, | 28 // Processes the list of candidates gathered while the reducer was running, |
29 // and inlines call sites that the heuristic determines to be important. | 29 // and inlines call sites that the heuristic determines to be important. |
30 void Finalize() final; | 30 void Finalize() final; |
31 | 31 |
32 private: | 32 private: |
| 33 // This limit currently matches what Crankshaft does. We may want to |
| 34 // re-evaluate and come up with a proper limit for TurboFan. |
| 35 static const int kMaxCallPolymorphism = 4; |
| 36 |
33 struct Candidate { | 37 struct Candidate { |
34 Handle<JSFunction> function; // The call target being inlined. | 38 Handle<JSFunction> functions[kMaxCallPolymorphism]; |
35 Node* node; // The call site at which to inline. | 39 int num_functions; |
36 int calls; // Number of times the call site was hit. | 40 Node* node = nullptr; // The call site at which to inline. |
| 41 int calls = -1; // Number of times the call site was hit. |
37 }; | 42 }; |
38 | 43 |
39 // Comparator for candidates. | 44 // Comparator for candidates. |
40 struct CandidateCompare { | 45 struct CandidateCompare { |
41 bool operator()(const Candidate& left, const Candidate& right) const; | 46 bool operator()(const Candidate& left, const Candidate& right) const; |
42 }; | 47 }; |
43 | 48 |
44 // Candidates are kept in a sorted set of unique candidates. | 49 // Candidates are kept in a sorted set of unique candidates. |
45 typedef ZoneSet<Candidate, CandidateCompare> Candidates; | 50 typedef ZoneSet<Candidate, CandidateCompare> Candidates; |
46 | 51 |
47 // Dumps candidates to console. | 52 // Dumps candidates to console. |
48 void PrintCandidates(); | 53 void PrintCandidates(); |
| 54 Reduction InlineCandidate(Candidate const& candidate); |
| 55 |
| 56 CommonOperatorBuilder* common() const; |
| 57 Graph* graph() const; |
| 58 JSGraph* jsgraph() const { return jsgraph_; } |
| 59 SimplifiedOperatorBuilder* simplified() const; |
49 | 60 |
50 Mode const mode_; | 61 Mode const mode_; |
51 JSInliner inliner_; | 62 JSInliner inliner_; |
52 Candidates candidates_; | 63 Candidates candidates_; |
53 ZoneSet<NodeId> seen_; | 64 ZoneSet<NodeId> seen_; |
54 CompilationInfo* info_; | 65 JSGraph* const jsgraph_; |
55 int cumulative_count_ = 0; | 66 int cumulative_count_ = 0; |
56 }; | 67 }; |
57 | 68 |
58 } // namespace compiler | 69 } // namespace compiler |
59 } // namespace internal | 70 } // namespace internal |
60 } // namespace v8 | 71 } // namespace v8 |
61 | 72 |
62 #endif // V8_COMPILER_JS_INLINING_HEURISTIC_H_ | 73 #endif // V8_COMPILER_JS_INLINING_HEURISTIC_H_ |
OLD | NEW |