Re: Remove node from cgraph

2013-01-25 Thread Chassin

On 01/24/2013 06:43 AM, Richard Biener wrote:

On Thu, Jan 24, 2013 at 4:46 AM, Chassin chas...@ceis.cujae.edu.cu wrote:

On 01/23/2013 02:37 PM, Richard Biener wrote:

Please keep this on the list.

On Wed, Jan 23, 2013 at 5:52 PM, Chassin chas...@ceis.cujae.edu.cu
wrote:

On 01/23/2013 10:55 AM, Richard Biener wrote:

The callgraph isn't the main data structure to modify here.  You probably
still
have references to the function in the IL via calls for example.  You
probably
want to remove all calls to the cgraph node.

Thanks for the quick replay Sr , do you mean by removing calls the (
edges )
? , but  by using cgraph_remove_node it seams to delete all callee and
callers to that node



01494   cgraph_node_remove_callers (node);
01495   cgraph_node_remove_callees (node);
01496   ipa_remove_all_references (node-ref_list);
01497   ipa_remove_all_refering (node-ref_list);
...


in the dump file in my previous mail it shows that all edges related were
removed , should i remove the reference in the GIMPLE body manually ? how
?

You need to remove the call stmts - they are the main representation
of the edges which
get re-built when needed.  You can iterate over the call statements
via the cgraph node
callers list of edges.  In the cgraph edge structure you'll find a
call_stmt member.  To
remove it you need to switch to the corresponding function (push/pop_cfun,
use
DECL_STRUCT_FUNCTION (edge-caller-decl)) and then remove the stmt via
for example gsi_remove () after initializing an iterator via gsi_for_stmt.

That's not all of the details, you of course have to think of what to
do for other
references to the function (function pointers and later indirect
calls).  You have to
think about what the point is of removing arbitrary calls throughout a
program
of course - I can't see any good reason to do this kind of stuff ;)

Richard.


cheers

--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty

48 Aniversario del Instituto Superior Politécnico José Antonio
Echeverría,
Cujae Una obra de la Revolución Cubana | 2 de diciembre de 1964 |
http://cujae.edu.cu


Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu

Hi Ms.Richard , i am new to gcc , i got confused so by removing the edge i
am really not doing anything !!! cuz if the call stmt still exist , did i
understood right ?
if so then what really the edge represent ??

Callgraph nodes and callgraph edges are a representation of functions
and call statements.  The functions with their statements are the main
representation of the intermediate language ontop of which other
high-level data structures are built.  The functions and their statements
are the representation to change.


, can you provide me a sample
code how to do that ?

No, because it's quite a nonsensical operation so there doesn't exist
an example in GCC itself I can point you to.

Please do not continue to ask me questions privately, but post questions
on the mailing-list.  This way other people can benefit as well from your
questions and answers you get.

Richard.


thnx for your time


--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty



48 Aniversario del Instituto Superior Politecnico Jose Antonio Echeverria,
Cujae
Una obra de la Revolucion Cubana | 2 de diciembre de 1964 |
http://cujae.edu.cu




Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu
Richard thnx for your feedbacks i managed to code the function here i 
provide a sample ,


// This will remove just one call but i think with this we can get 
a start point to manage how to delete all other references

char *in_str=main;
char *to_str=f_1;
struct cgraph_node *in_node = util_get_cgnode_by_name(in_str);
struct cgraph_node *to_node = util_get_cgnode_by_name(to_str);
struct cgraph_edge *edge= 
util_get_cgedge_matches_first_call(in_node,to_node);


push_cfun(DECL_STRUCT_FUNCTION(in_node-decl));
int i=0;
basic_block bb;
gimple_stmt_iterator gsi;
gimple stmt;

// itearte over the basic block in the current function pushed
FOR_EACH_BB(bb)
for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(gsi))
{
stmt = gsi_stmt(gsi);
if(stmt == edge-call_stmt)
{
gsi_remove((gsi), true); // remove the stmt
}
}

cgraph_remove_edge(edge);


Sample  APP calls Before
main - f_1
After
main

--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty



48 Aniversario del Instituto Superior Politecnico Jose Antonio Echeverria, Cujae
Una obra de la Revolucion Cubana | 2 de diciembre de 1964 | http://cujae.edu.cu



Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu


