International Journal of Computer Applications (0975 – 8887) Volume 79 – No.1, October 2013 37 An Optimal Code Heuristic Approach for Compiler Optimization using Graph Coloring Technique Prateek Saraf School of computing science and engineering VIT UNIVERSITY Rajnish Dashora School of computing science and engineering VIT UNIVERSITY ABSTRACT Graph theory has found its applications in various fields of computation involved in day to day life. A problem solving approach that incorporates graph theory has an added advantage of being simple and visually more comprehensible [9]. Data mining, image processing, astrology and astronomy, theoretical computer science, artificial intelligence and compiler optimization et al., every evolving field utilizes efficient algorithms involving graphs and their properties. Graph coloring has major applications in the field of compiler optimization. This paper proposes a heuristic approach of graph coloring for code optimization and hence, improvement in compiler performance and accuracy. Color-based merging of colored graphs reduces the use of temporary variables, increasing efficiency in memory utilization. A comparative analysis has been carried out in order to present the advantages of the proposed algorithm [5] [6]. Keywords Compiler optimization, reduced graph coloring, Compiler optimization, Graph coloring, Graph traversal. 1. INTRODUCTION AND MOTIVATION Graphs play a vital role in the optimization process phase of the compiler. There are several applications of graphs in different phases of compilers. Parse trees, Syntax trees, DAG’s are useful in the initial phases where the code is analysis and prepared for synthesis. In synthesis part, flow graphs and basic blocks are generated for Data and control flow analysis and code optimization. Graphs can be used for peephole optimization and optimization of resister allocation problem in memory. Graph coloring which is an NP- complete problem can be implied to solve the register allocation problem. Through graph coloring a heuristic solution can be implemented for reducing the number of temporary variables and hence reducing the memory required for computation. 2. RELATED WORKS AND EXISTING SOLUTIONS Earlier existing algorithms for optimizing compiler such as Generating syntax directed translation graph for 3 address codes. Graph coloring is one of the popular methods for register allocation problem. The existing graphs coloring heuristics generate the colored graph as the syntax tree populates every time coloring the whole graph which has a overhead of higher utilization of CPU. Use such algorithms do not efficiently optimizes the compilation process but sometimes becomes and overhead. Hence the proposed solution erects those flaws from the existing approaches [2]. 3. CURRENT PROBLEM SCENARIO The problem is to find how graph coloring needs to be done for optimal allocation of registers in compiler optimization technique for above disconnected graph hence to optimize the performance of compiler. . Fig 1(a) Graph G1 for a=b+c Fig 1(b) Graph G2 for d=e+f For the above situation, graph coloring algorithm is applied – 3 times (1 for graph 1(a) + 1 for graph 1(b)) + 1 for the connected graph obtained. Though only 3 colors are used, 3 registers required for temporary storage. Also excess use of coloring algorithm causes a heavy drop in the performance of the optimization process[10].