Esempio n. 1
0
            public override Task <MethodBody> ApplyAsync(MethodBody body, OptimizationState state)
            {
                var rules  = body.Implementation.GetAnalysisResult <AccessRules>();
                var method = state.Method;
                var pass   = new ScalarReplacement(
                    type => type.GetAllInstanceFields().All(field => rules.CanAccess(method, field)));

                return(Task.FromResult(body.WithImplementation(pass.Apply(body.Implementation))));
            }
Esempio n. 2
0
            public override Task <MethodBody> ApplyAsync(MethodBody body, OptimizationState state)
            {
                var rules  = body.Implementation.GetAnalysisResult <AccessRules>();
                var method = state.Method;
                var pass   = new PartialScalarReplacement(
                    type =>
                    !type.IsPointerType() &&
                    !type.IsSpecialType() &&
                    !(type is IGenericParameter) &&
                    type.GetAllInstanceFields()
                    .All(field => rules.CanAccess(method, field)));

                return(Task.FromResult(body.WithImplementation(pass.Apply(body.Implementation))));
            }
Esempio n. 3
0
        public Umap(
            DistanceCalculation distance = null,
            IProvideRandomValues random  = null,
            int dimensions                    = 2,
            int numberOfNeighbors             = 15,
            int?customNumberOfEpochs          = null,
            ProgressReporter progressReporter = null)
        {
            if ((customNumberOfEpochs != null) && (customNumberOfEpochs <= 0))
            {
                throw new ArgumentOutOfRangeException(nameof(customNumberOfEpochs), "if non-null then must be a positive value");
            }

            _distanceFn        = distance ?? DistanceFunctions.Cosine;
            _random            = random ?? DefaultRandomGenerator.Instance;
            _nNeighbors        = numberOfNeighbors;
            _optimizationState = new OptimizationState {
                Dim = dimensions
            };
            _customNumberOfEpochs = customNumberOfEpochs;
            _progressReporter     = progressReporter;
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public override async Task <MethodBody> ApplyAsync(MethodBody body, OptimizationState state)
        {
            var graph = body.Implementation.ToBuilder();

            // Find all inlinable instructions in the method body, map them
            // to their callees.
            var candidates = new Dictionary <InstructionBuilder, IMethod>();

            foreach (var instruction in graph.Instructions)
            {
                IMethod callee;
                if (TryGetCallee(instruction, out callee) &&
                    ShouldConsider(callee, state.Method))
                {
                    candidates[instruction] = callee;
                }
            }

            // Request method bodies for all callees.
            var bodies = await state.GetBodiesAsync(candidates.Values);

            // Actually inline method bodies.
            foreach (var pair in candidates)
            {
                var instruction = pair.Key;
                var calleeBody  = bodies[pair.Value];
                if (calleeBody == null || !CanInline(calleeBody, state.Method, graph.ImmutableGraph))
                {
                    continue;
                }

                TryInlineCall(instruction, calleeBody);
            }

            return(body.WithImplementation(graph.ToImmutable()));
        }
Esempio n. 5
0
            public override async Task <MethodBody> ApplyAsync(MethodBody body, OptimizationState state)
            {
                await Task.WhenAll(Dependencies.Select(state.GetBodyAsync).ToArray());

                return(body);
            }
Esempio n. 6
0
 /// <inheritdoc/>
 public override Task<MethodBody> ApplyAsync(
     MethodBody body,
     OptimizationState state)
 {
     return Task.FromResult(body.WithImplementation(Apply(body.Implementation)));
 }
        protected void OnStateChanged(OptimizationState state)
        {
            this.State = state;

            if (StateChanged != null)
            {
                StateChanged();
            }
        }
Esempio n. 8
0
            public override async Task <MethodBody> ApplyAsync(MethodBody body, OptimizationState state)
            {
                await state.GetBodiesAsync(Dependencies);

                return(body);
            }