CN109800086A - A kind of method of Optimizing Compiler ram space - Google Patents
A kind of method of Optimizing Compiler ram space Download PDFInfo
- Publication number
- CN109800086A CN109800086A CN201811609866.7A CN201811609866A CN109800086A CN 109800086 A CN109800086 A CN 109800086A CN 201811609866 A CN201811609866 A CN 201811609866A CN 109800086 A CN109800086 A CN 109800086A
- Authority
- CN
- China
- Prior art keywords
- register
- jump
- compiler
- distributing
- ram space
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 29
- 238000004064 recycling Methods 0.000 claims abstract description 7
- 238000009826 distribution Methods 0.000 claims description 10
- 238000011161 development Methods 0.000 abstract description 3
- 238000005457 optimization Methods 0.000 description 12
- 230000006870 function Effects 0.000 description 9
- 238000010586 diagram Methods 0.000 description 7
- 238000003860 storage Methods 0.000 description 4
- 238000012217 deletion Methods 0.000 description 2
- 230000037430 deletion Effects 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 241000208340 Araliaceae Species 0.000 description 1
- 235000005035 Panax pseudoginseng ssp. pseudoginseng Nutrition 0.000 description 1
- 235000003140 Panax quinquefolius Nutrition 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000006378 damage Effects 0.000 description 1
- 238000000151 deposition Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 235000008434 ginseng Nutrition 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000009790 rate-determining step (RDS) Methods 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses the methods of Optimizing Compiler ram space, this method is carried out on the basis of existing compiler register allocation algorithm, this method is using function as basic unit, the top-down allocated temporary register of statistics, when distributing register, first judges whether used register does not use using counting, it is then recycled if there is such register, then the used register of this recycling is directly distributed, if not provided, just distributing a new register.The present invention can be optimized when distributing register index to intermediate dummy order before distributing register, reduced the temporary register quantity used, substantially increased development efficiency.
Description
Technical field
The invention belongs to the technical fields of compiler, in particular to the method for Compiler Optimization in C language.
Background technique
C language is a kind of structured language, has operator abundant and data type, is easy to implement the number of all kinds of complexity
According to structure.It can also directly access the physical address of memory, carry out the operation of position (bit) level-one.Since C language realizes pair
The programming operation of hardware, therefore C language integrates the function of high-level language and low-level language.C language also have it is high-efficient, can
The features such as transplantability is strong, therefore can widely be transplanted on the computer or single-chip microcontroller of various platforms.
In C language, compiler is to measure the important indicator of a compiler quality to the efficiency of ram space, and RAM is used
It is few, product cost can be effectively reduced.Use of the compiler to ram space is mainly reflected in use of the program to temporary variable,
Therefore compiler is extremely important in the distribution to temporary variable, and algorithm has directly certainly write the usage quantity of temporary variable, determines
The speed of service and treatment effeciency of data.
Patent application 201510262282.7 discloses a kind of storage method of executable code under ARMv7m framework, by compiling
It translates and five burning program, startup program, FPB associated program, execution program and bus exception handler logic units ginsengs
With a piece of ram space is associated at one not and on the associated address physics Flash by FPB associated program, as depositing
The memory space for having stored up executable code obtains and is executed for CPU core machine instruction and uses.The ram space can move simultaneously
State is updated to newly be worth, and can be reset and be associated on the new address Flash by FPB.In this way, the method for the present invention is used only
Flash in one small pieces piece stores FPB management code, so that it may, will using little ram space and the outer Flash of cheap piece
The memory space of the executable code of CPU is expanded to 512MB.
It is that ram space is associated on the unknown associated address physics FLASH with associated program in above-mentioned patent application,
Therefore, control the enabled of dead battery functi on or cancel be the key that with current most equipment normal communication, at present still without phase
Pass technology solves the problems, such as.
Summary of the invention
To solve the above problems, the purpose of the present invention is to provide a kind of method of Optimizing Compiler ram space, this method
Be C compiler before distributing register to intermediate dummy order distribute register index when optimize, reduce use it is interim
Developer can be used in existing chip top in register number, develops that code is more, and the more complicated program of function goes out
Come, substantially increases development efficiency.
It is another object of the present invention to provide a kind of methods of Optimizing Compiler ram space, and this method is by deposit
The adjustment of device number, register recycling, register reassigns, register reads and writes the rate-determining steps such as optimization, and it is interim to can achieve optimization
Register uses, and effectively reduces the register number needed when program operation.
To achieve the above object, technical scheme is as follows.
A kind of method of Optimizing Compiler ram space, this method are the bases in existing compiler register allocation algorithm
It is carried out on plinth, it is characterised in that this method is using function as basic unit, the top-down allocated temporary register of statistics
First judge whether used register does not use when distributing register using counting, if there is such register
It is then recycled, then directly distributes the used register of this recycling, if not provided, just distributing a new deposit
Device.
But when, there are when jump instruction, situation is with regard to different, in register distribution, if there is JUMP is jumped in function
GO TO statement such case, when generation JUMP is jumped, the sentence from Jump sentence starting position to the target position JUMP is formd
One loop body, inside loop body, if read operation first occurs for some register, which cannot be recycled, if first
Write operation occurs, then can recycle.
Further, since compiler is to carry out by default sequence to register allocation algorithm, so being posted when distribution is set
The number of storage distribution can't be carried out according to sequence from small to large, it is also necessary to be optimized to the number of register, by suitable
The readjustment register number of sequence from top to bottom.
Further, after write operation read operation occurs never again for some registers, for such instruction, Ke Yizhi
This instruction of deletion is connect, without influencing whether program implementing result.
The present invention is to optimize in C compiler when distributing register index to intermediate dummy order before distributing register,
The temporary register quantity that the HEX shelves for alloing it to compile out use optimizes 50% to 75%, in this way, exploit person can be used
Member develops that code is more in existing chip top, and the more complicated program of function comes out, and substantially increases development efficiency.
This method is reassigned by register number adjustment, register recycling, register, register reads and writes the control such as optimization
Step can achieve optimization temporary register and use, effectively reduces the register number needed when program operation.
Detailed description of the invention
Fig. 1 is one of the schematic diagram of part C code in existing assembler language.
Fig. 2 is two of the schematic diagram of part C code in existing assembler language.
Fig. 3 is the optimization of registers schematic diagram that the present invention is realized.
Register schematic diagram when Fig. 4 is with JUMP skip instruction.
Fig. 5 is that the present invention realizes optimization of registers schematic diagram when with JUMP skip instruction.
Fig. 6 is the realized register rearrangement schematic diagram of the present invention.
Fig. 7 is the deletion register manipulation instruction schematic diagram that the present invention is realized.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.
As shown in connection with fig. 1, it applicants have found that, is generated in assembler language in C code, such as main function needs in total
It uses 22 registers (when code is more complicated, the register number of occupancy will linearly increase), analyzes assembly code, it can
With discovery, some registers can be multiplexed, such as temp+10 this temporary register used in the 7th line code, such as be schemed
Shown in 2, after the 7th row, it is previously used never again, if can be this temp_10 register utilization and recycle?
The method that the present invention uses register to recycle again, can correctly and effectively recycle temporary register, when
When compiler needs to distribute register, the temporary register recycled is preferentially distributed, then is not new interim of direct distribution one
Register, to achieve the purpose that reduce temporary register usage quantity.
Therefore, the method for the Optimizing Compiler ram space that the present invention is realized is distributed in existing compiler register
It is carried out on the basis of algorithm, using function as basic unit, the top-down allocated temporary register of statistics, which uses, to be counted,
When distributing register, first judge whether used register does not use, if there is such register then by its time
It receives, then directly distributes the used register of this recycling, if not provided, just distributing a new register.Such as Fig. 3
Shown (number that the number in box represents register).
Fig. 3 is that a register is found out No. 1 register and connect down using optimised process when distributing No. 8 registers
Will not be used again, thus it is all underneath with No. 8 registers replace with No. 1 register, when being assigned to No. 10 deposits
When device, it is found that No. 2 registers are no longer used, so No. 2 registers are replaced following No. 10 all registers, when distribution 11
When number register, No. 11 registers are replaced with No. 3 registers not used.
By such replacement process above, by original 6 registers of needs, become only to need 3 registers.
But when in function there are when jump instruction, situation with regard to different, cannot with this simple replacement above come
Complete the distribution of register.
As shown in figure 4, when having a Do statement gotoLBB0_1 in code, if that using above method row
Temporary register 8 in 6 sentences is replaced with register 1, then when going to gotoLBB0_1 sentence and returning to the position LBB0_1,
The content in register 1 quoted in row 5 is not just the content of initial register 1, and being expert at 6 is cited or modifies, this
Sample just constitutes destruction to the correctness of register read-write.
Therefore, when doing register distribution, it is also necessary to consider JUMP skip instruction such case, be jumped JUMP occurs
When, the sentence from Jump sentence starting position to the target position JUMP forms a loop body, inside loop body, if certain
Read operation first occurs for a register, then the register cannot recycle, if write operation first occurs, can recycle.Specific method
As shown in Figure 5.
In Fig. 5, R before register indicates read operation, and W indicates write operation, small frame enclose in be the deposit being replaced
Device number.Register 3 is expert at after 2, is not cited again, so when distributing register 8, it can be posting in row 6 and row 12
Storage 8 is all replaced with register 3.In loop body, read operation first occurs for register 1 and register 3, so register 1 and 3
It cannot be recovered, but write operation first occurs for register 2, so the register 11 for 10 positions of being expert at can be substituted for register 2.
Since compiler is to carry out by default sequence to register allocation algorithm, so register divides when distribution is set
The number matched can't be carried out according to sequence from small to large, although above only used 1,2,3,10 4, register deposit
Device, but when final link, the use of register can be distributed according to maximum register number, posted so 10 still can be used
Storage, therefore also need to optimize the number of register.Optimization algorithm is as shown in Figure 6.
As shown in fig. 6, readjustment register number from top to bottom, the register 3 of row 2 are adjusted to register in order
2, row 3, row 7, row 9 register 2 be adjusted to register 3, and so on, after final optimization pass, it is only necessary to use register 1,2,
3,4 four registers.
After write operation read operation occurs never again for some registers, for such instruction, can directly delete this
Item instruction, without influencing whether program implementing result.As shown in fig. 7, either being recycled after writing the operation of register 3 at row 10
In internal or entire code block, all without forming the read operation to register 3, therefore the register manipulation can be deleted and referred to
It enables.
The present invention is reassigned by register number adjustment, register recycling, register, register reads and writes optimization, this calculation
Method can achieve optimization temporary register and use, and effectively reduce the register number needed when program operation.
In short, the present invention is to distribute the progress of register index when to intermediate dummy order before distributing register in C compiler
Optimization, the temporary register quantity that the HEX shelves for alloing it to compile out use optimizes 50% to 75%, in this way, can be used
Developer develops that code is more in existing chip top, and the more complicated program of function comes out, and substantially increases exploitation effect
Rate.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Made any modifications, equivalent replacements, and improvements etc., should all be included in the protection scope of the present invention within mind and principle.
Claims (4)
1. a kind of method of Optimizing Compiler ram space, this method is on the basis of existing compiler register allocation algorithm
Upper progress, it is characterised in that using function as basic unit, the top-down allocated temporary register of statistics makes this method
First judge whether used register does not use when distributing register with counting, then if there is such register
It is recycled, then directly distributes the used register of this recycling, if not provided, just distributing a new deposit
Device.
2. the method for Optimizing Compiler ram space as described in claim 1, it is characterised in that when there are jump to refer in function
When enabling, in register distribution, if there is JUMP skip instruction such case is opened when generation JUMP is jumped from Jump sentence
The sentence of beginning position to the target position JUMP forms a loop body, inside loop body, if some register first occurs
Read operation, then the register cannot recycle, if write operation first occurs, can recycle.
3. the method for Optimizing Compiler ram space as described in claim 1, it is characterised in that after register then recycles, dividing
When configuration, the number of register is optimized, in order readjustment register number from top to bottom.
4. the method for Optimizing Compiler ram space as described in claim 1, which is characterized in that some registers are in write operation
Afterwards, read operation occurs never again, directly deletes this instruction.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811609866.7A CN109800086B (en) | 2018-12-27 | 2018-12-27 | Method for optimizing RAM space of compiler |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811609866.7A CN109800086B (en) | 2018-12-27 | 2018-12-27 | Method for optimizing RAM space of compiler |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN109800086A true CN109800086A (en) | 2019-05-24 |
| CN109800086B CN109800086B (en) | 2022-12-06 |
Family
ID=66557672
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201811609866.7A Active CN109800086B (en) | 2018-12-27 | 2018-12-27 | Method for optimizing RAM space of compiler |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN109800086B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112052004A (en) * | 2019-06-05 | 2020-12-08 | 深圳市汇顶科技股份有限公司 | Function parameter optimization method, compiler, chip and electronic equipment |
Citations (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6079014A (en) * | 1993-12-02 | 2000-06-20 | Intel Corporation | Processor that redirects an instruction fetch pipeline immediately upon detection of a mispredicted branch while committing prior instructions to an architectural state |
| CN101169710A (en) * | 2006-10-26 | 2008-04-30 | 中国科学院计算技术研究所 | Method for renaming status register and processor using the method |
| CN101246434A (en) * | 2008-03-06 | 2008-08-20 | 中国人民解放军国防科学技术大学 | A method of allocating registers by utilizing remaining resources |
| KR20090010530A (en) * | 2007-07-23 | 2009-01-30 | 재단법인서울대학교산학협력재단 | Register Allocation Method for Heterogeneous Register Architecture |
| CN101546271A (en) * | 2009-04-30 | 2009-09-30 | 上海交通大学 | Register allocation method for super block in dynamic binary translation system. |
| CN102831005A (en) * | 2012-07-13 | 2012-12-19 | 天津国芯科技有限公司 | Compiling method for optimizing allocation of register based on C*core processor and compiler |
| CN106126363A (en) * | 2016-06-20 | 2016-11-16 | 芯海科技(深圳)股份有限公司 | A kind of verification method of depositor |
| CN107632830A (en) * | 2017-09-19 | 2018-01-26 | 首都师范大学 | A kind of register allocation method and system for overflowing optimization |
-
2018
- 2018-12-27 CN CN201811609866.7A patent/CN109800086B/en active Active
Patent Citations (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6079014A (en) * | 1993-12-02 | 2000-06-20 | Intel Corporation | Processor that redirects an instruction fetch pipeline immediately upon detection of a mispredicted branch while committing prior instructions to an architectural state |
| CN101169710A (en) * | 2006-10-26 | 2008-04-30 | 中国科学院计算技术研究所 | Method for renaming status register and processor using the method |
| KR20090010530A (en) * | 2007-07-23 | 2009-01-30 | 재단법인서울대학교산학협력재단 | Register Allocation Method for Heterogeneous Register Architecture |
| CN101246434A (en) * | 2008-03-06 | 2008-08-20 | 中国人民解放军国防科学技术大学 | A method of allocating registers by utilizing remaining resources |
| CN101546271A (en) * | 2009-04-30 | 2009-09-30 | 上海交通大学 | Register allocation method for super block in dynamic binary translation system. |
| CN102831005A (en) * | 2012-07-13 | 2012-12-19 | 天津国芯科技有限公司 | Compiling method for optimizing allocation of register based on C*core processor and compiler |
| CN106126363A (en) * | 2016-06-20 | 2016-11-16 | 芯海科技(深圳)股份有限公司 | A kind of verification method of depositor |
| CN107632830A (en) * | 2017-09-19 | 2018-01-26 | 首都师范大学 | A kind of register allocation method and system for overflowing optimization |
Non-Patent Citations (2)
| Title |
|---|
| ŁUKASZ DOMAGAŁA 等: "Register allocation and promotion through combined instruction scheduling and loop unrolling", 《THE 25TH INTERNATIONAL CONFERENCE》 * |
| 岳峰 等: "一种基于分区域优先级的寄存器分配算法", 《电子与信息学报》 * |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112052004A (en) * | 2019-06-05 | 2020-12-08 | 深圳市汇顶科技股份有限公司 | Function parameter optimization method, compiler, chip and electronic equipment |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109800086B (en) | 2022-12-06 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8312447B2 (en) | Managing updates using compiler and linker information | |
| US10534590B2 (en) | Dynamic recompilation techniques for machine learning programs | |
| US6871341B1 (en) | Adaptive scheduling of function cells in dynamic reconfigurable logic | |
| Skinderowicz | The GPU-based parallel ant colony system | |
| US8996556B2 (en) | Parallel processing of an ordered data stream | |
| CN113835685B (en) | Network operating system design method based on mimicry database | |
| US11514010B2 (en) | Deduplication-adapted CaseDB for edge computing | |
| Jurczuk et al. | Evolutionary induction of a decision tree for large-scale data: a GPU-based approach | |
| CN110428054A (en) | Business Rule Engine pattern matching system and implementation method based on technique of compiling | |
| CN108874438A (en) | Patch generation method, device, electronic equipment and computer program product | |
| JP6877435B2 (en) | Database operation method and equipment | |
| Le et al. | Automatic gpu memory management for large neural models in tensorflow | |
| US20200012599A1 (en) | Apparatus and method and computer program product for controlling data access | |
| Shen et al. | Bridging the Gap between Relational {OLTP} and Graph-based {OLAP} | |
| CN118245207A (en) | Memory optimization method and device based on tensor version control | |
| Day | Compiler assignment of data items to registers | |
| CN107870922A (en) | A kind of method, apparatus and system for data deduplication | |
| CN109800086A (en) | A kind of method of Optimizing Compiler ram space | |
| Petrov et al. | Towards effective embedded processors in codesigns: customizable partitioned caches | |
| Schuster et al. | RAP. 2-An associative processor for data bases | |
| EP4083785B1 (en) | Profiling and optimization of compiler-generated code | |
| Eigenmann et al. | Is OpenMP for grids? | |
| Ruggiero | Throttle Mechanisms for the Manchester Dataflow Machine | |
| CN118761098A (en) | Cloud native container storage access policy optimization method and system based on federated learning | |
| US20200394202A1 (en) | System and a method of fast java object materialization from database data |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |