protected virtual void InsertTransferInstructionBefore( ValueNode val, Register fromReg, Register toReg, RegisterSet fromSet, RegisterSet toSet) { IList applicableTransferInstr = GetTransferInstructions(fromReg, toReg); ValueNode newVal = new RegisterValueNode(val.Datatype); instructionGraph.AddNode(newVal); if (!val.IsInputValue()) { InstructionNode prodInstr = val.ProducingInstruction; instructionGraph.RemoveEdge(prodInstr, val); instructionGraph.AddEdge(prodInstr, newVal); } Instruction transferInstr = (Instruction) applicableTransferInstr[ GA.Random.Next(applicableTransferInstr.Count)]; InstructionNode transferNode = new InstructionNode(transferInstr); instructionGraph.AddNode(transferNode); instructionGraph.AddEdge(newVal, transferNode); instructionGraph.AddEdge(transferNode, val); instructionGraph.AssignableRegisters[val] = toSet; instructionGraph.AssignableRegisters[newVal] = fromSet; }
protected ValueNode InsertTransferInstruction( ValueNode val, InstructionNode consInstr, RegisterSet assignableRegs) { ValueNode newVal = new RegisterValueNode(val.Datatype); instructionGraph.AddNode(newVal); instructionGraph.ReplaceEdgeStart(val, consInstr, newVal); IList applicableTransferInstr = new ArrayList(); foreach (Instruction instr in TransferInstructions) { RegisterSet instrRegs = instr.OperandsRegisters[0]; if ((assignableRegs * instrRegs).Count > 0) applicableTransferInstr.Add(instr); } int selectedIndex = GA.Random.Next(applicableTransferInstr.Count); Instruction selectedInstr = (Instruction) applicableTransferInstr[selectedIndex]; InstructionNode transferInstr = new InstructionNode(selectedInstr); instructionGraph.AddNode(transferInstr); instructionGraph.AddEdge(val, transferInstr); instructionGraph.AddEdge(transferInstr, newVal); return newVal; }