Creating parameters for functions calls
Dear all, I want to insert functions calls during a new pass. The problem is to create parameters. At this time, I successfully create a function call with two constante as parameter and insert it (I can see that in the asm's code). But, I want to give the address of an array and a constante to this function. I think the problem is the creation of the node which contains the address of the array. For example: I get from the code (in tree "rhs"): a[i] I want build a node like that: &a[i] and build a function call like that: foo(constante,&a[i]) This is the error message when a try to compile a program with my pass : tab.c: In function 'main': tab.c:7: erreur interne du compilateur: dans lookup_subvars_for_var, à tree-flow-inline.h:1629 This is an extract what I do in my pass: tree new_rhs = build4(TREE_CODE(rhs), TREE_TYPE(rhs), TREE_OPERAND (rhs, 0)?copy_list (TREE_OPERAND (rhs, 0)):NULL_TREE, TREE_OPERAND (rhs, 1)?copy_list (TREE_OPERAND (rhs, 1)):NULL_TREE, TREE_OPERAND (rhs, 2)?copy_list (TREE_OPERAND (rhs, 2)):NULL_TREE, TREE_OPERAND (rhs, 3)?copy_list (TREE_OPERAND (rhs, 3)):NULL_TREE); tree param = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs); tree compteur = build_int_cst (integer_type_node, 1 ); tree args = tree_cons(NULL_TREE,compteur, tree_cons(NULL_TREE, param, NULL_TREE)); tree call_type = build_function_type_list (void_type_node, integer_type_node, ptr_type_node, NULL_TREE); tree call_fn = build_fn_decl ("foo",call_type); tree call = build_function_call_expr (call_fn, args); block_stmt_iterator bsi; bsi = bsi_for_stmt (stmt); bsi_insert_before (&bsi, call, BSI_SAME_STMT); mark_symbols_for_renaming(call); I put that debug_tree() says: ***Debug_KG: Nom de l'arbre: rhs unit size align 32 symtab 0 alias set -1 canonical type 0xb7be32d8 precision 32 min max 0xb7bd2318 2147483647> pointer_to_this > arg 0 type sizes-gimplified BLK size unit size align 32 symtab 0 alias set -1 canonical type 0xb7ca2680 domain pointer_to_this > addressable used BLK file tab.c line 10 size 0xb7ca53c0 32> unit size align 32 context chain used BLK file tab.c line 11 size 32> unit size align 32 context chain >> arg 1 visited var def_stmt version 50>> ***Debug_KG: Nom de l'arbre: new_rhs unit size align 32 symtab 0 alias set -1 canonical type 0xb7be32d8 precision 32 min max 0xb7bd2318 2147483647> pointer_to_this > arg 0 type sizes-gimplified BLK size unit size align 32 symtab 0 alias set -1 canonical type 0xb7ca2680 domain pointer_to_this > addressable used BLK file tab.c line 10 size 0xb7ca53c0 32> unit size align 32 context chain used BLK file tab.c line 11 size 32> unit size align 32 context chain >> arg 1 var def_stmt version 50>> ***Debug_KG: Nom de l'arbre: param unit size align 32 symtab 0 alias set -1 canonical type 0xb7be32d8 precision 32 min max 0xb7bd2318 2147483647> pointer_to_this > arg 0 arg 0 addressable used BLK file tab.c line 10 size unit size align 32 context chain > arg 1 var def_stmt version 50>>> ***Debug_KG: Nom de l'arbre: compteur constant invariant 0> ***Debug_KG: Nom de l'arbre: args unit size align 32 symtab 0 alias set -1 canonical type 0xb7be32d8 precision 32 min max 0xb7bd2318 2147483647> pointer_to_this > arg 0 arg 0 arg 1 var def_stmt version 50>>> chain chain >>> Does the parameter' s construction correct? Thanks for any help in finishing this pass, Antoine
Re: Creating parameters for functions calls
Thx for your answer, But I believe the problem is not the contruction of the parameters of the function, but the construction of the adress of an array and give it at a function call. Maybe, I don't say good my problem in my previous mail. Example: If I have an array A in a source code, I want to create the address of this array and to give it at a function which I have insert: main{ int A[10]; int b; ... ... foo( & A[2]); //This is the statement that I want to insert b=A[2]; ... ... } I make clear that I success in doing: main{ int A; int b; ... ... b=A; foo( & A); ... } How can I to build this statement ? Sorry for my bad english ( if it is not comprehensible, tell it me ! ), Thanks in advance, Antoine
Re: Creating parameters for functions calls
Daniel Berlin wrote: On 3/27/07, Antoine Eiche <[EMAIL PROTECTED]> wrote: Dear all, I want to insert functions calls during a new pass. Which version of GCC? The problem is to create parameters. At this time, I successfully create a function call with two constante as parameter and insert it (I can see that in the asm's code). But, I want to give the address of an array and a constante to this function. I think the problem is the creation of the node which contains the address of the array. For example: I get from the code (in tree "rhs"): a[i] I want build a node like that: &a[i] and build a function call like that: foo(constante,&a[i]) This is the error message when a try to compile a program with my pass : tab.c: In function 'main': tab.c:7: erreur interne du compilateur: dans lookup_subvars_for_var, à tree-flow-inline.h:1629 Can you send a backtrace? This means nothing has created the variable annotation for a. Hi, My version of gcc: version gcc 4.3.0 20070316 (experimental) I try to do a backtrace with gcc but the program exit normally. So, I try to put a breakpoint but : (gdb) b tree-flow-inline.h:1629 No source file named tree-flow-inline.h. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (tree-flow-inline.h:1629) pending. I'm sorry but I can't show you a backtrace. (I do compilation with option "-g") How I can put a breakpoint ?
Re: Creating parameters for functions calls
Daniel Berlin wrote: On 3/30/07, Antoine Eiche <[EMAIL PROTECTED]> wrote: Daniel Berlin wrote: > On 3/27/07, Antoine Eiche <[EMAIL PROTECTED]> wrote: >> Dear all, >> >> I want to insert functions calls during a new pass. > > Which version of GCC? > The problem is to >> create parameters. At this time, I successfully create a function call >> with two constante as parameter and insert it (I can see that in the >> asm's code). But, I want to give the address of an array and a constante >> to this function. >> I think the problem is the creation of the node which contains the >> address of the array. >> >> For example: >> I get from the code (in tree "rhs"): >> a[i] >> I want build a node like that: >> &a[i] >> and build a function call like that: >> foo(constante,&a[i]) >> >> This is the error message when a try to compile a program with my pass : >> >> tab.c: In function 'main': >> tab.c:7: erreur interne du compilateur: dans lookup_subvars_for_var, à >> tree-flow-inline.h:1629 >> > Can you send a backtrace? > > This means nothing has created the variable annotation for a. Hi, My version of gcc: version gcc 4.3.0 20070316 (experimental) I try to do a backtrace with gcc but the program exit normally. So, I try to put a breakpoint but : Are you debugging gcc or cc1? you need to be debugging cc1 (use -v with your compiled gcc to get the cc1 command line it uses, and just run "gdb --args " (gdb) b tree-flow-inline.h:1629 No source file named tree-flow-inline.h. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (tree-flow-inline.h:1629) pending. I'm sorry but I can't show you a backtrace. (I do compilation with option "-g") How I can put a breakpoint ? Hi, It is the backtrace : #0 lookup_subvars_for_var (var=0xb7c3f370) at tree-flow-inline.h:1628 #1 0x085b3cf0 in get_subvars_for_var (var=0xb7c3f370) at tree-flow-inline.h:1646 #2 0x085b3500 in verify_ssa_name (ssa_name=0xb7c47570, is_virtual=1 '\001') at ../.././gcc/tree-ssa.c:139 #3 0x085b619a in verify_ssa (check_modified_stmt=0 '\0') at ../.././gcc/tree-ssa.c:660 #4 0x0854a982 in verify_loop_closed_ssa () at ../.././gcc/tree-ssa-loop-manip.c:430 #5 0x08372213 in execute_function_todo (data=0x41) at ../.././gcc/passes.c:921 #6 0x08371cd9 in do_per_function (callback=0x8371f3c , data=0x41) at ../.././gcc/passes.c:758 #7 0x08372275 in execute_todo (flags=65) at ../.././gcc/passes.c:936 #8 0x083726d2 in execute_one_pass (pass=0x8a060c0) at ../.././gcc/passes.c:1081 #9 0x08372754 in execute_pass_list (pass=0x8a060c0) at ../.././gcc/passes.c: #10 0x08372770 in execute_pass_list (pass=0x8a05e00) at ../.././gcc/passes.c:1112 #11 0x08372770 in execute_pass_list (pass=0x8a05680) at ../.././gcc/passes.c:1112 #12 0x084a94ea in tree_rest_of_compilation (fndecl=0xb7c33e00) at ../.././gcc/tree-optimize.c:412 #13 0x080d8a55 in c_expand_body (fndecl=0xb7c33e00) at ../.././gcc/c-common.c:4276 #14 0x0868bc11 in cgraph_expand_function (node=0xb7b75900) at ../.././gcc/cgraphunit.c:1015 #15 0x0868be01 in cgraph_expand_all_functions () at ../.././gcc/cgraphunit.c:1084 #16 0x0868c3c3 in cgraph_optimize () at ../.././gcc/cgraphunit.c:1287 #17 0x080736f2 in c_write_global_declarations () at ../.././gcc/c-decl.c:7930 #18 0x08424a18 in compile_file () at ../.././gcc/toplev.c:1063 #19 0x08426343 in do_compile () at ../.././gcc/toplev.c:2124 #20 0x084263a5 in toplev_main (argc=4, argv=0xbfca4c64) at ../.././gcc/toplev.c:2156 #21 0x081167fa in main (argc=0, argv=0x0) at ../.././gcc/main.c:35 Thanks for your help.
Expression with 2 operations
Dear all, I must calculate the address of an element's array. If the size of an element is one integer it's good. I do like that: new_rhs=fold_build2(PLUS_EXPR,TREE_TYPE(TREE_OPERAND(rhs,1)), build1(ADDR_EXPR, build_pointer_type (TREE_TYPE (array)),array), index); But, if the type of an element is not one integer, I must multiply the index by the size of an element. I try to do like that : tree decalage=fold_build2(MULT_EXPR,TREE_TYPE(index), index, compteur); new_rhs=fold_build2(PLUS_EXPR,TREE_TYPE(TREE_OPERAND(rhs,1)), build1(ADDR_EXPR, build_pointer_type (TREE_TYPE (array)),array), decalage); new_rhs is a futur parameter of a function call. When a try to compile a program gcc answer: " tab.c:22: erreur: invalid operand to binary operator i_28 * 4; tab.c:22: erreur interne du compilateur: verify_stmts failed " i_28 is index 4 is compteur How can I do that ? Thanks in advance. Antoine This is the debug_tree() of new_rhs : unit size align 32 symtab 0 alias set 3 canonical type 0x403532d8 precision 32 min max 0x40342318 2147483647> pointer_to_this > arg 0 arg 0 visited var def_stmt 0x403e79a0> version 28> arg 1 > arg 1 unsigned SI size unit size align 32 symtab 0 alias set -1 canonical type 0x403e38f0> constant invariant arg 0 addressable used public static common BLK file tab.c line 7 size unit size align 256 (mem/s/c:BLK (symbol_ref:SI ("") >) [2 +0 S40 A256]) chain >>>
Re: Expression with 2 operations
Quoting Tom Tromey <[EMAIL PROTECTED]>: "Antoine" == Antoine Eiche <[EMAIL PROTECTED]> writes: Without more information I don't know how to answer your question. But I do have a question for you... Antoine> I must calculate the address of an element's array. Antoine> If the size of an element is one integer it's good. Antoine> I do like that: Antoine> new_rhs=fold_build2(PLUS_EXPR,TREE_TYPE(TREE_OPERAND(rhs,1)), Antoine>build1(ADDR_EXPR, build_pointer_type (TREE_TYPE Antoine> (array)),array), Antoine>index); Why not use ARRAY_REF here? Then you don't have to worry about the size of an element of the array. Tom I tested whit ARRAY_REF but I did not succeed to build the address (error when I test my pass). Then, I try to calculate the address whit the index and the size of an element. I specify that I just have the problem whit a static array. This code is the code which is in the source file of a test program: int main() { int a[10]; int i; for(i=0;i<10;i++){ a[i]=1; } } I have succeed to transform the code like that: int main(){ int a[10]; int i; for(i=0;i<10;i++){ foo(a + i); a[i]=1; } } But I want to transform like that: int main(){ int a[10]; int i; for(i=0;i<10;i++){ foo(a + i * sizeof(*a)); a[i]=1; } } I specify that I have not succeed to transform like that!: int main(){ int a[10]; int i; for(i=0;i<10;i++){ foo(& a[i]); a[i]=1; } } Why can I not do "foo(a + i * x)" then I can do "foo(i * x)" ou "foo(a + i)" ?* How can I do that ? Thanks in advance.