{{Use dmy dates|date=June 2020|cs1-dates=y}} In compiler theory, '''upwards exposed uses''' or '''reachable uses'''<ref name="Harrold_2009"/> are all uses of a variable that are reachable from a point in the program. A use of variable is a point or statement where that variable is referenced (read) but not changed. A use of a variable A is reachable from a point p if there exists a control-flow path in the control-flow graph from p to the use with not definition of A on the path.
A '''reachable uses analysis''' is a data-flow analysis<ref name="Harrold_2009"/> to calculate all reachable uses of a program. It is very similar to the liveness analysis. A variable is live in a point in the program if it has one or more reachable uses. Compared to the liveness analysis, reachable uses analysis provides additional information where the variable is used.
== Uses == Upwards exposed uses occurs in the copy propagation stage of program compilation.<ref name="Aho-Lam-Sethi-Ullman_2006"/> During the copy propagation stage, instances of a target are replaced with assignments to their values. During this process, it is necessary for the compiler to understand which instances of a target are being accessed so that appropriate substitution may occur, related to the concept of reaching definition in reaching analysis.<ref name="Kore_2020"/> This is done with the purpose of simplifying code before execution: if the number of upwards exposed uses of an assignment is zero, it does not contribute to the end result of the code and can be safely removed.<ref name="Harrold_2009"/> This is also useful for improving code security during the compilation stages.<ref name="Bergeretti-Carré_1985"/>
== Example == Consider the following pseudocode: <syntaxhighlight lang="python3" line="1" start="1"> x = 1 y = z
if False: x = 0 else: x = y + 2</syntaxhighlight> It is safe to assume that line 5 will never occur, as demonstrated by the number of upwards exposed uses for this point being zero. This can therefore be simplified: <syntaxhighlight lang="python3" line="1" start="1"> y = z x = z + 2</syntaxhighlight>
This leads to a result that is less complex to compile and more efficient to run.<ref name="Aho-Lam-Sethi-Ullman_2006"/> This also meets the definition of reaching definition: In this context, upwards flow analysis was the technique used to demonstrate the needs for reaching definition. Additional techniques allow for more complex analysis of more deeply intertwined or complex control flow problems, such as those with various forms of loops.<ref name="Bergeretti-Carré_1985"/>
== See also == * Dead code elimination * Reaching definition * Live-variable analysis
== References == {{Reflist|refs= <ref name="Harrold_2009">{{Cite web |title=Basic Analysis |series=CS 6340: Software Analysis and Testing |last=Harrold |first=Mary Jean |date=Fall 2009 |work=Georgia Tech - College of Computing |publisher=Georgia Institute of Technology |location=Atlanta, Georgia, USA |url=https://www.cc.gatech.edu/~harrold/6340/cs6340_fall2009/Slides/BasicAnalysis3.pdf |access-date=2020-06-12 |url-status=live |archive-url=https://web.archive.org/web/20200620130147/https://www.cc.gatech.edu/~harrold/6340/cs6340_fall2009/Slides/BasicAnalysis3.pdf |archive-date=2020-06-20}}</ref> <ref name="Aho-Lam-Sethi-Ullman_2006">{{Cite book |title=Compilers: Principles, Techniques, and Tools |title-link=Compilers: Principles, Techniques, and Tools |last1=Aho |first1=Alfred Vaino |author-link1=Alfred Vaino Aho |last2=Lam |first2=Monica Sin-Ling |author-link2=Monica Sin-Ling Lam |last3=Sethi |first3=Ravi |author-link3=Ravi Sethi |last4=Ullman |first4=Jeffrey David |author-link4=Jeffrey David Ullman |date=2006 |isbn=0-321-48681-1 |edition=2 |publisher=Addison-Wesley |location=Boston, Massachusetts, USA |oclc=70775643}}</ref> <ref name="Kore_2020">{{Cite web |title=Upwards Exposed Uses |last=Kore |first=Aamod |date=2020 |publisher=Department of Computer Science, University of Toronto |location=Toronto, Ontario, Canada |url=https://www.cs.toronto.edu/~aamodkore/notes/dfa-tutorial/hw3-exposed-uses.html |access-date=2020-06-12 |url-status=live |archive-url=https://web.archive.org/web/20200620130828/https://www.cs.toronto.edu/~aamodkore/notes/dfa-tutorial/hw3-exposed-uses.html |archive-date=2020-06-20}}</ref> <ref name="Bergeretti-Carré_1985">{{Cite journal |title=Information-Flow and Data-Flow Analysis of while-Programs |last1=Bergeretti |first1=Jean-Francois |last2=Carré |first2=Bernard A. |date=1985-01-02 |journal=ACM Transactions on Programming Languages and Systems |volume=7 |issue=1 |publisher=Association for Computing Machinery |doi=10.1145/2363.2366 |pages=37–61 |s2cid=19682896 |doi-access=free }}</ref> }} {{Compiler optimizations}}
Category:Compiler theory Category:Compiler optimizations Category:Data-flow analysis