Alex, Thank you very much. I know REGISTER_TARGET_PRAGMAS interface, but I didn't realize you also use the same interface to create builtins. Did you still need modify loop-unroll.c or other gcc files to detect preceding "customop_unroll_pragma" instruction?
Cheers, Bingfeng -----Original Message----- From: Alex Turjan [mailto:[EMAIL PROTECTED] Sent: 30 May 2008 08:55 To: Bingfeng Mei; gcc@gcc.gnu.org Subject: RE: Implement #pragma unroll? Bingfeng, to define the pragma you use something like this: #define REGISTER_TARGET_PRAGMAS() { c_register_pragma (0, "unroll_factor", support_unroll_pragma); } such that when you compile a loop like this you get it unrolled 20 times: #pragma unroll_factor=20 for(i = 0; i < 40; i++){ m[i]=3; } then you have to implement the support_unroll_pragma function which in my case I used it to extract the unrolling factor (in this case 20) and to insert in the parse tree an intrinsic. Here is my code: void support_unroll_pragma (cpp_reader * pfile ATTRIBUTE_UNUSED) { tree x; enum cpp_ttype token; int unroll_factor = 0; token = pragma_lex (&x); gcc_assert (token == CPP_EQ); token = pragma_lex (&x); gcc_assert (token == CPP_NUMBER); unroll_factor = TREE_INT_CST_LOW (x); tree type = build_function_type_list (void_type_node, integer_type_node, NULL_TREE); tree t = build_fn_decl ("__unroll_pragma", type); enum built_in_function code = DECL_FUNCTION_CODE (t); DECL_BUILT_IN_CLASS (t) = BUILT_IN_MD; TREE_PUBLIC (t) = 1; DECL_EXTERNAL (t) = 1; DECL_FUNCTION_CODE (t) = builtin_line_no("__unroll_pragma"); tree operand = build_int_cst (NULL_TREE, unroll_factor); t = build_call_expr (t, 1, operand); add_stmt (t); } trimedia_builtin_line_no generates a call described by the following pattern: (define_insn "customop_unroll_pragma" [(unspec_volatile:SI [ (match_operand:SI 0 "immediate_operand" "i") ] UNSPEC_unroll_pragma) ] "" "" ) which in loop-unroll (where you have RTL instructions) is caught with the with something like this: (INSN_P(insn) && recog_memoized(insn) == CODE_FOR_customop_unroll_pragma more or less this is it. Alex --- Bingfeng Mei <[EMAIL PROTECTED]> wrote: > Alex, Thanks for your suggestion. What target hook > do you use for the > backend function? > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Alex Turjan > Sent: 29 May 2008 14:45 > To: gcc@gcc.gnu.org > Subject: RE: Implement #pragma unroll? > > Dear Bingfeng, > Some time ago I had to deal with a similar issue as > you. Basically I did as follows: I built a backend > function which catches the unroll pragma and > replaces > it with a target assembly intrinsic (which of course > has to be described in an .md file). After that in > the > RTL unroll phase, I analyze loop by loop and connect > them to the corresponding unrolling intrinsic (which > as a field contains the unrolling factor, you may > add > here extra information which allows you to recognize > the loop) from where I decide the unrolling factor. > After that in the RTL unroll phase I remove all the > unroll intrinsics. > hope this will help, > Alex > > > > > > >