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

Side by Side Diff: src/compiler/osr.h

Issue 809333002: [turbofan] Implement OSR for outer loops. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/compiler/opcodes.h ('k') | src/compiler/osr.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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_OSR_H_
6 #define V8_COMPILER_OSR_H_
7
8 #include "src/zone.h"
9
10 // TurboFan structures OSR graphs in a way that separates almost all phases of
11 // compilation from OSR implementation details. This is accomplished with
12 // special
13 // control nodes that are added at graph building time. In particular, the graph
14 // is built in such a way that typing still computes the best types and
15 // optimizations and lowering work unchanged. All that remains is to deconstruct
16 // the OSR artifacts before scheduling. The helper class below performs the
17 // necessary graph rewriting.
18
19 // Graphs built for OSR from the AstGraphBuilder are structured as follows:
20 // Start
21 // +-------------------^^-----+
22 // | |
23 // OsrNormalEntry OsrLoopEntry <-------------+
24 // | | |
25 // control flow before loop | A OsrValue
26 // | | | |
27 // | +------------------------+ | +-------+
28 // | | +-------------+ | | +--------+
29 // | | | | | | | |
30 // ( Loop )<-----------|------------------ ( phi ) |
31 // | | |
32 // loop body | backedge(s) |
33 // | | | |
34 // | +--------------+ B <-----+
35 // |
36 // end
37
38 // The control structure expresses the relationship that the loop has a separate
39 // entrypoint which corresponds to entering the loop directly from start.
40 // Similarly, the values that come in from unoptimized code are represented with
41 // {OsrValue} nodes that merge into any phis associated with the OSR loop.
42 // The nodes {A} and {B} represent values in the "normal" graph that correspond
43 // to the values of those phis before the loop and on any backedges,
44 // respectively.
45
46 // To deconstruct OSR, we simply replace the uses of the {OsrNormalEntry}
47 // control
48 // node with {Dead} and {OsrLoopEntry} with start and run the {ControlReducer}.
49 // Control reduction propagates the dead control forward, essentially "killing"
50 // all the code before the OSR loop. The entrypoint to the loop corresponding
51 // to the "normal" entry path will also be removed, as well as the inputs to
52 // the loop phis, resulting in the reduced graph:
53
54 // Start
55 // Dead |^-------------------------+
56 // | | |
57 // | | |
58 // | | |
59 // disconnected, dead | A=dead OsrValue
60 // | |
61 // +------------------+ +------+
62 // | +-------------+ | +--------+
63 // | | | | | |
64 // ( Loop )<-----------|------------------ ( phi ) |
65 // | | |
66 // loop body | backedge(s) |
67 // | | | |
68 // | +--------------+ B <-----+
69 // |
70 // end
71
72 // Other than the presences of the OsrValue nodes, this is a normal, schedulable
73 // graph. OsrValue nodes are handled specially in the instruction selector to
74 // simply load from the unoptimized frame.
75
76 // For nested OSR loops, loop peeling must first be applied as many times as
77 // necessary in order to bring the OSR loop up to the top level (i.e. to be
78 // an outer loop).
79
80 namespace v8 {
81 namespace internal {
82
83 class CompilationInfo;
84
85 namespace compiler {
86
87 class JSGraph;
88 class CommonOperatorBuilder;
89 class Frame;
90 class Linkage;
91
92 // Encapsulates logic relating to OSR compilations as well has handles some
93 // details of the frame layout.
94 class OsrHelper {
95 public:
96 explicit OsrHelper(CompilationInfo* info);
97 // Only for testing.
98 OsrHelper(size_t parameter_count, size_t stack_slot_count)
99 : parameter_count_(parameter_count),
100 stack_slot_count_(stack_slot_count) {}
101
102 // Deconstructs the artificial {OsrNormalEntry} and rewrites the graph so
103 // that only the path corresponding to {OsrLoopEntry} remains.
104 void Deconstruct(JSGraph* jsgraph, CommonOperatorBuilder* common,
105 Zone* tmp_zone);
106
107 // Prepares the frame w.r.t. OSR.
108 void SetupFrame(Frame* frame);
109
110 // Returns the number of unoptimized frame slots for this OSR.
111 size_t UnoptimizedFrameSlots() { return stack_slot_count_; }
112
113 // Returns the environment index of the first stack slot.
114 static int FirstStackSlotIndex(int parameter_count) {
115 // n.b. unlike Crankshaft, TurboFan environments do not contain the context.
116 return 1 + parameter_count; // receiver + params
117 }
118
119 private:
120 size_t parameter_count_;
121 size_t stack_slot_count_;
122 };
123
124 } // namespace compiler
125 } // namespace internal
126 } // namespace v8
127
128 #endif // V8_COMPILER_OSR_H_
OLDNEW
« no previous file with comments | « src/compiler/opcodes.h ('k') | src/compiler/osr.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698