michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* May-return analysis. michael@0: * This makes sense only for functions that return a value. The analysis michael@0: * determines the set of variables that may transitively reach the return michael@0: * statement. */ michael@0: michael@0: function MayReturnAnalysis() { michael@0: BackwardAnalysis.apply(this, arguments); michael@0: // May-return variables. We collect them all here. michael@0: this.vbls = create_decl_set(); michael@0: // The return value variable itself michael@0: this.retvar = undefined; michael@0: } michael@0: michael@0: MayReturnAnalysis.prototype = new BackwardAnalysis; michael@0: michael@0: MayReturnAnalysis.prototype.flowState = function(isn, state) { michael@0: if (TREE_CODE(isn) == GIMPLE_RETURN) { michael@0: let v = return_expr(isn); michael@0: if (!v) michael@0: return; michael@0: if (v.tree_code() == RESULT_DECL) // only an issue with 4.3 michael@0: throw new Error("Weird case hit"); michael@0: this.vbls.add(v); michael@0: state.add(v); michael@0: this.retvar = v; michael@0: } else if (TREE_CODE(isn) == GIMPLE_ASSIGN) { michael@0: let lhs = gimple_op(isn, 0); michael@0: let rhs = gimple_op(isn, 1); michael@0: if (DECL_P(rhs) && DECL_P(lhs) && state.has(lhs)) { michael@0: this.vbls.add(rhs); michael@0: state.add(rhs); michael@0: } michael@0: michael@0: for (let e in isn_defs(isn, 'strong')) { michael@0: if (DECL_P(e)) { michael@0: state.remove(e); michael@0: } michael@0: } michael@0: } michael@0: };