Goose  Artifact [5aa4d4e80d]

Artifact 5aa4d4e80da83f0a4aff8ac3aaf4c792d7201baa1c986f606dd26a2004b097fc:

  • File bs/llr/branch.h — part of check-in [4ae6912760] at 2019-09-29 22:30:12 on branch trunk —
    • Fixed some issues with implicit termination of void functions.
    • llr: give an index to each basic block, and keep track of back links towards previous blocks.
    (user: achavasse size: 1583)

#ifndef GOOSE_LLR_BRANCH_H
#define GOOSE_LLR_BRANCH_H

namespace goose::llr
{
    class BasicBlock;

    class Branch
    {
        public:
            template< typename B >
            Branch( B&& dest ) :
                m_dest( forward< B >( dest ) )
            {}

            const auto& dest() const { return m_dest; }

            bool canBeExecuted() const { return true; }
            bool canBeEagerlyEvaluated() const { return true; }

            void setupBackLinks( uint32_t srcBBIndex );

        private:
            wptr< BasicBlock > m_dest;
    };

    class CondBranch
    {
        public:
            template< typename V, typename BT, typename BF >
            CondBranch( V&& cond, BT&& trueDest, BF&& falseDest ) :
                m_cond( forward< V >( cond ) ),
                m_trueDest( forward< BT >( trueDest ) ),
                m_falseDest( forward< BF >( falseDest ) )
            {}

            const auto& cond() const { return m_cond; }
            const auto& trueDest() const { return m_trueDest; }
            const auto& falseDest() const { return m_falseDest; }

            bool canBeExecuted() const
            {
                return IsValueConstantOrExecutable( m_cond );
            }

            bool canBeEagerlyEvaluated() const
            {
                return CanValueBeEagerlyEvaluated( m_cond );
            }

            void setupBackLinks( uint32_t srcBBIndex );

        private:
            ir::Value m_cond;
            wptr< BasicBlock > m_trueDest;
            wptr< BasicBlock > m_falseDest;
    };
}

#endif