コード例 #1
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
 public static void RemoveGuards(NodeGraph graph)
 {
     for (int i = graph.numBlocks - 1; i >= 0; i--)
     {
         NodeBlock block = graph[i];
         for (NodeList.reverse_iterator iter = block.nodes.rbegin(); iter.more(); )
         {
             if (iter.node.guard)
             {
                 //Debug.Assert(iter.node.idempotent);
                 iter.node.removeFromUseChains();
                 block.nodes.remove(iter);
                 continue;
             }
             iter.next();
         }
     }
 }
コード例 #2
0
ファイル: SourceStructure.cs プロジェクト: not1ce111/Spedit
 public SourceStructureBuilder(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #3
0
ファイル: NodeRewriter.cs プロジェクト: maxijabase/SPCode
 public NodeRewriter(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #4
0
 public SourceStructureBuilder(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #5
0
ファイル: NodeRenamer.cs プロジェクト: not1ce111/Spedit
 public NodeRenamer(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #6
0
 public BackwardTypePropagation(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #7
0
ファイル: BlockAnalysis.cs プロジェクト: not1ce111/Spedit
 private static NodeBlock InLoop(NodeGraph graph, NodeBlock block)
 {
     while (true)
     {
         if (block.lir.backedge != null)
             return block;
         NodeBlock next = graph[block.lir.idom.id];
         if (block == next)
             return null;
         block = next;
     }
 }
コード例 #8
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();
        }
コード例 #9
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
 // We rely on accurate use counts to rename nodes in a readable way,
 // so we provide a phase for updating use info.
 public static void RemoveDeadCode(NodeGraph graph)
 {
     for (int i = graph.numBlocks - 1; i >= 0; i--)
         RemoveDeadCodeInBlock(graph[i]);
 }
コード例 #10
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
 public static void AnalyzeHeapUsage(NodeGraph graph)
 {
     for (int i = 0; i < graph.numBlocks; i++)
         AnalyzeHeapUsage(graph[i]);
 }
コード例 #11
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
 public static void CoalesceLoadStores(NodeGraph graph)
 {
     for (int i = 0; i < graph.numBlocks; i++)
         CoalesceLoadStores(graph[i]);
 }
コード例 #12
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
        public static void CoalesceLoadsAndDeclarations(NodeGraph graph)
        {
            for (int i = 0; i < graph.numBlocks; i++)
            {
                NodeBlock block = graph[i];
                for (NodeList.iterator iter = block.nodes.begin(); iter.more(); )
                {
                    DNode node = iter.node;

                    if (node.type == NodeType.DeclareLocal)
                    {
                        // Peephole next = store(this, expr)
                        DDeclareLocal local = (DDeclareLocal)node;
                        if (node.next.type == NodeType.Store)
                        {
                            DStore store = (DStore)node.next;
                            if (store.getOperand(0) == local)
                            {
                                local.replaceOperand(0, store.getOperand(1));
                                store.removeFromUseChains();
                                iter.next();
                                block.nodes.remove(iter);
                                continue;
                            }
                        }
                    }

                    iter.next();
                }
            }
        }
コード例 #13
0
ファイル: NodeAnalysis.cs プロジェクト: not1ce111/Spedit
 // Find adds that should really be array references.
 public static void CollapseArrayReferences(NodeGraph graph)
 {
     bool changed;
     do
     {
         changed = false;
         for (int i = graph.numBlocks - 1; i >= 0; i--)
             changed |= CollapseArrayReferences(graph[i]);
     } while (changed);
 }
コード例 #14
0
ファイル: NodeRewriter.cs プロジェクト: not1ce111/Spedit
 public NodeRewriter(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #15
0
 public NodeRenamer(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #16
0
ファイル: BlockAnalysis.cs プロジェクト: not1ce111/Spedit
 private static NodeBlock FindJoinBlock(NodeGraph graph, NodeBlock block)
 {
     if (block.nodes.last.type == NodeType.JumpCondition && block.lir.idominated.Length == 3)
         return graph[block.lir.idominated[2].id];
     if (block.lir.idom == null)
         return null;
     if (block.lir.idom == block.lir)
         return null;
     return FindJoinBlock(graph, graph[block.lir.idom.id]);
 }
コード例 #17
0
ファイル: TypePropagation.cs プロジェクト: not1ce111/Spedit
 public ForwardTypePropagation(NodeGraph graph)
 {
     graph_ = graph;
 }
コード例 #18
0
ファイル: Lysis.cs プロジェクト: not1ce111/Spedit
        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();
        }