public List<BasicBlock> linearization() { depends(cfg()); assert linearizedBBList != null : "You have not run linearization"; return linearizedBBList; }
public void inlineMethod( IRScope method, RubyModule implClass, int classToken, BasicBlock basicBlock, CallBase call) { // Inline depends(cfg()); new CFGInliner(cfg).inlineMethod(method, implClass, classToken, basicBlock, call); // Reset state resetState(); // Re-run opts for (CompilerPass pass : getManager().getInliningCompilerPasses(this)) { pass.run(this); } }
private Instr[] prepareInstructionsForInterpretation() { checkRelinearization(); if (linearizedInstrArray != null) return linearizedInstrArray; // Already prepared try { buildLinearization(); // FIXME: compiler passes should have done this depends(linearization()); } catch (RuntimeException e) { LOG.error("Error linearizing cfg: ", e); CFG c = cfg(); LOG.error("\nGraph:\n" + c.toStringGraph()); LOG.error("\nInstructions:\n" + c.toStringInstrs()); throw e; } // Set up IPCs HashMap<Label, Integer> labelIPCMap = new HashMap<Label, Integer>(); List<Instr> newInstrs = new ArrayList<Instr>(); int ipc = 0; for (BasicBlock b : linearizedBBList) { labelIPCMap.put(b.getLabel(), ipc); List<Instr> bbInstrs = b.getInstrs(); int bbInstrsLength = bbInstrs.size(); for (int i = 0; i < bbInstrsLength; i++) { Instr instr = bbInstrs.get(i); if (instr instanceof Specializeable) { instr = ((Specializeable) instr).specializeForInterpretation(); bbInstrs.set(i, instr); } if (!(instr instanceof ReceiveSelfInstr)) { newInstrs.add(instr); ipc++; } } } // Set up label PCs setupLabelPCs(labelIPCMap); // Exit BB ipc cfg().getExitBB().getLabel().setTargetPC(ipc + 1); linearizedInstrArray = newInstrs.toArray(new Instr[newInstrs.size()]); return linearizedInstrArray; }
// SSS FIXME: Extremely inefficient public int getEnsurerPC(Instr excInstr) { depends(cfg()); for (BasicBlock b : linearizedBBList) { for (Instr i : b.getInstrs()) { if (i == excInstr) { BasicBlock ensurerBB = cfg.getEnsurerBBFor(b); return (ensurerBB == null) ? -1 : ensurerBB.getLabel().getTargetPC(); } } } // SSS FIXME: Cannot happen! Throw runtime exception LOG.error("Fell through looking for ensurer ipc for " + excInstr); return -1; }
/** Run any necessary passes to get the IR ready for compilation */ public Tuple<Instr[], Map<Integer, Label[]>> prepareForCompilation() { // Build CFG and run compiler passes, if necessary if (getCFG() == null) runCompilerPasses(); // Add this always since we dont re-JIT a previously // JIT-ted closure. But, check if there are other // smarts available to us and eliminate adding this // code to every closure there is. // // Add a global ensure block to catch uncaught breaks // and throw a LocalJumpError. if (this instanceof IRClosure && ((IRClosure) this).addGEBForUncaughtBreaks()) { this.relinearizeCFG = true; } try { buildLinearization(); // FIXME: compiler passes should have done this depends(linearization()); } catch (RuntimeException e) { LOG.error("Error linearizing cfg: ", e); CFG c = cfg(); LOG.error("\nGraph:\n" + c.toStringGraph()); LOG.error("\nInstructions:\n" + c.toStringInstrs()); throw e; } // Set up IPCs // FIXME: Would be nice to collapse duplicate labels; for now, using Label[] HashMap<Integer, Label[]> ipcLabelMap = new HashMap<Integer, Label[]>(); List<Instr> newInstrs = new ArrayList<Instr>(); int ipc = 0; for (BasicBlock b : linearizedBBList) { Label l = b.getLabel(); ipcLabelMap.put(ipc, catLabels(ipcLabelMap.get(ipc), l)); for (Instr i : b.getInstrs()) { if (!(i instanceof ReceiveSelfInstr)) { newInstrs.add(i); ipc++; } } } return new Tuple<Instr[], Map<Integer, Label[]>>( newInstrs.toArray(new Instr[newInstrs.size()]), ipcLabelMap); }