@Override public void encode(Instr instr) { for (Operand operand: instr.getOperands()) { increment(operand); } }
@Override public void encode(Instr instr) { for (Operand operand: instr.getOperands()) { increment(operand); } }
public Operand[] cloneOperands(CloneInfo info) { Operand[] operands = getOperands(); Operand[] newOperands = new Operand[operands.length]; for (int i = 0; i < operands.length; i++) { newOperands[i] = operands[i].cloneForInlining(info); } return newOperands; } /**
public List<Variable> getUsedVariables() { ArrayList<Variable> vars = new ArrayList<Variable>(); for (Operand o : getOperands()) { o.addUsedVariables(vars); } return vars; }
public List<Variable> getUsedVariables() { ArrayList<Variable> vars = new ArrayList<>(); for (Operand operand : getOperands()) { operand.addUsedVariables(vars); } return vars; }
public Operand[] cloneOperands(CloneInfo info) { Operand[] operands = getOperands(); Operand[] newOperands = new Operand[operands.length]; for (int i = 0; i < operands.length; i++) { newOperands[i] = operands[i].cloneForInlining(info); } return newOperands; } /**
public List<Variable> getUsedVariables() { ArrayList<Variable> vars = new ArrayList<>(); for (Operand operand : getOperands()) { operand.addUsedVariables(vars); } return vars; }
public List<Variable> getUsedVariables() { ArrayList<Variable> vars = new ArrayList<Variable>(); for (Operand o : getOperands()) { o.addUsedVariables(vars); } return vars; }
/** * This method takes as input a map of operands to their values, and outputs * * If the value map provides a value for any of the instruction's operands * this method is expected to replace the original operands with the simplified values. * It is not required that it do so -- code correctness is not compromised by failure * to simplify */ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) { if (getOperands() != EMPTY_OPERANDS) { System.out.println("simplifyOperands: Missing implementation for: " + this.getOperation()); throw new RuntimeException("simplifyOperands: Missing implementation for: " + this.getOperation()); } }
/** * This method takes as input a map of operands to their values, and outputs * * If the value map provides a value for any of the instruction's operands * this method is expected to replace the original operands with the simplified values. * It is not required that it do so -- code correctness is not compromised by failure * to simplify */ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) { if (getOperands() != EMPTY_OPERANDS) { System.out.println("simplifyOperands: Missing implementation for: " + this.getOperation()); throw new RuntimeException("simplifyOperands: Missing implementation for: " + this.getOperation()); } }
public String toStringVariables() { Map<Variable, Integer> ends = new HashMap<Variable, Integer>(); Map<Variable, Integer> starts = new HashMap<Variable, Integer>(); SortedSet<Variable> variables = new TreeSet<Variable>(); for (int i = instrList.size() - 1; i >= 0; i--) { Instr instr = instrList.get(i); if (instr instanceof ResultInstr) { Variable var = ((ResultInstr) instr).getResult(); variables.add(var); starts.put(var, i); } for (Operand operand : instr.getOperands()) { if (operand != null && operand instanceof Variable && ends.get((Variable)operand) == null) { ends.put((Variable)operand, i); variables.add((Variable)operand); } } } StringBuilder sb = new StringBuilder(); int i = 0; for (Variable var : variables) { Integer end = ends.get(var); if (end != null) { // Variable is actually used somewhere and not dead if (i > 0) sb.append("\n"); i++; sb.append(" ").append(var).append(": ").append(starts.get(var)).append("-").append(end); } } return sb.toString(); }
public String toStringVariables() { Map<Variable, Integer> ends = new HashMap<Variable, Integer>(); Map<Variable, Integer> starts = new HashMap<Variable, Integer>(); SortedSet<Variable> variables = new TreeSet<Variable>(); for (int i = instrList.size() - 1; i >= 0; i--) { Instr instr = instrList.get(i); if (instr instanceof ResultInstr) { Variable var = ((ResultInstr) instr).getResult(); variables.add(var); starts.put(var, i); } for (Operand operand : instr.getOperands()) { if (operand != null && operand instanceof Variable && ends.get((Variable)operand) == null) { ends.put((Variable)operand, i); variables.add((Variable)operand); } } } StringBuilder sb = new StringBuilder(); int i = 0; for (Variable var : variables) { Integer end = ends.get(var); if (end != null) { // Variable is actually used somewhere and not dead if (i > 0) sb.append("\n"); i++; sb.append(" ").append(var).append(": ").append(starts.get(var)).append("-").append(end); } } return sb.toString(); }
/** * This method takes as input a map of operands to their values, and outputs * * If the value map provides a value for any of the instruction's operands * this method is expected to replace the original operands with the simplified values. * It is not required that it do so -- code correctness is not compromised by failure * to simplify */ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) { Operand[] operands = getOperands(); for (int i = 0; i < operands.length; i++) { setOperand(i, operands[i].getSimplifiedOperand(valueMap, force)); } }
/** * This method takes as input a map of operands to their values, and outputs * * If the value map provides a value for any of the instruction's operands * this method is expected to replace the original operands with the simplified values. * It is not required that it do so -- code correctness is not compromised by failure * to simplify */ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) { Operand[] operands = getOperands(); for (int i = 0; i < operands.length; i++) { setOperand(i, operands[i].getSimplifiedOperand(valueMap, force)); } }
/** * Instructions are meant to be in a machine-readable format so offline tooling can parse the * debugging output. The format is: * * (result_op '=')? instr '(' (operand ',' )* operand? ';' (extra_arg ',')* extra_arg? ')' * extra_arg can either be plain value or in a key: value format. * @return a String */ @Override public String toString() { StringBuilder buf = new StringBuilder(isDead() ? "[DEAD]" : ""); if (this instanceof ResultInstr) buf.append(((ResultInstr) this).getResult()).append(" = "); Operand[] operands = getOperands(); buf.append(operation).append('('); toArgList(buf, operands); String[] extraArgs = toStringNonOperandArgs(); if (extraArgs.length >= 1) { if (operands.length > 0) buf.append(' '); buf.append(';'); toArgList(buf, extraArgs); } buf.append(')'); return buf.toString(); }
/** * Instructions are meant to be in a machine-readable format so offline tooling can parse the * debugging output. The format is: * * (result_op '=')? instr '(' (operand ',' )* operand? ';' (extra_arg ',')* extra_arg? ')' * extra_arg can either be plain value or in a key: value format. * @return a String */ @Override public String toString() { StringBuilder buf = new StringBuilder(isDead() ? "[DEAD]" : ""); if (this instanceof ResultInstr) buf.append(((ResultInstr) this).getResult()).append(" = "); Operand[] operands = getOperands(); buf.append(operation).append('('); toArgList(buf, operands); String[] extraArgs = toStringNonOperandArgs(); if (extraArgs.length >= 1) { if (operands.length > 0) buf.append(' '); buf.append(';'); toArgList(buf, extraArgs); } buf.append(')'); return buf.toString(); }
/** * Wrapped IRClosures in dead BB are lexically rooted to that dead BB so they can * be removed from the parent scope if the BB they live in died. */ private void removeNestedScopesFromBB(BasicBlock bb) { for (Instr instr: bb.getInstrs()) { for (Operand oper: instr.getOperands()) { if (oper instanceof WrappedIRClosure) { scope.removeClosure(((WrappedIRClosure) oper).getClosure()); break; // Only one WrappedIRClosure possible per instr } } } }
/** * Wrapped IRClosures in dead BB are lexically rooted to that dead BB so they can * be removed from the parent scope if the BB they live in died. */ private void removeNestedScopesFromBB(BasicBlock bb) { for (Instr instr: bb.getInstrs()) { for (Operand oper: instr.getOperands()) { if (oper instanceof WrappedIRClosure) { scope.removeClosure(((WrappedIRClosure) oper).getClosure()); break; // Only one WrappedIRClosure possible per instr } } } }
@Override public void visit(Instr instr) { printAnsi(INSTR_COLOR, instr.getOperation().toString().toLowerCase()); boolean comma = false; for (Operand o : instr.getOperands()) { if (!comma) printAnsi(INSTR_COLOR, "("); if (comma) print(", "); comma = true; visit(o); } for (Field f : instr.dumpableFields()) { if (!comma) printAnsi(INSTR_COLOR, "("); if (comma) print(", "); comma = true; f.setAccessible(true); printAnsi(FIELD_COLOR, f.getName() + ": "); print(get(f, instr)); } if (comma) printAnsi(INSTR_COLOR, ")"); }
@Override public void visit(Instr instr) { printAnsi(INSTR_COLOR, instr.getOperation().toString().toLowerCase()); boolean comma = false; for (Operand o : instr.getOperands()) { if (!comma) printAnsi(INSTR_COLOR, "("); if (comma) print(", "); comma = true; visit(o); } for (Field f : instr.dumpableFields()) { if (!comma) printAnsi(INSTR_COLOR, "("); if (comma) print(", "); comma = true; f.setAccessible(true); printAnsi(FIELD_COLOR, f.getName() + ": "); print(get(f, instr)); } if (comma) printAnsi(INSTR_COLOR, ")"); }