CN112445483B - Instruction generation method and device, electronic equipment and storage medium - Google Patents

Instruction generation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112445483B
CN112445483B CN201910797915.2A CN201910797915A CN112445483B CN 112445483 B CN112445483 B CN 112445483B CN 201910797915 A CN201910797915 A CN 201910797915A CN 112445483 B CN112445483 B CN 112445483B
Authority
CN
China
Prior art keywords
compiled
static
use information
program
keyword
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.)
Active
Application number
CN201910797915.2A
Other languages
Chinese (zh)
Other versions
CN112445483A (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.)
Loongson Technology Corp Ltd
Original Assignee
Loongson Technology Corp 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 Loongson Technology Corp Ltd filed Critical Loongson Technology Corp Ltd
Priority to CN201910797915.2A priority Critical patent/CN112445483B/en
Publication of CN112445483A publication Critical patent/CN112445483A/en
Application granted granted Critical
Publication of CN112445483B publication Critical patent/CN112445483B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • 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/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The embodiment of the invention provides a method and a device for generating an instruction, wherein the method comprises the following steps: in the static compiling process, a subprogram to be statically compiled, which is called by a parent program to be just-in-time compiled, is obtained, the use information of a register used by the subprogram is determined, and then in the just-in-time compiling process, a compiled save instruction or a recovery instruction of the register is generated according to the use information, so that the just-in-time compiler can know the condition that the subprogram to be statically compiled uses the register, and then can generate the save or recovery instruction only aiming at a necessary register, thereby achieving the effect of reducing the number of instructions generated by the just-in-time compiler, and further improving the execution performance of the just-in-time compiled program.

Description

