예제 #1
0
        public static XILSFunction Rewrite(XILSFunction func)
        {
            var rw = new ImplTypeRewriterImpl(func.Instructions);

            rw.Rewrite();
            var result = new XILSFunction(func.Name, func.Arguments, rw.Locals.ToArray(), rw.OutInstructions.ToArray());

            return(result);
        }
예제 #2
0
        // scheduled for removal.
        public XIL3Function ExecuteXILTransformations(XILSFunction fnasm)
        {
            fnasm.SanityCheck();
            IList <XILSInstr> instrs = fnasm.Instructions.ToList();

            foreach (IXILSRewriter rw in XILSTransformations)
            {
                instrs = rw.Rewrite(instrs);
                fnasm  = new XILSFunction(fnasm.Name, fnasm.Arguments, fnasm.Locals, instrs.ToArray());
                fnasm.SanityCheck();
            }

            XIL3Function fnasm3 = fnasm.ToXIL3();

            foreach (IXIL3Rewriter rw in XIL3Transformations)
            {
                fnasm3 = rw.Rewrite(fnasm3);
                fnasm3.SanityCheck();
            }

            return(fnasm3);
        }
예제 #3
0
        /// <summary>
        /// Executes the HLS design flow.
        /// </summary>
        /// <param name="design">the design</param>
        /// <param name="host">the hosting component</param>
        /// <param name="proc">the process being subject to HLS</param>
        /// <param name="targetProject">the target project</param>
        /// <remarks>Inside the hosting component, the process will be replaced by the synthesized hardware.</remarks>
        public void Execute(DesignContext design, Component host, ProcessDescriptor proc, IProject targetProject)
        {
            Contract.Requires<ArgumentNullException>(design != null);
            Contract.Requires<ArgumentNullException>(host != null);
            Contract.Requires<ArgumentNullException>(proc != null);
            Contract.Requires<ArgumentNullException>(targetProject != null);

            design.CurrentProcess = proc.Instance;

            var clk = proc.Sensitivity[0];
            SignalBase clkI;
            var sdClk = clk as SignalDescriptor;
            if (sdClk == null)
                clkI = ((SignalDescriptor)((PortDescriptor)clk).BoundSignal).Instance;
            else
                clkI = sdClk.Instance;
            
            var state = new HLSState(this, design, host, proc, targetProject);
            proc.AddAttribute(state);

            if (_beginHLS != null)
                _beginHLS(state);

            var dpb = new DefaultDatapathBuilder(host, clkI, proc.Name);
            state.InterconnectBuilder = InterconnectBuilder.Create(host, dpb.ICBinder);
            state.ControlpathBuilder = ControlPathBuilder.Create(host, dpb.FUBinder);
            state.ControlpathBuilder.PersonalizePlan(this);

            do
            {
                XILSFunction fnasm;
                if (!proc.HasAttribute<XILSFunction>())
                {
                    var func = proc.Implementation;
                    IEnumerable<Function> inlinedFunctions;
                    func = func.InlineCalls(out inlinedFunctions);
                    if (ConvertFieldsToLocals)
                    {
                        Variable[] newLocals;
                        func = func.ConvertFieldsToLocals(out newLocals);
                    }
                    state.PreprocessedFunction = func;

                    fnasm = state.PreprocessedFunction.Compile(DefaultInstructionSet.Instance);
                }
                else
                {
                    fnasm = proc.QueryAttribute<XILSFunction>();
                }
                fnasm.SanityCheck();
                state.XILSInput = fnasm;
                IList<XILSInstr> instrs = state.XILSInput.Instructions.ToList();
                foreach (var rw in XILSTransformations)
                {
                    instrs = rw.Rewrite(instrs);
                    fnasm = new XILSFunction(fnasm.Name, fnasm.Arguments, fnasm.Locals, instrs.ToArray());
                    fnasm.SanityCheck();
                }
                state.XILSTransformed = fnasm;

                XIL3Function fnasm3 = fnasm.ToXIL3();
                state.XIL3Input = fnasm3;

                foreach (IXIL3Rewriter rw in XIL3Transformations)
                {
                    fnasm3 = rw.Rewrite(fnasm3);
                    fnasm3.SanityCheck();
                }

                state.XIL3Transformed = fnasm3;
                state.NotifyProgress(EHLSProgress.Compiled);
            } while (state._repeat);
            if (state._cancel)
                return;

            SchedulingConstraints constraints;

            do
            {
                var xmm = new XILMapperManager();
                foreach (var dpu in Enumerable.Reverse(XILMappers))
                    xmm.AddMapper(dpu);

                DesignContext.Push();

                var xilsa = new XILSchedulingAdapter(state.XIL3Transformed, xmm, host, targetProject);
                if (AllocationPolicy != null)
                    xilsa.Allocator.Policy = AllocationPolicy.Create();
                if (_onFUCreated != null)
                    xilsa.Allocator.OnFUAllocation += _onFUCreated;
                state.SchedulingAdapter = xilsa;
                state.NotifyProgress(EHLSProgress.AboutToSchedule);

                constraints = SchedulingConstraints;
                if (constraints == null)
                {
                    if (proc.Implementation != null)
                        constraints = proc.Implementation.QueryAttribute<SchedulingConstraints>();
                    if (constraints == null)
                        constraints = new SchedulingConstraints();
                }
                state.Constraints = constraints;

                if (constraints.MinimizeNumberOfFUs)
                {
                    foreach (var instr in state.XIL3Transformed.Instructions)
                    {
                        xilsa.SetMaxFUAllocation(xilsa.IClass[instr], 1);
                    }
                }

                Scheduler.Schedule(xilsa.CFG, constraints, xilsa);
                DesignContext.Pop();

                state.NotifyProgress(EHLSProgress.Scheduled);
            } while (state._repeat);

            ComputeCStepsForBranchTargets(state.SchedulingAdapter);

            do
            {
                state.ControlpathBuilder.PrepareAllocation(state.SchedulingAdapter.ComputeCStepCount());
                var flowSpec = state.SchedulingAdapter.Allocate(dpb);
                state.RawFlows = flowSpec;
                var realFlow = new FlowMatrix();
                state.InterconnectBuilder.CreateInterconnect(flowSpec, realFlow);
                state.RealFlows = realFlow;
                state.NotifyProgress(EHLSProgress.InterconnectCreated);
            } while (state._repeat);
            if (state._cancel)
                return;

            Debug.Assert(state.RealFlows.FlowSources.All(sr => sr.Desc.Owner != null));
            Debug.Assert(state.RealFlows.FlowTargets.All(sr => sr.Desc.Owner != null));

            do
            {
                state.ControlpathBuilder.CreateControlpath(state.RealFlows, proc.Name);
                foreach (var prof in constraints.Profilers)
                    prof.ExtractFrom(state.XIL3Transformed, state.SchedulingAdapter);
                state.NotifyProgress(EHLSProgress.ControlpathCreated);
            } while (state._repeat);
            if (state._cancel)
                return;
        }
