Cross-language compilation optimization method based on graph neural network

By constructing a unified mapping of cross-language abstract syntax trees and stream enhancement processing, combined with a lightweight transformer architecture, the problem of migrating compiler automatic tuning methods between different compilers and programming languages ​​is solved. This achieves efficient global optimization and accurate compiler decisions, improving compiler performance and stability.

CN121764480BActive Publication Date: 2026-06-09NANJING UNIV OF INFORMATION SCI & TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING UNIV OF INFORMATION SCI & TECH
Filing Date
2026-03-05
Publication Date
2026-06-09

Smart Images

  • Figure CN121764480B_ABST
    Figure CN121764480B_ABST
Patent Text Reader

Abstract

This invention discloses a cross-language compiler optimization method based on graph neural networks. The method uses a UAST module to map the abstract syntax trees (ASTs) of different programming languages ​​to a shared semantic space. The FUAST module then fuses control flow and data flow information to form a flow-enhanced AST representation. The Sub2Vec module extracts key optimization subgraphs such as control flow, function inlining, and loops, and models their local structure and global relationships. The IRGAT module uses a sparse attention mechanism after structural pruning to aggregate features from the subgraphs, generating graph-enhanced sequence vectors. Finally, the SALT module, based on a lightweight Transformer architecture, embeds IRGAT as a structure-aware component, which processes and outputs optimization decisions through a feedforward network. This invention achieves unified semantic understanding, dynamic information fusion, and key region focusing for multi-language programs, and possesses compiler platform versatility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of compiler optimization technology, and more specifically to a cross-language compiler optimization method based on graph neural networks. Background Technology

[0002] As the number of compiler optimization options integrated into the compiler framework increases, the cost of exhaustive manual tuning becomes enormous. Fixed heuristic strategies, based on simple static analysis models and lacking runtime information, mean that extensive manual debugging of the compiler is required every time it is deployed to new hardware, resulting in poor portability and scalability. To address these issues, machine learning models offer new approaches to compiler optimization.

[0003] Because existing compilers and automatic tuning methods are only designed for a single programming language, and different programming languages ​​exhibit significant differences in syntax structure and abstract syntax tree organization across different compilers, automatic tuning methods struggle to learn and reason within a unified semantic space, making their optimizations difficult to transfer. To address these issues, cross-language compiler optimization research is of great significance for improving software performance consistency and engineering efficiency.

[0004] To address cross-language challenges, a dual-neural network framework has been proposed, learning semantic features from two different programming languages ​​and employing structurally similar dual networks for code feature learning. While this model can handle cross-language program classification tasks, it essentially learns features from a single programming language separately and then fuses the code features from different languages. Furthermore, this architecture has poor scalability; as the number of programming languages ​​increases, additional networks are needed, leading to increased network complexity and training time. Therefore, pre-trained models based on self-supervised learning have been proposed. These models train code features on large corpora containing multiple programming languages ​​and can be applied to cross-language program classification tasks. However, this model does not perform specific preprocessing for different languages; it only directly generates a hybrid training abstract syntax tree (AST), essentially failing to consider the differences between different languages.

[0005] To address the flow augmentation problem in ASTs, graph representations based on flow inversion (IR) have been proposed. These methods simplify the optimization process by removing redundant control flow edges, constructing compact graph representations. For example, ConteXtual Flow Graph (XFG) integrates control flow and data flow relationships to achieve unsupervised embedding learning of LLVM-IR statements. It omits key analysis information, including parameter order concepts, vertices of variables and constants, and all control flow edges. In data flow graph-based representations, each node uses a hand-designed feature representation, which is then processed using LSTM after serialization. Existing techniques employ graph structures specifically designed for vectorization tasks to represent LLVM-IR. These structures distinguish the positions of the first five operands through unique edge types and pre-compute vectorization opportunities to augment the graph structure.

