V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-inlining-heuristic.h
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_JS_INLINING_HEURISTIC_H_
6 #define V8_COMPILER_JS_INLINING_HEURISTIC_H_
7 
8 #include "src/compiler/js-inlining.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13 
14 class JSInliningHeuristic final : public AdvancedReducer {
15  public:
16  enum Mode { kGeneralInlining, kRestrictedInlining, kStressInlining };
17  JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone,
18  OptimizedCompilationInfo* info, JSGraph* jsgraph,
19  JSHeapBroker* broker,
20  SourcePositionTable* source_positions)
21  : AdvancedReducer(editor),
22  mode_(mode),
23  inliner_(editor, local_zone, info, jsgraph, broker, source_positions),
24  candidates_(local_zone),
25  seen_(local_zone),
26  source_positions_(source_positions),
27  jsgraph_(jsgraph) {}
28 
29  const char* reducer_name() const override { return "JSInliningHeuristic"; }
30 
31  Reduction Reduce(Node* node) final;
32 
33  // Processes the list of candidates gathered while the reducer was running,
34  // and inlines call sites that the heuristic determines to be important.
35  void Finalize() final;
36 
37  private:
38  // This limit currently matches what the old compiler did. We may want to
39  // re-evaluate and come up with a proper limit for TurboFan.
40  static const int kMaxCallPolymorphism = 4;
41 
42  struct Candidate {
43  Handle<JSFunction> functions[kMaxCallPolymorphism];
44  // In the case of polymorphic inlining, this tells if each of the
45  // functions could be inlined.
46  bool can_inline_function[kMaxCallPolymorphism];
47  // Strong references to bytecode to ensure it is not flushed from SFI
48  // while choosing inlining candidates.
49  Handle<BytecodeArray> bytecode[kMaxCallPolymorphism];
50  // TODO(2206): For now polymorphic inlining is treated orthogonally to
51  // inlining based on SharedFunctionInfo. This should be unified and the
52  // above array should be switched to SharedFunctionInfo instead. Currently
53  // we use {num_functions == 1 && functions[0].is_null()} as an indicator.
54  Handle<SharedFunctionInfo> shared_info;
55  int num_functions;
56  Node* node = nullptr; // The call site at which to inline.
57  CallFrequency frequency; // Relative frequency of this call site.
58  int total_size = 0;
59  };
60 
61  // Comparator for candidates.
62  struct CandidateCompare {
63  bool operator()(const Candidate& left, const Candidate& right) const;
64  };
65 
66  // Candidates are kept in a sorted set of unique candidates.
68 
69  // Dumps candidates to console.
70  void PrintCandidates();
71  Reduction InlineCandidate(Candidate const& candidate, bool small_function);
72  void CreateOrReuseDispatch(Node* node, Node* callee,
73  Candidate const& candidate, Node** if_successes,
74  Node** calls, Node** inputs, int input_count);
75  bool TryReuseDispatch(Node* node, Node* callee, Candidate const& candidate,
76  Node** if_successes, Node** calls, Node** inputs,
77  int input_count);
78  enum StateCloneMode { kCloneState, kChangeInPlace };
79  Node* DuplicateFrameStateAndRename(Node* frame_state, Node* from, Node* to,
80  StateCloneMode mode);
81  Node* DuplicateStateValuesAndRename(Node* state_values, Node* from, Node* to,
82  StateCloneMode mode);
83 
84  CommonOperatorBuilder* common() const;
85  Graph* graph() const;
86  JSGraph* jsgraph() const { return jsgraph_; }
87  Isolate* isolate() const { return jsgraph_->isolate(); }
88  SimplifiedOperatorBuilder* simplified() const;
89 
90  Mode const mode_;
91  JSInliner inliner_;
92  Candidates candidates_;
93  ZoneSet<NodeId> seen_;
94  SourcePositionTable* source_positions_;
95  JSGraph* const jsgraph_;
96  int cumulative_count_ = 0;
97 };
98 
99 } // namespace compiler
100 } // namespace internal
101 } // namespace v8
102 
103 #endif // V8_COMPILER_JS_INLINING_HEURISTIC_H_
Definition: libplatform.h:13