This is part one of a series “Writing a GCC back end”.
The GCC back end is configured in
The back end places some functionality in
gcc/config.host and the implementation is placed in directories machine under gcc/config and gcc/common/config where “machine” is the name of the back end (for example, i386 for the x86 architecture).The back end places some functionality in
libgcc. For example, architectures that do not have an instruction for integer division will instead generate a call to a function __divsi3 in libgcc. libgcc is configured in libgcc/config.host and target-specific files are located in a directory machine under libgcc/config.gcc/config.gcc
config.gcc is a shell script that parses the target string (e.g. x86_64-linux-gnu) and sets variables pointing out where to find the rest of the back end and how to compile it. The variables that can be set are documented at the top of the config.gcc file.The only variable that must be set is
cpu_type that specifies machine. Most targets also set extra_objs that specifies extra object files that should be linked into the compiler, tmake_file that contains makefile fragments that compiles those extra objects (or sets makefile variables modifying the build), and tm_file that adds header files containing target-specific information.A typical configuration for a simple target (such as
ft32-unknown-elf) looks something likecpu_type=ft32
tm_file="dbxelf.h elfos.h newlib-stdint.h ${tm_file}"
gcc/config/machine
The main part of the back end is located in
gcc/config/machine. It consists of eight different components, each implemented in a separate file:machine.his included all over the compiler and contains macros defining properties of the target, such as the size of integers and pointers, number of registers, data alignment rules, etc.- GCC implements a generic backend where
machine.ccan override most of the functionality. The backend is written in C,1 so the virtual functions are handled manually with function pointers in a structure, andmachine.coverrides the defaults using code of the form#undef TARGET_FRAME_POINTER_REQUIRED #define TARGET_FRAME_POINTER_REQUIRED ft32_frame_pointer_required static bool ft32_frame_pointer_required (void) { return cfun->calls_alloca; }
machine-protos.hcontains prototypes for the external functions defined inmachine.c.machine.optadds target-specific command-line options to the compiler using a record format specifying the option name, properties, and a documentation string for the--helpoutput. For example,
msmall-data-limit= Target Joined Separate UInteger Var(g_switch_value) Init(8) -msmall-data-limit=N Put global and static data smaller than <number> bytes into a special section.
adds a command-line option machine.md,predicates.md, andconstraints.mdcontain the machine description consisting of rules for instruction selection and register allocation, pipeline description, and peephole optimizations. These will be covered in detail in parts 3–7 of this series.machine-modes.defdefines extra machine modes for use in the low-level IR (a “machine mode” in the GCC terminology defines the size and representation of a data object. That is, it is a data type.). This is typically used for condition codes and vectors.
-msmall-data-limit that has a default value 8, and is generated as an unsigned variable named g_switch_value.
.opt files by setting extra_options in config.gcc.gcc/common/config/machine
The
Many back ends do not need to do anything here, and this file can be disabled by setting
gcc/common/config/machine directory contains a file machine-common.c that can add/remove optimization passes, change the defaults for --param values, etc.Many back ends do not need to do anything here, and this file can be disabled by setting
target_has_targetm_common=noin
config.gcc.libgcc/config.host
The libgcc
The only variable that must be set is
A typical configuration for a simple target looks something like
1. GCC is written in C++03 these days, but the structure has not been changed since it was written in C.
config.host works in the same way as config.gcc, but with different variables.The only variable that must be set is
cpu_type that specifies machine. Most targets also set extra_parts that specifies extra object files to include in the library and tmake_file that contains makefile fragments that add extra functionality (such as soft-float support).A typical configuration for a simple target looks something like
cpu_type=ft32 tmake_file="$tmake_file t-softfp" extra_parts="$extra_parts crti.o crtn.o crtbegin.o crtend.o"
libgcc/config/machine
Thelibgcc/config/machine directory contains extra files that may be needed for the target architecture. Simple implementations typically only contain a crti.S and crtn.S (crtbegin/crtend and the makefile support for building all of these have default implementation) and a file sfp-machine.h containing defaults for the soft-float implementation.1. GCC is written in C++03 these days, but the structure has not been changed since it was written in C.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.