Exemplo n.º 1
0
        public void OptimizeClosure()
        {
            var level = new OptimizationLevels();

            var optimizations = level.BuildOptimizationPasses1();

            level.BuildOptimizationPasses2();
            OptimizationLevelBase.UpdateOptimizationsFromCategories(optimizations);
            var cilMethods = MethodImplementations.Values
                             .Where(m => m.Kind == MethodKind.CilInstructions)
                             .Cast <CilMethodInterpreter>()
                             .ToArray();

            ResultingOptimizationPass.Closure = this;
            var doOptimize = true;

            while (doOptimize)
            {
                doOptimize = false;
                foreach (var cilMethod in cilMethods)
                {
                    doOptimize |= MethodInterpreterCodeWriter.ApplyLocalOptimizations(optimizations, cilMethod);
                }
                var isOptimized = ApplyProgramWideOptimizations();
                doOptimize |= isOptimized;
            }
        }
Exemplo n.º 2
0
        public static void ApplyOptimizations(List <MethodInterpreter> methodsToOptimize)
        {
            methodsToOptimize = methodsToOptimize.Where(m => m.Kind == MethodKind.Default).ToList();
            bool doOptimize;

            do
            {
                doOptimize = false;
                var toRemove = methodsToOptimize.Where(mth => mth == null).ToArray();
                foreach (var item in toRemove)
                {
                    methodsToOptimize.Remove(item);
                }
                var inFunctionOptimizations = CommandLineParse.SortedOptimizations[OptimizationKind.InFunction];
                var methodsArray            = methodsToOptimize.ToArray();
                //Parallel.ForEach(methodsToOptimize, methodBase=>
                foreach (var methodBase in methodsArray)
                {
                    var interpreter = methodBase;
                    //Console.WriteLine("Optimize locally: {0}", methodBase);
                    MethodInterpreterCodeWriter.ApplyLocalOptimizations(
                        inFunctionOptimizations, interpreter);
                }
                //);
                foreach (var methodBase in methodsArray)
                {
                    var interpreter = methodBase;
                    //Console.WriteLine("Optimize globally: {0}", methodBase);
                    doOptimize |= MethodInterpreterCodeWriter.ApplyLocalOptimizations(
                        CommandLineParse.SortedOptimizations[OptimizationKind.Global], interpreter);
                }
            } while (doOptimize);
        }