The present application generally relates to allocation of stacked registers, and more particularly, to an inter-procedural allocation of stacked registers for a processor having an architecture similar to Intel's Itanium® processor.
Processors typically have no stacked registers inside the processor and are unable to implement a hardware-based stack frame architecture. An application calling a new procedure requires a task switch operation, in which the current stacked register information needs to be stored on the main memory stack of the calling application. Once the called procedure exits, stacked register data from the calling procedure is repopulated inside the processor from the main memory stack before execution continues. The return values of the called procedure are largely stored in memory with retrieval requiring expensive memory reads.
Intel's Itanium® processor includes 128 general integer registers. The first 32 registers, i.e., r0–r31, are static registers, which are visible to all procedures. The remaining 96 registers, i.e., r32–r128 are stacked registers, which are local to each procedure. The set of stacked registers visible to a given procedure is called a register stack frame. Intel's Itanium® processor also includes a Register Stack Engine (RSE), which is responsible for mapping a register stack frame to stacked registers in the physical register file. When a procedure is called, the stacked registers are renamed such that caller's first register in the output area becomes r32 for the callee. The input area of callee starts from the first of caller's area. Parameters passed to callee through the output area of caller's register stack frame. When callee returns, the register renaming is restored to the caller's configuration. This mechanism allows registers of caller to be preserved in register file instead of storing to memory.
If not enough stacked registers are available, RSE will overflow the oldest register stack frames to memory to make room. The overflowed register stack frames will be stored to a memory area called backing store. Once a function returns, RSE restores the register stack frame from backing store to registers. This process is automatically done by RSE and transparent to a compiler.
RSE fills stall program execution. When the total stacked registers allocated from the active procedures on call stack exceeds the allowed stacked register, a stacked register overflow occurs and the program execution is stalled to wait for the completion of RSE processing. Similarly, the RSE fill will also stall the execution. Therefore, maximizing the usage of stacked registers in each procedure may not be optimal as it may cause delays in program execution. In particular, programs with high RSE costs as a percentage of their overall execution cost will be highly affected by RSE fills.
a)–2(d) show a listing of a stacked register quota algorithm in accordance with the teachings of the present disclosure.
a) shows a listing of an exemplary program used to illustrate a stacked register quota algorithm in accordance with the teachings of the present disclosure.
b) shows a weighted call graph of the exemplary program of
c) shows a call graph of the exemplary program of
a)–4(e) show exemplary snapshots of the algorithm of
a)–6(c) show another exemplary program used to illustrate a stacked register quota algorithm in accordance with the teachings of the present disclosure.
A computer system and method for allocation of stacked registers for a processor having a similar architecture as that of Intel's Itanium® processor is disclosed. The disclosed method includes a three step process. Step I determines an intra-procedural stacked register usage by a program having a plurality of procedures. In step II, the disclosed method performs an inter-procedural analysis to assign quota of stacked register usage to every procedure. In step III, each procedure is allocated stacked register usage based on the quota assignments of step II.
The storage device of 20 may be any of the various storage devices used with a computer system such as, an internal drive or an external drive. The computer system 10 also includes a communications bus 30. The communications bus 30 is used to communicate information between various components within the computer system 10 as well as to communicate with communication channels outside the computer system 10.
The memory 60 is used to store data and/or software. It typically includes a volatile memory used to store information temporarily while the computer system 10 is in use. The volatile memory may be implemented by any type of random access memory device such as SDRAM, DRAM, RAMBUS, etc., or any other type of memory used in computers. The memory 60 may also include non-volatile memory, implemented by any known type of read-only memory (ROM) such as flash memory, EPROM, etc.
For the purpose of this description, a machine-accessible medium includes any mechanism that provides (i.e., stores and/or transmits) information in a form accessible by a machine, such as the computer system 10 (e.g., a computer, network device, personal digital assistant, manufacturing tool, any device with a set of one or more processors, etc.). For example, a machine-accessible medium includes recordable/non-recordable media, such as the memory 60 and the storage device 20, as well as electrical, optical, acoustical or other form of propagated signals (e.g., carrier waves, infrared signals, digital signals, etc.).
The illustrated example computer system 10 employs a power supply 40. The power supply 40 is operatively connected to the storage device 20 as well as to a number of other components in the computer system 10 (e.g., the processor 50, the memory 60, etc., as is conventional). The computer system 10 also includes an input-output controller 70 that communicates with a number of input and output devices. The input device(s) permit a user to enter data and commands into the processor 50. The input device(s) can be implemented by, for example, a keyboard, a mouse, a touch-screen, a track-pad, a trackball, etc. The output device(s) can be implemented, for example, by any display device such as a printer, a speaker, a monitor, etc.
The processor 50 is used to manage various resources and processes within the computer system 10. The processor 50 includes a plurality of memory registers that are accessed in a stacked manner, and therefore, are conventionally referred to as stacked registers. The stacked registers are used to store data for local variables, function parameters, and the return address for function calls. High-level language compilers typically compile a program to generate code and incorporate in the code procedures for moving parameters or data between the memory 60 and the staked registers. The code uses the stacked registers to pass parameters to a procedure that is executing in the processor and to retrieve the function's return value for the caller.
The processor 50 includes a hardware implementation inside the processor that automatically manages overflows of the stacked registers of the processor 50. Intel's Itanium® processor family also includes such a stacked register overflow management implementation, which is referred to as the Register Stack Engine (RSE). The RSE helps a subset of the processor's general stacked registers handle stacked register overflows. Each time a procedure is called by a program, it is allocated a group of stacked registers of the processor 50. The allocated stacked registers are temporary locations that store operands local to the procedure and those that are input and output from the procedure. When nested procedure calls exhaust all the available stacked registers of the processor 50, the RSE automatically overflows information from the stacked registers to the memory 60. Thus, the RSE frees up stacked register space for newly called nested procedures. When the stacked register resources on the processor are available again, the RSE moves the stacked register overflow information back into the stacked registers from the memory 60. Accordingly, the RSE performs a load and spill operation each time the stacked register overflows.
One of ordinary skill in the art will appreciate that the RSE or similar hardware implemented stacked register overflow management methods can be implemented on any processor that includes stacked registers. Accordingly, the disclosed method is not exclusive to Intel's Itanium® processor architecture and can be implemented in any type of processor that includes a hardware or software implementation, such as the RSE, for managing overflow of the processor's stacked registers.
The disclosed method minimizes spill-to-memory access time by providing a tradeoff between memory access cycles associated with each explicit load and spill operation, and memory access cycles associated with RSE. As will become apparent in the following, the disclosed method may assign a larger quota to procedures that have a lower RSE cost than the load and spill cost. Conversely, the disclosed method may assign a smaller or zero quota to procedures that have a higher RSE cost than the load and spill cost. In other words, the disclosed method provides a tradeoff between the load and spill cost and RSE cost between the explicit load and store cycles in intra-procedure stacked register allocation in individual procedures and the inter-procedure stacked register allocation, to minimize spill-to-memory access time.
In step I of the disclosed method, which is the intra-procedural stacked register usage estimation step, a weighted call graph G of the procedures in a program is constructed based on performing a first pass intra-procedure stacked register allocation. The weighted call graph G includes the weight of total invocation frequency of each procedure after the first pass. Furthermore, two parameters are estimated for each procedure in step I, a stacked register usage (“sru”) and a load/store cycles saved (“lscs”). The sru is in integer form and represents the total number of stacked registers used by each procedure during the first pass. The lscs for a specific stacked register usage is the total load and spill cycles saved by using the stacked register. Depending on control flow in a program, a load and spill operation may not be executed each time a procedure is invoked. Accordingly, the lscs value may be a fractional number. Thus, in step I, the weighted call graph G for each procedure is constructed, which includes the total invocation frequency, the sru, and the lscs of each procedure.
Before proceeding with step II of the disclosed method, however, certain hardware parameters of the processor architecture are also known. Two such hardware parameters are the upper bound of stacked registers (“bound”), and the cost for each stacked register overflow (“per_cost”). Bound represents the number of stacked registers that are available to procedures. For example, Intel's Itanium® processor has 96 stacked registers, and thus, bound for Intel's Itanium® processor is equal to 96.
Step II of the disclosed method, i.e., the intra-procedural stacked register quota assignment step, is shown in
In the weighted call graph G, hot regions of interest are where the cost/benefit of stacked register allocation appears to be most significant. Referring to
Function Find_Hot_Region(G) finds a hot region by determining whether invocation frequency of the hot spot procedure by a caller of the hotspot procedure is above a certain threshold. The function Find_Hot_Region(G) can also determine whether the invocation frequency of a procedure by the callee of the hotspot procedure is above a certain threshold. For example, a callee threshold is determined by the following equation:
In the above equation, the hot region is extended forward of the hot spot, or extended to procedures called by the hotspot procedure. Also, t and t′ are two threshold values decided by a compiler, x is the hotspot procedure, and y is the callee of x, which is a procedure call most frequently by x. Similarly, caller_threshold(x,y) is defined in the function Find_Hot_Region(G) so that the hot region can also extend backward from the hotspot, or extend to procedures calling the hotspot procedure. After each hot region is identified, the Function Find_Hot_Region(G) will be called again by Main(G) to identify more hot regions from the remaining procedures of the weighted call graph G, i.e., the procedures not in any hot region yet.
After the identified hot regions h in set H are processed one at a time in the function Find_Hot_Region(G), every stacked register usage r by procedures p within hot region h is inserted into a list L in ascending order of lscs by calling function Construct_Sorted_List(h) shown in
In the first segment, if the procedure p in which stacked register usage r is used is not a self-recursive procedure, then the stacked register usage r is kept and the quota of procedure p increases by one because there is no RSE cost incurred by procedure p. If procedure p is self-recursive, all stacked registers used by procedure p will overflow per invocation of the procedure p by itself. Therefore, if accumulated stacked register usage does not exceed bound and p is self-recursive, RSE cost caused by r is computed as follows:
Call_Edge_Freq(p→p)*per_cost
For a self-recursive procedure, if lscs is greater than RSE cost, the usage r is kept and quota of p increases by one. However, if lscs is not greater than RSE cost, the quota of p is not increased by one. In other words, the usage r of stacked registers should be taken away to reduce overall memory access time.
In the second segment of Quota_Assignment(L,h), where the accumulated stacked register usage exceeds bound, each additional stacked register usage in p may cause a stacked register overflow per invocation of procedure p. Therefore, once the accumulated stacked register usage exceeds bound, then the accumulative RSE cost caused by each additional stacked register usage could be computed as the product of procedure p's called frequency from its caller in the hot region and the per_cost, as shown in line 59 of
In the above-described quota assignment, the overlapping of stacked registers between adjacent procedures in the call chain is not considered in the accumulated stacked register usage computation. The overlapping of stacked registers occurs when passing parameters between procedures. However, if the stacked register is used for passing parameters, the variable count of Quota_Assignment(L,h) that is used for calculating the accumulated stacked register usage does not increase by one.
Referring to
In step II of the disclosed method, the hotspot of program P is first identified. As described above, a method of identifying a hot spot is to calculate the total accumulated stacked register usage of each procedure, which is the product of edge frequency of each procedure and its sru. For procedures A, B, C, D, E and F, total accumulated stacked register usages are 60, 5000, 6000, 60, 5050, and 60, respectively. Referring to
The three identified hot regions are processed one at a time. Hot region {A, B, C} is processed first, and a sorted list L is constructed for the hot region {A, B, C} by calling the function Construct_Sorted_List(h), as shown in
d) shows the function Quota_Assignment(L,h) when count is equal to bound. When count exceeds bound for a procedure, each additional stacked register usage is decided by comparing the procedure's lscs with its RSE cost caused by exceeding bound. In order to reduce the explicit load and store operation cycles as much as possible, stacked registers are assigned to procedures where the saving in spill cost exceeds the cost of using the stacked registers. When the accumulated stacked register usage on a call path in a hot region exceeds bound, the quota assigned to some procedures is reduced in order to reduce the total spill to memory access cycles.
In procedure B, obtaining each stacked register assignment could save 50 cycles (the invocation frequency of 100 multiplied by lscs of 0.5) in the explicit load/store operation cycles. However, procedure B incurs 100 cycles of RSE. Accordingly, procedure B should not be assigned any stacked registers, and should not be assigned a quota. Taking away procedure B's quota will save 2500 (50×50) load/store cycles. Thus when quota assignment for the disclosed example concludes, procedures A, B and C will be assigned stacked register quotas of 60, 0, 60, respectively as shown in
The disclosed method can be modified to extend a hot region as described above to an extensive hot region, i.e., an area extending along several call paths instead of only a call-intensive trace. An example of when such a modification may provide a more robust quota assignment is shown in the weighted call graph G of
In the disclosed example, if the accumulated stacked register usage within a hot region exceeds bound, each additional stacked register usage will cause a stacked register overflow. However, such is not true for all programs. Referring to programs illustrated in
Persons of ordinary skill in the art will appreciate that, although the teachings of the invention have been illustrated in connection with certain embodiments, there is no intent to limit the invention to such embodiments. On the contrary, the intention of this application is to cover all modifications and embodiments fairly falling within the scope of the teachings of the invention.
Number | Name | Date | Kind |
---|---|---|---|
5564031 | Amerson et al. | Oct 1996 | A |
5640582 | Hays et al. | Jun 1997 | A |
6487630 | Bui | Nov 2002 | B1 |
20040015901 | Koseki et al. | Jan 2004 | A1 |
20040064632 | Lin | Apr 2004 | A1 |
20040237076 | Vedaraman et al. | Nov 2004 | A1 |
Number | Date | Country | |
---|---|---|---|
20050149918 A1 | Jul 2005 | US |