An Architectural Overview of GCC

Similar documents
GCC An Architectural Overview

Using GCC as a Research Compiler

The GNU Compiler Collection

GCC Internals Alias analysis

A Propagation Engine for GCC

GCC Internals Control and data flow support

Design and Implementation of Tree SSA

Intermediate Code & Local Optimizations

GCC Developers Summit Ottawa, Canada, June 2006

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

OpenMP 4.0 implementation in GCC. Jakub Jelínek Consulting Engineer, Platform Tools Engineering, Red Hat

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

CS 406/534 Compiler Construction Putting It All Together

Usually, target code is semantically equivalent to source code, but not always!

Extension of GCC with a fully manageable reverse engineering front end

Intermediate Representations

The Design and Implementation of Gnu Compiler Collection

Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world.

CSE 401/M501 Compilers

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Intermediate Code Generation

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Intermediate Representation (IR)

Principles of Compiler Design

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment

CS553 Lecture Dynamic Optimizations 2

Compiler Optimization

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

GCC Internals: A Conceptual View Part II

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Alternatives for semantic processing

GCC Internals. Diego Novillo Red Hat Canada. CGO 2007 San Jose, California March 2007

Introduction to Code Optimization. Lecture 36: Local Optimization. Basic Blocks. Basic-Block Example

Appendix A The DL Language

Compiler Construction: LLVMlite

INTRODUCTION TO LLVM Bo Wang SA 2016 Fall

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Why Global Dataflow Analysis?

Code Merge. Flow Analysis. bookkeeping

Review. Pat Morin COMP 3002

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

Intermediate Representations

SSA Construction. Daniel Grund & Sebastian Hack. CC Winter Term 09/10. Saarland University

Intermediate representation

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

CS5363 Final Review. cs5363 1

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

USC 227 Office hours: 3-4 Monday and Wednesday CS553 Lecture 1 Introduction 4

Accelerating Ruby with LLVM

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Intermediate Representations

Alias Analysis for Intermediate Code

Other Forms of Intermediate Code. Local Optimizations. Lecture 34

Administrative. Other Forms of Intermediate Code. Local Optimizations. Lecture 34. Code Generation Summary. Why Intermediate Languages?

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

1 Lexical Considerations

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

Alias Analysis for Intermediate Code

Intermediate Representations & Symbol Tables

Programming Languages, Summary CSC419; Odelia Schwartz

Register Allocation. CS 502 Lecture 14 11/25/08

OpenACC Course. Office Hour #2 Q&A

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Adding custom instructions to the Simplescalar infrastructure

Incremental Machine Descriptions for GCC

6. Intermediate Representation

An Overview of Compilation

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University

Assignment 11: functions, calling conventions, and the stack

IR Optimization. May 15th, Tuesday, May 14, 13

5. Semantic Analysis!

The structure of a compiler

15-411: LLVM. Jan Hoffmann. Substantial portions courtesy of Deby Katz

Compiler Code Generation COMP360

CS415 Compilers. Intermediate Represeation & Code Generation

CS691/SC791: Parallel & Distributed Computing

Administration. Prerequisites. Meeting times. CS 380C: Advanced Topics in Compilers

Code generation and local optimization

The View from 35,000 Feet

Chapter 1. Preliminaries

Computer Science 160 Translation of Programming Languages

Short Notes of CS201

Code generation and local optimization

Lecture 3 Local Optimizations, Intro to SSA

CJT^jL rafting Cm ompiler

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Agenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1

Flow-sensitive Alias Analysis

CS201 - Introduction to Programming Glossary By

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz

CSE 501 Midterm Exam: Sketch of Some Plausible Solutions Winter 1997

Overview of a Compiler

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

Introduction A Tiny Example Language Type Analysis Static Analysis 2009

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

CS A331 Programming Language Concepts

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Transcription:

An Architectural Overview of GCC Diego Novillo dnovillo@redhat.com Red Hat Canada Linux Symposium Ottawa, Canada, July 2006

Topics 1. Overview 2. Development model 3. Compiler infrastructure 4. Intermediate Representation 5. Current status and future work 22/07/06 2

Overview Key strengths Widely popular Freely available almost everywhere Open development model However Large code base (2.2 MLOC) and aging (~15 years) Difficult to maintain and enhance Technically demanding Recent architectural changes bring hope 22/07/06 3

Development Model 22/07/06 4

Development Model Project organization Steering Committee Administrative, political Release Manager Release coordination Maintainers Design, implementation Three main stages (~2 months each) Stage 1 Big disruptive changes. Stage 2 Stabilization, minor features. Stage 3 Bug fixes only (driven by bugzilla, mostly). 22/07/06 5

Development Model Major development is done in branches Design/implementation discussion on public lists Frequent merges from mainline Final contribution into mainline only at stage 1 and approved by maintainers Anyone with SVN access may create a development branch Vendors create own branches from FSF release branches 22/07/06 6

Development Model All contributors must sign FSF copyright release Even if only working on branches Three levels of access Snapshots (weekly) Anonymous SVN Read/write SVN 22/07/06 7

Compiler Infrastructure 22/07/06 8

Source code <src> gcc libcpp libada libstdc++-v3 libgfortran libobjc boehm-gc libffi libjava zlib libiberty libgomp libssp libmudflap libdecnumber Front/middle/back end Pre-processor Ada runtime C++ runtime Fortran runtime Objective-C runtime Java runtime Utility functions and generic data structures OpenMP runtime Stack Smash Protection runtime Pointer/memory check runtime Decimal arithmetic library 22/07/06 9

Compiler pipeline C C++ Java Fortran Front End Middle End Back End GENERIC GIMPLE RTL Assembly Inter Procedural Optimizer RTL Optimizer SSA Optimizer Final Code Generation Call Graph Manager Pass Manager 22/07/06 10

SSA Optimizers Operate on GIMPLE IL Around 100 passes Vectorization Various loop optimizations Traditional scalar optimizations: CCP, DCE, DSE, FRE, PRE, VRP, SRA, jump threading, forward propagation Field-sensitive, points-to alias analysis Pointer checking instrumentation for C/C++ 22/07/06 11

RTL Optimizers Operate closer to the hardware Register allocation Scheduling Software pipelining Common subexpression elimination Instruction recombination Mode switching reduction Peephole optimizations Machine specific reorganization 22/07/06 12

Intermediate Representation 22/07/06 13

GENERIC and GIMPLE GENERIC is a common representation shared by all front ends Parsers may build their own representation for convenience Once parsing is complete, they emit GENERIC GIMPLE is a simplified version of GENERIC 3-address representation Restricted grammar to facilitate the job of optimizers 22/07/06 14

GENERIC and GIMPLE GENERIC High GIMPLE Low GIMPLE if (foo (a + b,c)) c = b++ / a endif return c t1 = a + b t2 = foo (t1, c) if (t2!= 0) t3 = b b = b + 1 c = t3 / a endif return c t1 = a + b t2 = foo (t1, c) if (t2!= 0) <L1,L2> L1: t3 = b b = b + 1 c = t3 / a goto L3 L2: L3: return c 22/07/06 15

GIMPLE No hidden/implicit side-effects Simplified control flow Loops represented with if/goto Lexical scopes removed (low-gimple) Locals of scalar types are treated as registers (real operands) Globals, aliased variables and non-scalar types treated as memory (virtual operands) 22/07/06 16

GIMPLE At most one memory load/store operation per statement Memory loads only on RHS of assignments Stores only on LHS of assignments Can be incrementally lowered (2 levels currently) 22/07/06 17

SSA Form Static Single Assignment (SSA) Versioning representation to expose data flow explicitly Assignments generate new versions of symbols Convergence of multiple versions generates new one (Φ functions) a 1 = 3 b 2 = 9 if (i 3 > 20) a 3 = a 1 2 b 4 = b 2 + a 3 a 5 = a 1 + 1 a 6 = Φ(a 3, a 5 ) b 7 = Φ(b 4, b 2 ) c 8 = a 6 + b 7 22/07/06 18

SSA Form Rewriting (or standard) SSA form Used for real operands Different names for the same symbol are distinct objects overlapping live ranges (OLR) are allowed if (x 2 > 4) z 5 = x 3 1 Program is taken out of SSA form for RTL generation (new symbols are created to fix OLR) 22/07/06 19

SSA Form Factored Use-Def Chains (FUD Chains) Also known as Virtual SSA Form Used for virtual operands. All names refer to the same object. Optimizers may not produce OLR for virtual operands. 22/07/06 20

RTL Register Transfer Language Assembler for abstract machine with infinite registers b = a - 1 (set (reg/v:si 59 [ b ]) (plus:si (reg/v:si 60 [ a ] (const_int -1 [0xffffffff])))) 22/07/06 21

RTL Abstracts Register classes Memory addressing modes Word sizes and types Compare-and-branch instructions Calling conventions Bitfield operations Type and sign conversions 22/07/06 22

RTL Abstractions defined and controlled in machine description file gcc/config/<arch>/<arch>.md MD file defines all code generation mappings (instruction templates) Target description macros describe hardware capabilities (register classes, calling conventions, type sizes, etc) 22/07/06 23

Current Status and Future Work 22/07/06 24

Current Status New Intermediate Representations decouple Front End and Back End Increased internal modularity Lots of new features Fortran 95, mudflap, vectorizer, OpenMP, inter/intra procedural optimizers, stack protection, profiling, etc. Easier to modify 22/07/06 25

Future Work Static analysis support Extensibility mechanism to allow 3 rd party tools Link time optimizations Write intermediate representation Read and combine multiple compilation units Dynamic compilation Emit bytecodes Implement virtual machine with optimizing JIT 22/07/06 26

Contacts Home page http://gcc.gnu.org/ Wiki http://gcc.gnu.org/wiki Mailing lists gcc@gcc.gnu.org gcc-patches@gcc.gnu.org gcc-help@gcc.gnu.org IRC irc.oft.net/#gcc 22/07/06 27

Additional Implementation Details 22/07/06 28

Statement Operands Real operands Non-aliased, scalar, local variables Atomic references to the whole object GIMPLE registers (may not fit in a physical register) double x, y, z; z = x + y; 22/07/06 29

Statement Operands Virtual operands Globals, aliased, structures, arrays, pointer dereferences. Potential and/or partial references to the object. Distinction becomes important when building SSA form. int x[10] struct A y # x = V_MAY_DEF <x> # VUSE <y> x[3] = y.f 22/07/06 30

Statement Operands Partial, potential and/or aliased stores p = (cond)? &a : &b # a = V_MAY_DEF <a> # b = V_MAY_DEF <b> *p = x + 1 Partial, total and/or aliased loads # VUSE <s> y = s.f 22/07/06 31

Alias Analysis GIMPLE only has single level pointers. Pointer dereferences represented by artificial symbols memory tags (MT). If p points-to x p's tag is aliased with x. # MT = V_MAY_DEF <MT> *p =... Since MT is aliased with x: # x = V_MAY_DEF <x> *p =... 22/07/06 32

Alias Analysis Symbol Memory Tags (SMT) Used in type-based and flow-insensitive points-to analyses. Tags are associated with symbols. Name Memory Tags (NMT) Used in flow-sensitive points-to analysis. Tags are associated with SSA names. Compiler tries to use name tags first. 22/07/06 33

Implementing Optimizations To implement a new pass Create an instance of struct tree_opt_pass Declare it in tree-pass.h Sequence it in init_tree_optimization_passes 22/07/06 34

Implementing Optimizations APIs available for CFG: block/edge insertion, removal, dominance information, block iterators, dominance tree walker. Statements: insertion in block and edge, removal, iterators, replacement. Operands: iterators, replacement. Loop discovery and manipulation. Data dependency information (scalar evolutions framework). 22/07/06 35

Implementing Optimizations Other available infrastructure Debugging dumps (-fdump-tree-...) Timers for profiling passes (-ftime-report) CFG/GIMPLE/SSA verification (--enable-checking) Generic value propagation engine with callbacks for statement and Φ node visits. Generic use-def chain walker. Support in test harness for scanning dump files looking for specific transformations. Pass manager for scheduling passes and describing interdependencies, attributes required and attributes provided. 22/07/06 36