Code Size Reduction via Weighted IR Grouping
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Conventional procedural abstraction techniques for code size reduction are not effective in minimizing the difference between non-optimized and optimized intermediate representation (IR) code sizes, and object code sizes generated from these IR codes.
Innovation Solution
A method and apparatus that determine basic blocks with duplicate code, group them, assign weighting values based on intermediate representation program codes, calculate weighted sizes, remove duplicates, and compare the sizes to optimize code size reduction, utilizing a procedural extraction mechanism and weighting values to identify and process groups that offer performance gains.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Quantity of substance
If conventional procedural abstraction techniques are applied to reduce code size, then the size of generated codes can be reduced, but the reduction effect between optimized IR code and object code is insufficient
Solution Approach 1:
The patent applies preliminary action by performing procedural abstraction on intermediate representation (IR) code before compilation to object code. The system identifies and extracts common code patterns at the IR level, creating reusable procedures that are then referenced throughout the codebase. This preliminary optimization ensures that the reduced code structure is preserved through compilation, achieving both IR code size reduction and object code size reduction simultaneously rather than attempting optimization after compilation.
2Adaptability or versatility
If procedural abstraction is applied to extract common code segments, then code reusability is improved, but the complexity of the optimization process increases
Solution Approach 1:
The patent implements feedback mechanisms that monitor code patterns during the procedural abstraction process. The system analyzes the IR code to identify common patterns, extracts them into procedures, and then evaluates whether the extraction actually reduces overall code size and improves reusability. Based on this feedback, the optimizer adjusts its strategy - continuing to extract patterns that provide benefit while avoiding extractions that increase complexity without sufficient gain. This feedback-driven approach balances code reusability improvements against optimization process complexity.
Data Source
AI summary
A method for code size reduction, which comprises determining basic blocks in an IR module; grouping the basic blocks having duplicate code into groups; providing weighting values corresponding to different instructions of the module, wherein the weighting values are determined based on a plurality of intermediate representation program codes; determining a weighted size of the module, wherein the weighted size of the module is determined by summing weighted sizes of the basic blocks of the module, and the weighted size of each basic block is determined by summing products of numbers of different instructions of the basic blocks and the corresponding weighting values; removing duplicates in one group to obtain a module having one processed group; determining a weighted size of the module having one processed group; and comparing the weighted size of the module to the weighted size of the module having one processed group.


