1 // Copyright 2014 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_INT64_LOWERING_H_ 6 #define V8_COMPILER_INT64_LOWERING_H_ 7 8 #include <memory> 9 10 #include "src/common/globals.h" 11 #include "src/compiler/common-operator.h" 12 #include "src/compiler/graph.h" 13 #include "src/compiler/machine-operator.h" 14 #include "src/compiler/node-marker.h" 15 #include "src/zone/zone-containers.h" 16 17 namespace v8 { 18 namespace internal { 19 20 template <typename T> 21 class Signature; 22 23 namespace compiler { 24 25 // Struct for CallDescriptors that need special lowering. 26 struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase { 27 // Map from CallDescriptors that should be replaced, to the replacement 28 // CallDescriptors. 29 std::unordered_map<const CallDescriptor*, const CallDescriptor*> replacements; 30 }; 31 32 class V8_EXPORT_PRIVATE Int64Lowering { 33 public: 34 Int64Lowering( 35 Graph* graph, MachineOperatorBuilder* machine, 36 CommonOperatorBuilder* common, Zone* zone, 37 Signature<MachineRepresentation>* signature, 38 std::unique_ptr<Int64LoweringSpecialCase> special_case = nullptr); 39 40 void LowerGraph(); 41 42 static int GetParameterCountAfterLowering( 43 Signature<MachineRepresentation>* signature); 44 45 private: 46 enum class State : uint8_t { kUnvisited, kOnStack, kVisited }; 47 48 struct Replacement { 49 Node* low; 50 Node* high; 51 }; 52 zone()53 Zone* zone() const { return zone_; } graph()54 Graph* graph() const { return graph_; } machine()55 MachineOperatorBuilder* machine() const { return machine_; } common()56 CommonOperatorBuilder* common() const { return common_; } signature()57 Signature<MachineRepresentation>* signature() const { return signature_; } 58 59 void PushNode(Node* node); 60 void LowerNode(Node* node); 61 bool DefaultLowering(Node* node, bool low_word_only = false); 62 void LowerComparison(Node* node, const Operator* signed_op, 63 const Operator* unsigned_op); 64 void LowerWord64AtomicBinop(Node* node, const Operator* op); 65 void LowerWord64AtomicNarrowOp(Node* node, const Operator* op); 66 67 const CallDescriptor* LowerCallDescriptor( 68 const CallDescriptor* call_descriptor); 69 70 void ReplaceNode(Node* old, Node* new_low, Node* new_high); 71 bool HasReplacementLow(Node* node); 72 Node* GetReplacementLow(Node* node); 73 bool HasReplacementHigh(Node* node); 74 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 struct NodeState { 81 Node* node; 82 int input_index; 83 }; 84 85 Zone* zone_; 86 Graph* const graph_; 87 MachineOperatorBuilder* machine_; 88 CommonOperatorBuilder* common_; 89 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 } // namespace compiler 98 } // namespace internal 99 } // namespace v8 100 101 #endif // V8_COMPILER_INT64_LOWERING_H_ 102