This is the mail archive of the
mailing list for the GCC project.
Re: [GSoC] user defined predicates
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Prathamesh Kulkarni <bilbotheelffriend at gmail dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>, Maxim Kuvyrkov <maxim dot kuvyrkov at linaro dot org>
- Date: Fri, 8 Aug 2014 10:52:46 +0200
- Subject: Re: [GSoC] user defined predicates
- Authentication-results: sourceware.org; auth=none
- References: <CAJXstsCWLSCfYdwKZeCH5T-PdY=2j-k5M4WHqykWEADn3gCJ=Q at mail dot gmail dot com>
On Fri, Aug 8, 2014 at 1:16 AM, Prathamesh Kulkarni
> Currently, we treat predicates as "second-class" citizens:
> - assume any identifier as a valid predicate
> - cannot write more complex predicates than an identifier in match-op
> I was wondering whether it would be a good idea
> to ave user-defined predicates,
> instead of hard-coding them as macros in gimple-match-head.c ?
> * Syntax
> A predicate is assumed to expect only one operand as input.
> (define_predicate <name> (c_expr))
> and use it the same way we do currently.
> Example Use case:
> Consider following pattern:
> (foo @0 @1)
> (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
> The second operand (@1) is only captured for sake of testing it's type
> in if-expr.
> Instead, define a predicate:
> (define_predicate type_unsigned_p (TYPE_UNSIGNED (TREE_TYPE (@@)))
> @@ refers to the operand we use the predicate on.
> (foo @0 type_unsigned)
> in this case @@ would be op21 (one of the generated temporaries during
> code-gen for match-op in decision tree).
> * code-gen
> We would generate predicates as macros in the generated file.
> so in gimple-match.c, there would be
> #define type_unsigned(op) (TYPE_UNSIGNED (TREE_TYPE (op)))
> (we also need this for generic-match.c, so maybe generate macros in
> separate file say genpreds.c and include it in both gimple-match.c and
> and replace @@ by correct operand in the patterns the predicates
> are used.
> The current "predicates" in gimple-match-head.c can be written as:
> (define_predicate INTEGER_CST_P (TREE_CODE (@@) == INTEGER_CST)))
> (define_predicate integral_op_p (INTEGRAL_TYPE_P (TREE_TYPE (@@)))
> Not sure if this would have real benefit, just an idea...
My line of thinking was that if there are new predicates that are useful
for writing patterns then they are useful in GCC generally and thus
should be made available in the proper generic places (not
gimple-match-head.c), like for example in tree.[ch].
Note that code-generation should be changed to delay testing of
predicates until the if-expression is processed. That is, predicates
are really just a "shortcut" for capturing the operand and testing
the predicate in the if-expr.
The idea here is that matching the whole structure of the expression
is cheap while testing predicates is not.
So I don't think we want any define-predicate stuff in the language.