Instruction generation method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technology, and in particular, to an instruction generating method, an instruction generating device, an electronic device, and a readable storage medium.
Background
Dynamic compilation is a method used by some programming languages to improve performance when executed, and generally refers to the compilation of a program at runtime. In contrast, compilation in advance, also called static compilation, is used. Static compiling is that when a compiler compiles an executable file, a part of a corresponding static library (for example, a library with an extension name of. A or. Lib) which is required to be called by the executable file is extracted and linked into the executable file, so that the executable file does not depend on a dynamic link library when running. A typical example of static compilation is the compilation mode of gcc (GNU Compiler Collection, GNU compiler suite). gcc will compile the source program into executable machine code, and when deploying or distributing the program, the compiled machine code will be deployed directly, and when executing the program, the compiling process will not be needed.
A typical example of dynamic compilation is Just-in-time compilation (JIT) mode in a Java (a computer programming language) virtual machine. A Java program is a kind of bytecode program, and cannot be directly executed on an actual physical machine, and when executing the Java program, it is generally interpreted and executed first, and the execution speed is definitely slower than that of an executable binary machine code program. To increase execution speed, JIT was introduced. When a hot spot method or a loop is identified in the operation, the JIT dynamically compiles the hot spot method, compiles the byte code into locally executable machine code, directly operates the compiled machine code, and stores the translated machine code for the next use.
There will be a caller and a callee in the compiled program. When a subroutine call is made, a register that is responsible for saving by a caller (caller) is called a caller-saved register. When a subroutine call is made, a register that is responsible for saving by a callee (callee) is referred to as a callee-saved register.
When compiling a caller and a callee in a program, if the caller and the callee compile at the same compiler and the same time, the compiler knows the information of the called subprogram at the compiling time, so that the required registers of the subprogram can be determined at the compiling time, and only the caller-protected registers used in the subprogram can be saved at the calling place, thereby avoiding saving and recovering unnecessary caller-protected registers and generating optimal codes.
But it is apparent that this approach is not applicable to both just-in-time compilation and static compilation mixed cases. At just-in-time compilation, the called subroutine has been compiled into machine code by other static compilers and optimization of the associated register save and restore is not possible.
In the prior art, before and after the instant compiler calls the static compiler, the save and restore operation has to be performed on all the impeller-shared registers, so that some unnecessary save and restore operations may occur, and in an architecture with more impeller-shared registers, a larger performance overhead may occur.
Disclosure of Invention
The embodiment of the invention aims to solve the technical problem of providing an instruction generation method, an instruction generation device, electronic equipment and a readable storage medium, so as to solve the problem that the storage and recovery of a register cannot be optimized when just-in-time compiling and static compiling are mixed.
In order to solve the above problems, the present invention provides an instruction generating method, including:
in the static compiling process, acquiring a subprogram which is called by a parent program and needs to be compiled at the same time and needs to be compiled statically;
determining the use information of the subroutine use register in a static compiling process;
And in the instant compiling process, generating a compiled save instruction or a recovery instruction of the register according to the use information.
Optionally, the obtaining the child program to be statically compiled of the parent program to be just-in-time compiled includes:
identifying a first keyword in a subroutine call function to be statically compiled, wherein the first keyword is used for identifying a subroutine to be statically compiled, which is called by a parent program to be just-in-time compiled;
and acquiring the subprogram corresponding to the first keyword.
Optionally, the determining the usage information of the subroutine usage register includes:
performing static compiling on the subprogram to obtain the use information;
and storing the use information into a cache.
Optionally, the saving the usage information in the cache includes:
identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and transmitting the use information corresponding to the second key word to a push function or a pop function.
Optionally, before the obtaining the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, the method further includes:
Detecting whether the static compiler meets preset requirements or not;
if the preset requirement is not met, replacing the use information with preset use information, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be immediately compiled, and the second keyword is used for identifying the use information.
Correspondingly, the invention also provides an instruction generating device, which comprises:
the sub program acquisition module is used for acquiring a sub program which is called by a parent program and needs to be compiled at once in the static compiling process;
the information determining module is used for determining the use information of the subroutine use register in the static compiling process;
and the instruction generation module is used for generating a compiled save instruction or a restoration instruction of the register according to the use information in the instant compiling process.
Optionally, the subroutine acquisition module includes:
the first recognition sub-module is used for recognizing a first keyword in a sub-program calling function to be statically compiled, wherein the first keyword is used for identifying a sub-program to be statically compiled, which is called by a parent program to be just-in-time compiled;
And the subprogram acquisition sub-module is used for acquiring the subprogram corresponding to the first keyword.
Optionally, the information determining module includes:
the compiling sub-module is used for carrying out static compiling on the sub-program to obtain the use information;
and the storage submodule is used for storing the use information into a cache.
Optionally, the saving submodule includes:
the second identification unit is used for identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and the transfer unit is used for transferring the use information corresponding to the second key word to a push function or a pop function.
Optionally, the apparatus further comprises:
the detection module is used for detecting whether the static compiler meets the preset requirement before the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, is obtained;
and the replacing module is used for replacing the use information with preset use information if the preset requirement is not met, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be just-in-time compiled, and the second keyword is used for identifying the use information.
Accordingly, the present invention also provides an electronic device comprising a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising instructions for:
in the static compiling process, acquiring a subprogram which is called by a parent program and needs to be compiled at the same time and needs to be compiled statically;
determining the use information of the subroutine use register in a static compiling process;
and in the instant compiling process, generating a compiled save instruction or a recovery instruction of the register according to the use information.
Optionally, the obtaining the child program to be statically compiled of the parent program to be just-in-time compiled includes:
identifying a first keyword in a subroutine call function to be statically compiled, wherein the first keyword is used for identifying a subroutine to be statically compiled, which is called by a parent program to be just-in-time compiled;
and acquiring the subprogram corresponding to the first keyword.
Optionally, the determining the usage information of the subroutine usage register includes:
Performing static compiling on the subprogram to obtain the use information;
and storing the use information into a cache.
Optionally, the saving the usage information in the cache includes:
identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and transmitting the use information corresponding to the second key word to a push function or a pop function.
Optionally, before the obtaining the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, the method further includes:
detecting whether the static compiler meets preset requirements or not;
if the preset requirement is not met, replacing the use information with preset use information, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be immediately compiled, and the second keyword is used for identifying the use information.
Accordingly, the present invention also provides a readable storage medium, which when executed by a processor of an electronic device, enables the electronic device to perform the above-described instruction generating method.
According to the embodiment of the invention, the use information of the register used by the subprogram is determined by acquiring the subprogram required to be statically compiled, which is called by the parent program required to be statically compiled, in the static compiling process, and then the compiled save instruction or restore instruction of the register is generated according to the use information in the instant compiling process, so that the instant compiler can know the condition that the subprogram required to be statically compiled uses the register, and then the save or restore instruction can be generated only aiming at the necessary register, thereby achieving the effect of reducing the number of instructions generated by the instant compiler, and further improving the execution performance of the instant compiled program.
Drawings
FIG. 1 is a flow chart showing the steps of a method for generating an instruction according to a first embodiment of the present invention;
FIG. 2 is a flow chart showing the steps of a method for generating instructions according to a second embodiment of the present invention;
FIG. 3 is a flow chart showing the steps of a method for generating instructions according to a third embodiment of the present invention;
FIG. 4 is a block diagram showing an embodiment of an instruction generating apparatus according to a fourth embodiment of the present invention;
fig. 5 shows a block diagram of an electronic device for instruction generation, according to an example embodiment.
Detailed Description
In order that the above-recited objects, features and advantages of the present invention will become more readily apparent, a more particular description of the invention will be rendered by reference to the appended drawings and appended detailed description.
Referring to fig. 1, a flowchart illustrating steps of a method for generating an instruction according to a first embodiment of the present invention may specifically include the following steps:
step 101, in the static compiling process, acquiring a subroutine needing static compiling, which is called by a parent program needing just-in-time compiling.
In the embodiment of the present invention, the program needs to be executed through a compiling process, and the compiling process may be classified into a static compiling process and a just-in-time compiling process. For example, executing a Java program requires compiling a program source code file into a Java bytecode file, then JRE (Java Runtime Environment, java running environment) loads the Java bytecode file, loads the memory area allocated to JVM (Java Virtual Machine ) by the system, then interprets or compiles class files, then converts the bytecode into local machine code by a just-in-time compiler, and before the program runs, part of the program source code file can be directly compiled into local machine code by a static compiler, so that the compiled local machine code can be saved in disk, does not occupy memory, can be used for multiple times, does not occupy running time, does some time-consuming optimization, and can accelerate the program start.
In the embodiment of the invention, a calling relationship exists in the program, a caller is marked as a parent program, and a callee is marked as a subprogram. Some father programs need to be compiled statically, and some father programs need to be compiled just in time; some subroutines need to be compiled statically and some subroutines need to be compiled just-in-time. When a subroutine is required to be compiled statically, but a parent program for calling the subroutine is required to be compiled immediately, the information of the subroutine cannot be obtained by the instant compiler when the parent program is compiled because the parent program and the subroutine are not compiled at the same compiler and the same time, and therefore, the invention proposes to change the static compiling process of the subroutine and the instant compiling process of the corresponding parent program.
In the embodiment of the present invention, in the static compiling process, the implementation manner of obtaining the sub program to be statically compiled called by the parent program to be just-in-time compiled may include various ways, for example, identifying the first key in the program code to be statically compiled, where the first key is used to identify the sub program to be statically compiled called by the parent program to be just-in-time compiled, obtaining the sub program corresponding to the first key, or any other suitable implementation manner, and the embodiment of the present invention is not limited to this.
For example, under the MIPS (Microprocessor without Interlocked Pipedline Stages architecture, microprocessor without internal interlocking pipeline stage), the gcc compiler may perform static compilation on the program code, and if in the static compilation process, it is found that the program code to be compiled at once has a case of calling a C function called func, where the C function needs to be compiled statically, the code of the C function is obtained.
Step 102, determining the usage information of the subroutine usage register in the static compiling process.
In the embodiment of the invention, the subroutine may modify the values of some registers during the execution process, so that the values of the registers need to be saved before the subroutine is executed, so that the subroutine returns to the parent program to continue to execute after the execution process is completed.
In the embodiment of the invention, when compiling the acquired subprogram, the static compiler can determine the condition that the subprogram uses the register to obtain the use information. The usage information includes, but is not limited to, an identification of registers that will change when the subroutine executes. The implementation of determining the usage information of the subroutine usage register may include: compiling the subroutine to obtain the usage information, and saving the usage information in a cache, or any other suitable implementation, which is not limited in this embodiment of the present invention. For example, when the gcc compiler compiles the func function, usage information about the function's impeller-shared registers may be obtained.
Step 103, in the instant compiling process, according to the use information, generating a compiled save instruction or a recovery instruction of the register.
In the embodiment of the invention, in the instant compiling process, a compiled save instruction or a recovery instruction of a register is generated according to the use information, and the instant compiling instruction is a local machine code instruction. Wherein the save instruction is required to be executed before the execution of the subroutine for saving the value of the corresponding register, and the restore instruction is required to be executed after the execution of the subroutine for restoring the value of the corresponding register again. For example, the JIT compiler compiles the save instruction and the restore instruction based on the usage information, and the resulting compiled save instruction and restore instruction are directed only to the tapered-save register of the subroutine.
According to the embodiment of the invention, the use information of the register used by the subprogram is determined by acquiring the subprogram required to be statically compiled, which is called by the parent program required to be statically compiled, in the static compiling process, and then the compiled save instruction or recovery instruction of the register is generated according to the use information in the instant compiling process, so that the instant compiler can know the condition that the subprogram required to be statically compiled uses the register, and then the save or recovery instruction can be generated only aiming at the necessary register, thereby achieving the effect of reducing the number of instructions generated by the instant compiler, and further improving the execution performance of the instant compiled program.
Referring to fig. 2, a step flowchart of a method for generating an instruction according to a second embodiment of the present invention may specifically include the following steps:
in step 201, a first key is identified in a subroutine call function to be statically compiled.
In the embodiment of the invention, in order to ensure that the static compiler accurately identifies the source code of the program semantics needing to be subjected to the scheme, a first keyword is added for identifying the subprogram needing to be subjected to static compiling, which is called by the parent program needing to be subjected to instant compiling. When the static compiler compiles the program code and compiles the program code to a subroutine call function, the first keyword is identified, and the compiling process of the invention is executed on the subroutine. For example, if the parameter type in the calling function is callsub (i.e. the first keyword) and the parameter name is func, the called subroutine is a subroutine to be statically compiled, which is called by a parent program to be compiled just-in-time.
Step 202, obtaining the subroutine corresponding to the first keyword.
In the embodiment of the present invention, a subroutine corresponding to the first key is acquired, that is, a program code of the subroutine is acquired. For example, when the called subroutine is func and the subroutine is called, the parameter type is recognized as callsub, and thus the function code of the subroutine func is acquired.
And 203, performing static compiling on the subprogram to obtain the use information.
In the embodiment of the invention, the static compiler performs static compiling on the acquired subprogram, and in the compiling process, the static compiler can obtain the use information of the register used by the subprogram. For example, the gcc compiler performs static compilation on the subroutine func, converts the bytecode into a native machine code, and knows which registers in the func have their values changed during conversion, and then the identification of these registers is the usage information.
And step 204, saving the use information into a cache.
In the embodiment of the invention, the static compiler stores the obtained use information into a cache for just-in-time compiling to obtain.
In an embodiment of the present invention, optionally, one implementation of saving the usage information in the cache may include: identifying a second keyword from a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information, and transmitting the use information corresponding to the second keyword to the push function or the pop function
In the embodiment of the invention, in order to ensure that the static compiler accurately identifies the storage position of the usage information, a second keyword is added for identifying the usage information. And when compiling the program code to the push function or the pop function, the static compiler recognizes the second keyword and then executes the step of transmitting the use information corresponding to the second keyword to the push function or the pop function. For example, the type of a parameter in a push function before a function is called is rlist (i.e. a second keyword), the parameter name is list, the push operation is performed on the parameter list, the type of a parameter in a pop function after a function is called is also rlist, the parameter name is list, and the pop operation is performed on the parameter list.
Step 205, in the instant compiling process, generating a compiled save instruction or a recovery instruction of the register according to the usage information.
In the embodiments of the present invention, the specific implementation manner of this step may be referred to the description in the foregoing embodiments, which is not repeated herein.
According to the embodiment of the invention, the first keyword is identified in the subroutine call function to be statically compiled, the subroutine corresponding to the first keyword is obtained, static compiling is carried out on the subroutine, the use information is obtained, the use information is stored in a cache, then in the instant compiling process, according to the use information, a compiled save instruction or a recovery instruction of the register is generated, so that the instant compiler can know the condition that the subroutine to be statically compiled uses the register, and then the save or recovery instruction can be generated only aiming at the necessary register, the effect of reducing the number of instructions generated by the instant compiler is achieved, and the execution performance of the instant compiled program is improved.
Referring to fig. 3, a flowchart illustrating steps of a method for generating an instruction according to a third embodiment of the present invention may specifically include the following steps:
In step 301, it is detected whether the static compiler meets a preset requirement.
In the embodiment of the invention, in order to realize compatibility of the static compiler, before acquiring the subprogram to be statically compiled called by the parent program to be just-in-time compiled, whether the current static compiler meets the preset requirement is detected, namely whether the current static compiler supports the mechanism proposed by the invention is judged. For example, detecting whether the static compiler meets a preset version requirement, or any other applicable requirement, embodiments of the present invention are not limited in this respect.
For example, in the JVM source program, a macro definition is used to determine whether the current gcc compiler supports the mechanism of the present invention, that is, a certain text mode is replaced according to a series of predefined rules, the macro system is implemented by a preprocessor of the compiler, batch processing, and when a macro is encountered, this mode replacement is automatically performed, if the preset requirement is met, step 303 is executed, and if the preset requirement is not met, step 302 is executed.
Step 302, if the preset requirement is not met, replacing the usage information with preset usage information, and setting the first keyword or the second keyword in the program code to be statically compiled to be empty.
In the embodiment of the invention, the first key is used for identifying the subprogram requiring static compiling, which is called by the parent program requiring just-in-time compiling, and the second key is used for identifying the use information. The static compiler does not meet the preset requirement, that is, the static compiler cannot determine the usage information of the subroutine usage register, and then the static compiler cannot identify the first keyword and the second keyword, so that the static compiler cannot compile normally. Therefore, it is necessary to replace the usage information with preset usage information, for example, to replace the usage information with all registers, and to set the first key or the second key in the program code to be statically compiled to be empty.
For example, the usage information of the register is replaced with all the teller-shared registers by the macro definition, and the first keyword callsub and the second keyword rlist are empty by the macro definition. This ensures that the relevant modified JVM can be compiled normally also on gcc which does not support the mechanism of the present invention.
Step 303, in the static compiling process, obtaining the subroutine to be statically compiled, which is called by the parent program to be just-in-time compiled.
In the embodiments of the present invention, the specific implementation manner of this step may be referred to the description in the foregoing embodiments, which is not repeated herein.
Step 304, determining the usage information of the subroutine usage register in the static compiling process.
In the embodiments of the present invention, the specific implementation manner of this step may be referred to the description in the foregoing embodiments, which is not repeated herein.
Step 305, in the instant compiling process, generating a compiled save instruction or a recovery instruction of the register according to the usage information.
In the embodiments of the present invention, the specific implementation manner of this step may be referred to the description in the foregoing embodiments, which is not repeated herein.
According to the embodiment of the invention, the use information of the register used by the subprogram is determined by acquiring the subprogram required to be statically compiled, which is called by the parent program required to be statically compiled, in the static compiling process, and then the compiled save instruction or recovery instruction of the register is generated according to the use information in the instant compiling process, so that the instant compiler can know the condition that the subprogram required to be statically compiled uses the register, and then the save or recovery instruction can be generated only aiming at the necessary register, thereby achieving the effect of reducing the number of instructions generated by the instant compiler, and further improving the execution performance of the instant compiled program.
Further, by detecting whether the static compiler meets the preset requirement or not, if not, replacing the use information with preset use information, and setting the first keyword or the second keyword in the program code to be statically compiled to be empty, it can be ensured that the static compiler which does not support the mechanism of the invention can be normally compiled after relevant modification.
It should be noted that, for simplicity of description, the method embodiments are shown as a series of acts, but it should be understood by those skilled in the art that the embodiments are not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred embodiments, and that the acts are not necessarily required by the embodiments of the invention.
Referring to fig. 4, a block diagram of an embodiment of an instruction generating apparatus according to a fourth embodiment of the present invention is shown, and may specifically include the following modules:
a subroutine acquisition module 401, configured to acquire a subroutine to be statically compiled, which is called by a parent program to be just-in-time compiled, in a static compiling process;
An information determining module 402, configured to determine usage information of the subroutine usage register during static compiling;
the instruction generating module 403 is configured to generate a compiled save instruction or a compiled restore instruction of the register according to the usage information during the just-in-time compilation process.
In an embodiment of the present invention, optionally, the subroutine acquisition module includes:
the first recognition sub-module is used for recognizing a first keyword in a sub-program calling function to be statically compiled, wherein the first keyword is used for identifying a sub-program to be statically compiled, which is called by a parent program to be just-in-time compiled;
and the subprogram acquisition sub-module is used for acquiring the subprogram corresponding to the first keyword.
In an embodiment of the present invention, optionally, the information determining module includes:
the compiling sub-module is used for carrying out static compiling on the sub-program to obtain the use information;
and the storage submodule is used for storing the use information into a cache.
In an embodiment of the present invention, optionally, the saving submodule includes:
the second identification unit is used for identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
And the transfer unit is used for transferring the use information corresponding to the second key word to a push function or a pop function.
In an embodiment of the present invention, optionally, the apparatus further includes:
the detection module is used for detecting whether the static compiler meets the preset requirement before the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, is obtained;
and the replacing module is used for replacing the use information with preset use information if the preset requirement is not met, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be just-in-time compiled, and the second keyword is used for identifying the use information.
According to the embodiment of the invention, the use information of the register used by the subprogram is determined by acquiring the subprogram required to be statically compiled, which is called by the parent program required to be statically compiled, in the static compiling process, and then the compiled save instruction or recovery instruction of the register is generated according to the use information in the instant compiling process, so that the instant compiler can know the condition that the subprogram required to be statically compiled uses the register, and then the save or recovery instruction can be generated only aiming at the necessary register, thereby achieving the effect of reducing the number of instructions generated by the instant compiler, and further improving the execution performance of the instant compiled program.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
Fig. 5 is a block diagram illustrating an electronic device 700 for instruction generation, according to an example embodiment. For example, the electronic device 700 may be a mobile phone, computer, digital broadcast terminal, messaging device, game console, tablet device, medical device, exercise device, personal digital assistant, or the like.
Referring to fig. 5, an electronic device 700 may include one or more of the following components: a processing component 702, a memory 704, a power component 706, a multimedia component 708, an audio component 710, an input/output (I/O) interface 712, a sensor component 714, and a communication component 716.
The processing component 702 generally controls overall operation of the electronic device 700, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing element 702 may include one or more processors 720 to execute instructions to perform all or part of the steps of the methods described above. Further, the processing component 702 can include one or more modules that facilitate interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia module to facilitate interaction between the multimedia component 708 and the processing component 702.
Memory 704 is configured to store various types of data to support operations at device 700. Examples of such data include instructions for any application or method operating on the electronic device 700, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 704 may be implemented by any type or combination of volatile or nonvolatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disk.
The power component 704 provides power to the various components of the electronic device 700. Power component 704 can include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for electronic device 700.
The multimedia component 708 includes a screen between the electronic device 700 and the user that provides an output interface. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or slide action, but also the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 708 includes a front-facing camera and/or a rear-facing camera. When the electronic device 700 is in an operational mode, such as a shooting mode or a video mode, the front camera and/or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
The audio component 710 is configured to output and/or input audio signals. For example, the audio component 710 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 700 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 704 or transmitted via the communication component 716. In some embodiments, the audio component 710 further includes a speaker for outputting audio signals.
The I/O interface 712 provides an interface between the processing component 702 and peripheral interface modules, which may be a keyboard, click wheel, buttons, etc. These buttons may include, but are not limited to: homepage button, volume button, start button, and lock button.
The sensor assembly 714 includes one or more sensors for providing status assessment of various aspects of the electronic device 700. For example, the sensor assembly 714 may detect an on/off state of the device 700, a relative positioning of the components, such as a display and keypad of the electronic device 700, a change in position of the electronic device 700 or a component of the electronic device 700, the presence or absence of a user's contact with the electronic device 700, an orientation or acceleration/deceleration of the electronic device 700, and a change in temperature of the electronic device 700. The sensor assembly 714 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 714 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 714 may also include an acceleration sensor, a gyroscopic sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 716 is configured to facilitate communication between the electronic device 700 and other devices, either wired or wireless. The electronic device 700 may access a wireless network based on a communication standard, such as WiFi,2G, or 3G, or a combination thereof. In one exemplary embodiment, the communication part 714 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component 714 further includes a Near Field Communication (NFC) module to facilitate short range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra Wideband (UWB) technology, bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 700 may be implemented by one or more Application Specific Integrated Circuits (ASICs), digital Signal Processors (DSPs), digital Signal Processing Devices (DSPDs), programmable Logic Devices (PLDs), field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic elements for executing the methods described above.
In an exemplary embodiment, a non-transitory computer readable storage medium is also provided, such as memory 704, including instructions executable by processor 720 of electronic device 700 to perform the above-described method. For example, the non-transitory computer readable storage medium may be ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, etc.
A non-transitory computer readable storage medium, which when executed by a processor of a terminal, enables the terminal to perform an instruction generation method, the method comprising:
in the static compiling process, acquiring a subprogram which is called by a parent program and needs to be compiled at the same time and needs to be compiled statically;
determining the use information of the subroutine use register in a static compiling process;
and in the instant compiling process, generating a compiled save instruction or a recovery instruction of the register according to the use information.
Optionally, the obtaining the child program to be statically compiled of the parent program to be just-in-time compiled includes:
identifying a first keyword in a subroutine call function to be statically compiled, wherein the first keyword is used for identifying a subroutine to be statically compiled, which is called by a parent program to be just-in-time compiled;
and acquiring the subprogram corresponding to the first keyword.
Optionally, the determining the usage information of the subroutine usage register includes:
performing static compiling on the subprogram to obtain the use information;
and storing the use information into a cache.
Optionally, the saving the usage information in the cache includes:
Identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and transmitting the use information corresponding to the second key word to a push function or a pop function.
Optionally, before the obtaining the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, the method further includes:
detecting whether the static compiler meets preset requirements or not;
if the preset requirement is not met, replacing the use information with preset use information, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be immediately compiled, and the second keyword is used for identifying the use information.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described by differences from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other.
It will be apparent to those skilled in the art that embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the invention may take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or terminal device comprising the element.
The foregoing has described in detail a method and an apparatus for generating instructions according to the present invention, and specific examples are provided herein to illustrate the principles and embodiments of the present invention, and the above examples are only for aiding in the understanding of the method and core ideas of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.

