Faster short-circuiting of compound conditional set reordering

By configuring the compiler in the processor, determining and reordering the conditions in the composite condition set, the problem of difficult evaluating the computational cost of the composite condition set is solved, improving the code execution efficiency and avoiding resource waste.

CN111971651BActive Publication Date: 2024-11-22MICROSOFT TECHNOLOGY LICENSING LLC
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN201980025128.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2018-04-13
Filing Date
2019-03-12
Publication Date
2024-11-22
Estimated Expiration
2039-03-12

AI Technical Summary

Technical Problem

When writing source code for composite condition sets, it is difficult for programmers to determine which conditions have higher computational costs than others, resulting in potentially inefficient code, wasting processing resources and slowing code execution.

Method used

Reorder the conditions to obtain the lowest calculated cost by configuring the compiler in the processor, receiving source code and determining the sort of multiple conditions, satisfying the legality constraints and estimating the calculation cost.

Benefits of technology

It effectively avoids useless processing, improves code execution efficiency, and ensures that the compiled code performance is higher than that of traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111971651B_ABST
    Figure CN111971651B_ABST
Patent Text Reader

Abstract

A computing device is provided, the computing device including a processor configured to receive source code at a compiler. The source code may include at least one composite condition set having a plurality of conditions. The source code may also include a corresponding code block for each of the plurality of conditions, the corresponding code block including instructions for evaluating the condition. For each of a plurality of orderings of the plurality of conditions, the processor may determine that the ordering satisfies one or more legality constraints. For each of a plurality of orderings that satisfies one or more legality constraints, the processor may determine a corresponding estimated computational cost for the ordering. The processor may reorder the plurality of conditions to have an ordering with a lowest estimated computational cost among a plurality of orderings that satisfies one or more legality constraints.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to the field of computers. Background Art

[0002] A compound conditional is a code construct in which two or more conditions are checked to determine whether to execute one set of instructions or another set of instructions. For example, a compound conditional may be included in an "if" statement, a "for" loop, or a "while" loop. Checking a compound conditional may include checking whether each of the two or more conditions is true. For example, a compound conditional may have the following form: "if(a&&b)" or "if(a||b)".

[0003] The conditions in the compound condition set are evaluated at run time in the order in which they appear in the code. The computational cost consumed by checking some conditions may be higher than the computational cost consumed by checking other conditions. The programmer can first list the conditions with the lowest computational cost in order to avoid checking the condition set with higher computational cost when such evaluation is not required based on the first result, in order to save processing time. However, when writing source code including the compound condition set, the programmer may not know which conditions in the compound condition set are more expensive to check than the cost consumed by checking other conditions. Therefore, the conditions can be arranged in a suboptimal order, that is, the condition set with high cost can be evaluated before the condition set with low cost. This may result in a waste of processing resources and slow down code execution.

[0004] Consider the following set of compound conditions:

[0005] If(condition1&&condition2&&condition3){

[0006] }else{

[0007] }

[0008] Each set of conditions is a Boolean predicate. Therefore, the conditions can be combined into conjunctions or disjunctions.

[0009] In the above code example, the basic code generation scheme will first calculate the following expression, which calculates condition1, condition2, and condition3. Then, the generated code will perform the "&&" operation to calculate the final single condition value, based on which the following judgment will be made: the IF code should be executed or the ELSE code should be executed.

[0010] Some existing compilers use conditional short-circuiting as an optimization. Short-circuiting recognizes that if condition1 is false, then the expressions used to evaluate condition2 and condition3 do not need to be evaluated. The short-circuiting then jumps accordingly. Short-circuiting saves the computational cost of evaluating the additional condition variable. The generated code looks like this:

[0011] Compute expression that calculates Conditionn1

[0012] If! condition 1, jump toELSE code

[0013] Compute expression that calculates Condition2

[0014] If! condition2, jump to ELSE code

[0015] Compute expression that calculates condition3

[0016] If! condition3, jump to ELSE code

[0017] IF CODE

[0018] GOTO CONDITION REGION END

[0019] ELSE CODE

[0020] REGION END:...

[0021] (Evaluate the expression used to evaluate condition1

[0022] If !condition1, then jump to ELSE code

[0023] Calculates the expression used to calculate condition2

[0024] If !condition2, then jump to ELSE code

[0025] Calculate the expression used to calculate condition3

[0026] If !condition3, then jump to ELSE code

[0027] IF Code

[0028] Go to the end of the condition area

[0029] ELSE code

[0030] Zone ends:…)

[0031] However, even if the compiler can use such short-circuiting techniques, the developer may not be aware of the corresponding computational costs of different orderings. As a result, inefficient code may be written and compiled when short-circuiting would produce more efficient code. Summary of the invention

[0032] According to one aspect of the present disclosure, a computing device is provided, the computing device including a processor, the processor being configured to receive source code at a compiler. The source code may include at least one composite condition set having a plurality of conditions. For each of the plurality of conditions, the source code may also include a corresponding code block, the corresponding code block including instructions for evaluating the condition. For each of the plurality of orderings of the plurality of conditions, the processor may also be configured to determine that the ordering satisfies one or more legality constraints. For each of the plurality of orderings that satisfies one or more legality constraints, the processor may also be configured to determine a corresponding estimated computational cost for the ordering. The processor may also be configured to reorder the plurality of conditions to have an ordering with the lowest estimated computational cost among the plurality of orderings that satisfies one or more legality constraints.

