Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef V8_COMPILER_COMMON_OPERATOR_H_ |
| 6 | #define V8_COMPILER_COMMON_OPERATOR_H_ |
| 7 | |
| 8 | #include "src/compiler/machine-type.h" |
| 9 | #include "src/unique.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | // Forward declarations. |
| 15 | class ExternalReference; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | |
| 17 | |
| 18 | namespace compiler { |
| 19 | |
| 20 | // Forward declarations. |
| 21 | class CallDescriptor; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 22 | struct CommonOperatorGlobalCache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 23 | class Operator; |
| 24 | |
| 25 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 26 | // Prediction hint for branches. |
| 27 | enum class BranchHint : uint8_t { kNone, kTrue, kFalse }; |
| 28 | |
| 29 | inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); } |
| 30 | |
| 31 | std::ostream& operator<<(std::ostream&, BranchHint); |
| 32 | |
| 33 | BranchHint BranchHintOf(const Operator* const); |
| 34 | |
| 35 | |
| 36 | class SelectParameters FINAL { |
| 37 | public: |
| 38 | explicit SelectParameters(MachineType type, |
| 39 | BranchHint hint = BranchHint::kNone) |
| 40 | : type_(type), hint_(hint) {} |
| 41 | |
| 42 | MachineType type() const { return type_; } |
| 43 | BranchHint hint() const { return hint_; } |
| 44 | |
| 45 | private: |
| 46 | const MachineType type_; |
| 47 | const BranchHint hint_; |
| 48 | }; |
| 49 | |
| 50 | bool operator==(SelectParameters const&, SelectParameters const&); |
| 51 | bool operator!=(SelectParameters const&, SelectParameters const&); |
| 52 | |
| 53 | size_t hash_value(SelectParameters const& p); |
| 54 | |
| 55 | std::ostream& operator<<(std::ostream&, SelectParameters const& p); |
| 56 | |
| 57 | SelectParameters const& SelectParametersOf(const Operator* const); |
| 58 | |
| 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | // Flag that describes how to combine the current environment with |
| 61 | // the output of a node to obtain a framestate for lazy bailout. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 62 | class OutputFrameStateCombine { |
| 63 | public: |
| 64 | enum Kind { |
| 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. |
| 68 | }; |
| 69 | |
| 70 | static OutputFrameStateCombine Ignore() { |
| 71 | return OutputFrameStateCombine(kPushOutput, 0); |
| 72 | } |
| 73 | static OutputFrameStateCombine Push(size_t count = 1) { |
| 74 | return OutputFrameStateCombine(kPushOutput, count); |
| 75 | } |
| 76 | static OutputFrameStateCombine PokeAt(size_t index) { |
| 77 | return OutputFrameStateCombine(kPokeAt, index); |
| 78 | } |
| 79 | |
| 80 | Kind kind() const { return kind_; } |
| 81 | size_t GetPushCount() const { |
| 82 | DCHECK_EQ(kPushOutput, kind()); |
| 83 | return parameter_; |
| 84 | } |
| 85 | size_t GetOffsetToPokeAt() const { |
| 86 | DCHECK_EQ(kPokeAt, kind()); |
| 87 | return parameter_; |
| 88 | } |
| 89 | |
| 90 | bool IsOutputIgnored() const { |
| 91 | return kind_ == kPushOutput && parameter_ == 0; |
| 92 | } |
| 93 | |
| 94 | size_t ConsumedOutputCount() const { |
| 95 | return kind_ == kPushOutput ? GetPushCount() : 1; |
| 96 | } |
| 97 | |
| 98 | bool operator==(OutputFrameStateCombine const& other) const { |
| 99 | return kind_ == other.kind_ && parameter_ == other.parameter_; |
| 100 | } |
| 101 | bool operator!=(OutputFrameStateCombine const& other) const { |
| 102 | return !(*this == other); |
| 103 | } |
| 104 | |
| 105 | friend size_t hash_value(OutputFrameStateCombine const&); |
| 106 | friend std::ostream& operator<<(std::ostream&, |
| 107 | OutputFrameStateCombine const&); |
| 108 | |
| 109 | private: |
| 110 | OutputFrameStateCombine(Kind kind, size_t parameter) |
| 111 | : kind_(kind), parameter_(parameter) {} |
| 112 | |
| 113 | Kind const kind_; |
| 114 | size_t const parameter_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | |
| 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. |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | class FrameStateCallInfo FINAL { |
| 126 | public: |
| 127 | FrameStateCallInfo( |
| 128 | FrameStateType type, BailoutId bailout_id, |
| 129 | OutputFrameStateCombine state_combine, |
| 130 | MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>()) |
| 131 | : type_(type), |
| 132 | bailout_id_(bailout_id), |
| 133 | frame_state_combine_(state_combine), |
| 134 | jsfunction_(jsfunction) {} |
| 135 | |
| 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_; } |
| 140 | |
| 141 | private: |
| 142 | FrameStateType type_; |
| 143 | BailoutId bailout_id_; |
| 144 | OutputFrameStateCombine frame_state_combine_; |
| 145 | MaybeHandle<JSFunction> jsfunction_; |
| 146 | }; |
| 147 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 148 | bool operator==(FrameStateCallInfo const&, FrameStateCallInfo const&); |
| 149 | bool operator!=(FrameStateCallInfo const&, FrameStateCallInfo const&); |
| 150 | |
| 151 | size_t hash_value(FrameStateCallInfo const&); |
| 152 | |
| 153 | std::ostream& operator<<(std::ostream&, FrameStateCallInfo const&); |
| 154 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | |
| 156 | // Interface for building common operators that can be used at any level of IR, |
| 157 | // including JavaScript, mid-level, and low-level. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 158 | class CommonOperatorBuilder FINAL : public ZoneObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 159 | public: |
| 160 | explicit CommonOperatorBuilder(Zone* zone); |
| 161 | |
| 162 | const Operator* Dead(); |
| 163 | const Operator* End(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 164 | const Operator* Branch(BranchHint = BranchHint::kNone); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | const Operator* IfTrue(); |
| 166 | const Operator* IfFalse(); |
| 167 | const Operator* Throw(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 168 | const Operator* Terminate(int effects); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | const Operator* Return(); |
| 170 | |
| 171 | const Operator* Start(int num_formal_parameters); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 172 | const Operator* Loop(int control_input_count); |
| 173 | const Operator* Merge(int control_input_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | const Operator* Parameter(int index); |
| 175 | |
| 176 | const Operator* Int32Constant(int32_t); |
| 177 | const Operator* Int64Constant(int64_t); |
| 178 | const Operator* Float32Constant(volatile float); |
| 179 | const Operator* Float64Constant(volatile double); |
| 180 | const Operator* ExternalConstant(const ExternalReference&); |
| 181 | const Operator* NumberConstant(volatile double); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 182 | const Operator* HeapConstant(const Unique<HeapObject>&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 183 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 184 | const Operator* Select(MachineType, BranchHint = BranchHint::kNone); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 185 | const Operator* Phi(MachineType type, int arguments); |
| 186 | const Operator* EffectPhi(int arguments); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | const Operator* ValueEffect(int arguments); |
| 188 | const Operator* Finish(int arguments); |
| 189 | const Operator* StateValues(int arguments); |
| 190 | const Operator* FrameState( |
| 191 | FrameStateType type, BailoutId bailout_id, |
| 192 | OutputFrameStateCombine state_combine, |
| 193 | MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>()); |
| 194 | const Operator* Call(const CallDescriptor* descriptor); |
| 195 | const Operator* Projection(size_t index); |
| 196 | |
| 197 | private: |
| 198 | Zone* zone() const { return zone_; } |
| 199 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 200 | const CommonOperatorGlobalCache& cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | Zone* const zone_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 202 | |
| 203 | DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | } // namespace compiler |
| 207 | } // namespace internal |
| 208 | } // namespace v8 |
| 209 | |
| 210 | #endif // V8_COMPILER_COMMON_OPERATOR_H_ |