OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_BRANCH_CONDITION_ELIMINATION_H_ | |
6 #define V8_COMPILER_BRANCH_CONDITION_ELIMINATION_H_ | |
7 | |
8 #include "src/compiler/graph-reducer.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 namespace compiler { | |
13 | |
14 class JSGraph; | |
15 | |
16 | |
17 class BranchConditionElimination final : public AdvancedReducer { | |
18 public: | |
19 BranchConditionElimination(Editor* editor, JSGraph* js_graph, Zone* zone); | |
20 ~BranchConditionElimination() final; | |
21 | |
22 Reduction Reduce(Node* node) final; | |
23 | |
24 private: | |
25 struct BranchCondition { | |
26 Node* condition_; | |
27 bool is_true_; | |
28 | |
29 // Inequality compares only the condition identity. | |
30 // This is sufficient for our search because we cannot have | |
31 // conflicting conditions on a path. | |
32 bool operator<(const BranchCondition& other) const; | |
33 | |
34 // Equality is field-wise. | |
35 bool operator==(const BranchCondition& other) const; | |
36 bool operator!=(const BranchCondition& other) const { | |
37 return !(*this == other); | |
38 } | |
39 | |
40 BranchCondition(Node* condition, bool is_true) | |
41 : condition_(condition), is_true_(is_true) {} | |
42 }; | |
43 | |
44 // Class for tracking information about branch conditions. | |
45 // At the moment it is a simple list of conditions and their values | |
46 // (true or false). The list is sorted by the node conditions' ids. | |
47 class ControlPathConditions { | |
titzer
2015/10/08 18:01:07
The number of control path conditions is proportio
Jarin
2015/10/09 05:28:08
Yeah, that's a good idea. The code might be even s
Jarin
2015/10/17 14:18:21
Changed now, and it is indeed a bit faster (~10%)
| |
48 public: | |
49 const ControlPathConditions* AddCondition(Zone* zone, Node* condition, | |
50 bool is_true) const; | |
51 Maybe<bool> LookupCondition(Node* condition) const; | |
52 | |
53 static const ControlPathConditions* Empty(Zone* zone); | |
54 static const ControlPathConditions* Merge( | |
55 Zone* zone, const ZoneVector<const ControlPathConditions*>& inputs); | |
56 | |
57 bool operator==(const ControlPathConditions& other) const; | |
58 bool operator!=(const ControlPathConditions& other) const { | |
59 return !(*this == other); | |
60 } | |
61 | |
62 private: | |
63 ControlPathConditions(Zone* zone, size_t reserved_count) | |
64 : conditions_(zone) { | |
65 conditions_.reserve(reserved_count); | |
66 } | |
67 | |
68 ZoneVector<BranchCondition> conditions_; | |
69 }; | |
70 | |
71 // Maps each control node to the condition information known about the node. | |
72 // If the information is nullptr, then we have not calculated the information | |
73 // yet. | |
74 class PathConditionsForControlNodes { | |
75 public: | |
76 PathConditionsForControlNodes(Zone* zone, size_t size_hint) | |
77 : info_for_node_(size_hint, nullptr, zone) {} | |
78 const ControlPathConditions* Get(Node* node); | |
79 void Set(Node* node, const ControlPathConditions* conditions); | |
80 | |
81 private: | |
82 ZoneVector<const ControlPathConditions*> info_for_node_; | |
83 }; | |
84 | |
85 Reduction ReduceBranch(Node* node); | |
86 Reduction ReduceIf(Node* node, bool is_true_branch); | |
87 Reduction ReduceLoop(Node* node); | |
88 Reduction ReduceMerge(Node* node); | |
89 Reduction ReduceStart(Node* node); | |
90 Reduction ReduceOtherControl(Node* node); | |
91 | |
92 Reduction TakeConditionsFromFirstControl(Node* node); | |
93 Reduction UpdateConditions(Node* node, | |
94 const ControlPathConditions* conditions); | |
95 | |
96 Node* dead() const { return dead_; } | |
97 | |
98 PathConditionsForControlNodes node_conditions_; | |
99 Zone* zone_; | |
100 Node* dead_; | |
101 }; | |
102 | |
103 } // namespace compiler | |
104 } // namespace internal | |
105 } // namespace v8 | |
106 | |
107 #endif // V8_COMPILER_BRANCH_CONDITION_ELIMINATION_H_ | |
OLD | NEW |