Esempio n. 1
0
 public void inherit(LGraph graph, NodeBlock other)
 {
     if (other == null)
     {
         stack_ = new AbstractStack(graph.nargs);
         for (int i = 0; i < graph.nargs; i++)
         {
             DDeclareLocal local = new DDeclareLocal(lir_.pc, null);
             local.setOffset((i * 4) + 12);
             add(local);
             stack_.init((i * 4) + 12, local);
         }
     }
     else if (stack_ == null)
     {
         //Debug.Assert(other.stack_ != null);
         stack_ = new AbstractStack(other.stack_);
     }
     else
     {
         // Right now we only create phis for pri/alt.
         joinRegs(Register.Pri, other.stack_.pri);
         joinRegs(Register.Alt, other.stack_.alt);
     }
 }
Esempio n. 2
0
 public NodeBuilder(SourcePawnFile file, LGraph graph)
 {
     file_ = file;
     graph_ = graph;
     blocks_ = new NodeBlock[graph_.blocks.Length];
     for (int i = 0; i < graph_.blocks.Length; i++)
         blocks_[i] = new NodeBlock(graph_.blocks[i]);
 }
Esempio n. 3
0
 public NodeBuilder(SourcePawnFile file, LGraph graph)
 {
     file_   = file;
     graph_  = graph;
     blocks_ = new NodeBlock[graph_.blocks.Length];
     for (int i = 0; i < graph_.blocks.Length; i++)
     {
         blocks_[i] = new NodeBlock(graph_.blocks[i]);
     }
 }
Esempio n. 4
0
        private LGraph buildBlocks()
        {
            lir_.entry = new LBlock(lir_.entry_pc);
            var builder = new BlockBuilder(lir_);
            var entry   = builder.parse();

            // Get an RPO ordering of the blocks, since we don't have predecessors yet.
            var blocks = BlockAnalysis.Order(entry);

            if (!BlockAnalysis.IsReducible(blocks))
            {
                throw new Exception("control flow graph is not reducible");
            }

            // Split critical edges in the graph (is this even needed?)
            BlockAnalysis.SplitCriticalEdges(blocks);

            // Reorder the blocks since we could have introduced new nodes.
            blocks = BlockAnalysis.Order(entry);
            //Debug.Assert(BlockAnalysis.IsReducible(blocks));

            BlockAnalysis.ComputeDominators(blocks);
            BlockAnalysis.ComputeImmediateDominators(blocks);
            BlockAnalysis.ComputeDominatorTree(blocks);
            BlockAnalysis.FindLoops(blocks);

            var graph = new LGraph
            {
                blocks = blocks,
                entry  = blocks[0]
            };

            if (lir_.argDepth > 0)
            {
                graph.nargs = ((lir_.argDepth - 12) / 4) + 1;
            }
            else
            {
                graph.nargs = 0;
            }

            return(graph);
        }
Esempio n. 5
0
        private LGraph buildBlocks()
        {
            lir_.entry = new LBlock(lir_.entry_pc);
            BlockBuilder builder = new BlockBuilder(lir_);
            LBlock entry = builder.parse();

            // Get an RPO ordering of the blocks, since we don't have predecessors yet.
            LBlock[] blocks = BlockAnalysis.Order(entry);

            if (!BlockAnalysis.IsReducible(blocks))
                throw new Exception("control flow graph is not reducible");

            // Split critical edges in the graph (is this even needed?)
            BlockAnalysis.SplitCriticalEdges(blocks);

            // Reorder the blocks since we could have introduced new nodes.
            blocks = BlockAnalysis.Order(entry);
            //Debug.Assert(BlockAnalysis.IsReducible(blocks));

            BlockAnalysis.ComputeDominators(blocks);
            BlockAnalysis.ComputeImmediateDominators(blocks);
            BlockAnalysis.ComputeDominatorTree(blocks);
            BlockAnalysis.FindLoops(blocks);

            LGraph graph = new LGraph();
            graph.blocks = blocks;
            graph.entry = blocks[0];
            if (lir_.argDepth > 0)
                graph.nargs = ((lir_.argDepth - 12) / 4) + 1;
            else
                graph.nargs = 0;

            return graph;
        }
Esempio n. 6
0
 public void inherit(LGraph graph, NodeBlock other)
 {
     if (other == null)
     {
         stack_ = new AbstractStack(graph.nargs);
         for (int i = 0; i < graph.nargs; i++)
         {
             DDeclareLocal local = new DDeclareLocal(lir_.pc, null);
             local.setOffset((i * 4) + 12);
             add(local);
             stack_.init((i * 4) + 12, local);
         }
     }
     else if (stack_ == null)
     {
         //Debug.Assert(other.stack_ != null);
         stack_ = new AbstractStack(other.stack_);
     }
     else
     {
         // Right now we only create phis for pri/alt.
         joinRegs(Register.Pri, other.stack_.pri);
         joinRegs(Register.Alt, other.stack_.alt);
     }
 }
Esempio n. 7
0
        static void DumpMethod(SourcePawnFile file, SourceBuilder source, uint addr)
        {
            MethodParser mp    = new MethodParser(file, addr);
            LGraph       graph = mp.parse();

            NodeBuilder nb = new NodeBuilder(file, graph);

            NodeBlock[] nblocks = nb.buildNodes();

            NodeGraph ngraph = new NodeGraph(file, nblocks);

            // Remove dead phis first.
            NodeAnalysis.RemoveDeadCode(ngraph);

            NodeRewriter rewriter = new NodeRewriter(ngraph);

            rewriter.rewrite();

            NodeAnalysis.CollapseArrayReferences(ngraph);

            // Propagate type information.
            ForwardTypePropagation ftypes = new ForwardTypePropagation(ngraph);

            ftypes.propagate();

            BackwardTypePropagation btypes = new BackwardTypePropagation(ngraph);

            btypes.propagate();

            // We're not fixpoint, so just iterate again.
            ftypes.propagate();
            btypes.propagate();

            // Try this again now that we have type information.
            NodeAnalysis.CollapseArrayReferences(ngraph);

            ftypes.propagate();
            btypes.propagate();

            // Coalesce x[y] = x[y] + 5 into x[y] += 5
            NodeAnalysis.CoalesceLoadStores(ngraph);

            // After this, it is not legal to run type analysis again, because
            // arguments expecting references may have been rewritten to take
            // constants, for pretty-printing.
            NodeAnalysis.AnalyzeHeapUsage(ngraph);

            // Do another DCE pass, this time, without guards.
            NodeAnalysis.RemoveGuards(ngraph);
            NodeAnalysis.RemoveDeadCode(ngraph);

            NodeRenamer renamer = new NodeRenamer(ngraph);

            renamer.rename();

            // Do a pass to coalesce declaration+stores.
            NodeAnalysis.CoalesceLoadsAndDeclarations(ngraph);

            // Simplify conditional expressions.
            // BlockAnalysis.NormalizeConditionals(ngraph);
            var sb        = new SourceStructureBuilder(ngraph);
            var structure = sb.build();

            source.write(structure);

            //System.Console.In.Read();
            //System.Console.In.Read();
        }