Line data Source code
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/js-graph.h"
11 : #include "src/compiler/machine-operator.h"
12 : #include "src/compiler/node-marker.h"
13 : #include "src/zone/zone-containers.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 : namespace compiler {
18 :
19 : class SimdScalarLowering {
20 : public:
21 : SimdScalarLowering(JSGraph* jsgraph,
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 { kFloat32x4, kInt32x4, kInt16x8, kInt8x16 };
32 :
33 : #if defined(V8_TARGET_BIG_ENDIAN)
34 : static constexpr int kLaneOffsets[16] = {15, 14, 13, 12, 11, 10, 9, 8,
35 : 7, 6, 5, 4, 3, 2, 1, 0};
36 : #else
37 : static constexpr int kLaneOffsets[16] = {0, 1, 2, 3, 4, 5, 6, 7,
38 : 8, 9, 10, 11, 12, 13, 14, 15};
39 : #endif
40 : struct Replacement {
41 : Node** node = nullptr;
42 : SimdType type; // represents output type
43 : int num_replacements = 0;
44 : };
45 :
46 : struct NodeState {
47 : Node* node;
48 : int input_index;
49 : };
50 :
51 : Zone* zone() const { return jsgraph_->zone(); }
52 16386 : Graph* graph() const { return jsgraph_->graph(); }
53 6960 : MachineOperatorBuilder* machine() const { return jsgraph_->machine(); }
54 4278 : CommonOperatorBuilder* common() const { return jsgraph_->common(); }
55 : Signature<MachineRepresentation>* signature() const { return signature_; }
56 :
57 : void LowerNode(Node* node);
58 : bool DefaultLowering(Node* node);
59 :
60 : int NumLanes(SimdType type);
61 : void ReplaceNode(Node* old, Node** new_nodes, int count);
62 : bool HasReplacement(size_t index, Node* node);
63 : Node** GetReplacements(Node* node);
64 : int ReplacementCount(Node* node);
65 : void Float32ToInt32(Node** replacements, Node** result);
66 : void Int32ToFloat32(Node** replacements, Node** result);
67 : Node** GetReplacementsWithType(Node* node, SimdType type);
68 : SimdType ReplacementType(Node* node);
69 : void PreparePhiReplacement(Node* phi);
70 : void SetLoweredType(Node* node, Node* output);
71 : void GetIndexNodes(Node* index, Node** new_indices, SimdType type);
72 : void LowerLoadOp(MachineRepresentation rep, Node* node,
73 : const Operator* load_op, SimdType type);
74 : void LowerStoreOp(MachineRepresentation rep, Node* node,
75 : const Operator* store_op, SimdType rep_type);
76 : void LowerBinaryOp(Node* node, SimdType input_rep_type, const Operator* op);
77 : void LowerCompareOp(Node* node, SimdType input_rep_type, const Operator* op,
78 : bool invert_inputs = false);
79 : Node* FixUpperBits(Node* input, int32_t shift);
80 : void LowerBinaryOpForSmallInt(Node* node, SimdType input_rep_type,
81 : const Operator* op);
82 : Node* Mask(Node* input, int32_t mask);
83 : void LowerSaturateBinaryOp(Node* node, SimdType input_rep_type,
84 : const Operator* op, bool is_signed);
85 : void LowerUnaryOp(Node* node, SimdType input_rep_type, const Operator* op);
86 : void LowerIntMinMax(Node* node, const Operator* op, bool is_max,
87 : SimdType type);
88 : void LowerConvertFromFloat(Node* node, bool is_signed);
89 : void LowerShiftOp(Node* node, SimdType type);
90 : Node* BuildF64Trunc(Node* input);
91 : void LowerNotEqual(Node* node, SimdType input_rep_type, const Operator* op);
92 : MachineType MachineTypeFrom(SimdType simdType);
93 :
94 : JSGraph* const jsgraph_;
95 : NodeMarker<State> state_;
96 : ZoneDeque<NodeState> stack_;
97 : Replacement* replacements_;
98 : Signature<MachineRepresentation>* signature_;
99 : Node* placeholder_;
100 : int parameter_count_after_lowering_;
101 : };
102 :
103 : } // namespace compiler
104 : } // namespace internal
105 : } // namespace v8
106 :
107 : #endif // V8_COMPILER_SIMD_SCALAR_LOWERING_H_
|