On Wed, Sep 30, 2015 at 03:01:22PM -0400, Nathan Sidwell wrote: > On 09/30/15 08:46, Richard Biener wrote: > > >>>Please don't add any new GENERIC based builtin folders. Instead add to > >>>gimple-fold.c:gimple_fold_builtin > > Is this patch ok? > > nathan
> 2015-09-30 Nathan Sidwell <nat...@codesourcery.com> > > * builtins.c: Don't include gomp-constants.h. > (fold_builtin_1): Don't fold acc_on_device here. > * gimple-fold.c: Include gomp-constants.h. > (gimple_fold_builtin_acc_on_device): New. > (gimple_fold_builtin): Call it. > > Index: gimple-fold.c > =================================================================== > --- gimple-fold.c (revision 228288) > +++ gimple-fold.c (working copy) > @@ -62,6 +62,7 @@ along with GCC; see the file COPYING3. > #include "output.h" > #include "tree-eh.h" > #include "gimple-match.h" > +#include "gomp-constants.h" > > /* Return true when DECL can be referenced from current unit. > FROM_DECL (if non-null) specify constructor of variable DECL was taken > from. > @@ -2708,6 +2709,34 @@ gimple_fold_builtin_strlen (gimple_stmt_ > return true; > } > > +/* Fold a call to __builtin_acc_on_device. */ > + > +static bool > +gimple_fold_builtin_acc_on_device (gimple_stmt_iterator *gsi, tree arg0) > +{ > + /* Defer folding until we know which compiler we're in. */ > + if (symtab->state != EXPANSION) > + return false; > + > + unsigned val_host = GOMP_DEVICE_HOST; > + unsigned val_dev = GOMP_DEVICE_NONE; > + > +#ifdef ACCEL_COMPILER > + val_host = GOMP_DEVICE_NOT_HOST; > + val_dev = ACCEL_COMPILER_acc_device; > +#endif > + > + tree host = build2 (EQ_EXPR, boolean_type_node, arg0, > + build_int_cst (integer_type_node, val_host)); > + tree dev = build2 (EQ_EXPR, boolean_type_node, arg0, > + build_int_cst (integer_type_node, val_dev)); > + > + tree result = build2 (TRUTH_OR_EXPR, boolean_type_node, host, dev); > + > + result = fold_convert (integer_type_node, result); > + gimplify_and_update_call_from_tree (gsi, result); > + return true; > +} Wouldn't it be better to just emit GIMPLE here instead? So tree res = make_ssa_name (boolean_type_node); gimple g = gimple_build_assign (res, EQ_EXPR, arg0, build_int_cst (integer_type_node, val_host)); gsi_insert_before (gsi, g); ... ? Jakub