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); } } } }
private void ProcessInstruction(InstructionNode node) { if (node.Instruction == IRInstruction.Load) { if (node.MosaType != null && TypeLayout.IsCompoundType(node.MosaType)) { 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)) { 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)) { var prevNode = node.Previous; var nextNode = node.Next; while (prevNode.IsEmpty) prevNode = prevNode.Previous; while (nextNode.IsEmpty) nextNode = nextNode.Next; // If this move is proceeded by a return then remove this instruction // It is basically a double up caused by some instructions result in the same instruction output if (nextNode.Instruction == IRInstruction.Return && nextNode.Operand1 == node.Result) { nextNode.Operand1 = node.Operand1; 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 ((prevNode.Instruction == IRInstruction.CompoundMove || prevNode.Instruction == IRInstruction.CompoundLoad || prevNode.Instruction == IRInstruction.Call) && prevNode.Result == node.Operand1) { if (repl.ContainsKey(prevNode.Result)) repl[node.Result] = repl[prevNode.Result]; prevNode.Result = node.Result; 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.Result.Type.Equals(node.Operand1.Type) && node.Result.IsStackLocal && node.Operand1.IsStackLocal) { node.ReplaceInstructionOnly(IRInstruction.CompoundMove); } } else if (node.Instruction == IRInstruction.Call) { if (node.Result != null && TypeLayout.IsCompoundType(node.Result.Type)) { if (node.Result.IsVirtualRegister && !repl.ContainsKey(node.Result)) { repl[node.Result] = MethodCompiler.StackLayout.AddStackLocal(node.Result.Type); } } } }