This invention relates to an intermediate representation form of source code, and more specifically but not exclusively, to an intermediate representation of source code that provides effective and explicit control and data flow information.
In compiler design, Intermediate Representation (IR) is important for analyzing and optimizing the data and control flow of source code. There are commonly known IR forms such as Static Single Assignment (SSA) that source code can be converted into. Source code include but are not limited to programming statements written in a computer language or any form of statements readable by a compiler or machine.
In SSA IR form, every definition or assignment of a variable in the source code is represented as an assignment of a distinct instance (or version) of the variable.
In
SSA IR form, although it can make several optimizations such as constant propagation, copy propagation and symbolic analysis more effective, only provides control-flow-insensitive data flow information. This is observed in lines 4, 16 and 24 of the SSA IR form 200 where phi (φ) functions introduce new versions of a variable to cover all possible versions reaching at the merge point of different control flow path. However, the phi (φ) function does not contain any control flow information. It does not show which version of the variable comes from a particular control flow path. In SSA IR form 200, the definitions of variable version X3 and X4 are given in D3 and D4 respectively as
X3=φ (X1, X2) and X4= (X1, X3)
The phi (φ) function in D3 shows that X3 is assigned from either X1 or X2 but it does not have control flow information on how X1 and X2 reach the D3.
Gated Single Assignment (GSA) and Thinned Gated Single Assignment (TGSA) are two prior proposed extensions to SSA IR form to provide additional control flow information. In GSA and TGSA forms, control flow condition predicates are integrated into the representation of SSA IR form. A gamma (γ) function is used instead of phi (φ) function in SSA IR form 200 to represent merging of different versions of variable X. In TGSA form, D3 and D4 define X3 and X4 respectively as
X3=γ (P, X1, X2) and X4=γ (P, γ(Q, X1, X3), X3)
In GSA form, D3 and D4 define X3 and X4 respectively as
X3=γ (P, γ (Q, Ø, X1), X2) and X4=γ (P, γ (Q, X1, γ(S, X3, Ø)), γ(S, X3, Ø))
The difference between GSA and TGSA form is that GSA form provides more accurate control flow information by showing all control predicates required to reach the current definition. A null (Ø) in the gamma (γ) function of GSA form shows a control flow path that does not reach the current definition.
GSA and TGSA do not provide explicit accurate path information important in control flow sensitive analysis. For example, in GSA form, definition D4 cannot provide the path information from definition of X1 (D1) to definition of X4 (D4) directly. An indirect way is to expand the pseudo assignment expressions of D4's gamma (}) function. The expanded expression is given as
X4=γ(P, γ(Q, X1, γ(S, γ(P, γ(Q, Ø, X1), X2), Ø)), γ(S, γ(P, γ(Q, Ø, X1), X2), Ø))
This expanded expression has unnecessary and redundant path predicates.
In TGSA form, since some control path information is dropped in the gamma (γ) function, it does not support accurate path sensitive analysis. For example, X1 can only reach D3 when the condition predicate Q is false but the gamma (γ) function in D3 in TGSA form does not provide any information regarding the condition predicate Q.
The features and advantages of embodiments of the invention matter will become apparent from the following detailed description of the subject matter in which:
Reference in the specification to “one embodiment” or “an embodiment” of the invention means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the invention. Thus, the appearances of the phrase “in one embodiment” appearing in various places throughout the specification are not necessarily all referring to the same embodiment.
Embodiments of the invention provide a Path Sensitive single Assignment (PSA) IR form with effective and explicit control and data path information to support control flow sensitive optimizations such as path sensitive symbolic substitution, array privatization and speculative multi threading.
In one embodiment of the invention, the PSA form is defined based on an IR form including but is not limited to, an SSA IR form. In PSA form, a versioned variable defined by a phi (φ) function in the base SSA IR form is termed as a φ variable. A versioned variable not defined by a phi (φ) function is termed as a non-φ variable. For example in
One embodiment of PSA form is defined by three properties as described below. Other embodiments of PSA form may have more than three properties where the additional property (or properties) does not affect the operation of the invention described herein.
The first property of PSA form is as follows:
For a versioned variable vi of a variable v in a node x, the versioned variable v'is gamma function from a node z is recursively defined as
vi=γz=
v
i=γz=γn1 (=γn2= . . . =γnm)
For a versioned variable vi of a variable v in a node x, its gamma function refers to its gamma function from the entry node of the CFG.
The second property of PSA form is as follows:
In PSA form, for each versioned variable vi of variable v defined in node x with a phi (φ) function in the base SSA IR form where node x is not a loop header, the corresponding phi (φ) function is replaced by the gamma function of vi.
The third property of PSA is as follows:
In PSA form, for each versioned variable vi of variable v defined in a loop header node x with a phi (φ) function in the base SSA IR form, the corresponding phi (φ) function is replaced by the following mu (μ) function:
v
i=μ(vinit, viter)
where vinit is the gamma function of the initial versioned variable of variable v entering the loop header from outside of the loop body, and viter is the gamma function of versioned variables of variable v reaching the loop header from the back edges of the loop. In this case, the gamma function of vi equals to vi itself.
In the definition of PSA form, besides defining new versioned variables, the gamma functions keep control path information. The gamma function in PSA form keeps the basic attribute of SSA IR form and only one definition exists for each use. Therefore, all existing SSA IR form based analysis can be applied in PSA form. In addition, PSA form has an advantage over SSA, GSA or TGSA IR forms. The gamma function in PSA form keeps all essential control flow information and eliminates unnecessary predicates at the same time. For example, from all the out-going paths of a branch node in a CFG, if the same versioned variable reaches the same joined node, no gamma function is built using the condition predicate of the branch node. PSA form keeps only effective and explicit control and data flow information and detailed examples are described later.
One embodiment of PSA form breaks out the implicit rule in SSA, GSA and TGSA IR forms where versioned variables defined by phi (φ) functions or gamma (γ) functions are the arguments of the other phi (φ) functions or gamma (γ) functions. As these versioned variables are defined by pseudo assignment in the joined node, redundant path information may be introduced. For example, as described earlier, the path information from definition D1 to definition D4 in GSA form has many condition predicates appearing in the middle of the reaching paths and the expanded pseudo assignment expression of D4's gamma function is long and unwieldy. In PSA form, definition D4 is defined as
X4=γ (P, γ(Q, X1, γ(S, X1, Ø)), γ(S, X2, Ø))
In PSA form, no other versioned variables produced by the gamma functions which exist between the entry of the CFG and the joined node appear as the arguments of the gamma function in the joined node. Therefore, the path information is simplified and readily available as compared to GSA form.
If step 615 is true, the flow goes to step 620 where the gamma functions of the versioned variables in the predecessor nodes are merged. This is performed using function_merge( ) based on a set of merging rules to be described with reference to later figures. When the merged gamma function is obtained in step 620, the merged gamma function is propagated to all successor nodes of the current node in step 625. If step 615 is false, the flow goes to step 625 where the gamma function of the versioned variable in the predecessor node is propagated to all successor nodes of the current node without performing the merging step of 620.
Step 630 determines if the gamma function of the current node changes. If it changes, the Boolean variable EXIT is set as false in step 635. If it doesn't change, the flow goes to step 640 to determine if the current node has more than one successor node. If the current node has more than one successor node, a function create_gamma_function( ) is performed for each successor node in step 645. In the function create_gamma_function( ), a new gamma function in accordance with the definition of PSA form is created based on the propagated gamma function(s) from the predecessor node(s) in step 645. The flow goes to step 650 and the current node is removed from the list of nodes obtained in step 605. If the current node does not have more than one successor node, it goes to step 650 as described earlier. Step 655 determines if the list of nodes is empty. If it is empty, the flow ends and goes to step 660. If it is not empty, the flow goes back to step 610. This ensures that each node in the list is processed.
γ (cγ1, γ2)+γ (c, γ3, γ4)=γ (c, γ1+γ3, γ2+γ4)
γ+Ø=Ø+γ=γ
γ (c, γ1, γ1)=γ1
γ1=γ( P, γ(Q, Ø, D0), Ø) //from Edge 1356
γ2=γ( P, Ø, γ(T, D1, Ø)) //from Edge 1358
Step 815 determines if γ1 and γ2 have the same condition predicate. Since both γ1 and γ2 have the same condition predicate P, step 820 is followed. In step 820, merging rules are used to merge γ1 and γ2. Using rule one of the merging rules described earlier, the following is obtained:
Using rule two of the merging rules described earlier, the final result of D3 is obtained:
D3=γ( P, γ(Q, Ø, D0), γ(T, D1, Ø))
The method for obtaining D4 and D5 illustrated in
In the first pass of
γ1=γ(P, D0, Ø) //from Edge 1550
γ2=Ø //from Edge 1562
D3=μ(γ(P, D0, Ø), Ø)
The method for obtaining D2 and D4 illustrated in
After the first pass, edge 1562 is modified. In the second pass illustrated in
γ1=γ(P, D0 , Ø) //from Edge 1550
γ2=γ(P, γ(Qγ(R, D1, Ø), γ(R, D3, Ø)), Ø) //from Edge 1562
D3=μ(γ(P, D0, Ø), γ(P, γ(Q, γ(R, D1, Ø), γ(R, D3, Ø)), Ø))
In the third pass illustrated in
As illustrated in
D5=γ (P, γ (R, D0, D4), γ (R, D1, D4))
The probability of reaching DO to D5 as illustrated in
The system 2000 includes a chipset 2035 with a memory controller 2030 and an input/output (I/O) controller 2040. A chipset typically provides memory and 1/O management functions, as well as a plurality of general purpose and/or special purpose registers, timers, etc. that are accessible or used by a processor 2025. The processor 2025 may be implemented using one or more processors.
The memory controller 2030 performs functions that enable the processor 2025 to access and communicate with a main memory 2015 that includes a volatile memory 2010 and a non-volatile memory 2020 via a bus 2065.
The volatile memory 2010 includes but is not limited to, Synchronous Dynamic Random Access Memory (SDRAM), Dynamic Random Access Memory (DRAM), RAMBUS Dynamic Random Access Memory (RDRAM), and/or any other type of random access memory device. The non-volatile memory 2020 includes but is not limited by, flash memory, Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), and/or any other desired type of memory device.
Memory 2015 stores information and instructions to be executed by the processor 2025. Memory 2015 may also stores temporary variables or other intermediate information while the processor 2025 is executing instructions.
The system 2000 includes but is not limited to, an interface circuit 2055 that is coupled with bus 2065. The interface circuit 2055 is implemented using any type of well known interface standard including, but is not limited to, an Ethernet interface, a universal serial bus (USB), a third generation input/output interface (3GIO) interface, and/or any other suitable type of interface.
One or more input devices 2045 are connected to the interface circuit 2055. The input device(s) 2045 permit a user to enter data and commands into the processor 2025. For example, the input device(s) 2045 is implemented using but is not limited to, a keyboard, a mouse, a touch-sensitive display, a track pad, a track ball, and/or a voice recognition system.
One or more output devices 2045 connect to the interface circuit 2055. For example, the output device(s) 2050 are implemented using but are not limited to, light emitting displays (LEDs), liquid crystal displays (LCDs), cathode ray tube (CRT) displays, printers and/or speakers). The interface circuit 2055 includes a graphics driver card.
The system 2000 also includes one or more mass storage devices 2060 to store software and data. Examples of such mass storage device(s) 2060 include but are not limited to, floppy disks and drives, hard disk drives, compact disks and drives, and digital versatile disks (DVD) and drives.
The interface circuit 2055 includes a communication device such as a modem or a network interface card to facilitate exchange of data with external computers via a network. The communication link between the system 2000 and the network may be any type of network connection such as an Ethernet connection, a digital subscriber line (DSL), a telephone line, a cellular telephone system, a coaxial cable, etc.
Access to the input device(s) 2045, the output device(s) 2050, the mass storage device(s) 2060 and/or the network is typically controlled by the I/O controller 2040 in a conventional manner. In particular, the I/O controller 2040 performs functions that enable the processor 2025 to communicate with the input device(s) 2045, the output device(s) 2050, the mass storage device(s) 2060 and/or the network via the bus 2065 and the interface circuit 2055.
While the components shown in
Although examples of the embodiments of the disclosed subject matter are described, one of ordinary skill in the relevant art will readily appreciate that many other methods of implementing the disclosed subject matter may alternatively be used. For example, the order of execution of the blocks in the flow diagrams may be changed, and/or some of the blocks in block/flow diagrams described may be changed, eliminated, or combined.
In the preceding description, various aspects of the disclosed subject matter have been described. For purposes of explanation, specific numbers, systems and configurations were set forth in order to provide a thorough understanding of the subject matter. However, it is apparent to one skilled in the relevant art having the benefit of this disclosure that the subject matter may be practiced without the specific details. In other instances, well-known features, components, or modules were omitted, simplified, combined, or split in order not to obscure the disclosed subject matter.
Various embodiments of the disclosed subject matter may be implemented in hardware, firmware, software, or combination thereof, and may be described by reference to or in conjunction with program code, such as instructions, functions, procedures, data structures, logic, application programs, design representations or formats for simulation, emulation, and fabrication of a design, which when accessed by a machine results in the machine performing tasks, defining abstract data types or low-level hardware contexts, or producing a result.
While the disclosed subject matter has been described with reference to illustrative embodiments, this description is not intended to be construed in a limiting sense. Various modifications of the illustrative embodiments, as well as other embodiments of the subject matter, which are apparent to persons skilled in the art to which the disclosed subject matter pertains are deemed to lie within the scope of the disclosed subject matter.