public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List <Declaration> decls) { MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls); // TODO: make enumeration of mover checks more efficient / elegant var regularMoverChecks = from first in civlTypeChecker.procToAtomicAction.Values from second in civlTypeChecker.procToAtomicAction.Values where first.layerRange.OverlapsWith(second.layerRange) where first.IsRightMover || second.IsLeftMover select new { first, second }; foreach (var moverCheck in regularMoverChecks) { if (moverCheck.first.IsRightMover) { moverChecking.CreateRightMoverCheckers(moverCheck.first, moverCheck.second); } if (moverCheck.second.IsLeftMover) { moverChecking.CreateLeftMoverCheckers(moverCheck.first, moverCheck.second); } } var inductiveSequentializationMoverChecks = from IS in civlTypeChecker.inductiveSequentializations from leftMover in IS.elim.Values from action in civlTypeChecker.procToAtomicAction.Values where action.layerRange.Contains(IS.inputAction.layerRange.upperLayerNum) select new { action, leftMover }; foreach (var moverCheck in inductiveSequentializationMoverChecks) { moverChecking.CreateLeftMoverCheckers(moverCheck.action, moverCheck.leftMover); } // Here we include IS abstractions foreach (var atomicAction in civlTypeChecker.AllAtomicActions.Where(a => a.IsLeftMover)) { moverChecking.CreateNonBlockingChecker(atomicAction); } // IS abstractions are marked left movers, so here we select regular atomic actions // that are not marked left mover but used as abstraction in IS. foreach (var atomicAction in civlTypeChecker.inductiveSequentializations.SelectMany(IS => IS.elim.Values) .Where(a => !a.IsLeftMover).Distinct()) { moverChecking.CreateNonBlockingChecker(atomicAction); } foreach (var introductionAction in civlTypeChecker.procToIntroductionAction.Values) { moverChecking.CreateNonBlockingChecker(introductionAction); } }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List <Declaration> decls) { if (civlTypeChecker.procToAtomicAction.Count == 0) { return; } MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls); foreach (int layer in civlTypeChecker.allAtomicActionLayers) { var pool = civlTypeChecker.procToAtomicAction.Values.Where(a => a.layerRange.Contains(layer)); var moverChecks = from first in pool from second in pool where first.moverType != MoverType.Atomic select new { First = first, Second = second }; foreach (var moverCheck in moverChecks) { var first = moverCheck.First.layerToActionCopy[layer]; var second = moverCheck.Second.layerToActionCopy[layer]; if (moverCheck.First.IsRightMover) { moverChecking.CreateCommutativityChecker(first, second); moverChecking.CreateGatePreservationChecker(second, first); } if (moverCheck.First.IsLeftMover) { moverChecking.CreateCommutativityChecker(second, first); moverChecking.CreateGatePreservationChecker(first, second); moverChecking.CreateFailurePreservationChecker(second, first); } } foreach (AtomicAction atomicAction in pool.Where(a => a.IsLeftMover)) { moverChecking.CreateNonBlockingChecker(atomicAction.layerToActionCopy[layer]); } } }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List <Declaration> decls) { if (civlTypeChecker.procToActionInfo.Count == 0) { return; } List <ActionInfo> sortedByCreatedLayerNum = new List <ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern)); sortedByCreatedLayerNum.Sort((x, y) => { return((x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1); }); List <ActionInfo> sortedByAvailableUptoLayerNum = new List <ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern)); sortedByAvailableUptoLayerNum.Sort((x, y) => { return((x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1); }); Dictionary <int, HashSet <AtomicActionInfo> > pools = new Dictionary <int, HashSet <AtomicActionInfo> >(); int indexIntoSortedByCreatedLayerNum = 0; int indexIntoSortedByAvailableUptoLayerNum = 0; HashSet <AtomicActionInfo> currPool = new HashSet <AtomicActionInfo>(); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum; pools[currLayerNum] = new HashSet <AtomicActionInfo>(currPool); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo; if (actionInfo.createdAtLayerNum > currLayerNum) { break; } pools[currLayerNum].Add(actionInfo); indexIntoSortedByCreatedLayerNum++; } while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count) { var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo; if (actionInfo.availableUptoLayerNum > currLayerNum) { break; } pools[currLayerNum].Remove(actionInfo); indexIntoSortedByAvailableUptoLayerNum++; } currPool = pools[currLayerNum]; } // No atomic action has mover type Top Debug.Assert(pools.All(l => l.Value.All(a => a.moverType != MoverType.Top))); Program program = civlTypeChecker.program; MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls); var moverChecks = from layer in pools.Keys from first in pools[layer] from second in pools[layer] where first.moverType != MoverType.Atomic select new { First = first, Second = second }; foreach (var moverCheck in moverChecks) { var first = moverCheck.First; var second = moverCheck.Second; if (first.IsRightMover) { moverChecking.CreateCommutativityChecker(program, first, second); moverChecking.CreateGatePreservationChecker(program, second, first); } if (first.IsLeftMover) { moverChecking.CreateCommutativityChecker(program, second, first); moverChecking.CreateGatePreservationChecker(program, first, second); moverChecking.CreateFailurePreservationChecker(program, second, first); } } foreach (AtomicActionInfo atomicActionInfo in sortedByCreatedLayerNum) { if (atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd) { moverChecking.CreateNonBlockingChecker(program, atomicActionInfo); } } }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, MoverTypeChecker moverTypeChecker, List <Declaration> decls) { if (moverTypeChecker.procToActionInfo.Count == 0) { return; } List <ActionInfo> sortedByCreatedLayerNum = new List <ActionInfo>(moverTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo)); sortedByCreatedLayerNum.Sort((x, y) => { return((x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1); }); List <ActionInfo> sortedByAvailableUptoLayerNum = new List <ActionInfo>(moverTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo)); sortedByAvailableUptoLayerNum.Sort((x, y) => { return((x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1); }); Dictionary <int, HashSet <AtomicActionInfo> > pools = new Dictionary <int, HashSet <AtomicActionInfo> >(); int indexIntoSortedByCreatedLayerNum = 0; int indexIntoSortedByAvailableUptoLayerNum = 0; HashSet <AtomicActionInfo> currPool = new HashSet <AtomicActionInfo>(); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum; pools[currLayerNum] = new HashSet <AtomicActionInfo>(currPool); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo; if (actionInfo.createdAtLayerNum > currLayerNum) { break; } pools[currLayerNum].Add(actionInfo); indexIntoSortedByCreatedLayerNum++; } while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count) { var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo; if (actionInfo.availableUptoLayerNum > currLayerNum) { break; } pools[currLayerNum].Remove(actionInfo); indexIntoSortedByAvailableUptoLayerNum++; } currPool = pools[currLayerNum]; } Program program = moverTypeChecker.program; MoverCheck moverChecking = new MoverCheck(linearTypeChecker, moverTypeChecker, decls); foreach (int layerNum in pools.Keys) { foreach (AtomicActionInfo first in pools[layerNum]) { Debug.Assert(first.moverType != MoverType.Top); if (first.moverType == MoverType.Atomic) { continue; } foreach (AtomicActionInfo second in pools[layerNum]) { if (first.IsRightMover) { moverChecking.CreateCommutativityChecker(program, first, second); moverChecking.CreateGatePreservationChecker(program, second, first); } if (first.IsLeftMover) { moverChecking.CreateCommutativityChecker(program, second, first); moverChecking.CreateGatePreservationChecker(program, first, second); moverChecking.CreateFailurePreservationChecker(program, second, first); } } } } foreach (ActionInfo actionInfo in moverTypeChecker.procToActionInfo.Values) { AtomicActionInfo atomicActionInfo = actionInfo as AtomicActionInfo; if (atomicActionInfo != null && atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd) { moverChecking.CreateNonBlockingChecker(program, atomicActionInfo); } } }
public static void AddCheckers(LinearTypeChecker linearTypeChecker, CivlTypeChecker civlTypeChecker, List<Declaration> decls) { if (civlTypeChecker.procToActionInfo.Count == 0) return; List<ActionInfo> sortedByCreatedLayerNum = new List<ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern)); sortedByCreatedLayerNum.Sort((x, y) => { return (x.createdAtLayerNum == y.createdAtLayerNum) ? 0 : (x.createdAtLayerNum < y.createdAtLayerNum) ? -1 : 1; }); List<ActionInfo> sortedByAvailableUptoLayerNum = new List<ActionInfo>(civlTypeChecker.procToActionInfo.Values.Where(x => x is AtomicActionInfo && !x.isExtern)); sortedByAvailableUptoLayerNum.Sort((x, y) => { return (x.availableUptoLayerNum == y.availableUptoLayerNum) ? 0 : (x.availableUptoLayerNum < y.availableUptoLayerNum) ? -1 : 1; }); Dictionary<int, HashSet<AtomicActionInfo>> pools = new Dictionary<int, HashSet<AtomicActionInfo>>(); int indexIntoSortedByCreatedLayerNum = 0; int indexIntoSortedByAvailableUptoLayerNum = 0; HashSet<AtomicActionInfo> currPool = new HashSet<AtomicActionInfo>(); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var currLayerNum = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum].createdAtLayerNum; pools[currLayerNum] = new HashSet<AtomicActionInfo>(currPool); while (indexIntoSortedByCreatedLayerNum < sortedByCreatedLayerNum.Count) { var actionInfo = sortedByCreatedLayerNum[indexIntoSortedByCreatedLayerNum] as AtomicActionInfo; if (actionInfo.createdAtLayerNum > currLayerNum) break; pools[currLayerNum].Add(actionInfo); indexIntoSortedByCreatedLayerNum++; } while (indexIntoSortedByAvailableUptoLayerNum < sortedByAvailableUptoLayerNum.Count) { var actionInfo = sortedByAvailableUptoLayerNum[indexIntoSortedByAvailableUptoLayerNum] as AtomicActionInfo; if (actionInfo.availableUptoLayerNum > currLayerNum) break; pools[currLayerNum].Remove(actionInfo); indexIntoSortedByAvailableUptoLayerNum++; } currPool = pools[currLayerNum]; } // No atomic action has mover type Top Debug.Assert(pools.All(l => l.Value.All(a => a.moverType != MoverType.Top))); Program program = civlTypeChecker.program; MoverCheck moverChecking = new MoverCheck(linearTypeChecker, civlTypeChecker, decls); var moverChecks = from layer in pools.Keys from first in pools[layer] from second in pools[layer] where first.moverType != MoverType.Atomic select new { First = first, Second = second }; foreach (var moverCheck in moverChecks) { var first = moverCheck.First; var second = moverCheck.Second; if (first.IsRightMover) { moverChecking.CreateCommutativityChecker(program, first, second); moverChecking.CreateGatePreservationChecker(program, second, first); } if (first.IsLeftMover) { moverChecking.CreateCommutativityChecker(program, second, first); moverChecking.CreateGatePreservationChecker(program, first, second); moverChecking.CreateFailurePreservationChecker(program, second, first); } } foreach (AtomicActionInfo atomicActionInfo in sortedByCreatedLayerNum) { if (atomicActionInfo.IsLeftMover && atomicActionInfo.hasAssumeCmd) { moverChecking.CreateNonBlockingChecker(program, atomicActionInfo); } } }