### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Compiling And Programming Systems CS 50200

Purdue

GPA 3.68

### View Full Document

## 49

## 0

## Popular in Course

## Popular in ComputerScienence

This 41 page Class Notes was uploaded by Nick Rowe on Saturday September 19, 2015. The Class Notes belongs to CS 50200 at Purdue University taught by Suresh Jagannathan in Fall. Since its upload, it has received 49 views. For similar materials see /class/208076/cs-50200-purdue-university in ComputerScienence at Purdue University.

## Reviews for Compiling And Programming Systems

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/19/15

Pa r rern Ma rching CS 502 Lec rur39e 3 82808 Tr39ee PaTTer39n MaTching El ML funcTions can be defined by a sequence of paTTer39n expression pair39s called r39ules ThaT ar39e maTched To a subjecT paTTer39n III The fir39sT r39ule ThaT maTches The subjecT has iTs expr39ession evaluaTed and r39eTur39ned as The r39esulT of The paTTer39n maTch PaTTerns III PaTTer39ns can be eiTher39 l Simple variables consTanTs wildcards l Tuples of paTTerns l A consTrucTor oper39aTion applied To a Tuple of paTTer39ns III This definiTion implies ThaT paTTer39ns ar39e Tr39eeshaped builT using consTr39ucTor39s Tuples and simple values El Goal minimize The number39 of TesTs ThaT have To be applied To deTer39mine The fir39sT r39ule ThaT maTches a subjecT I For ML This is an NPcompleTe problem I Use heur39isTics ThaT work well in pr39acTice Classical Approach III Build a decision Tr39ee l The Tree encodes The paTTern and defines The order in which subTer39ms of a Ter39m have To be evaluaTed l IT also injecTs r39unTime TesTs To deTermine if a paTTer39n maTches a value III Two classificaTions ExhausTive Ther39e exisTs aT leasT one paTTer39n ThaT maTches The subjecT RedundanT There is more Than one paTTern ThaT maTches The subjecT Desire exhausTive nonredundanT paTTern expressions Example fun diffniy y 1 diffxni x 2 I diffhdxTlxhdyle diffTlxle The seT of paTTerns is exhausTive PaTTerns 1 and 2 are nondisjoinT or overlap because There is aT leasT one value for which boTh paTTerns maTch ie nini Ordering of rules impose a prioriTy ordering among paTTerns PaTTerns musT be linear no variable in a paTTern can occur more Than once I fun equalxx True This is illegal PaTTerns should noT be redundanT They should maTch some value noT maTched by earlier paTTerns Syn rax of pa r rerns and Terms wildcar39d variable co ns ran r I P1pn ruples I C p39 cons rr39uc ror39 C applied ro pattern p III Pa r rer39ns mus r be wellTyped l Cons3 no r wellTyped l Wha r abou r Consx Value Ter39ms PaTTer39ns maTch values which are also Treeshaped sTr39ucTur39es formed by The applicaTion of consTr39ucTor39s and Tupling aTom aTomic values values of pr39imiTive Types funcTional Types and absTr39acT Types c consTanTs T1Tn Tuple of Terms C T39 consTrucTor C applied To Term T39 Example Value Ter39m T True Cons1Nil Following Sequence of pa er39ns of Type bool im lisT p1 True p2 faISe nil p3 faISe ConsxNil p4 faISe Consyz p1 agrees wifh T on ifs firsf componem p2 p3 p4 do noT p1 also agrees on ifs Second Ter39m p3 and p4 have a pa er n of The form Consp39 and agree wifh T on This componem p3 and p4 also agree wiTh T on boTh argumenTs To Cons Formal DefiniTion Given paTTern p and value Term T p agrees wiTh T on a subTerm T of T iff p wildcard p is a variable p c where c is a consTanT and T c p p1pn T T1Tn and T T p p1pn T T1Tn T is a subTerm of TJ for 1lt J lt2 n and pi agrees wiTh TJ on subTerm T pCp39andTTCT39 p C p39 T C T39 T is a subTerm of T39 and p39 agrees wiTh T39 on T MaTching A paTTern p maTches 1 Term T iff p agrees wiTh T on all subTer39ms of T The maTching problem Given a finiTe sequence of paTTer39ns p1pn and value Ter39m T find The fir39sT paTTer39n in The sequence which maTches T if one exisTs We elide issue of Typing her39e Efficiency El Na ive approach I Ma rch each argumen r wi rh each pa r rern in furn Topdown s rar ring over affer every failure I Inefficien r because informa rion gleaned abou r The argumen r in each par rially successful ma rch is ignored on subsequen r ma rches El Be r rer s rra regy analyze pa r rern sequence a r compileTime and Try To minimize number of case discrimina rion Tes rs Example r39evisiTed El Ter39m T True Cons1Nil El PaTTer39ns p1 True p2 false Nil p3 false ConsxNil p4 false Consyz WanT To find The paTTer39n ThaT maTches T MusT compar39e subTer39ms of T wiTh subpaTTer39ns Example revisited El Two choices test either on first component or second component I First component discover that p1 is the only pattern that matches Wildcard in second component establishes p1 as a matching pattern Second component can discard p2 Must compare against p1 p3 and p4 El Three additional tests required I Test on first component of t leads to desired result I Test on first component of Cons I Test on second component of Cons Decision Tree 2 192493494 Cork Minimal decision Tree for example Finding OpTimol Decision Trees El Finding The opTimol minimal decision Tree is NPcompleTe III In pr39ocTice employ a vor39ieTy of heur39isTics To achieve This goal El DifferenT compilers employ differenT schemes To reduce The size of The decision Tr39ee consTr39ucTed under39 The no39l39ve inTer39pr39eToTion Relevance HeurisTic El If Two paTTerns overlap The one wiTh The lowesT index is preferred El Consider p1 nil x and p2 yni I01 Branching Fac ror Heuris ric El Favoring choice of TesTs wiTh low branching facTor first III Type color red blue green III p1 True green p2 false green 191 p2 redglue green VibIue een 192 1 p In rr39oduc rion To Shape and Poin rer39 Analxsis CS 502 Lecture 11 103008 Some slides adapted from Nielson Nielson Hankin Principles of Program Analysis Analysis of The Heap III Thus far we have focussed on con rrol and da raflow proper ries of programs I da raflow analysis approxima res cons rruc rs or derives program proper ries based on a program39s con rrol and da raflow III Wha r abou r The heap I How do we approxima re proper ries of heap alloca red da ra s rruc rures III Poin rs ro analysis I Useful for de rec ring sharing and aliasing Shape Analysis III Obtain a finite representation of the shape of the program heap at different program points I Consider a language with pointers and references El Utility l Aliasing and sharing El Can be u3ed for more efficient code generation I Inlining constantfolding method dispatch etc El Identify possible nullpointer dereferences El Program verification l reverSe transforms a noncyclic list to a noncyclic list 3 Poin rer Analysis Goal wha l objects can a pointer poin l lo S la lically undecidable in general I What are good approxima lions Can be used To infer aliaSes I if a points To b and b poin ls To c Then El ltabgt ltbcgt gt ltacgt and Thus a and b are aliases Fundamen lally an in lerprocedural analysis I A poin ler variable can be supplied as arguments or returned as a resul l from a procedure Flowinsensi live vs flowsensi live con leX lsensi livi39ly shape analysis field sensi livi39ly S rr39a regies El Example p malloc q malloc fp ampp fp ampq fp El Flowinsensitive equalitybased heap1 heap2 Equali ry based Analyses III Example xampa yamph pampx pampw Typebased Formula rion III Running example x ampa yamph I0 ampX pampw III Assign each variable a Type x r1y r2a r3b r4p r5 III Cons rr39uc r ini rial cons rr39ain rs l x ampa T1 r39ef r3 l y ampb T2 r39ef r4 l p ampy T5 r39efT1 l p ampy T5 r39efT2 Typebased formula rioncon r III Solve and unify The constraints l T4 r39ef r1 r39ef r2 III Mer ge T1 and 2 info 1 I x T1 y T1 1 T3 b r4 p 5 I T1 r39ef r3 T1 r39ef r4 T5 r39ef r1 III Repea r The process I T1 r39ef r3 r39ef r4 El Merge l T1 r39ef r3 T5 r39ef r1 S rr39a regies p malloc q malloc fp 840 III Example El Flowinsensitive subsetbased p gtheap1 q gt heap2 Subset based inclusion El Example q ampx q ampy p q q ampz Dotted line indicates that the pointsto set for q must be a subset of the pointsto set for p Subset based inclusion Subset constraint dotted line indicates that an edge must be established between p and 2 as well What is the runningtime complexity of these two analyses Shape Analysis Syn rax a 1 p 71 a1 Opa a2 nil 13 xse p b 1 true false not b b1 Opb 2 a1 Opr a2 Opp p S pael Skipv 31 32 if b6 then 31 else 32 while be do 8 malloc 196 Example ynil1 while not isnilx2 do zy13 yx4 xxcdr5 ycdrz6 znil TI 0 e r U I C U r I S p 0 e In O S r e V e R p O b e In I LI 0 s n m I O r e h I n e r 6 LI 1 d Cdr Cdr Cdr Cdr X 0 Cdr 1 Y0 Cdr Cdr Cdr Cdr Cdr X aaaaaao 24gtltgt Cdr Cdr x O Cdr Cdr Cdr 3 y aaaao Cdr Cdr Cdr x O Cdr Cdr 2 y 0 Z Cdr Cdr Cdr Cdr Cdr 5 y 0 Cdr X 0 Cdr Cdr Cdr Cdr 4 y 0 Z Analysis III To analyze da ra s rruc rures of This form develop an approximation To The ac rual run rime s rruc rure of The heap III Approach l Firs r develop a seman rics rha r describes changes To The heap as The program execu res l Second develop a conserva rive approxima rion To This seman rics l The approxima re s ra re of The heap at different program poin rs is The resul r of The analysis Semantics A configurations consists of o a state a E State 2 Van gt Z Loc 0 mapping variables to values locations in the heap or the nil value o a heap H E Heap 2 Loc gtlt Sel gt n Z Loc 0 mapping pairs of locations and selectors to values locations in the heap or the nil value Defining Pointers p PExp gt State gtlt Heap gt n Z ltgt Loc is defined by meH 000 Haxse pumse w if 0x 6 Loc and H is defined on 0xse undefined otherwise Arithmetic and boolean expressions A Z AExp gt State gtlt Heap gt n Z Loc ltgt 8 BEXp gt State gtlt Heap gt n T Assignmen r and Selec rion Clauses for assignments ltxa 03 gt lt0c H A a aHHgt if AaaH is defined ltmsea 0Hgt gt lt0Hax sel gt AaUHgt if 0x E Loc and AaaH iS defined Clauses for malloc malloc x aHgt gt ltax I gt ELH where 5 does not occur in a or H malloc xse 0Hgt s lt0HUm sel H 51gt where 5 does not occur in a or H and 0x 6 Loc 17 Shape Graphs The analysis will operate on shape graphs 5 H is consisting of 0 an abstract state S 0 an abstract heap H and 0 sharing information is for the abstract locations The nodes of the shape graphs are abstract locations ALoc nX X g Van Note there will only be finitely many abstract locations Example In the semantics x Ami ltgt y amigo Z In the analysis cdr x MW y emw Z Abstract Locations The abstract location nX represents the location 0x if x e X The abstract location n0 is called the abstract summary location n0 rep resents all the locations that cannot be reached directly from the state without consulting the heap Invariant 1 If two abstract locations nX and my occur in the same shape graph then either X Y or XmY V Abstract States and Heaps S e AState 73Var gtlt ALoc abstract states H E AHeap 73ALoc gtlt Sel gtlt ALoc abstract heap Invariant 2 If 1 is mapped to nX by the abstract state S then a E X Invariant 3 Whenever nVsenW and nVSenW are in the abstract heap H then either V Q or W W 20 Lis r Reversal afTer successive i rer39a rions Sharing x air L l cd x aim cdr A ltgt is the abstract locations that might be shared due to pointers in the heap nX is included in is if it might repre sents a location that is the target of more than one pointer in the heap Examples dr lcdr i0 x C4dr cgdr i c x aluln i cdr ltgt 4 cdr x a mir o y Sharing Invariants The implicit sharing information of the abstract heap must be consistent with the explicit sharing information Invariant 4 If nX e is then either o n senX is in the abstract heap for some se or o there are two distinct triples nV se1nX and nWse2nX in the abstract heap Invariant 5 Whenever there are two distinct triples nVSe1nX and nWse2 nX in the abstract heap and X 72 Q then nX E is

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

#### "Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over $500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.