GCC - 添加ipa pass

关于ipa的介绍和基本使用,在之前的博客中:编译优化之 - 过程间优化(IPA/IPO)入门。这里主要是记录一下gcc-8.2.0版本中新建一个ipa pass的过程。

  1. 进入gcc-8.2.0/gcc目录,新建ipa-test.c文件。代码可参考ipa-*.c那些pass中的过程进行修改,在此参考ipa-hsa.c文件,其代码较少。拷贝头文件到ipa-test.c
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "is-a.h"
#include "hash-set.h"
#include "vec.h"
#include "tree.h"
#include "tree-pass.h"
#include "function.h"
#include "basic-block.h"
#include "gimple.h"
#include "dumpfile.h"
#include "gimple-pretty-print.h"
#include "tree-streamer.h"
#include "stringpool.h"
#include "cgraph.h"
#include "print-tree.h"
#include "symbol-summary.h"
  1. 拷贝namespace中的const pass_data相关信息进行修改:
namespace {

const pass_data pass_data_ipa_test =
{
  IPA_PASS, /* type */
  "ipa-test", /* name */
  OPTGROUP_NONE, /* optinfo_flags */
  TV_IPA_TEST, /* tv_id */ 
  0, /* properties_required */
  0, /* properties_provided */
  0, /* properties_destroyed */
  0, /* todo_flags_start */
  TODO_dump_symtab, /* todo_flags_finish */
};
...
}
  1. 拷贝class pass_ipa_hsa信息进行修改:
class pass_ipa_test : public ipa_opt_pass_d
{
 public:
   pass_ipa_test (gcc::context *ctxt)
     : ipa_opt_pass_d (pass_data_ipa_test, ctxt,
               NULL, /* generate_summary */
               NULL, /* write_summary */
               NULL, /* read_summary */
               NULL, /* write_optimization_summary */
               NULL, /* read_optimization_summary */
               NULL, /* stmt_fixup */
               0, /* function_transform_todo_flags_start */
               NULL, /* function_transform */
               NULL) /* variable_transform */
     {}
 
   /* opt_pass methods: */
   virtual bool gate (function *);
 
   virtual unsigned int execute (function *) { return process_test_functions (); }
 
}; // class pass_ipa_reference
bool
pass_ipa_test::gate (function *)
 {
   return hsa_gen_requested_p ();
 }
 
} // anon namespace
  1. 拷贝make_pass_ipa进行修改并在namespace外添加process_test_functions函数:
static unsigned int
process_test_functions (void)
{
  return 0;
}
...
ipa_opt_pass_d *
make_pass_ipa_test (gcc::context *ctxt)
{
   return new pass_ipa_test (ctxt);
} 

修改完成后代码如下:

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "is-a.h"
#include "hash-set.h"
#include "vec.h"
#include "tree.h"
#include "tree-pass.h"
#include "function.h"
#include "basic-block.h"
#include "gimple.h"
#include "dumpfile.h"
#include "gimple-pretty-print.h"
#include "tree-streamer.h"
#include "stringpool.h"
#include "cgraph.h"
#include "print-tree.h"
#include "symbol-summary.h"

static unsigned int
process_test_functions(void)
{
    return 0;
}
 
namespace {

const pass_data pass_data_ipa_test =
{
    IPA_PASS, /* type */
    "ipa-test", /* name */
    OPTGROUP_NONE, /* optinfo_flags */
    TV_IPA_TEST, /* tv_id */
    0, /* properties_required */
    0, /* properties_provided */
    0, /* properties_destroyed */
    0, /* todo_flags_start */
    TODO_dump_symtab, /* todo_flags_finish */
;

class pass_ipa_test : public ipa_opt_pass_d
{
public:
    pass_ipa_test (gcc::context *ctxt)
        : ipa_opt_pass_d (pass_data_ipa_test, ctxt,
                          NULL, /* generate_summary */
                          NULL, /* write_summary */
                          NULL, /* read_summary */
                          NULL, /* write_optimization_summary */
                          NULL, /* read_optimization_summary */
                           NULL, /* stmt_fixup */
                           0, /* function_transform_todo_flags_start */
                          NULL, /* function_transform */
                          NULL) /* variable_transform */
    {}
 
    /* opt_pass methods: */
    virtual bool gate (function *);

    virtual unsigned int execute (function *) { return process_test_functions (); }

}; // class pass_ipa_referen

 bool
 pass_ipa_test::gate (function *)
 {
    return hsa_gen_requested_p ();
}
 
} // anon namespace
 
ipa_opt_pass_d *
make_pass_ipa_test (gcc::context *ctxt)
{
    return new pass_ipa_test (ctxt);
}
  1. 在gcc/tree-pass.h中添加声明:
extern ipa_opt_pass_d *make_pass_ipa_test (gcc::context *ctxt);
  1. 在gcc/passes.def中新增:
NEXT_PASS (pass_ipa_test);
  1. 在gcc/timevar.def中新增:
DEFTIMEVAR (TV_IPA_TEST,  "load ipa test pass")
  1. 在gcc/Makefile.in中新增ipa-test.c和ipa-test.o
  2. 进行../configure、make、make install即可
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值