[0006] Direct prediction based on machine learning can predict the performance of new programs based on historical program data, such as the SLOPS method. It automatically generates compiler optimization parameters based on supervised learning techniques, making decisions on optimization parameters such as loop unrolling factor, block factor, and array fill factor. It directly predicts the optimal parameters for new programs, reducing search overhead. However, it focuses on optimization parameters in multiple local optimizations, making it incomplete and unable to guarantee optimization at the global level. Machine learning-driven iterative compilation, on the other hand, incorporates machine learning techniques into the traditional iterative compilation optimization process, such as the ALIC model. It uses supervised learning methods, first describing the target program using base static and dynamic feature representations, constructing an initial optimization prediction model using a classifier, and then advancing the early data labeling and updating the prediction model by selecting training samples based on active learning. It maximizes performance gains by dynamically adjusting compiler optimization sub-options, but it does not optimize at the code granularity, and the active iteration computation is significant.

[0007] Furthermore, the application of the Transformer architecture in code language tasks has attracted attention. Code languages ​​(such as variable scope, function calls, control flow, etc.) have highly structured long-distance dependencies and are strict syntactic and semantic combinations. The Transformer architecture retains hierarchical modeling capabilities well and has a natural advantage in handling structural dependencies. For example, CodeBERT is based on a multi-layer Transformer architecture and uses contrastive learning to bring code languages ​​closer to their corresponding vector representations. It is trained using a hybrid objective function, but it does not integrate AST and data flow graphs, resulting in poor accuracy on code tasks. Moreover, the self-attention mechanism of the Transformer introduces high time complexity, which is not conducive to embedding it into compilers. To improve task accuracy, the GNNFormers architecture and GAT graph attention network have been proposed. GNNFormers embeds the GNN model into the Transformer architecture, which enhances the model's ability to integrate information, but the model parameters are too large. GAT aggregates neighbor information by adaptively learning the importance weights between nodes. Although it can capture the attention weights between nodes, the computational cost is too high. To reduce model parameters and computational costs, a lightweight Transformer model architecture was proposed, which replaces the cumbersome self-attention mechanism in the Transformer with a feedforward neural network (FFN). Although this reduces the computational cost of the model, the lack of a self-attention mechanism leads to poor accuracy. Summary of the Invention

[0008] Purpose of the invention: The purpose of this invention is to provide a cross-language compiler optimization method based on graph neural networks, which solves the problem of the difficulty in transferring existing compiler automatic tuning methods across different compilers or different programming languages, as well as the lack of global optimization at the code granularity in existing compiler automatic tuning methods and the imbalance between model computation and model optimization decision accuracy.

[0009] Technical solution: The cross-language compilation optimization method based on graph neural networks described in this invention is characterized by the following steps:

[0010] (1) Parse the source code of different programming languages, obtain their respective abstract syntax trees, and map the abstract syntax tree nodes of different languages ​​to a shared lexical space through unified semantic mapping, so as to achieve a unified representation of cross-language grammatical structures.

[0011] (2) Based on the unified representation of the abstract syntax tree, the syntax tree is structurally enhanced by incorporating control flow and data flow information, and multiple additional edges representing variable dependencies, execution order and branch jumps are added to construct a flow-enhanced abstract syntax tree that integrates static syntax and dynamic behavior.

[0012] (3) Identify and extract key subgraph structures for compiler optimization from the flow-enhanced abstract syntax tree, including control flow subgraph, loop structure subgraph and function call subgraph, and extract the internal topological features of each key subgraph and its boundary association features with the global syntax tree respectively;

[0013] (4) Perform graph attention aggregation operation on the extracted key subgraphs, and use the pruning attention mechanism based on the sparse characteristics of graph structure to perform weighted fusion of the features of nodes in each subgraph to generate a serialized feature vector that fuses graph structure information.

[0014] (5) The generated serialized feature vector is input into the lightweight transformer architecture for processing. This architecture embeds a graph attention aggregation component as a structure-aware unit in the encoding layer and uses a feedforward network to replace the self-attention mechanism in the standard transformer. After residual connection, layer normalization and fully connected operations, the compiler optimization decision result is output.

