Browse Source

#1610: Slightly more aggressive copy propagation.

This helps clean up the mess left behind when stack slots are not eliminated by the normal transforms.
We previously didn't do this because aggressive copy propagation could confuse the normal transforms; but this is no longer an issue with the new pass ordering.
pull/1633/head
Daniel Grunwald 6 years ago
parent
commit
fc73851bb4
  1. 11
      ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs

11
ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs

@ -105,13 +105,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -105,13 +105,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// Parameters can be copied only if they aren't assigned to (directly or indirectly via ldarga)
// note: the initialization by the caller is the first store -> StoreCount must be 1
return v.IsSingleDefinition;
case VariableKind.StackSlot:
case VariableKind.ExceptionStackSlot:
// Variables are be copied only if both they and the target copy variable are generated,
// and if the variable has only a single assignment
return v.IsSingleDefinition && target.Kind == VariableKind.StackSlot;
default:
return false;
// Variables can be copied if both are single-definition.
// To avoid removing too many variables, we do this only if the target
// is either a stackslot or a ref local.
Debug.Assert(target.IsSingleDefinition);
return v.IsSingleDefinition && (target.Kind == VariableKind.StackSlot || target.StackType == StackType.Ref);
}
default:
// All instructions without special behavior that target a stack-variable can be copied.

Loading…
Cancel
Save