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/compiler/simplified-operator.h" 16 #include "src/zone/zone-containers.h" 17 18 namespace v8 { 19 namespace internal { 20 21 template <typename T> 22 class Signature; 23 24 namespace compiler { 25 26 // Struct for CallDescriptors that need special lowering. 27 struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase { 28 // Map from CallDescriptors that should be replaced, to the replacement 29 // CallDescriptors. 30 std::unordered_map<const CallDescriptor*, const CallDescriptor*> replacements; 31 }; 32 33 class V8_EXPORT_PRIVATE Int64Lowering { 34 public: 35 Int64Lowering( 36 Graph* graph, MachineOperatorBuilder* machine, 37 CommonOperatorBuilder* common, SimplifiedOperatorBuilder* simplified_, 38 Zone* zone, Signature<MachineRepresentation>* signature, 39 std::unique_ptr<Int64LoweringSpecialCase> special_case = nullptr); 40 41 void LowerGraph(); 42 43 static int GetParameterCountAfterLowering( 44 Signature<MachineRepresentation>* signature); 45 46 private: 47 enum class State : uint8_t { kUnvisited, kOnStack, kVisited }; 48 49 struct Replacement { 50 Node* low; 51 Node* high; 52 }; 53 zone()54 Zone* zone() const { return zone_; } graph()55 Graph* graph() const { return graph_; } machine()56 MachineOperatorBuilder* machine() const { return machine_; } common()57 CommonOperatorBuilder* common() const { return common_; } simplified()58 SimplifiedOperatorBuilder* simplified() const { return simplified_; } signature()59 Signature<MachineRepresentation>* signature() const { return signature_; } 60 61 void PushNode(Node* node); 62 void LowerNode(Node* node); 63 bool DefaultLowering(Node* node, bool low_word_only = false); 64 void LowerComparison(Node* node, const Operator* signed_op, 65 const Operator* unsigned_op); 66 void LowerWord64AtomicBinop(Node* node, const Operator* op); 67 void LowerWord64AtomicNarrowOp(Node* node, const Operator* op); 68 void LowerLoadOperator(Node* node, MachineRepresentation rep, 69 const Operator* load_op); 70 void LowerStoreOperator(Node* node, MachineRepresentation rep, 71 const Operator* store_op); 72 73 const CallDescriptor* LowerCallDescriptor( 74 const CallDescriptor* call_descriptor); 75 76 void ReplaceNode(Node* old, Node* new_low, Node* new_high); 77 bool HasReplacementLow(Node* node); 78 Node* GetReplacementLow(Node* node); 79 bool HasReplacementHigh(Node* node); 80 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 struct NodeState { 87 Node* node; 88 int input_index; 89 }; 90 91 Zone* zone_; 92 Graph* const graph_; 93 MachineOperatorBuilder* machine_; 94 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 } // namespace compiler 105 } // namespace internal 106 } // namespace v8 107 108 #endif // V8_COMPILER_INT64_LOWERING_H_ 109