[0015] Further, step (1) is as follows: by constructing a unified vocabulary mapping table across programming languages, the syntax node types generated by parsing source code of different languages ​​are mapped to a shared vocabulary space; at the same time, a sequence neural network is used to extract the global sequence features of the abstract syntax tree, a graph neural network is used to extract the local structural features of the abstract syntax tree, and the global sequence features and local structural features are fused to form a unified syntax tree representation across languages.

[0016] Furthermore, in step (2), the types of additional edges added include: sequential edges between adjacent leaf nodes, execution order edges between sibling nodes, data dependency edges between variable nodes and their next usage location, control flow edges between conditional statements and corresponding execution blocks, loop flow edges between loop structures and loop bodies, and sequential execution flow edges between statements within a code block.

[0017] Furthermore, in step (3), the core regions of interest to the compiler optimization are obtained by using the anchor region message passing mechanism, and the internal structure representation of the subgraph and its semantic association representation with the global syntax tree are constructed based on the internal position features, boundary position features, internal neighborhood features, boundary neighborhood features, internal connectivity features and boundary connectivity features of the subgraph.

[0018] Furthermore, in step (4), a combination of graph structure sparsity pruning attention mechanism and sliding window attention and global attention is adopted. Sliding window attention only focuses on the local neighbor nodes of each node, while global attention focuses on the preset global key nodes. The structural pruning strategy reduces the computational complexity of attention while maintaining the ability to perceive the graph structure.

[0019] Furthermore, in step (5), the graph attention aggregation component is embedded in the transformer coding layer as a structure-aware unit. The self-attention mechanism of the standard transformer is replaced by a feedforward network, and the graph attention information provided by the embedded structure-aware unit is used to enhance the ability to extract code structure features.

[0020] An electronic device according to the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement any of the methods described herein.

[0021] The present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods described herein.

[0022] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: The present invention completes the unified mapping and flow enhancement processing of cross-language abstract syntax trees at the compiler front end, completes the extraction of subgraphs of key optimization regions and the generation of graph enhancement features at the compiler mid-end, and completes the prediction and output of optimization decisions based on the lightweight transformer architecture at the compiler back end; Specifically, the following advantages are: (1) Unifying the abstract syntax trees (AST) of different programming languages ​​through the UAST module to achieve cross-language semantic alignment. By using the FUAST module to integrate static syntax and dynamic execution information, the learning of key program features such as variable life cycle, branch reachability, and data flow path is enhanced; (2) The Sub2Vec module is proposed, and the "anchor region message passing" mechanism is adopted to accurately extract the key optimization subgraphs such as CFG, function inlining, and loops from the large graph. By modeling the topological features and boundary semantics of the six subgraphs, the local structural features and global associations are taken into account, avoiding information overload and focus dispersion caused by global graph analysis. (3) Integrating the lightweight Transformer (SALT) and the improved graph attention mechanism (IRGAT), the ability to extract code structure features and usage scenarios is enhanced while maintaining lightweightness. IRGAT reduces self-attention redundancy and improves the model's understanding of code structure by using sliding window attention and structure-aware pruning. (4) In the SPEC CPU2000 test, compared with the compiler's native O3 optimization, the SPEC score is improved by 18%, the number of CPU instructions executed is reduced by 5%, and the branch prediction error rate is reduced by 63%. It is superior to existing machine learning optimization methods (such as SLOPS and ALIC) and has significant improvements in multiple indicators. (5) It performs well in different compiler environments such as GCC and LLVM. The SPEC score on GCC reaches 1.95, which is better than 1.86 on LLVM, showing good adaptability and optimization stability; it has compiler platform universality. Attached Figure Description

[0023] Figure 1 This is a flowchart of the present invention;

[0024] Figure 2 This is a UAST framework diagram of the present invention;

[0025] Figure 3 This is a FUAST example diagram of the present invention;

