/// <summary> /// Returns the variables live at the end of the block. /// </summary> public static List <Declaration> GetLiveVariables(Block block) { LiveChartClass chart = new LiveChartClass(block); chart.GenerateVariableChart(); var liveVars = chart.Where(kvp => kvp.Value.Last() == true).Select(kvp => kvp.Key); return(liveVars.ToList <Declaration>()); }
static List <Dictionary <Declaration, ISet <Declaration> > > BuildInterferenceGraph(List <BasicBlock> blocks) { var graphs = new List <Dictionary <Declaration, ISet <Declaration> > >(); foreach (var block in blocks) { var graph = new Dictionary <Declaration, ISet <Declaration> >(); LiveChartClass liveChart = new LiveChartClass(block); liveChart.GenerateVariableChart(true); foreach (var keyValuePair in liveChart) { foreach (var declToCompare in liveChart) { if (keyValuePair.Equals(declToCompare)) { continue; } bool constructEdge = false; for (int i = 0; i < keyValuePair.Value.Count; i++) { if (keyValuePair.Value[i] && declToCompare.Value[i]) { constructEdge = true; } } if (constructEdge) { //we don't check if these are flipped so we store 2x extra data //i think this will be good later so we don't have to do two lookups //just need to remember to treat them as the same ISet <Declaration> interferenceNodes; if (!graph.TryGetValue(keyValuePair.Key, out interferenceNodes)) { interferenceNodes = new HashSet <Declaration>(); graph[keyValuePair.Key] = interferenceNodes; } interferenceNodes.Add(declToCompare.Key); } } } graphs.Add(graph); } return(graphs); }