Exemple #1
0
        internal static void SetupInliningAttributes(
            IRContext context,
            Method method,
            DisassembledMethod disassembledMethod)
        {
            // Check whether we are allowed to inline this method
            if (context.HasFlags(ContextFlags.NoInlining) || !method.HasImplementation)
            {
                return;
            }

            if (method.HasSource)
            {
                var source = method.Source;
                if ((source.MethodImplementationFlags & MethodImplAttributes.NoInlining)
                    == MethodImplAttributes.NoInlining)
                {
                    return;
                }

                if ((source.MethodImplementationFlags & MethodImplAttributes.AggressiveInlining)
                    == MethodImplAttributes.AggressiveInlining ||
                    source.Module.Name == Context.FullAssemblyModuleName)
                {
                    method.AddFlags(MethodFlags.Inline);
                }
            }

            // Evaluate a simple inlining heuristic
            if (context.HasFlags(ContextFlags.AggressiveInlining) ||
                disassembledMethod.Instructions.Length <= MaxNumILInstructionsToInline)
            {
                method.AddFlags(MethodFlags.Inline);
            }
        }