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