Пример #1
0
        public override bool Optimize(List <BaseBlock> codeBlocks)
        {
            var CFG = new ControlFlowGraph(codeBlocks);

            var(InExprs, OutExpr) = CFG.GenerateInputOutputAvaliableExpr();


            var startToId = new Dictionary <int, int>();

            for (int i = 0; i < codeBlocks.Count; ++i)
            {
                startToId[codeBlocks[i].StartLabel] = i;
            }

            for (int i = 0; i < codeBlocks.Count; ++i)
            {
                if (TryOptimize(codeBlocks[i], InExprs[i], CFG.PrevBlocks(codeBlocks[i])))
                {
                    var code = BaseBlockHelper.JoinBaseBlocks(codeBlocks);
                    BaseBlockHelper.FixLabelsNumeration(code);
                    codeBlocks.Clear();
                    codeBlocks.InsertRange(0, BaseBlockHelper.GenBaseBlocks(code));

                    return(true);
                }
            }
            return(false);
        }