int64-lowering.h 3.34 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
#include "src/common/globals.h"
9 10 11 12
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-marker.h"
13
#include "src/zone/zone-containers.h"
14 15 16

namespace v8 {
namespace internal {
17 18 19 20

template <typename T>
class Signature;

21 22
namespace compiler {

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
// 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;
};

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

48
  void LowerGraph();
49

50 51 52
  static int GetParameterCountAfterLowering(
      Signature<MachineRepresentation>* signature);

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

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

61 62 63 64 65 66
  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_; }

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

75 76
  CallDescriptor* LowerCallDescriptor(const CallDescriptor* call_descriptor);

77 78 79 80 81
  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);
82
  void PreparePhiReplacement(Node* phi);
83
  void GetIndexNodes(Node* index, Node** index_low, Node** index_high);
84
  void ReplaceNodeWithProjections(Node* node);
85
  void LowerMemoryBaseAndIndex(Node* node);
86

87 88 89 90 91
  struct NodeState {
    Node* node;
    int input_index;
  };

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

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

108
#endif  // V8_COMPILER_INT64_LOWERING_H_