Claims (10)

1. A method of generating instructions, comprising:
in the static compiling process, acquiring a subprogram which is called by a parent program and needs to be compiled at the same time and needs to be compiled statically;
determining the use information of the subroutine use register in a static compiling process;
in the instant compiling process, according to the use information, a compiled save instruction or a recovery instruction of the register is generated;
wherein the static compilation is performed by a static compiler and the just-in-time compilation is performed by a just-in-time compiler;
the parent program is compiled in a just-in-time compiler, and the child program is compiled in a static compiler;
The use information comprises information that a static compiler determines a use register of the subprogram in a static compiling process of the subprogram;
the determining the usage information of the subroutine usage register includes:
performing static compiling on the subprogram to obtain the use information;
and storing the use information into a cache.
2. The method of claim 1, wherein the obtaining the statically compiled subroutine of the just-in-time compiled parent call comprises:
identifying a first keyword in a subroutine call function to be statically compiled, wherein the first keyword is used for identifying a subroutine to be statically compiled, which is called by a parent program to be just-in-time compiled;
and acquiring the subprogram corresponding to the first keyword.
3. The method of claim 1, wherein the saving the usage information into a cache comprises:
identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and transmitting the use information corresponding to the second key word to a push function or a pop function.
4. A method according to any of claims 1-3, wherein prior to the obtaining of the statically compiled subroutine called by the just-in-time compiled parent, the method further comprises:
Detecting whether the static compiler meets preset requirements or not;
if the preset requirement is not met, replacing the use information with preset use information, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be immediately compiled, and the second keyword is used for identifying the use information.
5. An instruction generating apparatus, comprising:
the sub program acquisition module is used for acquiring a sub program which is called by a parent program and needs to be compiled at once in the static compiling process;
the information determining module is used for determining the use information of the subroutine use register in the static compiling process;
the instruction generation module is used for generating a compiled save instruction or a restoration instruction of the register according to the use information in the instant compiling process;
wherein the static compilation is performed by a static compiler; the just-in-time compilation is performed by a just-in-time compiler;
the parent program is compiled in a just-in-time compiler, and the child program is compiled in a static compiler;
The information determination module includes:
the compiling sub-module is used for carrying out static compiling on the sub-program to obtain the use information;
and the storage submodule is used for storing the use information into a cache.
6. The apparatus of claim 5, wherein the subroutine acquisition module comprises:
the first recognition sub-module is used for recognizing a first keyword in a sub-program calling function to be statically compiled, wherein the first keyword is used for identifying a sub-program to be statically compiled, which is called by a parent program to be just-in-time compiled;
and the subprogram acquisition sub-module is used for acquiring the subprogram corresponding to the first keyword.
7. The apparatus of claim 5, wherein the save submodule comprises:
the second identification unit is used for identifying a second keyword in a push function or a pop function to be statically compiled, wherein the second keyword is used for identifying the use information;
and the transfer unit is used for transferring the use information corresponding to the second key word to a push function or a pop function.
8. The apparatus according to any one of claims 5-7, further comprising:
The detection module is used for detecting whether the static compiler meets the preset requirement before the sub program to be statically compiled, which is called by the parent program to be just-in-time compiled, is obtained;
and the replacing module is used for replacing the use information with preset use information if the preset requirement is not met, and setting a first keyword or a second keyword in the program code to be statically compiled to be empty, wherein the first keyword is used for identifying a subprogram to be statically compiled, which is called by a parent program to be just-in-time compiled, and the second keyword is used for identifying the use information.
9. An electronic device comprising a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors, the one or more programs comprising instructions for:
in the static compiling process, acquiring a subprogram which is called by a parent program and needs to be compiled at the same time and needs to be compiled statically;
determining the use information of the subroutine use register in a static compiling process;
in the instant compiling process, according to the use information, a compiled save instruction or a recovery instruction of the register is generated;
Wherein the static compilation is performed by a static compiler and the just-in-time compilation is performed by a just-in-time compiler;
the parent program is compiled in a just-in-time compiler, and the child program is compiled in a static compiler;
the use information comprises information that a static compiler determines a use register of the subprogram in a static compiling process of the subprogram;
the determining the usage information of the subroutine usage register includes:
performing static compiling on the subprogram to obtain the use information;
and storing the use information into a cache.
10. A readable storage medium, characterized in that instructions in the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the instruction generation method of one or more of the method claims 1-4.
CN201910797915.2A 2019-08-27 2019-08-27 Instruction generation method and device, electronic equipment and storage medium Active CN112445483B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910797915.2A CN112445483B (en) 2019-08-27 2019-08-27 Instruction generation method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910797915.2A CN112445483B (en) 2019-08-27 2019-08-27 Instruction generation method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112445483A CN112445483A (en) 2021-03-05
CN112445483B true CN112445483B (en) 2023-11-24