[0033] This summary is provided to introduce some concepts that are further described below in the detailed description in a simplified form. This summary is neither intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter. Furthermore, the claimed subject matter is not limited to implementations that solve any or all disadvantages noted in any part of this disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 An example embodiment of a computing device according to one embodiment of the present disclosure is shown.

[0035] Figure 2 Shown according to Figure 1 Example source code for an embodiment including an "if" statement.

[0036] Figure 3 Shown according to Figure 1 Example source code for an embodiment including a "while" loop.

[0037] Figure 4 Shown according to Figure 1 An example of computing cost estimates of an embodiment of the invention.

[0038] Figure 5 An example method that may be performed by a processor of a computing device according to one embodiment of the present disclosure is shown.

[0039] Figure 6 A schematic diagram of an example computing system is shown according to one embodiment of the present disclosure. DETAILED DESCRIPTION

[0040] To address the above challenges, a computing device is provided. Figure 1 An example embodiment of a computing device 10 is shown, which may include a volatile storage device 12, a non-volatile storage device 14, and / or a processor 16. The volatile storage device 12 and the non-volatile storage device 14 may each include a memory address configured to store data. The processor 16 may be configured to run a compiler 30, which is configured to receive a source code 20 and convert the source code 20 into an assembly code 38. The system and method shown in the accompanying drawings of the present disclosure are described herein to convert the source code 20 into the assembly code 38 when the source code 20 includes at least one compound condition set 22.

[0041] refer to Figure 2 , Figure 1 The example source code 20 is shown in further detail. Figure 1 and Figure 2 As shown, the example source code 20 includes a compound condition set 22 in the form of an "if" statement. The source code 20 received by the compiler 30 may include at least one compound condition set 22. The compound condition set 22 may include multiple conditions 24, each of which may have a Boolean value (true or false). The source code 20 may include a corresponding code block 26 for each condition 24 in the multiple conditions 24, and the corresponding code block 26 includes one or more instructions 28 for evaluating the condition 24. When the one or more instructions 28 are evaluated, the code block 26 may return a Boolean value for the condition 24. In some embodiments, each code block 26 may be a basic block in which no branching occurs. Alternatively, at least one code block 26 may include multiple basic blocks.

[0042] The composite condition set 22 may return a Boolean value based on the Boolean values ​​of the multiple conditions 24. Figure 2 As shown, the source code 20 may further include a first branch code block 42, the first branch code block 42 including one or more first branch evaluation instructions 44, the one or more first branch evaluation instructions 44 being configured to be executed when the plurality of conditions 24 are true. Figure 2In the embodiment of the present invention, the compound condition set 22 includes a logical operator 40, which is shown herein as an AND (&&) logical operator. However, in other embodiments, the compound condition set 22 can be expressed using another logical operator 40 such as OR, XOR, or NAND. The Boolean value of the compound condition set can be evaluated by applying the logical operator 40 to multiple conditions 24. The source code 20 can also include a second branch code block 46, which includes one or more second branch evaluation instructions 48, and the one or more second branch evaluation instructions 48 are configured to be executed when at least one condition 24 of the multiple conditions 24 is false. Figure 2 As shown, the second branch code block 46 may be an "else" branch of an "if" statement.

[0043] although Figure 1 and Figure 2 The compound condition set 22 is shown as having two conditions 24, but other numbers of conditions 24 are also contemplated. In some embodiments, the compound condition set 22 may include three or more conditions 24. In such embodiments, the compound condition set 22 may also include two or more logical operators 40 that may be applied to the conditions 24 to evaluate the compound condition set 22.

[0044] In addition to the compound condition set 22, the first branch code block 42 and the second branch code block 46, the source code 20 may also include other code blocks, such as Figure 2 The ellipse before the compound condition set 22 and after the second branch code block 46 is shown.

[0045] return Figure 1 , the composite condition set 22 may be sent to a compiler 30. The compiler 30 may be configured to determine a plurality of orderings 32 among the plurality of conditions 24 included in the composite condition set 22. In some embodiments, the compiler 30 may determine every possible ordering 32 of the plurality of conditions 24. In other embodiments, the compiler 30 may determine only a subset of all possible orderings 32 of the conditions 24.

[0046] As a consequence of Rice's theorem, there is no algorithm that can always determine which condition 24 has the lowest computational cost for any composite set of conditions 22. However, the condition 24 that is likely to have the lowest computational cost can be identified using heuristic techniques. Such heuristic techniques can be based on syntactic properties of one or more instructions 28 included in the corresponding code block 26 of each of the conditions 24.

[0047] For each of the plurality of orderings 32 of the conditions 24, the processor 16 may also be configured to determine that the ordering 32 satisfies one or more legality constraints 34. A legality constraint 34 is defined herein as a constraint based on one or more syntactic properties of one or more conditions 24 having a particular ordering 32, such that when one or more conditions 24 do not satisfy the legality constraints 34, the processor 16 is configured to prevent the compiler 30 from outputting assembly code 38 using that ordering 32. Thus, by determining which orderings 32 satisfy the one or more legality constraints 34, the processor 16 may prevent errors in the assembly code 38 that may result from reordering the conditions 24. Figure 2 An example legality constraint 34 is discussed.

