• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/diamond.h"
10 #include "src/compiler/graph.h"
11 #include "src/compiler/machine-graph.h"
12 #include "src/compiler/machine-operator.h"
13 #include "src/compiler/node-marker.h"
14 #include "src/zone/zone-containers.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 template <typename T>
20 class Signature;
21 
22 namespace compiler {
23 
24 class SimdScalarLowering {
25  public:
26   SimdScalarLowering(MachineGraph* mcgraph,
27                      Signature<MachineRepresentation>* signature);
28 
29   void LowerGraph();
30 
31   int GetParameterCountAfterLowering();
32 
33  private:
34   enum class State : uint8_t { kUnvisited, kOnStack, kVisited };
35 
36   enum class SimdType : uint8_t {
37     kFloat64x2,
38     kFloat32x4,
39     kInt64x2,
40     kInt32x4,
41     kInt16x8,
42     kInt8x16
43   };
44 
45 #if defined(V8_TARGET_BIG_ENDIAN)
46   static constexpr int kLaneOffsets[16] = {15, 14, 13, 12, 11, 10, 9, 8,
47                                            7,  6,  5,  4,  3,  2,  1, 0};
48 #else
49   static constexpr int kLaneOffsets[16] = {0, 1, 2,  3,  4,  5,  6,  7,
50                                            8, 9, 10, 11, 12, 13, 14, 15};
51 #endif
52   struct Replacement {
53     Node** node = nullptr;
54     SimdType type;  // represents output type
55     int num_replacements = 0;
56   };
57 
58   struct NodeState {
59     Node* node;
60     int input_index;
61   };
62 
zone()63   Zone* zone() const { return mcgraph_->zone(); }
graph()64   Graph* graph() const { return mcgraph_->graph(); }
machine()65   MachineOperatorBuilder* machine() const { return mcgraph_->machine(); }
common()66   CommonOperatorBuilder* common() const { return mcgraph_->common(); }
signature()67   Signature<MachineRepresentation>* signature() const { return signature_; }
68 
69   void LowerNode(Node* node);
70   bool DefaultLowering(Node* node);
71 
72   int NumLanes(SimdType type);
73   void ReplaceNode(Node* old, Node** new_nodes, int count);
74   bool HasReplacement(size_t index, Node* node);
75   Node** GetReplacements(Node* node);
76   int ReplacementCount(Node* node);
77   void Float64ToInt64(Node** replacements, Node** result);
78   void Float32ToInt32(Node** replacements, Node** result);
79   void Int32ToFloat32(Node** replacements, Node** result);
80   void Int64ToFloat64(Node** replacements, Node** result);
81   void Int64ToInt32(Node** replacements, Node** result);
82   template <typename T>
83   void Int32ToSmallerInt(Node** replacements, Node** result);
84   template <typename T>
85   void SmallerIntToInt32(Node** replacements, Node** result);
86   void Int32ToInt64(Node** replacements, Node** result);
87   Node** GetReplacementsWithType(Node* node, SimdType type);
88   SimdType ReplacementType(Node* node);
89   void PreparePhiReplacement(Node* phi);
90   void SetLoweredType(Node* node, Node* output);
91   void GetIndexNodes(Node* index, Node** new_indices, SimdType type);
92   void LowerLoadOp(Node* node, SimdType type);
93   void LowerLoadTransformOp(Node* node, SimdType type);
94   void LowerStoreOp(Node* node);
95   void LowerBinaryOp(Node* node, SimdType input_rep_type, const Operator* op,
96                      bool not_horizontal = true);
97   Node* ConstructPhiForComparison(Diamond d, SimdType rep_type, int true_value,
98                                   int false_value);
99   void LowerCompareOp(Node* node, SimdType input_rep_type, const Operator* op,
100                       bool invert_inputs = false);
101   Node* FixUpperBits(Node* input, int32_t shift);
102   void LowerBinaryOpForSmallInt(Node* node, SimdType input_rep_type,
103                                 const Operator* op, bool not_horizontal = true);
104   Node* Mask(Node* input, int32_t mask);
105   void LowerSaturateBinaryOp(Node* node, SimdType input_rep_type,
106                              const Operator* op, bool is_signed);
107   void LowerUnaryOp(Node* node, SimdType input_rep_type, const Operator* op);
108   void LowerIntMinMax(Node* node, const Operator* op, bool is_max,
109                       SimdType type);
110   void LowerConvertFromFloat(Node* node, bool is_signed);
111   void LowerConvertFromInt(Node* node, SimdType input_rep_type,
112                            SimdType output_rep_type, bool is_signed,
113                            int start_index);
114   void LowerPack(Node* node, SimdType input_rep_type, SimdType output_rep_type,
115                  bool is_signed);
116   void LowerShiftOp(Node* node, SimdType type);
117   Node* BuildF64Trunc(Node* input);
118   void LowerNotEqual(Node* node, SimdType input_rep_type, const Operator* op);
119   MachineType MachineTypeFrom(SimdType simdType);
120   void LowerBitMaskOp(Node* node, SimdType rep_type, int msb_index);
121   void LowerAllTrueOp(Node* node, SimdType rep_type);
122   void LowerFloatPseudoMinMax(Node* node, const Operator* op, bool is_max,
123                               SimdType type);
124 
125   MachineGraph* const mcgraph_;
126   NodeMarker<State> state_;
127   ZoneDeque<NodeState> stack_;
128   Replacement* replacements_;
129   Signature<MachineRepresentation>* signature_;
130   Node* placeholder_;
131   int parameter_count_after_lowering_;
132 };
133 
134 }  // namespace compiler
135 }  // namespace internal
136 }  // namespace v8
137 
138 #endif  // V8_COMPILER_SIMD_SCALAR_LOWERING_H_
139