Exemple #1
0
        public int GetOverlapPosition(LiveInterval other)
        {
            LiveRange a = CurrRange;
            LiveRange b = other.CurrRange;

            while (a != default)
            {
                while (b != default && b.Start < a.Start)
                {
                    if (a.Overlaps(b))
                    {
                        return(a.Start);
                    }

                    b = b.Next;
                }

                if (b == default)
                {
                    break;
                }
                else if (a.Overlaps(b))
                {
                    return(a.Start);
                }

                a = a.Next;
            }

            return(NotFound);
        }
Exemple #2
0
        public void AddRange(int start, int end)
        {
            Debug.Assert(start < end, $"Invalid range start position {start}, {end}");

            if (FirstRange != default)
            {
                // If the new range ends exactly where the first range start, then coalesce together.
                if (end == FirstRange.Start)
                {
                    FirstRange.Start = start;

                    return;
                }
                // If the new range is already contained, then coalesce together.
                else if (FirstRange.Overlaps(start, end))
                {
                    FirstRange.Start = Math.Min(FirstRange.Start, start);
                    FirstRange.End   = Math.Max(FirstRange.End, end);
                    End = Math.Max(End, end);

                    Debug.Assert(FirstRange.Next == default || !FirstRange.Overlaps(FirstRange.Next));
                    return;
                }
            }

            FirstRange = new LiveRange(start, end, FirstRange);
            End        = Math.Max(End, end);

            Debug.Assert(FirstRange.Next == default || !FirstRange.Overlaps(FirstRange.Next));
        }
Exemple #3
0
        public void Forward(int position)
        {
            LiveRange prev = PrevRange;
            LiveRange curr = CurrRange;

            while (curr != default && curr.Start < position && !curr.Overlaps(position))
            {
                prev = curr;
                curr = curr.Next;
            }

            PrevRange = prev;
            CurrRange = curr;
        }
Exemple #4
0
        public bool Overlaps(int position)
        {
            LiveRange curr = CurrRange;

            while (curr != default && curr.Start <= position)
            {
                if (curr.Overlaps(position))
                {
                    return(true);
                }

                curr = curr.Next;
            }

            return(false);
        }
Exemple #5
0
        public LiveInterval Split(int position)
        {
            LiveInterval result = new(Local, Parent);

            result.End = End;

            LiveRange prev = PrevRange;
            LiveRange curr = CurrRange;

            while (curr != default && curr.Start < position && !curr.Overlaps(position))
            {
                prev = curr;
                curr = curr.Next;
            }

            if (curr.Start >= position)
            {
                prev.Next = default;

                result.FirstRange = curr;

                End = prev.End;
            }
            else
            {
                result.FirstRange = new LiveRange(position, curr.End, curr.Next);

                curr.End  = position;
                curr.Next = default;

                End = curr.End;
            }

            result.Uses = Uses.Split(position);

            AddSplitChild(result);

            Debug.Assert(!IsEmpty, "Left interval is empty after split.");
            Debug.Assert(!result.IsEmpty, "Right interval is empty after split.");

            // Make sure the iterator in the new split is pointing to the start.
            result.Reset();

            return(result);
        }