International Journal For Technological Research In Engineering Volume 3, Issue 5, January-2016 ISSN (Online): 2347 - 4718

CODE OPTIMIZATION: A DETAILED REVIEW

Atul Gaur1, Himanshu Verma2 2AP, 1,2Computer Science Engg, St. Margaret Engg. College Neemrana

Abstract: The main motive of this paper is to present the to realize performance within the execution. ASCII text file need of the code optimization and work done in the field of improvement refers to the 3 aspects, a programming the code optimization. The improvement within the quality language code (front code), associate programming language of code remains an enormous issue from the sooner days. code that is generated by the to the acceptable Typically it's troublesome for a computer programmer to programming language (intermediate code), the article code seek out that a part of code consumes a lot of resources and that is generated from the programming language code for thence result in an inefficient code. Antecedently most of the execution of the particular work. This work involves the the improvement were done manually or are often same as implementation of 2 totally different techniques, dead code statically those results in variety of issues to the computer elimination and customary sub expression elimination with programmer and additionally had a number of the the employment of various tools so as to optimize the code. restrictions. However, of late many area unit obtainable that makes the improvement to be performed II. LEVELS OF OPTIMIZATION dynamically. During this treatise work, an endeavor has Optimization is accomplished at varied levels (e.g. ASCII been created to style and implement a system that may text file, intermediate representations), and by totally mechanically optimize the code so as to reduce the quality different parties, like developer or the compiler or optimizer. of the code specified the code becomes a lot of economical. Improvement is assessed into 2 levels that area unit Keywords: Code Optimization, Compiler, Code Reduction, mentioned below: Inlining HIGH LEVEL OPTIMIZATION High level improvement is usually implemented by those I. INTRODUCTION programmers WHO manage the abstract entities like In compiler style, there's one in all the technique within functions, procedures, classes, etc. and conjointly the coder which a region of code is being reworked to provide ought to create concern concerning the final framework of additional economical still on improve the performance such the task to optimize the planning of a system. Optimizations the output remains same, termed as “Optimization”. Code that are typically performed at the amount of basic structural improvement aims to create top quality code with best quality blocks of ASCII text file i.e. loops, branches, etc. are (time and space) such it mustn't have an effect on the precise mentioned as high level improvement. results of the code. it's chiefly supported the criterion to LOW LEVEL OPTIMIZATION preserve the linguistics equivalence of the program, such the Low level optimizations are dead at a stage once ASCII text rule should not be changed. On a mean, the transformation file is being compiled into a collection of machine level ought to speed up the execution of the program. directions and during this stage usually automatic Improvement includes finding a bottleneck, a important a optimization is employed. part of the code that is that the primary shopper of the required resources. Essentially Code improvement issues on III. SCOPE OF CODE OPTIMIZATION correctness, it suggests that the correctness of the generated The scope of optimization can be local, global and inter- code mustn't be modified. The most aim of the code procedural which are described below: improvement is to create top quality code with improved A. LOCAL OPTIMIZATION quality (time and space) while not moving the precise results Local optimization area unit typically enforced during a part of the code. On victimization totally different improvement of one procedure or it is say that it's principally applied to techniques, the code is often optimized while not moving the straight lines phase of code, called basic block. Native first (actual) rule and final output with the intent of high strategies area units are typically straightforward to research performance. Once performance is to be thought of, then and perceive. 2 necessary properties hold within a basic there ought to select associate rule that runs quickly and block, 1st the statements area unit dead in some simply therefore the on the market computing resources are getting determined order and second the whole block executes, if used expeditiously. So, it are often aforementioned that the any of statement executes. local strategies build target of improvement is to put in writing a code in such the enhancements that merely cannot be obtained on larger simplest way that may cut back each the memory still as scope. speed. Basically, Code improvement involves the utilization B. GLOBAL OR INTRA-PROCEDURAL OPTIMIZATION of rules and algorithms to the program phase with the aim Global improvement is performed on the far side the such the code becomes quicker, smaller, additional essential blocks. International strategies area unit continually economical then on. In theoretical perspective, the compiler depend upon the worldwide analysis. Typically knowledge improvement essentially refers to the program improvement flow analysis is employed for this purpose. To assemble

