CN114661296A - Program code compiling method, program code compiling device, electronic equipment and storage medium - Google Patents

Program code compiling method, program code compiling device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114661296A
CN114661296A CN202210314501.1A CN202210314501A CN114661296A CN 114661296 A CN114661296 A CN 114661296A CN 202210314501 A CN202210314501 A CN 202210314501A CN 114661296 A CN114661296 A CN 114661296A
Authority
CN
China
Prior art keywords
callee
register
code
call
function
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
CN202210314501.1A
Other languages
Chinese (zh)
Other versions
CN114661296B (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.)
Uc Mobile Co ltd
Original Assignee
Alibaba China Co 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 China Co Ltd filed Critical Alibaba China Co Ltd
Priority to CN202210314501.1A priority Critical patent/CN114661296B/en
Publication of CN114661296A publication Critical patent/CN114661296A/en
Application granted granted Critical
Publication of CN114661296B publication Critical patent/CN114661296B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4432Reducing the energy consumption
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

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

Abstract

In the embodiment of the application, a callee register mechanism is introduced in a program code compiling process, so that when a program runs, if registers in a callee saving register set need to be modified by a callee function, values of the registers are saved on a call stack and restored to the registers when the call is finished, and if the values of the registers do not need to be modified, the values of the registers are not saved on the call stack, so that instruction consumption can be reduced to a great extent, computational resources consumed by saving the registers are reduced, the frequency of modifying the registers is reduced, and program code performance and size are improved.

Description

