Goose  Artifact [a11eafdaad]

Artifact a11eafdaad981300926cc670ff0bcdaf7000c951987d2cc83361f84cb335fd6e:

  • File bs/llr/helpers.h — part of check-in [af650a9e95] at 2019-09-22 14:37:55 on branch trunk — Project renaming. (user: achavasse size: 1932)

#ifndef GOOSE_LLR_HELPERS_H
#define GOOSE_LLR_HELPERS_H

namespace goose::llr
{
    class Instruction;

    bool IsValueConstantOrExecutable( const ir::Value& val );
    bool CanValueBeEagerlyEvaluated( const ir::Value& val );

    template< typename T, typename I >
    auto BuildComputedValue( T&& type, I&& instr )
    {
        return ir::Value( forward< T >( type ),
            make_shared< Instruction >( forward< I >( instr ) ) );
    }

    template< typename T >
    class TempStorage
    {
        public:
            template< typename TT >
            void set( uint32_t cfgId, uint32_t index, TT&& x )
            {
                auto [it, inserted] = m_storage.try_emplace( cfgId );

                if( it->second.size() <= index )
                    it->second.resize( index + 1 );

                it->second[index] = forward< TT >( x );
            }

            template< typename TT >
            void setVec( uint32_t cfgId, TT&& x )
            {
                auto [it, inserted] = m_storage.try_emplace( cfgId );
                it->second = forward< TT >( x );
            }

            const T* get( uint32_t cfgId, uint32_t index ) const
            {
                auto it = m_storage.find( cfgId );
                if( it == m_storage.end() )
                    return nullptr;

                if( it->second.size() <= index )
                    return nullptr;

                return &it->second[index];
            }

            T* get( uint32_t cfgId, uint32_t index )
            {
                auto it = m_storage.find( cfgId );
                if( it == m_storage.end() )
                    return nullptr;

                if( it->second.size() <= index )
                    return nullptr;

                return &it->second[index];
            }

        private:
            unordered_map< uint32_t, llvm::SmallVector< T, 8 > >
                m_storage;
    };
}

#endif