[0048] In an embodiment where the source code 20 includes a first branch code block 42 and a second branch code block 46, wherein the first branch code block 42 includes one or more first branch evaluation instructions 44, the one or more first branch evaluation instructions 44 being configured to be executed when a plurality of conditions 24 are true, and the second branch code block 46 includes one or more second branch evaluation instructions 48, the one or more second branch evaluation instructions 48 being configured to be executed when at least one of the plurality of conditions 24 is false, the one or more legality constraints 34 include the following constraints: the source code 20 includes a first branch code block 42 and a second branch code block 46. When the above-mentioned legality constraints 34 are satisfied, the source code 20 does not include more than one first branch code block 42 and / or more than one second branch code block 46. Additionally or alternatively, the one or more legality constraints 34 may include the following constraints: the corresponding code block 26 of each condition 24 includes a code block for proceeding to a common target code block (which is in Figure 2 4). Thus, the compiler 30 can prevent changes in the ordering 32 of the plurality of conditions 24 from affecting what code block is executed after the compound condition set 22 is evaluated.

[0049] In some embodiments, Figure 3 As shown, the source code 20 may include a portion 50 that is after the last code block 26 of the corresponding code blocks 26 of the plurality of conditions 24 and before the common target code block. For example, when the compound condition set 22 is included in a "while" loop, such as Figure 3As shown, the portion 50 of the source code 20 may be at least one code block that includes one or more instructions for incrementing a variable. Other functions of the portion 50 of the source code 20 are also contemplated. In such an embodiment, the one or more legality constraints 34 may include the following constraint: the portion 50 of the source code 20 after the last code block 26 of the corresponding code blocks 26 of the plurality of conditions 24 and before the common target code block has an entry point and an exit point. In such an embodiment, the entry point may be an instruction in the portion 50 of the source code 20 at which the processor 16 may begin executing the portion 50 of the source code 20. Similarly, the exit point may be an instruction at which the processor 16 stops executing the portion 50 of the source code 20.

[0050] In some embodiments, one or more legality constraints 34 may include a constraint that no instruction 28 calls an undefined variable. Two example scenarios in which an instruction 28 may call an undefined variable are discussed below. In one example, an undefined variable may be an untracked memory address. When an instruction 28 to dereference an untracked memory address occurs before an instruction 28 to track an untracked memory address, an undefined variable error may occur. In a second example, an undefined variable error may occur when an instruction 28 uses a variable before another instruction 28 that defines the variable.

[0051] In some embodiments, one or more legality constraints 34 may include the following constraint: no code block 26 includes an instruction 28 that is a division operation or a remainder operation where the divisor may have a value of zero. By checking the legality constraints 34, the processor 16 may prevent a divide-by-zero error from being generated by reordering the conditions 24.

[0052] When the candidate reordering included in the plurality of orderings 32 does not satisfy each of the legality constraints 34 checked by the processor 16, the compiler 30 may output a warning message 52, such as Figure 1 In some embodiments, the warning message 52 may include an indication that the compound condition set 22 cannot be reordered to have a less computationally expensive order 32. The warning message 52 may include an indication of the location (e.g., line number) in the source code 20 where the compound condition set 22 appears. In some embodiments, when the compiler 30 outputs the warning message 52, the compiler 30 does not output the assembly code 38.

[0053] For each ordering 32 of the plurality of orderings 32 that satisfies the one or more legality constraints 34, the processor 16 may also be configured to determine a corresponding estimated computational cost 36 for the ordering 32. The corresponding estimated computational cost 36 of the ordering 36 may be determined based on predetermined static values ​​assigned to one or more instructions 28 included in each code block 26. Thus, the estimated computational cost 36 of the ordering 32 may be determined without having to collect data regarding historical computational costs of similar instructions.

[0054] refer to Figure 4 , further details the determination of the estimated computational cost 36 according to an example embodiment. Figure 4 As shown, when multiple conditions 24 have a particular ordering 32, to determine the estimated computational cost 36 of the code block 26 included in the condition 24, the processor 16 may refer to an estimated computational cost table 60 for each instruction 28 included in the code block 26, the estimated computational cost table 60 containing predetermined static values ​​for each instruction type in the code block. Thus, for one or more types of operations 62, the estimated computational cost table 60 may include an estimated cost score 64 associated with the operation 62. The types of operations 62 may include, for example, addition, subtraction, comparison, negation, division, remainder, AND, OR, XOR, minimum, maximum, load, store, and / or one or more other operations 62. Each type of operation 62 listed in the estimated computational cost table may have an estimated cost score 64, such as Figure 4 62. In some embodiments, each operation may have an estimated integer cost and an estimated floating point cost. When an integer calculation is performed, the estimated integer cost may be an estimated cost score 64 for the operation 62, and when a floating point calculation is performed, the estimated floating point cost may be an estimated cost score 64 for the operation 62.

[0055] The processor 16 may be configured to determine the respective estimated cost score 64 for each instruction 28 included in the code block 26, generally with reference to the table discussed above. In addition, when multiple conditions 24 have an ordering 32, the processor 16 may determine the respective estimated cost score 64 for each instruction 28 of each code block 26 in this manner. Thus, the processor 16 may be configured to assign an estimated cost score 64 to each instruction 28 included in the ordering 32. Based on the respective estimated cost score 64 for each instruction 28, the processor 16 may determine the estimated computational cost 36 of the ordering. For example, the estimated computational cost 36 of the ordering 32 may be determined by summing the respective estimated cost scores 64 assigned to each instruction 28. Alternatively, the estimated computational cost 36 may be determined using some other formula. For example, a weighting factor may be applied to at least one of the estimated cost scores 64.

[0056] In some embodiments, the processor 16 may determine the estimated computational cost 36 for each ordering 32 only, rather than satisfying the one or more legality constraints 34. In other embodiments, the processor 16 may determine the estimated computational cost 36 for each ordering 32 before checking whether the one or more legality constraints 34 are satisfied. In such embodiments, the processor 16 may be configured to discard any ordering 32 having an estimated computational cost 36 that exceeds a predetermined threshold. The filtering of the estimated computational cost may occur before checking for satisfaction of the one or more legality constraints 34.

