• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-properties.h"
11 #include "src/compiler/node.h"
12 #include "src/compiler/simplified-operator.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class TickCounter;
18 
19 namespace compiler {
20 
21 // Forward declarations.
22 class NodeOriginTable;
23 class ObserveNodeManager;
24 class RepresentationChanger;
25 class RepresentationSelector;
26 class SourcePositionTable;
27 class TypeCache;
28 
29 class V8_EXPORT_PRIVATE SimplifiedLowering final {
30  public:
31   SimplifiedLowering(JSGraph* jsgraph, JSHeapBroker* broker, Zone* zone,
32                      SourcePositionTable* source_position,
33                      NodeOriginTable* node_origins, TickCounter* tick_counter,
34                      Linkage* linkage, OptimizedCompilationInfo* info,
35                      ObserveNodeManager* observe_node_manager = nullptr);
36   ~SimplifiedLowering() = default;
37 
38   void LowerAllNodes();
39 
40   void DoMax(Node* node, Operator const* op, MachineRepresentation rep);
41   void DoMin(Node* node, Operator const* op, MachineRepresentation rep);
42   void DoJSToNumberOrNumericTruncatesToFloat64(
43       Node* node, RepresentationSelector* selector);
44   void DoJSToNumberOrNumericTruncatesToWord32(Node* node,
45                                               RepresentationSelector* selector);
46   void DoIntegral32ToBit(Node* node);
47   void DoOrderedNumberToBit(Node* node);
48   void DoNumberToBit(Node* node);
49   void DoIntegerToUint8Clamped(Node* node);
50   void DoNumberToUint8Clamped(Node* node);
51   void DoSigned32ToUint8Clamped(Node* node);
52   void DoUnsigned32ToUint8Clamped(Node* node);
53 
54  private:
55   // The purpose of this nested class is to hide method
56   // v8::internal::compiler::NodeProperties::ChangeOp which should not be
57   // directly used by code in SimplifiedLowering.
58   // SimplifiedLowering code should call SimplifiedLowering::ChangeOp instead,
59   // in order to notify the changes to ObserveNodeManager and support the
60   // %ObserveNode intrinsic.
61   class NodeProperties : public compiler::NodeProperties {
ChangeOp(Node * node,const Operator * new_op)62     static void ChangeOp(Node* node, const Operator* new_op) { UNREACHABLE(); }
63   };
64   void ChangeOp(Node* node, const Operator* new_op);
65 
66   JSGraph* const jsgraph_;
67   JSHeapBroker* broker_;
68   Zone* const zone_;
69   TypeCache const* type_cache_;
70   SetOncePointer<Node> to_number_code_;
71   SetOncePointer<Node> to_number_convert_big_int_code_;
72   SetOncePointer<Node> to_numeric_code_;
73   SetOncePointer<Operator const> to_number_operator_;
74   SetOncePointer<Operator const> to_number_convert_big_int_operator_;
75   SetOncePointer<Operator const> to_numeric_operator_;
76 
77   // TODO(danno): SimplifiedLowering shouldn't know anything about the source
78   // positions table, but must for now since there currently is no other way to
79   // pass down source position information to nodes created during
80   // lowering. Once this phase becomes a vanilla reducer, it should get source
81   // position information via the SourcePositionWrapper like all other reducers.
82   SourcePositionTable* source_positions_;
83   NodeOriginTable* node_origins_;
84 
85   TickCounter* const tick_counter_;
86   Linkage* const linkage_;
87   OptimizedCompilationInfo* info_;
88 
89   ObserveNodeManager* const observe_node_manager_;
90 
91   Node* Float64Round(Node* const node);
92   Node* Float64Sign(Node* const node);
93   Node* Int32Abs(Node* const node);
94   Node* Int32Div(Node* const node);
95   Node* Int32Mod(Node* const node);
96   Node* Int32Sign(Node* const node);
97   Node* Uint32Div(Node* const node);
98   Node* Uint32Mod(Node* const node);
99 
100   Node* ToNumberCode();
101   Node* ToNumberConvertBigIntCode();
102   Node* ToNumericCode();
103   Operator const* ToNumberOperator();
104   Operator const* ToNumberConvertBigIntOperator();
105   Operator const* ToNumericOperator();
106 
107   friend class RepresentationSelector;
108 
isolate()109   Isolate* isolate() { return jsgraph_->isolate(); }
zone()110   Zone* zone() { return jsgraph_->zone(); }
jsgraph()111   JSGraph* jsgraph() { return jsgraph_; }
graph()112   Graph* graph() { return jsgraph()->graph(); }
common()113   CommonOperatorBuilder* common() { return jsgraph()->common(); }
machine()114   MachineOperatorBuilder* machine() { return jsgraph()->machine(); }
simplified()115   SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); }
linkage()116   Linkage* linkage() { return linkage_; }
117 };
118 
119 }  // namespace compiler
120 }  // namespace internal
121 }  // namespace v8
122 
123 #endif  // V8_COMPILER_SIMPLIFIED_LOWERING_H_
124