public void setUpUseDefLocalVarMaps() { definedLocalVars = new java.util.HashSet<Variable>(); usedLocalVars = new java.util.HashSet<Variable>(); for (BasicBlock bb : cfg().getBasicBlocks()) { for (Instr i : bb.getInstrs()) { for (Variable v : i.getUsedVariables()) { if (v instanceof LocalVariable) usedLocalVars.add(v); } if (i instanceof ResultInstr) { Variable v = ((ResultInstr) i).getResult(); if (v instanceof LocalVariable) definedLocalVars.add(v); } } } for (IRClosure cl : getClosures()) { cl.setUpUseDefLocalVarMaps(); } }
public void setUpUseDefLocalVarMaps() { definedLocalVars = new java.util.HashSet<Variable>(); usedLocalVars = new java.util.HashSet<Variable>(); for (BasicBlock bb : cfg().getBasicBlocks()) { for (Instr i : bb.getInstrs()) { for (Variable v : i.getUsedVariables()) { if (v instanceof LocalVariable) usedLocalVars.add(v); } if (i instanceof ResultInstr) { Variable v = ((ResultInstr) i).getResult(); if (v instanceof LocalVariable) definedLocalVars.add(v); } } } for (IRClosure cl : getClosures()) { cl.setUpUseDefLocalVarMaps(); } }
public void setUpUseDefLocalVarMaps() { definedLocalVars = new HashSet<>(1); usedLocalVars = new HashSet<>(1); for (BasicBlock bb : getCFG().getBasicBlocks()) { for (Instr i : bb.getInstrs()) { for (Variable v : i.getUsedVariables()) { if (v instanceof LocalVariable) usedLocalVars.add((LocalVariable) v); } if (i instanceof ResultInstr) { Variable v = ((ResultInstr) i).getResult(); if (v instanceof LocalVariable && !((LocalVariable)v).isOuterScopeVar()) { definedLocalVars.add((LocalVariable) v); } } } } for (IRClosure cl : getClosures()) { cl.setUpUseDefLocalVarMaps(); } }
public void setUpUseDefLocalVarMaps() { definedLocalVars = new HashSet<>(1); usedLocalVars = new HashSet<>(1); for (BasicBlock bb : getCFG().getBasicBlocks()) { for (Instr i : bb.getInstrs()) { for (Variable v : i.getUsedVariables()) { if (v instanceof LocalVariable) usedLocalVars.add((LocalVariable) v); } if (i instanceof ResultInstr) { Variable v = ((ResultInstr) i).getResult(); if (v instanceof LocalVariable && !((LocalVariable)v).isOuterScopeVar()) { definedLocalVars.add((LocalVariable) v); } } } } for (IRClosure cl : getClosures()) { cl.setUpUseDefLocalVarMaps(); } }
private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int nestingLevel) { int clBaseDepth = nestingLevel + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1); cl.setUpUseDefLocalVarMaps(); for (LocalVariable lv: cl.getUsedLocalVariables()) { // This can happen where an outer scope variable // is not used in this scope but is used in a nested // scope. Ex: ~jruby/bin/ast:21 if (problem.getDFVar(lv) == null) { continue; } // Find variables which belong to the problem.getScope() if (lv.getScopeDepth() == clBaseDepth && !tmp.get(problem.getDFVar(lv))) { // We want lv suitable for initializing in this scope undefinedVars.add(!lv.isOuterScopeVar() ? lv : lv.cloneForDepth(0)); tmp.set(problem.getDFVar(lv)); } } // Recurse for (IRClosure nestedCl: cl.getClosures()) { identifyUndefinedVarsInClosure(undefinedVars, nestedCl, nestingLevel + 1); } }
private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int nestingLevel) { int clBaseDepth = nestingLevel + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1); cl.setUpUseDefLocalVarMaps(); for (LocalVariable lv: cl.getUsedLocalVariables()) { // This can happen where an outer scope variable // is not used in this scope but is used in a nested // scope. Ex: ~jruby/bin/ast:21 if (problem.getDFVar(lv) == null) { continue; } // Find variables which belong to the problem.getScope() if (lv.getScopeDepth() == clBaseDepth && !tmp.get(problem.getDFVar(lv))) { // We want lv suitable for initializing in this scope undefinedVars.add(!lv.isOuterScopeVar() ? lv : lv.cloneForDepth(0)); tmp.set(problem.getDFVar(lv)); } } // Recurse for (IRClosure nestedCl: cl.getClosures()) { identifyUndefinedVarsInClosure(undefinedVars, nestedCl, nestingLevel + 1); } }