Example #1
0
        public virtual object Clone()
        {
            RegisterSet clone = new RegisterSet();

            foreach (Register reg in registers)
                clone.registers.Add(reg);

            return clone;
        }
Example #2
0
        public static RegisterSet Difference(RegisterSet s1, RegisterSet s2)
        {
            RegisterSet result = new RegisterSet();

            foreach (Register reg in s1.registers) {
                if (!s2.registers.Contains(reg))
                    result.registers.Add(reg);
            }

            return result;
        }
Example #3
0
        public static RegisterSet Union(RegisterSet s1, RegisterSet s2)
        {
            RegisterSet result = new RegisterSet();

            foreach (Register reg in s1.registers)
                result.registers.Add(reg);

            foreach (Register reg in s2.registers) {
                if (!result.Contains(reg))
                    result.registers.Add(reg);
            }

            return result;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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;
        }
Example #7
0
        public virtual void ComputeAssignableRegisters()
        {
            instructionGraph.AssignableRegisters.Clear();
            Queue registerValues = new Queue();

            foreach (ValueNode val in instructionGraph.GetValueNodes()) {
                if (val is RegisterValueNode)
                    registerValues.Enqueue(val);
            }

            while (registerValues.Count > 0) {

                ValueNode val = (ValueNode) registerValues.Dequeue();
                RegisterSet assignableRegs;

                if (ProgramGraph.PreassignedRegisters[val] != null) {
                    assignableRegs = new RegisterSet();
                    assignableRegs.Add(
                        (Register) ProgramGraph.PreassignedRegisters[val]);

                } else {
                    assignableRegs =
                        ComputeAssignableRegistersForValue(val, registerValues);
                }

                instructionGraph.AssignableRegisters[val] = assignableRegs;
            }
        }