Beispiel #1
0
        private Operand Map(Operand operand, Dictionary <Operand, Operand> map, InstructionNode callNode)
        {
            if (operand == null)
            {
                return(null);
            }

            Operand mappedOperand;

            if (map.TryGetValue(operand, out mappedOperand))
            {
                return(mappedOperand);
            }

            if (operand.IsSymbol)
            {
                if (operand.StringData != null)
                {
                    mappedOperand = Operand.CreateStringSymbol(operand.Type.TypeSystem, operand.Name, operand.StringData);
                }
                else if (operand.Method != null)
                {
                    mappedOperand = Operand.CreateSymbolFromMethod(operand.Type.TypeSystem, operand.Method);
                }
                else if (operand.Name != null)
                {
                    mappedOperand = Operand.CreateManagedSymbol(operand.Type, operand.Name);
                }
            }
            else if (operand.IsParameter)
            {
                mappedOperand = callNode.GetOperand(operand.Index + 1);
            }
            else if (operand.IsStackLocal)
            {
                mappedOperand = MethodCompiler.AddStackLocal(operand.Type, operand.IsPinned);
            }
            else if (operand.IsVirtualRegister)
            {
                mappedOperand = AllocateVirtualRegister(operand.Type);
            }
            else if (operand.IsStaticField)
            {
                mappedOperand = Operand.CreateField(operand.Field);
            }
            else if (operand.IsCPURegister)
            {
                mappedOperand = operand;
            }
            else if (operand.IsConstant)
            {
                mappedOperand = operand;
            }

            Debug.Assert(mappedOperand != null);

            map.Add(operand, mappedOperand);

            return(mappedOperand);
        }
Beispiel #2
0
        /// <summary>
        /// Converts the virtual register to stack local.
        /// </summary>
        /// <param name="virtualRegister">The virtual register.</param>
        /// <returns></returns>
        Operand IInstructionDecoder.ConvertVirtualRegisterToStackLocal(Operand virtualRegister)
        {
            if (virtualRegister.IsStackLocal)
            {
                return(virtualRegister);
            }

            int index = 0;

            foreach (var op in MethodCompiler.LocalVariables)
            {
                if (op == virtualRegister)
                {
                    break;
                }

                index++;
            }

            var local = Method.LocalVariables[index];

            var stackLocal = MethodCompiler.AddStackLocal(local.Type, local.IsPinned);

            MethodCompiler.LocalVariables[index] = stackLocal;

            //ReplaceOperand(virtualRegister, stackLocal);
            foreach (var node in virtualRegister.Uses.ToArray())
            {
                for (int i = 0; i < node.OperandCount; i++)
                {
                    var op = node.GetOperand(i);

                    if (virtualRegister == op)
                    {
                        node.SetOperand(i, stackLocal);
                    }
                }
            }

            foreach (var node in virtualRegister.Definitions.ToArray())
            {
                for (int i = 0; i < node.ResultCount; i++)
                {
                    var op = node.GetResult(i);

                    if (virtualRegister == op)
                    {
                        node.SetResult(i, stackLocal);
                    }
                }
            }

            return(stackLocal);
        }
Beispiel #3
0
        private Operand Map(Operand operand, Dictionary <Operand, Operand> map, InstructionNode callSiteNode)
        {
            if (operand == null)
            {
                return(null);
            }

            if (map.TryGetValue(operand, out Operand mappedOperand))
            {
                return(mappedOperand);
            }

            if (operand.IsSymbol)
            {
                if (operand.IsString)
                {
                    // FUTURE: explore operand re-use
                    mappedOperand = Operand.CreateStringSymbol(operand.Name, operand.StringData, operand.Type.TypeSystem);
                }
                else if (operand.Method != null)
                {
                    // FUTURE: explore operand re-use
                    mappedOperand = Operand.CreateSymbolFromMethod(operand.Method, operand.Type.TypeSystem);
                }
                else if (operand.Name != null)
                {
                    // FUTURE: explore operand re-use
                    mappedOperand = Operand.CreateSymbol(operand.Type, operand.Name);
                }
            }
            else if (operand.IsParameter)
            {
                mappedOperand = callSiteNode.GetOperand(operand.Index + 1);
            }
            else if (operand.IsStackLocal)
            {
                mappedOperand = MethodCompiler.AddStackLocal(operand.Type, operand.IsPinned);
            }
            else if (operand.IsVirtualRegister)
            {
                mappedOperand = AllocateVirtualRegister(operand.Type);
            }
            else if (operand.IsStaticField)
            {
                // FUTURE: explore operand re-use
                mappedOperand = Operand.CreateStaticField(operand.Field, TypeSystem);
            }
            else if (operand.IsCPURegister)
            {
                mappedOperand = operand;
            }
            else if (operand.IsConstant)
            {
                mappedOperand = operand;
            }

            Debug.Assert(mappedOperand != null);

            if (operand.HasLongParent)
            {
                MethodCompiler.SplitLongOperand(mappedOperand);

                if (operand.IsLow)
                {
                    mappedOperand = mappedOperand.Low;
                }
                else if (operand.IsHigh)
                {
                    mappedOperand = mappedOperand.High;
                }
            }

            map.Add(operand, mappedOperand);

            return(mappedOperand);
        }