Re: Remove node from cgraph

2013-01-25 Thread Richard Biener
On Fri, Jan 25, 2013 at 8:57 AM, Chassin chas...@ceis.cujae.edu.cu wrote:
 On 01/24/2013 06:43 AM, Richard Biener wrote:

 On Thu, Jan 24, 2013 at 4:46 AM, Chassin chas...@ceis.cujae.edu.cu
 wrote:

 On 01/23/2013 02:37 PM, Richard Biener wrote:

 Please keep this on the list.

 On Wed, Jan 23, 2013 at 5:52 PM, Chassin chas...@ceis.cujae.edu.cu
 wrote:

 On 01/23/2013 10:55 AM, Richard Biener wrote:

 The callgraph isn't the main data structure to modify here.  You
 probably
 still
 have references to the function in the IL via calls for example.  You
 probably
 want to remove all calls to the cgraph node.

 Thanks for the quick replay Sr , do you mean by removing calls the (
 edges )
 ? , but  by using cgraph_remove_node it seams to delete all callee and
 callers to that node


 
 01494   cgraph_node_remove_callers (node);
 01495   cgraph_node_remove_callees (node);
 01496   ipa_remove_all_references (node-ref_list);
 01497   ipa_remove_all_refering (node-ref_list);
 ...


 in the dump file in my previous mail it shows that all edges related
 were
 removed , should i remove the reference in the GIMPLE body manually ?
 how
 ?

 You need to remove the call stmts - they are the main representation
 of the edges which
 get re-built when needed.  You can iterate over the call statements
 via the cgraph node
 callers list of edges.  In the cgraph edge structure you'll find a
 call_stmt member.  To
 remove it you need to switch to the corresponding function
 (push/pop_cfun,
 use
 DECL_STRUCT_FUNCTION (edge-caller-decl)) and then remove the stmt via
 for example gsi_remove () after initializing an iterator via
 gsi_for_stmt.

 That's not all of the details, you of course have to think of what to
 do for other
 references to the function (function pointers and later indirect
 calls).  You have to
 think about what the point is of removing arbitrary calls throughout a
 program
 of course - I can't see any good reason to do this kind of stuff ;)

 Richard.

 cheers

 --
 Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

 Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
 Informatics Engineering Faculty

 48 Aniversario del Instituto Superior Politécnico José Antonio
 Echeverría,
 Cujae Una obra de la Revolución Cubana | 2 de diciembre de 1964 |
 http://cujae.edu.cu


 Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu

 Hi Ms.Richard , i am new to gcc , i got confused so by removing the edge
 i
 am really not doing anything !!! cuz if the call stmt still exist , did i
 understood right ?
 if so then what really the edge represent ??

 Callgraph nodes and callgraph edges are a representation of functions
 and call statements.  The functions with their statements are the main
 representation of the intermediate language ontop of which other
 high-level data structures are built.  The functions and their statements
 are the representation to change.

 , can you provide me a sample
 code how to do that ?

 No, because it's quite a nonsensical operation so there doesn't exist
 an example in GCC itself I can point you to.

 Please do not continue to ask me questions privately, but post questions
 on the mailing-list.  This way other people can benefit as well from your
 questions and answers you get.

 Richard.

 thnx for your time


 --
 Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

 Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
 Informatics Engineering Faculty



 48 Aniversario del Instituto Superior Politecnico Jose Antonio
 Echeverria,
 Cujae
 Una obra de la Revolucion Cubana | 2 de diciembre de 1964 |
 http://cujae.edu.cu




 Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu

 Richard thnx for your feedbacks i managed to code the function here i
 provide a sample ,

 // This will remove just one call but i think with this we can get a
 start point to manage how to delete all other references
 char *in_str=main;
 char *to_str=f_1;
 struct cgraph_node *in_node = util_get_cgnode_by_name(in_str);
 struct cgraph_node *to_node = util_get_cgnode_by_name(to_str);
 struct cgraph_edge *edge=
 util_get_cgedge_matches_first_call(in_node,to_node);

 push_cfun(DECL_STRUCT_FUNCTION(in_node-decl));
 int i=0;
 basic_block bb;
 gimple_stmt_iterator gsi;
 gimple stmt;

 // itearte over the basic block in the current function pushed
 FOR_EACH_BB(bb)
 for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(gsi))
 {
 stmt = gsi_stmt(gsi);
 if(stmt == edge-call_stmt)

The loops can be replaced with

gsi = gsi_for_stmt (edge-call_stmt);

 {
 gsi_remove((gsi), true); // remove the stmt
 }
 }

 cgraph_remove_edge(edge);


 Sample  APP calls Before
 main - f_1
 After
 main


 --
 Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

 Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
 Informatics Engineering 

Re: Remove node from cgraph

2013-01-25 Thread Chassin

On 01/25/2013 09:21 AM, Richard Biener wrote:

On Fri, Jan 25, 2013 at 8:57 AM, Chassin chas...@ceis.cujae.edu.cu wrote:

On 01/24/2013 06:43 AM, Richard Biener wrote:

On Thu, Jan 24, 2013 at 4:46 AM, Chassin chas...@ceis.cujae.edu.cu
wrote:

On 01/23/2013 02:37 PM, Richard Biener wrote:

Please keep this on the list.

On Wed, Jan 23, 2013 at 5:52 PM, Chassin chas...@ceis.cujae.edu.cu
wrote:

On 01/23/2013 10:55 AM, Richard Biener wrote:

The callgraph isn't the main data structure to modify here.  You
probably
still
have references to the function in the IL via calls for example.  You
probably
want to remove all calls to the cgraph node.

Thanks for the quick replay Sr , do you mean by removing calls the (
edges )
? , but  by using cgraph_remove_node it seams to delete all callee and
callers to that node



01494   cgraph_node_remove_callers (node);
01495   cgraph_node_remove_callees (node);
01496   ipa_remove_all_references (node-ref_list);
01497   ipa_remove_all_refering (node-ref_list);
...


in the dump file in my previous mail it shows that all edges related
were
removed , should i remove the reference in the GIMPLE body manually ?
how
?

You need to remove the call stmts - they are the main representation
of the edges which
get re-built when needed.  You can iterate over the call statements
via the cgraph node
callers list of edges.  In the cgraph edge structure you'll find a
call_stmt member.  To
remove it you need to switch to the corresponding function
(push/pop_cfun,
use
DECL_STRUCT_FUNCTION (edge-caller-decl)) and then remove the stmt via
for example gsi_remove () after initializing an iterator via
gsi_for_stmt.

That's not all of the details, you of course have to think of what to
do for other
references to the function (function pointers and later indirect
calls).  You have to
think about what the point is of removing arbitrary calls throughout a
program
of course - I can't see any good reason to do this kind of stuff ;)

Richard.


cheers

--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty

48 Aniversario del Instituto Superior Politécnico José Antonio
Echeverría,
Cujae Una obra de la Revolución Cubana | 2 de diciembre de 1964 |
http://cujae.edu.cu


Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu

Hi Ms.Richard , i am new to gcc , i got confused so by removing the edge
i
am really not doing anything !!! cuz if the call stmt still exist , did i
understood right ?
if so then what really the edge represent ??

Callgraph nodes and callgraph edges are a representation of functions
and call statements.  The functions with their statements are the main
representation of the intermediate language ontop of which other
high-level data structures are built.  The functions and their statements
are the representation to change.


, can you provide me a sample
code how to do that ?

No, because it's quite a nonsensical operation so there doesn't exist
an example in GCC itself I can point you to.

Please do not continue to ask me questions privately, but post questions
on the mailing-list.  This way other people can benefit as well from your
questions and answers you get.

Richard.


thnx for your time


--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty



48 Aniversario del Instituto Superior Politecnico Jose Antonio
Echeverria,
Cujae
Una obra de la Revolucion Cubana | 2 de diciembre de 1964 |
http://cujae.edu.cu




Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu

Richard thnx for your feedbacks i managed to code the function here i
provide a sample ,

 // This will remove just one call but i think with this we can get a
start point to manage how to delete all other references
 char *in_str=main;
 char *to_str=f_1;
 struct cgraph_node *in_node = util_get_cgnode_by_name(in_str);
 struct cgraph_node *to_node = util_get_cgnode_by_name(to_str);
 struct cgraph_edge *edge=
