Chromium Code Reviews| 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_ESCAPE_ANALYSIS_H_ | |
| 6 #define V8_COMPILER_ESCAPE_ANALYSIS_H_ | |
| 7 | |
| 8 #include "src/base/flags.h" | |
| 9 #include "src/compiler/graph.h" | |
| 10 | |
| 11 namespace v8 { | |
| 12 namespace internal { | |
| 13 | |
| 14 // Forward declarations. | |
| 15 class CompilationDependencies; | |
| 16 class TypeCache; | |
|
Michael Starzinger
2015/11/30 10:05:39
nit: Some of the forward declarations seem not to
sigurds
2015/11/30 13:50:24
Done.
| |
| 17 | |
| 18 | |
| 19 namespace compiler { | |
| 20 | |
| 21 // Forward declarations. | |
| 22 class CommonOperatorBuilder; | |
| 23 | |
| 24 | |
| 25 class VirtualObject : public ZoneObject { | |
| 26 public: | |
| 27 enum Status { kUntracked = 0, kTracked = 1 }; | |
| 28 VirtualObject(NodeId id, Zone* zone) | |
| 29 : id_(id), status_(kUntracked), fields_(zone), representation_(nullptr) {} | |
| 30 | |
| 31 VirtualObject(const VirtualObject& other) | |
| 32 : id_(other.id_), | |
| 33 status_(other.status_), | |
| 34 fields_(other.fields_), | |
| 35 representation_(other.representation_) {} | |
| 36 | |
| 37 VirtualObject(NodeId id, Zone* zone, size_t field_number) | |
| 38 : id_(id), status_(kTracked), fields_(zone), representation_(nullptr) { | |
| 39 fields_.resize(field_number); | |
| 40 } | |
| 41 | |
| 42 Node* GetField(size_t offset) { return fields_[offset]; } | |
| 43 bool SetField(size_t offset, Node* node) { | |
| 44 bool changed = fields_[offset] != node; | |
| 45 fields_[offset] = node; | |
| 46 return changed; | |
| 47 } | |
| 48 bool IsVirtual() const { return status_ == kTracked; } | |
| 49 bool IsTracked() const { return status_ != kUntracked; } | |
| 50 Node* GetRepresentation() { return representation_; } | |
| 51 bool SetRepresentation(Node* node) { | |
| 52 bool changed = representation_ != node; | |
| 53 representation_ = node; | |
| 54 return changed; | |
| 55 } | |
| 56 size_t fields() { return fields_.size(); } | |
| 57 | |
| 58 bool UpdateFrom(const VirtualObject& other); | |
| 59 | |
| 60 NodeId id() { return id_; } | |
| 61 void id(NodeId id) { id_ = id; } | |
| 62 | |
| 63 private: | |
| 64 NodeId id_; | |
| 65 Status status_; | |
| 66 ZoneVector<Node*> fields_; | |
| 67 Node* representation_; | |
| 68 }; | |
| 69 | |
| 70 | |
| 71 class VirtualState : public ZoneObject { | |
| 72 public: | |
| 73 VirtualState(Zone* zone, size_t size); | |
| 74 VirtualState(const VirtualState& states); | |
| 75 | |
| 76 VirtualObject* GetState(Node* node); | |
| 77 VirtualObject* GetState(size_t id); | |
| 78 void SetState(NodeId id, VirtualObject* state); | |
| 79 void SetLastChanged(Node* node) { last_changed_ = node; } | |
| 80 Node* GetLastChanged() { return last_changed_; } | |
| 81 bool UpdateFrom(NodeId id, VirtualObject* state, Zone* zone); | |
| 82 | |
| 83 size_t size() { return info_.size(); } | |
| 84 | |
| 85 private: | |
| 86 ZoneVector<VirtualObject*> info_; | |
| 87 Node* last_changed_; | |
| 88 }; | |
| 89 | |
| 90 | |
| 91 // EscapeStatusAnalysis determines for each allocation whether it escapes. | |
| 92 class EscapeStatusAnalysis { | |
| 93 public: | |
| 94 EscapeStatusAnalysis(Graph* graph, Zone* zone); | |
| 95 ~EscapeStatusAnalysis(); | |
| 96 | |
| 97 enum EscapeStatusFlag { | |
| 98 kUnknown = 0u, | |
| 99 kVirtual = 1u << 0, | |
| 100 kEscaped = 1u << 1, | |
| 101 }; | |
| 102 typedef base::Flags<EscapeStatusFlag> EscapeStatusFlags; | |
| 103 | |
| 104 void Run(); | |
| 105 | |
| 106 bool HasEntry(Node* node); | |
| 107 bool IsVirtual(Node* node); | |
| 108 bool IsEscaped(Node* node); | |
| 109 | |
| 110 void DebugPrint(); | |
| 111 | |
| 112 private: | |
| 113 void Process(Node* node); | |
| 114 void ProcessAllocate(Node* node); | |
| 115 void ProcessFinishRegion(Node* node); | |
| 116 void ProcessStoreField(Node* node); | |
| 117 bool CheckUsesForEscape(Node* node); | |
| 118 void RevisitUses(Node* node); | |
| 119 void RevisitInputs(Node* node); | |
| 120 bool SetEscaped(Node* node); | |
| 121 | |
| 122 Graph* graph() const { return graph_; } | |
| 123 Zone* zone() const { return zone_; } | |
| 124 | |
| 125 Graph* const graph_; | |
| 126 Zone* const zone_; | |
| 127 ZoneVector<EscapeStatusFlags> info_; | |
| 128 ZoneDeque<Node*> queue_; | |
| 129 }; | |
| 130 | |
| 131 | |
| 132 DEFINE_OPERATORS_FOR_FLAGS(EscapeStatusAnalysis::EscapeStatusFlags) | |
| 133 | |
| 134 | |
| 135 // EscapeObjectAnalysis simulates stores to determine values of loads if | |
| 136 // an object is virtual and eliminated. | |
| 137 class EscapeObjectAnalysis { | |
| 138 public: | |
| 139 EscapeObjectAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone); | |
| 140 ~EscapeObjectAnalysis(); | |
| 141 | |
| 142 void Run(); | |
| 143 | |
| 144 Node* representation(Node* at, NodeId id); | |
| 145 | |
| 146 private: | |
| 147 bool Process(Node* node); | |
| 148 void ProcessLoadField(Node* node); | |
| 149 void ProcessStoreField(Node* node); | |
| 150 void ProcessAllocation(Node* node); | |
| 151 void ProcessFinishRegion(Node* node); | |
| 152 void ProcessCall(Node* node); | |
| 153 void ProcessStart(Node* node); | |
| 154 bool ProcessEffectPhi(Node* node); | |
| 155 void ForwardObjectState(Node* node); | |
| 156 bool IsEffectBranchPoint(Node* node); | |
| 157 bool IsDanglingEffectNode(Node* node); | |
| 158 | |
| 159 void DebugPrint(); | |
| 160 | |
| 161 Graph* graph() const { return graph_; } | |
| 162 CommonOperatorBuilder* common() const { return common_; } | |
| 163 Zone* zone() const { return zone_; } | |
| 164 | |
| 165 Graph* const graph_; | |
| 166 CommonOperatorBuilder* const common_; | |
| 167 Zone* const zone_; | |
| 168 ZoneVector<VirtualState*> states_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(EscapeObjectAnalysis); | |
| 171 }; | |
| 172 | |
| 173 } // namespace compiler | |
| 174 } // namespace internal | |
| 175 } // namespace v8 | |
| 176 | |
| 177 #endif // V8_COMPILER_TYPER_H_ | |
| OLD | NEW |