This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC plugin not executing


ok. This is how the problem got resolved-
The problem was not in the plugin but in the Makefile. My earlier
Makefile looked like this-

#------ MAKE CHANGES TO BASE_DIR : Please put the path to base
directory of your pristine gcc-4.7.2 build -----------#
BASE_DIR = /home/administrator/gccroot

INSTALL = $(BASE_DIR)/install
CC = $(INSTALL)/bin/g++
NEW_PATH = $(BASE_DIR)/gcc-4.7.2/gcc

#----- MAKE CHANGES TO OBJS : Add the name of your test file with
extension .o (say test as test.o) --------#
#-----------------------------
-- Multiple dependent files maybe also
be added ------------------------------#
OBJS = test.o

GCCPLUGINS_DIR:= $(shell $(CC) -print-file-name=plugin)
INCLUDE= -I$(GCCPLUGINS_DIR)/include -I$(NEW_PATH)

FLAGS= -fPIC -O2 -flto -flto-partition=none


%.o : %.c
    $(CC) $(FLAGS) $(INCLUDE) -c $<

plugin.so: testpass.o
    $(CC) $(INCLUDE) $(FLAGS) -shared $^ -o $@

test:  $(OBJS) plugin.so
    $(CC) -o result -flto -flto-partition=none -fplugin=./plugin.so
$(OBJS) -fdump-tree-all -fdump-ipa-all

clean:
    \rm -f plugin.so *~ *.o a.out result*
----
Note that for building "test", there is no "O2" flag because of which
my pass was not executed. Now I have modified the command to be-

test:  $(OBJS) plugin.so
    $(CC) -o result $(FLAGS) -fplugin=./plugin.so $(OBJS)
-fdump-tree-all -fdump-ipa-all

$FLAGS contains "O2". Now my plugin is executed.

On Sun, Jul 14, 2013 at 8:43 PM, Deepak Aggrawal
<deepakkansal1989@gmail.com> wrote:
> Problem Resolved
>
> On Sun, Jul 14, 2013 at 7:43 PM, Deepak Aggrawal
> <deepakkansal1989@gmail.com> wrote:
>> I am trying to add a gimple pass, after "pre"-partial redundancy
>> elimination pass. But when I execute the code below, it does not
>> create file "myfile" and so does not write anything in the file. It
>> seems like the plugin is not executing.
>>
>> Please check where I am wrong in this. Thanks in advance.
>>
>>
>>
>> #include "gcc-plugin.h"
>> #include "config.h"
>> #include "system.h"
>> #include "alloc-pool.h"
>> #include "params.h"
>> #include "ggc.h"
>> #include "coretypes.h"
>> #include "tm.h"
>> #include "tree.h"
>> #include "tree-flow.h"
>> #include "diagnostic.h"
>> #include "tree-pass.h"
>> #include "timevar.h"
>> #include "cgraph.h"
>> #include "gimple.h"
>>
>> int plugin_is_GPL_compatible = 1;
>>
>> static unsigned int  execute_TV_plugin(void)
>> {
>> FILE *fp;
>> FILE *cg;
>> cg = fopen("cgdump","a");
>> fp = fopen("myfile","a");
>> fprintf(fp,"The plugin is executing !!\n");
>> }
>>
>> struct gimple_opt_pass pass_TV =
>> {
>>   {
>>     GIMPLE_PASS,
>>     "TV",                                /* name */
>>     NULL,                                   /* gate */
>>     execute_TV_plugin,                   /* execute */
>>     NULL,                                   /* sub */
>>     NULL,                                   /* next */
>>     0,                                      /* static_pass_number */
>>     TV_INTEGRATION,            /*tv_id*/
>>     0,                       /* properties_required */
>>     0,                                      /* properties_provided */
>>     0,                                      /* properties_destroyed */
>>     0,                                      /* todo_flags_start */
>>     0 /* todo_flags_finish */
>>   }
>> };
>>
>> struct register_pass_info pass_info =
>> {
>>         &(pass_TV.pass),
>>         "pre",
>>         0,
>>         PASS_POS_INSERT_AFTER
>> };
>>
>> int plugin_init(struct plugin_name_args *plugin_info, struct
>> plugin_gcc_version *version)
>> {
>>         register_callback(
>>                 plugin_info->base_name,
>>                 PLUGIN_PASS_MANAGER_SETUP,
>>                 NULL,
>>                 &pass_info);
>>
>>         return 0;
>>
>> }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]