#ifndef GOOSE_LLR_CFG_H
#define GOOSE_LLR_CFG_H
namespace goose::llr
{
class BasicBlock;
class CFG
{
public:
CFG();
bool isPoisoned() const { return m_poisoned; }
void poison() { m_poisoned = true; }
const auto& entryBB() const { return m_basicBlocks.front(); }
const auto& lastBB() const { return m_basicBlocks.back(); }
const auto& currentBB() const { return m_currentBB; }
template< typename T >
void setCurrentBB( T&& pBB )
{
m_currentBB = forward< T >( pBB );
}
const auto& getBB( uint32_t index ) { return m_basicBlocks[index]; }
auto count() const { return m_basicBlocks.size(); }
auto uniqueId() const { return m_uniqueId; }
const ptr< llr::BasicBlock >& createBB();
auto getNewTemporaryIndex() { return m_temporariesCount++; }
// Clear the llvm basic block pointers from the entire cfg.
void unbindFromLLVM();
bool canBeExecuted() const;
bool canBeEagerlyEvaluated() const;
template< typename F >
void ForEachBB( F&& func )
{
for( auto&& bb : m_basicBlocks )
func( bb );
}
private:
vector< ptr< BasicBlock > > m_basicBlocks;
ptr< BasicBlock > m_currentBB;
// The unique identifier of this CFG.
uint32_t m_uniqueId = ms_nextUniqueId++;
// The number of temporary indices used by this CFG.
uint32_t m_temporariesCount = 0;
bool m_poisoned = false;
static uint32_t ms_nextUniqueId;
};
}
#endif