Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "src/compiler/frame-states.h" |
| 9 | #include "src/machine-type.h" |
| 10 | #include "src/zone-containers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
| 15 | // Forward declarations. |
| 16 | class ExternalReference; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 17 | class Type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | |
| 19 | namespace compiler { |
| 20 | |
| 21 | // Forward declarations. |
| 22 | class CallDescriptor; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | struct CommonOperatorGlobalCache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | class Operator; |
| 25 | |
| 26 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 27 | // Prediction hint for branches. |
| 28 | enum class BranchHint : uint8_t { kNone, kTrue, kFalse }; |
| 29 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | inline BranchHint NegateBranchHint(BranchHint hint) { |
| 31 | switch (hint) { |
| 32 | case BranchHint::kNone: |
| 33 | return hint; |
| 34 | case BranchHint::kTrue: |
| 35 | return BranchHint::kFalse; |
| 36 | case BranchHint::kFalse: |
| 37 | return BranchHint::kTrue; |
| 38 | } |
| 39 | UNREACHABLE(); |
| 40 | return hint; |
| 41 | } |
| 42 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); } |
| 44 | |
| 45 | std::ostream& operator<<(std::ostream&, BranchHint); |
| 46 | |
| 47 | BranchHint BranchHintOf(const Operator* const); |
| 48 | |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | // Deoptimize bailout kind. |
| 51 | enum class DeoptimizeKind : uint8_t { kEager, kSoft }; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 52 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | size_t hash_value(DeoptimizeKind kind); |
| 54 | |
| 55 | std::ostream& operator<<(std::ostream&, DeoptimizeKind); |
| 56 | |
| 57 | DeoptimizeKind DeoptimizeKindOf(const Operator* const); |
| 58 | |
| 59 | |
| 60 | // Prediction whether throw-site is surrounded by any local catch-scope. |
| 61 | enum class IfExceptionHint { kLocallyUncaught, kLocallyCaught }; |
| 62 | |
| 63 | size_t hash_value(IfExceptionHint hint); |
| 64 | |
| 65 | std::ostream& operator<<(std::ostream&, IfExceptionHint); |
| 66 | |
| 67 | |
| 68 | class SelectParameters final { |
| 69 | public: |
| 70 | explicit SelectParameters(MachineRepresentation representation, |
| 71 | BranchHint hint = BranchHint::kNone) |
| 72 | : representation_(representation), hint_(hint) {} |
| 73 | |
| 74 | MachineRepresentation representation() const { return representation_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 75 | BranchHint hint() const { return hint_; } |
| 76 | |
| 77 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | const MachineRepresentation representation_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 79 | const BranchHint hint_; |
| 80 | }; |
| 81 | |
| 82 | bool operator==(SelectParameters const&, SelectParameters const&); |
| 83 | bool operator!=(SelectParameters const&, SelectParameters const&); |
| 84 | |
| 85 | size_t hash_value(SelectParameters const& p); |
| 86 | |
| 87 | std::ostream& operator<<(std::ostream&, SelectParameters const& p); |
| 88 | |
| 89 | SelectParameters const& SelectParametersOf(const Operator* const); |
| 90 | |
| 91 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 92 | size_t ProjectionIndexOf(const Operator* const); |
| 93 | |
| 94 | MachineRepresentation PhiRepresentationOf(const Operator* const); |
| 95 | |
| 96 | |
| 97 | // The {IrOpcode::kParameter} opcode represents an incoming parameter to the |
| 98 | // function. This class bundles the index and a debug name for such operators. |
| 99 | class ParameterInfo final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 100 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 101 | ParameterInfo(int index, const char* debug_name) |
| 102 | : index_(index), debug_name_(debug_name) {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 103 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 104 | int index() const { return index_; } |
| 105 | const char* debug_name() const { return debug_name_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 106 | |
| 107 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 108 | int index_; |
| 109 | const char* debug_name_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | std::ostream& operator<<(std::ostream&, ParameterInfo const&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 114 | int ParameterIndexOf(const Operator* const); |
| 115 | const ParameterInfo& ParameterInfoOf(const Operator* const); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 116 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 117 | |
| 118 | // Interface for building common operators that can be used at any level of IR, |
| 119 | // including JavaScript, mid-level, and low-level. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 120 | class CommonOperatorBuilder final : public ZoneObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 121 | public: |
| 122 | explicit CommonOperatorBuilder(Zone* zone); |
| 123 | |
| 124 | const Operator* Dead(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 125 | const Operator* End(size_t control_input_count); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 126 | const Operator* Branch(BranchHint = BranchHint::kNone); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | const Operator* IfTrue(); |
| 128 | const Operator* IfFalse(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 129 | const Operator* IfSuccess(); |
| 130 | const Operator* IfException(IfExceptionHint hint); |
| 131 | const Operator* Switch(size_t control_output_count); |
| 132 | const Operator* IfValue(int32_t value); |
| 133 | const Operator* IfDefault(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 134 | const Operator* Throw(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 135 | const Operator* Deoptimize(DeoptimizeKind kind); |
| 136 | const Operator* Return(int value_input_count = 1); |
| 137 | const Operator* Terminate(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 139 | const Operator* Start(int value_output_count); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 140 | const Operator* Loop(int control_input_count); |
| 141 | const Operator* Merge(int control_input_count); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 142 | const Operator* Parameter(int index, const char* debug_name = nullptr); |
| 143 | |
| 144 | const Operator* OsrNormalEntry(); |
| 145 | const Operator* OsrLoopEntry(); |
| 146 | const Operator* OsrValue(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 147 | |
| 148 | const Operator* Int32Constant(int32_t); |
| 149 | const Operator* Int64Constant(int64_t); |
| 150 | const Operator* Float32Constant(volatile float); |
| 151 | const Operator* Float64Constant(volatile double); |
| 152 | const Operator* ExternalConstant(const ExternalReference&); |
| 153 | const Operator* NumberConstant(volatile double); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 154 | const Operator* HeapConstant(const Handle<HeapObject>&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 156 | const Operator* Select(MachineRepresentation, BranchHint = BranchHint::kNone); |
| 157 | const Operator* Phi(MachineRepresentation representation, |
| 158 | int value_input_count); |
| 159 | const Operator* EffectPhi(int effect_input_count); |
| 160 | const Operator* EffectSet(int arguments); |
| 161 | const Operator* Guard(Type* type); |
| 162 | const Operator* BeginRegion(); |
| 163 | const Operator* FinishRegion(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 164 | const Operator* StateValues(int arguments); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 165 | const Operator* ObjectState(int pointer_slots, int id); |
| 166 | const Operator* TypedStateValues(const ZoneVector<MachineType>* types); |
| 167 | const Operator* FrameState(BailoutId bailout_id, |
| 168 | OutputFrameStateCombine state_combine, |
| 169 | const FrameStateFunctionInfo* function_info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 170 | const Operator* Call(const CallDescriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 171 | const Operator* TailCall(const CallDescriptor* descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | const Operator* Projection(size_t index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | |
| 174 | // Constructs a new merge or phi operator with the same opcode as {op}, but |
| 175 | // with {size} inputs. |
| 176 | const Operator* ResizeMergeOrPhi(const Operator* op, int size); |
| 177 | |
| 178 | // Constructs function info for frame state construction. |
| 179 | const FrameStateFunctionInfo* CreateFrameStateFunctionInfo( |
| 180 | FrameStateType type, int parameter_count, int local_count, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 181 | Handle<SharedFunctionInfo> shared_info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | Zone* zone() const { return zone_; } |
| 185 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 186 | const CommonOperatorGlobalCache& cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | Zone* const zone_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 188 | |
| 189 | DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | } // namespace compiler |
| 193 | } // namespace internal |
| 194 | } // namespace v8 |
| 195 | |
| 196 | #endif // V8_COMPILER_COMMON_OPERATOR_H_ |