CN111857816A - Register allocation method and device, electronic equipment and computer storage medium - Google Patents

Register allocation method and device, electronic equipment and computer storage medium Download PDF

Info

Publication number
CN111857816A
CN111857816A CN201910339025.7A CN201910339025A CN111857816A CN 111857816 A CN111857816 A CN 111857816A CN 201910339025 A CN201910339025 A CN 201910339025A CN 111857816 A CN111857816 A CN 111857816A
Authority
CN
China
Prior art keywords
register
information
calling
registers
parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201910339025.7A
Other languages
Chinese (zh)
Other versions
CN111857816B (en
Inventor
林作健
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201910339025.7A priority Critical patent/CN111857816B/en
Priority claimed from CN201910339025.7A external-priority patent/CN111857816B/en
Publication of CN111857816A publication Critical patent/CN111857816A/en
Application granted granted Critical
Publication of CN111857816B publication Critical patent/CN111857816B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30098Register arrangements

Abstract

The embodiment of the invention provides a register allocation method, a register allocation device, electronic equipment and a computer storage medium, wherein the register allocation method comprises the following steps: acquiring a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment; acquiring the information of a register used by the target function according to the calling appointed information; and according to the information of the register, allocating a register for the calling instance so as to transfer the parameters of the target function through the register. By the embodiment of the invention, the transfer cost of the register parameter is effectively reduced, and the code compiling efficiency is improved.

Description

Register allocation method and device, electronic equipment and computer storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a register allocation method, a register allocation device, electronic equipment and a computer storage medium.
Background
Register allocation is a method of increasing the execution speed of a program by allocating program variables to registers as much as possible. In an actual compiler, various different ways are adopted to optimize a register allocation algorithm in order to extract performance as much as possible and improve the allocation efficiency of the compiler.
Taking LLVM as an example, LLVM is a framework system for constructing compiler (compiler), and is used to optimize compile-time (compile-time), link-time (link-time), run-time (run-time), and idle-time (idle-time) of a program written in any programming language, and is compatible with existing scripts. Also, LLVM provides intermediate code that is independent of the language, so that intermediate code can be generated from different language codes, thereby enabling different languages to be linked to each other through LLVM. In LLVM, function parameters are defined by ABI (Application Binary Interface) and passed in specified physical registers, and LLVM is represented by copying between physical and virtual registers before and after function call. The register allocator attempts to allocate virtual registers to the same physical registers so that copying can be eliminated. However, in the current LLVM, there is no explicit Calling convention (Calling Conventions, CC) for transferring register parameters, and in practical applications, if a certain register is used, a programmer is required to set an additional Calling convention for the register to be used, such as a Calling convention defining v8r0r3CC, to specifically handle the cases of r0 and r3 transfer. If the reference needs to be transferred by using the register r4r5, the programmer needs to define a calling convention for r4 and r 5.
Therefore, the transmission cost of the register parameters in the LLVM is greatly increased, and the compiling efficiency of the LLVM is reduced.
Disclosure of Invention
Embodiments of the present invention provide a register allocation scheme to at least partially solve the above problems.
According to a first aspect of the embodiments of the present invention, there is provided a register allocation method, including: acquiring a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment; acquiring the information of a register used by the target function according to the calling appointed information; and according to the information of the register, allocating a register for the calling instance so as to transfer the parameters of the target function through the register.
According to a second aspect of the embodiments of the present invention, there is provided a register allocation apparatus including: the first obtaining module is used for obtaining a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment; the second obtaining module is used for obtaining the information of the register used by the target function according to the calling appointed information; and the allocation module is used for allocating a register for the calling instance according to the information of the register so as to transmit the parameter of the target function through the register.
According to a third aspect of embodiments of the present invention, there is provided an electronic apparatus, including: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus; the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the register allocation method according to the first aspect.
According to a fourth aspect of embodiments of the present invention, there is provided a computer storage medium having stored thereon a computer program which, when executed by a processor, implements the register allocation method according to the first aspect.
According to the register allocation scheme provided by the embodiment of the invention, when a register needs to be allocated for a target function to be called, the register is carried in the information of the calling instance according to a preset calling convention, so that the information of the calling instance is analyzed according to the calling convention, the information of the register is obtained from the information, and the register is allocated according to the information to transfer the parameter of the target function. The calling convention includes definition information of all available registers in the current device, that is, the calling convention can find corresponding positions and processes in the calling convention for all available register services of the current device, and a special calling convention does not need to be additionally set for used registers each time corresponding register parameters are transmitted. The method can be used on the current equipment for a long time by one-time setting, effectively reduces the transmission cost of register parameters, and improves the code compiling efficiency.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments described in the embodiments of the present invention, and it is also possible for a person skilled in the art to obtain other drawings based on the drawings.
FIG. 1 is a flowchart illustrating steps of a register allocation method according to a first embodiment of the present invention;
FIG. 2 is a flowchart illustrating steps of a register allocation method according to a second embodiment of the present invention;
FIG. 3 is a block diagram of a register allocation apparatus according to a third embodiment of the present invention;
FIG. 4 is a block diagram of a register allocation apparatus according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments obtained by a person skilled in the art based on the embodiments of the present invention shall fall within the scope of the protection of the embodiments of the present invention.
The following further describes specific implementation of the embodiments of the present invention with reference to the drawings.
Example one
Referring to fig. 1, a flowchart illustrating steps of a register allocation method according to a first embodiment of the present invention is shown.
The register allocation method of the embodiment comprises the following steps:
step S102: and acquiring the target function to be called and the information of calling convention according to the information of the calling example.
In the embodiment of the present invention, the adopted calling convention is different from the conventional calling convention that is required for a specifically used register, and the calling convention in the embodiment of the present invention includes definition information of all available registers in the current device. The definition information includes but is not limited to: indication information (e.g., identification information or pointer information) of each available register, location information (which may also be considered sequence information) of each available register, information about the specific processing of registers and/or parameters in the call convention, and so on. For example, if the current device has 5 available registers (e.g., r0-r4), then the format of the calling convention may be such as: xxxcc: the target function to be called, r0, r1, r2, r3, r 4.
In which, a person skilled in the art can set what registers are available according to actual requirements, and in a possible way, registers other than the reserved registers can be set as available registers.
The call instance is an instance (instance) of a certain call, for example, a function, a call, and a reflection of the LLVM may each have a selection call convention to specify the call. In practical application, according to the functions, calls and reflections, the specific call functions, call points, reflection calls and the like which are correspondingly generated can be regarded as call examples.
The information of the calling instance carries the parameters to be transmitted and the information of the calling convention, wherein the information of the calling convention can be indicated by any appropriate mode, such as the name or the identification of the calling convention.
Step S104: and acquiring the information of the register used by the target function according to the calling appointed information.
As previously described, the calling convention includes information defining all available registers in the current device. Accordingly, the information of the registers can be acquired from the values corresponding to the respective registers in the call convention.
For example, still in xxxcc: the format of the target function to be called, r0, r1, r2, r3, r4 is taken as an example, if xxxcc: f1, undef, undef, r2, r3 and undef, and then the registers used by the target function to be called comprise r2 and r 3.
Step S106: and according to the information of the register, allocating the register for the calling instance so as to transfer the parameters of the target function through the register.
After determining the register used by the target function according to the information of the register, the register may be allocated for the call instance according to a register allocation algorithm currently applied, for example, in a current code generator or a compiler, or by a register allocator responsible for allocating the register therein, so as to perform parameter passing of the target function.
According to the embodiment, when the register needs to be allocated for the target function to be called, the register is carried in the information of the calling instance according to the preset calling convention so as to analyze the information of the calling instance according to the calling convention, obtain the information of the register from the information of the calling instance, and further allocate the register according to the information of the register so as to transfer the parameter of the target function. The calling convention includes definition information of all available registers in the current device, that is, the calling convention can find corresponding positions and processes in the calling convention for all available register services of the current device, and a special calling convention does not need to be additionally set for used registers each time corresponding register parameters are transmitted. The method can be used on the current equipment for a long time by one-time setting, effectively reduces the transmission cost of register parameters, and improves the code compiling efficiency.
The register allocation method of the present embodiment may be performed by any suitable electronic device having data processing capabilities, including but not limited to: server, mobile terminal (such as mobile phone, PAD, etc.), PC, etc.
Example two
Referring to fig. 2, a flowchart illustrating steps of a register allocation method according to a second embodiment of the present invention is shown.
The present embodiment describes a register allocation scheme according to an embodiment of the present invention, taking LLVM as a user of the register allocation method, and taking a call contract for setting the V8 engine as an example.
Based on this, the register allocation method of the present embodiment includes the following steps:
step S202: and generating a calling convention.
This step may include: acquiring information of other registers except a reserved register in current equipment; setting parameter indication information and parameter position information in a calling convention for the other registers; and generating a calling convention according to the parameter indication information and the parameter position information. The format may be as xxxcc: the target function to be called, r0, r1, r2, r3, r 4. In a specific example of a LLVM, it can be as @ some _ call, i 321, i 320, i64 addrspace (1)% obj, i 320, i 325, i 32-1 … …
Compilers typically use registers in three groups as needed: allocable registers, reserved registers, and zero-use registers. Wherein the allocable register is used to assign registers for variables (source variables and temporary variables); the reserved register is a special register reserved for special tasks by the system, such as a stack pointer register, a Display register and the like; the zero register is a very short-lived register used to make a "shortwork". The allocable register can only be applied by calling a subprogram; the reserved register is special during the whole running period of the target code, so that the reserved register can not participate in allocation and can not be used for short time; the zero register is a short register and therefore cannot participate in allocation, and unlike a dedicated reserved register, the system can be used on an as-needed basis. Thus, registers other than the reserved registers in current devices may be considered allocable registers, i.e., available registers in embodiments of the present invention.
After the information of the available register in the current device is acquired, the parameter indication information and the parameter position information in the calling agreement can be set for the register. The parameter indication information is used for indicating a register, such as a register name or a register identifier; the parameter position information is used to indicate the sequential position of the respective registers. In addition, each calling convention has certain functionality, e.g., calling convention "ccc" is a calling convention that matches targets to language C, supports variable-length parameter function calls and tolerates some mismatch between declarations and implementations of functions. Similarly, those skilled in the art can set the calling convention to perform corresponding register allocation and processing on parameters in the convention, such as information of registers and information of parameters passed by using registers.
In a feasible manner, the generating the calling convention according to the parameter indication information and the parameter location information may include: register allocation processing setting is carried out on the other registers, and the other registers are instructed not to carry out data storage processing in a register allocation stage through the register allocation processing setting; and generating the calling convention according to the parameter indication information, the parameter position information and the register allocation processing setting. In the call convention, it is specified that no value is saved to a register during the register allocation phase, the compiler will save all active values to the stack to facilitate finding the security point from the stack space, and since only the register allocator is handling this work, no conflict with the security point generation module will be caused.
Of course, in practical applications, other content may be agreed upon in the calling convention.
In particular, to set the calling convention for the V8 engine in the LLVM, in one possible approach, a calling convention V8cc may be defined, with references defined as all registers except the reserved registers, and the registers used by the V8 engine include r0-r 11. Where there is no parameter, an undefined value is introduced. Furthermore, this type of calling convention is defined such that in the register allocation phase, no values are saved to the registers, the compiler will save all active values to the stack to facilitate finding security points from stack space, and no conflicts will arise since only the register allocator is handling this task.
Through the steps, the setting and the generation of the calling convention are realized, and the calling convention can be used for a long term subsequently after being generated.
Step S204: and acquiring the information of the calling example, and acquiring the target function to be called and the information of calling convention according to the information of the calling example.
Wherein, the calling convention includes definition information of all available registers in the current device.
If the calling instance uses the calling convention in step S202, the target function to be called and the information of the calling convention may be obtained from the information of the calling instance.
For example, if reference needs to be made to r0 and r3, then it is possible to obtain from the information of the calling instance: LLVM IR CALLV8cc function p1(r0, undef, r3, undef … undef). Wherein "function p 1" is the target function to be called, and v8cc is the information of calling convention.
Step S206: and acquiring the information of the register used by the target function to be called according to the calling appointed information.
In a feasible manner, the information of the register used by the target function to be called can be acquired according to the parameter indication information and the parameter location information agreed by the calling convention. In this way, the information of the register can be determined efficiently and quickly.
As previously described, the registers used by the V8 engine include r0-r11, and the corresponding reference forms of the calling convention such as: v8cc target function to be called, r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r 10. According to LLVM IR, callv8cc function p1(r0, undef, r3, undef … undef) can determine that the used registers are r0 and r 3. Then, COPY nodes, parameters used by COPY p1 to r0 and r3, may be generated by SelctionDAG.
Step S208: and according to the information of the register, allocating the register for the calling instance so as to transfer the parameters of the target function through the register.
After the information of the register is obtained, the corresponding register can be allocated for the calling instance to carry out parameter transmission.
If the register allocation processing setting is also set in the call contract, this step may optionally be implemented as: and according to the information of the register and the register allocation processing setting, allocating a register for the calling instance, and storing all activity values in the calling instance into a stack corresponding to the calling instance. So that only the register allocator saves the value of the restoration security point without colliding with the security point generation module.
After all activity values in the call instance are saved in a stack corresponding to the call instance, further optionally, a security point of the call instance may be obtained from the stack; and processing the calling instance according to the safety point. The processing operation of the calling instance is implemented according to the calling convention and the specific code setting of the calling instance, such as code conversion or generation, and the like, which is not limited in the embodiment of the present invention.
In the LLVM, through the above process, the LLVM IR can easily implement the transmission and allocation of registers, no additional calling convention is needed, and the code generation is easier and more efficient. In addition, under the scene that garbage collection and security points are needed, one calling convention can cover a plurality of traditional calls, and the engineering is simple and feasible. In addition, only the register allocator saves the value of the restoration security point and does not conflict with the security point generation module.
It can be seen that, according to the embodiment, when a register needs to be allocated for a target function to be called, the register is carried in the information of the calling instance according to a preset calling convention, so as to analyze the information of the calling instance according to the calling convention, obtain the information of the register from the information, and allocate the register according to the information to transfer the parameter of the target function. The calling convention includes definition information of all available registers in the current device, that is, the calling convention can find corresponding positions and processes in the calling convention for all available register services of the current device, and a special calling convention does not need to be additionally set for used registers each time corresponding register parameters are transmitted. The method can be used on the current equipment for a long time by one-time setting, effectively reduces the transmission cost of register parameters, and improves the code compiling efficiency.
The register allocation method of the present embodiment may be performed by any suitable electronic device having data processing capabilities, including but not limited to: server, mobile terminal (such as mobile phone, PAD, etc.), PC, etc.
EXAMPLE III
Referring to fig. 3, a block diagram of a register allocation apparatus according to a third embodiment of the present invention is shown.
The register allocation device of the embodiment comprises: a first obtaining module 302, configured to obtain a target function to be called and information of a calling convention according to information of a calling instance, where the calling convention includes definition information of all available registers in current equipment; a second obtaining module 304, configured to obtain, according to the information agreed by the call, information of a register used by the target function to be called; the allocating module 306 is configured to allocate a register for the calling instance according to the information of the register, so as to perform parameter transfer of the target function to be called through the register.
The register allocation apparatus of this embodiment is used to implement the corresponding register allocation method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described herein again. In addition, the functional implementation of each module in the register allocation apparatus of this embodiment can refer to the description of the corresponding part in the foregoing method embodiment, and is not repeated herein.
Example four
Referring to fig. 4, a block diagram of a register allocation apparatus according to a fourth embodiment of the present invention is shown.
The register allocation device of the embodiment comprises: a first obtaining module 402, configured to obtain a target function to be called and information of a calling convention according to information of a calling instance, where the calling convention includes definition information of all available registers in current equipment; a second obtaining module 404, configured to obtain, according to the information agreed by the call, information of a register used by the target function to be called; the allocating module 406 is configured to allocate a register for the calling instance according to the information of the register, so as to perform parameter transfer of the target function to be called through the register.
Optionally, the register allocating apparatus of this embodiment further includes: a generating module 408, configured to generate the calling convention by: acquiring information of other registers except a reserved register in current equipment; setting parameter indication information and parameter position information in a calling convention for the other registers; and generating the calling convention according to the parameter indication information and the parameter position information.
Optionally, the generating module 408 generates the call appointment according to the parameter indication information and the parameter location information: register allocation processing setting is carried out on the other registers, and the other registers are instructed not to carry out data storage processing in a register allocation stage through the register allocation processing setting; and generating the calling convention according to the parameter indication information, the parameter position information and the register allocation processing setting.
Optionally, the allocating module 406 is configured to allocate a register to the call instance according to the information of the register and the register allocation processing setting, and store all activity values in the call instance in a stack corresponding to the call instance.
Optionally, the register allocating apparatus of this embodiment further includes: a processing module 410, configured to obtain a security point of the call instance from the stack; and processing the calling instance according to the safety point.
Optionally, the second obtaining module 404 is configured to obtain information of a register used by the target function to be called according to the parameter indication information and the parameter location information agreed by the calling agreement.
Optionally, the register allocation device of the present embodiment is applied to LLVM, and the call contract is a V8 engine call contract.
The register allocation apparatus of this embodiment is used to implement the corresponding register allocation method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described herein again. In addition, the functional implementation of each module in the register allocation apparatus of this embodiment can refer to the description of the corresponding part in the foregoing method embodiment, and is not repeated herein.
EXAMPLE five
Referring to fig. 5, a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention is shown, and the specific embodiment of the present invention does not limit the specific implementation of the electronic device.
As shown in fig. 5, the electronic device may include: a processor (processor)502, a Communications Interface 504, a memory 506, and a communication bus 508.
Wherein:
the processor 502, communication interface 504, and memory 506 communicate with one another via a communication bus 508.
A communication interface 504 for communicating with other electronic devices or servers.
The processor 502 is configured to execute the program 510, and may specifically perform the relevant steps in the above-described register allocation method embodiment.
In particular, program 510 may include program code that includes computer operating instructions.
The processor 52 may be a central processing unit CPU or an application specific Integrated circuit asic or one or more Integrated circuits configured to implement embodiments of the present invention. The intelligent device comprises one or more processors which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 506 for storing a program 510. The memory 506 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 510 may specifically be used to cause the processor 502 to perform the following operations: acquiring a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment; acquiring the information of a register used by the target function to be called according to the calling appointed information; and according to the information of the register, allocating a register for the calling instance so as to transmit the parameters of the target function to be called through the register.
In an alternative embodiment, program 510 is further configured to cause processor 502 to generate the calling convention by: acquiring information of other registers except a reserved register in current equipment; setting parameter indication information and parameter position information in a calling convention for the other registers; and generating the calling convention according to the parameter indication information and the parameter position information.
In an optional implementation manner, the program 510 is further configured to enable the processor 502 to perform register allocation processing setting for the other registers when generating the call contract according to the parameter indication information and the parameter location information, and instruct the other registers not to perform data saving processing in a register allocation stage through the register allocation processing setting; and generating the calling convention according to the parameter indication information, the parameter position information and the register allocation processing setting.
In an optional implementation, the program 510 is further configured to enable the processor 502, when allocating a register to the call instance according to the information of the register, allocate a register to the call instance according to the information of the register and the register allocation processing setting, and store all activity values in the call instance in the stack corresponding to the call instance.
In an alternative embodiment, program 510 is further configured to cause processor 502 to obtain a security point for the call instance from the stack; and processing the calling instance according to the safety point.
In an optional implementation manner, the program 510 is further configured to enable the processor 502 to, when acquiring the information of the register used by the target function to be called according to the information of the calling convention, acquire the information of the register used by the target function to be called according to the parameter indication information and the parameter location information agreed by the calling convention.
In an alternative embodiment, the electronic device of the present embodiment is applied to LLVM, and the invocation contract is a V8 engine invocation contract.
For specific implementation of each step in the program 510, reference may be made to corresponding steps and corresponding descriptions in units in the above register allocation method embodiment, which are not described herein again. It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described devices and modules may refer to the corresponding process descriptions in the foregoing method embodiments, and are not described herein again.
Through the electronic equipment of the embodiment, when the register needs to be allocated for the target function to be called, the register is carried in the information of the calling instance according to the preset calling convention, so that the information of the calling instance is analyzed according to the calling convention, the information of the register is obtained, and the register is allocated according to the information to transmit the parameter of the target function to be called. The calling convention includes definition information of all available registers in the current device, that is, the calling convention can find corresponding positions and processes in the calling convention for all available register services of the current device, and a special calling convention does not need to be additionally set for used registers each time corresponding register parameters are transmitted. The method can be used on the current equipment for a long time by one-time setting, effectively reduces the transmission cost of register parameters, and improves the code compiling efficiency.
It should be noted that, according to the implementation requirement, each component/step described in the embodiment of the present invention may be divided into more components/steps, and two or more components/steps or partial operations of the components/steps may also be combined into a new component/step to achieve the purpose of the embodiment of the present invention.
The above-described method according to an embodiment of the present invention may be implemented in hardware, firmware, or as software or computer code storable in a recording medium such as a CD ROM, a RAM, a floppy disk, a hard disk, or a magneto-optical disk, or as computer code originally stored in a remote recording medium or a non-transitory machine-readable medium downloaded through a network and to be stored in a local recording medium, so that the method described herein may be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware such as an ASIC or FPGA. It will be appreciated that a computer, processor, microprocessor controller, or programmable hardware includes memory components (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code that, when accessed and executed by a computer, processor, or hardware, implements the register allocation methods described herein. Further, when a general-purpose computer accesses code for implementing the register allocation methods illustrated herein, execution of the code transforms the general-purpose computer into a special-purpose computer for performing the register allocation methods illustrated herein.
Those of ordinary skill in the art will appreciate that the various illustrative elements and method steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present embodiments.
The above embodiments are only for illustrating the embodiments of the present invention and not for limiting the embodiments of the present invention, and those skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention, so that all equivalent technical solutions also belong to the scope of the embodiments of the present invention, and the scope of patent protection of the embodiments of the present invention should be defined by the claims.

Claims (16)

1. A register allocation method, comprising:
acquiring a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment;
Acquiring the information of a register used by the target function according to the calling appointed information;
and according to the information of the register, allocating a register for the calling instance so as to transfer the parameters of the target function through the register.
2. The method of claim 1, wherein the calling convention is generated by:
acquiring information of other registers except a reserved register in current equipment;
setting parameter indication information and parameter position information in a calling convention for the other registers;
and generating the calling convention according to the parameter indication information and the parameter position information.
3. The method of claim 2, wherein the generating the calling convention according to the parameter indication information and parameter location information comprises:
register allocation processing setting is carried out on the other registers, and the other registers are instructed not to carry out data storage processing in a register allocation stage through the register allocation processing setting;
and generating the calling convention according to the parameter indication information, the parameter position information and the register allocation processing setting.
4. The method of claim 3, wherein the allocating registers for the call instances according to the information of the registers comprises:
and according to the information of the register and the register allocation processing setting, allocating a register for the calling instance, and storing all activity values in the calling instance into a stack corresponding to the calling instance.
5. The method of claim 4, wherein the method further comprises:
acquiring a security point of the calling instance from the stack;
and processing the calling instance according to the safety point.
6. The method as claimed in claim 2 or 3, wherein the obtaining information of the register used by the target function according to the information of the calling convention comprises:
and acquiring the information of the register used by the target function according to the parameter indication information and the parameter position information agreed by the calling agreement.
7. The method of any of claims 1-6, wherein the method is applied to LLVM, and the invocation contract is a V8 engine invocation contract.
8. A register allocation apparatus comprising:
the first obtaining module is used for obtaining a target function to be called and information of a calling convention according to the information of a calling example, wherein the calling convention comprises definition information of all available registers in current equipment;
The second obtaining module is used for obtaining the information of the register used by the target function according to the calling appointed information;
and the allocation module is used for allocating a register for the calling instance according to the information of the register so as to transmit the parameter of the target function through the register.
9. The apparatus of claim 8, wherein the apparatus further comprises: a generating module, configured to generate the calling convention in the following manner:
acquiring information of other registers except a reserved register in current equipment;
setting parameter indication information and parameter position information in a calling convention for the other registers;
and generating the calling convention according to the parameter indication information and the parameter position information.
10. The apparatus of claim 9, wherein the means for generating generates the invocation contract when generating the invocation contract based on the parameter indication information and parameter location information:
register allocation processing setting is carried out on the other registers, and the other registers are instructed not to carry out data storage processing in a register allocation stage through the register allocation processing setting;
and generating the calling convention according to the parameter indication information, the parameter position information and the register allocation processing setting.
11. The apparatus according to claim 10, wherein the allocating module is configured to allocate a register to the call instance according to the information of the register and the register allocation processing setting, and store all activity values in the call instance in a stack corresponding to the call instance.
12. The apparatus of claim 11, wherein the apparatus further comprises:
the processing module is used for acquiring the security point of the calling instance from the stack; and processing the calling instance according to the safety point.
13. The apparatus according to claim 9 or 10, wherein the second obtaining module is configured to obtain information of a register used by the target function according to the parameter indication information and the parameter location information agreed by the calling agreement.
14. The apparatus of any one of claims 8-13, wherein the apparatus is applied to LLVM, and the invocation contract is a V8 engine invocation contract.
15. An electronic device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
The memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the register allocation method according to any one of claims 1-7.
16. A computer storage medium having stored thereon a computer program which, when executed by a processor, implements the register allocation method of any one of claims 1-7.
CN201910339025.7A 2019-04-25 Register allocation method, device, electronic equipment and computer storage medium Active CN111857816B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910339025.7A CN111857816B (en) 2019-04-25 Register allocation method, device, electronic equipment and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910339025.7A CN111857816B (en) 2019-04-25 Register allocation method, device, electronic equipment and computer storage medium

Publications (2)

Publication Number Publication Date
CN111857816A true CN111857816A (en) 2020-10-30
CN111857816B CN111857816B (en) 2024-05-10

Family

ID=

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114661296A (en) * 2022-03-28 2022-06-24 阿里巴巴(中国)有限公司 Program code compiling method, program code compiling device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040010784A1 (en) * 2002-06-12 2004-01-15 International Business Machines Corporation Compiler register allocation and compilation
CN103853532A (en) * 2012-11-29 2014-06-11 国际商业机器公司 Method and device for calling function
CN105190534A (en) * 2013-03-14 2015-12-23 国际商业机器公司 Instruction for performing pseudorandom number seed operation
US20160132428A1 (en) * 2014-11-10 2016-05-12 International Business Machines Corporation Assigning home memory addresses to function call parameters

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040010784A1 (en) * 2002-06-12 2004-01-15 International Business Machines Corporation Compiler register allocation and compilation
CN103853532A (en) * 2012-11-29 2014-06-11 国际商业机器公司 Method and device for calling function
CN105190534A (en) * 2013-03-14 2015-12-23 国际商业机器公司 Instruction for performing pseudorandom number seed operation
US20160132428A1 (en) * 2014-11-10 2016-05-12 International Business Machines Corporation Assigning home memory addresses to function call parameters

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
任胜兵等: "基于LLVM架构的NiosⅡ后端快速移植", 计算机应用与软件, vol. 28, no. 12, 31 December 2011 (2011-12-31), pages 22 - 25 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114661296A (en) * 2022-03-28 2022-06-24 阿里巴巴(中国)有限公司 Program code compiling method, program code compiling device, electronic equipment and storage medium
CN114661296B (en) * 2022-03-28 2022-12-09 优视科技有限公司 Program code compiling method, program code compiling device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111831287B (en) Method, apparatus and program product for determining resources required to execute a code segment
CN108121594B (en) Process management method and device
CN110673853B (en) Compiling method, device and system
EP3032413B1 (en) Code generation method, compiler, scheduling method, apparatus and scheduling system
CN110928548B (en) Data processing method and device
CN114327477A (en) Intelligent contract execution method and device, electronic device and storage medium
JP2018028777A (en) Emulation device, emulation method, and emulation program
US20190171466A1 (en) Method and system for multiple embedded device links in a host executable
CN107239298B (en) Application program debugging method and device
CN116521181B (en) Script data processing method, device, equipment and medium based on game system
CN115794355B (en) Task processing method, device, terminal equipment and storage medium
CN109828796B (en) Plug-in calling method and device based on microkernel architecture
CN111857816A (en) Register allocation method and device, electronic equipment and computer storage medium
CN113031954A (en) Code compiling method and device, electronic equipment, storage medium and heterogeneous system
CN106951236B (en) Plug-in development method and device
CN111857816B (en) Register allocation method, device, electronic equipment and computer storage medium
CN110333870B (en) Simulink model variable distribution processing method, device and equipment
CN114356342A (en) Compiling method and device
CN114139079A (en) API request processing method, device, equipment and storage medium
CN114064176A (en) View interaction method and device, electronic equipment and computer readable medium
CN113703734A (en) Applet generation method and device, electronic equipment and storage medium
CN109460296B (en) Resource allocation method and device of processor and storage medium
CN111240690A (en) Service processing method, device, equipment and storage medium based on policy mode
CN114020278A (en) Data processing method, device, equipment and storage medium
CN111061538A (en) Memory optimization method and system for multiple Lua virtual machines

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant