1 // Copyright 2016 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_SIMD_SCALAR_LOWERING_H_ 6 #define V8_COMPILER_SIMD_SCALAR_LOWERING_H_ 7 8 #include "src/compiler/common-operator.h" 9 #include "src/compiler/graph.h" 10 #include "src/compiler/machine-operator.h" 11 #include "src/compiler/node-marker.h" 12 #include "src/zone/zone-containers.h" 13 14 namespace v8 { 15 namespace internal { 16 namespace compiler { 17 18 class SimdScalarLowering { 19 public: 20 SimdScalarLowering(Graph* graph, MachineOperatorBuilder* machine, 21 CommonOperatorBuilder* common, Zone* zone, 22 Signature<MachineRepresentation>* signature); 23 24 void LowerGraph(); 25 26 int GetParameterCountAfterLowering(); 27 28 private: 29 enum class State : uint8_t { kUnvisited, kOnStack, kVisited }; 30 31 enum class SimdType : uint8_t { kInt32, kFloat32 }; 32 33 static const int kMaxLanes = 4; 34 35 struct Replacement { 36 Node* node[kMaxLanes]; 37 SimdType type; // represents what input type is expected 38 }; 39 zone()40 Zone* zone() const { return zone_; } graph()41 Graph* graph() const { return graph_; } machine()42 MachineOperatorBuilder* machine() const { return machine_; } common()43 CommonOperatorBuilder* common() const { return common_; } signature()44 Signature<MachineRepresentation>* signature() const { return signature_; } 45 46 void LowerNode(Node* node); 47 bool DefaultLowering(Node* node); 48 49 void ReplaceNode(Node* old, Node** new_nodes); 50 bool HasReplacement(size_t index, Node* node); 51 Node** GetReplacements(Node* node); 52 Node** GetReplacementsWithType(Node* node, SimdType type); 53 SimdType ReplacementType(Node* node); 54 void PreparePhiReplacement(Node* phi); 55 void SetLoweredType(Node* node, Node* output); 56 57 struct NodeState { 58 Node* node; 59 int input_index; 60 }; 61 62 Zone* zone_; 63 Graph* const graph_; 64 MachineOperatorBuilder* machine_; 65 CommonOperatorBuilder* common_; 66 NodeMarker<State> state_; 67 ZoneDeque<NodeState> stack_; 68 Replacement* replacements_; 69 Signature<MachineRepresentation>* signature_; 70 Node* placeholder_; 71 int parameter_count_after_lowering_; 72 }; 73 74 } // namespace compiler 75 } // namespace internal 76 } // namespace v8 77 78 #endif // V8_COMPILER_SIMD_SCALAR_LOWERING_H_ 79