10#ifndef ARK_COMPILER_INTERMEDIATEREPRESENTATION_IROPTIMIZER_HPP
11#define ARK_COMPILER_INTERMEDIATEREPRESENTATION_IROPTIMIZER_HPP
47 void process(
const std::vector<IR::Block>& pages,
const std::vector<std::string>& symbols,
const std::vector<ValTableElem>& values);
54 [[nodiscard]]
const std::vector<IR::Block>& intermediateRepresentation()
const noexcept;
67 constexpr static auto default_cond = [](
const Entities) {
72 expected(std::move(input)), condition(std::move(cond))
74 createReplacement = [replacement](
const Entities e) {
75 return IR::Entity(replacement, e[0].primaryArg(), e[1].primaryArg());
80 expected(std::move(input)), condition(std::move(cond)), createReplacement(std::move(repl))
84 expected(std::move(input)), condition(default_cond), createReplacement(std::move(repl))
91 std::vector<IR::Block>
m_ir;
95 [[nodiscard]]
bool match(
const std::vector<Instruction>& expected_insts, std::span<const IR::Entity> entities)
const;
96 [[nodiscard]]
bool canBeOptimizedSafely(std::span<const IR::Entity> entities, std::size_t window_size)
const;
97 std::optional<EntityWithOffset> replaceWithRules(
const std::vector<Rule>& rules, std::span<const IR::Entity> entities);
99 [[nodiscard]]
bool isPositiveNumberInlinable(uint16_t
id)
const;
100 [[nodiscard]] uint16_t numberAsArg(uint16_t
id)
const;
An entity in the IR is a bundle of information.
The basic value type handled by the compiler.
std::vector< ValTableElem > m_values
std::vector< IR::Block > m_ir
std::span< const IR::Entity > Entities
std::function< bool(const Entities)> Condition_t
std::vector< Rule > m_ruleset
std::function< IR::Entity(const Entities)> Replacement_t
std::vector< std::string > m_symbols
Instruction
The different bytecodes are stored here.
Condition_t condition
Additional condition to match.
Rule(std::vector< Instruction > &&input, Replacement_t &&repl)
Rule(std::vector< Instruction > &&input, Instruction replacement, Condition_t &&cond=default_cond)
Replacement_t createReplacement
Create the replacement instructions from given context.
Rule(std::vector< Instruction > &&input, Condition_t &&cond, Replacement_t &&repl)
std::vector< Instruction > expected