Beispiel #1
0
        /// <summary>
        /// Tries to move the assigment as far down the block as is possible.
        /// </summary>
        /// <param name="ass"></param>
        /// <param name="block"></param>
        /// <param name="i"></param>
        /// <returns>true if a change was made</returns>
        public bool TryMoveAssignment(Statement stmDef, SsaIdentifier sidDef, Expression defExpr, Block block, int initialPosition)
        {
            SideEffectFlags flagsDef = sef.FindSideEffect(stmDef.Instruction);

            for (int i = initialPosition + 1; i < block.Statements.Count; ++i)
            {
                Statement stm = block.Statements[i];
                if (sidDef.Uses.Contains(stm))
                {
                    if (CanCoalesce(sidDef, stmDef, stm))
                    {
                        Coalesced = true;
                        return(CoalesceStatements(sidDef, defExpr, stmDef, stm));
                    }
                    else
                    {
                        return(MoveAssignment(initialPosition, i, block));
                    }
                }
                if (stm.Instruction.IsControlFlow)
                {
                    return(MoveAssignment(initialPosition, i, block));
                }

                SideEffectFlags flagsStm = sef.FindSideEffect(stm.Instruction);
                if (sef.Conflict(flagsDef, flagsStm))
                {
                    return(MoveAssignment(initialPosition, i, block));
                }
            }
            return(MoveAssignment(initialPosition, block.Statements.Count, block));
        }