[0026] Figure 4 This is a diagram of the Sub2Vec framework of the present invention;

[0027] Figure 5 This is a schematic diagram of the IGSALT framework of the present invention;

[0028] Figure 6 This is a SALT module diagram of the present invention. Detailed Implementation

[0029] The technical solution of the present invention will be further described below with reference to the accompanying drawings.

[0030] like Figure 1 As shown, this embodiment of the invention provides a cross-language compilation optimization method based on graph neural networks, including the following steps:

[0031] Step 1: Construct a UAST module to learn and unify the features of different programming languages ​​to achieve cross-language semantic alignment. For semantic extraction, it employs a self-attention mechanism combined with a bidirectional recurrent neural network to extract flattened abstract syntax tree sequence features, which capture the overall logical structure of the code. Furthermore, it uses a graph convolutional neural network to extract local features of the graph-like abstract syntax tree structure. Subsequently, the sequence features and graph features are fused to enhance the feature representation of corresponding dimensions, thereby obtaining the structural and semantic features of the code. Additionally, a unified embedding mapping vocabulary is established to reduce differences between different programming languages, thus promoting neural network learning. This module first receives the AST parsed by the compiler frontend. Then, it performs path embedding and graph embedding on the AST using the unified vocabulary. Finally, the path embedding vectors and graph embedding vectors are input into different sub-networks to capture code features. Figure 2 As shown. Includes the following steps:

[0032] (11) Vocabulary unification. Different coding units are unified into the same unit, as shown in Table 1.

[0033] Table 1. Standardized Vocabulary for Some Terms

[0034] .

[0035] (12) Sequence-based AST network. First, a preorder traversal of the AST is performed, and the resulting path sequence can be seen as a flattened representation of the AST. The path sequence contains global information of the source code and, to some extent, reveals the syntactic structure features of the source code. To extract the dependencies between nodes in the sequence, a self-attention structure is used:

[0036] ;

[0037] in, The three matrices are generated based on the embedded path sequence vector; Represents the embedding dimension of the path sequence; This is the input path length.

[0038] In addition to extracting the internal dependencies of the input source code, it is also necessary to capture the contextual dependencies of the source code. Therefore, a bidirectional long short-term memory network is introduced. It can learn the features of the input data from two directions, comprehensively considering all available input path information in the context to extract the semantic and logical features of the source code; then the hidden states learned by the forward LSTM are... Hidden state learned by backward LSTM Connect to obtain It contains the contextual characteristics of the code.

[0039]

[0040] (13) Graph-based AST network. First, the AST structure is treated as a special graph, and then convolutional operations are performed on it to extract semantic features of the code. GCN can aggregate and learn the features of each node's neighboring nodes within a unified AST, thereby capturing the local features of the AST, i.e., the local semantics of the code. Nodes aggregate and summarize the information of their first-order neighbors through a single hop, which can extract the direct relationships between code statements. As the number of hops increases, nodes can also indirectly summarize the information of their second-order neighbors. Therefore, nodes can learn the local structure and semantic features of their neighbors. The graph convolution operation is defined as follows:

[0041]

[0042]

[0043] in, Indicates the first Layer nodes Features; Indicates the first Layer nodes The characteristics of itself and all its neighboring nodes; Represents a node The total number of neighbors; Represents a node The sum of the adjacency matrix and the identity matrix; yes The degree matrix; It is the first The trainable weight matrix of the layer.

[0044] (14) In order to fully consider the global and local semantic features of the code, the dimensional features are enhanced by vector concatenation, as described below:

[0045]

[0046] in, This represents the feature vector after AST feature fusion; This represents the global structural features learned from the sequence AST; This represents the local semantic features learned from the graph convolutional AST.

