









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of Compiler Optimisation which includes Scalar Optimisation, Redundant Expressions, Dataflow Framework, Adaptive Compilation, Subexpressions, Find Available Expressions, Number of Iterations, Live Variables etc. Key important points are: Scalar Optimisation, Redundant Elimination, Machine Dependent, Independent Optimisations, Super Value Numbering, Dominator Value Numbering, Alternative General Approach, Dataflow Analysis
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










January, 2013
1 Course Structure • L1 Introduction and Recap • 4/5 lectures on classical optimisation– 2 lectures on scalar optimisation – Today example optimisations – Next lecture dataflow framework and SSA • 5 lectures on high level approaches • 4-5 lectures on adaptive compilation M. O’Boyle Scalar Optimisation^
January, 2013
3 Optimisation Classification • Machine independent vs dependent - not always a clear distinction.
Main trends in architecture increased memory latency and exploitation of ILP aremachine dependent • Machine independent applicable to all.
Eliminate redundant work, accesses. Use less expensive operations where possible • Optimisation can be performed at source, IR, assembler, machine code level. • Concentrate on machine independent scalar optimisation - IR level. • Optimisation = analysis + transformation. Form depends on IR - impact oncomplexity. M. O’Boyle^ Scalar Optimisation
January, 2013
4 Redundant expression elimination An expression x + y is redundant if already evaluated and not redefinedValue numbering: Associate numbers with operators/operands and hash lookupin table Hash (+,x,y) return value numberIf value number already there replace with reference to variable (^3 1 23 1 2312) a= x+ y a=^ x+^ y^ a=^ x+^ y^0 0 04 1 24 3412 b= x+ y b=^ a^ b=^ x+^ y^0 0 03 3 3 a= 17 a= 17^ a= 17^1 5 1 25 3512 c= x+ y c=^ a!!^ c=^ x+^ y^0 0
(^312) a=^ x+^ y (^0 0 043) b=^ a (^0 034) a= 17 (^1 53) c=^ a 0 0 Can be extended to handle larger scope based on dominators.
Fails in presence of general control-flow M. O’Boyle^ Scalar Optimisation
January, 2013
6 Super Local Value numbering SVN Basic blocks(BB) have just one entry and exit. • Extended BB: (EBB) A tree of BBs^ {B,... , B}^ where^1 n
Bmay have multiple^1 predecessors. • All others have a single unique predecessor but possibly multiple exits. • This tree is only entered at the root.In our example 3 EBBs (A,B,C,D,E), (F), (G)SVN considers each path within an EBB as single blockSo (A,B), (A,C,D), (A,C,E) are considered paths for LVN M. O’Boyle^ Scalar Optimisation
January, 2013
7 Example: Extended Basic Blocks.^ m = a+b^ ALn = a+bp = c + d^ q = a+b B^ CSr = c + dr = c+dL e = b + 18e = a + 17ED^ s = a + bt = c + du = e + fu = e + f v = a + bF^? w = c + d?x = e + f? y = a + bG? z = c + d?
SS M. O’Boyle^ Scalar Optimisation
January, 2013
9 Example: Dominator value numbering.^ m = a+b^ An = a+bL p = c + d^ q = a+b^ B^ CS r = c + dr = c+dL e = b + 18e = a + 17ED^ s = a + bt = c + du = e + fu = e + f v = a + bF w = c + dx = e + f^? y = a + bGz = c + d?
SS DD D What about the remaining two ?s in G and F? M. O’Boyle^ Scalar Optimisation
January, 2013
(^10) Dataflow analysis
-^ A formal program analysis that has a wide range of application. •^ Described property of a program at a particular point in set based recurrenceequations •^ Assumes a control-flow graph(CFG) consisting of nodes (basic blocks) andedges: control-flow •^ Determines property at a point in the program as a function of local informationand approximation of global information •^ Approx solutions will converge to exact solution in finite number of iterationsfor finite lattices - more detail next lecture M. O’Boyle^ Scalar Optimisation
January, 2013
12 Find available expressions part 1 Node A^ B^ C^ D^ E^
pred^ -^ A^ A^ C^
DEExpr^ a+b^ c+d^ a+b^ b+
a+17^ a+b^ a+b c+d a+b c+d^ c+d^ c+d e+f e+f^ e+f Kill^ e+f
e+f Calculate Avail(b) for each Basic Block b starting at block A AV AIL(B) = (DEExpr(A)^ ∪^ (AV AIL(A
=^ {a^ +^ b} ∪^ (∅ ∩^ U^ ) =^ {a^ +^ b} AV AIL(C) = (DEExpr(A)^ ∪^ (AV AIL
=^ {a^ +^ b} ∪^ (∅ ∩^ U^ ) =^ {a^ +^ b} M. O’Boyle^ Scalar Optimisation
January, 2013
13 Find available expressions part 2 D and E are the same AV AIL(D) = (DEExpr(C)^ ∪^ (AV AIL(C)^ ∩^ N OT KILLED
=^ {a^ +^ b, c^ +^ d} ∪^ ({a^ +^ b} ∩^ U^ ) =
{a^ +^ b, c^ +^ d} AV AIL(E) = (DEExpr(C)^ ∪^ (AV AIL
=^ {a^ +^ b, c^ +^ d} ∪^ ({a^ +^ b} ∩^ U^ ) =
{a^ +^ b, c^ +^ d} F is a join point: 2 predecessors AV AIL(F^ ) = (DEExpr(D)^ ∪^ (AV AIL
⋂(DEExpr(E)^ ∪^ (AV AIL(E)^ ∩
{b^ + 18, a^ +^ b, e^ +^ f^ } ∪^ ({a^ +^ b,^ c
+^ d} ∩^ U^ − {e^ +^ f^ }) ⋂{a^ + 17, c^ +^ d, e^ +^ f^ } ∪^ ({a^ +^ b
,^ c^ +^ d} ∩^ U^ − {e^ +^ f^ }) =^ {a^ +^ b, c^ +^ d, e^ +^ f^ } M. O’Boyle^ Scalar Optimisation
January, 2013
15 Example: Global redundancy elim using AVAIL()^ m = a+bn = a+bp = c + d^ q = a+br = c + dr = c+de = b + 18s = a + bu = e + f AL B C^ SL e = a + 17ED^ t = c + dSS u = e + f v = a + bFDw = c + dDx = e + fG y = a + bGDz = c + dG M. O’Boyle^ Scalar Optimisation
January, 2013
(^16) Summary
-^ Levels of optimisations •^ Redundant expression elimination •^ LVN, SVN, DVN •^ Introduced dataflow as a generic optimisation framework •^ Iterative solution to equations •^ Next time: More detailed examination of dataflow and SSA M. O’Boyle^ Scalar Optimisation
January, 2013