/// <summary>
        /// Provides method bodies for intrinsics recognized by the compiler.
        /// It can return null if it's not an intrinsic recognized by the compiler,
        /// but an intrinsic e.g. recognized by codegen.
        /// </summary>
        private MethodIL TryGetIntrinsicMethodIL(MethodDesc method)
        {
            var mdType = method.OwningType as MetadataType;

            if (mdType == null)
            {
                return(null);
            }

            if (mdType.Name == "RuntimeHelpers" && mdType.Namespace == "System.Runtime.CompilerServices")
            {
                return(RuntimeHelpersIntrinsics.EmitIL(method));
            }

            if (mdType.Name == "Unsafe" && mdType.Namespace == "Internal.Runtime.CompilerServices")
            {
                return(UnsafeIntrinsics.EmitIL(method));
            }

            if (mdType.Name == "Volatile" && mdType.Namespace == "System.Threading")
            {
                return(VolatileIntrinsics.EmitIL(method));
            }

            if (mdType.Name == "Interlocked" && mdType.Namespace == "System.Threading")
            {
                return(InterlockedIntrinsics.EmitIL(method));
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Provides method bodies for intrinsics recognized by the compiler.
        /// It can return null if it's not an intrinsic recognized by the compiler,
        /// but an intrinsic e.g. recognized by codegen.
        /// </summary>
        private MethodIL TryGetIntrinsicMethodIL(MethodDesc method)
        {
            Debug.Assert(method.IsIntrinsic);

            MetadataType owningType = method.OwningType as MetadataType;

            if (owningType == null)
            {
                return(null);
            }

            switch (owningType.Name)
            {
            case "Unsafe":
            {
                if (owningType.Namespace == "Internal.Runtime.CompilerServices")
                {
                    return(UnsafeIntrinsics.EmitIL(method));
                }
            }
            break;

            case "Debug":
            {
                if (owningType.Namespace == "System.Diagnostics" && method.Name == "DebugBreak")
                {
                    return(new ILStubMethodIL(method, new byte[] { (byte)ILOpcode.break_, (byte)ILOpcode.ret }, Array.Empty <LocalVariableDefinition>(), null));
                }
            }
            break;

            case "EETypePtr":
            {
                if (owningType.Namespace == "System" && method.Name == "EETypePtrOf")
                {
                    return(EETypePtrOfIntrinsic.EmitIL(method));
                }
            }
            break;

            case "RuntimeAugments":
            {
                if (owningType.Namespace == "Internal.Runtime.Augments" && method.Name == "GetCanonType")
                {
                    return(GetCanonTypeIntrinsic.EmitIL(method));
                }
            }
            break;
            }

            return(null);
        }
Beispiel #3
0
        private MethodIL TryGetIntrinsicMethodIL(MethodDesc method)
        {
            // Provides method bodies for intrinsics recognized by the compiler.
            // It can return null if it's not an intrinsic recognized by the compiler,
            // but an intrinsic e.g. recognized by codegen.

            Debug.Assert(method.IsIntrinsic);
            MetadataType owningType = method.OwningType as MetadataType;

            if (owningType == null)
            {
                return(null);
            }

            switch (owningType.Name)
            {
            case "Unsafe":
            {
                if (owningType.Namespace == "System.Runtime.CompilerServices")
                {
                    return(UnsafeIntrinsics.EmitIL(method));
                }
            }
            break;

            case "Debug":
            {
                if (owningType.Namespace == "System.Diagnostics" && method.Name == "DebugBreak")
                {
                    return(new ILStubMethodIL(method, new byte[] { (byte)ILOpcode.break_, (byte)ILOpcode.ret }, Array.Empty <LocalVariableDefinition>(), null));
                }
            }
            break;

            case "EETypePtr":
            {
                if (owningType.Namespace == "System" && method.Name == "EETypePtrOf")
                {
                    return(EETypePtrOfIntrinsic.EmitIL(method));
                }
            }
            break;
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Provides method bodies for intrinsics recognized by the compiler.
        /// It can return null if it's not an intrinsic recognized by the compiler,
        /// but an intrinsic e.g. recognized by codegen.
        /// </summary>
        private MethodIL TryGetIntrinsicMethodIL(MethodDesc method)
        {
            Debug.Assert(method.IsIntrinsic);

            MetadataType owningType = method.OwningType as MetadataType;

            if (owningType == null)
            {
                return(null);
            }

            switch (owningType.Name)
            {
            case "Interlocked":
            {
                if (owningType.Namespace == "System.Threading")
                {
                    return(InterlockedIntrinsics.EmitIL(method));
                }
            }
            break;

            case "Unsafe":
            {
                if (owningType.Namespace == "Internal.Runtime.CompilerServices")
                {
                    return(UnsafeIntrinsics.EmitIL(method));
                }
            }
            break;

            case "MemoryMarshal":
            {
                if (owningType.Namespace == "System.Runtime.InteropServices")
                {
                    return(MemoryMarshalIntrinsics.EmitIL(method));
                }
            }
            break;

            case "Volatile":
            {
                if (owningType.Namespace == "System.Threading")
                {
                    return(VolatileIntrinsics.EmitIL(method));
                }
            }
            break;

            case "Debug":
            {
                if (owningType.Namespace == "System.Diagnostics" && method.Name == "DebugBreak")
                {
                    return(new ILStubMethodIL(method, new byte[] { (byte)ILOpcode.break_, (byte)ILOpcode.ret }, Array.Empty <LocalVariableDefinition>(), null));
                }
            }
            break;

            case "EETypePtr":
            {
                if (owningType.Namespace == "System" && method.Name == "EETypePtrOf")
                {
                    return(EETypePtrOfIntrinsic.EmitIL(method));
                }
            }
            break;

            case "RuntimeAugments":
            {
                if (owningType.Namespace == "Internal.Runtime.Augments" && method.Name == "GetCanonType")
                {
                    return(GetCanonTypeIntrinsic.EmitIL(method));
                }
            }
            break;

            case "EEType":
            {
                if (owningType.Namespace == "Internal.Runtime" && method.Name == "get_SupportsRelativePointers")
                {
                    ILOpcode value = method.Context.Target.SupportsRelativePointers ?
                                     ILOpcode.ldc_i4_1 : ILOpcode.ldc_i4_0;
                    return(new ILStubMethodIL(method, new byte[] { (byte)value, (byte)ILOpcode.ret }, Array.Empty <LocalVariableDefinition>(), null));
                }
            }
            break;
            }

            return(null);
        }