public static List<BasicBlock> linearize(CFG cfg) { List<BasicBlock> list = new ArrayList<BasicBlock>(); BitSet processed = new BitSet(cfg.size()); // Assumes all id's are used linearizeInner(cfg, list, processed, cfg.getEntryBB()); verifyAllBasicBlocksProcessed(cfg, processed); fixupList(cfg, list); return list; }
private static void linearizeInner(CFG cfg, List<BasicBlock> list, BitSet processed, BasicBlock current) { if (processed.get(current.getID())) return; // Cannot lay out current block till its fall-through predecessor has been laid out already BasicBlock source = cfg.getIncomingSourceOfType(current, EdgeType.FALL_THROUGH); if (source != null && !processed.get(source.getID())) return; list.add(current); processed.set(current.getID()); // First, fall-through BB BasicBlock fallThrough = cfg.getOutgoingDestinationOfType(current, EdgeType.FALL_THROUGH); if (fallThrough != null) linearizeInner(cfg, list, processed, fallThrough); // Next, regular edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.REGULAR)) { linearizeInner(cfg, list, processed, destination); } // Next, exception edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.EXCEPTION)) { linearizeInner(cfg, list, processed, destination); } // Next, exit for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.EXIT)) { linearizeInner(cfg, list, processed, destination); } }
private static int linearizeInner(CFG cfg, BasicBlock[] list, int listSize, BitSet processed, BasicBlock current) { if (processed.get(current.getID())) return listSize; // Cannot lay out current block till its fall-through predecessor has been laid out already BasicBlock source = cfg.getIncomingSourceOfType(current, FALL_THROUGH); if (source != null && !processed.get(source.getID())) return listSize; list[listSize] = current; listSize++; processed.set(current.getID()); // First, fall-through BB BasicBlock fallThrough = cfg.getOutgoingDestinationOfType(current, FALL_THROUGH); if (fallThrough != null) listSize = linearizeInner(cfg, list, listSize, processed, fallThrough); // Next, regular edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, REGULAR)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } // Next, exception edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EXCEPTION)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } // Next, exit for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EXIT)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } return listSize; }
private static int linearizeInner(CFG cfg, BasicBlock[] list, int listSize, BitSet processed, BasicBlock current) { if (processed.get(current.getID())) return listSize; // Cannot lay out current block till its fall-through predecessor has been laid out already BasicBlock source = cfg.getIncomingSourceOfType(current, FALL_THROUGH); if (source != null && !processed.get(source.getID())) return listSize; list[listSize] = current; listSize++; processed.set(current.getID()); // First, fall-through BB BasicBlock fallThrough = cfg.getOutgoingDestinationOfType(current, FALL_THROUGH); if (fallThrough != null) listSize = linearizeInner(cfg, list, listSize, processed, fallThrough); // Next, regular edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, REGULAR)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } // Next, exception edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EXCEPTION)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } // Next, exit for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EXIT)) { listSize = linearizeInner(cfg, list, listSize, processed, destination); } return listSize; }
public static List<BasicBlock> linearize(CFG cfg) { List<BasicBlock> list = new ArrayList<BasicBlock>(); BitSet processed = new BitSet(cfg.size()); // Assumes all id's are used linearizeInner(cfg, list, processed, cfg.getEntryBB()); verifyAllBasicBlocksProcessed(cfg, processed); fixupList(cfg, list); return list; }
private static void linearizeInner(CFG cfg, List<BasicBlock> list, BitSet processed, BasicBlock current) { if (processed.get(current.getID())) return; // Cannot lay out current block till its fall-through predecessor has been laid out already BasicBlock source = cfg.getIncomingSourceOfType(current, EdgeType.FALL_THROUGH); if (source != null && !processed.get(source.getID())) return; list.add(current); processed.set(current.getID()); // First, fall-through BB BasicBlock fallThrough = cfg.getOutgoingDestinationOfType(current, EdgeType.FALL_THROUGH); if (fallThrough != null) linearizeInner(cfg, list, processed, fallThrough); // Next, regular edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.REGULAR)) { linearizeInner(cfg, list, processed, destination); } // Next, exception edges for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.EXCEPTION)) { linearizeInner(cfg, list, processed, destination); } // Next, exit for (BasicBlock destination: cfg.getOutgoingDestinationsOfType(current, EdgeType.EXIT)) { linearizeInner(cfg, list, processed, destination); } }
public static BasicBlock[] linearize(CFG cfg) { BasicBlock[] list = new BasicBlock[cfg.size()]; BitSet processed = new BitSet(cfg.size()); int listSize = linearizeInner(cfg, list, 0, processed, cfg.getEntryBB()); verifyAllBasicBlocksProcessed(cfg, processed); fixupList(cfg, list, listSize); return list; }
public static BasicBlock[] linearize(CFG cfg) { BasicBlock[] list = new BasicBlock[cfg.size()]; BitSet processed = new BitSet(cfg.size()); int listSize = linearizeInner(cfg, list, 0, processed, cfg.getEntryBB()); verifyAllBasicBlocksProcessed(cfg, processed); fixupList(cfg, list, listSize); return list; }