Program code compiling method, program code compiling device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for compiling a program code, an electronic device, and a storage medium.
Background
Program code typically includes a plurality of functions, both calling and called functions, that are called by calling functions. When a calling function calls a called function, data needs to be transferred by means of a register and a Call stack (Call stack). Generally, when a calling function calls a called function, it is assumed that the called function modifies values stored in all registers of a Central Processing Unit (CPU), and for this purpose, the values stored in all registers need to be stored in a Call stack (Call stack), and after the function Call is finished, the values stored in the Call stack are restored to the registers again. If the code amount of the program code is large and the number of the called functions is large, the above method wastes much calculation power and affects the performance of the program code.
Disclosure of Invention
Aspects of the present application provide a program code compiling method, apparatus, electronic device, and storage medium, to reduce instruction consumption, reduce computational resources consumed by saving registers, reduce the frequency of modifying registers, and improve the performance and volume of a program code.
An embodiment of the present application provides a program code compiling method, including: acquiring a source code expressed in a source language corresponding to a target application program, wherein the target application program refers to an application program depending on a virtualized operating environment; defining a function call convention aiming at a source code, wherein the function call convention indicates a callee saved register set and a saving sequence of the callee saved registers in the set on a call stack; compiling the source code according to the function calling convention, and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register allocation stage in the compiling process so as to obtain the executable code.
An embodiment of the present application further provides a program code compiling apparatus, including: the system comprises an acquisition module, a processing module and a display module, wherein the acquisition module is used for acquiring a source code expressed in a source language corresponding to a target application program, and the target application program refers to an application program depending on a virtualized running environment; the definition module is used for defining a function call convention aiming at the source code, wherein the function call convention indicates a callee saved register set and a saving sequence of the callee saved registers in the set on a call stack; and the compiling module is used for compiling the source code according to the function calling convention and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register distribution stage in the compiling process so as to obtain the executable code.
An embodiment of the present application further provides an electronic device, including: a memory and a processor; a memory for storing a computer program; the processor is coupled to the memory for executing the computer program for performing the steps in the program code compilation method.
Embodiments of the present application also provide a computer storage medium storing a computer program, which, when executed by a processor, causes the processor to implement the steps in the program code compiling method.
In the embodiment of the application, a callee register mechanism is introduced in a program code compiling process, so that when a program runs, a callee function only performs stack protection on registers in a callee saving register set, and under the condition that the registers in the callee saving register set need to be modified, values of the registers are saved on a call stack and restored to the registers when the call is finished, and if the values of the registers do not need to be modified, the values of the registers are not saved on the call stack, so that instruction consumption can be reduced to a great extent, calculation resources consumed by saving the registers are reduced, the frequency of modifying the registers is reduced, and program code performance and size are improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a flowchart of a program code compiling method according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a program code compiling apparatus according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Generally, when a calling function calls a called function, it is assumed that the called function modifies values stored in all registers of a Central Processing Unit (CPU), and for this purpose, the values stored in all registers need to be stored in a Call stack (Call stack), and after the function Call is finished, the values stored in the Call stack are restored to the registers again. If the code amount of the program code is large and the number of the called functions is large, the above method wastes much calculation power and affects the performance of the program code. In view of the foregoing technical problems, embodiments of the present application provide a program code compiling method and apparatus, an electronic device, and a storage medium. In the embodiment of the application, a callee register mechanism is introduced in a program code compiling process, so that when a program runs, a callee function only performs stack protection on registers in a callee saving register set, and under the condition that the registers in the callee saving register set need to be modified, values of the registers are saved on a call stack and restored to the registers when the call is finished, and if the values of the registers do not need to be modified, the values of the registers are not saved on the call stack, so that instruction consumption can be reduced to a great extent, calculation resources consumed by saving the registers are reduced, the frequency of modifying the registers is reduced, and program code performance and size are improved.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a flowchart of a program code compiling method according to an embodiment of the present disclosure. The method may be performed by a program code compiling means, which may be implemented by means of software and/or hardware, and may generally be integrated in an electronic device. Referring to fig. 1, the method may include the steps of:
101. and acquiring source codes expressed in a source language corresponding to the target application program, wherein the target application program refers to the application program depending on the virtualized running environment.
102. And defining a function call convention aiming at the source code, wherein the function call convention indicates a set of saved registers of a callee and a saving sequence of the saved registers of the callee in the set on a call stack.
103. Compiling the source code according to the function calling convention, and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register allocation stage in the compiling process so as to obtain the executable code.
Generally, a compiler (compiler) compiles a program code by using different compiling tools to perform syntax analysis, lexical analysis, and the like on a source code file to form an Abstract Syntax Tree (AST); in the intermediate code generation stage, converting the abstract syntax tree into an Intermediate Representation (IR), and optimizing the intermediate representation; in an instruction selection (instruction selection) stage, the optimized intermediate representation can be converted into machine codes which can be identified by a machine through an instruction selection operation; and in the register allocation stage, executing register allocation operation on the machine code to obtain a final executable code. The compiler may be a compiler (compiler) adopting an LLVM (Low Level Virtual Machine) framework.
The present embodiment does not limit the source language of the source code, and the source language includes, but is not limited to: and various programming languages such as Dart language, c language and c + + language. Among them, Dart is an object-oriented, class-defined, single-inheritance programming language, support interface (interfaces), mix (mistxins), abstract class (abstract classes), materialized generic (differentiated classes), optional type (optional typing), and the like.
In this embodiment, source code associated with the application may be compiled. The application program can be an application program depending on a virtualized running environment or a real electronic device. Among them, an application program relying on a virtualized execution environment may be understood as an application program running in a Virtual Machine (VM). For ease of understanding, the application that relies on the virtualized execution environment will be referred to as the target application. Alternatively, the target application may be a flutter engine or an application that uses a flutter engine. The flutter engine may also be referred to as a Hummer engine, but is not limited thereto. In the case that the target application is an application using a flute/hummer engine, and a code corresponding to the application is written in Dart language, a VM operating environment (for example, a virtual machine providing a Dart operating environment, which may be referred to as a Dart virtual machine for short) may be provided, and an LLVM compiler is used in the VM operating environment to compile a source code using the capability of the LLVM compiler, so as to improve the quality of an executable code corresponding to the target application. The compiling process of this embodiment merges the callee register saving mechanism, and the specific compiling process is described in the following embodiments.
In this embodiment, the definition of the function call convention is performed on the source code to be compiled. The defined function call convention indicates the set of callee saved registers and the order in which the callee saved registers in the set are saved on the call stack. The callee saved registers (callee saved registers) refer to registers used by the calling function for parameter transfer, and values in the callee saved registers can be accessed and modified by the called function. If the value in the saved register of the callee needs to be modified by the callee, the value in the saved register of the callee needs to be saved in the call stack, and after the function is called, the value is restored by the callee, that is, the value is read from the call stack and rewritten into the saved register of the callee. The caller saved registers (caller saved registers) are opposite to the callee saved registers, the value in the caller saved registers does not need to be saved, and if a program needs to save the value of the caller saved registers, the main call function needs to save the value of the caller saved registers to the call stack first. Among the registers that can be provided by the CPU, register RAX, register RCX, register RDX, register R8, register R9, register R10, register R11, and the like are generally divided into caller holding registers. The register RBX, register RBP, register RDI, register RSI, register RSP, register R12, register R13, register R14, register R15, and the like are divided into callee-saved registers.
Specifically, for a calling instruction of each main calling function calling a called function in a source code, a register required to be used by the called function when the calling instruction is executed is used as a called saving register corresponding to the calling instruction, the called saving register is added to a called saving register set corresponding to the calling instruction, and finally, a function calling convention of the calling instruction is defined according to the called saving register set and a saving sequence of the called saving registers in the set on a calling stack. And sequencing all the callee storage registers in the callee storage register set according to the storage sequence of the callee storage registers on the call stack. The saving order of the callee saving registers on the call stack refers to the order in which the callee function saves the values in the corresponding callee saving registers to the call stack. For example, the called function related to a certain call instruction needs to use the register R12, the register R13, and the register R14 in sequence, and the callee-saved register set corresponding to the certain call instruction sequentially includes the register R12, the register R13, and the register R14.
After a function calling convention is carried out on a calling instruction in a source code, the source code is compiled based on the function calling convention. The whole compiling process is basically consistent with the conventional compiling process, and is different from the conventional compiling process in that the compiling process is realized at least in an intermediate code generating stage, an instruction selecting stage and a register distributing stage according to a function calling convention so as to obtain an executable code supporting a register saving mechanism of a callee. The executable code obtained by the embodiment can reduce the frequency of modifying the register in the running process, so that the times of saving the register are reduced, the calculation resources are reduced, and the code execution performance is better.
As an example, alternative implementations for implementing the function call convention during the intermediate code generation phase are: in the process of converting a source code into an intermediate code, adding attribute information in a function statement of the intermediate code and an intermediate state calling instruction to obtain the intermediate code; the attribute information represents the callee saved register set and the saving order of the callee saved registers in the set on the call stack.
It is noted that the attribute information representation is related to the intermediate representation corresponding to the intermediate code. Taking an LLVM compiler as an example, LLVM intermediate code is an LLVM underlying instruction. Optionally, if the intermediate representation mode corresponding to the intermediate code supports the character string, the attribute information is a self-defined character string. For example, the function calling convention corresponding to a certain calling instruction is set as { r10, r11, r12, r13}, and the attribute information represented by a character string is { r10, r11, r12, r13}, and the attribute information represented by the character string is added to the function declaration and the intermediate state calling instruction of the intermediate code in the intermediate code generation stage. The intermediate state call instruction is an intermediate representation obtained by converting the call instruction in the source code in the intermediate code generation stage.
It should be noted that attribute information is also added to the function declaration of the intermediate code, so that the compiler can be informed that a new function call convention needs to be processed in the compiling process.
As an example, alternative implementations for implementing the function call convention during the instruction selection phase are: in the process of converting the intermediate code into the target machine code, adding a processing algorithm for processing the attribute information aiming at a selection algorithm for selecting a machine calling instruction for the intermediate state calling instruction; the processing algorithm is used to convert the attribute information into an object of an operand of the selected machine call instruction, the object of the operand indicating that a calling function executing the machine call instruction cannot modify a callee's saved register in the set of callee's saved registers.
In this embodiment, the selection algorithm used to select the machine call instruction for the intermediate state call instruction may be any existing instruction selection algorithm, including, but not limited to: based on a tree-based pattern-matching algorithm, based on a pattern extension algorithm, and based on an aggressive iterative peephole optimization (iterative optimization) algorithm.
In this embodiment, a processing algorithm for processing the attribute information newly added in the intermediate code is added in the selection algorithm, and the attribute information processed by the processing algorithm is converted into an object of an operand of the machine call instruction in the instruction selection stage, where the object of the operand indicates that a master call function executing the machine call instruction cannot modify a callee holding register in the callee holding register set. Alternatively, in the case of an LLVM compiler, the operand object may be a RegMask type object, which is a set of bits, and the registers in the set are not modified. The machine call instruction refers to a call instruction that can be executed by a machine. The machine calling instruction is obtained by selecting the intermediate state calling instruction represented by the intermediate state calling instruction and is also the machine code corresponding to the calling instruction represented by the source language.
It should be noted that, in the code execution stage, when the machine call instruction is executed, based on the object of the operand newly added to the machine call instruction, the master call function cannot modify the callee saving register in the callee saving register set, and in addition, based on the object of the operand newly added to the machine call instruction, the callee saving register in the callee saving register set is only used by the function called by the machine call instruction, that is, the callee function only saves the value in the callee saving register to the call stack, and after the call is finished, the value saved to the call stack is restored to the callee saving register. For example, in the instruction selection stage, attribute information expressed in the form of a character string newly added in the intermediate code is processed, the obtained operand may be in the form of RegMask, and the LLVM can recognize the calling convention through the RegMask. The RegMask form is a set, for example, RegMask { R10, R11, R12, R13} indicates that the callmaker function of the corresponding machine call instruction does not modify registers R10, R11, R12, and R13, and meets the previous convention of saving register sets by callees, which is a specific implementation of the convention.
It should be understood that, in such a function calling manner, since the called function is not required to store the values of all registers in the CPU on the call stack, and after the call is completed, the values on the call stack are restored to the registers, instruction consumption can be greatly reduced, computational resources can be saved, and program code performance can be improved.
As an example, alternative implementations for implementing the function call convention during the register allocation phase are: adding an interference algorithm in the adopted register allocation algorithm, wherein the interference algorithm is used for limiting the allocation relation between the callee saved register set and the variable types operable by the garbage recycling operation; and allocating registers for variables in the target machine code based on a register allocation algorithm after the interference algorithm is added.
Register allocation is a method for increasing the execution speed of a program by allocating program variables to registers as much as possible. The register of this embodiment refers to a register used by a compiler to represent a variable, and may be a CPU register or a space on a call stack. Alternatively, where an LLVM compiler is employed, the register allocation is also referred to as LLVM LiveIntervals. LLVM live intervals is an LLVM algorithm for calculating register life cycle and interference, and can generate LLVM live intervals set for query. LLVM live interval is an LLVM data structure that describes the life cycle of a register. In this embodiment, the register allocation algorithm may be any existing register allocation algorithm, including, but not limited to: graph coloring (graph coloring) algorithm, linear scan (linear scan) algorithm, integer linear programming algorithm, SSA (Static Single Assignment) based register allocation algorithm.
In this embodiment, an interference algorithm is newly added to the register allocation algorithm, and the interference algorithm may constrain variables allocated to the callee saved register set based on an allocation relationship between the variable types operable to define the callee saved register set and the garbage collection operation. Wherein the allocation relationship may indicate whether variables in the target machine code having a same variable type as operable by the garbage collection operation may be allocated to the callee saved registers in the set of callee saved registers.
The purpose of the Garbage Collection (GC) operation is to track all the objects in use, mark the remaining objects as Garbage, and then clear the objects marked as Garbage, and recover the memory occupied by the Garbage objects, thereby implementing automatic management of the memory.
It is noted that, when the variable type of the variable of the target machine code is a variable type operable by a Garbage Collection (GC) operation, during a triggering period of the Garbage Collection operation, the Garbage Collection operation scans a memory space for storing a value of the variable, and when it is determined that the scanned value of the variable is an active value, continues to store the active value in the memory space; and upon determining that the value of the scanned variable is not an active value, clearing the active value saved in the memory space. For more description of garbage collection operations in memory management, reference may be made to the related art.
As an example, based on the register allocation algorithm after adding the interference algorithm, alternative implementations of allocating registers for variables in the target machine code are: traversing variables related to a machine call instruction in the target code aiming at each callee saving register in the callee saving register set; and if the variable type of the currently traversed variable belongs to the pointer type or the reference type defined in the allocation relation, distributing the currently traversed variable to a saved register of a callee.
The variable type in the allocation relationship indicating that the garbage collection operation is operable may be a pointer type or a reference type, and the other variable types except the pointer type or the reference type are not operable variable types for the garbage collection operation. Other variable types include, for example, but are not limited to: integer type, character type, floating point type, etc.
It is noted that when the variable involved in the machine call instruction does not belong to the pointer type or the reference type defined in the above allocation relationship, other registers in the CPU are allocated to the currently traversed variable.
As another example, an alternative implementation of allocating registers for variables in the target machine code based on a register allocation algorithm after adding the interference algorithm is: traversing a register in the CPU aiming at any variable in the target code, and if the currently traversed register is a callee saving register in a callee saving register set; judging whether the variable type of the variable belongs to a pointer type or a reference type defined in the distribution relationship; if the variable type of the variable is a pointer type or a reference type defined in the allocation relation, allocating a currently traversed callee storage register to the variable; if the variable type of the variable is other than the pointer type or the reference type, the callee save register is prohibited from being allocated to the variable.
For example, if a value that the GC should not scan is allocated to a callee saved register in the set of callee saved registers and the callee saved register is used by the callee function when the machine call instruction executes, for example, an integer value 0 that the GC should not scan is allocated to the callee saved register R10, and the callee function also uses R10, the integer value 0 needs to be saved to the call stack according to the function call convention. If a GC operation occurs at this time, when the GC detects the called function, the GC scans the position of the value R10 on the call stack, so as to scan the integer value 0, and at this time, the GC operation tries to mark the object corresponding to the integer value 0 in the memory, so as to cause a crash.
In practical applications, some source codes use the Safe Point (Safe Point) technology. The safe point is a point during program execution where all GC roots are known and the contents of all heap objects are consistent. GC Root refers to an object of a Garbage Collector (Garblage Collector), which GC will collect objects that are not GC roots and are not referenced by GC roots. If the source code uses the security point technology, the method further includes: and at the safety point generation stage in the compiling process, realizing aiming at the function calling convention.
Further optionally, in the security point generation stage in the compiling process, implementing for the function call contract includes: and generating a corresponding safety point aiming at the machine call instruction selected in the instruction selection stage, and adding a corresponding scanning position of a callee storage register in the callee storage register set in a call stack in metadata of the safety point.
In practical application, a corresponding security point may be generated for each machine call instruction, and a scanning position corresponding to the machine call instruction is added to metadata of the security point, where the scanning position refers to a scanning position corresponding to a callee storage register in a callee storage register set in a call stack. The GC can safely scan the values at these locations without crashing. In this embodiment, the callee register saving mechanism can be fully utilized for a function using a security point, thereby reducing the volume of generated code and improving the performance of code.
In this embodiment, the source code may obtain an executable code after undergoing the compiling process, and the executable code supports the callee register saving mechanism, so that the execution process is different from that of the conventional executable code, specifically: during the running phase of the executable code, when the executable code is run to an entry point, a callee saving register in a callee saving register set can be initialized to a specific value, wherein the specific value is a NULL value, for example, and the NULL value is a value which can be safely scanned by a GC; and when the garbage collection operation is triggered in the running process of the executable code, if the garbage collection operation relates to a machine call instruction, scanning the call stack according to the scanning position in the corresponding safety point.
According to the program code compiling method provided by the embodiment of the application, a callee register mechanism is introduced in the program code compiling process, so that when a program runs, a callee function only needs to modify the values of registers in a callee saving register set, the values in the registers are saved on a call stack and restored to the registers after the call is finished, and other registers which are not used by the callee function in a CPU do not need to be saved to the call stack. In addition, the program code compiling method of the embodiment can be used for all functions, and can be applied to both a fast path and a slow path. The fast/slow path is a path defined with a high entry frequency when a program jumps, for example, whether stack space overflows is checked, the overflow is a fast path, and the overflow is a slow path. Since the probability program that does not overflow determines to be a high probability event, it is defined as a fast path.
It should be noted that the execution subjects of the steps of the methods provided in the above embodiments may be the same device, or different devices may be used as the execution subjects of the methods. For example, the execution subjects of steps 101 to 103 may be device a; for another example, the execution subject of steps 101 and 102 may be device a, and the execution subject of step 103 may be device B; and so on.
In addition, in some of the flows described in the above embodiments and the drawings, a plurality of operations are included in a specific order, but it should be clearly understood that the operations may be executed out of the order presented herein or in parallel, and the sequence numbers of the operations, such as 101, 102, etc., are merely used for distinguishing different operations, and the sequence numbers do not represent any execution order per se. Additionally, the flows may include more or fewer operations, and the operations may be performed sequentially or in parallel. It should be noted that, the descriptions of "first", "second", etc. in this document are used for distinguishing different messages, devices, modules, etc., and do not represent a sequential order, nor limit the types of "first" and "second" to be different.
Fig. 2 is a schematic structural diagram of a program code compiling apparatus according to an embodiment of the present disclosure. Referring to fig. 2, the apparatus may include: an acquisition module 21, a definition module 22 and a compilation module 23.
The obtaining module 21 is configured to obtain a source code expressed in a source language corresponding to a target application, where the target application is an application depending on a virtualized operating environment;
a defining module 22, configured to define a function call convention for a source code, where the function call convention indicates a callee saving register set and a saving order of callee saving registers in the set on a call stack;
the compiling module 23 is configured to compile the source code according to the function call convention, and implement the compiling at least in the intermediate code generation stage, the instruction selection stage, and the register allocation stage in the compiling process according to the function call convention to obtain the executable code.
Further optionally, when the compiling module 23 is implemented in the intermediate code generation stage for the function call convention, the compiling module is specifically configured to: in the process of converting a source code into an intermediate code, adding attribute information in a function statement and an intermediate state calling instruction of the intermediate code to obtain the intermediate code; the attribute information represents the callee saved register set and the saving order of the callee saved registers in the set on the call stack.
Further optionally, if the intermediate representation mode corresponding to the intermediate code supports a character string, the attribute information is a self-defined character string.
Further optionally, when the compiling module 23 is implemented in the instruction selection stage for a function call convention, the compiling module is specifically configured to: in the process of converting the intermediate code into the target machine code, adding a processing algorithm for processing the attribute information aiming at a selection algorithm for selecting a machine calling instruction for the intermediate state calling instruction; the processing algorithm is used to convert the attribute information into an object of an operand of the selected machine call instruction, the object of the operand indicating that a calling function executing the machine call instruction cannot modify a callee's saved register in the set of callee's saved registers.
Further optionally, when the compiling module 23 implements the function call convention in the register allocation stage, specifically configured to: adding an interference algorithm in an adopted register allocation algorithm, wherein the interference algorithm is used for limiting the allocation relation between a callee storage register set and the operable variable types of the garbage recycling operation; and allocating registers for variables in the target machine code based on a register allocation algorithm after the interference algorithm is added.
Further optionally, when the compiling module 23 allocates a register for a variable in the target machine code based on the register allocation algorithm after the interference algorithm is added, the compiling module is specifically configured to: traversing variables related to a machine call instruction in the target code aiming at each callee saving register in the callee saving register set; and if the variable type of the currently traversed variable belongs to the pointer type or the reference type defined in the allocation relation, distributing the currently traversed variable to a saved register of the callee.
Further optionally, if the source code uses a security point technique, the compiling module 23 is further configured to:
and at the safety point generation stage in the compiling process, realizing aiming at the function calling convention.
Further optionally, when the compiling module 23 is implemented in a safety point generating stage in the compiling process aiming at the function call convention, it is specifically configured to: and generating a corresponding safety point aiming at the machine call instruction selected in the instruction selection stage, and adding a corresponding scanning position of a callee storage register in the callee storage register set in a call stack in metadata of the safety point.
Further optionally, the method further comprises: an execution module; the execution module is used for initializing a callee saving register in the callee saving register set to a specific value when the execution module runs to an entry point of the executable code; and when the garbage collection operation is triggered in the running process of the executable code, if the garbage collection operation relates to a machine call instruction, scanning the call stack according to the scanning position in the corresponding safety point.
The program code compiling device shown in fig. 2 may execute the program code compiling method shown in the embodiment shown in fig. 1, and the implementation principle and the technical effect are not described again. The specific manner in which each module and each unit of the program code compiling device in the above embodiments execute the operations has been described in detail in the embodiments related to the method, and will not be described in detail herein.
Fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 3, the electronic apparatus includes: a memory 31 and a processor 32;
memory 31 is used to store computer programs and may be configured to store other various data to support operations on the computing platform. Examples of such data include instructions for any application or method operating on the computing platform, contact data, phonebook data, messages, pictures, videos, and so forth.
The memory 31 may be implemented by any type or combination of volatile or non-volatile 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 disks.
A processor 32, coupled to the memory 31, for executing the computer program in the memory 31 to: acquiring a source code expressed in a source language corresponding to a target application program, wherein the target application program refers to an application program depending on a virtualized operating environment; defining a function call convention aiming at a source code, wherein the function call convention indicates a callee storage register set and a storage sequence of callee storage registers in the set on a call stack; compiling the source code according to the function calling convention, and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register allocation stage in the compiling process so as to obtain the executable code.
Further optionally, when the processor 32 is implemented in the intermediate code generation stage for a function call convention, it is specifically configured to: in the process of converting a source code into an intermediate code, adding attribute information in a function statement of the intermediate code and an intermediate state calling instruction to obtain the intermediate code; the attribute information represents the callee saved register set and the saving order of the callee saved registers in the set on the call stack.
Further optionally, if the intermediate representation mode corresponding to the intermediate code supports a character string, the attribute information is a self-defined character string.
Further optionally, when the processor 32 is implemented in the instruction selection stage with respect to the function call convention, the processor is specifically configured to: in the process of converting the intermediate code into the target machine code, adding a processing algorithm for processing the attribute information aiming at a selection algorithm for selecting a machine calling instruction for the intermediate state calling instruction; the processing algorithm is used to convert the attribute information into an object of an operand of the selected machine call instruction, the object of the operand indicating that a calling function executing the machine call instruction cannot modify a callee's saved register in the set of callee's saved registers.
Further optionally, when the processor 32 implements the function call convention in the register allocation stage, the method is specifically configured to: adding an interference algorithm in the adopted register allocation algorithm, wherein the interference algorithm is used for limiting the allocation relation between the callee saved register set and the variable types operable by the garbage recycling operation; and allocating registers for variables in the target machine code based on a register allocation algorithm after the interference algorithm is added.
Further optionally, when the processor 32 allocates a register for a variable in the target machine code based on the register allocation algorithm after the interference algorithm is added, the method is specifically configured to: traversing variables related to a machine call instruction in the target code aiming at each callee saving register in the callee saving register set; and if the variable type of the currently traversed variable belongs to the pointer type or the reference type defined in the allocation relation, distributing the currently traversed variable to a saved register of the callee.
Further optionally, if the source code uses a security point technique, the processor 32 is further configured to:
and at the safety point generation stage in the compiling process, realizing aiming at the function calling convention.
Further optionally, when the processor 32 implements the function call convention at the security point generation stage in the compiling process, the method is specifically configured to: and generating a corresponding safety point aiming at the machine call instruction selected in the instruction selection stage, and adding a corresponding scanning position of a callee storage register in the callee storage register set in a call stack in metadata of the safety point.
Further optionally, the processor 32 is further configured to initialize a callee saved register in the callee saved register set to a specific value when running to an entry point of the executable code; and when the garbage collection operation is triggered in the running process of the executable code, if the garbage collection operation relates to a machine call instruction, scanning the call stack according to the scanning position in the corresponding safety point.
Further, as shown in fig. 3, the electronic device further includes: communications component 33, display 34, power component 35, audio component 36, and the like. Only some of the components are schematically shown in fig. 3, and it is not meant that the electronic device comprises only the components shown in fig. 3. In addition, the components within the dashed line in fig. 3 are optional components, not necessary components, and may be determined according to the product form of the electronic device. The electronic device of this embodiment may be implemented as a terminal device such as a desktop computer, a notebook computer, a smart phone, or an IOT device, or may be a server device such as a conventional server, a cloud server, or a server array. If the electronic device of this embodiment is implemented as a terminal device such as a desktop computer, a notebook computer, a smart phone, etc., the electronic device may include components within a dashed line frame in fig. 3; if the electronic device of this embodiment is implemented as a server device such as a conventional server, a cloud server, or a server array, the components in the dashed box in fig. 3 may not be included.
For details of the implementation process of each action performed by the processor, reference may be made to the foregoing method embodiment or the related description in the device embodiment, and details are not described herein again.
Accordingly, the present application further provides a computer-readable storage medium storing a computer program, where the computer program is capable of implementing the steps that can be executed by the electronic device in the foregoing method embodiments when executed.
Accordingly, the present application also provides a computer program product, which includes a computer program/instruction, when the computer program/instruction is executed by a processor, the processor is enabled to implement the steps that can be executed by an electronic device in the above method embodiments.
The communication component is configured to facilitate communication between the device in which the communication component is located and other devices in a wired or wireless manner. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, a mobile communication network such as 2G, 3G, 4G/LTE, 5G, or the like, or a combination thereof. In an exemplary embodiment, the communication component 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 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.
The display includes a screen, which 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 an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
The power supply assembly provides power for various components of the device in which the power supply assembly is located. The power components may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device in which the power component is located.
The audio component may be configured to output and/or input an audio signal. For example, the audio component includes a Microphone (MIC) configured to receive an external audio signal when the device in which the audio component is located is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal may further be stored in a memory or transmitted via a communication component. In some embodiments, the audio assembly further comprises a speaker for outputting audio signals.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams 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 apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, 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.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus 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 apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
The above are merely examples of the present application and are not intended to limit the present application. Various modifications and changes may occur to those skilled in the art to which the present application pertains. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of the present application shall be included in the scope of the claims of the present application.

