Reduced instructions to generate global variable addresses
AssigneeMicrosoft Technology Licensing, LLC
InventorsTodd Edward Sharpe, Ten Tzen
Life of this patent
Estimating the term…
Abstract
In order to reduce the number of instructions that the compiler generates to load the address of a global variable into a register, the compiler uses a technique that analyzes the global variables used in each function in order to estimate which global variables will be located within the same memory page and have a common base address. A base global variable is selected for each function whose address is fully resolved. The address of each subsequent global variable is constructed using an offset relative to the address of the base global variable that is based on the subsequent global variable's position in a global variable order list.
Claims20
A system, comprising:
- a processor and a memory;
- wherein the memory includes a compiler having instructions that when executed by the processor perform acts that:
- receive, through a network from a client machine, a source code program having a plurality of global variables;
- order the plurality of global variables in a global variable list, wherein the global variable order list includes a ranked order of the plurality of global variables by increasing frequency of usage in the source code program;
- perform one or more code optimizations on the source code program;
- assemble the global variables used within a same function into one or more groups, wherein a group includes the global variables with the same function in the ranked order and which fit within a size of a memory page, each group including a base variable;
- generate an address for each global variable of each group, wherein the base global variable has a fully-resolved address, wherein each of the remaining global variables of a group has an offset relative to the fully-resolved address, wherein each offset is based on a distance from the base global variable in the global variable order list;
- and
- output an object code file including a plurality of machine instructions having the addresses of the global variables.
A method performed by a compiler, the method comprising:
- generating a global variable order list of global variables in a source code program, wherein the global variable order list is ordered based on frequency of usage of each global variable in the source code program;
- performing a code optimization on the source code program;
- forming one or more groups of the global variables of a function in the source code program, wherein a group includes a base global variable and one or more remaining global variables of the function, wherein the group includes global variables that fit within a memory page, wherein a group incorporates the global variables of the function in a same order as the global variable order list;
- and
- generating at least one machine instruction to access each of the global variables of the group, wherein the at least one machine instruction for the base global variable of the group has a fully-resolved address, wherein the at least one machine instruction for each remaining global variable of the group has an offset relative to the fully-resolved address of the base global variable, wherein the offset is based on position of the base global variable in the global variable order list.
A device, comprising:
- a processor and a memory;
- wherein the memory includes a profiling compiler and a backend compiler,
- wherein the profiling compiler includes instructions that when executed on the processor perform acts to:
- generate profile data from at least one execution of a source code program, wherein the profile data includes counts of usage of global variables in the source code program,
- wherein the backend compiler includes instructions that when executed on the processor to perform acts to:
- order the global variables in increasing usage based on the counts;
- form at least one group for each method in the source code program that utilizes at least one global variable, wherein the at least one group selects the global variables in the order of increasing usage, wherein the global variables of each group fit within a size of a memory page;
- select a base global variable from the at least one group having a highest usage;
- generate an address for the base global variable using an ADRP instruction and an ADD instruction;
- and
- generate an address for each remaining global variable in the at least one group using an ADD instruction, wherein the ADD instruction includes an offset relative to the base global variable address.
Dependencies are inferred from the claim text.