This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Implement #pragma unroll?
- From: Alex Turjan <aturjan at yahoo dot com>
- To: Bingfeng Mei <bmei at broadcom dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 30 May 2008 00:54:47 -0700 (PDT)
- 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 <bmei@broadcom.com> wrote:
> Alex, Thanks for your suggestion. What target hook
> do you use for the
> backend function?
>
> -----Original Message-----
> From: gcc-owner@gcc.gnu.org
> [mailto:gcc-owner@gcc.gnu.org] 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
>
>
>
>
>
>
>