www.ijtre.com Copyright 2015.All rights reserved. 916

International Journal For Technological Research In Engineering Volume 3, Issue 5, January-2016 ISSN (Online): 2347 - 4718

facts, the worldwide techniques typically include procedure B. MACHINE DEPENDENT OPTIMIZATION wide analysis that is followed by the applying of derived Machine dependent optimization is performed when the facts to the precise transformation selections. These generation of target code and once the code is being improvement strategies find out the opportunities for the remodeled according to the machine design i.e. this method development that isn't possible within the local improvement. needs the information of target machine design. During these Compared to local optimization, the worldwide improvement quite techniques instead of the relative reference, processor is tough to implement. registers area unit concerned and conjointly might have C. INTER-PROCEDURAL OPTIMIZATION absolute reference. The trouble is formed by the optimizers This kind of optimization considers the full program as their specified the most utilization of memory hierarchy might scope. As moving from local to international, the scope of happen. Using this method the restricted machine resources, research will increase that exposes new opportunities. even the latency area unit managed. whereas observing complete programs, a number of the complications and limitations appeared like analyzing totally different parameter passing mechanisms, risk of non variable access and separate compilation, and can be there's have to be compelled to calculate coincidental data on all procedures which may call one another. Inter-procedural optimizations square measure those that take place among over one procedure. This sort of optimization is harder compared to native and international optimization.

IV. TYPES OF OPTIMIZATION Figure 2: Machine Dependent Transformation Optimization can be classified into following two categories machine independent optimization and machine dependent V. IMPORTANCE AND RELEVANCE OF THE STUDY optimization which are described below: Optimization is that the field wherever most of the analysis is A. MACHINE INDEPENDENT OPTIMIZATION finished. Studying the various papers and article a number of Machine freelance optimizations are those within which the the relevant data area unit gathered that makes the compiler takes within the intermediate code and transforms a optimization method attainable. Chirag[1] describes bit of code and additionally doesn't need any computer concerning the peephole optimization technique using hardware register and/or any absolute memory locations. this completely different pattern matching approaches that forms type of optimization is performed freelance of the target an regular expression and additionally has explores the machine that the compiler is generating the code. Machine previous and current analysis problems in term of freelance transformation replaces a redundant computation “optimizing” compilers mistreatment improvement rules that with reference, additionally the analysis is enraptured to a area unit presupposed to be matched through that the less often dead place, useless code is locate out and redundant instruction of intermediate code are often elimination of useless code takes place etc. The machine investigated and replaced. For this completely different freelance code optimization section attempts to boost the pattern matching approaches are mentioned like string based intermediate code such the higher target code ought to mostly, tree manipulation, object based mostly etc. The manufacture. Generally, higher code means the code ought to paper is being divide into four sections wherever specific execute quicker however at the side of this, completely rules and pattern rules area unit arduous coded that explains different objectives additionally need to be thought-about like concerning the machine dependent hole optimizers, the muse smaller code, or code that consumes less power. However in of retarget in a position hole improvement the combination work, main focus is to get a optimize code with less of code generation and optimization into one section and complexness and short code concerning completely different pattern matching methods severally. Brandolese[2] introduced a comprehensive methodology for software system execution time estimation, that is supported by rigorous mathematical models of C statements in terms of elementary operations. during this the complete analysis flow has been performed inside a example toolset that area unit presently getting used for confirmative and adapting model parameters. Johnson [3] in his article describes concerning the optimization that is procedure of changing a chunk of code such the code becomes a lot of economical and also the output remains same. it's being additionally expressed that several of the issues were NP complete and thus most of the optimization algorithmic program depends on approximation and heuristics. Figure 1: Machine Independent Transformation

www.ijtre.com Copyright 2015.All rights reserved. 917

International Journal For Technological Research In Engineering Volume 3, Issue 5, January-2016 ISSN (Online): 2347 - 4718

