forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.cpp
132 lines (107 loc) · 4.03 KB
/
analysis.cpp
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
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2014 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 |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/vm/jit/analysis.h"
#include "hphp/util/assertions.h"
#include "hphp/runtime/vm/jit/ssa-tmp.h"
#include "hphp/runtime/vm/jit/ir-instruction.h"
#include "hphp/runtime/vm/jit/block.h"
#include "hphp/runtime/vm/jit/id-set.h"
namespace HPHP { namespace jit {
//////////////////////////////////////////////////////////////////////
const SSATmp* canonical(const SSATmp* val) {
return canonical(const_cast<SSATmp*>(val));
}
SSATmp* canonical(SSATmp* value) {
if (value == nullptr) return nullptr;
auto inst = value->inst();
while (inst->isPassthrough()) {
value = inst->getPassthroughValue();
inst = value->inst();
}
return value;
}
//////////////////////////////////////////////////////////////////////
IRInstruction* findSpillFrame(SSATmp* sp) {
auto inst = sp->inst();
while (!inst->is(SpillFrame)) {
if (debug) {
[&] {
for (auto const& dst : inst->dsts()) {
if (dst.isA(Type::StkPtr)) return;
}
assert(false);
}();
}
assert(!inst->is(RetAdjustStack));
if (inst->is(DefSP)) return nullptr;
if (inst->is(InterpOne) && isFPush(inst->extra<InterpOne>()->opcode)) {
// A non-punted translation of this bytecode would contain a SpillFrame.
return nullptr;
}
// M-instr support opcodes have the previous sp in varying sources.
if (inst->modifiesStack()) inst = inst->previousStkPtr()->inst();
else inst = inst->src(0)->inst();
}
return inst;
}
//////////////////////////////////////////////////////////////////////
Block* findDefiningBlock(const SSATmp* t) {
assert(!t->inst()->is(DefConst));
auto const srcInst = t->inst();
/*
* Instructions that define temporaries that also have edges define the
* temporary only if they do not take the taken edge. Since the temporary is
* defined on the fallthrough edge, this means we only have a block that we
* can return if this edge is not the only edge leading to its target.
*/
if (srcInst->hasEdges()) {
auto const next = srcInst->next();
UNUSED auto const taken = srcInst->taken();
always_assert_flog(
next && taken,
"hasEdges instruction defining a dst had no edges:\n {}\n",
srcInst->toString()
);
return next->numPreds() == 1 ? next : nullptr;
}
return srcInst->block();
}
//////////////////////////////////////////////////////////////////////
SSATmp* least_common_ancestor(SSATmp* s1, SSATmp* s2) {
if (s1 == s2) return s1;
if (s1 == nullptr || s2 == nullptr) return nullptr;
IdSet<SSATmp> seen;
auto const step = [] (SSATmp* v) {
assert(v != nullptr);
return v->inst()->isPassthrough() ?
v->inst()->getPassthroughValue() :
nullptr;
};
auto const process = [&] (SSATmp*& v) {
if (v == nullptr) return false;
if (seen[v]) return true;
seen.add(v);
v = step(v);
return false;
};
while (s1 != nullptr || s2 != nullptr) {
if (process(s1)) return s1;
if (process(s2)) return s2;
}
return nullptr;
}
//////////////////////////////////////////////////////////////////////
}}