logo资料库

Engineering a Compiler, 2nd Edition.pdf

第1页 / 共825页
第2页 / 共825页
第3页 / 共825页
第4页 / 共825页
第5页 / 共825页
第6页 / 共825页
第7页 / 共825页
第8页 / 共825页
资料共825页,剩余部分请下载后查看
Front Cover
About the Authors
Engineering a Compiler
Copyright
Dedication
About the Cover
Table of Contents
Preface
Chapter 1. Overview of Compilation
1.1 Introduction
1.2 Compiler Structure
1.3 Overview of Translation
1.4 Summary and Perspective
Chapter Notes
Exercises
Chapter 2. Scanners
2.1 Introduction
2.2 Recognizing Words
2.3 Regular Expressions
2.4 From Regular Expression to Scanner
2.5 Implementing Scanners
2.6 Advanced Topics
2.7 Chapter Summary and Perspective
Chapter Notes
Exercises
Chapter 3. Parsers
3.1 Introduction
3.2 Expressing Syntax
3.3 Top-Down Parsing
3.4 Bottom-Up Parsing
3.5 Practical Issues
3.6 Advanced Topics
3.7 Summary and Perspective
Chapter Notes
Exercises
Chapter 4. Context-Sensitive Analysis
4.1 Introduction
4.2 An Introduction to Type Systems
4.3 The Attribute-Grammar Framework
4.4 Ad Hoc Syntax-Directed Translation
4.5 Advanced Topics
4.6 Summary and Perspective
Chapter Notes
Exercises
Chapter 5. Intermediate Representations
5.1 Introduction
5.2 Graphical IRs
5.3 Linear IRs
5.4 Mapping Values to Names
5.5 Symbol Tables
5.6 Summary and Perspective
Chapter Notes
Exercises
Chapter 6. The Procedure Abstraction
6.1 Introduction
6.2 Procedure Calls
6.3 Name Spaces
6.4 Communicating Values Between Procedures
6.5 Standardized Linkages
6.6 Advanced Topics
6.7 Summary and Perspective
Chapter Notes
Exercises
Chapter 7. Code Shape
7.1 Introduction
7.2 Assigning Storage Locations
7.3 Arithmetic Operators
7.4 Boolean and Relational Operators
7.5 Storing and Accessing Arrays
7.6 Character Strings
7.7 Structure References
7.8 Control-Flow Constructs
7.9 Procedure Calls
7.10 Summary and Perspective
Chapter Notes
Exercises
Chapter 8. Introduction to Optimization
8.1 Introduction
8.2 Background
8.3 Scope of Optimization
8.4 Local Optimization
8.5 Regional Optimization
8.6 Global Optimization
8.7 Interprocedural Optimization
8.8 Summary and Perspective
Chapter Notes
Exercises
Chapter 9. Data-Flow Analysis
9.1 Introduction
9.2 Iterative Data-Flow Analysis
9.3 Static Single-Assignment Form
9.4 Interprocedural Analysis
9.5 Advanced Topics
9.6 Summary and Perspective
Chapter Notes
Exercises
Chapter 10. Scalar Optimizations
10.1 Introduction
10.2 Eliminating Useless and Unreachable Code
10.3 Code Motion
10.4 Specialization
10.5 Redundancy Elimination
10.6 Enabling Other Transformations
10.7 Advanced Topics
10.8 Summary and Perspective
Chapter Notes
Exercises
Chapter 11. Instruction Selection
11.1 Introduction
11.2 Code Generation
11.3 Extending the Simple Treewalk Scheme
11.4 Instruction Selection via Tree-Pattern Matching
11.5 Instruction Selection via Peephole Optimization
11.6 Advanced Topics
11.7 Summary and Perspective
Chapter Notes
Exercises
Chapter 12. Instruction Scheduling
12.1 Introduction
12.2 The Instruction-Scheduling Problem
12.3 Local List Scheduling
12.4 Regional Scheduling
12.5 Advanced Topics
12.6 Summary and Perspective
Chapter Notes
Exercises
Chapter 13. Register Allocation
13.1 Introduction
13.2 Background Issues
13.3 Local Register Allocation and Assignment
13.4 Global Register Allocation and Assignment
13.5 Advanced Topics
13.6 Summary and Perspective
Chapter Notes
Exercises
Appendix A. ILOC
A.1 Introduction
A.2 Naming Conventions
A.3 Individual Operations
A.4 Control-Flow Operations
A.5 Representing SSA Form
Appendix B. Data Structures
B.1 Introduction
B.2 Representing Sets
B.3 Implementing Intermediate Representations
B.4 Implementing Hash Tables
B.5 A Flexible Symbol-Table Design
Appendix Notes
Bibliography
Index
In Praise of Engineering a Compiler Second Edition Compilers are a rich area of study, drawing together the whole world of computer science in one, elegant construction. Cooper and Torczon have succeeded in creating a welcoming guide to these software systems, enhancing this new edition with clear lessons and the details you simply must get right, all the while keeping the big picture firmly in view. Engineering a Compiler is an invaluable companion for anyone new to the subject. Michael D. Smith Dean of the Faculty of Arts and Sciences John H. Finley, Jr. Professor of Engineering and Applied Sciences, Harvard University The Second Edition of Engineering a Compiler is an excellent introduction to the construction of modern optimizing compilers. The authors draw from a wealth of experience in compiler construction in order to help students grasp the big picture while at the same time guiding them through many important but subtle details that must be addressed to construct an effec- tive optimizing compiler. In particular, this book contains the best introduction to Static Single Assignment Form that I’ve seen. Jeffery von Ronne Assistant Professor Department of Computer Science The University of Texas at San Antonio Engineering a Compiler increases its value as a textbook with a more regular and consistent structure, and with a host of instructional aids: review questions, extra examples, sidebars, and marginal notes. It also includes a wealth of technical updates, including more on nontraditional languages, real-world compilers, and nontraditional uses of compiler technology. The optimi- zation material—already a signature strength—has become even more accessible and clear. Michael L. Scott Professor Computer Science Department University of Rochester Author of Programming Language Pragmatics Keith Cooper and Linda Torczon present an effective treatment of the history as well as a practitioner’s perspective of how compilers are developed. Theory as well as practical real world examples of existing compilers (i.e. LISP, FORTRAN, etc.) comprise a multitude of effec- tive discussions and illustrations. Full circle discussion of introductory along with advanced “allocation” and “optimization” concepts encompass an effective “life-cycle” of compiler engineering. This text should be on every bookshelf of computer science students as well as professionals involved with compiler engineering and development. David Orleans Nova Southeastern University
This page intentionally left blank
Engineering a Compiler Second Edition
About the Authors Keith D. Cooper is the Doerr Professor of Computational Engineering at Rice University. He has worked on a broad collection of problems in optimization of compiled code, including inter- procedural data-flow analysis and its applications, value numbering, algebraic reassociation, register allocation, and instruction scheduling. His recent work has focused on a fundamental reexamination of the structure and behavior of traditional compilers. He has taught a variety of courses at the undergraduate level, from introductory programming through code optimization at the graduate level. He is a Fellow of the ACM. Linda Torczon, Senior Research Scientist, Department of Computer Science at Rice Uni- versity, is a principal investigator on the Platform-Aware Compilation Environment project (PACE), a DARPA-sponsored project that is developing an optimizing compiler environment which automatically adjusts its optimizations and strategies to new platforms. From 1990 to 2000, Dr. Torczon served as executive director of the Center for Research on Parallel Compu- tation (CRPC), a National Science Foundation Science and Technology Center. She also served as the executive director of HiPerSoft, of the Los Alamos Computer Science Institute, and of the Virtual Grid Application Development Software Project (VGrADS).
Engineering a Compiler Second Edition Keith D. Cooper Linda Torczon Rice University Houston, Texas AMSTERDAM • BOSTON • HEIDELBERG • LONDON SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO NEW YORK • OXFORD • PARIS • SAN DIEGO Morgan Kaufmann Publishers is an imprint of Elsevier
Acquiring Editor: Todd Green Development Editor: Nate McFadden Project Manager: Andre Cuello Designer: Alisa Andreola Cover Image: “The Landing of the Ark,” a vaulted ceiling-design whose iconography was narrated, designed, and drawn by John Outram of John Outram Associates, Architects and City Planners, London, England. To read more visit www.johnoutram.com/rice.html. Morgan Kaufmann is an imprint of Elsevier. 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA Copyright © 2012 Elsevier, Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions. This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein). Notices Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods or professional practices may become necessary. Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information or methods described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility. To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein. Library of Congress Cataloging-in-Publication Data Application submitted British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN: 978-0-12-088478-0 For information on all Morgan Kaufmann publications visit our website at www.mkp.com Printed in the United States of America 11 12 13 14 10 9 8 7 6 5 4 3 2 1
We dedicate this volume to I our parents, who instilled in us the thirst for knowledge and supported us as we developed the skills to follow our quest for knowledge; I our children, who have shown us again how wonderful the process of learning and growing can be; and I our spouses, without whom this book would never have been written.
分享到:
收藏