public override void Run(IRContext context) { var intervals = IRBasicBlock.GetIntervalSequence(context.Function.BasicBlocks, context.Function.BasicBlocks[0]); foreach (var gi in intervals) { var ni = gi.SelectMany(g => g.GetNodes()).ToArray(); foreach (var intervalNode in gi) { var headBBlock = intervalNode.GetHeadBasicBlock(); var nodes = intervalNode.GetAllBasicBlocks().ToArray(); IRBasicBlock latchNode = null; foreach (var predecessor in headBBlock.Predecessors) { if (!nodes.Contains(predecessor) || !IsBackEdge(predecessor, headBBlock)) { continue; } if (latchNode == null || predecessor.ReversePostOrderIndex > latchNode.ReversePostOrderIndex) { latchNode = predecessor; } } if (latchNode != null) { //todo: case level check headBBlock.LatchNode = latchNode; FindLoopNodes(context.Function, headBBlock, latchNode, nodes); latchNode.IsLatchNode = true; } } } }