예제 #4
0
        // scheduled for removal.
        public XIL3Function ExecuteXILTransformations(XILSFunction fnasm)
        {
            fnasm.SanityCheck();
            IList<XILSInstr> instrs = fnasm.Instructions.ToList();
            foreach (IXILSRewriter rw in XILSTransformations)
            {
                instrs = rw.Rewrite(instrs);
                fnasm = new XILSFunction(fnasm.Name, fnasm.Arguments, fnasm.Locals, instrs.ToArray());
                fnasm.SanityCheck();
            }

            XIL3Function fnasm3 = fnasm.ToXIL3();

            foreach (IXIL3Rewriter rw in XIL3Transformations)
            {
                fnasm3 = rw.Rewrite(fnasm3);
                fnasm3.SanityCheck();
            }

            return fnasm3;
        }
예제 #5
0
        public XILSFunction Run()
        {
            int count = 0;
            foreach (var stype in _inFunc.SlotTypes)
                _interLocals.Add(new Variable(stype) { Name = _inFunc.Name + (count++) });

            foreach (var xil3i in _inFunc.Instructions)
                Process(xil3i);

            foreach (var label in _labels)
                label.InstructionIndex = _instRemap[label.InstructionIndex];

            var locals = _inFunc.Locals.Concat(_interLocals).ToArray();
            var result = new XILSFunction(
                _inFunc.Name,
                _inFunc.Arguments,
                locals,
                _outInstrs.ToArray());

            return result;
        }
예제 #6
0
 public static XILSFunction Rewrite(XILSFunction func)
 {
     var rw = new ImplTypeRewriterImpl(func.Instructions);
     rw.Rewrite();
     var result = new XILSFunction(func.Name, func.Arguments, rw.Locals.ToArray(), rw.OutInstructions.ToArray());
     return result;
 }
