blob: 839e54ccd3e5fc4277eac6d1d5c8116d140b60fc [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 Murdoch097c5b22016-05-18 11:27:45 +010054 VirtualState* CopyForModificationAt(VirtualState* state, Node* node);
55 VirtualObject* CopyForModificationAt(VirtualObject* obj, VirtualState* state,
56 Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 Node* replacement(Node* node);
59 Node* ResolveReplacement(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 bool SetReplacement(Node* node, Node* rep);
61 bool UpdateReplacement(VirtualState* state, Node* node, Node* rep);
62
63 VirtualObject* GetVirtualObject(VirtualState* state, Node* node);
64
65 void DebugPrint();
66 void DebugPrintState(VirtualState* state);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067
Ben Murdochc5610432016-08-08 18:44:38 +010068 Graph* graph() const;
69 Zone* zone() const { return zone_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 CommonOperatorBuilder* common() const { return common_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071
Ben Murdochc5610432016-08-08 18:44:38 +010072 Zone* const zone_;
Ben Murdoch61f157c2016-09-16 13:49:30 +010073 Node* const slot_not_analyzed_;
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_