OLD | NEW |
---|---|
(Empty) | |
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 #include "src/compiler/int64-reducer.h" | |
6 #include "src/compiler/common-operator.h" | |
7 #include "src/compiler/graph.h" | |
8 #include "src/compiler/machine-operator.h" | |
9 #include "src/compiler/node.h" | |
10 #include "src/zone.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 namespace compiler { | |
15 | |
16 Int64Reducer::Int64Reducer(Graph* graph, MachineOperatorBuilder* machine, | |
17 CommonOperatorBuilder* common, Zone* zone) | |
18 : graph_(graph), | |
19 machine_(machine), | |
20 common_(common), | |
21 state_(graph, 4), | |
22 stack_(zone), | |
23 replacements_(zone->NewArray<Replacement>(graph->NodeCount())) {} | |
24 | |
25 void Int64Reducer::ReduceGraph() { | |
26 stack_.push(graph()->end()); | |
27 state_.Set(graph()->end(), State::kOnStack); | |
28 | |
29 for (;;) { | |
titzer
2016/02/02 10:14:35
while (!stack.empty())
ahaas
2016/02/02 13:32:48
Done.
| |
30 if (stack_.empty()) { | |
31 break; | |
32 } | |
33 Node* top = stack_.top(); | |
34 if (state_.Get(top) == State::kInputsPushed) { | |
35 stack_.pop(); | |
36 state_.Set(top, State::kVisited); | |
37 // All inputs of top have already been reduced, now reduce top. | |
38 ReduceNode(top); | |
39 } else { | |
40 // Push all children onto the stack. | |
41 for (Node* input : top->inputs()) { | |
42 if (state_.Get(input) == State::kUnvisited) { | |
43 stack_.push(input); | |
44 state_.Set(input, State::kOnStack); | |
45 replacements_[input->id()].low = nullptr; | |
46 } | |
47 } | |
48 state_.Set(top, State::kInputsPushed); | |
49 } | |
50 } | |
51 } | |
52 | |
53 void Int64Reducer::ReduceNode(Node* node) { | |
54 if (node->opcode() == IrOpcode::kInt64Constant) { | |
titzer
2016/02/02 10:14:35
Make me a switch.
ahaas
2016/02/02 13:32:48
Done.
| |
55 int64_t value = OpParameter<int64_t>(node); | |
56 Node* low_node = | |
57 graph()->NewNode(common()->Int32Constant(static_cast<int32_t>(value))); | |
titzer
2016/02/02 10:14:35
I think you need to do a static_cast<uint32_t>(val
ahaas
2016/02/02 13:32:48
Done.
| |
58 Node* high_node = graph()->NewNode( | |
59 common()->Int32Constant(static_cast<int32_t>(value >> 32))); | |
60 replacements_[node->id()].low = low_node; | |
61 replacements_[node->id()].high = high_node; | |
62 } else if (node->opcode() == IrOpcode::kWord64And) { | |
63 Node* left = node->InputAt(0); | |
64 DCHECK(replacements_[left->id()].low); | |
65 Node* left_low = replacements_[left->id()].low; | |
66 Node* left_high = replacements_[left->id()].high; | |
67 | |
68 Node* right = node->InputAt(1); | |
69 DCHECK(replacements_[right->id()].low); | |
70 Node* right_low = replacements_[right->id()].low; | |
71 Node* right_high = replacements_[right->id()].high; | |
72 | |
73 replacements_[node->id()].low = | |
74 graph()->NewNode(machine()->Word32And(), left_low, right_low); | |
75 replacements_[node->id()].high = | |
76 graph()->NewNode(machine()->Word32And(), left_high, right_high); | |
77 } else if (node->opcode() == IrOpcode::kTruncateInt64ToInt32) { | |
78 Node* input = node->InputAt(0); | |
79 DCHECK(replacements_[input->id()].low); | |
80 replacements_[node->id()].low = replacements_[input->id()].low; | |
81 } else { | |
82 // Also the inputs of nodes can change which do not expect int64 inputs. | |
83 for (int i = 0; i < node->InputCount(); i++) { | |
84 Node* input = node->InputAt(i); | |
85 // The input has changed altough it was not an int64 input. This can | |
86 // happen e.g. if the input node is IrOpcode::kTruncateInt64ToInt32. We | |
87 // use the low word replacement as the new input. | |
88 if (replacements_[input->id()].low) { | |
89 node->ReplaceInput(i, replacements_[input->id()].low); | |
90 } | |
91 } | |
92 } | |
93 } | |
94 | |
95 } // namespace compiler | |
96 } // namespace internal | |
97 } // namespace v8 | |
OLD | NEW |