[0057] The processor 16 may also be configured to determine an ordering 32 having a lowest estimated computational cost 36 among the plurality of orderings 32 that satisfies the one or more legality constraints 34. The processor 16 may then reorder the plurality of conditions 24 to have an ordering 32 having a lowest estimated computational cost 36 among the plurality of orderings 32 that satisfies the one or more legality constraints 34. If the ordering having the lowest estimated computational cost 36 is the original ordering 32 among the plurality of conditions 24, the processor 16 may be configured to maintain the original ordering 32. If two or more orderings 32 are tied together to obtain the lowest estimated computational cost 36, the processor 16 may select one of the two or more orderings 32 and reorder the plurality of conditions 24 to have the selected ordering 32, or if the original ordering 32 is included in the two or more orderings 32, the processor 16 may maintain the original ordering 32.

[0058] In embodiments where the estimated computational cost 36 of the corresponding ordering 32 is determined before checking whether the ordering 32 satisfies one or more legality constraints 34, the processor 16 may be configured to rank the one or more orderings 32 by the estimated computational cost 36. The processor 16 may then determine whether each ordering 32 satisfies the one or more legality constraints 34 in ascending order of the estimated computational cost 36 in the plurality of orderings 32. Thus, the processor 16 may check the orderings 32 for satisfaction of the one or more legality constraints 34 until the ordering 32 with the lowest estimated computational cost 36 that satisfies the one or more legality constraints 34 is determined. The processor 16 may also be configured to reorder the plurality of conditions 24 to have an ordering 32 with the lowest estimated computational cost 36 that satisfies the one or more legality constraints 34. For example, it may be advantageous to check the estimated computational cost 36 of the orderings 32 before checking the legality constraints 34 when the difference in estimated computational cost 36 between the expected orderings 32 is large and / or when the estimated computational cost 36 of the orderings 32 can be determined more quickly than whether the orderings 32 satisfy the one or more legality constraints 34.

[0059] Figure 5A flowchart of a method 100 performed by a processor of a computing device according to an example embodiment is shown. The computing device may be Figure 1 The computing device 10 of step 102 may include receiving source code at a compiler. The source code may include at least one compound condition set with multiple conditions. In some embodiments, the compound condition set may include three or more conditions. The compound condition set may include two or more Boolean conditions and one or more logical operators, such as AND, OR, XOR, and / or NAND. The compound condition set may also include a corresponding code block for each condition in the multiple conditions, and the corresponding code block includes one or more instructions for evaluating the condition. In some embodiments, each code block may be a basic block. In other embodiments, at least one code block may include multiple basic blocks.

[0060] In step 104, method 100 may also include: for each of the multiple sortings of the multiple conditions, determining that the sorting satisfies one or more legality constraints. The legality constraint is a constraint based on one or more grammatical attributes of one or more conditions with a specific sorting, so that when one or more conditions do not satisfy the legality constraint, the output assembly code using the sorting is prohibited. As an example, one or more legality constraints may include the following constraints: the corresponding code block of each condition includes instructions for proceeding to a shared target code block. Therefore, unwanted branches depending on the sorting of the condition may be prevented.

[0061] As another example, one or more legality constraints may include the following constraint: the portion of the source code after the last code block of the corresponding code blocks of the multiple conditions and before the common target code block has an entry point and an exit point. The legality constraint can prevent the processor from skipping instructions before the entry point or after the exit point due to not wanting to enter and / or exit from the portion of the source code after the last code block and before the common target code block.

[0062] As another example, the one or more legality constraints include a constraint that no instruction calls an undefined variable. When a variable is defined in a first condition in the original ordering of the conditions and then called in a second condition, the call to the undefined variable may occur when the second condition is moved before the first condition. The above legality constraints may be checked to determine that such a reordering is not performed.

[0063] As another example, the one or more legality constraints may include a constraint that no code block includes instructions that are division operations or remainder operations where the divisor may have a value of zero.

[0064] In some embodiments, the source code may also include a first branch code block, which includes one or more first branch evaluation instructions, and the one or more first branch evaluation instructions are configured to be executed when multiple conditions are true. The source code may also include a second branch code block, which includes one or more second branch evaluation instructions, and the one or more second branch evaluation instructions are configured to be executed when at least one of the multiple conditions is false. For example, when a composite conditional set is included in an "if" statement, the second branch code block can be the "else" branch of the "if" statement. In such an embodiment, one or more legality constraints may include the following constraints: the source code includes one first branch code block and one second branch code block, rather than including multiple first branch code blocks and / or multiple second branch code blocks.

[0065] At step 106, method 100 may also include: for each of a plurality of orderings that satisfy one or more legality constraints, determining a corresponding estimated computational cost for the ordering. In some embodiments, determining the corresponding estimated computational cost for each ordering may include: at step 108, assigning an estimated cost score to each instruction included in the ordering. For example, the estimated cost score may be determined by reading an estimated cost score associated with the operation indicated by the instruction from an estimated computational cost table. In some embodiments, a weighting factor may be applied to the estimated cost score of one or more instructions. At step 110, then, the estimated computational cost of the ordering may be determined, for example, by summing the corresponding estimated cost scores assigned to each instruction. In some embodiments, one or more other operations may be performed additionally or alternatively on the estimated cost score to determine the estimated computational cost of the ordering.

