Welcome to mirror list, hosted at ThFree Co, Russian Federation.

JitCompilation.cs « JitSupport « Runtime « Internal « src « System.Private.Jit « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c5f06f72e56ef1953b535809780db27cff3c435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;

using Internal.TypeSystem;
using ILCompiler.DependencyAnalysis;
using Internal.IL;
using Internal.IL.Stubs;

namespace ILCompiler
{
    /// <summary>
    /// Version of Compilation class used for JIT compilation. Should probably be merged with the Compilation class used in AOT compilation
    /// </summary>
    internal class Compilation
    {
        public Compilation(TypeSystemContext context)
        {
            _typeSystemContext = context;
            _typeGetTypeMethodThunks = new TypeGetTypeMethodThunkCache(context.GetWellKnownType(WellKnownType.Object));
            _pInvokeILProvider = new PInvokeILProvider(new PInvokeILEmitterConfiguration(forceLazyResolution: true), null);
            _methodILCache = new ILProvider(_pInvokeILProvider);
            _nodeFactory = new NodeFactory(context);
            _devirtualizationManager = new DevirtualizationManager();
        }

        private readonly NodeFactory _nodeFactory;
        private readonly TypeSystemContext _typeSystemContext;
        protected readonly Logger _logger = Logger.Null;
        private readonly TypeGetTypeMethodThunkCache _typeGetTypeMethodThunks;
        private ILProvider _methodILCache;
        private PInvokeILProvider _pInvokeILProvider;
        private readonly DevirtualizationManager _devirtualizationManager;

        internal Logger Logger => _logger;
        internal PInvokeILProvider PInvokeILProvider => _pInvokeILProvider;

        public TypeSystemContext TypeSystemContext { get { return _typeSystemContext; } }
        public NodeFactory NodeFactory { get { return _nodeFactory; } }

        public NameMangler NameMangler { get { return null; } }

        public ObjectNode GetFieldRvaData(FieldDesc field)
        {
            // Use the typical field definition in case this is an instantiated generic type
            field = field.GetTypicalFieldDefinition();
            throw new NotImplementedException();
        }

        internal MethodIL GetMethodIL(MethodDesc method)
        {
            // Flush the cache when it grows too big
            if (_methodILCache.Count > 1000)
                _methodILCache = new ILProvider(_pInvokeILProvider);

            return _methodILCache.GetMethodIL(method);
        }

        public bool HasLazyStaticConstructor(TypeDesc type) { return type.HasStaticConstructor; }

        public MethodDebugInformation GetDebugInfo(MethodIL methodIL)
        {
            // This method looks odd right now, but it's an extensibility point that lets us generate
            // fake debugging information for things that don't have physical symbols.
            return methodIL.GetDebugInfo();
        }

        /// <summary>
        /// Resolves a reference to an intrinsic method to a new method that takes it's place in the compilation.
        /// This is used for intrinsics where the intrinsic expansion depends on the callsite.
        /// </summary>
        /// <param name="intrinsicMethod">The intrinsic method called.</param>
        /// <param name="callsiteMethod">The callsite that calls the intrinsic.</param>
        /// <returns>The intrinsic implementation to be called for this specific callsite.</returns>
        public MethodDesc ExpandIntrinsicForCallsite(MethodDesc intrinsicMethod, MethodDesc callsiteMethod)
        {
            Debug.Assert(intrinsicMethod.IsIntrinsic);

            var intrinsicOwningType = intrinsicMethod.OwningType as MetadataType;
            if (intrinsicOwningType == null)
                return intrinsicMethod;

            if (intrinsicOwningType.Module != TypeSystemContext.SystemModule)
                return intrinsicMethod;

            if (intrinsicOwningType.Name == "Type" && intrinsicOwningType.Namespace == "System")
            {
                if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name == "GetType")
                {
                    ModuleDesc callsiteModule = (callsiteMethod.OwningType as MetadataType)?.Module;
                    if (callsiteModule != null)
                    {
                        Debug.Assert(callsiteModule is IAssemblyDesc, "Multi-module assemblies");
                        return _typeGetTypeMethodThunks.GetHelper(intrinsicMethod, ((IAssemblyDesc)callsiteModule).GetName().FullName);
                    }
                }
            }

            return intrinsicMethod;
        }

        public bool HasFixedSlotVTable(TypeDesc type)
        {
            return true;
        }

        public bool IsEffectivelySealed(TypeDesc type)
        {
            return _devirtualizationManager.IsEffectivelySealed(type);
        }

        public bool IsEffectivelySealed(MethodDesc method)
        {
            return _devirtualizationManager.IsEffectivelySealed(method);
        }

        public MethodDesc ResolveVirtualMethod(MethodDesc declMethod, TypeDesc implType)
        {
            return _devirtualizationManager.ResolveVirtualMethod(declMethod, implType);
        }

        public bool NeedsRuntimeLookup(ReadyToRunHelperId lookupKind, object targetOfLookup)
        {
            // The current plan seem to be to copy paste from ILCompiler.Compilation, but that's not a sustainable plan
            throw new NotImplementedException();
        }

        public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object targetOfLookup)
        {
            // The current plan seem to be to copy paste from ILCompiler.Compilation, but that's not a sustainable plan
            throw new NotImplementedException();
        }

        public GenericDictionaryLookup ComputeGenericLookup(MethodDesc contextMethod, ReadyToRunHelperId lookupKind, object targetOfLookup)
        {
            // The current plan seem to be to copy paste from ILCompiler.Compilation, but that's not a sustainable plan
            throw new NotImplementedException();
        }

        public DelegateCreationInfo GetDelegateCtor(TypeDesc delegateType, MethodDesc target, bool followVirtualDispatch)
        {
            return DelegateCreationInfo.Create(delegateType, target, NodeFactory, followVirtualDispatch);
        }
    }
}