ECE540S Optimizing Compilers - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

ECE540S Optimizing Compilers

Description:

ECE540S Optimizing Compilers – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 11
Provided by: Michae7
Category:

less

Transcript and Presenter's Notes

Title: ECE540S Optimizing Compilers


1
ECE540SOptimizing Compilers
  • http//www.eecg.toronto.edu/voss/ece540/
  • Using Simple SUIF

2
The SUIF Compiler
  • A compiler infrastructure from Stanford
    University (Stanford University Intermediate
    Format).
  • Research Compiler not production quality slow
    but modular.
  • Optimizations are implemented in passes that
    communicate via binary files.
  • Implemented in C.
  • Optimizations for uni-processor (scalar
    optimizations) and for parallel processors.
  • Simple-SUIF is a C implementation of SUIF that is
    intended for scalar optimizations, and is
    simplified for educational use.

3
Simple-SUIF
  • Few instruction format
  • op
  • op dest src
  • op dest src1 src2
  • jmp label
  • See The Simple-SUIF Compiler Guide and
    /cad1/ece540/suif/include/simple.h for details on
    instructions and their formats.

4
Simple-SUIF
  • Operands
  • registers (most instructions).
  • variables (loads and stores).
  • immediate values (ldc instruction).
  • procedures/functions (call instruction).
  • labels (jump and branch instructions).
  • Types
  • used in instructions to indicate type of result.
  • Registers
  • temporary
  • registers with only one assignment and one use,
    both within a basic block.
  • temporary variables that do not need global
    optimization typically intermediate values.
  • pseudo temporary variables that need global
    optimization.
  • machine actual machine register (only used in
    register allocation).

5
Simple-SUIF Instructions
ldc (s.32) t4 0 cpy (s.32) r2
t4 ldc (s.32) t5 10 cpy
(s.32) r3 t5 ldc (s.32) t6 0
sl (s.32) t7 t6, r3 bfls
t7, L3 ldc (s.32) t8 0
cpy (s.32) r1 t8 L4 ldc
(s.32) t9 1 add (s.32) t10 r2,
t9 cpy (s.32) r2 t10 L1
ldc (s.32) t11 1 add (s.32) t12
r1, t11 cpy (s.32) r1 t12
sle (s.32) t13 r3, r1 bfls
t13, L4 L2 jmp
__done5 L3 ldc (s.32) t14 0
cpy (s.32) r1 t14 __done5
main() int i,c,n c 0 n 10
for (i0 i lt n i) c c 1

6
Writing a Compiler Pass
  • You are given
  • Simple-SUIF data structures and library function
    interfaces. (/cad1/ece540/suif/include/simple.h)
  • main.cc (a C file). It performs the following
    for each procedure in ltfilegt.tmp
  • read the procedure and builds Simple-SUIF data
    structures (front-end).
  • call do_procedure(simple_instr inlist, char
    proc_name).
  • write modified structure to output file.
  • You must write the do_procedure function to
    analyze and modify Simple-SUIF data structures.
  • Example printsimple.c a pass that prints the
    instructions in a ltfilegt.tmp.

7
Writing a Compiler Pass (continued)
simple_instr do_procedure (simple_instr
inlist, char proc_name) simple_instr
i printf("\nProcedure s\n",
proc_name) i inlist while (i)
fprint_instr(stdout, i) i i-gtnext
return inlist
8
Writing a Compiler Pass (continued)
  • Do this on a ugsparc.eecg machine

mkdir -p /ece540/printsimple cd
/ece540/printsimple cp /cad1/ece540/printsimple
/ . ls Makefile doproc.c main.cc print.c
print.h make make depend g -c -g
-I/cad1/ece540/suif/include main.cc gcc -c -g
-I/cad1/ece540/suif/include doproc.c gcc -c -g
-I/cad1/ece540/suif/include print.c g -o
printsimple -g -I /cad1/ece540/suif/include
main.o doproc.o print.o -L/cad1/ece540/suif/SPARC/
lib -lsimple -lsuif
9
Writing a Compiler Pass (continued)
cat test.c int main() return 0 ssfe
test ls test. test.c test.tmp printsimple
test.tmp test.spx Procedure main ldc (s.32)
t1 0 ret ssbe test ls test. test.c
test.s test.tmp test.spx rlogin skule.ecf cd
/ece540/printsimple ftp ugsparc10.eecg gt get
test.s gt quit masm test ./test
10
Representation of Sets
  • Sets are typically represented as bit-vectors
    one bit for each object in the set.
  • A 1-bit indicates presence in the set a 0-bit
    indicates absence from the set.
  • Set union is implemented using bit-or operations.
  • Set intersection is implemented using bit-and
    operations.
  • Set difference A-B is implemented as A and (not
    B).
  • Code that implements sets is provided to you. See
    the files bitvector. in /cad1/ece540/hw/hw1/src/
    .
Write a Comment
User Comments (0)
About PowerShow.com