public string GetAssembly(InstructionNode iNode) { string result = ""; string iMnemonic = iNode.Instruction.Mnemonic; int i = 0; while (i < iMnemonic.Length) { if (iMnemonic[i] == '$') { string opStr = iMnemonic.Substring(++i, 1); if (opStr == "r") { result += GetAssemblyForValue(iNode.ResultValue); } else { int opIndex = Int32.Parse(opStr); result += GetAssemblyForValue( (ValueNode) iNode.OperandValues[opIndex]); } } else { result += iMnemonic[i]; } ++i; } return result; }
public virtual InstructionSchedule Clone(IDictionary instructionMap) { InstructionSchedule clone = new InstructionSchedule(); foreach (InstructionNode[] step in instructions) { InstructionNode[] cloneStep = new InstructionNode[step.Length]; for (int i = 0; i < step.Length; i++) { if (step[i] != null) cloneStep[i] = (InstructionNode) instructionMap[step[i]]; else cloneStep[i] = null; } clone.instructions.Add(cloneStep); } return clone; }
protected virtual void InitializeDependenciesForInstruction( InstructionNode instr, IDictionary dependenciesComputed) { IList instrDependencies = (IList) dependencies[instr]; foreach (ValueNode opValue in instr.OperandValues) { if (!opValue.IsInputValue()) { InstructionNode opInstr = opValue.ProducingInstruction; if (!((bool) dependenciesComputed[opInstr])) { InitializeDependenciesForInstruction( opInstr, dependenciesComputed); } IList opDependencies = (IList) dependencies[opInstr]; foreach (InstructionNode depInstr in opDependencies) { if (!instrDependencies.Contains(depInstr)) instrDependencies.Add(depInstr); } instrDependencies.Add(opInstr); } } dependenciesComputed[instr] = true; }
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; }
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 virtual void BuildInstructionGraphForValue( ValueNode val, IDictionary valueProcessed, IDictionary valueNodeMap) { if (!(bool) valueProcessed[val]) { ValueNode iVal = (ValueNode) val.Clone(); instructionGraph.AddNode(iVal); valueProcessed[val] = true; valueNodeMap[val] = iVal; if (!val.IsInputValue()) { CoveringInfo ci = (CoveringInfo) selection[val.ProducingOperation]; InstructionNode instr = new InstructionNode(ci.Instruction); instructionGraph.AddNode(instr); instructionGraph.AddEdge(instr, iVal); foreach (ValueNode opVal in ci.OperandValues) { BuildInstructionGraphForValue( opVal, valueProcessed, valueNodeMap); ValueNode iOpVal = (ValueNode) valueNodeMap[opVal]; instructionGraph.AddEdge(iOpVal, instr); } } } }
protected virtual void RelativeOrderCrossoverForExUnit( SchedulingGenome genome1, SchedulingGenome genome2, int exUnit, IList instructionsOnExUnit) { int nCross = (int) (GA.Random.NextGaussian() * (instructionsOnExUnit.Count / 6) + (instructionsOnExUnit.Count / 2)); nCross = Math.Min(nCross, instructionsOnExUnit.Count); nCross = Math.Max(nCross, 0); InstructionNode[] selectedInstr1 = new InstructionNode[nCross]; InstructionNode[] selectedInstr2 = new InstructionNode[nCross]; int[] instrSteps1 = new int[nCross]; int[] instrSteps2 = new int[nCross]; for (int i = 0; i < nCross; i++) { int selectedInstrIndex = GA.Random.Next(instructionsOnExUnit.Count); InstructionNode selectedInstr = (InstructionNode) instructionsOnExUnit[selectedInstrIndex]; selectedInstr1[i] = selectedInstr; selectedInstr2[i] = selectedInstr; instrSteps1[i] = genome1.GetInstructionInfo( selectedInstr).SchedulingStep; instrSteps2[i] = genome2.GetInstructionInfo( selectedInstr).SchedulingStep; } Array.Sort(instrSteps1, selectedInstr2); Array.Sort(instrSteps2, selectedInstr1); for (int i = 0; i < nCross; i++) { genome1.ScheduleInstructionForStep( selectedInstr1[i], instrSteps1[i]); genome2.ScheduleInstructionForStep( selectedInstr2[i], instrSteps2[i]); } }
public virtual void ScheduleInstructionForStep( InstructionNode iNode, int step) { schedule[ step, iNode.Instruction.ExecutionUnit ] = iNode; GetInstructionInfo(iNode).SchedulingStep = step; }
public virtual InstructionSchedule GetInstructionSchedule() { InstructionSchedule instructionSchedule = new InstructionSchedule(); for (int i = 0; i < ScheduleLength; i++) { InstructionNode[] step = new InstructionNode[ MachineDescription.ExecutionUnits]; for (int j = 0; j < step.Length; j++) step[j] = Schedule[i, j]; instructionSchedule.Instructions.Add(step); } return instructionSchedule; }
public InstructionInfo GetInstructionInfo(InstructionNode i) { return (InstructionInfo) instructionInfos[i]; }