forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalias-analysis.h
More file actions
182 lines (156 loc) · 7.1 KB
/
Copy pathalias-analysis.h
File metadata and controls
182 lines (156 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#pragma once
#include <bitset>
#include <string>
#include <cstdint>
#include "hphp/runtime/vm/jit/containers.h"
#include "hphp/runtime/vm/jit/alias-class.h"
#include "hphp/runtime/vm/jit/cfg.h"
#include "hphp/util/sparse-id-containers.h"
namespace HPHP::jit {
struct IRUnit;
//////////////////////////////////////////////////////////////////////
/*
* Sets of abstract locations tracked by AliasAnalysis come in ALocBits.
*
* Right now we have a static maximum number of tracked locations---passes
* using information from this module must be conservative about locations that
* aren't assigned an id. (E.g. via calls to may_alias in AliasAnalysis.)
*/
constexpr uint32_t kMaxTrackedALocs = 512;
using ALocBits = std::bitset<kMaxTrackedALocs>;
//////////////////////////////////////////////////////////////////////
struct ALocMeta {
uint32_t index; // id assigned to this location
ALocBits conflicts; // flow-insensitive may-alias set, without self
};
/*
* Information about various abstract locations an IR unit may be concerned
* with. See collect_aliases.
*/
struct AliasAnalysis {
explicit AliasAnalysis(const IRUnit&);
AliasAnalysis(const AliasAnalysis&) = delete;
AliasAnalysis(AliasAnalysis&&) = default;
AliasAnalysis& operator=(const AliasAnalysis&) = delete;
AliasAnalysis& operator=(AliasAnalysis&&) = default;
/*
* Bidirectional map from alias classes to metadata about that abstract
* memory location, primarily an assigned id. There is also an inverse map
* from id to the metadata structure.
*
* Two different alias classes in this map should not alias each other. If
* an alias class contains multiple locations (e.g., a range of stack slots,
* multiple frame locals), we need to use multiple bits in this map.
*
* The keyed locations in this map take their canonical form. You should use
* canonicalize before doing lookups.
*/
jit::hash_map<AliasClass,ALocMeta,AliasClass::Hash> locations;
jit::vector<ALocMeta> locations_inv;
using LocationMap = jit::hash_map<AliasClass,ALocBits,AliasClass::Hash>;
/*
* If an AStack, ALocal, or AIter alias class covers multiple locations,
* it will have an entry in the appropriate map here. It is okay if not all
* the memory locations aliased by the alias class are tracked. We only
* store the tracked subset here.
*/
LocationMap stk_expand_map;
LocationMap loc_expand_map;
LocationMap iter_expand_map;
/*
* Short-hand to find an alias class in the locations map, or get std::nullopt
* if the alias class wasn't assigned an ALocMeta structure.
*/
Optional<ALocMeta> find(AliasClass) const;
/*
* Several larger sets of locations, we have a set of all the ids assigned to
* properties, elemIs, frame locals, etc. This is used by may_alias below.
*/
ALocBits all_props;
ALocBits all_elemIs;
ALocBits all_elemSs;
ALocBits all_local;
ALocBits all_stack;
ALocBits all_rds;
ALocBits all_iter;
ALocBits all_fcontext;
ALocBits all_ffunc;
ALocBits all_fmeta;
/*
* Return the number of distinct locations we're tracking by id
*/
size_t count() const { return locations_inv.size(); }
/*
* Return a set of locations that we've assigned ids to that may alias a
* given AliasClass. Note that (as usual) memory locations we haven't
* assigned bits to may still be affected, but this module only reports
* effects on locations assigned bits.
*
* This function may conservatively return more bits than actually may
* overlap `acls'.
*/
ALocBits may_alias(AliasClass acls) const;
/*
* Return a set of locations that we've assigned ids to that are definitely
* contained in `acls'. This function may conservatively return a smaller
* set of bits: every bit that is set in the returned ALocBits is contained
* in `acls', but there may be locations contained in `acls' that don't have
* a bit set in the returned vector. As a consequence of this, any caller of
* expand() must produce correct (but potentially suboptimal) results if
* expand is hardcoded to always return an empty bitset.
*
* This should generally be used with AliasClasses that are exhaustive,
* must-style information. That is, AliasClasses that should be interpreted
* as referring to every point they contain. Right now, the primary example
* of that sort of AliasClasses is the class of locations in `kills' sets in
* certain memory effects structs: these sets indicate every location inside
* the class is affected.
*
* Right now, this function will work for specific AliasClasses we've
* assigned ids---for larger classes, it only supports stack ranges observed
* during alias collection, ALocalAny, and some cases of unions of those---if
* you need more to work, the implementation will need some improvements.
*/
ALocBits expand(AliasClass acls) const;
};
//////////////////////////////////////////////////////////////////////
/*
* Perform a flow-insensitive analysis on the supplied blocks, collecting
* possibly distinct abstract memory locations that are explicitly referenced,
* and assigning them ids and may-alias sets. Only certain types of locations
* are assigned ids, based on whether it maps to an AliasClass that that passes
* can currently plausibly optimize (because it is sufficiently concrete).
*
* Note: it is fine to continue to reuse one AliasAnalysis structure after
* mutating the IR, because the information it contains is both
* flow-insensitive and conservative. That is: if you change the IR to
* reference new abstract memory locations, the fact that AliasAnalysis didn't
* know about it won't invalidate the things it knows about (and the general
* may_alias function will still work on the new location). Similarly,
* removing references to locations or changing control flow won't invalidate
* anything.
*/
AliasAnalysis collect_aliases(const IRUnit&, const BlockList&);
//////////////////////////////////////////////////////////////////////
/*
* Produce summary information for debug printing.
*/
std::string show(const AliasAnalysis&);
std::string show(ALocBits);
//////////////////////////////////////////////////////////////////////
}