blob: 75fd9c2c65df1e7229baca3181d984411862a1d9 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch61f157c2016-09-16 13:49:30 +01008#include "src/base/flags.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/compiler/js-graph.h"
10#include "src/compiler/machine-operator.h"
11#include "src/compiler/node.h"
12#include "src/compiler/simplified-operator.h"
13
14namespace v8 {
15namespace internal {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016
17// Forward declarations.
18class TypeCache;
19
20
Ben Murdochb8a8cc12014-11-26 15:28:44 +000021namespace compiler {
22
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023// Forward declarations.
24class RepresentationChanger;
Ben Murdochc5610432016-08-08 18:44:38 +010025class RepresentationSelector;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026class SourcePositionTable;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040027
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028class SimplifiedLowering final {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +010030 enum Flag { kNoFlag = 0u, kTypeFeedbackEnabled = 1u << 0 };
31 typedef base::Flags<Flag> Flags;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032 SimplifiedLowering(JSGraph* jsgraph, Zone* zone,
Ben Murdoch61f157c2016-09-16 13:49:30 +010033 SourcePositionTable* source_positions,
34 Flags flags = kNoFlag);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040035 ~SimplifiedLowering() {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036
37 void LowerAllNodes();
38
Ben Murdochc5610432016-08-08 18:44:38 +010039 void DoJSToNumberTruncatesToFloat64(Node* node,
40 RepresentationSelector* selector);
41 void DoJSToNumberTruncatesToWord32(Node* node,
42 RepresentationSelector* selector);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043 // TODO(turbofan): The representation can be removed once the result of the
Emily Bernierd0a1eb72015-03-24 16:35:39 -040044 // representation analysis is stored in the node bounds.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 void DoLoadBuffer(Node* node, MachineRepresentation rep,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040046 RepresentationChanger* changer);
47 void DoStoreBuffer(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048 void DoShift(Node* node, Operator const* op, Type* rhs_type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049
Ben Murdoch61f157c2016-09-16 13:49:30 +010050 Flags flags() const { return flags_; }
51
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 private:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040053 JSGraph* const jsgraph_;
54 Zone* const zone_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055 TypeCache const& type_cache_;
Ben Murdochc5610432016-08-08 18:44:38 +010056 SetOncePointer<Node> to_number_code_;
57 SetOncePointer<Operator const> to_number_operator_;
Ben Murdoch61f157c2016-09-16 13:49:30 +010058 Flags flags_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 // TODO(danno): SimplifiedLowering shouldn't know anything about the source
61 // positions table, but must for now since there currently is no other way to
62 // pass down source position information to nodes created during
63 // lowering. Once this phase becomes a vanilla reducer, it should get source
64 // position information via the SourcePositionWrapper like all other reducers.
65 SourcePositionTable* source_positions_;
66
Ben Murdochda12d292016-06-02 14:46:10 +010067 Node* Float64Ceil(Node* const node);
68 Node* Float64Floor(Node* const node);
69 Node* Float64Round(Node* const node);
70 Node* Float64Trunc(Node* const node);
Ben Murdoch61f157c2016-09-16 13:49:30 +010071 Node* Int32Abs(Node* const node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040072 Node* Int32Div(Node* const node);
73 Node* Int32Mod(Node* const node);
74 Node* Uint32Div(Node* const node);
75 Node* Uint32Mod(Node* const node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076
Ben Murdochc5610432016-08-08 18:44:38 +010077 Node* ToNumberCode();
78 Operator const* ToNumberOperator();
79
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080 friend class RepresentationSelector;
81
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000082 Isolate* isolate() { return jsgraph_->isolate(); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000083 Zone* zone() { return jsgraph_->zone(); }
84 JSGraph* jsgraph() { return jsgraph_; }
85 Graph* graph() { return jsgraph()->graph(); }
86 CommonOperatorBuilder* common() { return jsgraph()->common(); }
87 MachineOperatorBuilder* machine() { return jsgraph()->machine(); }
Ben Murdochc5610432016-08-08 18:44:38 +010088 SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089};
90
91} // namespace compiler
92} // namespace internal
93} // namespace v8
94
95#endif // V8_COMPILER_SIMPLIFIED_LOWERING_H_