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_SIMPLIFIED_LOWERING_H_ 6 #define V8_COMPILER_SIMPLIFIED_LOWERING_H_ 7 8 #include "src/compiler/js-graph.h" 9 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/node.h" 11 #include "src/compiler/simplified-operator.h" 12 13 namespace v8 { 14 namespace internal { 15 16 class TickCounter; 17 18 namespace compiler { 19 20 // Forward declarations. 21 class NodeOriginTable; 22 class RepresentationChanger; 23 class RepresentationSelector; 24 class SourcePositionTable; 25 class TypeCache; 26 27 class V8_EXPORT_PRIVATE SimplifiedLowering final { 28 public: 29 SimplifiedLowering(JSGraph* jsgraph, JSHeapBroker* broker, Zone* zone, 30 SourcePositionTable* source_position, 31 NodeOriginTable* node_origins, 32 PoisoningMitigationLevel poisoning_level, 33 TickCounter* tick_counter, Linkage* linkage); 34 ~SimplifiedLowering() = default; 35 36 void LowerAllNodes(); 37 38 void DoMax(Node* node, Operator const* op, MachineRepresentation rep); 39 void DoMin(Node* node, Operator const* op, MachineRepresentation rep); 40 void DoJSToNumberOrNumericTruncatesToFloat64( 41 Node* node, RepresentationSelector* selector); 42 void DoJSToNumberOrNumericTruncatesToWord32(Node* node, 43 RepresentationSelector* selector); 44 void DoIntegral32ToBit(Node* node); 45 void DoOrderedNumberToBit(Node* node); 46 void DoNumberToBit(Node* node); 47 void DoIntegerToUint8Clamped(Node* node); 48 void DoNumberToUint8Clamped(Node* node); 49 void DoSigned32ToUint8Clamped(Node* node); 50 void DoUnsigned32ToUint8Clamped(Node* node); 51 52 private: 53 JSGraph* const jsgraph_; 54 JSHeapBroker* broker_; 55 Zone* const zone_; 56 TypeCache const* type_cache_; 57 SetOncePointer<Node> to_number_code_; 58 SetOncePointer<Node> to_number_convert_big_int_code_; 59 SetOncePointer<Node> to_numeric_code_; 60 SetOncePointer<Operator const> to_number_operator_; 61 SetOncePointer<Operator const> to_number_convert_big_int_operator_; 62 SetOncePointer<Operator const> to_numeric_operator_; 63 64 // TODO(danno): SimplifiedLowering shouldn't know anything about the source 65 // positions table, but must for now since there currently is no other way to 66 // pass down source position information to nodes created during 67 // lowering. Once this phase becomes a vanilla reducer, it should get source 68 // position information via the SourcePositionWrapper like all other reducers. 69 SourcePositionTable* source_positions_; 70 NodeOriginTable* node_origins_; 71 72 PoisoningMitigationLevel poisoning_level_; 73 74 TickCounter* const tick_counter_; 75 Linkage* const linkage_; 76 77 Node* Float64Round(Node* const node); 78 Node* Float64Sign(Node* const node); 79 Node* Int32Abs(Node* const node); 80 Node* Int32Div(Node* const node); 81 Node* Int32Mod(Node* const node); 82 Node* Int32Sign(Node* const node); 83 Node* Uint32Div(Node* const node); 84 Node* Uint32Mod(Node* const node); 85 86 Node* ToNumberCode(); 87 Node* ToNumberConvertBigIntCode(); 88 Node* ToNumericCode(); 89 Operator const* ToNumberOperator(); 90 Operator const* ToNumberConvertBigIntOperator(); 91 Operator const* ToNumericOperator(); 92 93 friend class RepresentationSelector; 94 isolate()95 Isolate* isolate() { return jsgraph_->isolate(); } zone()96 Zone* zone() { return jsgraph_->zone(); } jsgraph()97 JSGraph* jsgraph() { return jsgraph_; } graph()98 Graph* graph() { return jsgraph()->graph(); } common()99 CommonOperatorBuilder* common() { return jsgraph()->common(); } machine()100 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } simplified()101 SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); } linkage()102 Linkage* linkage() { return linkage_; } 103 }; 104 105 } // namespace compiler 106 } // namespace internal 107 } // namespace v8 108 109 #endif // V8_COMPILER_SIMPLIFIED_LOWERING_H_ 110