McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST...
-
Upload
myrtle-kennedy -
Category
Documents
-
view
222 -
download
2
Transcript of McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST...
![Page 1: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/1.jpg)
McLab Tutorialwww.sable.mcgill.ca/mclab
Part 4 – McLab Intermediate Representations
• High-level McAST• Lower-level McLAST
• Transforming McAST to McLAST
6/4/2011 IR- 1McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
![Page 2: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/2.jpg)
Big Picture
6/4/2011 McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4 IR - 2
McLab Front-End
McLab Simplifier
MATLAB-to-Natlab Translator
McAST Analyses
MATLAB
Natlab
McAST
McLAST McLAST Analyses
![Page 3: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/3.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
McAST
• High-level AST as produced from the front-end.• AST is implemented via a collection of Java classes
generated from the JastAdd specification file.• Fairly complex to write a flow analysis for McAST
because of:– arbitarly complex expressions, especially lvalues– ambiguous meaning of parenthesized expressions
such as a(i) – control-flow embedded in expressions (&&, &, ||, |)– MATLAB-specific issues such as the "end" expression
and returning multiple values.6/4/2011 IR - 3
![Page 4: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/4.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
McLAST
• Lower-level AST which:– has simpler and explicit control-flow;– simplifies expressions so that each expression has
a minimal amount of complexity and fewer ambiguities; and
– handles MATLAB-specific issues such as "end" and comma-separated lists in a simple fashion.
• Provides a good platform for more complex flow analyses.
6/4/2011 IR - 4
![Page 5: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/5.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
Simplification Process
6/4/2011 IR - 5
McLASTAnalysisFront- End
AST +
Simplifier
Simplification Phase
kind infoT1 T2 TnMcAST Kind
![Page 6: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/6.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
Dependences between simplifications
6/4/2011 IR - 6
COND
leftSimpleIF
MultiAssign
Short- Circuitarrays
SimpleAssign
Left FOR
Right
FULL
CSL
![Page 7: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/7.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
Expression Simplification
6/4/2011 IR - 7
f oo(x) + a(y( i ) )
Aim: create simple expressions with at most one operator and simple variable references.
t1 = f oo(x) ;t2 = y( i ) ;t3 = a(t2) ;t1 + t3
Aim: specialize parameterized expression nodes to array indexing or function call.
![Page 8: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/8.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
Short-circuit simplifications
• && and || are always short-circuit
• & and I are sometimes short-circuit– if (exp1 & exp2) is short-circuit– t = exp1 & exp2 is not short-circuit
• replace short-circuit expressions with explicit control-flow
6/4/2011 IR - 8
![Page 9: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/9.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
"end" expression simplification
6/4/2011 IR - 9
A(2, f (end))
Aim: make "end" expressions explicit, extract from complex expressions.
A(2, f (EndCal l (A, 2, 2) ) )
t1 = EndCal l (A, 2, 2) ;t2 = f ( t1) ;A(2, t2)
![Page 10: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/10.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
L-value Simplification
6/4/2011 IR - 10
A(a+b, 2) . e( f oo( ) ) = val ue;
Aim: create simple l-values.
t1 = a+b;t2 = f oo( ) ;A( t1, 2) . e( t2) = val ue;
Note: no mechanism for taking the address of location in MATLAB. Further simplification not possible, while still remaining as valid MATLAB.
![Page 11: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/11.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
if statement simplification
6/4/2011 IR - 11
i f E1body1( ) ;
el sei f E2body2( ) ;
el sebody3( ) ;
end
Aim: create if statements with only two control flow paths.
i f E1body1( ) ;
el sei f E2body2() ;
el sebody3() ;
endend
![Page 12: McLab Tutorial Part 4 – McLab Intermediate Representations High-level McAST Lower-level McLAST Transforming McAST to McLAST 6/4/2011IR-](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649e455503460f94b3a4c6/html5/thumbnails/12.jpg)
McLab Tutorial, Laurie Hendren, Rahul Garg and Nurudeen Lameed, Part 4
for loop simplification
6/4/2011 IR - 12
t1=E;t2=si ze( t1) ;t3=prod( t2(2: end) ) ;f or t4 = 1: t3i = t1( t4) ;%BODY
end
f or i = E%BODY
end
Aim: create for loops that iterate over a variable incremented by a fixed constant.
1 f or i = 1: 2: n2 %BODY3 end