2024-10-20 19:14:34 +02:00
<!DOCTYPE html>
< html class = "writer-html5" lang = "en" >
< head >
< meta charset = "utf-8" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" / >
< title > Lib.Dominators — MiniC documentation< / title >
< link rel = "stylesheet" href = "../../_static/pygments.css" type = "text/css" / >
< link rel = "stylesheet" href = "../../_static/css/theme.css" type = "text/css" / >
<!-- [if lt IE 9]>
< script src = "../../_static/js/html5shiv.min.js" > < / script >
<![endif]-->
< script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" > < / script >
< script data-url_root = "../../" id = "documentation_options" src = "../../_static/documentation_options.js" > < / script >
< script src = "../../_static/doctools.js" > < / script >
< script src = "../../_static/sphinx_highlight.js" > < / script >
< script src = "../../_static/js/theme.js" > < / script >
< link rel = "index" title = "Index" href = "../../genindex.html" / >
< link rel = "search" title = "Search" href = "../../search.html" / >
< / head >
< body class = "wy-body-for-nav" >
< div class = "wy-grid-for-nav" >
< nav data-toggle = "wy-nav-shift" class = "wy-nav-side" >
< div class = "wy-side-scroll" >
< div class = "wy-side-nav-search" >
< a href = "../../index.html" class = "icon icon-home" >
MiniC
< / a >
< div role = "search" >
< form id = "rtd-search-form" class = "wy-form" action = "../../search.html" method = "get" >
< input type = "text" name = "q" placeholder = "Search docs" aria-label = "Search docs" / >
< input type = "hidden" name = "check_keywords" value = "yes" / >
< input type = "hidden" name = "area" value = "default" / >
< / form >
< / div >
< / div > < div class = "wy-menu wy-menu-vertical" data-spy = "affix" role = "navigation" aria-label = "Navigation menu" >
< p class = "caption" role = "heading" > < span class = "caption-text" > Contents:< / span > < / p >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Errors.html" > Base library - Errors< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Statement.html" > Base library - Statement< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.RiscV.html" > Base library - RISC-V instructions< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Operands.html" > Base library - Operands< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.FunctionData.html" > Base library - Function data< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Graphes.html" > Base library - Graphs< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.LinearCode.html" > Linear intermediate representation< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Allocator.html" > Temporary allocation< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.CFG.html" > Control Flow Graph - CFG and Basic blocks< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Terminator.html" > Control Flow Graph - Terminators< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.Dominators.html" > SSA form - Dominance frontier< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "../../api/Lib.PhiNode.html" > SSA form - Phi Nodes< / a > < / li >
< / ul >
< / div >
< / div >
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" > < nav class = "wy-nav-top" aria-label = "Mobile navigation menu" >
< i data-toggle = "wy-nav-top" class = "fa fa-bars" > < / i >
< a href = "../../index.html" > MiniC< / a >
< / nav >
< div class = "wy-nav-content" >
< div class = "rst-content" >
< div role = "navigation" aria-label = "Page navigation" >
< ul class = "wy-breadcrumbs" >
< li > < a href = "../../index.html" class = "icon icon-home" aria-label = "Home" > < / a > < / li >
< li class = "breadcrumb-item" > < a href = "../index.html" > Module code< / a > < / li >
< li class = "breadcrumb-item active" > Lib.Dominators< / li >
< li class = "wy-breadcrumbs-aside" >
< / li >
< / ul >
< hr / >
< / div >
< div role = "main" class = "document" itemscope = "itemscope" itemtype = "http://schema.org/Article" >
< div itemprop = "articleBody" >
< h1 > Source code for Lib.Dominators< / h1 > < div class = "highlight" > < pre >
< span > < / span > < span class = "sd" > " " " < / span >
< span class = "sd" > Utility functions to work with dominators in a :py:class:`CFG < Lib.CFG.CFG> `.< / span >
< span class = "sd" > Do not hesitate to look at the source of the functions< / span >
< span class = "sd" > to get a better understanding of the algorithms.< / span >
< span class = "sd" > " " " < / span >
< span class = "kn" > from< / span > < span class = "nn" > typing< / span > < span class = "kn" > import< / span > < span class = "n" > Dict< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span >
< span class = "kn" > from< / span > < span class = "nn" > graphviz< / span > < span class = "kn" > import< / span > < span class = "n" > Digraph< / span >
< span class = "kn" > from< / span > < span class = "nn" > Lib.CFG< / span > < span class = "kn" > import< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > CFG< / span >
< div class = "viewcode-block" id = "computeDom" > < a class = "viewcode-back" href = "../../api/Lib.Dominators.html#Lib.Dominators.computeDom" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > computeDom< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "p" > :< / span > < span class = "n" > CFG< / span > < span class = "p" > )< / span > < span class = "o" > -> < / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]:< / span >
2024-11-04 13:43:55 +01:00
< span class = "sd" > " " " < / span >
2024-10-20 19:14:34 +02:00
< span class = "sd" > `computeDom(cfg)` computes the table associating blocks to their< / span >
< span class = "sd" > dominators in `cfg`.< / span >
< span class = "sd" > It works by solving the equation system.< / span >
< span class = "sd" > This is an helper function called during SSA entry.< / span >
< span class = "sd" > " " " < / span >
< span class = "n" > all_blocks< / span > < span class = "p" > :< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "nb" > set< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > get_blocks< / span > < span class = "p" > ())< / span >
< span class = "n" > dominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]< / span > < span class = "o" > =< / span > < span class = "nb" > dict< / span > < span class = "p" > ()< / span >
< span class = "k" > for< / span > < span class = "n" > b< / span > < span class = "ow" > in< / span > < span class = "n" > all_blocks< / span > < span class = "p" > :< / span >
< span class = "k" > if< / span > < span class = "n" > b< / span > < span class = "o" > .< / span > < span class = "n" > get_in< / span > < span class = "p" > ():< / span > < span class = "c1" > # If b has some predecessor< / span >
< span class = "n" > dominators< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "n" > all_blocks< / span >
< span class = "k" > else< / span > < span class = "p" > :< / span > < span class = "c1" > # If b has no predecessors< / span >
< span class = "n" > dominators< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "p" > {< / span > < span class = "n" > b< / span > < span class = "p" > }< / span >
< span class = "n" > new_dominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]< / span > < span class = "o" > =< / span > < span class = "nb" > dict< / span > < span class = "p" > ()< / span >
< span class = "k" > while< / span > < span class = "kc" > True< / span > < span class = "p" > :< / span >
< span class = "k" > for< / span > < span class = "n" > b< / span > < span class = "ow" > in< / span > < span class = "n" > all_blocks< / span > < span class = "p" > :< / span >
< span class = "k" > if< / span > < span class = "n" > b< / span > < span class = "o" > .< / span > < span class = "n" > get_in< / span > < span class = "p" > ():< / span >
< span class = "n" > dom_preds< / span > < span class = "o" > =< / span > < span class = "p" > [< / span > < span class = "n" > dominators< / span > < span class = "p" > [< / span > < span class = "n" > b2< / span > < span class = "p" > ]< / span > < span class = "k" > for< / span > < span class = "n" > b2< / span > < span class = "ow" > in< / span > < span class = "n" > b< / span > < span class = "o" > .< / span > < span class = "n" > get_in< / span > < span class = "p" > ()]< / span >
< span class = "n" > new_dominators< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "p" > {< / span > < span class = "n" > b< / span > < span class = "p" > }< / span > < span class = "o" > .< / span > < span class = "n" > union< / span > < span class = "p" > (< / span > < span class = "nb" > set< / span > < span class = "o" > .< / span > < span class = "n" > intersection< / span > < span class = "p" > (< / span > < span class = "o" > *< / span > < span class = "n" > dom_preds< / span > < span class = "p" > ))< / span >
< span class = "k" > else< / span > < span class = "p" > :< / span >
< span class = "n" > new_dominators< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "p" > {< / span > < span class = "n" > b< / span > < span class = "p" > }< / span >
< span class = "k" > if< / span > < span class = "n" > dominators< / span > < span class = "o" > ==< / span > < span class = "n" > new_dominators< / span > < span class = "p" > :< / span >
< span class = "k" > break< / span >
< span class = "k" > else< / span > < span class = "p" > :< / span >
< span class = "n" > dominators< / span > < span class = "o" > =< / span > < span class = "n" > new_dominators< / span >
< span class = "n" > new_dominators< / span > < span class = "o" > =< / span > < span class = "nb" > dict< / span > < span class = "p" > ()< / span >
< span class = "k" > return< / span > < span class = "n" > dominators< / span > < / div >
< div class = "viewcode-block" id = "printDT" > < a class = "viewcode-back" href = "../../api/Lib.Dominators.html#Lib.Dominators.printDT" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > printDT< / span > < span class = "p" > (< / span > < span class = "n" > filename< / span > < span class = "p" > :< / span > < span class = "nb" > str< / span > < span class = "p" > ,< / span > < span class = "n" > graph< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]])< / span > < span class = "o" > -> < / span > < span class = "kc" > None< / span > < span class = "p" > :< / span > < span class = "c1" > # pragma: no cover< / span >
2024-11-04 13:43:55 +01:00
< span class = "sd" > " " " Display a graphical rendering of the given domination tree." " " < / span >
2024-10-20 19:14:34 +02:00
< span class = "n" > dot< / span > < span class = "o" > =< / span > < span class = "n" > Digraph< / span > < span class = "p" > ()< / span >
< span class = "k" > for< / span > < span class = "n" > k< / span > < span class = "ow" > in< / span > < span class = "n" > graph< / span > < span class = "p" > :< / span >
< span class = "n" > dot< / span > < span class = "o" > .< / span > < span class = "n" > node< / span > < span class = "p" > (< / span > < span class = "nb" > str< / span > < span class = "p" > (< / span > < span class = "n" > k< / span > < span class = "o" > .< / span > < span class = "n" > get_label< / span > < span class = "p" > ()))< / span >
< span class = "k" > for< / span > < span class = "n" > k< / span > < span class = "ow" > in< / span > < span class = "n" > graph< / span > < span class = "p" > :< / span >
< span class = "k" > for< / span > < span class = "n" > v< / span > < span class = "ow" > in< / span > < span class = "n" > graph< / span > < span class = "p" > [< / span > < span class = "n" > k< / span > < span class = "p" > ]:< / span >
< span class = "n" > dot< / span > < span class = "o" > .< / span > < span class = "n" > edge< / span > < span class = "p" > (< / span > < span class = "nb" > str< / span > < span class = "p" > (< / span > < span class = "n" > k< / span > < span class = "o" > .< / span > < span class = "n" > get_label< / span > < span class = "p" > ()),< / span > < span class = "nb" > str< / span > < span class = "p" > (< / span > < span class = "n" > v< / span > < span class = "o" > .< / span > < span class = "n" > get_label< / span > < span class = "p" > ()))< / span >
< span class = "n" > dot< / span > < span class = "o" > .< / span > < span class = "n" > render< / span > < span class = "p" > (< / span > < span class = "n" > filename< / span > < span class = "p" > ,< / span > < span class = "n" > view< / span > < span class = "o" > =< / span > < span class = "kc" > True< / span > < span class = "p" > )< / span > < / div >
< div class = "viewcode-block" id = "computeDT" > < a class = "viewcode-back" href = "../../api/Lib.Dominators.html#Lib.Dominators.computeDT" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > computeDT< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "p" > :< / span > < span class = "n" > CFG< / span > < span class = "p" > ,< / span > < span class = "n" > dominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]],< / span >
< span class = "n" > dom_graphs< / span > < span class = "p" > :< / span > < span class = "nb" > bool< / span > < span class = "p" > ,< / span > < span class = "n" > basename< / span > < span class = "p" > :< / span > < span class = "nb" > str< / span > < span class = "p" > )< / span > < span class = "o" > -> < / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]:< / span >
2024-11-04 13:43:55 +01:00
< span class = "sd" > " " " < / span >
2024-10-20 19:14:34 +02:00
< span class = "sd" > `computeDT(cfg, dominators)` computes the domination tree of `cfg`< / span >
< span class = "sd" > using the previously computed `dominators`.< / span >
< span class = "sd" > It returns `DT`, a dictionary which associates a block with its children< / span >
< span class = "sd" > in the dominator tree.< / span >
< span class = "sd" > This is an helper function called during SSA entry.< / span >
< span class = "sd" > " " " < / span >
< span class = "c1" > # First, compute the immediate dominators< / span >
< span class = "n" > idominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Block< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "p" > {}< / span >
< span class = "k" > for< / span > < span class = "n" > b< / span > < span class = "p" > ,< / span > < span class = "n" > doms< / span > < span class = "ow" > in< / span > < span class = "n" > dominators< / span > < span class = "o" > .< / span > < span class = "n" > items< / span > < span class = "p" > ():< / span >
< span class = "c1" > # The immediate dominator of b is the unique vertex n ≠ b< / span >
< span class = "c1" > # which dominates b and is dominated by all vertices in Dom(b) − b.< / span >
< span class = "n" > strict_doms< / span > < span class = "o" > =< / span > < span class = "n" > doms< / span > < span class = "o" > -< / span > < span class = "p" > {< / span > < span class = "n" > b< / span > < span class = "p" > }< / span >
< span class = "n" > idoms< / span > < span class = "o" > =< / span > < span class = "nb" > set< / span > < span class = "p" > ()< / span >
< span class = "k" > for< / span > < span class = "n" > n< / span > < span class = "ow" > in< / span > < span class = "n" > strict_doms< / span > < span class = "p" > :< / span >
< span class = "k" > if< / span > < span class = "n" > strict_doms< / span > < span class = "o" > .< / span > < span class = "n" > issubset< / span > < span class = "p" > (< / span > < span class = "n" > dominators< / span > < span class = "p" > [< / span > < span class = "n" > n< / span > < span class = "p" > ]):< / span >
< span class = "n" > idoms< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > n< / span > < span class = "p" > )< / span >
< span class = "k" > if< / span > < span class = "n" > idoms< / span > < span class = "p" > :< / span >
< span class = "k" > assert< / span > < span class = "p" > (< / span > < span class = "nb" > len< / span > < span class = "p" > (< / span > < span class = "n" > idoms< / span > < span class = "p" > )< / span > < span class = "o" > ==< / span > < span class = "mi" > 1< / span > < span class = "p" > )< / span >
< span class = "n" > idominators< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "n" > idoms< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > ()< / span >
< span class = "c1" > # Then, simply inverse the relation to obtain the domination tree< / span >
< span class = "n" > DT< / span > < span class = "o" > =< / span > < span class = "p" > {< / span > < span class = "n" > b< / span > < span class = "p" > :< / span > < span class = "nb" > set< / span > < span class = "p" > ()< / span > < span class = "k" > for< / span > < span class = "n" > b< / span > < span class = "ow" > in< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > get_blocks< / span > < span class = "p" > ()}< / span >
< span class = "k" > for< / span > < span class = "n" > i< / span > < span class = "p" > ,< / span > < span class = "n" > idominator< / span > < span class = "ow" > in< / span > < span class = "n" > idominators< / span > < span class = "o" > .< / span > < span class = "n" > items< / span > < span class = "p" > ():< / span >
< span class = "n" > DT< / span > < span class = "p" > [< / span > < span class = "n" > idominator< / span > < span class = "p" > ]< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > i< / span > < span class = "p" > )< / span >
< span class = "c1" > # Print the domination tree if asked< / span >
< span class = "k" > if< / span > < span class = "n" > dom_graphs< / span > < span class = "p" > :< / span >
< span class = "n" > s< / span > < span class = "o" > =< / span > < span class = "s2" > " < / span > < span class = "si" > {}< / span > < span class = "s2" > .< / span > < span class = "si" > {}< / span > < span class = "s2" > .ssa.DT.dot" < / span > < span class = "o" > .< / span > < span class = "n" > format< / span > < span class = "p" > (< / span > < span class = "n" > basename< / span > < span class = "p" > ,< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > fdata< / span > < span class = "o" > .< / span > < span class = "n" > get_name< / span > < span class = "p" > ())< / span >
< span class = "nb" > print< / span > < span class = "p" > (< / span > < span class = "s2" > " SSA - domination tree graph:" < / span > < span class = "p" > ,< / span > < span class = "n" > s< / span > < span class = "p" > )< / span >
< span class = "n" > printDT< / span > < span class = "p" > (< / span > < span class = "n" > s< / span > < span class = "p" > ,< / span > < span class = "n" > DT< / span > < span class = "p" > )< / span >
< span class = "k" > return< / span > < span class = "n" > DT< / span > < / div >
< span class = "k" > def< / span > < span class = "nf" > _computeDF_at_block< / span > < span class = "p" > (< / span >
< span class = "n" > cfg< / span > < span class = "p" > :< / span > < span class = "n" > CFG< / span > < span class = "p" > ,< / span >
< span class = "n" > dominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]],< / span >
< span class = "n" > DT< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]],< / span >
< span class = "n" > b< / span > < span class = "p" > :< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span >
< span class = "n" > DF< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]])< / span > < span class = "o" > -> < / span > < span class = "kc" > None< / span > < span class = "p" > :< / span >
2024-11-04 13:43:55 +01:00
< span class = "sd" > " " " < / span >
2024-10-20 19:14:34 +02:00
< span class = "sd" > `_computeDF_at_block(...)` computes the dominance frontier at the given block,< / span >
< span class = "sd" > by updating `DF`.< / span >
< span class = "sd" > This is an helper function called during SSA entry.< / span >
< span class = "sd" > " " " < / span >
< span class = "n" > S< / span > < span class = "p" > :< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "p" > {< / span > < span class = "n" > succ< / span > < span class = "k" > for< / span > < span class = "n" > succ< / span > < span class = "ow" > in< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > out_blocks< / span > < span class = "p" > (< / span > < span class = "n" > b< / span > < span class = "p" > )< / span > < span class = "k" > if< / span > < span class = "n" > succ< / span > < span class = "ow" > not< / span > < span class = "ow" > in< / span > < span class = "n" > DT< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]}< / span >
< span class = "k" > for< / span > < span class = "n" > b_succ< / span > < span class = "ow" > in< / span > < span class = "n" > DT< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]:< / span >
< span class = "n" > _computeDF_at_block< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "p" > ,< / span > < span class = "n" > dominators< / span > < span class = "p" > ,< / span > < span class = "n" > DT< / span > < span class = "p" > ,< / span > < span class = "n" > b_succ< / span > < span class = "p" > ,< / span > < span class = "n" > DF< / span > < span class = "p" > )< / span >
< span class = "k" > for< / span > < span class = "n" > b_frontier< / span > < span class = "ow" > in< / span > < span class = "n" > DF< / span > < span class = "p" > [< / span > < span class = "n" > b_succ< / span > < span class = "p" > ]:< / span >
< span class = "k" > if< / span > < span class = "n" > b< / span > < span class = "ow" > not< / span > < span class = "ow" > in< / span > < span class = "p" > (< / span > < span class = "n" > dominators< / span > < span class = "p" > [< / span > < span class = "n" > b_frontier< / span > < span class = "p" > ]< / span > < span class = "o" > -< / span > < span class = "p" > {< / span > < span class = "n" > b_frontier< / span > < span class = "p" > }):< / span >
< span class = "n" > S< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > b_frontier< / span > < span class = "p" > )< / span >
< span class = "n" > DF< / span > < span class = "p" > [< / span > < span class = "n" > b< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "n" > S< / span >
< div class = "viewcode-block" id = "computeDF" > < a class = "viewcode-back" href = "../../api/Lib.Dominators.html#Lib.Dominators.computeDF" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > computeDF< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "p" > :< / span > < span class = "n" > CFG< / span > < span class = "p" > ,< / span > < span class = "n" > dominators< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]],< / span >
< span class = "n" > DT< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]],< / span > < span class = "n" > dom_graphs< / span > < span class = "p" > :< / span > < span class = "nb" > bool< / span > < span class = "p" > ,< / span > < span class = "n" > basename< / span > < span class = "p" > :< / span > < span class = "nb" > str< / span >
< span class = "p" > )< / span > < span class = "o" > -> < / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]:< / span >
2024-11-04 13:43:55 +01:00
< span class = "sd" > " " " < / span >
2024-10-20 19:14:34 +02:00
< span class = "sd" > `computeDF(...)` computes the dominance frontier of a CFG.< / span >
< span class = "sd" > It returns `DF` which associates a block to its frontier.< / span >
< span class = "sd" > This is an helper function called during SSA entry.< / span >
< span class = "sd" > " " " < / span >
< span class = "n" > DF< / span > < span class = "p" > :< / span > < span class = "n" > Dict< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ,< / span > < span class = "n" > Set< / span > < span class = "p" > [< / span > < span class = "n" > Block< / span > < span class = "p" > ]]< / span > < span class = "o" > =< / span > < span class = "nb" > dict< / span > < span class = "p" > ()< / span >
< span class = "k" > for< / span > < span class = "n" > b_entry< / span > < span class = "ow" > in< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > get_entries< / span > < span class = "p" > ():< / span >
< span class = "n" > _computeDF_at_block< / span > < span class = "p" > (< / span > < span class = "n" > cfg< / span > < span class = "p" > ,< / span > < span class = "n" > dominators< / span > < span class = "p" > ,< / span > < span class = "n" > DT< / span > < span class = "p" > ,< / span > < span class = "n" > b_entry< / span > < span class = "p" > ,< / span > < span class = "n" > DF< / span > < span class = "p" > )< / span >
< span class = "c1" > # Print the domination frontier on the CFG if asked< / span >
< span class = "k" > if< / span > < span class = "n" > dom_graphs< / span > < span class = "p" > :< / span >
< span class = "n" > s< / span > < span class = "o" > =< / span > < span class = "s2" > " < / span > < span class = "si" > {}< / span > < span class = "s2" > .< / span > < span class = "si" > {}< / span > < span class = "s2" > .ssa.DF.dot" < / span > < span class = "o" > .< / span > < span class = "n" > format< / span > < span class = "p" > (< / span > < span class = "n" > basename< / span > < span class = "p" > ,< / span > < span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > fdata< / span > < span class = "o" > .< / span > < span class = "n" > get_name< / span > < span class = "p" > ())< / span >
< span class = "nb" > print< / span > < span class = "p" > (< / span > < span class = "s2" > " SSA - dominance frontier graph:" < / span > < span class = "p" > ,< / span > < span class = "n" > s< / span > < span class = "p" > )< / span >
< span class = "n" > cfg< / span > < span class = "o" > .< / span > < span class = "n" > print_dot< / span > < span class = "p" > (< / span > < span class = "n" > s< / span > < span class = "p" > ,< / span > < span class = "n" > DF< / span > < span class = "p" > ,< / span > < span class = "kc" > True< / span > < span class = "p" > )< / span >
< span class = "k" > return< / span > < span class = "n" > DF< / span > < / div >
< / pre > < / div >
< / div >
< / div >
< footer >
< hr / >
< div role = "contentinfo" >
< p > © Copyright 2023, compil-lyon.< / p >
< / div >
Built with < a href = "https://www.sphinx-doc.org/" > Sphinx< / a > using a
< a href = "https://github.com/readthedocs/sphinx_rtd_theme" > theme< / a >
provided by < a href = "https://readthedocs.org" > Read the Docs< / a > .
< / footer >
< / div >
< / div >
< / section >
< / div >
< script >
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
< / script >
< / body >
< / html >