Download Instructions for Installing and Running Trimaran, a Compiler on Linux - Prof. Scott Mahlke and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!
EECS 583 – Lecture 3 Control Flow Optimization
University of Michigan January 13, 2003
Agenda for Today
Y
Trimaran overview^ »
What you need to know for HW 1
»^
See http://www.trimaran.org
, documentation page for more
Y
Finish off leftover from last time
Y
Simple control flow transformations^ »
Loop unrolling
»^
General code
Y
Start on regions if we have time
Needed Software Y
TCL/TK – v8.0p2 or higher (tclsh, wish)
Y
perl – v5.0p3 or higher
Y
gnumake (should be called make, gmake, gnumake, add links!)
Y
imake (generally part of X11)
Y
gzip/gunzip
Y
gcc^ »
3.0.4 works for sure »^
2.8.1 - 3.2 should work
Y
Gnu ranlib, ar (binutils 2.9 – 2.13)
Y
tcsh – Use this or you will have to translate some stuff
Y
emacs – Real compiler writers don’t use vi or pico
Y
Graph visualizing tools^ »
dot – http://www.research.att.com/sw/tools/graphviz »^
xvcg – source on course webpage (./configure, make)
Installation – Step 1
Y
Source on the course webpage, trimaran.w03.tgz
Y
In your home directory, mkdir trimaran
Y
tar zxvf trimaran.w03.tgz^ »
Will create 6 subdirectories
»^
impact, elcor, simu, scripts, benchmarks, gui
Y
Enviroment variables/path – this is critical^ »
trimaran/scripts/envrc – should have everything you need
»^
Or, trimaran/scripts/envrc.bash for you bash users
»^
Modify first line if you don’t put trimaran in $HOME/trimaran
»^
Add to your .cshrc, source trimaran/scripts/envrc^ y
So you don’t forget
Trimaran Overview
C source
Frontend – parsing, profiling function inlining, memory dep analysis. Also, does some backend stuff – region formation, optimization
Impact
Lcode
Backend – analysis, optimization, scheduling register allocation, code generation
Elcor
Rebel
Emulator – emulate VLIW semantics using C code – “compiled simulation”
Simu
C emulation code
Running Trimaran
Y
trimaran-gui – I don’t like/use this^ »
Compile strcpy with basic blocks to test install
»^
Lots of documentation at http://www.trimaran.org
Y
tcc – gcc equivalent, sorta!^ »
Command line way to invoke entire system – Gui calls this
»^
“tcc –help” to get options
»^
“tcc –bench strcpy” to run strcpy with basic blocks
Y
trimaran/benchmarks^ »
To run trimaran on a benchmark, need some setup^ y
source, compile flags, link flags y input for profiling the code y output to check it ran properly y To add a new benchmark, follow the organization that is there
»^
583hw1a, 583hw1b, 583hw1c, 583hw1d for HW
Elcor – Directory Structure
Y
bin, lib – the obvious stuff
Y
src – where you will spend most of your time^ »
type make in src to build elcor
Y
mdes^ »
Machine descriptions for the target processor
»^
hmdes2 = high level machine description – for human
»^
lmdes2 = low-level machine description – for compiler
»^
hc = script to convert hmdes2 to lmdes
»^
hpl_pd_elcor_std.hmdes2 – includes other files
Y
parms^ »
Compiler switches broken into groups^ y
DRIVER_DEFAULTS
, ANALYSIS_DEFAULTS, etc.
y^
Changing switch values^ X
Modify ***_DEFAULTS file X^
-Fswitch=value on the command-line
Running Elcor Manually
Y
Use trimaran-gui or tcc, compile a benchmark^ »
tcc –bench 583hw1a
Y
583hw1a_O directory created^ »
impact_intermediate
»^
elcor_intermediate^ y
583test1.O_tr.tgz – impact output / elcor input (bridge code)
X^
Impact assembly (called Lcode or Mcode) X^
This is what you will run Elcor manually on X^
Untar this file^ ±
file1.O_tr, file2.O_tr, … ±
1 file per original C source file
y^
583test1.O_el.tgz – elcor output^ X
Rebel
y^
host_layout_info.md – data structure organization stuff
»^
simu_intermediate
Running Simu Manually
Y
simu^ »
Converts Rebel to C
»^
Models VLIW architecture properly^ y
predicates, NUAL, etc.
»^
Allows testing the compiler is correct!
Y
running simu (aka codegen)^ »
codegen –el test1.O_el –o test1.c –Finput_format=rebel \ –Femulate_unscheduled=yes –Femulate_virtual_regs=yes^ y
test1.c y benchmark_data_init.simu.c
»^
Note need host_layout_info.md in the directory
»^
gcc –I$HOME/trimaran/simu/src/Emulib \ –L$HOME/trimaran/simu/lib *.c –lequals –lm
»^
./a.out > output, diff output verses expected output
Elcor Organization Y
src/Tools
y^
“homegrown” version of STL - list, dlist, slist, hash_set, hash_map, …
Y
src/Graph
y^
All the core compiler data structs in here y^
operand.h, port.h, op.h, region.h, edge.h, *_utilities.h, opcode_properties.h
Y
Main
y^
process_function.cpp is the main driver
Y
Mdes
y^
target processor info – built from .lmdes2 file
Y
Analysis
y^
control flow, dataflow analysis, predicate analysis, edge drawing
Y
Control
y^
Control flow transformations
Y
Templates
y^
Whenever you create a List that has never been done before y^
Must instantiate template – look in the files for example y^
Hw1 – can add to template_control.cpp
Back to Loops – Assembly Generation Schema
for (i=x; i<y; i+=z) {
body;
while-do schema
do-while schema
loop:
if (i >= y) goto done body; i += z; goto loop
if (i >= y) goto done body; i += z; if (i < y) goto loop
loop:
done:
done:
Question: which schema is better and why?
Loop Induction Variables
Y
Induction variables are variables such that every time theychanges value, they are incremented/decremented bysome constant
Y
Basic induction variable
- induction variable whose only
assignments within a loop are of the form j = j+- C, whereC is a constant
Y
Primary induction variable
- basic induction variable that
controls the loop execution (for I=0; I<100; I++), I(virtual register holding I) is the primary inductionvariable
Y
Derived induction variable
- variable that is a linear
function of a basic induction variable
Loop Unrolling Y
Most renowned control flow opti
Y
Replicate the body of a loop N-1times (giving N total copies)»
Loop unrolled N times or Nxunrolled »^
Enable overlap of operations fromdifferent iterations »^
Increase potential for ILP(instruction level parallelism)
Y
3 variants»
Unroll multiple of known tripcount »^
Unroll with remainder loop »^
While loop unroll
Loop:r1 = MEM[r2 + 0]r4 = r1 * r5r6 = r4 << 2MEM[r3 + 0] = r6r2 = r2 + 1blt r2 100 Loop
Loop Unroll – Type 1
r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1 blt r2 100 Loop
Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1 blt r2 100 Loop r2 is the loop variable, Increment is 1 Initial value is 0 Final value is 100 Trip count is 100
Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 1
Loop: r1 = MEM[r2 + 0] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r1 = MEM[r2 + 1] r4 = r1 * r5 r6 = r4 << 2 MEM[r3 + 0] = r6 r2 = r2 + 2 blt r2 100 Loop
Counted loop All parms known
Remove r2 increments from first N-1 iterations and update last increment
Remove branch from first N-1 iterations