util_get_cgedge_matches_first_call(in_node,to_node);

 push_cfun(DECL_STRUCT_FUNCTION(in_node-decl));
 int i=0;
 basic_block bb;
 gimple_stmt_iterator gsi;
 gimple stmt;

 // itearte over the basic block in the current function pushed
 FOR_EACH_BB(bb)
 for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(gsi))
 {
 stmt = gsi_stmt(gsi);
 if(stmt == edge-call_stmt)

The loops can be replaced with

 gsi = gsi_for_stmt (edge-call_stmt);


 {
 gsi_remove((gsi), true); // remove the stmt
 }
 }

 cgraph_remove_edge(edge);


 Sample  APP calls Before
 main - f_1
 After
 main


--
Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
Informatics Engineering Faculty



48 Aniversario del Instituto 

Re: Remove node from cgraph

2013-01-23 Thread Richard Biener
On Mon, Jan 21, 2013 at 6:31 AM, Chassin chas...@ceis.cujae.edu.cu wrote:
 Hi ,i am developing a simple plugin that allows me to delete a node from the
 cgraph that match a specific pattern but when i delete the node using
 cgraph_remove_node , it seams to delete it ( by printing the cgraph again it
 doesn't appear ) , but in the compiled file it exist  my plugin is
 attached to PLUGIN_ALL_PASSES_END event . can any one explain why this is
 happening and what should i do to fix this issues ?

The callgraph isn't the main data structure to modify here.  You probably still
have references to the function in the IL via calls for example.  You probably
want to remove all calls to the cgraph node.

Richard.

 Thnx in advance .

 --
 Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

 Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
 Informatics Engineering Faculty



 48 Aniversario del Instituto Superior Politecnico Jose Antonio Echeverria,
 Cujae
 Una obra de la Revolucion Cubana | 2 de diciembre de 1964 |
 http://cujae.edu.cu



 Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu


Re: Remove node from cgraph

2013-01-23 Thread Richard Biener
Please keep this on the list.

On Wed, Jan 23, 2013 at 5:52 PM, Chassin chas...@ceis.cujae.edu.cu wrote:
 On 01/23/2013 10:55 AM, Richard Biener wrote:

 The callgraph isn't the main data structure to modify here.  You probably
 still
 have references to the function in the IL via calls for example.  You
 probably
 want to remove all calls to the cgraph node.

 Thanks for the quick replay Sr , do you mean by removing calls the ( edges )
 ? , but  by using cgraph_remove_node it seams to delete all callee and
 callers to that node


 
 01494   cgraph_node_remove_callers (node);
 01495   cgraph_node_remove_callees (node);
 01496   ipa_remove_all_references (node-ref_list);
 01497   ipa_remove_all_refering (node-ref_list);
 ...


 in the dump file in my previous mail it shows that all edges related were
 removed , should i remove the reference in the GIMPLE body manually ? how ?

You need to remove the call stmts - they are the main representation
of the edges which
get re-built when needed.  You can iterate over the call statements
via the cgraph node
callers list of edges.  In the cgraph edge structure you'll find a
call_stmt member.  To
remove it you need to switch to the corresponding function (push/pop_cfun, use
DECL_STRUCT_FUNCTION (edge-caller-decl)) and then remove the stmt via
for example gsi_remove () after initializing an iterator via gsi_for_stmt.

That's not all of the details, you of course have to think of what to
do for other
references to the function (function pointers and later indirect
calls).  You have to
think about what the point is of removing arbitrary calls throughout a program
of course - I can't see any good reason to do this kind of stuff ;)

Richard.


 cheers

 --
 Chaddy Huussin Vazquez , chas...@ceis.cujae.edu.cu

 Superior Polytechnic Institute ‘Jose Antonio Echeverrıa’
 Informatics Engineering Faculty

 48 Aniversario del Instituto Superior Politécnico José Antonio Echeverría,
 Cujae Una obra de la Revolución Cubana | 2 de diciembre de 1964 |
 http://cujae.edu.cu


 Consulte la enciclopedia colaborativa cubana. http://www.ecured.cu