예제 #1
0
 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;
 }
예제 #2
0
        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);
                        }
                    }
                }
            }
        }
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
        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;
        }
예제 #5
0
파일: ValueNode.cs 프로젝트: harnold/cobe
 public virtual bool IsCoverableWith(ValueNode patternValue)
 {
     return IsCoverableWithDatatype(patternValue.Datatype) &&
            IsCoverableWithStorageClass(patternValue.StorageClass);
 }
예제 #6
0
파일: ValueNode.cs 프로젝트: harnold/cobe
        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;
        }
예제 #7
0
        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;
        }
예제 #8
0
        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;
        }
예제 #9
0
        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);
                }
            }
        }
예제 #10
0
        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;
        }
예제 #11
0
        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);
                    }
                }
            }
        }
예제 #12
0
 public ValueInfo GetValueInfo(ValueNode v)
 {
     return (ValueInfo) valueInfos[v];
 }
예제 #13
0
 public Register this[ValueNode valueNode]
 {
     get { return (Register) registers[valueNode]; }
     set { registers[valueNode] = value; }
 }