Browse Source

Simple heuristics to improve gotos related to loops

pull/70/head
David Srbecký 15 years ago
parent
commit
e53c2565e8
  1. 11
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

11
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -463,6 +463,17 @@ namespace Decompiler.ControlFlow @@ -463,6 +463,17 @@ namespace Decompiler.ControlFlow
scope.Remove(node);
branchExpr.Operand = null; // Do not keep label alive
// TODO: Does 'true' really point into the loop body? Swap if necessary
ControlFlowNode postLoopTarget;
labelToCfNode.TryGetValue(falseLabel, out postLoopTarget);
if (postLoopTarget != null) {
// Pull more nodes into the loop
HashSet<ControlFlowNode> postLoopContents = FindDominatedNodes(scope, postLoopTarget);
var pullIn = scope.Except(postLoopContents).Where(n => node.Dominates(n));
loopContents.UnionWith(pullIn);
}
// Use loop to implement the condition
result.Add(new ILBasicBlock() {
EntryLabel = basicBlock.EntryLabel,

Loading…
Cancel
Save