Technical Review of peephole Technique in compiler to
…
5 pages
Sign up for access to the world's latest research
Abstract
Peephole optimization is a efficient and easy optimization technique used by compilers sometime called window or peephole is set of code that replace one sequence of instructions by another equivalent set of instructions, but shorter, faster. Peephole optimization is traditionally done through String pattern matching that is using regular expression. There are some the techniques of peephole optimization like constant folding, Strength reduction, null sequences, combine operation, algebraic laws, special case instructions, address mode operations.
Key takeaways
AI
AI
- Peephole optimization reduces redundant instruction sequences, enhancing compiler efficiency.
- Median saving of 16% in EM instruction counts indicates significant optimization effectiveness.
- Peephole optimizers can be universally applied across all languages and machines.
- The optimizer operates at a speed of 1140 EM instructions per CPU second on a PDP-11/45.
- Utilizing pattern matching strategies aids in effective rule application during optimization.
Related papers
ACM SIGPLAN Notices, 2004
This paper describes a system that automatically generates peephole optimizations.
In the perspective of peephole optimization, this paper describes a framework that approaches a collaborative fashion for the pattern matching and replacement strategies on the basis of formal exploration of the pattern matching strategies that have been implemented. In the first section, the framework of this paper is set up: Peephole optimization is observed from an information-processing viewpoint; the distinct components that are involved in this process are presented and formally defined. Then in the next sections the strategically modules are illustrated, which are the different pattern matching, rule application and replacement policies that have been evaluated in this work.
In this paper a generic speci cation for verifying local optimizations on machine code (peephole optimization) using the speci cation and veri cation system PVS is presented. The scheme which provides useful de nitions, basic properties and user-de ned proof strategies abstracts from the specic instruction set of a machine as well as from its semantics. In addition, we formally represent a stack machine as well as a two-address machine. The general scheme is applied to both machines and local optimizations are formalized and veri ed using the de ned proof strategies. This research has been funded in part by the German Research Council (DFG) under project \Veri x"
FME '97: Industrial Applications and Strengthened Foundations of Formal Methods
{ do i d, vhenke, pf e i f er, rues s } 0 inf ormat ik. uni-ulm. de
Undergraduate Topics in Computer Science, 2017
The generation of high-quality code is a key objective in the development of compilers. It is of course true that a usable compiler can be written with little or no provision for optimisation, but the performance of the generated code may be disappointing. Today's production compilers can generate code of outstanding quality, normally much better than even handwritten target assembly code produced by an expert. However, producing this high-quality code using a compiler is not at all easy. The optimisation algorithms used are often complex and costly to run, they interact with each other in unpredictable ways and the choice of which techniques to use for best results will be influenced by the precise structure of the code being optimised. There is no easy solution and an approach to optimisation has to be adopted which works well with the "average" program. Is optimisation important? How hard should a compiler work to produce highly optimised code? The answer depends on the nature of the program being compiled and on the needs of the programmer. For many programs, optimisation is an irrelevance but performing it does no real harm. For other programs resource constraints may mean that optimisation is essential. An argument often heard against the need for optimisation, both by the programmer and by the compiler, is that by waiting for processors to get fast enough the problem will disappear. As the growth in processor speeds seems to be slowing, the wait for sufficiently fast processors may be longer than expected. This makes it increasingly important for both the programmer and the compiler writer to be aware of the importance of optimisation. Before examining practical techniques, it is important to remember that the term optimisation when used in the context of compiler design does not refer to the search for the "best" code. Instead it is concerned with the generation of "better" code. We will return to this issue later in Chap. 8 when covering the topic of superoptimisation. Another related issue is the choice of criteria for code improvement. Are we looking for fast code, small code (in terms of total memory footprint, code size, data usage or some other criterion), code that generates the least i/o traffic, code that minimises power consumption, or what? Some optimisations trade speed improvements against code size and so it is essential to know the real optimisation goal. In most of the techniques described in this chapter, the optimisation goal is to reduce the
Information and Software Technology, 1995
A simple approach to the integration of peephole optimization with retargetable code generation is presented. The method is based on an intermediate code optimizer that is programmable, i.e., driven by user-defined optimization and translation rules. Optimization and translation rules, specified in form of macros, are written in a simple high-level language. Three algorithms, intermediate code optimization, target code generation and target code optimization are unified in a single process, a rule based, pattern matching and replacement algorithm. Three programs implement the method. The first two are used during the development and test phase of the optimization and translation rules. The third program generates, from a tested set of rules, an efficient code optimizer and generator, specialized for a specific target machine, and to be included in a production compiler.
Lecture Notes in Computer Science, 2016
Peephole optimizations optimize and canonicalize code to enable other optimizations but are error-prone. Our prior research on Alive, a domain-specific language for specifying LLVM's peephole optimizations, automatically verifies the correctness of integer-based peephole optimizations and generates C++ code for use within LLVM. This paper proposes Alive-FP, an automated verification framework for floating point based peephole optimizations in LLVM. Alive-FP handles a class of floating point optimizations and fast-math optimizations involving signed zeros, not-a-number, and infinities, which do not result in loss of accuracy. This paper provides multiple encodings for various floating point operations to account for the various kinds of undefined behavior and under-specification in the LLVM's language reference manual. We have translated all optimizations that belong to this category into Alive-FP. In this process, we have discovered seven wrong optimizations in LLVM.
ACM SIGPLAN Notices, 1992
A complex and time-consuming function of a modern compiler is global optimization. Unlike other functions of a compiler such as parsing and code generation which examine only one statement or one basic block at a time, optimizers are much larger in scope, examining and changing large portions of a program all at once. The larger scope means optimizers must perform many program transformations. Each of these transformations makes its own particular demands on the internal representation of programs; each can interact with and depend on the others in different ways. This makes optimizers large and complex. Despite their complexity, few tools exist to help in building optimizers. This is in stark contrast with other parts of the compiler where years of experience have culminated in tools with which these other parts can be constructed easily. For example, parser generators are used to build front-ends, and peephole optimizers and tree matchers are used to build code generators. This pa...
2011
The use of general descriptive names, registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
References (16)
- McKee man, W. M. (1965) Peephole optimization. CACM 8(7):443-444.
- Lamb, D. A. (1981) Construction of a Peephole Optimizer. Software-Practice & Experience 11(6):639-647
- Fraser, C. W. (1982) Copt, a simple, retargetable peephole optimizer. Software, available at ftp://ftp.cs.princeton.edu/pub/lcc/contrib/ copt.shar (up 24/02/2005).
- Davidson, J. W., Fraser, C. W. (1980) The design and application of a retargetable peephole optimizer. ACM TOPLAS 2(2):191 - 202.
- Fraser, C. W. (1979) A compact, machine-independent peephole optimizer. POPL'79:1-6.
- Tanenbaum, A. S., van Staveren, H., Stevenson, J. W. (1982) Using Peephole Optimization on Intermediate Code. ACM TOPLAS 4(1):21-36.
- Davidson, J. W., Fraser, C. W. (1987) Automatic Inference and Fast Interpretation of Peephole Optimization Rules. Software - Practice & Experience 17(11):801-812.
- Davidson, J. W., Fraser, C. W. (1984) Automatic generation of peephole E optimizations. CC84:111-116.
- Kessler, P. B. (1986) Discovering machine-specific code improvements.CC86:249-254.
- Kessler, R. R. (1984) Peep -An architectural description driven peephole optimizer. CC84:106-110.
- STEEL, T.B., JR. UNCOL: The myth and the fact. Annu. Rev. Autom. Program. 2 (1960), 325-344.
- Warfield, J. W., Bauer, III, H. R. (1988) An Expert System for a Retargetable Peephole Optimizer. ACM SIGPLAN Notices 23(10):123-130.
- Davidson, J. W., Fraser, C. W. (1984) Register allocation and exhaustive peephole optimization. Software -Practice & Experience 14(9):857-865.
- Davidson, J. W., Fraser, C. W. (1984) Register allocation and exhaustive peephole optimization. Software -Practice & Experience 14(9):857-865.
- Aho, A. V., Ganapathi, M., Tjiang, S. W. K. (1989) Code Generation Using Tree Matching and Dynamic Programming. ACM TOPLAS11(4):491-516.
- Fraser, C. W., Wendt, A. L. (1986) Integrating Code Generation and Optimization. Proceedings of the SIGPLAN'86 symposium on Compiler Construction, pp. 242-248.
FAQs
AI
What are the key outcomes of peephole optimization on EM instructions?add
The study reveals a median saving of 16% in EM instructions, eliminating one in six instructions. This efficiency highlights the effectiveness of peephole optimization in reducing redundancies.
How does peephole optimization impact object code size?add
The median reduction in object code size is 14%, closely mirroring EM instruction results. This correlation suggests that EM optimizations significantly reflect in the final object code.
What methodologies were used to evaluate the effects of peephole optimization?add
Two tests were conducted: measuring the count of machine instructions and comparing bytes produced in PDP-11 code. These metrics provide independent measurements of optimization effectiveness across varying conditions.
Which pattern matching strategies were analyzed in the peephole optimization technique?add
The research implemented both a declarative, regular expressions-based and a generic object-oriented matching strategy. These strategies facilitated varying degrees of optimization based on rule application and ordering.
What is the speed performance of the peephole optimizer on the PDP-11/45?add
The optimizer processes 1140 EM instructions per CPU second, excluding overhead. This performance can be improved further with optimizations like hashing the pattern table.
Ankit Faldu