Global Value Numbering
CSU499 Project
Kartik Singhal
B090566CS
CSED NIT Calicut
Monday May 6, 2013
Outline
- Problem Definition
- Introduction
- GVN
- Known Algorithms
- Work Done
- Monsoon Semester 2012
-
Winter Semester 2013
- Conclusion
- Primary References
- Credits
Problem Definition
To study global value numbering,
a compiler optimization, in detail;
to review and compare known algorithms;
to implement one of the best among them;
and in the process,
improve upon the algorithm if possible.
Global Value Numbering
Global value numbering (GVN) is a program analysis
that categorizes expressions in the program
that compute the same value.
This information can be used
to remove redundant computations.
Known Algorithms
-
Kildall '73 - precise global analysis algorithm for program optimization
- AWZ '88 - an efficient algorithm, uses a value graph to represent symbolic execution of program, uses SSA, remains incomplete.
-
RKS '99 - polynomial time algorithm, extended AWZ, more equivalences, optimal for acyclic programs, remains incomplete.
- Gargi '02 - proposed balanced algorithms, extends AWZ, discovers more equivalences but is still incomplete.
- Gulwani '04 - polynomial time algorithm which is optimal if only equalities of bounded size are considered.
Work Done
Monsoon Semester 2012
- Literature Survey on GVN to solidify understanding
- Study of available compiler infrastructures, chose GCC
for implementation (Popular, Industry-standard, Open Source)
- High level study of GCC architecture:
- Study of GCC IR forms - GENERIC, GIMPLE and RTL
- Pipeline flow in GCC
- A naïve implementation of constant propagation
optimization for hands-on experience
Structure of GCC

Plugin Mechanism

Work Done
Winter Semester 2013
- Choice of GVN algorithm for implementation
- Study of GCC APIs for Pass Implementation
- Actual implementation
Chosen Algorithm
A Simple Algorithm for Global Value Numbering
- N Saleena, Vineeth Paleri. 2013. arXiv:1303.1880
- Completeness in terms of number of redundancies identified, same as that of Kildall '73
- Value expression to represent a set of equivalent expressions
- Simplicity in understanding
Study of GCC APIs
-
Using GCC version 4.6.3
- Extensive study done to gain familiarity with GCC
Application Programming Interface for pass implementation
using GCC source code, GCC Internals Documentation
and other online resources. - What helped:
Plugin Implementation
- Simple Algorithm for GVN
-
For GCC version 4.6.3
- Focused on verifying correctness and completeness
without regard to efficiency in the first attempt. - Current implementation handles only linear code.
- Pass applied after cfg pass.
- Expression pools at all program points are maintained in
a custom data structure and transfer function applied over
them iteratively.
Test Program

After CFG pass

Dump produced by plugin (1/3)


Dump produced by plugin (2/3)


Dump produced by plugin
(3/3)


Challenges Faced
- GCC is a long running (about 27 years!), production
quality framework, and consists of over 4 millions LOC
spread over more than 35,000 files; which is a fairly
difficult code base to understand.
- Attending the IITB workshop in summer 2012 got
me started.
- The GCC Internals Documentation, although about
700 pages in length, is considered quite sparse in terms
of completeness.
- Getting help over GCC mailing list and GCC dev IRC
channel, however slow in response at times, was
a good experience.
Conclusion
-
Value numbering is studied in detail and multiple
known algorithms for global analysis evaluated for
completeness.
-
Familiarity with functionality of GCC as a compiler
research infrastructure gained including some
understanding of GCC source code.
-
One of the algorithms implemented as a dynamic plugin
for linear code.
-
The complete goals of the project were not met due to
over-optimistic estimate of time required for implementation.
Lack of documentation and some difficulty faced in getting
timely help added to the delay.
Primary References
- VanDrunen, T. J. 2004. Partial redundancy elimination for global value numbering. (Doctoral dissertation, Purdue University)
- Gary A. Kildall. 1973. A unified approach to global program optimization. POPL '73. ACM, 194-206.
- B. Alpern, M. N. Wegman, and F. K. Zadeck. 1988. Detecting equality of variables in programs. POPL '88. ACM, 1-11.
- Rüthing, O., Knoop, J., & Steffen, B. 1999. Detecting equalities of variables: Combining efficiency with precision. Static Analysis, 848-848.
- Karthik Gargi. 2002. A sparse algorithm for predicated global value numbering. PLDI '02. ACM, 45-56.
- Gulwani, S., & Necula, G. 2004. A polynomial-time algorithm for global value numbering. Static Analysis, 703-1020.
- Saleena Nabeezath, Vineeth Paleri. 2013. A Simple Algorithm for Global Value Numbering. arXiv:1303.1880.
Credits
-
Image on Structure of GCC slide:
Compiler Pipeline, GCC Internals Course - November 2007 - Diego Novillo
- Image on Plugin Mechanism in GCC slide:
Essential Abstractions in GCC ’12 – A workshop on GCC Internals by GCC Resource Center, IIT Bombay
Global Value Numbering CSU499 Project Kartik Singhal B090566CS CSED NIT Calicut Monday May 6, 2013
global value numbering
By Kartik Singhal
global value numbering
- 3,704