Class DetectPinnedRegions
- Namespace
- ICSharpCode.Decompiler.IL.ControlFlow
- Assembly
- ICSharpCode.Decompiler.dll
IL uses 'pinned locals' to prevent the GC from moving objects.
C#:
fixed (int* s = &arr[index]) { use(s); use(s); }
Gets translated into IL:
pinned local P : System.Int32&
stloc(P, ldelema(arr, index))
call use(conv ref->i(ldloc P))
call use(conv ref->i(ldloc P))
stloc(P, conv i4->u(ldc.i4 0))
In C#, the only way to pin something is to use a fixed block (or to mess around with GCHandles). But fixed blocks are scoped, so we need to detect the region affected by the pin. To ensure we'll be able to collect all blocks in that region, we perform this transform early, before building any other control flow constructs that aren't as critical for correctness.
This means this transform must run before LoopDetection. To make our detection job easier, we must run after variable inlining.
public class DetectPinnedRegions : IILTransform
- Inheritance
-
DetectPinnedRegions
- Implements
- Inherited Members
Constructors
DetectPinnedRegions()
public DetectPinnedRegions()
Methods
Run(ILFunction, ILTransformContext)
public void Run(ILFunction function, ILTransformContext context)
Parameters
function
ILFunctioncontext
ILTransformContext