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
3 // found in the LICENSE file.
5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_
6 #define V8_COMPILER_COMMON_OPERATOR_H_
8 #include "src/compiler/machine-type.h"
9 #include "src/unique.h"
14 // Forward declarations.
15 class ExternalReference;
20 // Forward declarations.
22 struct CommonOperatorGlobalCache;
26 // Prediction hint for branches.
27 enum class BranchHint : uint8_t { kNone, kTrue, kFalse };
29 inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); }
31 std::ostream& operator<<(std::ostream&, BranchHint);
33 BranchHint BranchHintOf(const Operator* const);
36 class SelectParameters FINAL {
38 explicit SelectParameters(MachineType type,
39 BranchHint hint = BranchHint::kNone)
40 : type_(type), hint_(hint) {}
42 MachineType type() const { return type_; }
43 BranchHint hint() const { return hint_; }
46 const MachineType type_;
47 const BranchHint hint_;
50 bool operator==(SelectParameters const&, SelectParameters const&);
51 bool operator!=(SelectParameters const&, SelectParameters const&);
53 size_t hash_value(SelectParameters const& p);
55 std::ostream& operator<<(std::ostream&, SelectParameters const& p);
57 SelectParameters const& SelectParametersOf(const Operator* const);
60 // Flag that describes how to combine the current environment with
61 // the output of a node to obtain a framestate for lazy bailout.
62 class OutputFrameStateCombine {
65 kPushOutput, // Push the output on the expression stack.
66 kPokeAt // Poke at the given environment location,
67 // counting from the top of the stack.
70 static OutputFrameStateCombine Ignore() {
71 return OutputFrameStateCombine(kPushOutput, 0);
73 static OutputFrameStateCombine Push(size_t count = 1) {
74 return OutputFrameStateCombine(kPushOutput, count);
76 static OutputFrameStateCombine PokeAt(size_t index) {
77 return OutputFrameStateCombine(kPokeAt, index);
80 Kind kind() const { return kind_; }
81 size_t GetPushCount() const {
82 DCHECK_EQ(kPushOutput, kind());
85 size_t GetOffsetToPokeAt() const {
86 DCHECK_EQ(kPokeAt, kind());
90 bool IsOutputIgnored() const {
91 return kind_ == kPushOutput && parameter_ == 0;
94 size_t ConsumedOutputCount() const {
95 return kind_ == kPushOutput ? GetPushCount() : 1;
98 bool operator==(OutputFrameStateCombine const& other) const {
99 return kind_ == other.kind_ && parameter_ == other.parameter_;
101 bool operator!=(OutputFrameStateCombine const& other) const {
102 return !(*this == other);
105 friend size_t hash_value(OutputFrameStateCombine const&);
106 friend std::ostream& operator<<(std::ostream&,
107 OutputFrameStateCombine const&);
110 OutputFrameStateCombine(Kind kind, size_t parameter)
111 : kind_(kind), parameter_(parameter) {}
114 size_t const parameter_;
118 // The type of stack frame that a FrameState node represents.
119 enum FrameStateType {
120 JS_FRAME, // Represents an unoptimized JavaScriptFrame.
121 ARGUMENTS_ADAPTOR // Represents an ArgumentsAdaptorFrame.
125 class FrameStateCallInfo FINAL {
128 FrameStateType type, BailoutId bailout_id,
129 OutputFrameStateCombine state_combine,
130 MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>())
132 bailout_id_(bailout_id),
133 frame_state_combine_(state_combine),
134 jsfunction_(jsfunction) {}
136 FrameStateType type() const { return type_; }
137 BailoutId bailout_id() const { return bailout_id_; }
138 OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
139 MaybeHandle<JSFunction> jsfunction() const { return jsfunction_; }
142 FrameStateType type_;
143 BailoutId bailout_id_;
144 OutputFrameStateCombine frame_state_combine_;
145 MaybeHandle<JSFunction> jsfunction_;
148 bool operator==(FrameStateCallInfo const&, FrameStateCallInfo const&);
149 bool operator!=(FrameStateCallInfo const&, FrameStateCallInfo const&);
151 size_t hash_value(FrameStateCallInfo const&);
153 std::ostream& operator<<(std::ostream&, FrameStateCallInfo const&);
156 size_t ProjectionIndexOf(const Operator* const);
159 // Interface for building common operators that can be used at any level of IR,
160 // including JavaScript, mid-level, and low-level.
161 class CommonOperatorBuilder FINAL : public ZoneObject {
163 explicit CommonOperatorBuilder(Zone* zone);
165 // Special operator used only in Branches to mark them as always taken, but
166 // still unfoldable. This is required to properly connect non terminating
167 // loops to end (in both the sea of nodes and the CFG).
168 const Operator* Always();
170 const Operator* Dead();
171 const Operator* End();
172 const Operator* Branch(BranchHint = BranchHint::kNone);
173 const Operator* IfTrue();
174 const Operator* IfFalse();
175 const Operator* Switch(size_t control_output_count);
176 const Operator* IfValue(int32_t value);
177 const Operator* IfDefault();
178 const Operator* Throw();
179 const Operator* Return();
181 const Operator* Start(int num_formal_parameters);
182 const Operator* Loop(int control_input_count);
183 const Operator* Merge(int control_input_count);
184 const Operator* Parameter(int index);
186 const Operator* OsrNormalEntry();
187 const Operator* OsrLoopEntry();
188 const Operator* OsrValue(int index);
190 const Operator* Int32Constant(int32_t);
191 const Operator* Int64Constant(int64_t);
192 const Operator* Float32Constant(volatile float);
193 const Operator* Float64Constant(volatile double);
194 const Operator* ExternalConstant(const ExternalReference&);
195 const Operator* NumberConstant(volatile double);
196 const Operator* HeapConstant(const Unique<HeapObject>&);
198 const Operator* Select(MachineType, BranchHint = BranchHint::kNone);
199 const Operator* Phi(MachineType type, int arguments);
200 const Operator* EffectPhi(int arguments);
201 const Operator* EffectSet(int arguments);
202 const Operator* ValueEffect(int arguments);
203 const Operator* Finish(int arguments);
204 const Operator* StateValues(int arguments);
205 const Operator* FrameState(
206 FrameStateType type, BailoutId bailout_id,
207 OutputFrameStateCombine state_combine,
208 MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>());
209 const Operator* Call(const CallDescriptor* descriptor);
210 const Operator* Projection(size_t index);
212 // Constructs a new merge or phi operator with the same opcode as {op}, but
213 // with {size} inputs.
214 const Operator* ResizeMergeOrPhi(const Operator* op, int size);
217 Zone* zone() const { return zone_; }
219 const CommonOperatorGlobalCache& cache_;
222 DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder);
225 } // namespace compiler
226 } // namespace internal
229 #endif // V8_COMPILER_COMMON_OPERATOR_H_