[0066] At step 112, method 100 may also include reordering the plurality of conditions to have an ordering with a lowest estimated computational cost among the plurality of orderings that satisfies the one or more legality constraints. When the original ordering of the plurality of conditions satisfies the one or more legality constraints and has the lowest estimated computational cost, method 100 may alternatively include maintaining the original ordering.

[0067] Although in the systems and methods described above, at least one compound condition set that is reordered includes two conditions, embodiments in which more than two conditions are reordered may also be considered. For example, the compound condition set may be in the form of "if (a||b) && (c||d)". In such an example, blocks "(a||b)" and "(c||d)" may be reordered so that the compound condition set becomes "if (c||d) && (a||b)". Alternatively, conditions a, b, c, and d may be reordered so that the compound condition set becomes "if (b||a) && (d||c)" in one example. In embodiments in which more than two conditions are evaluated, one or more conditions may have corresponding code blocks that include multiple basic blocks.

[0068] The reordering of the compound condition set as described above can be generalized to include reordering of code blocks that are not included in the compound condition set, as shown in the example code provided below. In the example, the code blocks included in the following C++ code can be reordered:

[0069]

[0070] In the example code shown above, the computational cost of "var" is higher than the computational cost of "pred". Therefore, the computational cost of executing the example code can be reduced by reordering the code blocks in the following order: block 5, block 1, block 2, block 3, block 4, block 6, block 7. The system and method of legality constraint checking and computational cost estimation can be applied to determine the order of code blocks that satisfy one or more legality constraints and have the lowest estimated computational cost.

[0071] To this end, a computing device can be provided, which is configured to perform the following method. Initially, source code can be received at a compiler, and the source code includes multiple code blocks. The source code can have an initial ordering, which is one of multiple possible orderings. That is, the initial ordering can be reordered into a candidate reordering of multiple candidate reorderings. For each of the multiple orderings of the multiple code blocks, the computing device can be configured to determine that the ordering satisfies one or more legal constraints, and the one or more legal constraints are similar to the legal constraints discussed above. For each of the multiple orderings that satisfy one or more legal constraints, the computing device can be configured to determine the corresponding estimated computational cost for the ordering, and reorder the multiple code blocks to have an ordering with the lowest estimated computational cost among the multiple orderings that satisfy one or more legal constraints. The estimated computational cost can be determined using methods similar to those described above.

[0072] Using the systems and methods described above, a computing device can determine which of a plurality of compound condition sets is most likely to require the least computing resources while also satisfying syntactical legality constraints. In this way, the useless processing of prior art systems that previously occurred when complex condition sets did not have to be evaluated before simple conditions that could not be evaluated by tests can be avoided. Thus, the systems and methods described above can achieve an execution efficiency of compiled code that is higher than the execution efficiency of code compiled using previously existing methods.

[0073] In some embodiments, the methods and processes described herein may be associated with a computing system of one or more computing devices. In particular, such methods and processes may be implemented as computer applications or services, application programming interfaces (APIs), libraries, and / or other computer program products.

[0074] Figure 6 A non-limiting embodiment of a computing system 200 is schematically shown that can implement one or more of the methods and processes described above. The computing system 200 is shown in simplified form. For example, the computing system 200 can implement Figure 1 The computing device 10 of the embodiment of the present invention may be implemented in the form of one or more personal computers, server computers, tablet computers, home entertainment computers, network computing devices, gaming devices, mobile computing devices, mobile communication devices (e.g., smart phones), and / or other computing devices, as well as wearable computing devices (such as smart watches and head-mounted augmented / virtual reality devices).

[0075] The computing system 200 includes a logic processor 202, a volatile memory 204, and a non-volatile storage device 206. The computing system 200 may optionally include a display subsystem 208, an input subsystem 210, a communication subsystem 212, and / or Figure 6 Other components not shown.

[0076] Logical processor 202 includes one or more physical devices that are configured to execute instructions. For example, a logical processor may be configured to execute instructions that are part of one or more applications, programs, routines, libraries, objects, components, data structures, or other logical constructs. Such instructions may be implemented to perform tasks, implement data types, transform the state of one or more components, implement technical effects, or otherwise achieve a desired result.

[0077] The logical processor 202 may include one or more physical processors (hardware) configured to execute software instructions. Additionally or alternatively, the logical processor 202 may include one or more hardware logic circuits or firmware devices configured to execute hardware-implemented logic or firmware instructions. The processor of the logical processor 202 may be single-core or multi-core, and the instructions executed thereon may be configured for sequential processing, parallel processing, and / or distributed processing. The various components of the logical processor 202 may optionally be distributed between two or more separate devices, which may be remotely located and / or configured for coordinated processing. Various aspects of the logical processor may be virtualized and executed by a remotely accessible networked computing device configured with a cloud computing configuration. In this case, these virtualized aspects may be run on different physical logical processors of various different machines.

[0078] The volatile memory 204 may include a physical device that includes a random access memory. The volatile memory 204 is typically used by the logical processor 202 to temporarily store information during the processing of software instructions. It should be understood that when the power to the volatile memory 204 is cut off, the volatile memory 204 will generally not continue to store instructions.

[0079] The non-volatile storage device 206 includes one or more physical devices that are configured to store instructions that can be executed by a logical processor to implement the methods and processes described herein. When such methods and processes are implemented, the state of the non-volatile storage device 206 can be transformed, for example, to store different data.