Family

ID=74740958

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910797915.2A Active CN112445483B (en) 2019-08-27 2019-08-27 Instruction generation method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112445483B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6983459B1 (en) * 1999-04-06 2006-01-03 International Business Machines Corporation Incorporating register pressure into an inlining compiler
CN102236575A (en) * 2011-07-20 2011-11-09 复旦大学 Dynamical compilation method based on register mapping
US8429632B1 (en) * 2009-06-30 2013-04-23 Google Inc. Method and system for debugging merged functions within a program
CN104965687A (en) * 2015-06-04 2015-10-07 北京东方国信科技股份有限公司 Big data processing method and apparatus based on instruction set generation
CN105589729A (en) * 2015-12-28 2016-05-18 北京锐安科技有限公司 Dynamic compiling method and device based on embedded virtual machine
CN107992307A (en) * 2017-12-11 2018-05-04 北京奇虎科技有限公司 A kind of function Compilation Method and device
CN109426504A (en) * 2017-08-29 2019-03-05 龙芯中科技术有限公司 Processing method, device, electronic equipment and the storage medium of program
CN109542443A (en) * 2017-07-27 2019-03-29 阿里巴巴集团控股有限公司 Compilation Method and device, terminal, the data processing method of application program
CN109976793A (en) * 2019-03-15 2019-07-05 北京字节跳动网络技术有限公司 A kind of operation method of application program, device, equipment and medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6983459B1 (en) * 1999-04-06 2006-01-03 International Business Machines Corporation Incorporating register pressure into an inlining compiler
US8429632B1 (en) * 2009-06-30 2013-04-23 Google Inc. Method and system for debugging merged functions within a program
CN102236575A (en) * 2011-07-20 2011-11-09 复旦大学 Dynamical compilation method based on register mapping
CN104965687A (en) * 2015-06-04 2015-10-07 北京东方国信科技股份有限公司 Big data processing method and apparatus based on instruction set generation
CN105589729A (en) * 2015-12-28 2016-05-18 北京锐安科技有限公司 Dynamic compiling method and device based on embedded virtual machine
CN109542443A (en) * 2017-07-27 2019-03-29 阿里巴巴集团控股有限公司 Compilation Method and device, terminal, the data processing method of application program
CN109426504A (en) * 2017-08-29 2019-03-05 龙芯中科技术有限公司 Processing method, device, electronic equipment and the storage medium of program
CN107992307A (en) * 2017-12-11 2018-05-04 北京奇虎科技有限公司 A kind of function Compilation Method and device
CN109976793A (en) * 2019-03-15 2019-07-05 北京字节跳动网络技术有限公司 A kind of operation method of application program, device, equipment and medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于ARM 的PLC 指令编译与并行运算数据配置的设计;吴笔迅;广西工学院硕士学位论文;第2013卷(第4期);第11-12、44页 *

Also Published As

Publication number Publication date
CN112445483A (en) 2021-03-05

Similar Documents

Publication Publication Date Title
CN109032606B (en) Native application compiling method and device and terminal
EP3096224B1 (en) Method and apparatus for processing application installation package
CN111736916A (en) Dynamic expansion method and device based on Java language, electronic equipment and storage medium
CN109426504B (en) Program processing method, program processing device, electronic device and storage medium
CN111767058A (en) Program compiling method and device, electronic equipment and storage medium
CN109725943B (en) Program jumping method and device, electronic equipment and storage medium
CN111913756B (en) Application program optimizing method, device and system, electronic equipment and storage medium
CN113377370A (en) File processing method and device, electronic equipment and storage medium
CN112445484B (en) Register processing method and device, electronic equipment and storage medium
CN112114814A (en) Compiled file determining method and device and application program generating method and device
CN112445483B (en) Instruction generation method and device, electronic equipment and storage medium
CN109918132B (en) Instruction installation method and device, electronic equipment and storage medium
CN112631695A (en) Data verification method and device, electronic equipment and storage medium
CN107193622B (en) Code compiling processing method and device and terminal
CN111596949B (en) Method and device for developing application program
CN113778440B (en) Data processing method and device, electronic equipment and storage medium
CN113420531B (en) Code text conversion method, device and storage medium
CN116991416A (en) Program compiling method, device, electronic equipment and storage medium
CN113342355B (en) Code compiling method and device, electronic equipment and storage medium
CN112711420B (en) Code conversion method and device
CN116414392A (en) Compiling method and device based on inline extension, electronic equipment and storage medium
CN116954713A (en) Component generation method, device, electronic equipment and storage medium
CN114528200A (en) Method and device for dynamically modifying instruction, electronic equipment and storage medium
CN114661338A (en) Program package processing method and device, electronic equipment and storage medium
CN112256274A (en) Application program processing method and device and storage medium

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
GR01 Patent grant