int64-lowering.h 3.03 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
// Struct for CallDescriptors that need special lowering.
struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase {
27 28 29
  // Map from CallDescriptors that should be replaced, to the replacement
  // CallDescriptors.
  std::unordered_map<const CallDescriptor*, const CallDescriptor*> replacements;
30 31
};

32
class V8_EXPORT_PRIVATE Int64Lowering {
33
 public:
34 35 36 37 38
  Int64Lowering(
      Graph* graph, MachineOperatorBuilder* machine,
      CommonOperatorBuilder* common, Zone* zone,
      Signature<MachineRepresentation>* signature,
      std::unique_ptr<Int64LoweringSpecialCase> special_case = nullptr);
39

40
  void LowerGraph();
41

42 43 44
  static int GetParameterCountAfterLowering(
      Signature<MachineRepresentation>* signature);

45
 private:
46
  enum class State : uint8_t { kUnvisited, kOnStack, kVisited };
47 48 49 50 51 52

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

53 54 55 56 57 58
  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_; }

59
  void PushNode(Node* node);
60
  void LowerNode(Node* node);
61
  bool DefaultLowering(Node* node, bool low_word_only = false);
62 63
  void LowerComparison(Node* node, const Operator* signed_op,
                       const Operator* unsigned_op);
64
  void LowerWord64AtomicBinop(Node* node, const Operator* op);
65
  void LowerWord64AtomicNarrowOp(Node* node, const Operator* op);
66

67 68
  const CallDescriptor* LowerCallDescriptor(
      const CallDescriptor* call_descriptor);
69

70 71 72 73 74
  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);
75
  void PreparePhiReplacement(Node* phi);
76
  void GetIndexNodes(Node* index, Node** index_low, Node** index_high);
77
  void ReplaceNodeWithProjections(Node* node);
78
  void LowerMemoryBaseAndIndex(Node* node);
79

80 81 82 83 84
  struct NodeState {
    Node* node;
    int input_index;
  };

85
  Zone* zone_;
86 87 88 89
  Graph* const graph_;
  MachineOperatorBuilder* machine_;
  CommonOperatorBuilder* common_;
  NodeMarker<State> state_;
90
  ZoneDeque<NodeState> stack_;
91
  Replacement* replacements_;
92
  Signature<MachineRepresentation>* signature_;
93
  Node* placeholder_;
94
  std::unique_ptr<Int64LoweringSpecialCase> special_case_;
95 96 97 98 99 100
};

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

101
#endif  // V8_COMPILER_INT64_LOWERING_H_