static void CalculateForOutputBlocks <V>(TransferFunctionStorage <ISet <V> > result, Region r, Region s, List <int> outputBlocks, Graph graph) { foreach (BasicBlock bb in outputBlocks.Select(i => graph.getBlockById(i))) { LeafRegion b = new LeafRegion(bb); TransferFunctionStorage <ISet <V> > clone = result.Clone(); result[r, RegionDirection.Out, b] = input => clone[s, RegionDirection.Out, b](clone[r, RegionDirection.In, s](input)); } }
static TransferFunctionStorage <ISet <V> > ApplyAscendingPart <V>(Graph graph, List <Region> regions, SetIterativeAlgorithmParameters <V> param) { TransferFunctionStorage <ISet <V> > result = new TransferFunctionStorage <ISet <V> >(); foreach (Region r in regions) { LeafRegion leaf = r as LeafRegion; TransferFunctionStorage <ISet <V> > clone = result.Clone(); if (leaf != null) { ////// for (int i = graph.Count(); i < regions.Count; ++i) { result[regions[i], RegionDirection.Out, leaf] = input => param.TransferFunction(input, leaf.Block); } ///// result[leaf, RegionDirection.In, leaf] = Identity; result[leaf, RegionDirection.Out, leaf] = input => param.TransferFunction(input, leaf.Block); } BodyRegion body = r as BodyRegion; if (body != null) { foreach (Region s in body.Regions) { LeafRegion header = s as LeafRegion; if (header != null) { result[body, RegionDirection.In, s] = Identity; } else { result[body, RegionDirection.In, s] = input => GatherFunctionsResults(input, clone, body, s.Header.InputBlocks, graph, param); } CalculateForOutputBlocks(result, body, s, s.OutputBlocks, graph); } } LoopRegion loop = r as LoopRegion; if (loop != null) { result[loop, RegionDirection.In, loop.Body] = input => SetFactory.GetSet <V>(input.Union(GatherFunctionsResults(input, clone, loop.Body, loop.Header.InputBlocks, graph, param))); CalculateForOutputBlocks(result, loop, loop.Body, loop.OutputBlocks, graph); } } return(result); }
public List <Region> CreateSequence(Graph g) { if (!CheckRetreatingIsReverse.CheckRetreatingIsReverse.CheckReverseEdges(g)) { Console.WriteLine("there are some retreating edges which aren't reverse"); Environment.Exit(0); } var basicBlockLastRegion = new Dictionary <BasicBlock, Region>(); foreach (var v in g.GetVertices()) { var newReg = new LeafRegion(v); regionList.Add(newReg); basicBlockLastRegion[v] = newReg; } var loops = SearchNaturalLoops.FindAllNaturalLoops(g); var regionMade = new Dictionary <Edge <BasicBlock>, bool>(); foreach (var loop in loops) { regionMade[loop.Key] = false; } while (regionMade.ContainsValue(false)) { foreach (var loop in loops) { bool anyInsideLoops = false; foreach (var loopOther in loops) { anyInsideLoops = anyInsideLoops || checkLoopInclusion(loop, loopOther, regionMade[loopOther.Key]); } if (!anyInsideLoops) { continue; } regionMade[loop.Key] = true; var header = loop.Key.Target; var curRegions = new List <Region>(); var outputBlocks = new List <int>(); foreach (var blockId in loop.Value) { var block = g.getBlockById(blockId); if (!curRegions.Contains(basicBlockLastRegion[block])) { curRegions.Add(basicBlockLastRegion[block]); } foreach (var outputBlock in block.OutputBlocks) { if (!loop.Value.Contains(outputBlock)) { outputBlocks.Add(block.BlockId); break; } } } var bodyReg = new BodyRegion(header, outputBlocks, curRegions); regionList.Add(bodyReg); var loopReg = new LoopRegion(bodyReg); regionList.Add(loopReg); foreach (var blockId in loop.Value) { var block = g.getBlockById(blockId); basicBlockLastRegion[block] = loopReg; } } } // check if program has become one region foreach (var block in basicBlockLastRegion) { // if there are leaves not included in loops if (block.Value.GetType() == typeof(LeafRegion)) { var header = g.getRoot(); var outputBlocks = new List <int>(); var curRegions = new List <Region>(); foreach (var curblock in basicBlockLastRegion) { if (!curRegions.Contains(curblock.Value)) { curRegions.Add(curblock.Value); } } var newReg = new BodyRegion(header, outputBlocks, curRegions); regionList.Add(newReg); break; } } foreach (var reg in regionList) { if (reg.GetType() == typeof(LoopRegion)) { (reg as LoopRegion).Body.RegionParent = reg; } if (reg.GetType() == typeof(BodyRegion)) { foreach (var children in (reg as BodyRegion).Regions) { children.RegionParent = reg; } } } return(regionList); }