public ControlFlowLabelMap(ILBlock method, ErrorContext error) { method.FixParents(); this.error = error; foreach (ILBasicBlock bb in method.GetSelfAndChildrenRecursive <ILBasicBlock>()) { ILLabel entry = bb.Body[0] as ILLabel; // ILExpression br = bb.Body.ElementAtOrDefault(bb.Body.Count - 2) as ILExpression; // ILExpression b = bb.Body.ElementAtOrDefault(bb.Body.Count - 1) as ILExpression; // if (br != null && (br.Code == GMCode.Bt || br.Code == GMCode.Bt)) labelToBranch[br.Operand as ILLabel].Add(entry); // if (b != null && b.Code == GMCode.B) labelToBranch[b.Operand as ILLabel].Add(entry); // skip 1 cause we have the label entry labelToBasicBlock[entry] = bb; for (int i = 1; i < bb.Body.Count; i++) { ILNode n = bb.Body[i]; ILExpression e = n as ILExpression; if (e == null) { continue; } foreach (var target in e.GetBranchTargets()) { labelGlobalRefCount[target] = labelGlobalRefCount.GetOrDefault(target) + 1; HashSet <ILLabel> labels; if (!labelToBranch.TryGetValue(target, out labels)) { labelToBranch.Add(target, labels = new HashSet <ILLabel>()); } labels.Add(entry); } } } }
public static bool RunOptimizationAndRestart(this ILBlock block, params Func <IList <ILNode>, ILExpression, int, bool>[] optimizations) { bool modified = false; foreach (ILBasicBlock bb in block.Body) { modified |= bb.RunOptimizationAndRestart(optimizations); } if (Context.Debug) { block.FixParents(); } return(modified); }
/// <summary> /// Perform one pass of a given optimization on this block. /// This block must consist of only basicblocks. /// </summary> public static bool RunOptimization(this ILBlock block, Func <IList <ILNode>, ILBasicBlock, int, bool> optimization) { bool modified = false; IList <ILNode> body = block.Body; for (int i = body.Count - 1; i >= 0; i--) { if (i < body.Count && optimization(body, (ILBasicBlock)body[i], i)) { modified = true; } } if (Context.Debug) { block.FixParents(); } return(modified); }
public static bool RunOptimization(this ILBlock block, Func <IList <ILNode>, ILExpression, int, bool> optimization) { bool modified = false; foreach (ILBasicBlock bb in block.Body) { for (int i = bb.Body.Count - 1; i >= 0; i--) { ILExpression expr = bb.Body.ElementAtOrDefault(i) as ILExpression; if (expr != null && optimization(bb.Body, expr, i)) { modified = true; } } } if (Context.Debug) { block.FixParents(); } return(modified); }