/// <summary>
        /// Lays out all parameters of the method.
        /// </summary>
        private void LayoutParameters()
        {
            var parameters = new List <Operand>();

            int offset = 0;

            if (MethodCompiler.Method.HasThis || MethodCompiler.Method.HasExplicitThis)
            {
                ++offset;
            }

            for (int i = 0; i < MethodCompiler.Method.Signature.Parameters.Count + offset; ++i)
            {
                var parameter = MethodCompiler.GetParameterOperand(i);

                parameters.Add(parameter);
            }

            int returnSize = 0;

            if (TypeLayout.IsCompoundType(MethodCompiler.Method.Signature.ReturnType))
            {
                returnSize = TypeLayout.GetTypeSize(MethodCompiler.Method.Signature.ReturnType);
            }

            int size = LayoutVariables(parameters, CallingConvention, CallingConvention.OffsetOfFirstParameter + returnSize, false);

            MethodCompiler.StackLayout.StackParameterSize = size;
            MethodCompiler.TypeLayout.SetMethodParameterStackSize(MethodCompiler.Method, size);
        }
        public bool CanInline(CompilerMethodData method)
        {
            if (method.HasDoNotInlineAttribute)
            {
                return(false);
            }

            if (method.IsPlugged)
            {
                return(false);
            }

            if (method.HasProtectedRegions)
            {
                return(false);
            }

            //if (method.HasLoops)
            //	return false;

            if (method.IsVirtual)
            {
                return(false);
            }

            // current implementation limitation - can't include methods with addressOf instruction
            if (method.HasAddressOfInstruction)
            {
                return(false);
            }

            if (method.NonIRInstructionCount > 0)
            {
                return(false);
            }

            if (method.IRInstructionCount > MethodCompiler.Compiler.CompilerOptions.InlinedIRMaximum)
            {
                return(false);
            }

            var returnType = method.Method.Signature.ReturnType;

            if (TypeLayout.IsCompoundType(returnType) && !returnType.IsUI8 && !returnType.IsR8)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        public bool CanInline(CompilerMethodData method)
        {
            if (method.HasDoNotInlineAttribute)
            {
                return(false);
            }

            if (method.IsPlugged)
            {
                return(false);
            }

            if (method.HasProtectedRegions)
            {
                return(false);
            }

            //if (method.HasLoops)
            //	return false;

            if (method.IsVirtual)
            {
                return(false);
            }

            if (method.IROtherInstructionCount > 0)
            {
                return(false);
            }

            if (method.IRInstructionCount > IRMaximumForInline)
            {
                return(false);
            }

            var returnType = method.Method.Signature.ReturnType;

            if (TypeLayout.IsCompoundType(returnType) && !returnType.IsUI8 && !returnType.IsR8)
            {
                return(false);
            }

            return(true);
        }
        private void ProcessInstruction(InstructionNode node)
        {
            if (node.Instruction == IRInstruction.Load)
            {
                if (node.MosaType != null &&
                    TypeLayout.IsCompoundType(node.MosaType) && !node.MosaType.IsUI8 && !node.MosaType.IsR8)
                {
                    if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result))
                    {
                        repl[node.Result] = MethodCompiler.StackLayout.AddStackLocal(node.MosaType);
                    }
                    node.ReplaceInstructionOnly(IRInstruction.CompoundLoad);
                }
            }
            else if (node.Instruction == IRInstruction.Store)
            {
                if (node.MosaType != null &&
                    TypeLayout.IsCompoundType(node.MosaType) && !node.MosaType.IsUI8 && !node.MosaType.IsR8)
                {
                    if (node.Operand3.IsVirtualRegister && !repl.ContainsKey(node.Operand3))
                    {
                        repl[node.Operand3] = MethodCompiler.StackLayout.AddStackLocal(node.MosaType);
                    }
                    node.ReplaceInstructionOnly(IRInstruction.CompoundStore);
                }
            }
            else if (node.Instruction == IRInstruction.Move)
            {
                if (node.Result.Type.Equals(node.Operand1.Type) &&
                    TypeLayout.IsCompoundType(node.Result.Type) && !node.Result.Type.IsUI8 && !node.Result.Type.IsR8)
                {
                    // If this move is proceded by a return then remove this instruction
                    // It is basically a double up caused by some instructions result in the same instruction output
                    if (node.Next.Instruction == IRInstruction.Return && node.Next.Operand1 == node.Result)
                    {
                        node.Next.Operand1 = node.Operand1;

                        var nopNode = new InstructionNode(IRInstruction.Nop);
                        node.Previous.Insert(nopNode);

                        node.Empty();
                        return;
                    }

                    // If this move is preceded by a compound move (which will turn into a compound move) remove this instruction
                    // It is basically a double up caused by some instructions result in the same IR output
                    if ((node.Previous.Instruction == IRInstruction.CompoundMove ||
                         node.Previous.Instruction == IRInstruction.CompoundLoad ||
                         node.Previous.Instruction == IRInstruction.Call) &&
                        node.Previous.Result == node.Operand1)
                    {
                        if (repl.ContainsKey(node.Previous.Result))
                        {
                            repl[node.Result] = repl[node.Previous.Result];
                            repl.Remove(node.Previous.Result);
                        }
                        node.Previous.Result = node.Result;

                        var nopNode = new InstructionNode(IRInstruction.Nop);
                        node.Previous.Insert(nopNode);

                        node.Empty();
                        return;
                    }

                    if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result))
                    {
                        repl[node.Result] = MethodCompiler.StackLayout.AddStackLocal(node.Result.Type);
                    }
                    if (node.Operand1.IsVirtualRegister && !repl.ContainsKey(node.Operand1))
                    {
                        repl[node.Operand1] = MethodCompiler.StackLayout.AddStackLocal(node.Operand1.Type);
                    }
                    node.ReplaceInstructionOnly(IRInstruction.CompoundMove);
                }
            }
            else if (node.Instruction == IRInstruction.Call)
            {
                if (node.Result != null &&
                    TypeLayout.IsCompoundType(node.Result.Type) && !node.Result.Type.IsUI8 && !node.Result.Type.IsR8)
                {
                    if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result))
                    {
                        repl[node.Result] = MethodCompiler.StackLayout.AddStackLocal(node.Result.Type);
                    }
                }
            }
        }