blob: 139abd72c8c5c0e6889d9a7922c9a4772e5e1ecb [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/compiler/graph.h"
9
10namespace v8 {
11namespace internal {
12namespace compiler {
13
14// Forward declarations.
15class CommonOperatorBuilder;
Ben Murdochc5610432016-08-08 18:44:38 +010016class EscapeStatusAnalysis;
17class MergeCache;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018class VirtualState;
19class VirtualObject;
20
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000021// EscapeObjectAnalysis simulates stores to determine values of loads if
22// an object is virtual and eliminated.
23class EscapeAnalysis {
24 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025 EscapeAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone);
26 ~EscapeAnalysis();
27
28 void Run();
29
30 Node* GetReplacement(Node* node);
31 bool IsVirtual(Node* node);
32 bool IsEscaped(Node* node);
33 bool CompareVirtualObjects(Node* left, Node* right);
34 Node* GetOrCreateObjectState(Node* effect, Node* node);
Ben Murdoch097c5b22016-05-18 11:27:45 +010035 bool ExistsVirtualAllocate();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036
37 private:
38 void RunObjectAnalysis();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 bool Process(Node* node);
40 void ProcessLoadField(Node* node);
41 void ProcessStoreField(Node* node);
42 void ProcessLoadElement(Node* node);
43 void ProcessStoreElement(Node* node);
44 void ProcessAllocationUsers(Node* node);
45 void ProcessAllocation(Node* node);
46 void ProcessFinishRegion(Node* node);
47 void ProcessCall(Node* node);
48 void ProcessStart(Node* node);
49 bool ProcessEffectPhi(Node* node);
50 void ProcessLoadFromPhi(int offset, Node* from, Node* node,
51 VirtualState* states);
52
53 void ForwardVirtualState(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054 int OffsetFromAccess(Node* node);
Ben Murdoch097c5b22016-05-18 11:27:45 +010055 VirtualState* CopyForModificationAt(VirtualState* state, Node* node);
56 VirtualObject* CopyForModificationAt(VirtualObject* obj, VirtualState* state,
57 Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000059 Node* replacement(Node* node);
60 Node* ResolveReplacement(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000061 bool SetReplacement(Node* node, Node* rep);
62 bool UpdateReplacement(VirtualState* state, Node* node, Node* rep);
63
64 VirtualObject* GetVirtualObject(VirtualState* state, Node* node);
65
66 void DebugPrint();
67 void DebugPrintState(VirtualState* state);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068
Ben Murdochc5610432016-08-08 18:44:38 +010069 Graph* graph() const;
70 Zone* zone() const { return zone_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 CommonOperatorBuilder* common() const { return common_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072
Ben Murdochc5610432016-08-08 18:44:38 +010073 Zone* const zone_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074 CommonOperatorBuilder* const common_;
Ben Murdochc5610432016-08-08 18:44:38 +010075 EscapeStatusAnalysis* status_analysis_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 ZoneVector<VirtualState*> virtual_states_;
77 ZoneVector<Node*> replacements_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 MergeCache* cache_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000079
80 DISALLOW_COPY_AND_ASSIGN(EscapeAnalysis);
81};
82
83} // namespace compiler
84} // namespace internal
85} // namespace v8
86
87#endif // V8_COMPILER_ESCAPE_ANALYSIS_H_