[0047] Step 2: Construct the FUAST module, which deeply integrates static syntax structure with dynamic execution flow. This captures key information such as the lifecycle of traceable variables (definition-usage chain), branch reachability, and data propagation paths. This allows for the capture of more code information (e.g., node order), improved accuracy of static analysis (e.g., precise location of cross-function data leaks), and enhanced effectiveness of compiler optimization (e.g., dead code elimination based on data flow). This provides a more realistic abstract foundation for compiler optimization scenarios in complex multi-code languages. Figure 3 As shown. Includes the following steps:

[0048] (21) Receive the UAST and construct the graph structure, adding edges to the UAST to maintain data integrity and control the flow of the graph structure. We enhance the UAST by adding different types of additional edges to represent data flow and node order. Specifically, in addition to the AST child and AST parent edges naturally generated through AST parsing, the following additional flow enhancement edges are used:

[0049] ① Adjacent leaf nodes (a): This type of edge connects a terminal node (leaf node) in the abstract syntax tree to the next terminal node. A terminal node is a node that has no children.

[0050] ② Node siblings (b): This type of edge connects each node (including terminal and non-terminal nodes) to its next sibling node, allowing us to model the execution order of instructions in an otherwise unordered graph.

[0051] ③ Next use of a node (c): This type of edge connects the node representing the variable to the next location where the variable will be used. For example, the variable is declared in line i and then used in line j.

[0052] ④ If conditional flow (d): This type of edge connects the condition of an if statement with the code block executed when the condition is true. According to the construction rules, each if statement contains one such edge.

[0053] ⑤Else conditional flow (e): In contrast to the If conditional flow edge, this edge type connects the condition to an optional else block.

[0054] ⑥While loop flow (f): A while loop essentially consists of two elements—a condition and a block of code that continues to execute as long as the condition is true. We model the next use of the loop counter by connecting the condition to the code block with a While loop flow (f) edge and setting a next use (c) edge in the opposite direction.

[0055] ⑦ For loop flow (g): The for loop is conceptually similar to the while loop. We use the for loop flow (g) edge to connect the condition to the code block and set a next use (c) edge in the opposite direction for the node. Similar to modeling the while loop, the next use (c) edge of the node corresponds to the use of the loop counter (usually an increment operation).

[0056] ⑧ Sequential Execution Flow (h): In addition to the control flow structures discussed above, the module also supports a simple sequence of multiple statements executed sequentially within a code block. The sequential execution flow (h) edge is used to represent this situation. Unlike the aforementioned structures, a code block can contain any number of sub-statements, and the sequential execution flow (h) edge is always used to connect each statement to its immediate successor.

[0057] (22) Limiting the parsing depth of the abstract syntax tree: A major challenge in representing source code as a graph structure is that the graph size can become very large. This problem is addressed by limiting the parsing depth of the abstract syntax tree. Two approaches were investigated: File-level parsing: In the first approach, the abstract syntax tree is parsed only for a single source file. For references not implemented in that file (such as classes or functions), the system converts them into leaf nodes and does not perform further parsing. This approach not only generates a graph structure of manageable size but also simplifies the parsing process, but obviously leads to a large number of fragmented graphs and the loss of contextual semantics. System-level parsing: In the second approach, the parser can access all source code files of the system under study and fully parse all class or function references implemented in the system under study. External dependencies and calls to system libraries are not parsed; these remain as leaf nodes. Although this parsing strategy generates a larger and more complex graph structure, its advantage lies in its ability to capture complex semantics such as cross-file calls, inheritance, interfaces, polymorphism, and dependencies, and to trace the source of calls and data flow in the graph. The system-level parsing approach was chosen. Compared to file-level parsing, system-level parsing can comprehensively capture semantic information such as class inheritance, function calls, and data dependencies across files, thus more accurately reflecting the program's structure and operational characteristics. Although this method significantly increases the size of the graph structure and the parsing complexity, its advantages in method performance modeling and system-level behavioral analysis are more prominent. To control the graph size, the parsing depth is further limited, and a subgraph extraction strategy is adopted to balance semantic integrity and computability.

