| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_ESCAPE_ANALYSIS_H_ | 5 #ifndef V8_COMPILER_ESCAPE_ANALYSIS_H_ |
| 6 #define V8_COMPILER_ESCAPE_ANALYSIS_H_ | 6 #define V8_COMPILER_ESCAPE_ANALYSIS_H_ |
| 7 | 7 |
| 8 #include "src/base/flags.h" | 8 #include "src/base/flags.h" |
| 9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 // Forward declarations. | 15 // Forward declarations. |
| 16 class CommonOperatorBuilder; | 16 class CommonOperatorBuilder; |
| 17 class EscapeAnalysis; | 17 class EscapeAnalysis; |
| 18 class VirtualState; | 18 class VirtualState; |
| 19 class VirtualObject; | 19 class VirtualObject; |
| 20 | 20 |
| 21 | 21 |
| 22 // EscapeStatusAnalysis determines for each allocation whether it escapes. | 22 // EscapeStatusAnalysis determines for each allocation whether it escapes. |
| 23 class EscapeStatusAnalysis { | 23 class EscapeStatusAnalysis { |
| 24 public: | 24 public: |
| 25 ~EscapeStatusAnalysis(); | 25 ~EscapeStatusAnalysis(); |
| 26 | 26 |
| 27 enum EscapeStatusFlag { | 27 enum EscapeStatusFlag { |
| 28 kUnknown = 0u, | 28 kUnknown = 0u, |
| 29 kVirtual = 1u << 0, | 29 kTracked = 1u << 0, |
| 30 kEscaped = 1u << 1, | 30 kEscaped = 1u << 1, |
| 31 kOnStack = 1u << 2, |
| 32 kVisited = 1u << 3, |
| 31 }; | 33 }; |
| 32 typedef base::Flags<EscapeStatusFlag> EscapeStatusFlags; | 34 typedef base::Flags<EscapeStatusFlag, unsigned char> EscapeStatusFlags; |
| 33 | 35 |
| 34 void Run(); | 36 void Run(); |
| 35 | 37 |
| 36 bool IsVirtual(Node* node); | 38 bool IsVirtual(Node* node); |
| 37 bool IsEscaped(Node* node); | 39 bool IsEscaped(Node* node); |
| 38 bool IsAllocation(Node* node); | 40 bool IsAllocation(Node* node); |
| 39 | 41 |
| 40 void DebugPrint(); | 42 void DebugPrint(); |
| 41 | 43 |
| 42 friend class EscapeAnalysis; | 44 friend class EscapeAnalysis; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 void Resize(); | 62 void Resize(); |
| 61 size_t size(); | 63 size_t size(); |
| 62 bool IsAllocationPhi(Node* node); | 64 bool IsAllocationPhi(Node* node); |
| 63 | 65 |
| 64 Graph* graph() const { return graph_; } | 66 Graph* graph() const { return graph_; } |
| 65 Zone* zone() const { return zone_; } | 67 Zone* zone() const { return zone_; } |
| 66 | 68 |
| 67 EscapeAnalysis* object_analysis_; | 69 EscapeAnalysis* object_analysis_; |
| 68 Graph* const graph_; | 70 Graph* const graph_; |
| 69 Zone* const zone_; | 71 Zone* const zone_; |
| 70 ZoneVector<EscapeStatusFlags> info_; | 72 ZoneVector<EscapeStatusFlags> status_; |
| 71 ZoneDeque<Node*> queue_; | 73 ZoneDeque<Node*> queue_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(EscapeStatusAnalysis); | 75 DISALLOW_COPY_AND_ASSIGN(EscapeStatusAnalysis); |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 | 78 |
| 77 DEFINE_OPERATORS_FOR_FLAGS(EscapeStatusAnalysis::EscapeStatusFlags) | 79 DEFINE_OPERATORS_FOR_FLAGS(EscapeStatusAnalysis::EscapeStatusFlags) |
| 78 | 80 |
| 79 | 81 |
| 80 // Forward Declaration. | 82 // Forward Declaration. |
| 81 class MergeCache; | 83 class MergeCache; |
| 82 | 84 |
| 83 | 85 |
| 84 // EscapeObjectAnalysis simulates stores to determine values of loads if | 86 // EscapeObjectAnalysis simulates stores to determine values of loads if |
| 85 // an object is virtual and eliminated. | 87 // an object is virtual and eliminated. |
| 86 class EscapeAnalysis { | 88 class EscapeAnalysis { |
| 87 public: | 89 public: |
| 90 typedef NodeId Alias; |
| 91 |
| 88 EscapeAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone); | 92 EscapeAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone); |
| 89 ~EscapeAnalysis(); | 93 ~EscapeAnalysis(); |
| 90 | 94 |
| 91 void Run(); | 95 void Run(); |
| 92 | 96 |
| 93 Node* GetReplacement(Node* node); | 97 Node* GetReplacement(Node* node); |
| 94 bool IsVirtual(Node* node); | 98 bool IsVirtual(Node* node); |
| 95 bool IsEscaped(Node* node); | 99 bool IsEscaped(Node* node); |
| 96 bool CompareVirtualObjects(Node* left, Node* right); | 100 bool CompareVirtualObjects(Node* left, Node* right); |
| 97 Node* GetOrCreateObjectState(Node* effect, Node* node); | 101 Node* GetOrCreateObjectState(Node* effect, Node* node); |
| 98 | 102 |
| 99 private: | 103 private: |
| 100 void RunObjectAnalysis(); | 104 void RunObjectAnalysis(); |
| 105 void AssignAliases(); |
| 101 bool Process(Node* node); | 106 bool Process(Node* node); |
| 102 void ProcessLoadField(Node* node); | 107 void ProcessLoadField(Node* node); |
| 103 void ProcessStoreField(Node* node); | 108 void ProcessStoreField(Node* node); |
| 104 void ProcessLoadElement(Node* node); | 109 void ProcessLoadElement(Node* node); |
| 105 void ProcessStoreElement(Node* node); | 110 void ProcessStoreElement(Node* node); |
| 106 void ProcessAllocationUsers(Node* node); | 111 void ProcessAllocationUsers(Node* node); |
| 107 void ProcessAllocation(Node* node); | 112 void ProcessAllocation(Node* node); |
| 108 void ProcessFinishRegion(Node* node); | 113 void ProcessFinishRegion(Node* node); |
| 109 void ProcessCall(Node* node); | 114 void ProcessCall(Node* node); |
| 110 void ProcessStart(Node* node); | 115 void ProcessStart(Node* node); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 Node* GetReplacementIfSame(ZoneVector<VirtualObject*>& objs); | 127 Node* GetReplacementIfSame(ZoneVector<VirtualObject*>& objs); |
| 123 | 128 |
| 124 bool SetEscaped(Node* node); | 129 bool SetEscaped(Node* node); |
| 125 Node* replacement(NodeId id); | 130 Node* replacement(NodeId id); |
| 126 Node* replacement(Node* node); | 131 Node* replacement(Node* node); |
| 127 Node* ResolveReplacement(Node* node); | 132 Node* ResolveReplacement(Node* node); |
| 128 Node* GetReplacement(NodeId id); | 133 Node* GetReplacement(NodeId id); |
| 129 bool SetReplacement(Node* node, Node* rep); | 134 bool SetReplacement(Node* node, Node* rep); |
| 130 bool UpdateReplacement(VirtualState* state, Node* node, Node* rep); | 135 bool UpdateReplacement(VirtualState* state, Node* node, Node* rep); |
| 131 | 136 |
| 137 VirtualObject* GetVirtualObject(VirtualState* state, Node* node); |
| 138 |
| 132 void DebugPrint(); | 139 void DebugPrint(); |
| 133 void DebugPrintState(VirtualState* state); | 140 void DebugPrintState(VirtualState* state); |
| 134 void DebugPrintObject(VirtualObject* state, NodeId id); | 141 void DebugPrintObject(VirtualObject* state, Alias id); |
| 142 |
| 143 Alias NextAlias() { return next_free_alias_++; } |
| 144 Alias AliasCount() const { return next_free_alias_; } |
| 135 | 145 |
| 136 Graph* graph() const { return graph_; } | 146 Graph* graph() const { return graph_; } |
| 137 CommonOperatorBuilder* common() const { return common_; } | 147 CommonOperatorBuilder* common() const { return common_; } |
| 138 Zone* zone() const { return zone_; } | 148 Zone* zone() const { return zone_; } |
| 139 | 149 |
| 150 static const Alias kNotReachable; |
| 151 static const Alias kUntrackable; |
| 140 Graph* const graph_; | 152 Graph* const graph_; |
| 141 CommonOperatorBuilder* const common_; | 153 CommonOperatorBuilder* const common_; |
| 142 Zone* const zone_; | 154 Zone* const zone_; |
| 143 ZoneVector<VirtualState*> virtual_states_; | 155 ZoneVector<VirtualState*> virtual_states_; |
| 144 ZoneVector<Node*> replacements_; | 156 ZoneVector<Node*> replacements_; |
| 145 EscapeStatusAnalysis escape_status_; | 157 EscapeStatusAnalysis escape_status_; |
| 146 MergeCache* cache_; | 158 MergeCache* cache_; |
| 159 ZoneVector<Alias> aliases_; |
| 160 Alias next_free_alias_; |
| 147 | 161 |
| 148 DISALLOW_COPY_AND_ASSIGN(EscapeAnalysis); | 162 DISALLOW_COPY_AND_ASSIGN(EscapeAnalysis); |
| 149 }; | 163 }; |
| 150 | 164 |
| 151 } // namespace compiler | 165 } // namespace compiler |
| 152 } // namespace internal | 166 } // namespace internal |
| 153 } // namespace v8 | 167 } // namespace v8 |
| 154 | 168 |
| 155 #endif // V8_COMPILER_ESCAPE_ANALYSIS_H_ | 169 #endif // V8_COMPILER_ESCAPE_ANALYSIS_H_ |
| OLD | NEW |