CN115373689A - Compiling optimization method, device, equipment and medium based on LLVM - Google Patents

Compiling optimization method, device, equipment and medium based on LLVM Download PDF

Info

Publication number
CN115373689A
CN115373689A CN202211170504.9A CN202211170504A CN115373689A CN 115373689 A CN115373689 A CN 115373689A CN 202211170504 A CN202211170504 A CN 202211170504A CN 115373689 A CN115373689 A CN 115373689A
Authority
CN
China
Prior art keywords
compiling
variable
target
llvm
type
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.)
Pending
Application number
CN202211170504.9A
Other languages
Chinese (zh)
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.)
Shenzhen Inovance Technology Co Ltd
Original Assignee
Shenzhen Inovance Technology 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 Shenzhen Inovance Technology Co Ltd filed Critical Shenzhen Inovance Technology Co Ltd
Priority to CN202211170504.9A priority Critical patent/CN115373689A/en
Publication of CN115373689A publication Critical patent/CN115373689A/en
Pending legal-status Critical Current

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/70Software maintenance or management
    • G06F8/72Code refactoring

Abstract

The invention discloses a compiling optimization method, a compiling optimization device, compiling optimization equipment and a compiling optimization medium based on an LLVM (Linear virtual machine), which relate to the technical field of the LLVM. And by replacing a compiling interface consuming time in compiling with a compiling function and calling the compiling function to compile by referring to a target memory address, performing function packaging and corresponding interface replacement on API instructions with low compiling efficiency and low compiling efficiency of part of LLVMs. Therefore, the technical problems of low compiling speed and low compiling efficiency when the LLVM compiles and optimizes the data of the target platform in a non-standard alignment mode are solved, and the real-time compiling speed and efficiency of the LLVM are improved.

Description

