int64-lowering.h 3.45 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/compiler/simplified-operator.h"
16
#include "src/zone/zone-containers.h"
17 18 19

namespace v8 {
namespace internal {
20 21 22 23

template <typename T>
class Signature;

24 25
namespace compiler {

26 27
// Struct for CallDescriptors that need special lowering.
struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase {
28 29 30
  // Map from CallDescriptors that should be replaced, to the replacement
  // CallDescriptors.
  std::unordered_map<const CallDescriptor*, const CallDescriptor*> replacements;
31 32
};

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

41
  void LowerGraph();
42

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

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

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

54 55 56 57
  Zone* zone() const { return zone_; }
  Graph* graph() const { return graph_; }
  MachineOperatorBuilder* machine() const { return machine_; }
  CommonOperatorBuilder* common() const { return common_; }
58
  SimplifiedOperatorBuilder* simplified() const { return simplified_; }
59 60
  Signature<MachineRepresentation>* signature() const { return signature_; }

61
  void PushNode(Node* node);
62
  void LowerNode(Node* node);
63
  bool DefaultLowering(Node* node, bool low_word_only = false);
64 65
  void LowerComparison(Node* node, const Operator* signed_op,
                       const Operator* unsigned_op);
66
  void LowerWord64AtomicBinop(Node* node, const Operator* op);
67
  void LowerWord64AtomicNarrowOp(Node* node, const Operator* op);
68 69 70 71
  void LowerLoadOperator(Node* node, MachineRepresentation rep,
                         const Operator* load_op);
  void LowerStoreOperator(Node* node, MachineRepresentation rep,
                          const Operator* store_op);
72

73 74
  const CallDescriptor* LowerCallDescriptor(
      const CallDescriptor* call_descriptor);
75

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

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

91
  Zone* zone_;
92 93 94
  Graph* const graph_;
  MachineOperatorBuilder* machine_;
  CommonOperatorBuilder* common_;
95
  SimplifiedOperatorBuilder* simplified_;
96
  std::vector<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_