• No results found

Decomposing Loops: The S Decomposition

Starting with section 5.5, our goal has been to constructBS, for each shapeS.BSsummarizes

all strings of the formrpiqpqi`1,qi`1q˚, and with shapeS. In section 5.6 we restricted the space of shapes to only those that are upward-flowing, and in section 5.7, we defined a partial orderĎover shapes which constrained the possible shapes of sub-paths. In this section and in section 5.9, we will constructBS. Our construction ofBS is inductive: we assume thatBS1 is known for all strictly smaller shapesS1 Ĺ S. Furthermore, since each string in rpiq

pqi`1,qi`1q is non-empty, R Jr

piq

pqi`1,qi`1q`K. We therefore separately handle the

case ofand we will now construct an expression vectorB`S which summarizes strings (all

necessarily non-empty) inrpiqpqi`1,qi`1q`and with shapeS. Define the expression vector BSas follows:

BS,v,i

#

ÞÑ ifS“ txÞÑx,yÞÑy,zÞÑzu, and bot otherwise.

qi`1 qi`1 qi`1 qi`1 qi`1 qi`1 qi`1 qi`1 S1„S w1 S2„S w2 ¨ ¨ ¨ Sj„S wj ¨ ¨ ¨ Sl„S wl SfĂS wf qi`1 qi`1 qi`1 SpreĂS wprePJr piqpq i`1,qi`1q˚K Ssuff wsuffPJr piqpq i`1,qi`1qK

Figure 5.5: Decomposing paths in rpiqpqi`1,qi`1q` whose shape is S. Each w P tw1,w2, . . . ,wluhas shapeSw„S, and each of its proper prefixeswprehas shapeSpreĹS. EquivalentlywPLfirstpSwq. Each stringw P tw1,w2, . . . ,wlucan itself be unambiguously written as w “ wpre¨wsuff, with wsuff P Jr

piqpq

i`1,qi`1qKbeing a single iteration of the

qi`1 Ñqi`1 loop.

Then we can write:

BS “BSelseB`S. (5.8.1)

S-decompositions. Consider any pathwPJr

piq

pqi`1,qi`1q`Kwith shapeS. From proposi-

tions 5.15 and 5.16, we can unambiguously decomposew“w1w2¨ ¨ ¨wlwf, where:

1. each substringw1 P tw1,w2, . . . ,wl,wfuis a self-loop atqi`1:w1 PJr

piqpq

i`1,qi`1q`K,

2. each sub-path qi`1 Ñw

1

qi`1 for w1 P tw

1,w2, . . . ,wlu has shape Sw1 such that Sw „S, and for each proper looping prefix w2 ofw1 (i.e. such that|w2

| ň |w1

|and

qi`1 Ñw2 qi`1),Sw2 ĹS, and

3. the final sub-path wf is also a self-loop: wf P Jr

piq

pqi`1,qi`1q˚K, but has a strictly

smaller shapeSf ĹS. (Note that the final sub-pathwf is possibly even empty.) We call this splitw“w1w2¨ ¨ ¨wlwf theS-decomposition ofw. See figure 5.5.

Summarizing the segments of theS-decomposition. We will now construct expression

vectorsAS1which summarize these minimal sub-pathsw1 P tw1,w2, . . . ,wlu. For each shape S1

„ S, letLfirstpS1

q be the set of non-empty stringsw1 P Jr

piq

pqi`1,qi`1q`Ksuch that all

proper prefixeswpreofw1have shapeSpre ĹS1. Observe that for eachw1 P tw1,w2, . . . ,wlu,

w1

PLfirstpSw1q. The stringw1 can itself be unambiguously written asw1 “wprewsuff, where wsuff Prpiq

pqi`1,qi`1qis a single iteration of theqi`1 Ñqi`1 loop. Ifwpre has shapeSpre, and wsuff has shape Ssuff, then they are summarized by the expression vectors BSpre and RpSiq

suffp

qi`1,qi`1qrespectively. We have already constructed both of these expression vectors by the induction hypothesis. Therefore, we can define:

AS1 “ ÿ S1¨S2“S1,S1ĹS1 BS1¨R piq S2pqi`1,qi`1q. (5.8.2) By construction, we have:

Proposition 5.18. For each shape S1

„ S, the expression vectorAS1 summarizes all paths in LfirstpS1

q.

Short and longS-decompositions. Pick a small constantl0, and consider stringswsuch

thatqi`1 Ñw qi`1 with shape Sand with shortS-decompositionw “w1w2¨ ¨ ¨wlwf, i.e. lďl0. All such strings are easy to summarize: for eachlP t1, 2, . . . ,l0u, and for each shape

S1 „S, we define: A1S1 “AS1, and Al`1 S1 “ ÿ S1¨S2“S1 AiS 1 ¨AS2, so that AăSl1 “ l´1 ÿ j“1 AjS1. (5.8.3)

This still leaves the problem of strings with arbitrarily longS-decompositions. The following result, which is an immediate consequence of proposition 5.17, is an important first step. Recall that we defined a stable shapeSas one with the property that ifuÑSvthenvÑSv. Proposition 5.19. Let there bekregisters in the SSTM. Pick a stringwPJr

piq

pqi`1,qi`1q`K

with shape S. Let w “ w1w2¨ ¨ ¨wlwf be its S-decomposition. Then for each sequence of k

consecutive segments,w1

“wjwj`1¨ ¨ ¨wj`k´1,Sw1 is stable. There are two main consequences of this result:

1. For non-stable shapes,lăk, and they are therefore easy to summarize.

2. If theS-decomposition is divided into “k-segments”, each composed ofkconsecutive segments,w“ pw1w2¨ ¨ ¨wkq ¨ pwk`1wk`2¨ ¨ ¨w2kq ¨ ¨ ¨ pwl1qwf, then eachk-segment

ws,m“wmk`1wmk`2¨ ¨ ¨wpm`1qk

attains a stable shape. See figure 5.6.

(a) Every non-support register u R SupppSq is reset while processing ws,m. The ultimate value ofuis therefore a function of the suffixwl´k`1wl´k`2¨ ¨ ¨wlwf.

(b) If v P SupppSq, then every incoming register while processing ws,m was reset while processing the previous segmentws,m´1. The value appended tovwhile processingws,m is thereforeentirely determinedbyws,m´1¨ws,m.

We will write an expressionfwhich mapsws,m´1ws,mto the value appended to

vafter processingws,m. The expression of interest will then be chainpf,rq, with

qi`1 qi`1 qi`1 u u u v v v w w Ss,m´1„S, and is stable ws,m´1 “ wpm´1qk`1wpm´1qk`2 ¨ ¨ ¨wmk Ss,m„S, and is stable ws,m“ wmk`1wmk`2¨ ¨ ¨wpm`1qk

Figure 5.6: Analyzing data flows while iteratingk-segments. The entire pathqi`1Ñwqi`1

has shapeS, which is stable. The S-decompositionw “ w1w2¨ ¨ ¨wlwf is divided intok-

segmentsws,m “wmk`1wmk`2¨ ¨ ¨wpm`1qk ofkconsecutive iterations. In this figure, we

show two consecutivek-segments,ws,m´1ws,m. By proposition 5.19, eachk-segment itself has a stable shape.