Beispiel #1
0
        public EmitterContext()
        {
            _irLabels = new Dictionary <Operand, BasicBlock>();
            _irBlocks = new IntrusiveList <BasicBlock>();

            _needsNewBlock = true;
            _nextBlockFreq = BasicBlockFrequency.Default;
        }
Beispiel #2
0
        public void MarkLabel(Operand label, BasicBlockFrequency nextFreq = default)
        {
            _nextBlockFreq = nextFreq;

            if (_irLabels.TryGetValue(label, out BasicBlock nextBlock))
            {
                nextBlock.Index = _irBlocks.Count;

                _irBlocks.AddLast(nextBlock);

                NextBlock(nextBlock);
            }
            else
            {
                NewNextBlock();

                _irLabels.Add(label, _irBlock);
            }
        }
Beispiel #3
0
        private void NextBlock(BasicBlock nextBlock)
        {
            if (_irBlock?.SuccessorCount == 0 && !EndsWithUnconditional(_irBlock))
            {
                _irBlock.AddSuccessor(nextBlock);

                if (_ifBlock != null)
                {
                    _irBlock.AddSuccessor(_ifBlock);

                    _ifBlock = null;
                }
            }

            _irBlock           = nextBlock;
            _irBlock.Frequency = _nextBlockFreq;

            _needsNewBlock = false;
            _nextBlockFreq = BasicBlockFrequency.Default;
        }
Beispiel #4
0
        private void BranchToLabel(Operand label, bool uncond, BasicBlockFrequency nextFreq)
        {
            if (!_irLabels.TryGetValue(label, out BasicBlock branchBlock))
            {
                branchBlock = new BasicBlock();

                _irLabels.Add(label, branchBlock);
            }

            if (uncond)
            {
                _irBlock.AddSuccessor(branchBlock);
            }
            else
            {
                // Defer registration of successor to _irBlock so that the order of successors is correct.
                _ifBlock = branchBlock;
            }

            _needsNewBlock = true;
            _nextBlockFreq = nextFreq;
        }
Beispiel #5
0
 public void BranchIfTrue(Operand label, Operand op1, BasicBlockFrequency falseFreq = default)
 {
     BranchIf(label, op1, Const(op1.Type, 0), Comparison.NotEqual, falseFreq);
 }
Beispiel #6
0
        public void BranchIf(Operand label, Operand op1, Operand op2, Comparison comp, BasicBlockFrequency falseFreq = default)
        {
            Add(Instruction.BranchIf, null, op1, op2, Const((int)comp));

            BranchToLabel(label, uncond: false, falseFreq);
        }
Beispiel #7
0
 public void BranchIf(Operand label, Operand op1, Operand op2, Comparison comp, BasicBlockFrequency falseFreq = default)
 {
     Add(Instruction.BranchIf, default, op1, op2, Const((int)comp));