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 | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 8 | #include "src/assembler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/compiler/frame-states.h" |
| 10 | #include "src/machine-type.h" |
| 11 | #include "src/zone-containers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | namespace compiler { |
| 16 | |
| 17 | // Forward declarations. |
| 18 | class CallDescriptor; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 19 | struct CommonOperatorGlobalCache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 20 | class Operator; |
| 21 | |
| 22 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | // Prediction hint for branches. |
| 24 | enum class BranchHint : uint8_t { kNone, kTrue, kFalse }; |
| 25 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | inline BranchHint NegateBranchHint(BranchHint hint) { |
| 27 | switch (hint) { |
| 28 | case BranchHint::kNone: |
| 29 | return hint; |
| 30 | case BranchHint::kTrue: |
| 31 | return BranchHint::kFalse; |
| 32 | case BranchHint::kFalse: |
| 33 | return BranchHint::kTrue; |
| 34 | } |
| 35 | UNREACHABLE(); |
| 36 | return hint; |
| 37 | } |
| 38 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 39 | inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); } |
| 40 | |
| 41 | std::ostream& operator<<(std::ostream&, BranchHint); |
| 42 | |
| 43 | BranchHint BranchHintOf(const Operator* const); |
| 44 | |
| 45 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | // Deoptimize bailout kind. |
| 47 | enum class DeoptimizeKind : uint8_t { kEager, kSoft }; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 48 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | size_t hash_value(DeoptimizeKind kind); |
| 50 | |
| 51 | std::ostream& operator<<(std::ostream&, DeoptimizeKind); |
| 52 | |
| 53 | DeoptimizeKind DeoptimizeKindOf(const Operator* const); |
| 54 | |
| 55 | |
| 56 | // Prediction whether throw-site is surrounded by any local catch-scope. |
| 57 | enum class IfExceptionHint { kLocallyUncaught, kLocallyCaught }; |
| 58 | |
| 59 | size_t hash_value(IfExceptionHint hint); |
| 60 | |
| 61 | std::ostream& operator<<(std::ostream&, IfExceptionHint); |
| 62 | |
| 63 | |
| 64 | class SelectParameters final { |
| 65 | public: |
| 66 | explicit SelectParameters(MachineRepresentation representation, |
| 67 | BranchHint hint = BranchHint::kNone) |
| 68 | : representation_(representation), hint_(hint) {} |
| 69 | |
| 70 | MachineRepresentation representation() const { return representation_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 71 | BranchHint hint() const { return hint_; } |
| 72 | |
| 73 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 74 | const MachineRepresentation representation_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 75 | const BranchHint hint_; |
| 76 | }; |
| 77 | |
| 78 | bool operator==(SelectParameters const&, SelectParameters const&); |
| 79 | bool operator!=(SelectParameters const&, SelectParameters const&); |
| 80 | |
| 81 | size_t hash_value(SelectParameters const& p); |
| 82 | |
| 83 | std::ostream& operator<<(std::ostream&, SelectParameters const& p); |
| 84 | |
| 85 | SelectParameters const& SelectParametersOf(const Operator* const); |
| 86 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 87 | CallDescriptor const* CallDescriptorOf(const Operator* const); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 88 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 | size_t ProjectionIndexOf(const Operator* const); |
| 90 | |
| 91 | MachineRepresentation PhiRepresentationOf(const Operator* const); |
| 92 | |
| 93 | |
| 94 | // The {IrOpcode::kParameter} opcode represents an incoming parameter to the |
| 95 | // function. This class bundles the index and a debug name for such operators. |
| 96 | class ParameterInfo final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 97 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 | ParameterInfo(int index, const char* debug_name) |
| 99 | : index_(index), debug_name_(debug_name) {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 100 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 101 | int index() const { return index_; } |
| 102 | const char* debug_name() const { return debug_name_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 103 | |
| 104 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 105 | int index_; |
| 106 | const char* debug_name_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 109 | std::ostream& operator<<(std::ostream&, ParameterInfo const&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 110 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 111 | int ParameterIndexOf(const Operator* const); |
| 112 | const ParameterInfo& ParameterInfoOf(const Operator* const); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 113 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 114 | class RelocatablePtrConstantInfo final { |
| 115 | public: |
| 116 | enum Type { kInt32, kInt64 }; |
| 117 | |
| 118 | RelocatablePtrConstantInfo(int32_t value, RelocInfo::Mode rmode) |
| 119 | : value_(value), rmode_(rmode), type_(kInt32) {} |
| 120 | RelocatablePtrConstantInfo(int64_t value, RelocInfo::Mode rmode) |
| 121 | : value_(value), rmode_(rmode), type_(kInt64) {} |
| 122 | |
| 123 | intptr_t value() const { return value_; } |
| 124 | RelocInfo::Mode rmode() const { return rmode_; } |
| 125 | Type type() const { return type_; } |
| 126 | |
| 127 | private: |
| 128 | intptr_t value_; |
| 129 | RelocInfo::Mode rmode_; |
| 130 | Type type_; |
| 131 | }; |
| 132 | |
| 133 | bool operator==(RelocatablePtrConstantInfo const& lhs, |
| 134 | RelocatablePtrConstantInfo const& rhs); |
| 135 | bool operator!=(RelocatablePtrConstantInfo const& lhs, |
| 136 | RelocatablePtrConstantInfo const& rhs); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 137 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 138 | std::ostream& operator<<(std::ostream&, RelocatablePtrConstantInfo const&); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 139 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 140 | size_t hash_value(RelocatablePtrConstantInfo const& p); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 141 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 142 | // Used to mark a region (as identified by BeginRegion/FinishRegion) as either |
| 143 | // JavaScript-observable or not (i.e. allocations are not JavaScript observable |
| 144 | // themselves, but transitioning stores are). |
| 145 | enum class RegionObservability : uint8_t { kObservable, kNotObservable }; |
| 146 | |
| 147 | size_t hash_value(RegionObservability); |
| 148 | |
| 149 | std::ostream& operator<<(std::ostream&, RegionObservability); |
| 150 | |
| 151 | RegionObservability RegionObservabilityOf(Operator const*) WARN_UNUSED_RESULT; |
| 152 | |
| 153 | std::ostream& operator<<(std::ostream& os, |
| 154 | const ZoneVector<MachineType>* types); |
| 155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | // Interface for building common operators that can be used at any level of IR, |
| 157 | // including JavaScript, mid-level, and low-level. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [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(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | const Operator* End(size_t control_input_count); |
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(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 167 | const Operator* IfSuccess(); |
| 168 | const Operator* IfException(IfExceptionHint hint); |
| 169 | const Operator* Switch(size_t control_output_count); |
| 170 | const Operator* IfValue(int32_t value); |
| 171 | const Operator* IfDefault(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | const Operator* Throw(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | const Operator* Deoptimize(DeoptimizeKind kind); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 174 | const Operator* DeoptimizeIf(); |
| 175 | const Operator* DeoptimizeUnless(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | const Operator* Return(int value_input_count = 1); |
| 177 | const Operator* Terminate(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 178 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 179 | const Operator* Start(int value_output_count); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 180 | const Operator* Loop(int control_input_count); |
| 181 | const Operator* Merge(int control_input_count); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | const Operator* Parameter(int index, const char* debug_name = nullptr); |
| 183 | |
| 184 | const Operator* OsrNormalEntry(); |
| 185 | const Operator* OsrLoopEntry(); |
| 186 | const Operator* OsrValue(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | |
| 188 | const Operator* Int32Constant(int32_t); |
| 189 | const Operator* Int64Constant(int64_t); |
| 190 | const Operator* Float32Constant(volatile float); |
| 191 | const Operator* Float64Constant(volatile double); |
| 192 | const Operator* ExternalConstant(const ExternalReference&); |
| 193 | const Operator* NumberConstant(volatile double); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 194 | const Operator* HeapConstant(const Handle<HeapObject>&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 195 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 196 | const Operator* RelocatableInt32Constant(int32_t value, |
| 197 | RelocInfo::Mode rmode); |
| 198 | const Operator* RelocatableInt64Constant(int64_t value, |
| 199 | RelocInfo::Mode rmode); |
| 200 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 201 | const Operator* Select(MachineRepresentation, BranchHint = BranchHint::kNone); |
| 202 | const Operator* Phi(MachineRepresentation representation, |
| 203 | int value_input_count); |
| 204 | const Operator* EffectPhi(int effect_input_count); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 205 | const Operator* Checkpoint(); |
| 206 | const Operator* BeginRegion(RegionObservability); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 207 | const Operator* FinishRegion(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 208 | const Operator* StateValues(int arguments); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 209 | const Operator* ObjectState(int pointer_slots, int id); |
| 210 | const Operator* TypedStateValues(const ZoneVector<MachineType>* types); |
| 211 | const Operator* FrameState(BailoutId bailout_id, |
| 212 | OutputFrameStateCombine state_combine, |
| 213 | const FrameStateFunctionInfo* function_info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 214 | const Operator* Call(const CallDescriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 215 | const Operator* TailCall(const CallDescriptor* descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | const Operator* Projection(size_t index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 217 | |
| 218 | // Constructs a new merge or phi operator with the same opcode as {op}, but |
| 219 | // with {size} inputs. |
| 220 | const Operator* ResizeMergeOrPhi(const Operator* op, int size); |
| 221 | |
| 222 | // Constructs function info for frame state construction. |
| 223 | const FrameStateFunctionInfo* CreateFrameStateFunctionInfo( |
| 224 | FrameStateType type, int parameter_count, int local_count, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 225 | Handle<SharedFunctionInfo> shared_info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 226 | |
| 227 | private: |
| 228 | Zone* zone() const { return zone_; } |
| 229 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 230 | const CommonOperatorGlobalCache& cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 231 | Zone* const zone_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | } // namespace compiler |
| 237 | } // namespace internal |
| 238 | } // namespace v8 |
| 239 | |
| 240 | #endif // V8_COMPILER_COMMON_OPERATOR_H_ |