Compiling optimization method, device, equipment and medium based on LLVM
Technical Field
The present invention relates to the technical field of LLVM, and in particular, to a compiling optimization method based on LLVM, a compiling optimization device based on LLVM, and a computer storage medium.
Background
At present, in the process of compiling and optimizing an LLVM (low level virtual machine), since part of a target platform is not in a standard memory alignment manner, a source code of the LLVM needs to be modified for adaptation. Specifically, in the expression operation process, low-precision data needs to be promoted to a high-precision data type, but the operation and compilation speed of part of 32-bit Application Programming Interface (API) of the LLVM on the high-precision data type of the target platform such as 64/128 bits is slow, which affects the compilation efficiency, so that a mechanism for generating assembly codes at the bottom layer of the LLVM needs to be changed. The LLVM open source library has huge codes, complex modules, few documents, full English, difficulty in understanding, huge maintenance workload, uncertain influence on modifying bottom layer codes and easy bringing of unstable factors and consequences.
Disclosure of Invention
The invention mainly aims to provide a compiling and optimizing method based on LLVM, a compiling and optimizing device based on LLVM and a computer storage medium, and aims to solve the technical problems of low compiling speed and low compiling efficiency of LLVM in the prior art when compiling and optimizing data in a target platform in a non-standard alignment mode.
In order to achieve the above object, the present invention provides a compiling optimization method based on LLVM, which includes the following steps:
determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by a LLVM front end;
adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
determining a compiling component set corresponding to the abstract syntax tree, and replacing a target compiling interface in the compiling component set with a corresponding compiling function to obtain a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and calling the target compiling component set and compiling by referring to the second variable memory address information to generate an LLVM intermediate code corresponding to the source code.
Further, before the step of adjusting the first type address in the first variable memory address information to the second type address to obtain the second variable memory address information, the method further includes:
constructing a preset local variable pool, wherein the preset local variable pool comprises temporary variables, and the temporary variables correspond to the standard alignment mode of the first type address data type;
the step of adjusting the first type address in the first variable memory address information to a second type address to obtain second variable memory address information includes:
and adjusting the first type address in the first variable memory address information into a second type address through the temporary variable to obtain second variable memory address information.
Further, the step of adjusting the first type address in the memory address information of the first variable to the second type address through the temporary variable includes:
determining whether a target temporary variable exists in the preset local variable pool, wherein the data type of the target temporary variable is the same as the corresponding variable of the first type address;
if so, replacing the variable of the first type address with the target temporary variable;
if not, replacing the variable of the first type address with the temporary variable of an array type.
Further, the step of replacing the variable of the first type address with the temporary variable of an array type includes:
determining a first storage space bit number of a variable of the first type address;
determining a second number of bits of storage space for the temporary variable of a preset local variable Chi Zhongshu group type;
replacing a variable of the first type address with the temporary variable of an array type based on the first number of storage space bits and the second number of storage space bits;
wherein the array size of the temporary variable is a multiple of the first number of bits of storage space compared to the second number of bits of storage space.
Further, before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
determining a compiling instruction corresponding to the target compiling interface;
compiling the compiling instruction into an executable file of the target platform;
and packaging the executable file into the compiling function.
Further, after the step of packaging the executable file into the compiled function, the method further includes:
generating a corresponding relation between the target compiling interface and the compiling function;
before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
determining a target compiling interface in the compiling component set based on identification information corresponding to an expression operation process;
the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function includes:
and determining a target compiling function corresponding to the target compiling interface based on the corresponding relation, and replacing the target compiling interface with the target compiling function.
Further, the step of calling the target compiling component set and compiling with reference to the second variable memory address information includes:
calling a compiling interface in the target compiling component set to compile a non-expression operation process by referring to the second variable memory address information;
and calling a compiling function in the target compiling component set to compile the expression operation process by referring to the second variable memory address information.
In addition, to achieve the above object, the present invention further provides a compiling optimization device based on LLVM, where the device includes:
the device comprises a determining module, a judging module and a judging module, wherein the determining module is used for determining first variable memory address information corresponding to an abstract syntax tree, and the abstract syntax tree is obtained by converting a source code of a target platform by an LLVM front end;
the adjusting module is used for adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
the replacing module is used for determining a compiling component set corresponding to the abstract syntax tree, replacing a target compiling interface in the compiling component set with a corresponding compiling function, and obtaining a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and the generating module is used for calling the target compiling component set and compiling by referring to the second variable memory address information to generate the LLVM intermediate code corresponding to the source code.
In addition, to achieve the above object, the present invention further provides a compiling optimization device based on LLVM, where the compiling optimization based on LLVM includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program configured to implement the steps of the LLVM-based compilation optimization method of any one of the above.
Furthermore, to achieve the above object, the present invention further provides a computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the LLVM-based compilation optimization method as described in any one of the above.
The invention provides a compiling optimization method based on LLVM, a compiling optimization device based on LLVM and a computer storage medium, wherein the method comprises the following steps: determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by a LLVM front end; adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode; determining a compiling component set corresponding to the abstract syntax tree, and replacing a target compiling interface in the compiling component set with a corresponding compiling function to obtain a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process; and calling the target compiling component set and compiling by referring to the second variable memory address information to generate an LLVM intermediate code corresponding to the source code. In the application, on the basis of not modifying the source code of the LLVM open source library, the non-standard memory alignment variable of the target platform is adapted in a mode of replacing the memory address in the non-standard alignment mode with the target memory address in the standard alignment mode. And by replacing a compiling interface consuming compiling time with a compiling function and calling the compiling function to compile according to the target memory address, the API instruction with low compiling efficiency and low compiling efficiency of part of LLVM is subjected to function packaging and corresponding interface replacement. Therefore, the technical problems of low compiling speed and low compiling efficiency when the LLVM compiles and optimizes the data of the target platform in a non-standard alignment mode are solved, and the real-time compiling speed and efficiency of the LLVM are improved.
Drawings
Fig. 1 is a schematic structural diagram of the hardware operation of a terminal device according to an embodiment of the present invention;
FIG. 2 is a flow chart of an embodiment of a compiling optimization method based on LLVM in the present invention;
FIG. 3 is a diagram of a conventional compiler architecture;
FIG. 4 is a schematic diagram of an LLVM architecture;
FIG. 5 is a schematic diagram of a local variable pool of another embodiment of the LLVM-based compilation optimization method of the present invention;
FIG. 6 is a schematic diagram of a memory alignment construction according to another embodiment of the LLVM-based compilation optimization method of the present invention;
fig. 7 is a schematic diagram of a compiling process of another embodiment of the LLVM-based compiling optimization method of the present invention.
The objects, features and advantages of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic structural diagram of a hardware operating environment related to a terminal device according to an embodiment of the present invention.
It should be noted that fig. 1 is a schematic structural diagram of a hardware operating environment of the terminal device. The terminal equipment of the embodiment of the invention can be storage equipment based on nand flash as a storage medium. As shown in fig. 1, a terminal device executing the LLVM-based compilation optimization method provided by the present invention may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a storage device 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The storage device 1005 may be a non-volatile storage device (e.g., a Flash storage device), a high-speed RAM storage device, or a non-volatile memory device (e.g., a magnetic disk storage device). The storage device 1005 may alternatively be a storage means separate from the aforementioned processor 1001.
Those skilled in the art will appreciate that the terminal device configuration shown in fig. 1 is not intended to be limiting of the terminal device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a storage device 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a computer program. Among other things, the operating system is a program that manages and controls the hardware and software resources of the sample terminal device, supporting the operation of computer programs and other software or programs.
In the terminal apparatus shown in fig. 1, the user interface 1003 is mainly used for data communication with each terminal; the network interface 1004 is mainly used for connecting a background server and performing data communication with the background server; and the processor 1001 may be configured to call a computer program stored in the storage device 1005 and perform the following operations:
determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by a LLVM front end;
adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
determining a compiling component set corresponding to the abstract syntax tree, and replacing a target compiling interface in the compiling component set with a corresponding compiling function to obtain a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and calling the target compiling component set and compiling by referring to the second variable memory address information to generate an LLVM intermediate code corresponding to the source code.
Further, the processor 1001 may call a computer program stored in the storage device 1005, and also perform the following operations:
before the step of adjusting the first type address in the first variable memory address information to the second type address to obtain the second variable memory address information, the method further includes:
constructing a preset local variable pool, wherein the preset local variable pool comprises temporary variables, and the temporary variables correspond to the standard alignment mode of the first type address data type;
the step of adjusting the first type address in the first variable memory address information to a second type address to obtain second variable memory address information includes:
and adjusting the first type address in the first variable memory address information into a second type address through the temporary variable to obtain second variable memory address information.
Further, the processor 1001 may call a computer program stored in the storage device 1005, and also perform the following operations:
the step of adjusting the first type address in the memory address information of the first variable to the second type address through the temporary variable includes:
determining whether a target temporary variable exists in a preset local variable pool, wherein the data type of the target temporary variable is the same as the corresponding variable of the first type address;
if so, replacing the variable of the first type address with the target temporary variable;
if not, replacing the variable of the first type address with the temporary variable of an array type.
Further, the processor 1001 may call a computer program stored in the storage device 1005, and also perform the following operations:
the step of replacing the variable of the first type address with the temporary variable of an array type includes:
determining a first storage space bit number of a variable of the first type address;
determining a second number of bits of storage space for the temporary variable of a preset local variable Chi Zhongshu group type;
replacing a variable of the first type address with the temporary variable of an array type based on the first number of storage space bits and the second number of storage space bits;
wherein the array size of the temporary variable is a multiple of the first number of bits of storage space compared to the second number of bits of storage space.
Further, the processor 1001 may call a computer program stored in the storage device 1005, and also perform the following operations:
before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
determining a compiling instruction corresponding to the target compiling interface;
compiling the compiling instruction into an executable file of the target platform;
and packaging the executable file into the compiling function.
Further, the processor 1001 may call a computer program stored in the storage device 1005, and also perform the following operations:
after the step of packaging the executable file into the compiled function, the method further includes:
generating a corresponding relation between the target compiling interface and the compiling function;
before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
determining a target compiling interface in the compiling component set based on identification information corresponding to the expression operation process;
the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function comprises the following steps:
and determining a target compiling function corresponding to the target compiling interface based on the corresponding relation, and replacing the target compiling interface with the target compiling function.
Further, the step of calling the target compiling component set and compiling with reference to the second variable memory address information includes:
calling a compiling interface in the target compiling component set to compile a non-expression operation process by referring to the second variable memory address information;
and calling a compiling function in the target compiling component set to compile the expression operation process by referring to the second variable memory address information.
Referring to fig. 3, in a conventional compiler architecture, frontend is a front end, and performs lexical analysis, syntax analysis, semantic analysis, and intermediate code generation; the Optimizer is an Optimizer and realizes the optimization of intermediate codes; backend is the back end, and generates the machine code. Referring to fig. 4, LLVM replaces the C language in modern language compiler implementation, source code can be compiled into LLVM intermediate code (LLVM IR), and then the intermediate code is optimized by LLVM backend and compiled into binary program of corresponding target platform.
Specifically, taking C language compiler Clang as an example, the overall architecture of the compiler using the LLVM backend is described: firstly, the front-end compiler of Clang can make preprocessing, syntax analysis and semantic analysis of the code of C language, and convert the character string of 'source code' into meaningful data in the internal memory, i.e. generate abstract syntax tree; secondly, generating LLVM IR intermediate codes according to an abstract syntax tree in a memory; the LLVM backend then optimizes the IR after it has been read. The corresponding component in the LLVM back end performs corresponding optimization according to the input LLVM IR and the corresponding optimization level, and outputs the corresponding LLVM IR. Finally, the corresponding component in the LLVM back end generates assembly codes for the LLVM IR, and calls an assembler and a linker of an operating system to finally generate an executable program.
Referring to fig. 2, fig. 2 is a flowchart illustrating a compiling optimization method based on LLVM according to an embodiment of the present invention.
In this embodiment, the LLVM-based compilation optimization method includes:
and step S10, determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by an LLVM front end.
Step S20, adjusting a first type address in the first variable memory address information to a second type address, to obtain second variable memory address information, where the first type address is a memory address in a non-standard alignment manner, and the second type address is a memory address in a standard alignment manner.
In the expression operation process, low-precision data needs to be promoted to a high-precision data type, but the operation and the compiling speed of part of API of the 32-bit LLVM on high-precision data types such as 64/128 bits are low, and the compiling efficiency is influenced. Therefore, in contrast to the conventional manner of directly compiling the variable memory address of the first variable memory address information of the source code corresponding to the node of the abstract syntax tree to generate the LLVM intermediate code corresponding to the source code, in this embodiment, the first type address in the non-standard alignment manner is replaced by the second type address in the standard alignment manner to obtain the second variable memory address information, and then the LLVM intermediate code is compiled and generated with subsequent reference to the second variable memory address information.
Further, step S10 is preceded by: determining a standard alignment mode, optionally, a default four-byte memory alignment mode, or a set memory alignment mode of other byte sizes; further, the step of determining a standard alignment mode includes: and determining a variable memory address in the current source code, and taking the most memory address alignment mode in the variable memory address as a standard alignment mode to adapt to the variable memory address of the current source code, thereby further improving the compiling efficiency.
Further, step S10 further includes: analyzing an abstract syntax tree to obtain the address information of the first variable memory; and determining a first type address and a second type address in the first variable memory address information.
And S30, determining a compiling component set corresponding to the abstract syntax tree, and replacing a target compiling interface in the compiling component set with a corresponding compiling function to obtain a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process.
Similarly, when the compiling efficiency of the API is low and the compiling speed is slow, unlike the conventional way of directly modifying the mechanism for generating the assembly code at the bottom layer of the LLVM, in this embodiment, the compiling instruction corresponding to the compiling interface for generating the LLVM intermediate code according to the abstract syntax tree is compiled in advance and packaged as the compiling function, and the compiling interface is replaced.
Further, the determining the compiling component set corresponding to the abstract syntax tree includes: determining nodes of the abstract syntax tree; and determining the compiling interfaces required by the nodes, and forming the compiling interfaces corresponding to all the nodes into the compiling component set. The abstract syntax tree is an abstract representation of the syntax structure of the source code, the syntax structure of the programming language is represented in the form of a tree, and each node on the tree represents a structure in the source code. Each node corresponds to a different compiling interface, and compiling interfaces of all nodes are combined into a compiling component set corresponding to the current source code.
Further, the replacing the target compiling interface in the compiling component set with a corresponding compiling function includes: determining a target compiling interface in compiling interfaces in the compiling component set through identification information corresponding to the expression operation process; and determining a target compiling function corresponding to the target compiling interface based on the corresponding relation between the target compiling interface and the compiling function, and replacing the target compiling interface with the target compiling function. And when the LLVM intermediate code is obtained by compiling the source code, replacing a target compiling interface required by the expression operation process with a target compiling function so as to obtain a target compiling component set, wherein the target compiling component set comprises the target compiling function called by the expression operation process and the compiling interface called by the non-expression operation process.
And step S40, calling the target compiling component set and compiling by referring to the second variable memory address information to generate an LLVM intermediate code corresponding to the source code.
Further, the invoking the target compiling component set and compiling with reference to the second variable memory address information includes: and calling a target compiling function in the target compiling component set to compile the expression operation process, and calling a compiling interface in the target compiling component set to compile the non-expression operation process.
Further, the step of calling the target compiling component set and compiling with reference to the second variable memory address information includes:
step S401, calling a compiling interface in the target compiling component set to compile a non-expression operation process by referring to the second variable memory address information;
step S402, calling a compiling function in the target compiling component set to compile the expression operation process with reference to the second variable memory address information.
When compiling the non-expression operation process, calling a compiling interface in the target compiling component set and compiling by referring to a second type address in second variable memory address information corresponding to the non-expression operation process; when compiling the expression operation process, calling a compiling function in the target compiling component set and compiling by referring to a second type address in second variable memory address information corresponding to the expression operation process.
Therefore, referring to fig. 7, different from the conventional method of calling the compiling interface to compile the variable memory address in the non-standard alignment manner with the compiling instruction, in this embodiment, the replaced compiling function is called and compiled with reference to the second type address of the replaced second variable memory address information, so as to generate the LLVM intermediate code corresponding to the source code. Finally, the corresponding component in the LLVM back end generates assembly codes for the LLVM IR, and calls an assembler and a linker of an operating system to finally generate an executable program.
In this embodiment, the non-standard memory-aligned variable of the target platform is adapted in a manner of replacing the memory address in the non-standard aligned manner with the target memory address in the standard aligned manner without modifying the source code of the LLVM open source library. And by replacing a compiling interface consuming compiling time with a compiling function and calling the compiling function to compile according to the target memory address, the API instruction with low compiling efficiency and low compiling efficiency of part of LLVM is subjected to function packaging and corresponding interface replacement. Therefore, the technical problems of low compiling speed and low compiling efficiency when the LLVM compiles and optimizes the data of the target platform in a non-standard alignment mode are solved, and the real-time compiling speed and efficiency of the LLVM are improved by more than 10 times.
Referring to fig. 5, fig. 5 is a schematic diagram of a local variable pool according to another embodiment of the LLVM-based compilation optimization method of the present invention.
In this embodiment, before the step of adjusting the first type address in the first variable memory address information to the second type address to obtain the second variable memory address information, the method further includes:
step A, constructing a preset local variable pool, wherein the preset local variable pool comprises temporary variables, and the temporary variables correspond to the standard alignment mode of the first type address data type;
the step of adjusting the first type address in the first variable memory address information to a second type address to obtain second variable memory address information includes:
and step B, adjusting the first type address in the first variable memory address information into a second type address through the temporary variable to obtain second variable memory address information.
Further, the temporary variables in the preset local variable pool comprise historical variables appearing in the compiling process before the current compiling process; the method for constructing the preset local variable pool comprises the following steps: and constructing a preset local variable pool according to the historical variables. The preset local variable pool is automatically filled and expanded by using the historical variables of different data types in each compiling process, so that the adaptability of the preset local variable pool is improved, and the flexibility of the preset local variable pool is improved.
In this embodiment, the variable memory address in the non-standard alignment manner is replaced by the target memory address in the standard alignment manner through the preset local variable pool which is built in advance as shown in fig. 5, so that the preset local variable pool shown in fig. 5 is built in advance before the step of replacing the first type address in the non-standard alignment manner by the second type address in the standard alignment manner. In the default local variable pool, there are, but not limited to, 32-bit floating point type variables, 64-bit double precision floating point type variables, 64-bit integer type variables, and other temporary variables in the standard alignment mode corresponding to the variable memory address in the non-standard alignment mode.
Optionally, referring to fig. 6, the step of adjusting the first type address in the memory address information of the first variable to the second type address through the temporary variable includes:
step B1, determining whether a target temporary variable exists in a preset local variable pool, wherein the data type of the target temporary variable is the same as the corresponding variable of the first type address;
step B2, if the variable exists, replacing the variable of the first type address with the target temporary variable;
and step B3, if the temporary variable does not exist, replacing the variable of the first type address with the temporary variable of the array type.
Further, the step of determining whether a target temporary variable of the same data type as the variable of the first type address in the first variable memory address information exists in a preset local variable pool includes: determining the data type of the temporary variable in a preset local variable pool; determining the data type of the variable of the first type address in the first variable memory address information; and determining whether the target temporary variable exists in a preset local variable pool or not based on the data type of the temporary variable and the data type of the variable of the first type address.
When a first type address in a non-standard alignment mode is replaced by a second type address in a standard alignment mode through a preset local variable pool, firstly, a variable of the first type address is replaced by a temporary variable which has the same data type as the variable of the first type address in the preset local variable pool, and then the first type address which does not have the temporary variable which has the same data type as the variable of the first type address in the preset local variable pool is replaced by a temporary variable of an array type. In an implementable mode, the non-four bytes of the target platform are aligned to the memory, on one hand, the size and the layout of the variable memory are consistent through the same type of local variable replacement and on the other hand, the newly-built array is adopted for variable replacement. And after the replaced memory is used for operation, executing memory copy to complete data synchronization.
Optionally, the standard alignment mode is four-byte alignment, and the preset local variable pool includes a 32-bit floating point type standard temporary variable corresponding to the standard alignment mode. In one example, the standard alignment mode is four-byte alignment, so the 32-bit floating-point standard temporary variables in the preset local variable pool are temporary variables of the standard alignment mode, and the rest are temporary variables of the non-standard alignment mode. The local variable pool provides various reusable variables, and aims to reduce the occupation of the instantaneous memory of the target platform and prevent the memory of the target platform from overflowing; in addition, standard four byte aligned variables are provided for replacing the original variables.
Further, the step of replacing the variable of the first type address with the temporary variable of an array type includes:
step B31, determining a first storage space bit number of the variable of the first type address;
step B32, determining a second storage space bit number of the temporary variable of a preset local variable Chi Zhongshu group type;
step B33, replacing the variable of the first type address with the temporary variable of the array type based on the first number of bits of the storage space and the second number of bits of the storage space;
wherein the array size of the temporary variable is a multiple of the first number of bits of storage space compared to the second number of bits of storage space.
Further, the step of replacing the variable of the first type address with the temporary variable of an array type based on the first number of bits of storage space and the second number of bits of storage space comprises: determining an array temporary variable of which the second storage space bit number is an integral multiple of the first storage space bit number in different temporary variables of array types; and determining an array temporary variable for replacing the variable of the first type address in array temporary variables corresponding to the integral multiple of storage space bits. The method for determining the temporary variables of the array for replacing the variables of the first type address in the temporary variables of the array corresponding to the integer times of the bits of the storage space is not limited.
In one implementable manner, replacing said first type of address in a non-standard aligned manner with said standard temporary variable of said 32-bit floating point type of array type; the array size of the standard temporary variable is a multiple of the number of memory address bits of the first type address compared with the number of memory address bits of the standard temporary variable. In this example, when a first type address of a temporary variable of the same data type as the first type address does not exist in the preset local variable pool is replaced by a temporary variable of an array type, a variable memory address of a non-standard alignment mode is replaced by a standard temporary variable of a 32-bit floating point type of the array type, wherein the array size of the standard temporary variable is a multiple of the first type address compared with the standard temporary variable. For example, a four-byte integer variable may be replaced with two 16-bit one-byte arrays. The input memory address of the floating-point arithmetic unit requires four-byte alignment, and the target platform variable address is allocated to a non-four-byte memory, so that when the intermediate language is generated by using the API of the LLVM, the value of the non-four-byte address needs to be assigned to a four-byte variable in an internal local variable pool, and then the non-four-byte memory address variable is replaced by the value.
In another embodiment of the LLVM-based compilation optimization method of the present invention, before the step of replacing the target compilation interface in the compilation component set with the corresponding compilation function, the method includes:
p1, determining a compiling instruction corresponding to the target compiling interface;
p2, compiling the compiling instruction into an executable file of the target platform;
and P3, packaging the executable file into the compiling function.
Further, the step of determining the compiling instruction corresponding to the target compiling interface includes: and acquiring an interface identifier of the target compiling interface, and calling a compiling instruction corresponding to the interface identifier. Further, the step of compiling the compiling instruction into an executable file of the target platform includes: compiling the compiling instruction into an executable file of the target platform based on a compiler of the target platform or a compiler in an LLVM architecture.
In this embodiment, the improvement of the LLVM compiling efficiency is essentially to compile the time-consuming LLVM API into the entity function of the target platform in advance, and then replace the time-consuming compiled API instruction with a function calling method when generating the intermediate program, so as to realize the improvement of the real-time compiling efficiency. Therefore, in this embodiment, a compiling instruction corresponding to the target compiling interface API is determined first, then the compiling instruction is compiled into an executable file of the target platform in advance, and the executable file is packaged as a compiling function, so that a mode of directly calling the API instruction is replaced during the LLVM compiling, and efficient real-time compiling is directly performed in a mode of calling the function.
After the step of packaging the executable file into the compiled function, the method further includes:
p4, generating a corresponding relation between the target compiling interface and the compiling function;
further, the corresponding relationship is a corresponding relationship between the target compiling interface and the respective identifications of the compiling functions. The compiling function can be obtained by querying or matching in a preset compiling function library according to the corresponding relation according to the identifier of the target compiling interface.
Before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
step T, determining a target compiling interface in the compiling component set based on identification information corresponding to the expression operation process;
further, step T includes: determining a type identifier of the expression operation process, and determining the target compiling interface in the compiling component set through the type identifier; or, determining a compiling interface required by the expression operation process; determining a target compilation interface in the set of compilation components based on the identification of the compilation interface.
The step of replacing the target compiling interface in the compiling component set with the corresponding compiling function includes:
step S301, determining a target compiling function corresponding to the target compiling interface based on the corresponding relation, and replacing the target compiling interface with the target compiling function.
Determining a target compiling interface in compiling interfaces in the compiling component set through identification information corresponding to the expression operation process; and determining a target compiling function corresponding to the target compiling interface based on the corresponding relation between the target compiling interface and the compiling function, and further replacing the target compiling interface with the target compiling function.
In addition, an embodiment of the present invention further provides a compiling optimization device based on LLVM, where the device includes:
the determining module is used for determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by an LLVM front end;
the adjusting module is used for adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
the replacing module is used for determining a compiling component set corresponding to the abstract syntax tree, replacing a target compiling interface in the compiling component set with a corresponding compiling function, and obtaining a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and the generating module is used for calling the target compiling component set and compiling by referring to the second variable memory address information to generate the LLVM intermediate code corresponding to the source code.
Optionally, the apparatus further comprises:
a building module, configured to adjust the first type address in the first variable memory address information to a second type address, before the step of obtaining second variable memory address information:
constructing a preset local variable pool, wherein the preset local variable pool comprises temporary variables, and the temporary variables correspond to the standard alignment mode of the first type address data type;
an adjustment module further configured to:
and adjusting the first type address in the first variable memory address information into a second type address through the temporary variable to obtain second variable memory address information.
Optionally, the adjusting module is further configured to:
determining whether a target temporary variable exists in the preset local variable pool, wherein the data type of the target temporary variable is the same as the corresponding variable of the first type address;
if so, replacing the variable of the first type address with the target temporary variable;
if not, replacing the variable of the first type address with the temporary variable of an array type.
Optionally, the adjusting module is further configured to:
determining a first storage space bit number of a variable of the first type address;
determining a second number of bits of storage space for the temporary variable of a preset local variable Chi Zhongshu group type;
replacing a variable of the first type address with the temporary variable of an array type based on the first number of storage space bits and the second number of storage space bits;
wherein the array size of the temporary variable is a multiple of the first number of bits of storage space compared to the second number of bits of storage space
Optionally, the apparatus further comprises:
a packaging module, configured to replace the target compilation interface in the compilation component set with a corresponding compilation function before the step of replacing the target compilation interface in the compilation component set with the corresponding compilation function:
determining a compiling instruction corresponding to the target compiling interface;
compiling the compiling instruction into an executable file of the target platform;
and packaging the executable file into the compiling function.
Optionally, the packaging module is further configured to, after the step of packaging the executable file into the compiled function:
generating a corresponding relation between the target compiling interface and the compiling function;
optionally, the replacing module is further configured to, before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function:
determining a target compiling interface in the compiling component set based on identification information corresponding to the expression operation process;
optionally, the replacing module is further configured to determine, based on the corresponding relationship, a target compiling function corresponding to the target compiling interface, and replace the target compiling interface with the target compiling function.
Optionally, the generating module is further configured to invoke a compiling interface in the target compiling component set to compile a non-expression operation process with reference to the second variable memory address information;
and calling a compiling function in the target compiling component set to compile the expression operation process by referring to the second variable memory address information.
According to the compiling and optimizing device based on the LLVM, the compiling and optimizing method based on the LLVM is adopted, and the technical problems that in the prior art, when the LLVM is used for compiling and optimizing data in a target platform non-standard alignment mode, the compiling speed is low and the compiling efficiency is low are solved. Compared with the prior art, the beneficial effects of the compiling and optimizing device based on the LLVM provided by the embodiment of the present invention are the same as the beneficial effects of the compiling and optimizing method based on the LLVM provided by the above embodiment, and other technical features in the compiling and optimizing device based on the LLVM are the same as the features disclosed in the above embodiment method, which are not described herein again.
In addition, an embodiment of the present invention further provides a compiling optimization device based on the LLVM, where the compiling optimization based on the LLVM includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program configured to implement the steps of the LLVM-based compilation optimization method of any one of the above.
Furthermore, an embodiment of the present invention further provides a computer storage medium, where a computer program is stored, and when the computer program is executed by a processor, the steps of the LLVM-based compilation optimization method described in any one of the above are implemented.
The steps implemented when the computer program running on the processor is executed may refer to various embodiments of the LLVM-based compilation optimization method of the present invention, and are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system 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 system. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a computer storage medium (e.g., F l ash storage device, ROM/RAM, magnetic disk, optical disk), and includes several instructions for enabling a controller, which is used for controlling the storage medium to perform data reading and writing operations, in a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A compilation optimization method based on LLVM is characterized by comprising the following steps:
determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by a LLVM front end;
adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
determining a compiling component set corresponding to the abstract syntax tree, and replacing a target compiling interface in the compiling component set with a corresponding compiling function to obtain a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and calling the target compiling component set and compiling by referring to the second variable memory address information to generate an LLVM intermediate code corresponding to the source code.
2. The LLVM-based compilation optimization method of claim 1, wherein before the step of adjusting the first type address in the first variable memory address information to the second type address to obtain the second variable memory address information, the method further comprises:
constructing a preset local variable pool, wherein the preset local variable pool comprises temporary variables, and the temporary variables correspond to the standard alignment mode of the first type address data type;
the step of adjusting the first type address in the first variable memory address information to a second type address to obtain second variable memory address information includes:
and adjusting the first type address in the first variable memory address information into a second type address through the temporary variable to obtain second variable memory address information.
3. The LLVM-based compilation optimization method of claim 2 wherein said step of adjusting said first-type address in said first-variable memory address information to a second-type address through said temporary variable comprises:
determining whether a target temporary variable exists in the preset local variable pool, wherein the data type of the target temporary variable is the same as the corresponding variable of the first type address;
if so, replacing the variable of the first type address with the target temporary variable;
if not, replacing the variable of the first type address with the temporary variable of an array type.
4. The LLVM-based compilation optimization method of claim 3 wherein said step of replacing variables of said first type address with said temporary variables of an array type comprises:
determining a first storage space bit number of a variable of the first type address;
determining a second number of bits of storage space for the temporary variable of a preset local variable Chi Zhongshu group type;
replacing a variable of the first type address with the temporary variable of an array type based on the first number of storage space bits and the second number of storage space bits;
wherein the array size of the temporary variable is a multiple of the first number of bits of storage space compared to the second number of bits of storage space.
5. The LLVM-based compilation optimization method of claim 1, wherein prior to the step of replacing the target compilation interface in the set of compilation components with the corresponding compilation function, further comprising:
determining a compiling instruction corresponding to the target compiling interface;
compiling the compiling instruction into an executable file of the target platform;
and packaging the executable file into the compiling function.
6. The LLVM-based compilation optimization method of claim 5, wherein after the step of packaging the executable file as the compiled function, further comprising:
generating a corresponding relation between the target compiling interface and the compiling function;
before the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function, the method further includes:
determining a target compiling interface in the compiling component set based on identification information corresponding to the expression operation process;
the step of replacing the target compiling interface in the compiling component set with the corresponding compiling function includes:
and determining a target compiling function corresponding to the target compiling interface based on the corresponding relation, and replacing the target compiling interface with the target compiling function.
7. The LLVM-based compilation optimization method of claim 1 wherein said step of calling said set of target compilation components and compiling with reference to said second variable memory address information comprises:
calling a compiling interface in the target compiling component set to compile a non-expression operation process by referring to the second variable memory address information;
and calling a compiling function in the target compiling component set to compile the expression operation process by referring to the second variable memory address information.
8. An LLVM-based compilation optimization apparatus, the apparatus comprising:
the determining module is used for determining first variable memory address information corresponding to an abstract syntax tree, wherein the abstract syntax tree is obtained by converting a source code of a target platform by an LLVM front end;
the adjusting module is used for adjusting a first type address in the first variable memory address information to a second type address to obtain second variable memory address information, wherein the first type address is a memory address in a non-standard alignment mode, and the second type address is a memory address in a standard alignment mode;
the replacing module is used for determining a compiling component set corresponding to the abstract syntax tree, replacing a target compiling interface in the compiling component set with a corresponding compiling function, and obtaining a target compiling component set, wherein the target compiling interface is a compiling interface corresponding to an expression operation process;
and the generating module is used for calling the target compiling component set and compiling by referring to the second variable memory address information to generate the LLVM intermediate code corresponding to the source code.
9. An LLVM-based compilation optimization device, wherein the LLVM-based compilation optimization comprises: memory, a processor and a computer program stored on the memory and executable on the processor, the computer program configured to implement the steps of the LLVM-based compilation optimization method of any of claims 1 to 7.
10. A computer storage medium having a computer program stored thereon, wherein the computer program when executed by a processor implements the steps of the LLVM-based compilation optimization method of any of claims 1-7.
CN202211170504.9A 2022-09-23 2022-09-23 Compiling optimization method, device, equipment and medium based on LLVM Pending CN115373689A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211170504.9A CN115373689A (en) 2022-09-23 2022-09-23 Compiling optimization method, device, equipment and medium based on LLVM

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211170504.9A CN115373689A (en) 2022-09-23 2022-09-23 Compiling optimization method, device, equipment and medium based on LLVM

