/// <summary> /// try to insert registers in cyclic paths starting at (1) feedbackInputNode's input terminals and (2) RightShiftRegister's output terminal /// </summary> private void FixSolutionForComboCycles() { foreach (var v in Graph.Vertices.Where(v => v.IsTerminal() && !Registered(v) && (v.NodeType == DelayGraphNodeType.FeedbackInputNode || (v.NodeType == DelayGraphNodeType.RightShiftRegister && v.IsOutputTerminal)))) { foreach (var e in Graph.GetFeedbackOutEdges(v)) { var next = e.Target; if (Registered(next)) { continue; } var visited = new HashSet <DelayGraphVertex>(); if (FindForwardPath(next, v, visited)) { // there is a combo path from v to itself via next - fix the cycle by registering next if (v.DisallowRegister) { if (v.NodeType == DelayGraphNodeType.FeedbackInputNode) { // put registers on incoming forward edge's source, unless it is already registered or register is not allowed foreach (var edge in Graph.GetForwardInEdges(v)) { // register s iff ok to do so var s = edge.Source; if (!s.DisallowRegister && !Registered(s)) { RegisteredTerminals.Add(s); } } } } else { RegisteredTerminals.Add(v); } break; } } } }
private void RetimeRegister(DelayGraphVertex v) { if (v.IsInputTerminal) { // move v's register to incoming edges foreach (var e in Graph.GetForwardInEdges(v)) { RegisteredTerminals.Add(e.Source); } } else { // move v's register to outgoing edges foreach (var e in Graph.GetForwardOutEdges(v)) { RegisteredTerminals.Add(e.Source); } } RegisteredTerminals.Remove(v); }
/// <summary> /// fix sibling to be registered if any is registered /// </summary> /// <returns>a count of number of nodes that changed</returns> private int FixSolutionForSiblingVertices() { int count = 0; HashSet <DelayGraphVertex> grouped; var listOfSiblings = DelayGraphAlgorithms.FindVertexGroups(Graph, out grouped); foreach (var siblings in listOfSiblings) { if (siblings.Any(Registered) && siblings.Count() > 1) { // at least one in sibling is registered var verticesWhichAreNotRegistered = siblings.Where(v => !Registered(v)); count += verticesWhichAreNotRegistered.Count(); foreach (var v in verticesWhichAreNotRegistered) { RegisteredTerminals.Add(v); } } } return(count); }