[0080] The non-volatile storage device 206 may include a removable and / or built-in physical device. The non-volatile storage device 206 may include an optical memory (e.g., CD, DVD, HD-DVD, Blu-ray disc, etc.), a semiconductor memory (e.g., ROM, EPROM, EEPROM, FLASH memory, etc.), and / or a magnetic memory (e.g., a hard disk drive, a floppy disk drive, a tape drive, MRAM, etc.), or other mass storage device technology. The non-volatile storage device 206 may include a non-volatile device, a dynamic device, a static device, a read / write device, a read-only device, a sequential access device, a location addressable device, a file addressable device, and / or a content addressable device. It should be understood that the non-volatile storage device 206 is configured to save instructions even when the power to the non-volatile storage device 206 is cut off.

[0081] Various aspects of the logic processor 202, volatile memory 204, and non-volatile storage device 206 may be integrated together into one or more hardware logic components. For example, such hardware logic components may include field programmable gate arrays (FPGAs), program and application specific integrated circuits (PASIC / ASIC), program specific standard products and application specific standard products (PSSP / ASSP), systems on chips (SOCs), and complex programmable logic devices (CPLDs).

[0082] The term "program" may be used to describe an aspect of the computing system 200 that is implemented to perform a particular function. In some cases, a program may be instantiated via a logical processor 202 executing instructions held by a non-volatile storage device 206 using portions of volatile memory 204. It should be understood that different programs may be instantiated from the same application, service, code block, object, library, routine, API, function, etc. Likewise, the same program may be instantiated through different applications, services, code blocks, objects, routines, APIs, functions, etc. The term "program" encompasses a single or group of executable files, data files, libraries, drivers, scripts, database records, etc.

[0083] When included, the display subsystem 208 can be used to present a visual representation of the data stored by the non-volatile storage device 206. Because the methods and processes described herein change the data stored by the non-volatile storage device 206, thereby transforming the state of the non-volatile storage device 206, the state of the display subsystem 208 can likewise be transformed to visually represent the changes in the underlying data. The display subsystem 208 can include one or more display devices utilizing virtually any type of technology. Such a display device can be combined with the logical processor 202, the volatile memory 204, and / or the non-volatile storage device 206 in a shared enclosure, or such a display device can be a peripheral display device.

[0084] When included, the input subsystem 210 may include or interface with one or more user input devices such as a keyboard, mouse, touch screen, or game controller. In some embodiments, the input subsystem 210 may include or interface with a selected natural user input (NUI) component portion. Such a component portion may be an integrated component portion or a peripheral component portion, and the transduction and / or processing of input actions may be handled on-board or off-board. Example NUI component portions may include microphones for speech recognition and / or voice recognition; infrared, color, stereo, and / or depth cameras for machine vision and / or gesture recognition; head trackers, eye trackers, accelerometers, and / or gyroscopes for motion detection, gaze detection, and / or intent recognition; and electric field sensing component portions for assessing brain activity; and / or any other suitable sensors.

[0085] When included, the communication subsystem 212 can be configured to communicatively couple the computing system 200 with one or more other computing devices. The communication subsystem 212 can include wired communication devices and / or wireless communication devices that are compatible with one or more different communication protocols. As non-limiting examples, the communication subsystem 212 can be configured to communicate via a wireless telephone network, or a wired or wireless local area network or wide area network. In some embodiments, the communication subsystem 212 can allow the computing system 200 to send messages to other devices and / or receive messages from other devices via a network such as the Internet.

[0086] According to one aspect of the present disclosure, a computing device is provided, which includes a processor configured to receive source code at a compiler. The source code may include at least one composite condition set having multiple conditions; and a corresponding code block for each of the multiple conditions, the corresponding code block including one or more instructions for evaluating the condition. For each of the multiple orderings of the multiple conditions, the processor may also be configured to determine that the ordering satisfies one or more legality constraints. For each of the multiple orderings that satisfy the one or more legality constraints, the processor may also be configured to determine the corresponding estimated computational cost for the ordering. The processor may also be configured to reorder the multiple conditions to have an ordering with the lowest estimated computational cost among the multiple orderings that satisfy the multiple one or more legality constraints.

[0087] According to this aspect, the source code may also include a first branch code block, the first branch code block including one or more first branch evaluation instructions, the one or more first branch evaluation instructions being configured to be executed when multiple conditions are true. The source code may also include a second branch code block, the second branch code block including one or more second branch evaluation instructions, the one or more second branch evaluation instructions being configured to be executed when at least one of the multiple conditions is false.

[0088] According to this aspect, the one or more legality constraints may include the following constraint: the source code includes a first branch code block and a second branch code block.

[0089] According to this aspect, the one or more legality constraints may include a constraint that the corresponding code block of each condition includes instructions to proceed to a common target code block.

[0090] According to this aspect, the one or more legality constraints may include a constraint that a portion of the source code after a final code block of corresponding code blocks of the plurality of conditions and before the common target code block has an entry point and an exit point.

[0091] According to this aspect, the one or more legality constraints may include the constraint that no instruction calls an undefined variable.

[0092] According to this aspect, each code block may be a basic block.

[0093] According to this aspect, at least one code block may include a plurality of basic blocks.

[0094] According to this aspect, the processor may be configured to determine a respective estimated computational cost for each ordering at least in part by: assigning an estimated cost score to each instruction included in the ordering; and summing the respective estimated cost scores assigned to each instruction.

[0095] According to another aspect of the present disclosure, a method performed by a processor of a computing device is provided. The method may include: receiving source code at a compiler. The source code may include at least one composite condition set having multiple conditions; and a corresponding code block for each of the multiple conditions, the corresponding code block including one or more instructions for evaluating the condition. For each of the multiple orderings of the multiple conditions, the method may also include: determining that the ordering satisfies one or more legality constraints. For each of the multiple orderings that satisfy one or more legality constraints, the method may also include: determining a corresponding estimated computational cost for the ordering. The method may also include: reordering the multiple conditions to have an ordering with the lowest estimated computational cost among the multiple orderings that satisfy one or more legality constraints.

