ArkScript
A small, lisp-inspired, functional scripting language
Ark::internal::IRInliner Class Referencefinal

#include <IRInliner.hpp>

Inheritance diagram for Ark::internal::IRInliner:
[legend]
Collaboration diagram for Ark::internal::IRInliner:
[legend]

Public Member Functions

 IRInliner (unsigned debug)
 Create a new IRInliner.
 
void process (const std::vector< IR::Block > &pages, const std::vector< std::string > &symbols, const std::vector< ValTableElem > &values, IR::label_t last_label)
 Attempt to inline IR blocks to avoid function calls when possible.
 
const std::vector< IR::Block > & intermediateRepresentation () const noexcept
 Return the IR blocks (one per scope)
 
- Public Member Functions inherited from Ark::internal::Pass
 Pass (std::string name, unsigned debug_level)
 Construct a new Pass object.
 
virtual ~Pass ()=default
 
void configureLogger (std::ostream &os)
 Set a custom output stream for the logger.
 

Private Types

enum class  CallKind { Symbol , Constant }
 

Private Member Functions

std::optional< BlockInfoblockToInlineInCall (CallKind kind, const std::vector< IR::Block > &pages, std::optional< uint16_t > maybe_id, const IR::Block &current, std::size_t argc) const noexcept
 See if a block can be inlined in the current call site.
 
void inlineBlock (const IR::Block &inlinee, IR::Block &destination)
 Perform the inlining.
 
void extractPagesMetadata (const std::vector< IR::Block > &pages)
 Extract metadata from the IR entities pages, to have a name, constant id, and potentially symbol id per page.
 
std::optional< BlockInfofindBlockBy (CallKind kind, uint16_t id) const noexcept
 Search for a block by one of its IDs.
 

Static Private Member Functions

static bool canBeInlined (const IR::Block &candidate, const IR::Block &source, std::size_t argc) noexcept
 Check if a block can be inlined in another one.
 
static std::optional< IR::EntityisBuiltinProxy (const IR::Block &block)
 Check if an IR block represents a builtin proxy, and return its CALL instruction if it is.
 

Private Attributes

std::vector< IR::Blockm_ir
 
std::vector< std::string > m_symbols
 
std::vector< ValTableElemm_values
 
std::vector< BlockInfom_funcs
 
std::unordered_map< long, SymbolDatam_symbols_data
 
IR::label_t m_current_label
 

Additional Inherited Members

- Protected Attributes inherited from Ark::internal::Pass
Logger m_logger
 

Detailed Description

Definition at line 40 of file IRInliner.hpp.

Member Enumeration Documentation

◆ CallKind

enum class Ark::internal::IRInliner::CallKind
strongprivate
Enumerator
Symbol 
Constant 

Definition at line 75 of file IRInliner.hpp.

Constructor & Destructor Documentation

◆ IRInliner()

Ark::internal::IRInliner::IRInliner ( unsigned debug)
explicit

Create a new IRInliner.

Parameters
debugdebug level

Definition at line 9 of file IRInliner.cpp.

Member Function Documentation

◆ blockToInlineInCall()

std::optional< BlockInfo > Ark::internal::IRInliner::blockToInlineInCall ( CallKind kind,
const std::vector< IR::Block > & pages,
std::optional< uint16_t > maybe_id,
const IR::Block & current,
std::size_t argc ) const
nodiscardprivatenoexcept

See if a block can be inlined in the current call site.

Parameters
kindkind of call instruction being used (by symbol or constant)
pages
maybe_idoptional identifier of a block (constant id or symbol id)
currentcurrent block where inlining could take place
argcargument count in source to candidate
Returns
std::optional<BlockInfo> candidate to inlining

Definition at line 102 of file IRInliner.cpp.

Referenced by process().

◆ canBeInlined()

bool Ark::internal::IRInliner::canBeInlined ( const IR::Block & candidate,
const IR::Block & source,
std::size_t argc )
staticnodiscardprivatenoexcept

Check if a block can be inlined in another one.

Parameters
candidateblock to inline
sourcewhere the inlining will take place
argcargument count in source to candidate
Returns
true if the candidate can be inlined

Definition at line 86 of file IRInliner.cpp.

References Ark::internal::IR::AnonymousBlockName, and Ark::MaxValue16Bits.

◆ extractPagesMetadata()