Additionally he expressed that after the code has been reduction termed as OSR. OSR actually is an improvement written; let the compiler do the optimization using compiler over a prior/previous algorithm given by Allen, Cocke, and processes. In this paper the outline is given concerning the Kennedy. OSR depends on prior optimization and properties optimization that focuses thereon the compilation method of SSA graph such that the algorithm developed should be ought to be like because the correctness of the generated code easy to understand and implement, it should avoid shouldn't be modified, additionally strategy is defined like instantiation of sets of and region “when” and “where” to optimize for activity optimization. a constants which are required by other algorithm. The number of the techniques applied to intermediate code, others algorithm depends on dominance data which are calculated area unit applied to final code generation and even a number during the construction of SSA, the resultant algorithm is of the techniques may occur after the ultimate code easy to recognize, teach, and implement. Also, discussion generation during which the try is formed to transform the about previous work which are been done in the field of assemble code itself to a lot of economical one. It . KoushikGhosh[7] in his article have additionally describes concerning the “local optimization” collected all the experience and information that can be used that is outlined because the optimization that area unit solely to speed up the execution as well as memory to make a C enforced inside a basic block, thus these variety of code optimized. In this article the author had also presented optimization area unit easy to implement as a result of any the number of guidelines using which the optimization in C reasonably management data isn't required solely the can be made possible. It also discusses that which part of the optimization is to be performed inside a block. a number of code need to be optimized. Going through the article, the native optimization like , constant different techniques of optimization are well understood such propagation also are explained. Optimizations which will as about inlining, integers, Boolean expression etc. Tom eliminate useless directions using pure mathematics identities Erkkinen[8] presents Model based design capabilities and area unit like operator strength reduction, copy propagation, tools which support verification of optimized fixed point . With the exception of native ECU software. It also tells that while implementing optimizations, an analogous reasonably optimization that production software it is important to consider about the might be applied across the fundamental blocks makes them code optimization and code verification strategies for world optimization. Additionally concerning machine embedded software. It also covers the developed optimization is explained, one in every of the machine technologies that further enable organizations to adopt MBD optimization that is of specific importance is register for embedded system deployment and verification. Paul allocation, another most vital optimization is instruction Hsieh [9] have presented an elusive subject of program planning. Michael E Lee [4] narrates techniques that were performance optimization. This article outline the general wont to optimize the code of C. The concentration is on task of Code optimization, Code architecture which is about reducing time spent by the mainframe and provides sample the simple mathematical analysis, understanding of ASCII text file transformation which regularly yield technological performance, optimization, also many of the improvement. The transformation or optimization is examples is been given by the author. Keith D. Cooper [10] performed such the developers of the applying programs presented a part of survey in which transformation of code is have the responsibility to style programs so as to create use intended to enhance the running time of programs on the uni- of restricted and high-priced resources. The article processor machines. Instead of analysis methods, the aim of additionally describes a number of techniques that were transformations is to enhance the quality of code. Analytical developed for C and C++ code that were developed for real techniques and specific data flow problems are described systems. Detail is additionally given as a way to work with which are necessary to understand transformations. Author the massive switch statements so as to scale back the quantity had individually discussed many code transformations. Each of comparisons, variety of} the techniques area unit of the transformations was discussed in depth which makes represented which may be wont to minimize native variable broad understanding. Req. Chamey[11] describes about how declaring and reducing number of parameters. Additionally the code complexity can be determined with complexity use of “int , char and short” is most popular. The document metric and presented his own metric known as Pymetric. The additionally presents a number of the techniques which will author also described about maintenance metrics which are enhance performance. Huang Zhijun[5] in his paper discuss also known as static metric and has also subdivided concerning completely different code optimization such the maintenance metrics into formatting and logical, where system resources are often totally optimize so as to maximize formatting metric concerns with indentation conventions, the potency of code. Using completely different techniques of naming conventions, comment forms, whitespace usage, and optimization like information flow optimization, loop so on whereas logical metric concerns with number of paths invariant code, the operation of knowledge etc., a through a program, conditional statements and blocks, level replacement product on TI-DSP is being developed. Code of parenthesization, number of terms and factors in an optimization will greatly improve the calculation speed, to a expression etc. Also, the column of author outlines factors number of the particular software system implementation which can be described while calculating the complexity processes, alternative ways of optimization are often such as MCB. Bruce Childers[12] describes a new method integrated such most optimization are often achieved. Keith which is based on a constant compilation system, by which [6] developed a modified algorithm for Operator strength the application of code is constantly improved when the

