| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 | 6 |
| 7 #include "src/assembler.h" | 7 #include "src/assembler.h" |
| 8 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
| 9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
| 10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 #define CACHED_OP_LIST(V) \ | 106 #define CACHED_OP_LIST(V) \ |
| 107 V(Dead, Operator::kFoldable, 0, 0, 0, 1) \ | 107 V(Dead, Operator::kFoldable, 0, 0, 0, 1) \ |
| 108 V(End, Operator::kFoldable, 0, 0, 1, 0) \ | 108 V(End, Operator::kFoldable, 0, 0, 1, 0) \ |
| 109 V(IfTrue, Operator::kFoldable, 0, 0, 1, 1) \ | 109 V(IfTrue, Operator::kFoldable, 0, 0, 1, 1) \ |
| 110 V(IfFalse, Operator::kFoldable, 0, 0, 1, 1) \ | 110 V(IfFalse, Operator::kFoldable, 0, 0, 1, 1) \ |
| 111 V(Throw, Operator::kFoldable, 1, 1, 1, 1) \ | 111 V(Throw, Operator::kFoldable, 1, 1, 1, 1) \ |
| 112 V(Return, Operator::kNoProperties, 1, 1, 1, 1) | 112 V(Return, Operator::kNoProperties, 1, 1, 1, 1) |
| 113 | 113 |
| 114 | 114 |
| 115 #define CACHED_LOOP_LIST(V) \ |
| 116 V(1) \ |
| 117 V(2) |
| 118 |
| 119 |
| 120 #define CACHED_MERGE_LIST(V) \ |
| 121 V(1) \ |
| 122 V(2) \ |
| 123 V(3) \ |
| 124 V(4) \ |
| 125 V(5) \ |
| 126 V(6) \ |
| 127 V(7) \ |
| 128 V(8) |
| 129 |
| 130 |
| 131 #define CACHED_PARAMETER_LIST(V) \ |
| 132 V(0) \ |
| 133 V(1) \ |
| 134 V(2) \ |
| 135 V(3) \ |
| 136 V(4) \ |
| 137 V(5) \ |
| 138 V(6) |
| 139 |
| 140 |
| 115 struct CommonOperatorGlobalCache FINAL { | 141 struct CommonOperatorGlobalCache FINAL { |
| 116 #define CACHED(Name, properties, value_input_count, effect_input_count, \ | 142 #define CACHED(Name, properties, value_input_count, effect_input_count, \ |
| 117 control_input_count, control_output_count) \ | 143 control_input_count, control_output_count) \ |
| 118 struct Name##Operator FINAL : public Operator { \ | 144 struct Name##Operator FINAL : public Operator { \ |
| 119 Name##Operator() \ | 145 Name##Operator() \ |
| 120 : Operator(IrOpcode::k##Name, properties, #Name, value_input_count, \ | 146 : Operator(IrOpcode::k##Name, properties, #Name, value_input_count, \ |
| 121 effect_input_count, control_input_count, 0, 0, \ | 147 effect_input_count, control_input_count, 0, 0, \ |
| 122 control_output_count) {} \ | 148 control_output_count) {} \ |
| 123 }; \ | 149 }; \ |
| 124 Name##Operator k##Name##Operator; | 150 Name##Operator k##Name##Operator; |
| 125 CACHED_OP_LIST(CACHED) | 151 CACHED_OP_LIST(CACHED) |
| 126 #undef CACHED | 152 #undef CACHED |
| 127 | 153 |
| 128 template <BranchHint kBranchHint> | 154 template <BranchHint kBranchHint> |
| 129 struct BranchOperator FINAL : public Operator1<BranchHint> { | 155 struct BranchOperator FINAL : public Operator1<BranchHint> { |
| 130 BranchOperator() | 156 BranchOperator() |
| 131 : Operator1<BranchHint>( // -- | 157 : Operator1<BranchHint>( // -- |
| 132 IrOpcode::kBranch, Operator::kFoldable, // opcode | 158 IrOpcode::kBranch, Operator::kFoldable, // opcode |
| 133 "Branch", // name | 159 "Branch", // name |
| 134 1, 0, 1, 0, 0, 2, // counts | 160 1, 0, 1, 0, 0, 2, // counts |
| 135 kBranchHint) {} // parameter | 161 kBranchHint) {} // parameter |
| 136 }; | 162 }; |
| 137 BranchOperator<BranchHint::kNone> kBranchNoneOperator; | 163 BranchOperator<BranchHint::kNone> kBranchNoneOperator; |
| 138 BranchOperator<BranchHint::kTrue> kBranchTrueOperator; | 164 BranchOperator<BranchHint::kTrue> kBranchTrueOperator; |
| 139 BranchOperator<BranchHint::kFalse> kBranchFalseOperator; | 165 BranchOperator<BranchHint::kFalse> kBranchFalseOperator; |
| 166 |
| 167 template <size_t kInputCount> |
| 168 struct LoopOperator FINAL : public Operator { |
| 169 LoopOperator() |
| 170 : Operator( // -- |
| 171 IrOpcode::kLoop, Operator::kFoldable, // opcode |
| 172 "Loop", // name |
| 173 0, 0, kInputCount, 0, 0, 1) {} // counts |
| 174 }; |
| 175 #define CACHED_LOOP(input_count) \ |
| 176 LoopOperator<input_count> kLoop##input_count##Operator; |
| 177 CACHED_LOOP_LIST(CACHED_LOOP) |
| 178 #undef CACHED_LOOP |
| 179 |
| 180 template <size_t kInputCount> |
| 181 struct MergeOperator FINAL : public Operator { |
| 182 MergeOperator() |
| 183 : Operator( // -- |
| 184 IrOpcode::kMerge, Operator::kFoldable, // opcode |
| 185 "Merge", // name |
| 186 0, 0, kInputCount, 0, 0, 1) {} // counts |
| 187 }; |
| 188 #define CACHED_MERGE(input_count) \ |
| 189 MergeOperator<input_count> kMerge##input_count##Operator; |
| 190 CACHED_MERGE_LIST(CACHED_MERGE) |
| 191 #undef CACHED_MERGE |
| 192 |
| 193 template <int kIndex> |
| 194 struct ParameterOperator FINAL : public Operator1<int> { |
| 195 ParameterOperator() |
| 196 : Operator1<int>( // -- |
| 197 IrOpcode::kParameter, Operator::kPure, // opcode |
| 198 "Parameter", // name |
| 199 1, 0, 0, 1, 0, 0, // counts, |
| 200 kIndex) {} // parameter |
| 201 }; |
| 202 #define CACHED_PARAMETER(index) \ |
| 203 ParameterOperator<index> kParameter##index##Operator; |
| 204 CACHED_PARAMETER_LIST(CACHED_PARAMETER) |
| 205 #undef CACHED_PARAMETER |
| 140 }; | 206 }; |
| 141 | 207 |
| 142 | 208 |
| 143 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache = | 209 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache = |
| 144 LAZY_INSTANCE_INITIALIZER; | 210 LAZY_INSTANCE_INITIALIZER; |
| 145 | 211 |
| 146 | 212 |
| 147 CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone) | 213 CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone) |
| 148 : cache_(kCache.Get()), zone_(zone) {} | 214 : cache_(kCache.Get()), zone_(zone) {} |
| 149 | 215 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 174 const Operator* CommonOperatorBuilder::Start(int num_formal_parameters) { | 240 const Operator* CommonOperatorBuilder::Start(int num_formal_parameters) { |
| 175 // Outputs are formal parameters, plus context, receiver, and JSFunction. | 241 // Outputs are formal parameters, plus context, receiver, and JSFunction. |
| 176 const int value_output_count = num_formal_parameters + 3; | 242 const int value_output_count = num_formal_parameters + 3; |
| 177 return new (zone()) Operator( // -- | 243 return new (zone()) Operator( // -- |
| 178 IrOpcode::kStart, Operator::kFoldable, // opcode | 244 IrOpcode::kStart, Operator::kFoldable, // opcode |
| 179 "Start", // name | 245 "Start", // name |
| 180 0, 0, 0, value_output_count, 1, 1); // counts | 246 0, 0, 0, value_output_count, 1, 1); // counts |
| 181 } | 247 } |
| 182 | 248 |
| 183 | 249 |
| 184 const Operator* CommonOperatorBuilder::Merge(int controls) { | 250 const Operator* CommonOperatorBuilder::Loop(int control_input_count) { |
| 251 switch (control_input_count) { |
| 252 #define CACHED_LOOP(input_count) \ |
| 253 case input_count: \ |
| 254 return &cache_.kLoop##input_count##Operator; |
| 255 CACHED_LOOP_LIST(CACHED_LOOP) |
| 256 #undef CACHED_LOOP |
| 257 default: |
| 258 break; |
| 259 } |
| 260 // Uncached. |
| 261 return new (zone()) Operator( // -- |
| 262 IrOpcode::kLoop, Operator::kFoldable, // opcode |
| 263 "Loop", // name |
| 264 0, 0, control_input_count, 0, 0, 1); // counts |
| 265 } |
| 266 |
| 267 |
| 268 const Operator* CommonOperatorBuilder::Merge(int control_input_count) { |
| 269 switch (control_input_count) { |
| 270 #define CACHED_MERGE(input_count) \ |
| 271 case input_count: \ |
| 272 return &cache_.kMerge##input_count##Operator; |
| 273 CACHED_MERGE_LIST(CACHED_MERGE) |
| 274 #undef CACHED_MERGE |
| 275 default: |
| 276 break; |
| 277 } |
| 278 // Uncached. |
| 185 return new (zone()) Operator( // -- | 279 return new (zone()) Operator( // -- |
| 186 IrOpcode::kMerge, Operator::kFoldable, // opcode | 280 IrOpcode::kMerge, Operator::kFoldable, // opcode |
| 187 "Merge", // name | 281 "Merge", // name |
| 188 0, 0, controls, 0, 0, 1); // counts | 282 0, 0, control_input_count, 0, 0, 1); // counts |
| 189 } | 283 } |
| 190 | 284 |
| 191 | 285 |
| 192 const Operator* CommonOperatorBuilder::Loop(int controls) { | |
| 193 return new (zone()) Operator( // -- | |
| 194 IrOpcode::kLoop, Operator::kFoldable, // opcode | |
| 195 "Loop", // name | |
| 196 0, 0, controls, 0, 0, 1); // counts | |
| 197 } | |
| 198 | |
| 199 | |
| 200 const Operator* CommonOperatorBuilder::Terminate(int effects) { | 286 const Operator* CommonOperatorBuilder::Terminate(int effects) { |
| 201 return new (zone()) Operator( // -- | 287 return new (zone()) Operator( // -- |
| 202 IrOpcode::kTerminate, Operator::kPure, // opcode | 288 IrOpcode::kTerminate, Operator::kPure, // opcode |
| 203 "Terminate", // name | 289 "Terminate", // name |
| 204 0, effects, 1, 0, 0, 1); // counts | 290 0, effects, 1, 0, 0, 1); // counts |
| 205 } | 291 } |
| 206 | 292 |
| 207 | 293 |
| 208 const Operator* CommonOperatorBuilder::Parameter(int index) { | 294 const Operator* CommonOperatorBuilder::Parameter(int index) { |
| 295 switch (index) { |
| 296 #define CACHED_PARAMETER(index) \ |
| 297 case index: \ |
| 298 return &cache_.kParameter##index##Operator; |
| 299 CACHED_PARAMETER_LIST(CACHED_PARAMETER) |
| 300 #undef CACHED_PARAMETER |
| 301 default: |
| 302 break; |
| 303 } |
| 304 // Uncached. |
| 209 return new (zone()) Operator1<int>( // -- | 305 return new (zone()) Operator1<int>( // -- |
| 210 IrOpcode::kParameter, Operator::kPure, // opcode | 306 IrOpcode::kParameter, Operator::kPure, // opcode |
| 211 "Parameter", // name | 307 "Parameter", // name |
| 212 1, 0, 0, 1, 0, 0, // counts | 308 1, 0, 0, 1, 0, 0, // counts |
| 213 index); // parameter | 309 index); // parameter |
| 214 } | 310 } |
| 215 | 311 |
| 216 | 312 |
| 217 const Operator* CommonOperatorBuilder::Int32Constant(int32_t value) { | 313 const Operator* CommonOperatorBuilder::Int32Constant(int32_t value) { |
| 218 return new (zone()) Operator1<int32_t>( // -- | 314 return new (zone()) Operator1<int32_t>( // -- |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 return new (zone()) Operator1<size_t>( // -- | 468 return new (zone()) Operator1<size_t>( // -- |
| 373 IrOpcode::kProjection, Operator::kPure, // opcode | 469 IrOpcode::kProjection, Operator::kPure, // opcode |
| 374 "Projection", // name | 470 "Projection", // name |
| 375 1, 0, 0, 1, 0, 0, // counts | 471 1, 0, 0, 1, 0, 0, // counts |
| 376 index); // parameter | 472 index); // parameter |
| 377 } | 473 } |
| 378 | 474 |
| 379 } // namespace compiler | 475 } // namespace compiler |
| 380 } // namespace internal | 476 } // namespace internal |
| 381 } // namespace v8 | 477 } // namespace v8 |
| OLD | NEW |