Publications (1)

Publication Number Publication Date
CN115373689A true CN115373689A (en) 2022-11-22

Family

ID=84070698

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211170504.9A Pending CN115373689A (en) 2022-09-23 2022-09-23 Compiling optimization method, device, equipment and medium based on LLVM

Country Status (1)

Country Link
CN (1) CN115373689A (en)

Similar Documents

Publication Publication Date Title
US7559050B2 (en) Generating software development tools via target architecture specification
EP0718760B1 (en) Method and apparatus for generating platform-standard object files containing machine-independent code
CN110149800B (en) Apparatus for processing abstract syntax tree associated with source code of source program
US5606697A (en) Compiler system for language processing program
US7823139B2 (en) Method and system for translating programming languages
US20070271553A1 (en) Method and system for translating assembler code to a target language
KR20050001472A (en) Software development infrastructure
US20130139137A1 (en) Systems and Methods for Customizing Optimization/Transformation/ Processing Strategies
US20110126179A1 (en) Method and System for Dynamic Patching Software Using Source Code
CN112799677B (en) Method, device, equipment and storage medium for hook of compiling period
JP2001022591A (en) Compiler device, computer-readable recording medium where compiling program is recorded, and compiling method
CN112379917A (en) Browser compatibility improving method, device, equipment and storage medium
JP2005141380A (en) Template compile method
US6519768B1 (en) Instruction translation method
US20080320456A1 (en) Targeted patching
CN111435312B (en) Application program management method and device and electronic equipment
US5418959A (en) Instruction operation size optimization
US20090187897A1 (en) Compiling method and compiling program
CN111930359B (en) System and method for developing algorithm on heterogeneous embedded system
CN111596970A (en) Dynamic library delay loading method, device, equipment and storage medium
JP5506936B2 (en) Object level compatibility and class resizing using semantic values
CN112000334A (en) Page development method, device, server and storage medium
US8793671B2 (en) Interface optimization in a closed system
CN115373689A (en) Compiling optimization method, device, equipment and medium based on LLVM
JPH08241196A (en) Branch instruction processing system

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