Пример #1
0
            /// <summary>
            /// Constructs a new phi builder.
            /// </summary>
            /// <param name="phiValue">The phi value.</param>
            internal Builder(PhiValue phiValue)
            {
                Debug.Assert(phiValue != null, "Invalid phi value");
                PhiValue = phiValue;

                arguments = ImmutableArray.CreateBuilder <ValueReference>();
            }
Пример #2
0
            /// <summary>
            /// Constructs a new phi builder.
            /// </summary>
            /// <param name="phiValue">The phi value.</param>
            /// <param name="capacity">The initial capacity.</param>
            internal Builder(PhiValue phiValue, int capacity)
            {
                Debug.Assert(phiValue != null, "Invalid phi value");
                PhiValue = phiValue;

                arguments      = ValueList.Create(capacity);
                argumentBlocks = BlockList.Create(capacity);
            }
Пример #3
0
 public readonly bool TryRemap(
     PhiValue phiValue,
     BasicBlock block,
     out BasicBlock newBlock)
 {
     newBlock = block == OldBlock ? NewBlock : block;
     return(true);
 }
Пример #4
0
        /// <summary>
        /// Tries to remove a trivial phi value.
        /// </summary>
        /// <param name="methodBuilder">The current method builder.</param>
        /// <param name="phiValue">The phi value to check.</param>
        /// <returns>The resolved value.</returns>
        public static Value TryRemoveTrivialPhi(
            Method.Builder methodBuilder,
            PhiValue phiValue)
        {
            // Implements a part of the SSA-construction algorithm from the paper:
            // Simple and Efficient Construction of Static Single Assignment Form
            // See also: SSABuilder.cs

            Debug.Assert(phiValue != null, "Invalid phi value to remove");
            Value same = null;

            foreach (Value argument in phiValue.Nodes)
            {
                if (same == argument || argument == phiValue)
                {
                    continue;
                }
                if (same != null)
                {
                    return(phiValue);
                }
                same = argument;
            }

            // Unreachable phi
            if (same == null)
            {
                return(phiValue);
            }

            var uses = phiValue.Uses.Clone();

            phiValue.Replace(same);

            // Remove the phi node from the current block
            var builder = methodBuilder[phiValue.BasicBlock];

            builder.Remove(phiValue);

            foreach (var use in uses)
            {
                if (use.Resolve() is PhiValue usedPhi)
                {
                    TryRemoveTrivialPhi(methodBuilder, usedPhi);
                }
            }

            return(same);
        }
Пример #5
0
 public readonly bool CanRemap(PhiValue phiValue) =>
 phiValue.Sources.Contains(OldBlock, new BasicBlock.Comparer());
Пример #6
0
 /// <summary>
 /// Returns the value of <paramref name="value"/>.
 /// </summary>
 public readonly Value RemapValue(
     PhiValue phiValue,
     BasicBlock updatedBlock,
     Value value) =>
 value;