|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /* May-return analysis. |
|
6 * This makes sense only for functions that return a value. The analysis |
|
7 * determines the set of variables that may transitively reach the return |
|
8 * statement. */ |
|
9 |
|
10 function MayReturnAnalysis() { |
|
11 BackwardAnalysis.apply(this, arguments); |
|
12 // May-return variables. We collect them all here. |
|
13 this.vbls = create_decl_set(); |
|
14 // The return value variable itself |
|
15 this.retvar = undefined; |
|
16 } |
|
17 |
|
18 MayReturnAnalysis.prototype = new BackwardAnalysis; |
|
19 |
|
20 MayReturnAnalysis.prototype.flowState = function(isn, state) { |
|
21 if (TREE_CODE(isn) == GIMPLE_RETURN) { |
|
22 let v = return_expr(isn); |
|
23 if (!v) |
|
24 return; |
|
25 if (v.tree_code() == RESULT_DECL) // only an issue with 4.3 |
|
26 throw new Error("Weird case hit"); |
|
27 this.vbls.add(v); |
|
28 state.add(v); |
|
29 this.retvar = v; |
|
30 } else if (TREE_CODE(isn) == GIMPLE_ASSIGN) { |
|
31 let lhs = gimple_op(isn, 0); |
|
32 let rhs = gimple_op(isn, 1); |
|
33 if (DECL_P(rhs) && DECL_P(lhs) && state.has(lhs)) { |
|
34 this.vbls.add(rhs); |
|
35 state.add(rhs); |
|
36 } |
|
37 |
|
38 for (let e in isn_defs(isn, 'strong')) { |
|
39 if (DECL_P(e)) { |
|
40 state.remove(e); |
|
41 } |
|
42 } |
|
43 } |
|
44 }; |