PandA-2024.02
|
#include <loops.hpp>
Public Member Functions | |
Loops (const FunctionBehaviorRef FB, const ParameterConstRef parameter) | |
The constructor builds the loop forest for the given method. More... | |
size_t | NumLoops () const |
Returns the number of loops. More... | |
const std::list< LoopConstRef > & | GetList () const |
Returns the list of loops (const) More... | |
const std::list< LoopRef > & | GetModifiableList () const |
Return the list of loops. More... | |
const LoopConstRef | CGetLoop (unsigned int id) const |
Returns a loop given the id. More... | |
const LoopRef | GetLoop (unsigned int id) |
Returns a loop given the id. More... | |
void | WriteDot (const std::string &file_name) const |
Write dot files representing the loop forest. More... | |
Private Types | |
using | vertex_pair = std::pair< vertex, vertex > |
Private Member Functions | |
bool | is_edge_in_list (CustomUnorderedSet< vertex_pair > &l, vertex source, vertex target) |
Loops ()=delete | |
void | DetectLoops () |
Computes the loops of the control flow graph. More... | |
void | DetectReducibleLoop (const BBGraphRef djg, CustomOrderedSet< vertex > &visited, LoopRef loop, vertex node, vertex header) |
Reducible loop construction. More... | |
void | DetectIrreducibleLoop (const BBGraphRef djg, unsigned int min_level, unsigned int max_level, std::vector< std::list< vertex >> &level_vertices_rel) |
void | tarjan_scc (const BBGraphRef djg, vertex v, CustomUnorderedMap< vertex, unsigned int > &dfs_order, CustomUnorderedMap< vertex, unsigned int > &lowlink, std::list< vertex > &s, CustomOrderedSet< vertex > &u, unsigned int &max_dfs) |
bool | stack_contains (std::list< vertex > stack, vertex v) |
void | BuildZeroLoop () |
Creates Loop zero data structure. More... | |
void | computeDepth (const LoopConstRef loop) |
Sets depth for each loop in the forest starting from loop. More... | |
Private Attributes | |
const FunctionBehaviorRef | FB |
The function behavior. More... | |
const ParameterConstRef | Param |
class containing all the parameters More... | |
int | debug_level |
Debug level. More... | |
CustomUnorderedMap< vertex, LoopRef > | block_to_loop |
Maps between basic block and loop to which it belongs. More... | |
std::list< LoopRef > | modifiable_loops_list |
List of found loops. More... | |
std::list< LoopConstRef > | const_loops_list |
|
private |
|
privatedelete |
Loops::Loops | ( | const FunctionBehaviorRef | FB, |
const ParameterConstRef | parameter | ||
) |
The constructor builds the loop forest for the given method.
FB | is the function behavior of the control flow graph to be analyzed |
parameter | is the set of input parameters |
Detect loops
Build Zero Loop
compute depth
compute landing pads
Definition at line 184 of file loops.cpp.
References BuildZeroLoop(), computeDepth(), DetectLoops(), GetLoop(), and modifiable_loops_list.
|
private |
Creates Loop zero data structure.
Putting all the basic blocks in blocks
Definition at line 754 of file loops.cpp.
References FunctionBehavior::BB, Loop::blocks, BBGraph::CGetBBGraphInfo(), Loop::children, const_loops_list, FB, Loop::is_innermost_loop, and modifiable_loops_list.
Referenced by Loops().
const LoopConstRef Loops::CGetLoop | ( | unsigned int | id | ) | const |
Returns a loop given the id.
id | is the id of the loop |
Definition at line 632 of file loops.cpp.
References const_loops_list, and THROW_UNREACHABLE.
|
private |
Sets depth for each loop in the forest starting from loop.
loop | is the root of the loop forest |
Definition at line 742 of file loops.cpp.
References test_panda::children, and Loop::depth.
Referenced by Loops().
|
private |
Populate u with all the non-visited node whose level is >= min_level
Definition at line 464 of file loops.cpp.
References FunctionBehavior::BB, BBGraph::CGetBBNodeInfo(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FB, INDENT_DBG_MEX, level, PRINT_DBG_MEX, STR, tarjan_scc(), and THROW_ASSERT.
Referenced by DetectLoops().
|
private |
Computes the loops of the control flow graph.
Retrieve dominator tree and dominance relation
Create the DJ graph. This is done in two steps: 1) build the dominator tree 2) add the "J" edges
Add J edges (and detect CJ ones) D edges are already there since we use boost filtered graphs
Check for CJ and BJ edges
This is a BJ edge, and we mark it as such
This is a CJ edge, and we mark it as such
Build the spanning tree and detect the sp-back edges
spanning tree ancestor data structure
initialization
spanning tree construction and vertex labeling
compute the level_vertices_rel
Detect the sp-back edges
This is a sp-back edge
Detect this Loop (n is the header)
Identify SCCs for the subgraphs induced by nodes at level greater or equal than lev
Definition at line 216 of file loops.cpp.
References block_to_loop, BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), check_ancestor(), const_loops_list, debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, DetectIrreducibleLoop(), DetectReducibleLoop(), FunctionBehavior::DJ, edges, FB, FunctionBehavior::FBB, BehavioralHelper::get_function_name(), dominance< GraphObj >::get_immediate_dominator(), dominance< GraphObj >::getAllDominated(), index, is_edge_in_list(), J_SELECTOR, modifiable_loops_list, Param, PRINT_DBG_MEX, lenet_tvm::target, THROW_ASSERT, and BBGraph::WriteDot().
Referenced by Loops().
|
private |
Reducible loop construction.
djg | is the DJ graph |
visited | is the set of vertex visited |
loop | is the current loop |
node | is current vertex |
header | is the entry of the reducible loop |
Definition at line 421 of file loops.cpp.
References Loop::add_block(), Loop::AddChild(), block_to_loop, Loop::Parent(), and Loop::SetParent().
Referenced by DetectLoops().
const std::list< LoopConstRef > & Loops::GetList | ( | ) | const |
Returns the list of loops (const)
return | the const list of loops |
Definition at line 622 of file loops.cpp.
References const_loops_list.
const LoopRef Loops::GetLoop | ( | unsigned int | id | ) |
Returns a loop given the id.
id | is the id of the loop |
Definition at line 647 of file loops.cpp.
References modifiable_loops_list, and THROW_UNREACHABLE.
Referenced by Loops().
const std::list< LoopRef > & Loops::GetModifiableList | ( | ) | const |
Return the list of loops.
return | the const list of loops |
Definition at line 627 of file loops.cpp.
References modifiable_loops_list.
|
private |
Definition at line 203 of file loops.cpp.
Referenced by DetectLoops().
size_t Loops::NumLoops | ( | ) | const |
Definition at line 502 of file loops.cpp.
Referenced by tarjan_scc().
|
private |
Definition at line 518 of file loops.cpp.
References Loop::add_block(), Loop::AddChild(), block_to_loop, BBGraph::CGetBBNodeInfo(), const_loops_list, debug_level, DEBUG_LEVEL_VERY_PEDANTIC, Loop::GetId(), INDENT_DBG_MEX, modifiable_loops_list, stack_contains(), STR, and lenet_tvm::target.
Referenced by DetectIrreducibleLoop().
void Loops::WriteDot | ( | const std::string & | file_name | ) | const |
Write dot files representing the loop forest.
file_name | is the file name to be produced |
profiling_information | is the profiling information used to print data about loop iterations |
Definition at line 667 of file loops.cpp.
References FunctionBehavior::BB, BBGraph::CGetBBNodeInfo(), const_loops_list, COUNTABLE_LOOP, DO_WHILE_LOOP, DOALL_LOOP, FB, FOR_LOOP, Param, PIPELINABLE_LOOP, SINGLE_EXIT_LOOP, STR, UNKNOWN_LOOP, and WHILE_LOOP.
|
private |
Maps between basic block and loop to which it belongs.
Definition at line 103 of file loops.hpp.
Referenced by DetectLoops(), DetectReducibleLoop(), and tarjan_scc().
|
private |
Definition at line 107 of file loops.hpp.
Referenced by BuildZeroLoop(), CGetLoop(), DetectLoops(), GetList(), NumLoops(), tarjan_scc(), and WriteDot().
|
private |
Debug level.
Definition at line 100 of file loops.hpp.
Referenced by DetectIrreducibleLoop(), DetectLoops(), and tarjan_scc().
|
private |
The function behavior.
Definition at line 94 of file loops.hpp.
Referenced by BuildZeroLoop(), DetectIrreducibleLoop(), DetectLoops(), and WriteDot().
|
private |
List of found loops.
Definition at line 106 of file loops.hpp.
Referenced by BuildZeroLoop(), DetectLoops(), GetLoop(), GetModifiableList(), Loops(), and tarjan_scc().
|
private |
class containing all the parameters
Definition at line 97 of file loops.hpp.
Referenced by DetectLoops(), and WriteDot().