int64-lowering.h 3.36 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_INT64_LOWERING_H_
#define V8_COMPILER_INT64_LOWERING_H_
7

8 9
#include <memory>

10
#include "src/common/globals.h"
11 12 13 14
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-marker.h"
15
#include "src/zone/zone-containers.h"
16 17 18

namespace v8 {
namespace internal {
19 20 21 22

template <typename T>
class Signature;

23 24
namespace compiler {

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// Struct for CallDescriptors that need special lowering.
struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase {
  Int64LoweringSpecialCase()
      : bigint_to_i64_call_descriptor(nullptr),
        i64_to_bigint_call_descriptor(nullptr),
        bigint_to_i32_pair_call_descriptor(nullptr),
        i32_pair_to_bigint_call_descriptor(nullptr) {}

  // CallDescriptors that need special lowering.
  CallDescriptor* bigint_to_i64_call_descriptor;
  CallDescriptor* i64_to_bigint_call_descriptor;

  // The replacement CallDescriptors.
  CallDescriptor* bigint_to_i32_pair_call_descriptor;
  CallDescriptor* i32_pair_to_bigint_call_descriptor;
};

42
class V8_EXPORT_PRIVATE Int64Lowering {
43
 public:
44 45 46 47 48
  Int64Lowering(
      Graph* graph, MachineOperatorBuilder* machine,
      CommonOperatorBuilder* common, Zone* zone,
      Signature<MachineRepresentation>* signature,
      std::unique_ptr<Int64LoweringSpecialCase> special_case = nullptr);
49

50
  void LowerGraph();
51

52 53 54
  static int GetParameterCountAfterLowering(
      Signature<MachineRepresentation>* signature);

55
 private:
56
  enum class State : uint8_t { kUnvisited, kOnStack, kVisited };
57 58 59 60 61 62

  struct Replacement {
    Node* low;
    Node* high;
  };

63 64 65 66 67 68
  Zone* zone() const { return zone_; }
  Graph* graph() const { return graph_; }
  MachineOperatorBuilder* machine() const { return machine_; }
  CommonOperatorBuilder* common() const { return common_; }
  Signature<MachineRepresentation>* signature() const { return signature_; }

69
  void PushNode(Node* node);
70
  void LowerNode(Node* node);
71
  bool DefaultLowering(Node* node, bool low_word_only = false);
72 73
  void LowerComparison(Node* node, const Operator* signed_op,
                       const Operator* unsigned_op);
74
  void LowerWord64AtomicBinop(Node* node, const Operator* op);
75
  void LowerWord64AtomicNarrowOp(Node* node, const Operator* op);
76

77 78
  CallDescriptor* LowerCallDescriptor(const CallDescriptor* call_descriptor);

79 80 81 82 83
  void ReplaceNode(Node* old, Node* new_low, Node* new_high);
  bool HasReplacementLow(Node* node);
  Node* GetReplacementLow(Node* node);
  bool HasReplacementHigh(Node* node);
  Node* GetReplacementHigh(Node* node);
84
  void PreparePhiReplacement(Node* phi);
85
  void GetIndexNodes(Node* index, Node** index_low, Node** index_high);
86
  void ReplaceNodeWithProjections(Node* node);
87
  void LowerMemoryBaseAndIndex(Node* node);
88

89 90 91 92 93
  struct NodeState {
    Node* node;
    int input_index;
  };

94
  Zone* zone_;
95 96 97 98
  Graph* const graph_;
  MachineOperatorBuilder* machine_;
  CommonOperatorBuilder* common_;
  NodeMarker<State> state_;
99
  ZoneDeque<NodeState> stack_;
100
  Replacement* replacements_;
101
  Signature<MachineRepresentation>* signature_;
102
  Node* placeholder_;
103
  std::unique_ptr<Int64LoweringSpecialCase> special_case_;
104 105 106 107 108 109
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

110
#endif  // V8_COMPILER_INT64_LOWERING_H_