44
55#include " src/compiler/change-lowering.h"
66
7- #include " src/compiler/common-node-cache.h"
8- #include " src/compiler/graph.h"
7+ #include " src/compiler/js-graph.h"
98
109namespace v8 {
1110namespace internal {
1211namespace compiler {
1312
14- ChangeLoweringBase::ChangeLoweringBase (Graph* graph, Linkage* linkage,
15- CommonNodeCache* cache)
16- : graph_(graph),
17- isolate_ (graph->zone ()->isolate()),
18- linkage_(linkage),
19- cache_(cache),
20- common_(graph->zone ()),
21- machine_(graph->zone ()) {}
13+ ChangeLowering::~ChangeLowering () {}
2214
2315
24- ChangeLoweringBase::~ChangeLoweringBase () {}
25-
26-
27- Node* ChangeLoweringBase::ExternalConstant (ExternalReference reference) {
28- Node** loc = cache ()->FindExternalConstant (reference);
29- if (*loc == NULL ) {
30- *loc = graph ()->NewNode (common ()->ExternalConstant (reference));
31- }
32- return *loc;
33- }
34-
35-
36- Node* ChangeLoweringBase::HeapConstant (PrintableUnique<HeapObject> value) {
37- // TODO(bmeurer): Use common node cache.
38- return graph ()->NewNode (common ()->HeapConstant (value));
39- }
40-
41-
42- Node* ChangeLoweringBase::ImmovableHeapConstant (Handle<HeapObject> value) {
43- return HeapConstant (
44- PrintableUnique<HeapObject>::CreateImmovable (graph ()->zone (), value));
45- }
46-
47-
48- Node* ChangeLoweringBase::Int32Constant (int32_t value) {
49- Node** loc = cache ()->FindInt32Constant (value);
50- if (*loc == NULL ) {
51- *loc = graph ()->NewNode (common ()->Int32Constant (value));
52- }
53- return *loc;
54- }
55-
56-
57- Node* ChangeLoweringBase::NumberConstant (double value) {
58- Node** loc = cache ()->FindNumberConstant (value);
59- if (*loc == NULL ) {
60- *loc = graph ()->NewNode (common ()->NumberConstant (value));
61- }
62- return *loc;
63- }
64-
65-
66- Node* ChangeLoweringBase::CEntryStubConstant () {
67- if (!c_entry_stub_constant_.is_set ()) {
68- c_entry_stub_constant_.set (
69- ImmovableHeapConstant (CEntryStub (isolate (), 1 ).GetCode ()));
16+ Reduction ChangeLowering::Reduce (Node* node) {
17+ Node* control = graph ()->start ();
18+ Node* effect = control;
19+ switch (node->opcode ()) {
20+ case IrOpcode::kChangeBitToBool :
21+ return ChangeBitToBool (node->InputAt (0 ), control);
22+ case IrOpcode::kChangeBoolToBit :
23+ return ChangeBoolToBit (node->InputAt (0 ));
24+ case IrOpcode::kChangeInt32ToTagged :
25+ return ChangeInt32ToTagged (node->InputAt (0 ), effect, control);
26+ case IrOpcode::kChangeTaggedToFloat64 :
27+ return ChangeTaggedToFloat64 (node->InputAt (0 ), effect, control);
28+ default :
29+ return NoChange ();
7030 }
71- return c_entry_stub_constant_.get ();
31+ UNREACHABLE ();
32+ return NoChange ();
7233}
7334
7435
75- Node* ChangeLoweringBase::TrueConstant () {
76- if (!true_constant_.is_set ()) {
77- true_constant_.set (
78- ImmovableHeapConstant (isolate ()->factory ()->true_value ()));
79- }
80- return true_constant_.get ();
36+ Node* ChangeLowering::HeapNumberValueIndexConstant () {
37+ STATIC_ASSERT (HeapNumber::kValueOffset % kPointerSize == 0 );
38+ const int heap_number_value_offset =
39+ ((HeapNumber::kValueOffset / kPointerSize ) * (machine ()->is64 () ? 8 : 4 ));
40+ return jsgraph ()->Int32Constant (heap_number_value_offset - kHeapObjectTag );
8141}
8242
8343
84- Node* ChangeLoweringBase::FalseConstant () {
85- if (!false_constant_.is_set ()) {
86- false_constant_.set (
87- ImmovableHeapConstant (isolate ()->factory ()->false_value ()));
88- }
89- return false_constant_.get ();
44+ Node* ChangeLowering::SmiShiftBitsConstant () {
45+ const int smi_shift_size = (machine ()->is64 () ? SmiTagging<8 >::kSmiShiftSize
46+ : SmiTagging<4 >::kSmiShiftSize );
47+ return jsgraph ()->Int32Constant (smi_shift_size + kSmiTagSize );
9048}
9149
9250
93- Reduction ChangeLoweringBase ::ChangeBitToBool (Node* val, Node* control) {
51+ Reduction ChangeLowering ::ChangeBitToBool (Node* val, Node* control) {
9452 Node* branch = graph ()->NewNode (common ()->Branch (), val, control);
9553
9654 Node* if_true = graph ()->NewNode (common ()->IfTrue (), branch);
97- Node* true_value = TrueConstant ();
55+ Node* true_value = jsgraph ()-> TrueConstant ();
9856
9957 Node* if_false = graph ()->NewNode (common ()->IfFalse (), branch);
100- Node* false_value = FalseConstant ();
58+ Node* false_value = jsgraph ()-> FalseConstant ();
10159
10260 Node* merge = graph ()->NewNode (common ()->Merge (2 ), if_true, if_false);
10361 Node* phi =
@@ -107,51 +65,20 @@ Reduction ChangeLoweringBase::ChangeBitToBool(Node* val, Node* control) {
10765}
10866
10967
110- template <size_t kPointerSize >
111- ChangeLowering<kPointerSize >::ChangeLowering(Graph* graph, Linkage* linkage)
112- : ChangeLoweringBase(graph, linkage,
113- new (graph->zone ()) CommonNodeCache(graph->zone ())) {}
114-
115-
116- template <size_t kPointerSize >
117- Reduction ChangeLowering<kPointerSize >::Reduce(Node* node) {
118- Node* control = graph ()->start ();
119- Node* effect = control;
120- switch (node->opcode ()) {
121- case IrOpcode::kChangeBitToBool :
122- return ChangeBitToBool (node->InputAt (0 ), control);
123- case IrOpcode::kChangeBoolToBit :
124- return ChangeBoolToBit (node->InputAt (0 ));
125- case IrOpcode::kChangeInt32ToTagged :
126- return ChangeInt32ToTagged (node->InputAt (0 ), effect, control);
127- case IrOpcode::kChangeTaggedToFloat64 :
128- return ChangeTaggedToFloat64 (node->InputAt (0 ), effect, control);
129- default :
130- return NoChange ();
131- }
132- UNREACHABLE ();
133- return NoChange ();
134- }
135-
136-
137- template <>
138- Reduction ChangeLowering<4 >::ChangeBoolToBit(Node* val) {
68+ Reduction ChangeLowering::ChangeBoolToBit (Node* val) {
13969 return Replace (
140- graph ()->NewNode (machine ()->Word32Equal (), val, TrueConstant ()));
70+ graph ()->NewNode (machine ()->WordEqual (), val, jsgraph ()-> TrueConstant ()));
14171}
14272
14373
144- template <>
145- Reduction ChangeLowering< 8 >::ChangeBoolToBit( Node* val ) {
146- return Replace (
147- graph ()-> NewNode ( machine ()-> Word64Equal (), val, TrueConstant ()));
148- }
149-
74+ Reduction ChangeLowering::ChangeInt32ToTagged (Node* val, Node* effect,
75+ Node* control ) {
76+ if ( machine ()-> is64 ()) {
77+ return Replace (
78+ graph ()-> NewNode ( machine ()-> WordShl (), val, SmiShiftBitsConstant ()));
79+ }
15080
151- template <>
152- Reduction ChangeLowering<4 >::ChangeInt32ToTagged(Node* val, Node* effect,
153- Node* control) {
154- Node* context = NumberConstant (0 );
81+ Node* context = jsgraph ()->SmiConstant (0 );
15582
15683 Node* add = graph ()->NewNode (machine ()->Int32AddWithOverflow (), val, val);
15784 Node* ovf = graph ()->NewNode (common ()->Projection (1 ), add);
@@ -167,15 +94,14 @@ Reduction ChangeLowering<4>::ChangeInt32ToTagged(Node* val, Node* effect,
16794 DCHECK_EQ (0 , fn->nargs );
16895 CallDescriptor* desc = linkage ()->GetRuntimeCallDescriptor (
16996 fn->function_id , 0 , Operator::kNoProperties );
170- Node* heap_number =
171- graph ()-> NewNode ( common ()->Call (desc), CEntryStubConstant (),
172- ExternalConstant (ExternalReference (fn, isolate ())),
173- Int32Constant ( 0 ), context, effect, if_true);
97+ Node* heap_number = graph ()-> NewNode (
98+ common ()->Call (desc), jsgraph ()-> CEntryStubConstant (),
99+ jsgraph ()-> ExternalConstant (ExternalReference (fn, isolate ())),
100+ jsgraph ()-> ZeroConstant ( ), context, effect, if_true);
174101
175102 Node* store = graph ()->NewNode (
176103 machine ()->Store (kMachFloat64 , kNoWriteBarrier ), heap_number,
177- Int32Constant (HeapNumber::kValueOffset - kHeapObjectTag ), number, effect,
178- heap_number);
104+ HeapNumberValueIndexConstant (), number, effect, heap_number);
179105
180106 Node* if_false = graph ()->NewNode (common ()->IfFalse (), branch);
181107 Node* smi = graph ()->NewNode (common ()->Projection (0 ), add);
@@ -187,34 +113,26 @@ Reduction ChangeLowering<4>::ChangeInt32ToTagged(Node* val, Node* effect,
187113}
188114
189115
190- template <>
191- Reduction ChangeLowering<8 >::ChangeInt32ToTagged(Node* val, Node* effect,
192- Node* control) {
193- return Replace (graph ()->NewNode (
194- machine ()->Word64Shl (), val,
195- Int32Constant (SmiTagging<8 >::kSmiShiftSize + kSmiTagSize )));
196- }
197-
116+ Reduction ChangeLowering::ChangeTaggedToFloat64 (Node* val, Node* effect,
117+ Node* control) {
118+ STATIC_ASSERT (kSmiTagMask == 1 );
198119
199- template <>
200- Reduction ChangeLowering<4 >::ChangeTaggedToFloat64(Node* val, Node* effect,
201- Node* control) {
202- Node* branch = graph ()->NewNode (
203- common ()->Branch (),
204- graph ()->NewNode (machine ()->Word32And (), val, Int32Constant (kSmiTagMask )),
205- control);
120+ Node* tag = graph ()->NewNode (machine ()->WordAnd (), val,
121+ jsgraph ()->Int32Constant (kSmiTagMask ));
122+ Node* branch = graph ()->NewNode (common ()->Branch (), tag, control);
206123
207124 Node* if_true = graph ()->NewNode (common ()->IfTrue (), branch);
208- Node* load = graph ()->NewNode (
209- machine ()->Load (kMachFloat64 ), val,
210- Int32Constant (HeapNumber::kValueOffset - kHeapObjectTag ), if_true);
125+ Node* load = graph ()->NewNode (machine ()->Load (kMachFloat64 ), val,
126+ HeapNumberValueIndexConstant (), if_true);
211127
212128 Node* if_false = graph ()->NewNode (common ()->IfFalse (), branch);
129+ Node* integer =
130+ graph ()->NewNode (machine ()->WordSar (), val, SmiShiftBitsConstant ());
213131 Node* number = graph ()->NewNode (
214132 machine ()->ChangeInt32ToFloat64 (),
215- graph ()->NewNode (
216- machine ()->Word32Sar (), val,
217- Int32Constant (SmiTagging< 4 >:: kSmiShiftSize + kSmiTagSize )) );
133+ machine ()->is64 ()
134+ ? graph ()-> NewNode ( machine ()->ConvertInt64ToInt32 (), integer)
135+ : integer );
218136
219137 Node* merge = graph ()->NewNode (common ()->Merge (2 ), if_true, if_false);
220138 Node* phi = graph ()->NewNode (common ()->Phi (2 ), load, number, merge);
@@ -223,38 +141,16 @@ Reduction ChangeLowering<4>::ChangeTaggedToFloat64(Node* val, Node* effect,
223141}
224142
225143
226- template <>
227- Reduction ChangeLowering<8 >::ChangeTaggedToFloat64(Node* val, Node* effect,
228- Node* control) {
229- Node* branch = graph ()->NewNode (
230- common ()->Branch (),
231- graph ()->NewNode (machine ()->Word64And (), val, Int32Constant (kSmiTagMask )),
232- control);
144+ Isolate* ChangeLowering::isolate () const { return jsgraph ()->isolate (); }
233145
234- Node* if_true = graph ()->NewNode (common ()->IfTrue (), branch);
235- Node* load = graph ()->NewNode (
236- machine ()->Load (kMachFloat64 ), val,
237- Int32Constant (HeapNumber::kValueOffset - kHeapObjectTag ), if_true);
238146
239- Node* if_false = graph ()->NewNode (common ()->IfFalse (), branch);
240- Node* number = graph ()->NewNode (
241- machine ()->ChangeInt32ToFloat64 (),
242- graph ()->NewNode (
243- machine ()->ConvertInt64ToInt32 (),
244- graph ()->NewNode (
245- machine ()->Word64Sar (), val,
246- Int32Constant (SmiTagging<8 >::kSmiShiftSize + kSmiTagSize ))));
147+ Graph* ChangeLowering::graph () const { return jsgraph ()->graph (); }
247148
248- Node* merge = graph ()->NewNode (common ()->Merge (2 ), if_true, if_false);
249- Node* phi = graph ()->NewNode (common ()->Phi (2 ), load, number, merge);
250149
251- return Replace (phi);
150+ CommonOperatorBuilder* ChangeLowering::common () const {
151+ return jsgraph ()->common ();
252152}
253153
254-
255- template class ChangeLowering <4 >;
256- template class ChangeLowering <8 >;
257-
258154} // namespace compiler
259155} // namespace internal
260156} // namespace v8
0 commit comments