US2024201968A1PendingUtilityA1

Program compilation method and apparatus

45
Assignee: HUAWEI TECH CO LTDPriority: Jul 9, 2021Filed: Jan 8, 2024Published: Jun 20, 2024
Est. expiryJul 9, 2041(~15 yrs left)· nominal 20-yr term from priority
G06F 8/51G06F 8/443G06F 8/315G06F 8/4441G06F 8/4435
45
PatentIndex Score
0
Cited by
0
References
0
Claims

Abstract

This application discloses a program compilation method including: obtaining a first program, where the first program includes a plurality of layers of loop statements, a loop condition of each layer of loop statement in the plurality of layers of loop statements includes a variable and a value interval of the variable, and a loop body of the plurality of layers of loop statements includes at least one conditional statement; processing a value interval of a first variable in a first loop statement included in the plurality of layers of loop statements, to obtain a second loop statement; and compiling the first program based on at least one loop statement to obtain a compilation result of the first program.

Claims

exact text as granted — not AI-modified
What is claimed is: 
     
         1 . A program compilation method, comprising:
 obtaining a first program, the first program comprising a plurality of layers of loop statements, a loop condition of each layer of loop statement in the plurality of layers of loop statements comprising a variable and a value interval of the variable, and a loop body of the plurality of layers of loop statements comprising at least one conditional statement, the plurality of layers of loop statements comprise a first loop statement, the first loop statement comprising a layer of loop statement in the plurality of layers of loop statements, a variable comprised in a loop condition of the first loop statement comprising a first variable, and the first variable comprising one of variables comprised in a first conditional statement in the at least one conditional statement;   processing a value interval of the first variable in the first loop statement to obtain at least one loop statement corresponding to the first loop statement, the at least one loop statement comprises a second loop statement, both the first loop statement and the second loop statement comprising the first variable, a value interval of the first variable in the second loop statement comprising a first interval, the first interval comprising a subset of the value interval of the first variable in the first loop statement, and the first interval making the first conditional statement always true; and   compiling the first program based on the at least one loop statement to obtain a compilation result of the first program, the compilation result of the first program being related to the at least one loop statement.   
     
     
         2 . The method according to  claim 1 , wherein the first program comprises an instruction mapping label; and
 when an estimated mapping time of the compilation result of the first program is greater than a preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of loop statements following the instruction mapping label, and the estimated mapping time is required for mapping the compilation result of the first program to an executable instruction on hardware; or   when the estimated mapping time of the compilation result of the first program is less than or equal to the preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of all of the plurality of layers of loop statements.   
     
     
         3 . The method according to  claim 2 , wherein the estimated mapping time of the compilation result of the first program is determined based on one or more of a quantity of variables comprised in the at least one conditional statement, a quantity of layers of the plurality of layers of loop statements, fuzzy intervals of the variables comprised in the at least one conditional statement, or a quantity of conditional statements; and
 when a value of the variable is a value in a fuzzy interval of the variable, whether a conditional statement comprising the variable is true is further related to another factor.   
     
     
         4 . The method according to  claim 2 , wherein the at least one loop statement corresponding to the first loop statement further comprises a third loop statement, wherein:
 a value interval of the first variable in the third loop statement is a second interval, and when a value of the first variable is a value in the second interval, whether the first conditional statement is true is further related to another factor.   
     
     
         5 . The method according to  claim 4 , wherein the first conditional statement further comprises a second variable, and the method further comprises:
 processing the second interval of the first variable in the third loop statement to obtain one or more fourth loop statements when the estimated mapping time of the compilation result of the first program is greater than the preset time and the second variable is one of the variables comprised in both the at least one conditional statement and the loop conditions of the loop statements following the instruction mapping label, or when the estimated mapping time of the compilation result of the first program is less than or equal to the preset time and the second variable is one of the variables comprised in both the at least one conditional statement and the loop conditions of all of the plurality of layers of loop statements;   wherein a value interval of the first variable in each of the fourth loop statements is a subset of the second interval.   
     
     
         6 . The method according to  claim 4 , wherein the first conditional statement further comprises a second variable, a value interval of the second variable in the third loop statement comprises a third interval; the method further comprising:
 processing the third interval in the third loop statement to obtain one or more fifth loop statements when the estimated mapping time of the compilation result of the first program is greater than the preset time, and the second variable is a variable comprised in a loop condition of a loop statement above the instruction mapping label;   wherein a value interval of the second variable in each of the fifth loop statements is a subset of the third interval.   
     
     
         7 . The method according to  claim 1 , wherein two endpoints of the value interval of the variable comprised in the loop condition of each layer of loop statement are constants, and the variables comprised in the at least one conditional statement are variables comprised in loop conditions of the plurality of layers of loop statements. 
     
     
         8 . A program compilation method, comprising:
 obtaining a second program, the second program comprising a plurality of layers of loop statements, a loop condition of each layer of loop statement comprising a variable and a value interval of the variable, and a loop body of the plurality of layers of loop statements comprising at least one conditional statement, the plurality of layers of loop statements comprising a fifth loop statement, the fifth loop statement is a layer of loop statement in the plurality of layers of loop statements, a variable comprised in a loop condition of the fifth loop statement comprising a third variable, and the third variable comprising one of variables comprised in a second conditional statement in the at least one conditional statement;   updating a first value interval of the third variable in the fifth loop statement to obtain a sixth loop statement, the updated first value interval making the second conditional statement always true; and   compiling the second program based on the sixth loop statement to obtain a compilation result of the second program, the compilation result of the second program being related to the sixth loop statement.   
     
     
         9 . The method according to  claim 8 , wherein the second program comprises an instruction mapping label; and
 the third variable is one of variables comprised in both the at least one conditional statement and loop conditions of loop statements following the instruction mapping label.   
     
     
         10 . The method according to  claim 8 , wherein the updating the first value interval of the third variable in the fifth loop statement comprises:
 obtaining a second value interval of the third variable based on the second conditional statement; and   updating the first value interval by using an intersection set of the first value interval and the second value interval.   
     
     
         11 . The method according to  claim 8 , wherein at least one of two endpoints of the value interval of the variable comprised in the loop condition of each layer of loop statement is a non-constant number, and/or each conditional statement of the at least one conditional statement further comprises a fourth variable that is not comprised in the loop condition of each layer of loop statement. 
     
     
         12 . A chip system, comprising:
 an interface circuit;   a memory storing instructions; and   at least one processor in communication with the memory and the interface circuit, the at least one processor configured, upon execution of the instructions, to perform the following steps:
 obtaining a first program, the first program comprising a plurality of layers of loop statements, a loop condition of each layer of loop statement in the plurality of layers of loop statements comprising a variable and a value interval of the variable, and a loop body of the plurality of layers of loop statements comprising at least one conditional statement, the plurality of layers of loop statements comprise a first loop statement, the first loop statement comprising a layer of loop statement in the plurality of layers of loop statements, a variable comprised in a loop condition of the first loop statement comprising a first variable, and the first variable is one of variables comprised in a first conditional statement in the at least one conditional statement; 
 processing a value interval of the first variable in the first loop statement to obtain at least one loop statement corresponding to the first loop statement, the at least one loop statement comprises a second loop statement, both the first loop statement and the second loop statement comprising the first variable, a value interval of the first variable in the second loop statement comprising a first interval, the first interval comprising a subset of the value interval of the first variable in the first loop statement, and the first interval making the first conditional statement always true; and 
 compiling the first program based on the at least one loop statement to obtain a compilation result of the first program, the compilation result of the first program being related to the at least one loop statement. 
   
     
     
         13 . The chip system according to  claim 12 , wherein the first program comprises an instruction mapping label; and
 when an estimated mapping time of the compilation result of the first program is greater than a preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of loop statements following the instruction mapping label, and the estimated mapping time is required for mapping the compilation result of the first program to an executable instruction on hardware; or   when the estimated mapping time of the compilation result of the first program is less than or equal to the preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of all of the plurality of layers of loop statements.   
     
     
         14 . The chip system according to  claim 13 , wherein the estimated mapping time of the compilation result of the first program is determined based on one or more of a quantity of variables comprised in the at least one conditional statement, a quantity of layers of the plurality of layers of loop statements, fuzzy intervals of the variables comprised in the at least one conditional statement, or a quantity of conditional statements; and
 when a value of the variable is a value in a fuzzy interval of the variable, whether a conditional statement comprising the variable is true is further related to another factor.   
     
     
         15 . The chip system according to  claim 13 , wherein the at least one loop statement corresponding to the first loop statement further comprises a third loop statement, wherein:
 a value interval of the first variable in the third loop statement is a second interval, and when a value of the first variable is a value in the second interval, whether the first conditional statement is true is further related to another factor.   
     
     
         16 . The chip system according to  claim 13 , wherein a discrete device is coupled to the chip system to form a compilation apparatus. 
     
     
         17 . A non-transitory computer-readable media storing computer instructions that configure at least one processor, upon execution of the instructions, to perform the following steps:
 obtaining a first program, the first program comprising a plurality of layers of loop statements, a loop condition of each layer of loop statement in the plurality of layers of loop statements comprising a variable and a value interval of the variable, and a loop body of the plurality of layers of loop statements comprising at least one conditional statement, the plurality of layers of loop statements comprise a first loop statement, the first loop statement comprising a layer of loop statement in the plurality of layers of loop statements, a variable comprised in a loop condition of the first loop statement comprising a first variable, and the first variable comprising one of variables comprised in a first conditional statement in the at least one conditional statement;   processing a value interval of the first variable in the first loop statement to obtain at least one loop statement corresponding to the first loop statement, the at least one loop statement comprises a second loop statement, both the first loop statement and the second loop statement comprising the first variable, a value interval of the first variable in the second loop statement comprising a first interval, the first interval comprising a subset of the value interval of the first variable in the first loop statement, and the first interval making the first conditional statement always true; and   compiling the first program based on the at least one loop statement to obtain a compilation result of the first program, the compilation result of the first program being related to the at least one loop statement.   
     
     
         18 . The method according to  claim 17 , wherein the first program comprises an instruction mapping label; and
 when an estimated mapping time of the compilation result of the first program is greater than a preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of loop statements following the instruction mapping label, and the estimated mapping time is required for mapping the compilation result of the first program to an executable instruction on hardware; or   when the estimated mapping time of the compilation result of the first program is less than or equal to the preset time, the first variable is one of variables comprised in both the at least one conditional statement and loop conditions of all of the plurality of layers of loop statements.   
     
     
         19 . The method according to  claim 17 , wherein the estimated mapping time of the compilation result of the first program is determined based on one or more of a quantity of variables comprised in the at least one conditional statement, a quantity of layers of the plurality of layers of loop statements, fuzzy intervals of the variables comprised in the at least one conditional statement, or a quantity of conditional statements; and
 when a value of the variable is a value in a fuzzy interval of the variable, whether a conditional statement comprising the variable is true is further related to another factor.   
     
     
         20 . The method according to  claim 17 , wherein the at least one loop statement corresponding to the first loop statement further comprises a third loop statement, wherein:
 a value interval of the first variable in the third loop statement is a second interval, and when a value of the first variable is a value in the second interval, whether the first conditional statement is true is further related to another factor.

Cited by (0)

No later patents cite this yet.

References (0)

No backward citations on record.