[0096] According to this aspect, the source code may also include a first branch code block, the first branch code block including one or more first branch evaluation instructions, the one or more first branch evaluation instructions being configured to be executed when multiple conditions are true. The source code may also include a second branch code block, the second branch code block including one or more second branch evaluation instructions, the one or more second branch evaluation instructions being configured to be executed when at least one of the multiple conditions is false.

[0097] According to this aspect, the one or more legality constraints may include the following constraint: the source code includes a first branch code block and a second branch code block.

[0098] According to this aspect, the one or more legality constraints include a constraint that a portion of the source code after a last code block of corresponding code blocks of the plurality of conditions and before the common target code block has an entry point and an exit point.

[0099] According to this aspect, the one or more legality constraints may include the constraint that no instruction calls an undefined variable.

[0100] According to this aspect, each code block may be a basic block.

[0101] According to this aspect, determining a respective estimated computational cost for each ordering includes: assigning an estimated cost score to each instruction included in the ordering; and summing the respective estimated cost scores assigned to each instruction.

[0102] According to another aspect of the present disclosure, a computing device is provided, comprising a processor configured to receive source code at a compiler. The source code may include multiple code blocks. For each of multiple orderings of the multiple code blocks, the processor may also be configured to determine that the ordering satisfies one or more legality constraints. For each of the multiple orderings that satisfy one or more legality constraints, the processor may also be configured to determine a corresponding estimated computational cost for the ordering. The processor may also be configured to reorder the multiple code blocks to have an ordering with the lowest estimated computational cost among the multiple orderings that satisfy one or more legality constraints.

[0103] It should be understood that, because multiple changes can be made, the configuration and / or method described herein are exemplary in nature, and these specific embodiments or examples should not be considered restrictive. The specific routine or method described herein can represent one or more processing strategies in any number of processing strategies. In this way, the various actions illustrated and / or described can be performed in the order illustrated and / or described, in other orders, in parallel or omitted. Similarly, the order of the above process can be changed.

[0104] The subject matter of the present disclosure includes all novel and non-obvious combinations and sub-combinations of the various processes, systems and configurations, and other features, functions, acts, and / or properties disclosed herein, and any and all equivalents thereof.

Claims

1. A computing device comprising a processor, wherein the processor is configured to: During the execution of the compiler: Receiving source code at the compiler, wherein the source code includes: at least one compound condition set having a plurality of conditions, the at least one compound condition set configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code is to be executed as part of the execution of the assembly code, wherein each of the plurality of conditions comprises a code block, the code block comprising one or more instructions for evaluating the condition comprising the code block as part of execution of the assembly code; determining a plurality of orderings of the plurality of conditions included in the composite condition set; determining that two or more of the plurality of orderings of the plurality of conditions satisfy one or more legality constraints and at least one of the plurality of orderings does not satisfy the one or more legality constraints, the one or more legality constraints relating to a grammatical structure of the one or more instructions of each of the plurality of conditions; determining, during the execution of the compiler and after determining that the ordering satisfies the one or more legality constraints, only for each of the plurality of orderings that satisfies the one or more legality constraints, a corresponding estimated computational cost for the ordering, while not determining at least one corresponding computational cost for the at least one ordering that does not satisfy the one or more legality constraints, wherein at least one respective computational cost for each of the plurality of orderings satisfying the one or more legality constraints is determined at least in part by: assigning an estimated cost score to each instruction included in the ordering specified by an estimated computational cost table, the estimated computational cost table mapping a plurality of instruction types to a corresponding plurality of estimated cost scores; as well as summing the respective estimated cost scores assigned to each instruction; reordering the plurality of conditions to have an ordering having a lowest estimated computational cost of the plurality of orderings that satisfies the one or more legality constraints; as well as The source code having the reordered plurality of conditions is compiled into the assembly code.

2. The computing device of claim 1, wherein the source code further comprises: a first branch code block including one or more first branch evaluation instructions, the one or more first branch evaluation instructions being configured to be executed when the plurality of conditions are true; as well as The second branch code block includes one or more second branch evaluation instructions, wherein the one or more second branch evaluation instructions are configured to be executed when at least one condition among the plurality of conditions is false.

3. The computing device of claim 2, wherein the one or more legality constraints include the following constraint: the source code includes a first branch code block and a second branch code block. 4 . The computing device of claim 1 , wherein the one or more legality constraints include a constraint that the code block of each condition includes instructions to proceed to a common target code block.

5. The computing device of claim 4, wherein the one or more legality constraints include the following constraint: a portion of the source code after a last code block of the plurality of conditional code blocks and before the common target code block has an entry point and an exit point.

6. The computing device of claim 1, wherein the one or more legality constraints include the constraint that no instruction calls an undefined variable. The computing device of claim 1 , wherein each code block is a basic block. The computing device of claim 1 , wherein at least one code block comprises a plurality of basic blocks. 9 . The computing device of claim 1 , wherein when the assembly code is executed, the compound condition set and the plurality of conditions included in the compound condition set are each configured to be evaluated as a corresponding Boolean value.

10. The computing device of claim 1 , wherein each of the plurality of instruction types is a respective type of operation, and wherein the respective type of operation has an associated estimated integer cost and an estimated floating point cost, the estimated integer cost being an estimated cost score of the respective type of operation when the respective type of operation is performed using integer calculations, and the estimated floating point cost being an estimated cost score of the respective type of operation when the respective type of operation is performed using floating point calculations.

