Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
f1bff911
Commit
f1bff911
authored
14 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Finished assignment 1 of 'compiler design'.
parent
90b6be6e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compiler/.gitignore
+4
-0
4 additions, 0 deletions
compiler/.gitignore
compiler/ass1.tex
+117
-0
117 additions, 0 deletions
compiler/ass1.tex
graphics/ass10/assignment_texture_mapping.pdf
+0
-0
0 additions, 0 deletions
graphics/ass10/assignment_texture_mapping.pdf
with
121 additions
and
0 deletions
compiler/.gitignore
0 → 100644
+
4
−
0
View file @
f1bff911
*.aux
*.pdf
*.log
*.toc
This diff is collapsed.
Click to expand it.
compiler/ass1.tex
0 → 100644
+
117
−
0
View file @
f1bff911
\documentclass
[10pt,a4paper]
{
article
}
\usepackage
{
float
}
% aliases
\newcommand
{
\tab
}{
\hspace*
{
1cm
}}
\title
{
Compiler Optimalisation Assignment 1: Loops
}
\author
{
Sander van Veen (6167969)
}
\begin{document}
\maketitle
\section
{
Natural loops
}
% (fold)
\label
{
sec:Natural loops
}
Given flow graph
$
G
=
(
V,E,v
_
0
)
$
, where
$
V
$
is a collection of all vertices
(typically basic blocks),
$
E
$
is a collection of edges (which represent the
relation between the basic blocks) and
$
v
_
0
$
is the entry node. A natural loop
has the following definition:
\begin{itemize}
\item
A loop has a single entry point, which dominates the loop.
\item
There must be a path back to the entry point of the loop.
\item
Loops can be found by searching for edges of which their heads
dominate their tails, also know as backedges.
\item
Given an backedge
$
n
\rightarrow
d
$
, the natural loop is
$
d
$
plus the
nodes that can reach
$
n
$
without going through
$
d
$
.
\end{itemize}
\noindent
\textbf
{
Assignment: Give the natural loop(s) of the assignment's flow graph.
}
\\
To answer this assignment, I'll go through the definition of a natural loop and
discard the basic blocks which do not met the criteria.
\begin{enumerate}
\item
A loop has a single entry point, which dominates the loop.
\\
Blocks
$
B
_
1
$
and
$
B
_
2
$
met this criteria. Block
$
B
_
5
$
does not, since
$
B
_
3
$
and
$
B
_
4
$
both have an edge to
$
B
_
5
$
, which
makes
$
B
_
5
$
a multiple entrance point.
$
B
_
3
$
and
$
B
_
4
$
do not
dominate the loop, since they are both a successor of
$
B
_
2
$
.
\item
There must be a path back to the entry point of the loop.
\\
Block
$
B
_
1
$
does not have a path back to itself, so only block
$
B
_
2
$
remains.
\item
Loops can be found by searching for edges of which their heads
dominate their tails, also know as backedges.
\\
Block
$
B
_
2
$
has a backedge
$
B
_
5
\rightarrow
B
_
2
$
.
\item
Given an backedge
$
n
\rightarrow
d
$
, the natural loop is
$
d
$
plus the
nodes that can reach
$
n
$
without going through
$
d
$
.
\\
Since
$
B
_
2
$
is
the only remaining header, the assignment's flow graph has one
natural loop:
$
\{
B
_
2
, B
_
3
, B
_
4
, B
_
5
\}
$
. Note:
$
B
_
6
$
is not part of
the loop, because it is not stated if
$
B
_
6
$
has a path back to
$
B
_
2
$
.
\end{enumerate}
% section Natural loops (end)
\section
{
Reaching definition
}
% (fold)
\label
{
sec:Reaching definition
}
\textbf
{
Assignment: Give the
\texttt
{
gen
}
and
\texttt
{
kill
}
sets of the basic blocks.
}
%A typical dataflow equation has the form:
%\[\texttt{out}[S] = \texttt{gen}[S] \cup ( \texttt{in}[S] - \texttt{kill}[S])\]
\begin{table}
[H]
\begin{tabular}
{
|l|l|l|
}
\hline
$
B
_
i
$
&
\texttt
{
gen
}
$
[
B
_
i
]
$
&
\texttt
{
kill
}
$
[
B
_
i
]
$
\\
\hline
1
&
$
\{
d
_
1
,d
_
2
,d
_
3
,d
_
4
\}
$
&
$
\{
d
_
5
,d
_
6
,d
_
7
,d
_
8
,d
_
9
\}
$
\\
\hline
2
&
$
\{
d
_
5
\}
$
&
$
\{
d
_
4
,d
_
7
,d
_
8
\}
$
\\
\hline
3
&
$
\{
d
_
6
,
7
\}
$
&
$
\{
d
_
1
,d
_
3
,d
_
4
,d
_
5
,d
_
8
\}
$
\\
\hline
4
&
$
\{
d
_
8
\}
$
&
$
\{
d
_
4
,d
_
5
\}
$
\\
\hline
5
&
$
\{
d
_
9
\}
$
&
$
\{\}
$
\\
\hline
6
&
undefined
&
undefined
\\
\hline
\end{tabular}
\end{table}
\noindent
Note: I'm not sure about the
\texttt
{
gen
}
and
\texttt
{
kill
}
set of
$
B
_
1
$
. I noticed
$
d
_
3
$
will overwrite
$
d
_
1
$
, but I thought that doesn't mean
that
$
d
_
1
$
should be added to this
\texttt
{
kill
}
set.
% section Reaching definition (end)
\section
{
Iterative algorithm for reaching definitions
}
% (fold)
\label
{
sec:Iterative algorithm for reaching definitions
}
\textbf
{
algorithm
}
\\
for each block B:
\\
\tab
out[B] = gen[B]
\\
\\
changed = true
\\
while changed:
\\
\tab
changed = false
\\
\tab
for each block B:
\\
\tab
\tab
in[B] =
$
\bigcup
_{
p
\in
pred
(
B
)
}$
out[p]
\\
\tab
\tab
oldout = out[B]
\\
\tab
\tab
out[B] = gen[B]
$
\cup
$
(in[B]
$
-
$
kill[B])
\\
\tab
\tab
if out[B]
$
\neq
$
oldout:
\\
\tab
\tab
\tab
changed = true
\\
\noindent
Using this algorithm, the following result is generated.
\begin{table}
[H]
\begin{tabular}
{
|l|l|l|l|l|l|
}
\hline
&
start
&
first
&
first
&
second
&
second
\\
\hline
$
B
_
i
$
&
\texttt
{
out
}
[
$
B
_
i
$
]
&
\texttt
{
in
}
[
$
B
_
i
$
]
&
\texttt
{
out
}
[
$
B
_
i
$
]
&
\texttt
{
in
}
[
$
B
_
i
$
]
&
\texttt
{
out
}
[
$
B
_
i
$
]
\\
\hline
1
&
1,2,3,4
&
$
\emptyset
$
&
1,2,3,4
&
$
\emptyset
$
&
1,2,3,4
\\
\hline
2
&
5
&
1,2,3,4,9
&
1,2,3,5,9
&
1,2,3,4,5,8,9
&
1,2,3,5,9
\\
\hline
3
&
6,7
&
1,2,3,5,9
&
2,6,7,9
&
1,2,3,5,9
&
2,6,7,9
\\
\hline
4
&
8
&
1,2,3,5,9
&
1,2,3,8,9
&
1,2,3,5,9
&
1,2,3,8,9
\\
\hline
5
&
9
&
1,2,3,5,8,9
&
1,2,3,5,8,9
&
1,2,3,5,8,9
&
1,2,3,5,8,9
\\
\hline
6
&
undef.
&
1,2,3,8,9
&
undef.
&
1,2,3,8,9
&
undef.
\\
\hline
\end{tabular}
\end{table}
% section Iterative algorithm for reaching definitions (end)
\end{document}
This diff is collapsed.
Click to expand it.
graphics/ass10/assigment_texture_mapping.pdf
→
graphics/ass10/assig
n
ment_texture_mapping.pdf
+
0
−
0
View file @
f1bff911
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment