GCC Control Flow and Plugins

Similar documents
Motivation. GCC Control Flow and Plugins. Outline. Essential Abstractions in GCC. Module Binding Mechanisms. Part 1. GCC Resource Center.

Plugin Mechanisms in GCC

The Design and Implementation of Gnu Compiler Collection

GCC Internals: A Conceptual View Part II

The Design and Implementation of Gnu Compiler Collection

GCC The Implementation

Introduction to Machine Descriptions

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

specrtl: A Language for GCC Machine Descriptions

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

Advanced Programming & C++ Language

About These Slides. GDFA: Generic Data Flow Analyser for GCC. Part 1. Copyright. Outline. Uday Khedker

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

First Level Gray Box Probing

Introduction and Opening Remarks

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

The Phasewise File Groups of GCC

Retargeting GCC to Spim: A Recap

LECTURE 3. Compiler Phases

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Computers Programming Course 5. Iulian Năstac

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi

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

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Final CSE 131B Spring 2004

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Pass-by-Pointer. Advanced Pointer Ideas. Pointers are also used in C to enable a function to modify a variable held by the caller:

A simple tutorial on generating PTX assembler out of Ada source code using LLVM NVPTX backend

Chapter 11 Introduction to Programming in C

An Overview of Compilation

Chapter 11 Introduction to Programming in C

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Lecture 2. Xiaoguang Wang. January 16th, 2014 STAT 598W. (STAT 598W) Lecture 2 1 / 41

Lectures 5-6: Introduction to C

Extension of GCC with a fully manageable reverse engineering front end

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Compilers Project 3: Semantic Analyzer

M2 Instruction Set Architecture

Program Translation. text. text. binary. binary. C program (p1.c) Compiler (gcc -S) Asm code (p1.s) Assembler (gcc or as) Object code (p1.

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

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2012

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Chapter 11 Introduction to Programming in C

Page 1. Agenda. Programming Languages. C Compilation Process

Using GCC as a Research Compiler

C - Basics, Bitwise Operator. Zhaoguo Wang

The C Preprocessor (and more)!

Introduction to the C Programming Language

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

C Programming Review CSC 4320/6320

Lectures 5-6: Introduction to C

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

QUIZ. What are 3 differences between C and C++ const variables?

2 Compiling a C program


Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Code Structure Visualization

CS5363 Final Review. cs5363 1

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

An Architectural Overview of GCC

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

nftables switchdev support

Incremental Machine Descriptions for GCC

CS2141 Software Development using C/C++ C++ Basics

Stream Computing using Brook+

Program Translation. text. text. binary. binary. C program (p1.c) Compiler (gcc -S) Asm code (p1.s) Assembler (gcc or as) Object code (p1.

The GNU Compiler Collection

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

The SGI Pro64 Compiler Infrastructure - A Tutorial

Type Checking. Chapter 6, Section 6.3, 6.5

6.096 Introduction to C++ January (IAP) 2009

Review of the C Programming Language

The structure of a compiler

Chapter 1 INTRODUCTION

GCC Plugins Die by the Sword

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

Assembler Programming. Lecture 10

Chapter 11 Introduction to Programming in C

Undergraduate Compilers in a Day

Chapter 11 Introduction to Programming in C

6. Pointers, Structs, and Arrays. 1. Juli 2011

Instantiation of Template class

Welcome to CSE131b: Compiler Construction

Generic Programming in C

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Computational Physics Operating systems

Pioneering Compiler Design

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

ENERGY 211 / CME 211. Evolution

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Syntax-Directed Translation. Lecture 14

Data and File Structures Laboratory

CSE 307: Principles of Programming Languages

Transcription:

Workshop on GCC Control Flow and Plugins GCC Resource Center (www.cse.iitb.ac.in/grc) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay July 2010

July 2010 Plugins: Outline 1/22 Outline Motivation Plugins in GCC GCC Control Flow Conclusions

Part 1 Motivation

July 2010 Plugins: Motivation 2/22 Walking the Maze of a Large Code Base Use cscope cd $SOURCE cscope -R Use ctags cd $SOURCE ctags -R Make sure you use exeburant-ctags

July 2010 Plugins: Motivation 3/22 The Role of Plugins in Large Software A plugin is neither a stub nor a driver A plugin allows plugging in new modules without making changes at many places Most often a plugin in a C based software is a data structure containing function pointers and other related information The terms plugin and hook are used interchangeably

July 2010 Plugins: Motivation 4/22 Plugins in the GCC Driver Source Program cc1 cpp gcc as glibc/newlib ld Target Program

July 2010 Plugins: Motivation 4/22 Plugins in the GCC Driver Source Program cc1 cpp gcc as Plugin for a translator in the driver gcc glibc/newlib ld Target Program

July 2010 Plugins: Motivation 5/22 Plugins in the Generated Compiler Input Language Compiler Generation Framework Target Name Language Specific Code Language and Machine Independent Generic Code Machine Dependent Generator Code Machine Descriptions Selected Copied Copied Generated Generated Parser Gimplifier Source Program Tree SSA Optimizer RTL Generator Generated Compiler (cc1) Optimizer Code Generator Assembly Program

July 2010 Plugins: Motivation 5/22 Plugins in the Generated Compiler Input Language Compiler Generation Framework Target Name Language Specific Code Language and Machine Independent Generic Code Machine Dependent Generator Code Machine Descriptions Selected Plugin for Copied a language front end in cc1 Copied Generated Generated Parser Gimplifier Source Program Tree SSA Optimizer RTL Generator Generated Compiler (cc1) Optimizer Code Generator Assembly Program

July 2010 Plugins: Motivation 5/22 Plugins in the Generated Compiler Input Language Compiler Generation Framework Target Name Language Specific Code Language and Machine Independent Generic Code Machine Dependent Generator Code Machine Descriptions Selected Plugin for Copied a Plugin for language front adding passes end in cc1 Copied in cc1 Generated Generated Parser Gimplifier Source Program Tree SSA Optimizer RTL Generator Generated Compiler (cc1) Optimizer Code Generator Assembly Program

July 2010 Plugins: Motivation 5/22 Plugins in the Generated Compiler Input Language Compiler Generation Framework Target Name Language Specific Code Language and Machine Independent Generic Code Machine Dependent Generator Code Machine Descriptions Selected Plugin for Copied a Plugin for language front adding passes end in cc1 Copied in cc1 Generated Generated Plugin for code generator in cc1 Parser Gimplifier Source Program Tree SSA Optimizer RTL Generator Generated Compiler (cc1) Optimizer Code Generator Assembly Program

Part 2 GCC Plugins

July 2010 Plugins: GCC Plugins 6/22 GCC s Solution Plugin Implementation Data Structure Initialization Translator in gcc Array of C structures Development time Front end in cc1 C structure Build time Passes in cc1 Linked list of C structures Development time Back end in cc1 Arrays of structures Build time

July 2010 Plugins: GCC Plugins 7/22 Plugin Data Structure in the GCC Driver struct compiler { const char *suffix; /* Use this compiler for input files whose names end in this suffix. */ const char *spec; /* To use this compiler, run this spec. * const char *cpp_spec; /* If non-null, substitute this spec for %C, rather than the usual cpp_spec. */ const int combinable; /* If nonzero, compiler can deal with multiple source files at once (IMA). const int needs_preprocessing; /* If nonzero, source files need to be run through a preprocessor. */ };

July 2010 Plugins: GCC Plugins 8/22 Populated Plugin Data Structure in the GCC Driver All entries of Objective C/C++ and some entries of Fortran removed. static const struct compiler default_compilers[] = { {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0}, {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, {".c", "@c", 0, 1, 1}, {".h", "@c-header", 0, 0, 0}, {".i", "@cpp-output", 0, 1, 0}, {".s", "@assembler", 0, 1, 0} }

July 2010 Plugins: GCC Plugins 8/22 Populated Plugin Data Structure in the GCC Driver All entries of Objective C/C++ and some entries of Fortran removed. static const struct compiler default_compilers[] = { {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, What about linker files? {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0}, {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, {".c", "@c", 0, 1, 1}, {".h", "@c-header", 0, 0, 0}, {".i", "@cpp-output", 0, 1, 0}, {".s", "@assembler", 0, 1, 0} }

July 2010 Plugins: GCC Plugins 8/22 Populated Plugin Data Structure in the GCC Driver All entries of Objective C/C++ and some entries of Fortran removed. static const struct compiler default_compilers[] = { {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, What about linker files? {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, {".ads", "#Ada", 0, 0, 0}, Linking is {".adb", the last step "#Ada", 0, 0, 0}, {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, {".c", "@c", 0, 1, 1}, {".h", "@c-header", 0, 0, 0}, {".i", "@cpp-output", 0, 1, 0}, {".s", "@assembler", 0, 1, 0} }

July 2010 Plugins: GCC Plugins 8/22 Populated Plugin Data Structure in the GCC Driver All entries of Objective C/C++ and some entries of Fortran removed. static const struct compiler default_compilers[] = { {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, What about linker files? {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, {".ads", "#Ada", 0, 0, 0}, Linking is {".adb", the last step "#Ada", 0, 0, 0}, {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, Every file is passed on to {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, linker unless it is suppressed {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0}, {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0}, {".c", "@c", 0, 1, 1}, {".h", "@c-header", 0, 0, 0}, {".i", "@cpp-output", 0, 1, 0}, {".s", "@assembler", 0, 1, 0} }

July 2010 Plugins: GCC Plugins 8/22 Populated Plugin Data Structure in the GCC Driver All entries of Objective C/C++ and some entries of Fortran removed. static const struct compiler default_compilers[] = { {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0}, {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0}, {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0}, What about linker files? {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0}, {".ads", "#Ada", 0, 0, 0}, Linking is {".adb", the last step "#Ada", 0, 0, 0}, {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0}, Every file is passed on to {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0}, linker unless it is suppressed {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0}, {".p", "#Pascal", 0, 0, 0}, If a translator {".pas", is not"#pascal", found, 0, 0, 0}, {".java", "#Java", 0, 0, 0}, input file{".class", is assumed to"#java", be a 0, 0, 0}, {".c", "@c", 0, 1, 1}, file for linker {".h", "@c-header", 0, 0, 0}, {".i", "@cpp-output", 0, 1, 0}, {".s", "@assembler", 0, 1, 0} }

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager double arrow represents control flow whereas single arrow represents pointer or index pass 1 pass 2 pass expand...... pass n

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager pass 1 pass 2 pass expand pass n...... code for pass 1 code for pass 2 expander code optab table code for pass n

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager langhook... pass 1 code for pass 1 code for language 1 code for language 2 code for language n pass 2 pass expand pass n...... code for pass 2 expander code optab table code for pass n

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager langhook... pass 1 code for pass 1 code for language 1 code for language 2 code for language n pass 2 pass expand pass n...... code for pass 2 expander code optab table code for pass n

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main front end pass manager langhook... pass 1 code for pass 1 code for language 1 code for language 2 code for language n pass 2 pass expand pass n...... code for pass 2 expander code optab table code for pass n

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main langhook... code for language 1 code for language 2 code for language n front end pass 1 pass 2 pass expand pass n pass manager...... code for pass 1 code for pass 2 expander code optab table code for pass n insn data generated code for machine 1 MD n MD 2 MD 1

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main langhook... code for language 1 code for language 2 code for language n front end pass 1 pass 2 pass expand pass n pass manager...... code for pass 1 code for pass 2 expander code optab table code for pass n insn data generated code for machine 2 MD n MD 2 MD 1

July 2010 Plugins: GCC Plugins 9/22 Plugin Structure in cc1 toplev main langhook... code for language 1 code for language 2 code for language n front end pass 1 pass 2 pass expand pass n pass manager...... code for pass 1 code for pass 2 expander code optab table code for pass n insn data generated code for machine n MD n MD 2 MD 1

July 2010 Plugins: GCC Plugins 10/22 Front End Plugin Important fields of struct lang hooks instantiated for C #define LANG_HOOKS_FINISH c_common_finish #define LANG_HOOKS_EXPAND_EXPR c_expand_expr #define LANG_HOOKS_PARSE_FILE c_common_parse_file #define LANG_HOOKS_WRITE_GLOBALS c_write_global_declarations

July 2010 Plugins: GCC Plugins 11/22 Plugins for Intraprocedural Passes struct opt_pass { enum opt_pass_type type; const char *name; bool (*gate) (void); unsigned int (*execute) (void); struct opt_pass *sub; struct opt_pass *next; int static_pass_number; timevar_id_t tv_id; unsigned int properties_required; unsigned int properties_provided; unsigned int properties_destroyed; unsigned int todo_flags_start; unsigned int todo_flags_finish; }; struct gimple_opt_pass { struct opt_pass pass; }; struct rtl_opt_pass { struct opt_pass pass; };

July 2010 Plugins: GCC Plugins 12/22 Plugins for Interprocedural Passes struct ipa_opt_pass_d { struct opt_pass pass; void (*generate_summary) (void); void (*write_summary) (struct cgraph_node_set_def *); void (*read_summary) (void); void (*function_read_summary) (struct cgraph_node *); void (*stmt_fixup) (struct cgraph_node *, gimple *); unsigned int function_transform_todo_flags_start; unsigned int (*function_transform) (struct cgraph_node *); void (*variable_transform) (struct varpool_node *); }; struct simple_ipa_opt_pass { struct opt_pass pass; };

Part 3 GCC Control Flow

July 2010 Plugins: GCC Control Flow 13/22 gcc Driver Control Flow main /* In file gcc.c */ validate_all_switches lookup_compiler do_spec do_spec_2 do_spec_1 /* Get the name of the compiler */ execute pex_init pex_run pex_run_in_environment obj->funcs->exec_child

July 2010 Plugins: GCC Control Flow 13/22 gcc Driver Control Flow main /* In file gcc.c */ validate_all_switches lookup_compiler do_spec Observations do_spec_2 do_spec_1 /* Get the All compilers name of the are invoked compiler by */ this driver execute pex_init pex_run Assembler is also invoked by this driver pex_run_in_environment obj->funcs->exec_child Linker is invoked in the end by default

July 2010 Plugins: GCC Control Flow 14/22 cc1 Top Level Control Flow main /* In file toplev.c */ toplev_main decode_options do_compile compile_file lang_hooks.parse_file => c_common_parse_file lang_hooks.decls.final_write_globals => c_write_global_declarations targetm.asm_out.file_end finalize

July 2010 Plugins: GCC Control Flow 14/22 cc1 Top Level Control Flow main /* In file toplev.c */ toplev_main decode_options do_compile compile_file Observations lang_hooks.parse_file => c_common_parse_file The entire compilation is lang_hooks.decls.final_write_globals => driven by functions specified c_write_global_declarations in language hooks targetm.asm_out.file_end finalize Bad design!

July 2010 Plugins: GCC Control Flow 15/22 cc1 Control Flow: Parsing for C lang_hooks.parse_file => c_common_parse_file c_parse_file c_parser_translation_unit c_parser_external_declaration c_parser_declaration_or_fndef c_parser_declspecs /* parse declarations */ c_parser_compound_statement finish_function /* finish parsing */ c_genericize cgraph_finalize_function /* finalize AST of a function */

July 2010 Plugins: GCC Control Flow 15/22 cc1 Control Flow: Parsing for C lang_hooks.parse_file => c_common_parse_file c_parse_file c_parser_translation_unit c_parser_external_declaration Observations c_parser_declaration_or_fndef c_parser_declspecs GCC has moved /* parse to a declarations */ c_parser_compound_statement recursive descent parser from finish_function version 4.1.0 /* finish parsing */ c_genericize Earlier parser was generated cgraph_finalize_function using Bison specification /* finalize AST of a function */

July 2010 Plugins: GCC Control Flow 16/22 cc1 Control Flow: Lowering Passes for C lang_hooks.decls.final_write_globals => c_write_global_declarations cgraph_finalize_compilation_unit cgraph_analyze_functions /* Create GIMPLE */ cgraph_analyze_function gimplify_function_tree gimplify_body gimplify_stmt gimplify_expr cgraph_lower_function /* Intraprocedural */ tree_lowering_passes execute_pass_list (all_lowering_passes)

July 2010 Plugins: GCC Control Flow 16/22 cc1 Control Flow: Lowering Passes for C lang_hooks.decls.final_write_globals => c_write_global_declarations cgraph_finalize_compilation_unit cgraph_analyze_functions /* Create GIMPLE */ Observations cgraph_analyze_function gimplify_function_tree Lowering passes are language gimplify_body independent gimplify_stmt Yet they are being called gimplify_expr from a function in language cgraph_lower_function /* Intraprocedural */ hooks tree_lowering_passes execute_pass_list Bad design! (all_lowering_passes)

July 2010 Plugins: GCC Control Flow 17/22 cc1 Control Flow: Optimization and Code Generation Passes lang_hooks.decls.final_write_globals => c_write_global_declarations cgraph_finalize_compilation_unit cgraph_analyze_function /* Create GIMPLE */ cgraph_optimize ipa_passes cgraph_expand_all_functions cgraph_expand_function /* Intraprocedural passes on GIMPLE, */ /* expansion pass, and passes on RTL. */ tree_rest_of_compilation execute_pass_list (&all_passes)

July 2010 Plugins: GCC Control Flow 17/22 cc1 Control Flow: Optimization and Code Generation Passes lang_hooks.decls.final_write_globals => c_write_global_declarations cgraph_finalize_compilation_unit cgraph_analyze_function Observations /* Create GIMPLE */ cgraph_optimize Optimization and code ipa_passes generation passes are cgraph_expand_all_functions language independent cgraph_expand_function /* Intraprocedural Yet theypasses are beingon called GIMPLE, */ /* expansionfrom pass, a function and passes in language on RTL. */ tree_rest_of_compilation hooks execute_pass_list (&all_passes) Bad design!

July 2010 Plugins: GCC Control Flow 18/22 Organization of Passes Order Task IR Level Pass data structure 1 Lowering GIMPLE Intraproc. struct gimple opt pass 2 Optimizations GIMPLE Interproc. struct ipa opt pass 3 Optimizations GIMPLE Intraproc. struct gimple opt pass 4 RTL Generation GIMPLE Intraproc. struct rtl opt pass 5 Optimization RTL Intraproc. struct rtl opt pass

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 19/22 Execution Order in Intraprocedural Passes Function 1 Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 20/22 Execution Order in Interprocedural Passes Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Function 1 Function 2 Function 3 Function 4 Function 5

July 2010 Plugins: GCC Control Flow 21/22 cc1 Control Flow: GIMPLE to RTL Expansion (pass expand) gimple_expand_cfg expand_gimple_basic_block(bb) expand_gimple_cond(stmt) expand_gimple_stmt(stmt) expand_gimple_stmt_1 (stmt) expand_expr_real_2 expand_expr /* Operands */ expand_expr_real optab_for_tree_code expand_binop /* Now we have rtx for operands */ expand_binop_directly /* The plugin for a machine */ code=optab_handler(binoptab,mode)->insn_code; GEN_FCN emit_insn

Part 4 Conclusions

July 2010 Plugins: Conclusions 22/22 Conclusions Excellent mechanism of plugging in different translators in the main driver front ends, passes, and back ends in the main compiler However, the plugins have been used in an adhoc manner