예제 #7
0
        /// <summary>
        /// Executes the HLS design flow.
        /// </summary>
        /// <param name="design">the design</param>
        /// <param name="host">the hosting component</param>
        /// <param name="proc">the process being subject to HLS</param>
        /// <param name="targetProject">the target project</param>
        /// <remarks>Inside the hosting component, the process will be replaced by the synthesized hardware.</remarks>
        public void Execute(DesignContext design, Component host, ProcessDescriptor proc, IProject targetProject)
        {
            Contract.Requires <ArgumentNullException>(design != null);
            Contract.Requires <ArgumentNullException>(host != null);
            Contract.Requires <ArgumentNullException>(proc != null);
            Contract.Requires <ArgumentNullException>(targetProject != null);

            design.CurrentProcess = proc.Instance;

            var        clk = proc.Sensitivity[0];
            SignalBase clkI;
            var        sdClk = clk as SignalDescriptor;

            if (sdClk == null)
            {
                clkI = ((SignalDescriptor)((PortDescriptor)clk).BoundSignal).Instance;
            }
            else
            {
                clkI = sdClk.Instance;
            }

            var state = new HLSState(this, design, host, proc, targetProject);

            proc.AddAttribute(state);

            if (_beginHLS != null)
            {
                _beginHLS(state);
            }

            var dpb = new DefaultDatapathBuilder(host, clkI, proc.Name);

            state.InterconnectBuilder = InterconnectBuilder.Create(host, dpb.ICBinder);
            state.ControlpathBuilder  = ControlPathBuilder.Create(host, dpb.FUBinder);
            state.ControlpathBuilder.PersonalizePlan(this);

            do
            {
                XILSFunction fnasm;
                if (!proc.HasAttribute <XILSFunction>())
                {
                    var func = proc.Implementation;
                    IEnumerable <Function> inlinedFunctions;
                    func = func.InlineCalls(out inlinedFunctions);
                    if (ConvertFieldsToLocals)
                    {
                        Variable[] newLocals;
                        func = func.ConvertFieldsToLocals(out newLocals);
                    }
                    state.PreprocessedFunction = func;

                    fnasm = state.PreprocessedFunction.Compile(DefaultInstructionSet.Instance);
                }
                else
                {
                    fnasm = proc.QueryAttribute <XILSFunction>();
                }
                fnasm.SanityCheck();
                state.XILSInput = fnasm;
                IList <XILSInstr> instrs = state.XILSInput.Instructions.ToList();
                foreach (var rw in XILSTransformations)
                {
                    instrs = rw.Rewrite(instrs);
                    fnasm  = new XILSFunction(fnasm.Name, fnasm.Arguments, fnasm.Locals, instrs.ToArray());
                    fnasm.SanityCheck();
                }
                state.XILSTransformed = fnasm;

                XIL3Function fnasm3 = fnasm.ToXIL3();
                state.XIL3Input = fnasm3;

                foreach (IXIL3Rewriter rw in XIL3Transformations)
                {
                    fnasm3 = rw.Rewrite(fnasm3);
                    fnasm3.SanityCheck();
                }

                state.XIL3Transformed = fnasm3;
                state.NotifyProgress(EHLSProgress.Compiled);
            } while (state._repeat);
            if (state._cancel)
            {
                return;
            }

            SchedulingConstraints constraints;

            do
            {
                var xmm = new XILMapperManager();
                foreach (var dpu in Enumerable.Reverse(XILMappers))
                {
                    xmm.AddMapper(dpu);
                }

                DesignContext.Push();

                var xilsa = new XILSchedulingAdapter(state.XIL3Transformed, xmm, host, targetProject);
                if (AllocationPolicy != null)
                {
                    xilsa.Allocator.Policy = AllocationPolicy.Create();
                }
                if (_onFUCreated != null)
                {
                    xilsa.Allocator.OnFUAllocation += _onFUCreated;
                }
                state.SchedulingAdapter = xilsa;
                state.NotifyProgress(EHLSProgress.AboutToSchedule);

                constraints = SchedulingConstraints;
                if (constraints == null)
                {
                    if (proc.Implementation != null)
                    {
                        constraints = proc.Implementation.QueryAttribute <SchedulingConstraints>();
                    }
                    if (constraints == null)
                    {
                        constraints = new SchedulingConstraints();
                    }
                }
                state.Constraints = constraints;

                if (constraints.MinimizeNumberOfFUs)
                {
                    foreach (var instr in state.XIL3Transformed.Instructions)
                    {
                        xilsa.SetMaxFUAllocation(xilsa.IClass[instr], 1);
                    }
                }

                Scheduler.Schedule(xilsa.CFG, constraints, xilsa);
                DesignContext.Pop();

                state.NotifyProgress(EHLSProgress.Scheduled);
            } while (state._repeat);

            ComputeCStepsForBranchTargets(state.SchedulingAdapter);

            do
            {
                state.ControlpathBuilder.PrepareAllocation(state.SchedulingAdapter.ComputeCStepCount());
                var flowSpec = state.SchedulingAdapter.Allocate(dpb);
                state.RawFlows = flowSpec;
                var realFlow = new FlowMatrix();
                state.InterconnectBuilder.CreateInterconnect(flowSpec, realFlow);
                state.RealFlows = realFlow;
                state.NotifyProgress(EHLSProgress.InterconnectCreated);
            } while (state._repeat);
            if (state._cancel)
            {
                return;
            }

            Debug.Assert(state.RealFlows.FlowSources.All(sr => sr.Desc.Owner != null));
            Debug.Assert(state.RealFlows.FlowTargets.All(sr => sr.Desc.Owner != null));

            do
            {
                state.ControlpathBuilder.CreateControlpath(state.RealFlows, proc.Name);
                foreach (var prof in constraints.Profilers)
                {
                    prof.ExtractFrom(state.XIL3Transformed, state.SchedulingAdapter);
                }
                state.NotifyProgress(EHLSProgress.ControlpathCreated);
            } while (state._repeat);
            if (state._cancel)
            {
                return;
            }
        }
예제 #8
0
 private StkTo3ACImpl(XILSFunction func)
 {
     _func = func;
 }
예제 #9
0
 public static XIL3Function ToXIL3(XILSFunction xils)
 {
     StkTo3ACImpl conv = new StkTo3ACImpl(xils);
     return conv.Run();
 }