[0058] Step 3: Construct the Sub2Vec subgraph extraction module, where SubGNN is used to extract subgraphs. First, a message-passing function operating at the subgraph level is defined to explicitly capture subgraph representation features that are not applicable to nodes or the entire graph. That is, messages are propagated to every connected component in the subgraph, thus constructing meaningful representations of subgraphs with multiple different connected components. Next, six subgraph topological properties (as shown in Table 2) are defined to learn the representation of each subgraph, preserving its specific attributes in the vector space as much as possible. Then, SubGNN is used to capture the representations of the six aspects of the subgraph structure in Table 2. SubGNN propagates neuronal messages from anchor regions to subgraph components, and finally to the entire subgraph, generating subgraph representations that capture the unique characteristics of the subgraph's topological structure. Figure 4 As shown.

[0059] Table 2 shows six characteristics of subgraph topology in SubGNN.

[0060] .

[0061] Step 4: Construct the IRGAT module, utilizing the sparsity of the IR graph structure to perform structural pruning on the GAT's self-attention mechanism. The pruned IRGAT module performs graph aggregation on the vectors passed from the front end. Its built-in attention mechanism will also be part of the process, passing the aggregated vectors along with the input vectors to the subsequent SALT module. This includes the following steps:

[0062] (41) Model pruning. Due to the high sparsity of the IR graph (nodes in the IR graph are usually only connected to a few other nodes), the original attention mechanism is replaced with the sparse attention mechanism in the fixed sparse mode. The sparse attention of the IRGAT module consists of two parts: sliding window attention and global attention.

[0063] In this approach, sliding window attention employs a fixed-size window around each label. Multiple stacked layers using this window-based attention create a large receptive field, where the top layers can access all input locations and are capable of constructing representations containing the entire input information, similar to a CNN. Given a fixed window size... Each marker will focus on the two sides of it. 100 tags. The computational complexity of this pattern is O(n log n). It is related to the length of the input sequence. The relationship is linear. To further increase the receptive field without increasing computation, the sliding window can be "expanded." This is similar to an expanded CNN[x], where the window has a size expansion. The gaps. Assuming all layers and They are all fixed; the size of the sensory field is... It can reach tens of thousands of marks.

[0064] (42) Global Attention. In IRGAT, windowed and expanded attention is not flexible enough to learn task-specific representations. Therefore, “global attention” markers are added at several pre-selected input locations. This attention is made symmetrical: that is, a marker with global attention attends to all markers in the sequence, and all markers in the sequence attend to it, where global attention is located on several markers at custom locations. Since the number of such markers is relatively large... And independent of And since they are rare, the combined complexity of local attention and global attention remains... .

[0065] (43) Graph aggregation. "Neighbor weighting" is achieved through attention weights, enabling the model to automatically learn the importance of different neighbor nodes. Using IRGAT to perform graph aggregation on FUAST can capture neighbor information and structural features, propagate contextual information and fuse features, while avoiding the representation bias of isolated nodes.

[0066] First, for the initial feature vector of each node... Mapped to a new feature space through a linear transformation:

[0067]

[0068] in, It is a learnable parameter matrix used to unify feature dimensions and extract higher-level features;

[0069] Next, for each edge compute nodes To his neighbors Attention score:

[0070]

[0071] in, It is the attention vector, and || represents the vector concatenation operation. Represents a node For nodes The intensity of the impact;

[0072] Then, for the node All neighbors Normalize the attention weights:

[0073]

[0074] in, They are neighbors For nodes The importance of;

[0075] Finally, for nodes Aggregate the features of its neighbors:

[0076]

[0077] in, It is a non-linear activation function. It is a new node representation.

[0078] Step 5: Construct the IGSALT module, a lightweight Transformer architecture that considers both local and global information. First, replace the self-attention mechanism in the original architecture with a feedforward neural network to reduce model size; utilize the pruned self-attention mechanism in the IRGAT module to enhance model decision accuracy; finally, use structure-aware techniques to collect contextual information from neighboring nodes, such as... Figure 5 As shown, the SALT module is as follows: Figure 6 As shown. Specifically:

[0079] For each node, the sequence-level vector passed from the front end is pre-programmed as the node-level vector: ← All node-level vectors are collected and aggregated using IRGAT: the vectors are processed using structure-aware techniques, and the neighboring node-level vectors are weighted and summed to encode the node-level vectors.

[0080] ;

[0081] ;

[0082] Where T represents transpose, and || is the vector concatenation operation.

[0083] Next, each vector ( ∈ The vector is assigned to its original feature node and concatenated (⊕) with the original sequence-level vector passed from the front end, resulting in a graph-enhanced sequence-level vector:

[0084] ;

[0085] Then, the graph-enhanced vectors are fed into the feedforward neural network:

[0086] ;

[0087] ;

[0088] in, , For the hidden layer dimension; ; , For bias terms;

[0089] Then, residual joins and normalization operations are performed, followed by a fully connected layer:

[0090] ;

[0091] ;

[0092] in, , It is the target dimension;

[0093] If it's a classification task, such as determining whether a function needs to be inlined, then ;

[0094] The LT module is a lightweight Transformer architecture. It replaces the cumbersome multi-head self-attention mechanism with a lightweight feedforward neural network, and uses the pruned self-attention mechanism from the IRGAT module to replace the original self-attention mechanism.

[0095] The Structure Awareness (SA) module explicitly models the relationships between nodes and edges, thus preserving the program's hierarchy and dependency characteristics. It propagates information at the graph level, enabling statement-level and function-level dependency feature extraction, providing support for multi-level optimization. The SA algorithm table is shown below.

[0096] Define structural awareness attention as:

[0097] -

[0098]

[0099]

[0100] in, Represented by node A subgraph centered on a node, the node possesses node characteristics. ; It is any kernel function that compares a pair of subgraphs. This new self-attention function considers not only attribute similarity but also structural similarity between subgraphs, thus generating more expressive node representations than the original self-attention. Furthermore, this self-attention is an ideal property that is no longer equivariant to arbitrary node permutations, but only to nodes that match the features and subgraphs.

[0101] Calculate directly using IRGAT The whole center A representation of a connected subgraph, not just a node representation. Adjust the IRGAT extractor to utilize the entire... Connected subgraph, The connected subgraph IRGAT extractor uses convergence functions for aggregation. The updated node representation after considering all nodes within the skip neighborhood. (Using...) A node that includes itself. of Skip the neighborhood, then the node The representation is:

[0102]

[0103] To capture attribute similarity and structural similarity, the original node features are concatenated with features from... The node representations of the connected subgraph IRGAT extractor are combined.

[0104] The final architecture of this invention, the SUBFUAST-IGSALT framework, handles compiler optimization tasks. The SUBFUAST-IGSALT framework focuses on the use cases of compiler optimization and the structural characteristics of the code. First, a unified vocabulary and AST network are designed to learn the AST features of different code languages ​​and map them uniformly to achieve cross-language semantic alignment. Second, the basic structural information of the AST is supplemented with semantic information representing data and control flow, expanding the tree structure of the AST into a richer graph structure. Then, focusing on the optimization region problem, a message passing function and six subgraph topological characteristics are defined to capture the representation of six aspects of the subgraph structure, and neuronal messages are passed to the entire subgraph, thereby generating subgraph representations that can capture the unique characteristics of the subgraph topological structure. Next, attention weights are used to implement "neighbor weighting," performing graph aggregation operations on the FUAST, propagating contextual information, and fusing features. Then, a feedforward neural network replaces the self-attention mechanism in the original architecture to reduce model size, and the pruned self-attention mechanism in the IRGAT module is used to enhance the model's decision accuracy. Structure-aware technology is used to collect contextual information from neighboring nodes. Finally, residual connections, normalization, and fully connected operations are performed in subsequent layers.

[0105] The SUBFUAST-IGSALT framework was trained and tested using the SPEC CPU2000 assembly as the dataset. The SUBFUAST-IGSALT framework was built, and comparative experiments were conducted with native compiler optimization levels O0 and O3, the SLOPS method, and the ALIC model. The advantages of the model presented in this invention were demonstrated through these comparative experiments (Table 3).

[0106] Table 3 Experimental Results

[0107] .

[0108] The physical meanings of all parameters are shown in Tables 4-5.

[0109] Table 4 Physical Meaning of Parameters 1

[0110] ;

[0111] Table 5 Physical Meaning of Parameters 2

[0112] .

Claims

1. A cross-language compilation optimization method based on graph neural networks, characterized in that, Includes the following steps: (1) Parse the source code of different programming languages ​​to obtain their respective abstract syntax trees, and map the nodes of the abstract syntax trees of different languages ​​to a shared vocabulary space through a unified semantic mapping to achieve a unified representation of cross-language syntax structure; by constructing a unified vocabulary mapping table across programming languages, the syntax node types generated by parsing the source code of different languages ​​are mapped to a shared vocabulary space; at the same time, a sequence neural network is used to extract the global sequence features of the abstract syntax tree, a graph neural network is used to extract the local structural features of the abstract syntax tree, and the global sequence features and local structural features are fused to form a unified syntax tree representation across languages; (2) Based on the unified representation of the abstract syntax tree, the syntax tree is structurally enhanced by incorporating control flow and data flow information, and multiple additional edges representing variable dependencies, execution order and branch jumps are added to construct a flow-enhanced abstract syntax tree that integrates static syntax and dynamic behavior. (3) Identify and extract key subgraph structures for compiler optimization from the flow-enhanced abstract syntax tree, including control flow subgraph, loop structure subgraph and function call subgraph, and extract the internal topological features of each key subgraph and its boundary association features with the global syntax tree respectively; (4) Perform graph attention aggregation operation on the extracted key subgraphs, and use the pruning attention mechanism based on the sparse characteristics of graph structure to perform weighted fusion of the features of nodes in each subgraph to generate a serialized feature vector that fuses graph structure information. (5) The generated serialized feature vector is input into the lightweight transformer architecture for processing. A graph attention aggregation component is embedded in the encoding layer as a structure-aware unit. A feedforward network is used to replace the self-attention mechanism in the standard transformer. The compiler optimization decision result is output after residual connection, layer normalization and full connection operation.

2. The cross-language compilation optimization method based on graph neural networks according to claim 1, characterized in that, In step (2), the types of additional edges added include: sequential edges between adjacent leaf nodes, execution order edges between sibling nodes, data dependency edges between variable nodes and their next usage location, control flow edges between conditional statements and corresponding execution blocks, loop flow edges between loop structures and loop bodies, and sequential execution flow edges between statements within a code block.

3. The cross-language compilation optimization method based on graph neural networks according to claim 1, characterized in that, In step (3), the core regions of interest to the compiler optimization are obtained by using the anchor region message passing mechanism. Based on the internal position features, boundary position features, internal neighborhood features, boundary neighborhood features, internal connectivity features, and boundary connectivity features of the subgraph, the internal structure representation of the subgraph and its semantic association representation with the global syntax tree are constructed respectively.

4. The cross-language compilation optimization method based on graph neural networks according to claim 1, characterized in that, In step (4), a combination of graph structure sparsity pruning attention mechanism and sliding window attention and global attention is adopted. Sliding window attention focuses on the local neighboring nodes of each node, while global attention focuses on the preset global key nodes. The structural pruning strategy reduces the computational complexity of attention while maintaining the ability to perceive the graph structure.

5. The cross-language compilation optimization method based on graph neural networks according to claim 1, characterized in that, In step (5), the graph attention aggregation component is embedded in the transformer coding layer as a structure-aware unit. The self-attention mechanism of the standard transformer is replaced by a feedforward network, and the graph attention information provided by the embedded structure-aware unit is used to enhance the ability to extract code structure features.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-5.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.