Ejemplo n.º 1
0
        private static async Task UpdateMethodBodyAsync(
            ClrMethodDefinition method,
            Optimizer optimizer,
            TypeEnvironment typeSystem,
            bool printIr)
        {
            var optBody = await optimizer.GetBodyAsync(method);

            if (optBody == null)
            {
                // Looks like the method either doesn't have a body or
                // we can't handle it for some reason.
                return;
            }

            // Lower the optimized method body.
            optBody = optBody.WithImplementation(
                optBody.Implementation.Transform(
                    JumpToEntryRemoval.Instance,
                    DeadBlockElimination.Instance,
                    new SwitchLowering(typeSystem),
                    CopyPropagation.Instance,
                    InstructionReordering.Instance,
                    FuseMemoryAccesses.Instance,
                    new LowerBox(typeSystem.Object.GetDefiningAssemblyOrNull()),
                    DeadValueElimination.Instance,
                    new JumpThreading(false),
                    LowerDelegates.Instance));

            if (printIr)
            {
                PrintIr(method, method.Body, optBody);
            }

            // Select CIL instructions for the optimized method body.
            var newCilBody = ClrMethodBodyEmitter.Compile(optBody, method.Definition, typeSystem);

            lock (method.Definition)
            {
                method.Definition.Body = newCilBody;
            }
        }