hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
IRFunctionOptimizer Class Reference

#include <IROptimizer.hpp>

Collaboration diagram for IRFunctionOptimizer:

Classes

struct  SimulationStack
 
struct  VariablesExtraInfo
 

Public Member Functions

yoi::indexT reduce (const SimulationStack::Item::ContributedInstructionSet &contributedInstructions, yoi::indexT currentIndex)
 
SimulationStack::Item add (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item sub (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item mul (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item div (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item mod (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item negate (const IRFunctionOptimizer::SimulationStack::Item &a)
 
SimulationStack::Item bitwiseNot (const IRFunctionOptimizer::SimulationStack::Item &a)
 
SimulationStack::Item bitwiseAnd (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item bitwiseOr (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item bitwiseXor (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item bitwiseShiftLeft (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item bitwiseShiftRight (const IRFunctionOptimizer::SimulationStack::Item &a, const IRFunctionOptimizer::SimulationStack::Item &b)
 
SimulationStack::Item lessThan (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
SimulationStack::Item lessThanOrEqual (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
SimulationStack::Item greaterThan (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
SimulationStack::Item greaterThanOrEqual (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
SimulationStack::Item equal (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
SimulationStack::Item notEqual (const SimulationStack::Item &item, const SimulationStack::Item &right)
 
yoi::indexT generatePushOp (const SimulationStack::Item &item, yoi::indexT index)
 
 IRFunctionOptimizer (const std::shared_ptr< compilerContext > &compilerCtx, const std::shared_ptr< IRModule > &irModule, std::map< CallGraph::FuncIdentifier, FunctionAnalysisInfo > &globalResults)
 
IRFunctionOptimizersetTargetFunction (const std::shared_ptr< IRFunctionDefinition > &targetFunction, CallGraph::FuncIdentifier funcId)
 
IRFunctionOptimizerreduceRedundantConstantExpr ()
 
IRFunctionOptimizerreduceRedundantTempVar ()
 
IRFunctionOptimizerreduceRedundantNop ()
 
IRFunctionOptimizerreduceRedundantJump ()
 
IRFunctionOptimizerreduceRedundantCodeAfterRet ()
 
IRFunctionOptimizercontrolFlowOptimization ()
 
IRFunctionOptimizerdoOptimizationForCurrentFunction ()
 
IRFunctionOptimizerreduceEmptyCodeBlock ()
 
void handleInstruction (const IR &ins, yoi::indexT insIndex, yoi::indexT currentCodeBlockIndex)
 
AnalysisState analyzeBlock (indexT blockIndex, const AnalysisState &inState)
 
void transformBlock (indexT blockIndex, const AnalysisState &inState)
 
std::pair< std::map< indexT, std::vector< indexT > >, std::map< indexT, std::vector< indexT > > > performCFGAnalysis ()
 
bool performNullableCheck ()
 
bool performRawCheck ()
 
bool performParamBorrowCheck ()
 
bool performInterfaceAllocationReduction ()
 

Public Attributes

struct yoi::IRFunctionOptimizer::SimulationStack simulationStack
 
std::map< yoi::indexT, VariablesExtraInfovariablesExtraInfo
 
CallGraph::FuncIdentifier currentFuncId
 

Private Member Functions

AnalysisState analyzeBlockForNullable (indexT blockIndex, const AnalysisState &inState)
 
AnalysisState analyzeBlockForRaw (indexT blockIndex, const AnalysisState &inState)
 
AnalysisState analyzeBlockForInterfaceAllocationReduction (indexT blockIndex, const AnalysisState &inState)
 
AnalysisState mergeStatesForNullable (const AnalysisState &s1, const AnalysisState &s2)
 
AnalysisState mergeStatesForRaw (const AnalysisState &s1, const AnalysisState &s2)
 
AnalysisState mergeStatesForInterfaceAllocationReduction (const AnalysisState &s1, const AnalysisState &s2)
 

Private Attributes

std::shared_ptr< compilerContextcompilerCtx
 
std::shared_ptr< IRModuleirModule
 
std::shared_ptr< IRFunctionDefinitiontargetFunction
 
yoi::indexT currentCodeBlockIndex
 
std::map< CallGraph::FuncIdentifier, FunctionAnalysisInfo > & globalAnalysisResults
 

Detailed Description

Definition at line 52 of file IROptimizer.hpp.

Constructor & Destructor Documentation

◆ IRFunctionOptimizer()

IRFunctionOptimizer ( const std::shared_ptr< compilerContext > &  compilerCtx,
const std::shared_ptr< IRModule > &  irModule,
std::map< CallGraph::FuncIdentifier, FunctionAnalysisInfo > &  globalResults 
)

Definition at line 553 of file IROptimizer.cpp.

Member Function Documentation

◆ add()

◆ analyzeBlock()

◆ analyzeBlockForInterfaceAllocationReduction()

◆ analyzeBlockForNullable()

AnalysisState analyzeBlockForNullable ( indexT  blockIndex,
const AnalysisState inState 
)
private

Definition at line 2374 of file IROptimizer.cpp.

References IR::add, IR::array_length, IR::basic_cast_bool, IR::basic_cast_char, IR::basic_cast_deci, IR::basic_cast_int, IR::bitwise_and, IR::bitwise_not, IR::bitwise_or, IR::bitwise_xor, IRFunctionOptimizer::compilerCtx, IRFunctionOptimizer::currentCodeBlockIndex, IRFunctionOptimizer::currentFuncId, IR::direct_assign, IR::div, IR::dyn_cast_any, IR::equal, IRFunctionOptimizer::globalAnalysisResults, IR::greater_equal, IR::greater_than, IRFunctionOptimizer::handleInstruction(), IR::interfaceof, IRFunctionDefinition::Intrinsic, IR::invoke, IR::invoke_dangling, IR::invoke_imported, IR::invoke_virtual, IRFunctionOptimizer::SimulationStack::items, IR::jump, IR::left_shift, IR::less_equal, IR::less_than, IR::load_element, IR::load_global, IR::load_local, IR::load_member, yoi::managedPtr(), IR::mod, IR::mul, IR::negate, IRFunctionDefinition::NoFFI, IRValueType::none, IR::nop, IR::not_equal, IRValueType::null, IRValueType::Nullable, FunctionAnalysisInfo::Nullable, IRFunctionOptimizer::SimulationStack::peek(), IR::pointer_cast, IRValueType::pointerObject, IRFunctionOptimizer::SimulationStack::pop(), IRFunctionOptimizer::SimulationStack::push(), IR::push_boolean, IR::push_character, IR::push_decimal, IR::push_integer, IR::push_null, IR::push_short, IR::push_string, IR::push_unsigned, FunctionAnalysisInfo::Raw, IR::resume, IR::ret, IR::ret_none, IR::right_shift, IRFunctionOptimizer::simulationStack, AnalysisState::stack, IR::store_element, IR::store_global, IR::store_local, IR::store_member, IR::sub, IRFunctionOptimizer::targetFunction, IRFunctionOptimizer::variablesExtraInfo, AnalysisState::variableStates, yoi::warning(), yoi::wstring2string(), IR::yield, and IR::yield_none.

Referenced by IRFunctionOptimizer::performNullableCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ analyzeBlockForRaw()

AnalysisState analyzeBlockForRaw ( indexT  blockIndex,
const AnalysisState inState 
)
private

Definition at line 2875 of file IROptimizer.cpp.

References IR::add, IR::basic_cast_bool, IR::basic_cast_char, IR::basic_cast_deci, IR::basic_cast_int, IR::basic_cast_short, IR::basic_cast_unsigned, IR::bind_elements_post, IR::bind_elements_pred, IR::bitwise_and, IR::bitwise_or, IR::bitwise_xor, IRFunctionOptimizer::compilerCtx, IRFunctionOptimizer::currentCodeBlockIndex, IRFunctionOptimizer::currentFuncId, IRValueType::datastructObject, IR::direct_assign, IR::div, IR::equal, IRFunctionOptimizer::equal(), IRValueType::getBasicRawType(), IRFunctionOptimizer::globalAnalysisResults, IR::greater_equal, IR::greater_than, IRFunctionOptimizer::greaterThan(), IRFunctionOptimizer::greaterThanOrEqual(), IRFunctionOptimizer::handleInstruction(), IR::interfaceof, IRFunctionDefinition::Intrinsic, IR::invoke, IR::invoke_dangling, IR::invoke_imported, IR::invoke_virtual, IR::left_shift, IR::less_equal, IR::less_than, IRFunctionOptimizer::lessThan(), IR::load_element, IR::load_field, IR::load_local, yoi::managedPtr(), IR::mod, IR::mul, IR::new_datastruct, IRFunctionDefinition::NoFFI, IR::not_equal, IRFunctionOptimizer::notEqual(), IRValueType::null, yoi::panic(), IRFunctionOptimizer::SimulationStack::peek(), IRFunctionOptimizer::SimulationStack::pop(), IRFunctionOptimizer::SimulationStack::push(), IR::push_boolean, IR::push_character, IR::push_decimal, IR::push_integer, IR::push_null, IR::push_short, IR::push_string, IR::push_unsigned, IRValueType::Raw, IR::resume, IR::ret, IR::ret_none, IR::right_shift, IRFunctionOptimizer::simulationStack, AnalysisState::stack, IR::store_element, IR::store_field, IR::store_local, IR::sub, IRFunctionOptimizer::targetFunction, IRFunctionOptimizer::SimulationStack::Item::type, IRFunctionOptimizer::variablesExtraInfo, AnalysisState::variableStates, IR::yield, and IR::yield_none.

Referenced by IRFunctionOptimizer::performRawCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bitwiseAnd()

◆ bitwiseNot()

◆ bitwiseOr()

◆ bitwiseShiftLeft()

◆ bitwiseShiftRight()

◆ bitwiseXor()

◆ controlFlowOptimization()

◆ div()

◆ doOptimizationForCurrentFunction()

◆ equal()

◆ generatePushOp()

yoi::indexT generatePushOp ( const SimulationStack::Item item,
yoi::indexT  index 
)

Generate push constant operation for the given value.

Parameters
itemThe value to be pushed.
indexThe index of the instruction to be inserted.
Returns
The index of the next instruction to be inserted.

Definition at line 497 of file IROptimizer.cpp.

References IRFunctionOptimizer::currentCodeBlockIndex, IR::debugInfo, IRFunctionOptimizer::SimulationStack::Item::ContributedInstructionSet::insert(), IRValueType::integerObject, IRFunctionOptimizer::targetFunction, IRFunctionOptimizer::SimulationStack::Item::type, and IRValueType::unsignedObject.

Here is the call graph for this function:

◆ greaterThan()

◆ greaterThanOrEqual()

◆ handleInstruction()

void handleInstruction ( const IR ins,
yoi::indexT  insIndex,
yoi::indexT  currentCodeBlockIndex 
)

◆ lessThan()

◆ lessThanOrEqual()

◆ mergeStatesForInterfaceAllocationReduction()

AnalysisState mergeStatesForInterfaceAllocationReduction ( const AnalysisState s1,
const AnalysisState s2 
)
private

◆ mergeStatesForNullable()

AnalysisState mergeStatesForNullable ( const AnalysisState s1,
const AnalysisState s2 
)
private

Definition at line 2709 of file IROptimizer.cpp.

References IRFunctionOptimizer::SimulationStack::items, IRValueType::Nullable, yoi::panic(), IRFunctionOptimizer::SimulationStack::push(), AnalysisState::stack, and AnalysisState::variableStates.

Referenced by IRFunctionOptimizer::performNullableCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mergeStatesForRaw()

AnalysisState mergeStatesForRaw ( const AnalysisState s1,
const AnalysisState s2 
)
private

Definition at line 3349 of file IROptimizer.cpp.

References IRFunctionOptimizer::SimulationStack::items, yoi::panic(), IRFunctionOptimizer::SimulationStack::push(), IRValueType::Raw, AnalysisState::stack, and AnalysisState::variableStates.

Referenced by IRFunctionOptimizer::performRawCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mod()

◆ mul()

◆ negate()

◆ notEqual()

◆ performCFGAnalysis()

std::pair< std::map< indexT, std::vector< indexT > >, std::map< indexT, std::vector< indexT > > > performCFGAnalysis ( )

◆ performInterfaceAllocationReduction()

bool performInterfaceAllocationReduction ( )

Definition at line 4429 of file IROptimizer.cpp.

References AnalysisState::variableStates.

Referenced by IRFunctionOptimizer::doOptimizationForCurrentFunction().

Here is the caller graph for this function:

◆ performNullableCheck()

◆ performParamBorrowCheck()

bool performParamBorrowCheck ( )

Definition at line 4409 of file IROptimizer.cpp.

References IRValueType::Borrow, yoi::managedPtr(), IRValueType::NoBorrow, IRValueType::Raw, and IRFunctionDefinition::Variadic.

Referenced by IRFunctionOptimizer::doOptimizationForCurrentFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ performRawCheck()

◆ reduce()

yoi::indexT reduce ( const SimulationStack::Item::ContributedInstructionSet contributedInstructions,
yoi::indexT  currentIndex 
)

Reduce the given set of instructions by removing redundant instructions.

Parameters
contributedInstructionsThe set of instructions to be reduced.
currentIndexThe current index of the instruction being processed.
Returns
The index of the next instruction to be processed.

Definition at line 106 of file IROptimizer.cpp.

References IRFunctionOptimizer::SimulationStack::Item::ContributedInstructionSet::codeBlockIndex, IRFunctionOptimizer::SimulationStack::Item::contributedInstructions, IR::nop, IRFunctionOptimizer::SimulationStack::Item::ContributedInstructionSet::optimizable, and IRFunctionOptimizer::targetFunction.

Referenced by IRFunctionOptimizer::reduceRedundantTempVar().

Here is the caller graph for this function:

◆ reduceEmptyCodeBlock()

IRFunctionOptimizer & reduceEmptyCodeBlock ( )

Definition at line 2051 of file IROptimizer.cpp.

References IR::jump, IR::jump_if_false, IR::jump_if_true, IR::nop, IRFunctionOptimizer::targetFunction, yoi::warning(), and yoi::wstring2string().

Referenced by IRFunctionOptimizer::doOptimizationForCurrentFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduceRedundantCodeAfterRet()

IRFunctionOptimizer & reduceRedundantCodeAfterRet ( )

Definition at line 1856 of file IROptimizer.cpp.

References IRFunctionOptimizer::currentCodeBlockIndex, and IRFunctionOptimizer::targetFunction.

Referenced by IRFunctionOptimizer::transformBlock().

Here is the caller graph for this function:

◆ reduceRedundantConstantExpr()

◆ reduceRedundantJump()

IRFunctionOptimizer & reduceRedundantJump ( )

Definition at line 1838 of file IROptimizer.cpp.

References IR::jump, and IRFunctionOptimizer::targetFunction.

Referenced by IRFunctionOptimizer::doOptimizationForCurrentFunction().

Here is the caller graph for this function:

◆ reduceRedundantNop()

IRFunctionOptimizer & reduceRedundantNop ( )

Definition at line 1830 of file IROptimizer.cpp.

References IR::nop, IR::opcode, and IRFunctionOptimizer::targetFunction.

Referenced by IRFunctionOptimizer::doOptimizationForCurrentFunction().

Here is the caller graph for this function:

◆ reduceRedundantTempVar()

IRFunctionOptimizer & reduceRedundantTempVar ( )

Definition at line 1823 of file IROptimizer.cpp.

References IRFunctionOptimizer::SimulationStack::items, IRFunctionOptimizer::reduce(), and IRFunctionOptimizer::simulationStack.

Here is the call graph for this function:

◆ setTargetFunction()

IRFunctionOptimizer & setTargetFunction ( const std::shared_ptr< IRFunctionDefinition > &  targetFunction,
CallGraph::FuncIdentifier  funcId 
)

Definition at line 558 of file IROptimizer.cpp.

References IRFunctionOptimizer::currentCodeBlockIndex, IRFunctionOptimizer::currentFuncId, and IRFunctionOptimizer::targetFunction.

Referenced by IROptimizer::performBaseOptimization().

Here is the caller graph for this function:

◆ sub()

◆ transformBlock()

Member Data Documentation

◆ compilerCtx

◆ currentCodeBlockIndex

◆ currentFuncId

◆ globalAnalysisResults

◆ irModule

std::shared_ptr<IRModule> irModule
private

Definition at line 54 of file IROptimizer.hpp.

◆ simulationStack

◆ targetFunction

◆ variablesExtraInfo


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