Browse Source

Improve decompiler performance.

pull/832/head
Daniel Grunwald 8 years ago
parent
commit
4c77022988
  1. 7
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  2. 10
      ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs
  3. 4
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  4. 6
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs
  5. 4
      ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs
  6. 12
      ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs

7
ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

@ -112,7 +112,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -112,7 +112,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (c != Conversion.None) return c;
}
} else {
c = ImplicitConversion(resolveResult.Type, toType, allowUserDefined);
if (allowUserDefined) {
// if allowUserDefined is true, we might as well use the cache
c = ImplicitConversion(resolveResult.Type, toType);
} else {
c = ImplicitConversion(resolveResult.Type, toType, allowUserDefined);
}
if (c != Conversion.None) return c;
}
if (resolveResult.Type.Kind == TypeKind.Dynamic)

10
ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

@ -409,7 +409,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -409,7 +409,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
#region Analyze MoveNext() and generate new body
BlockContainer AnalyzeMoveNext()
{
context.Stepper.StartGroup("AnalyzeMoveNext");
context.StepStartGroup("AnalyzeMoveNext");
MethodDefinition moveNextMethod = enumeratorType.Methods.FirstOrDefault(m => m.Name == "MoveNext");
ILFunction moveNextFunction = CreateILAst(moveNextMethod);
@ -450,7 +450,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -450,7 +450,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
moveNextFunction.Variables.Clear();
// release references from old moveNextFunction to instructions that were moved over to newBody
moveNextFunction.ReleaseRef();
context.Stepper.EndGroup();
context.StepEndGroup();
return newBody;
}
@ -458,7 +458,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -458,7 +458,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
{
// Roslyn may optimize MoveNext() by copying fields from the iterator class into local variables
// at the beginning of MoveNext(). Undo this optimization.
context.Stepper.StartGroup("PropagateCopiesOfFields");
context.StepStartGroup("PropagateCopiesOfFields");
var mutableFields = body.Descendants.OfType<LdFlda>().Where(ldflda => ldflda.Parent.OpCode != OpCode.LdObj).Select(ldflda => ldflda.Field).ToHashSet();
for (int i = 0; i < body.EntryPoint.Instructions.Count; i++) {
if (body.EntryPoint.Instructions[i] is StLoc store
@ -482,7 +482,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -482,7 +482,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
break; // unknown instruction
}
}
context.Stepper.EndGroup();
context.StepEndGroup();
}
/// <summary>
@ -718,7 +718,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -718,7 +718,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
void ReconstructTryFinallyBlocks(ILFunction iteratorFunction)
{
BlockContainer newBody = (BlockContainer)iteratorFunction.Body;
context.Stepper.Step("Reconstuct try-finally blocks");
context.Step("Reconstuct try-finally blocks", newBody);
var blockState = new int[newBody.Blocks.Count];
blockState[0] = -1;
var stateToContainer = new Dictionary<int, BlockContainer>();

4
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -215,10 +215,10 @@ namespace ICSharpCode.Decompiler.IL @@ -215,10 +215,10 @@ namespace ICSharpCode.Decompiler.IL
this.CheckInvariant(ILPhase.Normal);
foreach (var transform in transforms) {
context.CancellationToken.ThrowIfCancellationRequested();
context.Stepper.StartGroup(transform.GetType().Name);
context.StepStartGroup(transform.GetType().Name);
transform.Run(this, context);
this.CheckInvariant(ILPhase.Normal);
context.Stepper.EndGroup();
context.StepEndGroup();
}
}

6
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -114,13 +114,13 @@ namespace ICSharpCode.Decompiler.IL @@ -114,13 +114,13 @@ namespace ICSharpCode.Decompiler.IL
foreach (var transform in transforms) {
context.CancellationToken.ThrowIfCancellationRequested();
if (transform is BlockILTransform blockTransform) {
context.Stepper.StartGroup(blockTransform.ToString());
context.StepStartGroup(blockTransform.ToString());
} else {
context.Stepper.StartGroup(transform.GetType().Name);
context.StepStartGroup(transform.GetType().Name);
}
transform.Run(this, context);
this.CheckInvariant(ILPhase.Normal);
context.Stepper.EndGroup(keepIfEmpty: true);
context.StepEndGroup(keepIfEmpty: true);
}
}

4
ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs

@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
void VisitBlock(ControlFlowNode cfgNode, BlockTransformContext context)
{
Block block = (Block)cfgNode.UserData;
context.Stepper.StartGroup(block.Label, block);
context.StepStartGroup(block.Label, block);
context.ControlFlowNode = cfgNode;
context.Block = block;
@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
context.ControlFlowNode = cfgNode;
context.Block = block;
block.RunTransforms(PostOrderTransforms, context);
context.Stepper.EndGroup();
context.StepEndGroup();
}
}
}

12
ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs

@ -62,5 +62,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -62,5 +62,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
Stepper.Step(description, near);
}
[Conditional("STEP")]
internal void StepStartGroup(string description, ILInstruction near = null)
{
Stepper.StartGroup(description, near);
}
[Conditional("STEP")]
internal void StepEndGroup(bool keepIfEmpty = false)
{
Stepper.EndGroup(keepIfEmpty);
}
}
}

Loading…
Cancel
Save