void Ark::internal::IRInliner::extractPagesMetadata ( const std::vector< IR::Block > & pages)
private

Extract metadata from the IR entities pages, to have a name, constant id, and potentially symbol id per page.

Parameters
pagespages of IR entities

Definition at line 258 of file IRInliner.cpp.

References Ark::internal::IR::AnonymousBlockName, Ark::internal::IR::Entity::inst(), m_funcs, m_symbols, m_symbols_data, m_values, Ark::internal::PageAddr, Ark::internal::IR::Entity::primaryArg(), Ark::internal::IR::Entity::relatedResourceId(), Ark::internal::ValTableElem::type, and Ark::internal::ValTableElem::value.

Referenced by process().

◆ findBlockBy()

std::optional< BlockInfo > Ark::internal::IRInliner::findBlockBy ( CallKind kind,
uint16_t id ) const
nodiscardprivatenoexcept

Search for a block by one of its IDs.

Parameters
kindkind of call instruction being used (by symbol or constant)
id
Returns
std::optional<BlockInfo>

Definition at line 332 of file IRInliner.cpp.

References Ark::internal::BlockInfo::constant_id, and Ark::internal::BlockInfo::symbol_id.

◆ inlineBlock()

◆ intermediateRepresentation()

const std::vector< IR::Block > & Ark::internal::IRInliner::intermediateRepresentation ( ) const
nodiscardnoexcept

Return the IR blocks (one per scope)

Returns
const std::vector<Block>&

Definition at line 81 of file IRInliner.cpp.

References m_ir.

Referenced by Ark::Welder::generateBytecode().

◆ isBuiltinProxy()

std::optional< IR::Entity > Ark::internal::IRInliner::isBuiltinProxy ( const IR::Block & block)
staticnodiscardprivate

Check if an IR block represents a builtin proxy, and return its CALL instruction if it is.

Parameters
blockIR block
Returns
std::optional<IR::Entity>

Definition at line 128 of file IRInliner.cpp.

References Ark::internal::IR::Block::data, and Ark::internal::IR::Label.

Referenced by inlineBlock().

◆ process()

void Ark::internal::IRInliner::process ( const std::vector< IR::Block > & pages,
const std::vector< std::string > & symbols,
const std::vector< ValTableElem > & values,
IR::label_t last_label )

Attempt to inline IR blocks to avoid function calls when possible.

Parameters
pageslist of lists of IR entities generated by the compiler
symbolssymbol table generated by the compiler
valuesvalue table generated by the compiler
last_labellast label generated by the AST lowerer

Definition at line 14 of file IRInliner.cpp.

References blockToInlineInCall(), Constant, Ark::internal::IR::Block::data, extractPagesMetadata(), Ark::internal::IR::Block::InitWithMetadata(), inlineBlock(), Ark::internal::IR::Label, m_current_label, m_ir, Ark::internal::Pass::m_logger, m_symbols, m_values, Symbol, Ark::internal::Logger::traceEnd(), and Ark::internal::Logger::traceStart().

Referenced by Ark::Welder::generateBytecode().

Member Data Documentation

◆ m_current_label

IR::label_t Ark::internal::IRInliner::m_current_label
private

Definition at line 73 of file IRInliner.hpp.

Referenced by inlineBlock(), and process().

◆ m_funcs

std::vector<BlockInfo> Ark::internal::IRInliner::m_funcs
private

Definition at line 71 of file IRInliner.hpp.

Referenced by extractPagesMetadata().

◆ m_ir

std::vector<IR::Block> Ark::internal::IRInliner::m_ir
private

Definition at line 68 of file IRInliner.hpp.

Referenced by intermediateRepresentation(), and process().

◆ m_symbols

std::vector<std::string> Ark::internal::IRInliner::m_symbols
private

Definition at line 69 of file IRInliner.hpp.

Referenced by extractPagesMetadata(), and process().

◆ m_symbols_data

std::unordered_map<long, SymbolData> Ark::internal::IRInliner::m_symbols_data
private

Definition at line 72 of file IRInliner.hpp.

Referenced by extractPagesMetadata().

◆ m_values

std::vector<ValTableElem> Ark::internal::IRInliner::m_values
private

Definition at line 70 of file IRInliner.hpp.

Referenced by extractPagesMetadata(), and process().


The documentation for this class was generated from the following files: