一、前言
本篇只介绍一下框架,就不具体介绍每个步骤了。
二、Pass框架
上一篇已经讲了gcc的中间语言的表现形式。gcc 对中间语言的每一步处理叫做一个pass。从一个函数的GENERIC树刚被转换为GIMPLE之后,接下来的工作就由一连串的pass来完成。这些pass环环相扣,最终完成整个程序的优化工作,为目标代码生成做最后的准备。
GCC的pass结构定义在gcc/tree-pass.h头文件中:
/* Optimization pass type. */
enum opt_pass_type // 四种pass类型对应的枚举
{
GIMPLE_PASS,
RTL_PASS,
SIMPLE_IPA_PASS,
IPA_PASS
};
/* Describe one pass; this is the common part shared across different pass
types. */
struct opt_pass // pass的基本结构
{
/* Optimization pass type. */
enum opt_pass_type type;
/* Terse name of the pass used as a fragment of the dump file
name. If the name starts with a star, no dump happens. */
const char *name; // pass名字
/* If non-null, this pass and all sub-passes are executed only if
the function returns true. */
bool (*gate) (void); // 是否应该执行此pass?
/* This is the code to run. If null, then there should be sub-passes
otherwise this pass does nothing. The return value contains
TODOs to execute in addition to those in TODO_flags_finish. */
unsigned int (*execute) (void); // 执行此pass!
/* A list of sub-passes to run, dependent on gate predicate. */
struct opt_pass *sub; // 子pass。如果此pass被关闭,子pass也被一起关闭。
/* Next in the list of passes to run, independent of gate predicate. */
struct opt_pass *next; // 后面的pass。
/* Static pass number, used as a fragment of the dump file name. */
int static_pass_number; // 一个唯一的pass号
/* The timevar id associated with this pass. */
/* ??? Ideally would be dynamically assigned. */
timevar_id_t tv_id; // 一个唯一的ID。
/* Sets of properties input and output from this pass. */
unsigned int properties_required; // 这些是要被检查的property
unsigned int properties_provided;
unsigned int properties_destroyed;
/* Flags indicating common sets things to do before and after. */
unsigned int todo_flags_start; // 这些是在执行此pass之前/之后的附加动作
unsigned int todo_flags_finish;
};</