|
|
|
@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
@@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
|
|
|
|
|
context.CancellationToken.ThrowIfCancellationRequested(); |
|
|
|
|
|
|
|
|
|
RemoveNopInstructions(block); |
|
|
|
|
RemoveDeadStackStores(block); |
|
|
|
|
RemoveDeadStackStores(block, aggressive: context.Settings.RemoveDeadCode); |
|
|
|
|
|
|
|
|
|
InlineVariableInReturnBlock(block, context); |
|
|
|
|
// 1st pass SimplifySwitchInstruction before SimplifyBranchChains()
|
|
|
|
@ -70,20 +70,33 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
@@ -70,20 +70,33 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
|
|
|
|
|
block.Instructions.RemoveAll(inst => inst.OpCode == OpCode.Nop); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void RemoveDeadStackStores(Block block) |
|
|
|
|
private void RemoveDeadStackStores(Block block, bool aggressive) |
|
|
|
|
{ |
|
|
|
|
// Previously copy propagation did this;
|
|
|
|
|
// ideally the ILReader would already do this,
|
|
|
|
|
// for now do this here (even though it's not control-flow related).
|
|
|
|
|
for (int i = block.Instructions.Count - 1; i >= 0; i--) { |
|
|
|
|
if (block.Instructions[i] is StLoc stloc && stloc.Variable.IsSingleDefinition && stloc.Variable.LoadCount == 0 && stloc.Variable.Kind == VariableKind.StackSlot) { |
|
|
|
|
if (SemanticHelper.IsPure(stloc.Value.Flags)) { |
|
|
|
|
if (aggressive ? SemanticHelper.IsPure(stloc.Value.Flags) : IsSimple(stloc.Value)) { |
|
|
|
|
Debug.Assert(SemanticHelper.IsPure(stloc.Value.Flags)); |
|
|
|
|
block.Instructions.RemoveAt(i++); |
|
|
|
|
} else { |
|
|
|
|
stloc.Value.AddILRange(stloc); |
|
|
|
|
stloc.ReplaceWith(stloc.Value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsSimple(ILInstruction inst) |
|
|
|
|
{ |
|
|
|
|
switch (inst.OpCode) { |
|
|
|
|
case OpCode.LdLoc: |
|
|
|
|
case OpCode.LdStr: // C# 1.0 compiler sometimes emits redundant ldstr in switch-on-string pattern
|
|
|
|
|
return true; |
|
|
|
|
default: |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void InlineVariableInReturnBlock(Block block, ILTransformContext context) |
|
|
|
|