protected string GetAssemblyForValue(ValueNode vNode) { if (vNode is RegisterValueNode) return registerAssignment[vNode].Mnemonic; else if (vNode is MemoryValueNode) return vNode.ToString(); else if (vNode is ConstantValueNode) return vNode.ToString(); else return null; }
protected virtual void GetOperationsToMutate( ProgramGraph programGraph, ValueNode rootVal, int depth, IList operationsToMutate) { if (depth > 0) { if (!rootVal.IsInputValue()) { OperationNode op = (OperationNode) rootVal.ProducingOperation; if (!operationsToMutate.Contains(op)) { operationsToMutate.Add(op); foreach (ValueNode opVal in op.OperandValues) { GetOperationsToMutate(programGraph, opVal, depth - 1, operationsToMutate); } } } } }
protected virtual void CloneEdgesForValue( ValueNode val, InstructionGraph clone, IDictionary instructionMap, IDictionary valueMap, IDictionary valueProcessed) { if (!(bool) valueProcessed[val] && !val.IsInputValue()) { valueProcessed[val] = true; ValueNode cloneResValue = (ValueNode) valueMap[val]; InstructionNode cloneInstr = (InstructionNode) instructionMap[val.ProducingInstruction]; clone.AddEdge(cloneInstr, cloneResValue); foreach (ValueNode opVal in val.ProducingInstruction.OperandValues) { ValueNode cloneOpVal = (ValueNode) valueMap[opVal]; clone.AddEdge(cloneOpVal, cloneInstr); CloneEdgesForValue(opVal, clone, instructionMap, valueMap, valueProcessed); } } }
protected virtual IList CreateCoveringDescForValue( ValueNode val, IList instructions) { IList coveringDescForValue = new ArrayList(); foreach (Instruction instr in instructions) { CoveringInfo coveringInfo = new CoveringInfo(instr); if (val.Cover(instr.Pattern.ResultValue, coveringInfo)) { coveringInfo.ResultValue = val; coveringDescForValue.Add(coveringInfo); } } return coveringDescForValue; }
public virtual bool IsCoverableWith(ValueNode patternValue) { return IsCoverableWithDatatype(patternValue.Datatype) && IsCoverableWithStorageClass(patternValue.StorageClass); }
public virtual bool Cover( ValueNode patternValue, CoveringInfo coveringInfo) { bool result = false; if (IsCoverableWith(patternValue)) { if (!IsInputValue() && !patternValue.IsInputValue()) { if (patternValue.OutNodes.Count == 0 || ConsumingOperations.Count <= 1 && !OutputFlag) { if (ProducingOperation.Cover( patternValue.ProducingOperation, coveringInfo)) { result = true; } } } else if (patternValue.IsInputValue()) { coveringInfo.OperandValues.Add(this); result = true; } if (result == true) coveringInfo.CoveredValues.Add(this); } return result; }
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 InitializeValue( ValueNode val, IDictionary valueInitialized) { if (!((bool) valueInitialized[val])) { valueInitialized[val] = true; if (!val.IsInputValue()) { IList coveringDesc = (IList) CoveringDesc[val]; CoveringInfo ci = (CoveringInfo) coveringDesc[GA.Random.Next(coveringDesc.Count)]; foreach (OperationNode op in ci.CoveredOperations) selection[op] = ci; foreach (ValueNode opVal in ci.OperandValues) InitializeValue(opVal, valueInitialized); } } }
protected virtual RegisterSet ComputeAssignableRegistersForValue( ValueNode val, Queue registerValues) { RegisterSet assignableRegs = new RegisterSet(); if (!val.IsInputValue()) { InstructionNode prodInstr = val.ProducingInstruction; assignableRegs = assignableRegs + prodInstr.Instruction.ResultRegisters; } else { InstructionNode consInstr0 = (InstructionNode) val.ConsumingInstructions[0]; int valIndex = consInstr0.OperandValues.IndexOf(val); assignableRegs = assignableRegs + consInstr0.Instruction.OperandsRegisters[valIndex]; } if (val.OutNodes.Count > 0) { IList consumingInstructions = new ArrayList(); foreach (InstructionNode consInstr in val.ConsumingInstructions) consumingInstructions.Add(consInstr); foreach (InstructionNode consInstr in consumingInstructions) { int valIndex = consInstr.OperandValues.IndexOf(val); RegisterSet consRegs = consInstr.Instruction.OperandsRegisters[valIndex]; if ((assignableRegs * consRegs).Count == 0) { ValueNode newVal = InsertTransferInstruction( val, consInstr, assignableRegs); registerValues.Enqueue(val); registerValues.Enqueue(newVal); } else { assignableRegs = assignableRegs * consRegs; } } } return assignableRegs; }
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); } } } }
public ValueInfo GetValueInfo(ValueNode v) { return (ValueInfo) valueInfos[v]; }
public Register this[ValueNode valueNode] { get { return (Register) registers[valueNode]; } set { registers[valueNode] = value; } }