#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