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

Side by Side Diff: src/compiler/common-operator.h

Issue 565753004: [turbofan] Some common operators are globally shared singletons. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes2 Created 6 years, 3 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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_COMMON_OPERATOR_H_ 5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_
6 #define V8_COMPILER_COMMON_OPERATOR_H_ 6 #define V8_COMPILER_COMMON_OPERATOR_H_
7 7
8 #include "src/assembler.h"
9 #include "src/compiler/linkage.h"
10 #include "src/compiler/machine-type.h" 8 #include "src/compiler/machine-type.h"
11 #include "src/compiler/opcodes.h"
12 #include "src/compiler/operator.h"
13 #include "src/unique.h"
14 9
15 namespace v8 { 10 namespace v8 {
16 namespace internal { 11 namespace internal {
17 12
13 // Forward declarations.
14 class ExternalReference;
18 class OStream; 15 class OStream;
16 template <typename>
17 class Unique;
18 class Zone;
19
19 20
20 namespace compiler { 21 namespace compiler {
21 22
22 class ControlOperator FINAL : public Operator1<int> { 23 // Forward declarations.
23 public: 24 class CallDescriptor;
24 ControlOperator(IrOpcode::Value opcode, Properties properties, int inputs, 25 struct CommonOperatorBuilderImpl;
25 int outputs, int controls, const char* mnemonic) 26 class Operator;
26 : Operator1<int>(opcode, properties, inputs, outputs, mnemonic,
27 controls) {}
28 27
29 virtual OStream& PrintParameter(OStream& os) const OVERRIDE { // NOLINT
30 return os;
31 }
32 int ControlInputCount() const { return parameter(); }
33 };
34
35 class CallOperator FINAL : public Operator1<CallDescriptor*> {
36 public:
37 // TODO(titzer): Operator still uses int, whereas CallDescriptor uses size_t.
38 CallOperator(CallDescriptor* descriptor, const char* mnemonic)
39 : Operator1<CallDescriptor*>(
40 IrOpcode::kCall, descriptor->properties(),
41 static_cast<int>(descriptor->InputCount() +
42 descriptor->FrameStateCount()),
43 static_cast<int>(descriptor->ReturnCount()), mnemonic, descriptor) {
44 }
45
46 virtual OStream& PrintParameter(OStream& os) const OVERRIDE { // NOLINT
47 return os << "[" << *parameter() << "]";
48 }
49 };
50 28
51 // Flag that describes how to combine the current environment with 29 // Flag that describes how to combine the current environment with
52 // the output of a node to obtain a framestate for lazy bailout. 30 // the output of a node to obtain a framestate for lazy bailout.
53 enum OutputFrameStateCombine { 31 enum OutputFrameStateCombine {
54 kPushOutput, // Push the output on the expression stack. 32 kPushOutput, // Push the output on the expression stack.
55 kIgnoreOutput // Use the frame state as-is. 33 kIgnoreOutput // Use the frame state as-is.
56 }; 34 };
57 35
58 36
59 class FrameStateCallInfo { 37 class FrameStateCallInfo FINAL {
60 public: 38 public:
61 FrameStateCallInfo(BailoutId bailout_id, 39 FrameStateCallInfo(BailoutId bailout_id,
62 OutputFrameStateCombine state_combine) 40 OutputFrameStateCombine state_combine)
63 : bailout_id_(bailout_id), frame_state_combine_(state_combine) {} 41 : bailout_id_(bailout_id), frame_state_combine_(state_combine) {}
64 42
65 BailoutId bailout_id() const { return bailout_id_; } 43 BailoutId bailout_id() const { return bailout_id_; }
66 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } 44 OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
67 45
68 private: 46 private:
69 BailoutId bailout_id_; 47 BailoutId bailout_id_;
70 OutputFrameStateCombine frame_state_combine_; 48 OutputFrameStateCombine frame_state_combine_;
71 }; 49 };
72 50
51
73 // Interface for building common operators that can be used at any level of IR, 52 // Interface for building common operators that can be used at any level of IR,
74 // including JavaScript, mid-level, and low-level. 53 // including JavaScript, mid-level, and low-level.
75 // TODO(titzer): Move the mnemonics into SimpleOperator and Operator1 classes. 54 class CommonOperatorBuilder FINAL {
76 class CommonOperatorBuilder {
77 public: 55 public:
78 explicit CommonOperatorBuilder(Zone* zone) : zone_(zone) {} 56 explicit CommonOperatorBuilder(Zone* zone);
79 57
80 #define CONTROL_OP(name, inputs, controls) \ 58 const Operator* Dead();
81 return new (zone_) ControlOperator(IrOpcode::k##name, Operator::kFoldable, \ 59 const Operator* End();
82 inputs, 0, controls, #name); 60 const Operator* Branch();
61 const Operator* IfTrue();
62 const Operator* IfFalse();
63 const Operator* Throw();
64 const Operator* Return();
83 65
84 const Operator* Start(int num_formal_parameters) { 66 const Operator* Start(int num_formal_parameters);
85 // Outputs are formal parameters, plus context, receiver, and JSFunction. 67 const Operator* Merge(int controls);
86 int outputs = num_formal_parameters + 3; 68 const Operator* Loop(int controls);
87 return new (zone_) ControlOperator(IrOpcode::kStart, Operator::kFoldable, 0, 69 const Operator* Parameter(int index);
88 outputs, 0, "Start");
89 }
90 const Operator* Dead() { CONTROL_OP(Dead, 0, 0); }
91 const Operator* End() { CONTROL_OP(End, 0, 1); }
92 const Operator* Branch() { CONTROL_OP(Branch, 1, 1); }
93 const Operator* IfTrue() { CONTROL_OP(IfTrue, 0, 1); }
94 const Operator* IfFalse() { CONTROL_OP(IfFalse, 0, 1); }
95 const Operator* Throw() { CONTROL_OP(Throw, 1, 1); }
96 70
97 const Operator* Return() { 71 const Operator* Int32Constant(int32_t);
98 return new (zone_) ControlOperator( 72 const Operator* Int64Constant(int64_t);
99 IrOpcode::kReturn, Operator::kNoProperties, 1, 0, 1, "Return"); 73 const Operator* Float64Constant(volatile double);
100 } 74 const Operator* ExternalConstant(const ExternalReference&);
75 const Operator* NumberConstant(volatile double);
76 const Operator* HeapConstant(const Unique<Object>&);
101 77
102 const Operator* Merge(int controls) { 78 const Operator* Phi(MachineType type, int arguments);
103 return new (zone_) ControlOperator(IrOpcode::kMerge, Operator::kFoldable, 0, 79 const Operator* EffectPhi(int arguments);
104 0, controls, "Merge"); 80 const Operator* ControlEffect();
105 } 81 const Operator* ValueEffect(int arguments);
106 82 const Operator* Finish(int arguments);
107 const Operator* Loop(int controls) { 83 const Operator* StateValues(int arguments);
108 return new (zone_) ControlOperator(IrOpcode::kLoop, Operator::kFoldable, 0,
109 0, controls, "Loop");
110 }
111
112 const Operator* Parameter(int index) {
113 return new (zone_) Operator1<int>(IrOpcode::kParameter, Operator::kPure, 1,
114 1, "Parameter", index);
115 }
116 const Operator* Int32Constant(int32_t value) {
117 return new (zone_)
118 Operator1<int32_t>(IrOpcode::kInt32Constant, Operator::kPure, 0, 1,
119 "Int32Constant", value);
120 }
121 const Operator* Int64Constant(int64_t value) {
122 return new (zone_)
123 Operator1<int64_t>(IrOpcode::kInt64Constant, Operator::kPure, 0, 1,
124 "Int64Constant", value);
125 }
126 const Operator* Float64Constant(double value) {
127 return new (zone_)
128 Operator1<double>(IrOpcode::kFloat64Constant, Operator::kPure, 0, 1,
129 "Float64Constant", value);
130 }
131 const Operator* ExternalConstant(ExternalReference value) {
132 return new (zone_) Operator1<ExternalReference>(IrOpcode::kExternalConstant,
133 Operator::kPure, 0, 1,
134 "ExternalConstant", value);
135 }
136 const Operator* NumberConstant(double value) {
137 return new (zone_)
138 Operator1<double>(IrOpcode::kNumberConstant, Operator::kPure, 0, 1,
139 "NumberConstant", value);
140 }
141 const Operator* HeapConstant(Unique<Object> value) {
142 return new (zone_) Operator1<Unique<Object> >(
143 IrOpcode::kHeapConstant, Operator::kPure, 0, 1, "HeapConstant", value);
144 }
145 const Operator* Phi(MachineType type, int arguments) {
146 DCHECK(arguments > 0); // Disallow empty phis.
147 return new (zone_) Operator1<MachineType>(IrOpcode::kPhi, Operator::kPure,
148 arguments, 1, "Phi", type);
149 }
150 const Operator* EffectPhi(int arguments) {
151 DCHECK(arguments > 0); // Disallow empty phis.
152 return new (zone_) Operator1<int>(IrOpcode::kEffectPhi, Operator::kPure, 0,
153 0, "EffectPhi", arguments);
154 }
155 const Operator* ControlEffect() {
156 return new (zone_) SimpleOperator(IrOpcode::kControlEffect, Operator::kPure,
157 0, 0, "ControlEffect");
158 }
159 const Operator* ValueEffect(int arguments) {
160 DCHECK(arguments > 0); // Disallow empty value effects.
161 return new (zone_) SimpleOperator(IrOpcode::kValueEffect, Operator::kPure,
162 arguments, 0, "ValueEffect");
163 }
164 const Operator* Finish(int arguments) {
165 DCHECK(arguments > 0); // Disallow empty finishes.
166 return new (zone_) Operator1<int>(IrOpcode::kFinish, Operator::kPure, 1, 1,
167 "Finish", arguments);
168 }
169 const Operator* StateValues(int arguments) {
170 return new (zone_) Operator1<int>(IrOpcode::kStateValues, Operator::kPure,
171 arguments, 1, "StateValues", arguments);
172 }
173 const Operator* FrameState(BailoutId bailout_id, 84 const Operator* FrameState(BailoutId bailout_id,
174 OutputFrameStateCombine combine) { 85 OutputFrameStateCombine combine);
175 return new (zone_) Operator1<FrameStateCallInfo>( 86 const Operator* Call(const CallDescriptor* descriptor);
176 IrOpcode::kFrameState, Operator::kPure, 4, 1, "FrameState", 87 const Operator* Projection(size_t index);
177 FrameStateCallInfo(bailout_id, combine));
178 }
179 const Operator* Call(CallDescriptor* descriptor) {
180 return new (zone_) CallOperator(descriptor, "Call");
181 }
182 const Operator* Projection(size_t index) {
183 return new (zone_) Operator1<size_t>(IrOpcode::kProjection, Operator::kPure,
184 1, 1, "Projection", index);
185 }
186 88
187 private: 89 private:
188 Zone* zone_; 90 Zone* zone() const { return zone_; }
91
92 const CommonOperatorBuilderImpl& impl_;
93 Zone* const zone_;
189 }; 94 };
190 95
191 } // namespace compiler 96 } // namespace compiler
192 } // namespace internal 97 } // namespace internal
193 } // namespace v8 98 } // namespace v8
194 99
195 #endif // V8_COMPILER_COMMON_OPERATOR_H_ 100 #endif // V8_COMPILER_COMMON_OPERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698