Claims (12)

1. A program code compiling method, comprising:
acquiring a source code expressed in a source language corresponding to a target application program, wherein the target application program refers to an application program depending on a virtualized operating environment;
defining a function call convention aiming at the source code, wherein the function call convention indicates a callee saved register set and a saving sequence of the callee saved registers in the set on a call stack;
compiling the source code according to the function calling convention, and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register allocation stage in the compiling process so as to obtain an executable code.
2. The method of claim 1, wherein implementing for the function call convention during an intermediate code generation phase comprises:
in the process of converting the source code into the intermediate code, adding attribute information in a function statement and an intermediate state calling instruction of the intermediate code to obtain the intermediate code;
and the attribute information represents the callee saved register set and the saving sequence of the callee saved registers in the set on the call stack.
3. The method according to claim 2, wherein the intermediate representation corresponding to the intermediate code supports a character string, and the attribute information is a custom character string.
4. The method of claim 2, wherein implementing for the function call convention during an instruction selection phase comprises:
in the process of converting the intermediate code into a target machine code, adding a processing algorithm for processing the attribute information aiming at a selection algorithm for selecting a machine calling instruction for the intermediate state calling instruction;
the processing algorithm is used for converting the attribute information into an operand object of the selected machine call instruction, wherein the operand object indicates that a calling function executing the machine call instruction cannot modify a callee storage register in the callee storage register set.
5. The method of claim 4, wherein implementing for the function call convention during a register allocation phase comprises:
adding an interference algorithm in an adopted register allocation algorithm, wherein the interference algorithm is used for limiting the allocation relation between the callee saved register set and the variable types operable by the garbage collection operation;
and allocating registers for variables in the target machine code based on a register allocation algorithm after the interference algorithm is added.
6. The method of claim 5, wherein allocating registers for variables in the target machine code based on a register allocation algorithm after adding the interference algorithm comprises:
traversing variables involved by machine call instructions in the target code for each callee saved register in the set of callee saved registers;
and if the variable type of the currently traversed variable belongs to the pointer type or the reference type defined in the allocation relation, distributing the currently traversed variable to the callee storage register.
7. The method of any of claims 1-6, wherein if the source code uses a security point technique, the method further comprises:
and at the safety point generation stage in the compiling process, realizing aiming at the function calling convention.
8. The method of claim 7, wherein the implementation for the function call convention at a security point generation stage in a compilation process comprises:
and generating a corresponding safety point aiming at the machine call instruction selected by the instruction selection stage, and adding a scanning position, corresponding to a callee storage register in the callee storage register set, in a call stack in metadata of the safety point.
9. The method of claim 8, further comprising: when the executable code is run to an entry point, initializing a callee saving register in the callee saving register set to be a specific value; and
and when the garbage collection operation is triggered in the running process of the executable code, if the garbage collection operation relates to a machine call instruction, scanning the call stack according to the scanning position in the corresponding safety point.
10. A program code compiling apparatus characterized by comprising:
the system comprises an acquisition module, a processing module and a display module, wherein the acquisition module is used for acquiring a source code expressed in a source language corresponding to a target application program, and the target application program refers to an application program depending on a virtualized running environment;
the definition module is used for defining a function call convention aiming at the source code, wherein the function call convention indicates a callee saved register set and a saving sequence of the callee saved registers in the set on a call stack;
and the compiling module is used for compiling the source code according to the function calling convention and realizing the function calling convention at least in an intermediate code generation stage, an instruction selection stage and a register allocation stage in the compiling process so as to obtain an executable code.
11. An electronic device, comprising: a memory and a processor; the memory for storing a computer program; the processor is coupled to the memory for executing the computer program to perform the steps of the method of any of claims 1-9.
12. A computer storage medium having a computer program stored thereon, which, when executed by a processor, causes the processor to carry out the steps of the method of any one of claims 1 to 9.
CN202210314501.1A 2022-03-28 2022-03-28 Program code compiling method, program code compiling device, electronic equipment and storage medium Active CN114661296B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210314501.1A CN114661296B (en) 2022-03-28 2022-03-28 Program code compiling method, program code compiling device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210314501.1A CN114661296B (en) 2022-03-28 2022-03-28 Program code compiling method, program code compiling device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114661296A true CN114661296A (en) 2022-06-24
CN114661296B CN114661296B (en) 2022-12-09