www.ijtre.com Copyright 2015.All rights reserved. 918

International Journal For Technological Research In Engineering Volume 3, Issue 5, January-2016 ISSN (Online): 2347 - 4718

aggressive and adaptive code optimization is applied at all [7] KoushikGhosh, “Writing Efficient C and C Code times from static to dynamic optimization. Author has Optimization” available at: described a general approach and procedure for continuous http://www.codeproject.com/Articles/6154/Writing- compilation of application code, also in this paper it is shown Efficient-C-and-C-Code-Optimization. that for prediction framework has high [8] Tom Erkinen,“Fixed point ECU code optimization accuracy. Doeppner[13] in his article described about the and verification with model based design” different optimization technique such as code motion, loop available at unrolling, inlining etc. Also the author has discussed about http://in.mathworks.com/tagteam/59064_2009-01- writing cache friendly code that is, code which can be 0269.New.pdf. organized and designed such that it utilizes the machine’s [9] Paul Heish, “Programming Optimization: ache in the most efficient way possible. Also, about writing Techniques, examples and discussion” available at: pipeline friendly cache is described. Mohammed http://www.azillionmonkeys.com/qed/optimize.html FadleAbdulla[14] documented the experiences which they [10] Keith D. Cooper, Kathryn S. Mckinley, and Linda have collected, that can be used to enhance the style of Torczon,“Compiler-Based Code-Improvement writing programs in C language even an implementation of Techniques” available at Intel VTune profiler is presented using manual optimization. http://www.cs.tufts.edu/~nr/cs257/archive/keith- The document also shows how different small changes made cooper/survey.pdf to program can affect the performance of program. It is being [11] Req. Charney, “Programming Tools: Code also stated if the developers were using good compilers and Complexity Metrics” available at have some knowledge about the optimization techniques, http://www.linuxjournal.com/article/8035 then they can much easily develop applications with high [12] Bruce Childers, Jack W. Davidson, Mary Lou performance. Soffa, “Continuous Compilation: A New Approach to Aggressive and Adaptive Code Transformation” VI. CONCLUSION available at Code Optimization is the interesting concept and it is always http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumb the continuous process to device the new method of er=1213375&url=http%3A%2F%2Fieeexplore.ieee. optimizing the code. Various research in the field of the code org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D1213 optimization is going on and due to the importance of this 375\ concept in the field of programming and computing we in our [13] Doeppner, “Optimization Techniques in C”, Fall, future work will extend our research in the field of the code 2013. optimization. http://cs.brown.edu/courses/cs033/docs/guides/c_op timization_notes.pdf REFERENCES [14] Mohammed Fadle Abdulla, “Manual and Fast C [1] Mr. Chirag H. Bhatt, Dr. Harshad B. Bhadka , Code Optimization”, Anale. SeriaInformatica. “Peephole Optimization Technique for analysis and Vol.VIII fasc. I-2010. review of Compile Design and Construction”, IOSR Journal of Computer Engineering (IOSR-JCE), Volume 9, Issue 4 (Mar. - Apr. 2013). [2] C. Brandolese, W. Fornaciari, F. Salice, D. Sciuto, “Source–Level Execution Time Estimation of C Programs”, Proceedings of the ninth international symposium on Hardware/software codesign. [3] Maggie Johnson, “Code Optimization”, Handout 20 “August 08,2004. [4] Michael E. Lee, “Optimization of Computer Programs in C ”, Ontek Corporation, USA. [5] Huang Zhijun, Liu Weiming, HeZengzhen, “Research on code optimization when develop highway network monitoring software based on Trimedia” available at http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumb er=6843485&url=http%3A%2F%2Fieeexplore.ieee. org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D6843 485. [6] Keith D. Cooper, L. Taylor Simpson, Christopher A. Vick” “Operator Strength reduction” available at :http://www.cs.rice.edu/~keith/EMBED/OSR.pdf.

www.ijtre.com Copyright 2015.All rights reserved. 919