11. The computing device of claim 10, wherein the corresponding types of operations include addition, subtraction, comparison, negation, division, remainder, AND, OR, XOR, minimum, maximum, load, and / or store.

12. A method performed by a processor of a computing device, the method comprising: During the execution of the compiler: Receiving source code at the compiler, wherein the source code includes: at least one composite condition set having a plurality of conditions, the at least one composite condition set configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code is to be executed as part of the execution of the assembly code, wherein each of the plurality of conditions comprises a code block comprising one or more instructions to evaluate the condition comprising the code block as part of the execution of the assembly code; determining a plurality of orderings of the plurality of conditions included in the composite condition set; determining that two or more of the plurality of orderings of the plurality of conditions satisfy one or more legality constraints and at least one of the plurality of orderings does not satisfy the one or more legality constraints, the one or more legality constraints relating to a grammatical structure of the one or more instructions of each of the plurality of conditions; determining, during said execution of said compiler and after determining that said ordering satisfies said one or more legality constraints, only for each ordering of said plurality of orderings that satisfies said one or more legality constraints, a corresponding estimated computational cost for said ordering, while not determining at least one corresponding computational cost for said at least one ordering that does not satisfy said one or more legality constraints; wherein at least one respective computational cost for each of the plurality of orderings satisfying the one or more legality constraints is determined at least in part by: assigning an estimated cost score to each instruction included in the ordering specified by an estimated computational cost table, the estimated computational cost table mapping a plurality of instruction types to a corresponding plurality of estimated cost scores; and summing the respective estimated cost scores assigned to each instruction; reordering the plurality of conditions to have an ordering having a lowest estimated computational cost of the plurality of orderings that satisfies the one or more legality constraints; and The source code having the reordered plurality of conditions is compiled into the assembly code.

13. The method according to claim 12, wherein the source code further comprises: a first branch code block including one or more first branch evaluation instructions, the one or more first branch evaluation instructions being configured to be executed when the plurality of conditions are true; as well as The second branch code block includes one or more second branch evaluation instructions, wherein the one or more second branch evaluation instructions are configured to be executed when at least one condition among the plurality of conditions is false.

14. The method according to claim 13, wherein the one or more legality constraints include the following constraint: the source code includes a first branch code block and a second branch code block.

15. The method of claim 12, wherein the one or more legality constraints include a constraint that the code block of each condition includes instructions to proceed to a common target code block.

16. The method of claim 15, wherein the one or more legality constraints include the following constraint: a portion of the source code after a last code block of the plurality of conditional code blocks and before the common target code block has an entry point and an exit point.

17. The method of claim 12, wherein the one or more legality constraints include the following constraint: no instruction calls an undefined variable.

18. The method of claim 12, wherein each code block is a basic block. The method of claim 12 , wherein at least one code block comprises a plurality of basic blocks.

20. The method of claim 12, wherein each instruction type of the plurality of instruction types is a respective type of operation, and wherein the respective type of operation has an associated estimated integer cost and an estimated floating point cost, the estimated integer cost being an estimated cost score of the respective type of operation when the respective type of operation is performed using integer calculations, and the estimated floating point cost being an estimated cost score of the respective type of operation when the respective type of operation is performed using floating point calculations.

21. The method of claim 20, wherein the corresponding types of operations include addition, subtraction, comparison, negation, division, remainder, AND, OR, XOR, minimum, maximum, load, and / or store.

22. A computing device comprising a processor, the processor being configured to: During the execution of the compiler: receiving source code at the compiler, wherein the source code includes a plurality of code blocks included in a compound conditional set and configured to be evaluated as part of execution of assembly code compiled from the source code to determine which of a plurality of branch code blocks of the assembly code is to be executed as part of the execution of the assembly code; determining a plurality of orderings of a plurality of conditions included in the composite condition set; determining that two or more of the plurality of orderings of the plurality of code blocks satisfy one or more legality constraints and at least one of the plurality of orderings does not satisfy the one or more legality constraints, the one or more legality constraints relating to a grammatical structure of one or more instructions of each of the plurality of code blocks; determining, during said execution of said compiler and after determining that said ordering satisfies said one or more legality constraints, only for each ordering of said plurality of orderings that satisfies said one or more legality constraints, a corresponding estimated computational cost for said ordering, while not determining at least one corresponding computational cost for said at least one ordering that does not satisfy said one or more legality constraints; wherein at least one respective computational cost for each of the plurality of orderings satisfying the one or more legality constraints is determined at least in part by: assigning an estimated cost score to each instruction included in the ordering specified by an estimated computational cost table, the estimated computational cost table mapping a plurality of instruction types to a corresponding plurality of estimated cost scores; as well as summing the respective estimated cost scores assigned to each instruction; reordering the plurality of conditions to have an ordering having a lowest estimated computational cost of the plurality of orderings that satisfies the one or more legality constraints; as well as The source code having the reordered plurality of conditions is compiled into the assembly code.

Citation Information

Patent Citations

  • Automatic kernel migration for heterogeneous cores

    CN103534686A

  • Method and system using exceptions for code specialization in a computer architecture that supports transactions

    CN103999036A

  • Compiler caching for runtime routine redundancy tracking

    CN106716361A

  • Method and apparatus for optimizing boolean expression evaluation

    US20070174830A1

  • Streamlined execution of emulated code using block-based translation mode

    US20130090913A1