Family

ID=82033733

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210314501.1A Active CN114661296B (en) 2022-03-28 2022-03-28 Program code compiling method, program code compiling device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114661296B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1271889A (en) * 1999-04-23 2000-11-01 太阳微系统有限公司 Method and device for using register distributor to establish calling convented preface and ending program code
CN102831005A (en) * 2012-07-13 2012-12-19 天津国芯科技有限公司 Compiling method for optimizing allocation of register based on C*core processor and compiler
CN106201641A (en) * 2015-04-29 2016-12-07 龙芯中科技术有限公司 The memory access co mpiler optimization method and apparatus of function
CN111857816A (en) * 2019-04-25 2020-10-30 阿里巴巴集团控股有限公司 Register allocation method and device, electronic equipment and computer storage medium
CN112052004A (en) * 2019-06-05 2020-12-08 深圳市汇顶科技股份有限公司 Function parameter optimization method, compiler, chip and electronic equipment
CN114217886A (en) * 2021-12-17 2022-03-22 统信软件技术有限公司 Function calling method, computing device and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1271889A (en) * 1999-04-23 2000-11-01 太阳微系统有限公司 Method and device for using register distributor to establish calling convented preface and ending program code
CN102831005A (en) * 2012-07-13 2012-12-19 天津国芯科技有限公司 Compiling method for optimizing allocation of register based on C*core processor and compiler
CN106201641A (en) * 2015-04-29 2016-12-07 龙芯中科技术有限公司 The memory access co mpiler optimization method and apparatus of function
CN111857816A (en) * 2019-04-25 2020-10-30 阿里巴巴集团控股有限公司 Register allocation method and device, electronic equipment and computer storage medium
CN112052004A (en) * 2019-06-05 2020-12-08 深圳市汇顶科技股份有限公司 Function parameter optimization method, compiler, chip and electronic equipment
CN114217886A (en) * 2021-12-17 2022-03-22 统信软件技术有限公司 Function calling method, computing device and storage medium

Also Published As

Publication number Publication date
CN114661296B (en) 2022-12-09

Similar Documents

Publication Publication Date Title
US11720344B2 (en) Code hot-update method and device, storage medium, processor, and terminal
US11379943B2 (en) Optimizing compilation of shaders
US8997070B2 (en) Extension mechanism for scripting language compiler
US10175965B2 (en) Multiphased profile guided optimization
EP3379412A1 (en) Method and device for identifying high-usage intermediate code in language virtual machine
CN114168111B (en) Method, device, product and storage medium for realizing componentized route
CN115328454A (en) Program compiling and program loading method
CN104142819B (en) A kind of document handling method and device
Novillo Samplepgo-the power of profile guided optimizations without the usability burden
CN114840214A (en) Program compiling and starting method, device and storage medium
US8769498B2 (en) Warning of register and storage area assignment errors
CN112604273B (en) Data-driven game system function loading method, device and storage medium
CN105005497A (en) Method and apparatus for calling local function in Java card virtual machine
CN114661296B (en) Program code compiling method, program code compiling device, electronic equipment and storage medium
CN113220306A (en) Operation execution method and device and electronic equipment
CN107450937B (en) Application program running method and running device
CN107451203A (en) Data bank access method and device
CN107817972B (en) Cache code processing method and device, storage medium and electronic equipment
CN113031952A (en) Method and device for determining execution code of deep learning model and storage medium
US11720468B1 (en) Unwinding program call stacks for performance profiling
CN113296777A (en) Dependency analysis and program compilation method, apparatus, and storage medium
CN117608557A (en) Interface generation method and device, electronic equipment and storage medium
Vergilio et al. Comparative Performance and Energy Efficiency Analysis of JVM Variants and GraalVM in Java Applications
Hunter EmbedDB: Query Optimizations and Code Amalgamation for Simple Distribution
CN117892836A (en) Deep learning machine instruction generation method and device supporting multiple back-end computing hardware

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Room 554, 5 / F, building 3, 969 Wenyi West Road, Wuchang Street, Yuhang District, Hangzhou City, Zhejiang Province

Applicant after: Alibaba (China) Co.,Ltd.

Address before: 310052 room 508, 5th floor, building 4, No. 699 Wangshang Road, Changhe street, Binjiang District, Hangzhou City, Zhejiang Province

Applicant before: Alibaba (China) Co.,Ltd.

TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20221109

Address after: 100080 A706, Floor 7, Block A, Building B-6, Zhongguancun Dongsheng Science Park, 66 Xixiaokou Road, Haidian District, Beijing

Applicant after: UC MOBILE Co.,Ltd.

Address before: Room 554, 5 / F, building 3, 969 Wenyi West Road, Wuchang Street, Yuhang District, Hangzhou City, Zhejiang Province

Applicant before: Alibaba (China) Co.,Ltd.

GR01 Patent grant
GR01 Patent grant