Project Stage 2 - part 2 : Clone-Pruning Analysis Pass

Intro

In Project Stage 2, we are going to add a Pass to gcc compiler. Then, we will compile a code and see it generates a dump file that we added a pass for.


Progress

Let's start with adding a Pass to GCC compiler. 


1. Open passes.def file in ~/project/gcc/gcc folder

vi passes.def



2. You will See the codes as followings. Then, add a pass NEXT_PASS (pass_ctyler); in line 444

440 NEXT_PASS (pass_cleanup_eh);
441 NEXT_PASS (pass_musttail);
442 NEXT_PASS (pass_lower_resx);
443 NEXT_PASS (pass_nrv);
444 NEXT_PASS (pass_ctyler);
# Add your pass here
# If you change the location, the order of compilation is changed; and it might have problem.
# Since `pass_ctyler` is similar to `pass_nrv` I think it's safe to put here
445 NEXT_PASS (pass_gimple_isel);
446 NEXT_PASS (pass_harden_conditional_branches);
447 NEXT_PASS (pass_harden_compares);
448 NEXT_PASS (pass_warn_access, /*early=*/false);
449 NEXT_PASS (pass_cleanup_cfg_post_optimizing);
450 NEXT_PASS (pass_warn_function_noreturn);


3. Open tree-pass.h file in ~/project/gcc/gcc folder

vi tree-pass.h

You will see the following codes. Add extern gimple_opt_pass *make_pass_ctyler (gcc::context *ctxt);
 487	extern gimple_opt_pass *make_pass_nothrow (gcc::context *ctxt);
 488	extern gimple_opt_pass *make_pass_tracer (gcc::context *ctxt);
 489	extern gimple_opt_pass *make_pass_warn_restrict (gcc::context *ctxt);
 490	extern gimple_opt_pass *make_pass_warn_unused_result (gcc::context *ctxt);
 491	extern gimple_opt_pass *make_pass_ctyler (gcc::context *ctxt);
 492	extern gimple_opt_pass *make_pass_diagnose_tm_blocks (gcc::context *ctxt);
 493	extern gimple_opt_pass *make_pass_lower_tm (gcc::context *ctxt);
 494	extern gimple_opt_pass *make_pass_tm_init (gcc::context *ctxt);
 495	extern gimple_opt_pass *make_pass_tm_mark (gcc::context *ctxt);

4. Open tree-pass.h file in `~/project/gcc/gcc`

NEXT_PASS (pass_ctyler);


5. Copy the provided pass implementation file tree-ctyler.cc into ~/project/gcc/gcc folder

This file is the implementation file.

cp ~/spo600/gcc/tree-ctyler.cc .


6. Add tree-ctyler.o \  to the OBJS definition Makefile.in file  

  1373 OBJS = \
  
  ...
  
  1715		tree-call-cdce.o \
  1716		tree-cfg.o \
  1717		tree-cfgcleanup.o \
  1718		tree-chrec.o \
  1719		tree-complex.o \
  1720		tree-ctyler.o \
  1721		tree-data-ref.o \
  1722		tree-dfa.o \
  1723		tree-diagnostic.o \
  1724		tree-diagnostic-client-data-hooks.o \
  1725		tree-dump.o \

7. Rebuild the GCC and Install it

cd ~/project/gcc-build-001 time make -j 24 |& tee build.log make install

8. Compile your code with the revised GCC

The following steps wil be continued in the next post

Thank you for reading.


Comments

popular posts in this blog

Project Stage 2 part 4 - Testing clone-test-core.c file with Modified GCC file and making further modification

Project Stage 2 part 3 - Compile a program with revised GCC