• 沒有找到結果。

Approach 1:Pruning Method for Address Offset Assignment

Chapter 3 Proposed Approaches of Address Offset Assignment

3.2 Approach 1:Pruning Method for Address Offset Assignment

In this section, we describe a pruning method for the address offset assignment problem in presence a single address assignment and m modify registers. We trace access graph and decrease search time by pruning some paths that are not possible to be optimal solution.

Given a variable set V and a variable access sequence S of a function, the Bartley’s access graph is constructed in Figure 3-5 and the maximum weight path cover is shown in Figure 3-6(a). From the maximum weight path cover, the address assignment is in Figure 3-6(b). Consider 1AR and 1MR for this example, we get the distance count in Figure 3-6(c) derived from the address assignment in Figure 3-6(b).

The distance is 1 can be subsumed by auto-increment or auto-decrement operations, and the distance is 3 can be subsumed by auto-modify operation via assigning 3 to MR. Then we calculate the cost by the cost function in definition 3.5. So the total cost is 6 in Figure 3-6(d) is the cost of initial 1AR and 1MR, and distance count that can not be subsumed by auto-increment, auto-decrement, and auto-modify operations (count of distance 2 or 4).

Figure 3-5 An example of access graph for pruning

Figure 3-6 The solution of maximum weight path cover for Figure 3-5

Then, we explore the access graph in Figure 3-5 using depth-first search (DFS) that each vertex in access graph can be the original source and take the cost in Figure 3-6(d) as the cost bound to pruning some search path that cost is larger than cost bound. The strategy followed by depth-first search is, as its name implies, to search

“deeper” in the graph whenever possible. In depth-first search, edges are explored out of the most recently discovered vertex u that still has unexplored edges leaving it.

When all of u’s edges have been explored, the search “backtracks” to explore edges leaving the vertex from which u was discovered. This process continues until we have discovered all the vertices that are reachable from the original source vertex. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. This entire process is repeated until all vertices are discovered. Next, we give an example to see the pruning operation.

Consider the example in Figure 3-7(a). The DFS start from node “a” and explore to “c” currently (edges in bold). The current address assignment is shown in Figure

3-7(b) that “a” is assigned the address “0”, “b” is “1”, and “c” is “2”. The current distance count is shown in Figure 3-7(c) that the count of distance 1 is 2 (w(a,b)+w(b,c)) and the count of distance 2 is 3 (w( ca, )). Because the current distances are only 1 and 2, which can be subsumed by auto-increment, auto-decrement and auto-modify operation. So the current cost 2 is the cost of initializing 1AR and 1MR.

Now there are two uncovered nodes “d” and “e” that are adjacent to node “c”.

First, we choose node “d” as shown in Figure 3-7(e), and the current address assignment and distance count are shown in Figure 3-7(f) and Figure 3-7(g). And the current cost 7 in Figure 3-7(h) is cost of 1AR and 1MR initialization and distance count that can not be subsumed by auto-increment, auto-decrement and auto-modify operations (count of distance 3). Here, we find that the current cost 7 is larger than cost bound 6, so we stop search deeper from node “d” in current path and backtrack to node “c”. Therefore, we choose another node “e” that is adjacent to node “c” in Figure 3-7(a). The results of this choice are shown in Figure 3-7(i) to Figure 3-7(l). The current cost is not larger than cost bound, so we this search can be continue and will not be pruned.

Via our pruning method, we can search all possible paths to find the optimal solution and save some search time. The algorithms of our pruning method are in Figure 3-8 and Figure 3-9. We will discuss our pruning method with previous searches and our genetic algorithm about the time complexity and effect in later section and chapter.

Figure 3-7 An example of pruning for DFS

Consider the algorithm in Figure 3-8. This algorithm takes an access sequence

“L” which extracted from high level code as input, and produces an address offset assignment as output. In line 3, access graphG(V,E,w) is produced from the access sequence “L”. Line 4 produces an address offset assignmentπ by Liao’s SOA 1 heuristic algorithm mentioned in Chap 2. We set the cost_bound via the cost function in definition 3.5 that takesπ as its input. Then we start to explore the access graph 1

) , , (V E w

G using depth-first search (DFS) that each vertex in G can be the original source. The DFS-VISIT implements the DFS procedure with pruning.

Figure 3-8 Depth first search (DFS) for access graph

Consider the procedure DFS-VISIT in Figure 3-9. In each call DFS-VISIT(u), vertex u is checked if it can be added to tmp_π that record the current unfinished address offset assignment. Lines 2-3 add u totmpin order and set u is explored.

Line 4-5 check compute the cost of tmp_π and check cost. When cost≥ cost_bound, we prune the following process of π and leave DFS-VISIT(u). Otherwise, if

1 // INPUT: Access Sequence, L

2 // OUTPUT: Constructed Assignment to minimize the cost function in definition 3.5.

Figure 3-9 DFS with pruning for access graph

cost less than cost_bound, we further check the size of current tmp_π in line 6. If the size of current tmp_π is equal the size of variable set, this means that one solution is found. We record the current best solution in π and reset cost_bound from this solution in lines 7-8. If all variable are not covered, line 11 examines each vertex v adjacent to u and recursively visit v. We say that edge (u, v) is explored by the depth-first search. Finally, after every edge leaving u has been explored, lines 16-17 delete u in tmpand set u is unexplored. This causes the next search from the predecessor of u. When all vertex u is explored, the algorithm is stopped and we get the optimal path (i.e., the optimal address offset assignment).

1 DFS-VISIT(u) {

3.3 Approach 2:Genetic Algorithm for Address Offset

相關文件