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 static const int kLaneWidth = 16 / kMaxLanes; 35 36 struct Replacement { 37 Node* node[kMaxLanes]; 38 SimdType type; // represents what input type is expected 39 }; 40 zone()41 Zone* zone() const { return zone_; } graph()42 Graph* graph() const { return graph_; } machine()43 MachineOperatorBuilder* machine() const { return machine_; } common()44 CommonOperatorBuilder* common() const { return common_; } signature()45 Signature<MachineRepresentation>* signature() const { return signature_; } 46 47 void LowerNode(Node* node); 48 bool DefaultLowering(Node* node); 49 50 void ReplaceNode(Node* old, Node** new_nodes); 51 bool HasReplacement(size_t index, Node* node); 52 Node** GetReplacements(Node* node); 53 Node** GetReplacementsWithType(Node* node, SimdType type); 54 SimdType ReplacementType(Node* node); 55 void PreparePhiReplacement(Node* phi); 56 void SetLoweredType(Node* node, Node* output); 57 void GetIndexNodes(Node* index, Node** new_indices); 58 void LowerLoadOp(MachineRepresentation rep, Node* node, 59 const Operator* load_op); 60 void LowerStoreOp(MachineRepresentation rep, Node* node, 61 const Operator* store_op, SimdType rep_type); 62 void LowerBinaryOp(Node* node, SimdType rep_type, const Operator* op); 63 64 struct NodeState { 65 Node* node; 66 int input_index; 67 }; 68 69 Zone* zone_; 70 Graph* const graph_; 71 MachineOperatorBuilder* machine_; 72 CommonOperatorBuilder* common_; 73 NodeMarker<State> state_; 74 ZoneDeque<NodeState> stack_; 75 Replacement* replacements_; 76 Signature<MachineRepresentation>* signature_; 77 Node* placeholder_; 78 int parameter_count_after_lowering_; 79 }; 80 81 } // namespace compiler 82 } // namespace internal 83 } // namespace v8 84 85 #endif // V8_COMPILER_SIMD_SCALAR_LOWERING_H_ 86