OpenMP and OpenACC (GNU Compiler Collection (GCC) Internals)

### 19.15 OpenMP and OpenACC ¶

Target Hook: `int` TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN `(struct cgraph_node *, struct cgraph_simd_clone *, tree, int, bool)` ¶

  This hook should set vecsize_mangle, vecsize_int, vecsize_float fields in simd_clone structure pointed by clone_info argument and also simdlen field if it was previously 0. vecsize_mangle is a marker for the backend only. vecsize_int and vecsize_float should be left zero on targets where the number of lanes is not determined by the bitsize (in which case simdlen is always used). The hook should return 0 if SIMD clones shouldn’t be emitted, or number of vecsize_mangle variants that should be emitted.

Target Hook: `void` TARGET_SIMD_CLONE_ADJUST `(struct cgraph_node *)` ¶

  This hook should add implicit `attribute(target("..."))` attribute to SIMD clone node if needed.

Target Hook: `int` TARGET_SIMD_CLONE_USABLE `(struct cgraph_node *, machine_mode)` ¶

  This hook should return -1 if SIMD clone node shouldn’t be used in vectorized loops in current function with vector_mode, or non-negative number if it is usable. In that case, the smaller the number is, the more desirable it is to use it.

Target Hook: `int` TARGET_SIMT_VF `(void)` ¶

  Return number of threads in SIMT thread group on the target.

Target Hook: `int` TARGET_OMP_DEVICE_KIND_ARCH_ISA `(enum omp_device_kind_arch_isa trait, const char *name)` ¶

  Return 1 if trait name is present in the OpenMP context’s device trait set, return 0 if not present in any OpenMP context in the whole translation unit, or -1 if not present in the current OpenMP context but might be present in another OpenMP context in the same TU.

Target Hook: `bool` TARGET_GOACC_VALIDATE_DIMS `(tree decl, int *dims, int fn_level, unsigned used)` ¶

  This hook should check the launch dimensions provided for an OpenACC compute region, or routine. Defaulted values are represented as -1 and non-constant values as 0. The fn_level is negative for the function corresponding to the compute region. For a routine it is the outermost level at which partitioned execution may be spawned. The hook should verify non-default values. If DECL is NULL, global defaults are being validated and unspecified defaults should be filled in. Diagnostics should be issued as appropriate. Return true, if changes have been made. You must override this hook to provide dimensions larger than 1.

Target Hook: `int` TARGET_GOACC_DIM_LIMIT `(int axis)` ¶

  This hook should return the maximum size of a particular dimension, or zero if unbounded.

Target Hook: `bool` TARGET_GOACC_FORK_JOIN `(gcall *call, const int *dims, bool is_fork)` ¶

  This hook can be used to convert IFN_GOACC_FORK and IFN_GOACC_JOIN function calls to target-specific gimple, or indicate whether they should be retained. It is executed during the oacc_device_lower pass. It should return true, if the call should be retained. It should return false, if it is to be deleted (either because target-specific gimple has been inserted before it, or there is no need for it). The default hook returns false, if there are no RTL expanders for them.

Target Hook: `void` TARGET_GOACC_REDUCTION `(gcall *call)` ¶

  This hook is used by the oacc_transform pass to expand calls to the GOACC_REDUCTION internal function, into a sequence of gimple instructions. call is gimple statement containing the call to the function. This hook removes statement call after the expanded sequence has been inserted. This hook is also responsible for allocating any storage for reductions when necessary.

Target Hook: `tree` TARGET_PREFERRED_ELSE_VALUE `(unsigned ifn, tree type, unsigned nops, tree *ops)` ¶

  This hook returns the target’s preferred final argument for a call to conditional internal function ifn (really of type `internal_fn`). type specifies the return type of the function and ops are the operands to the conditional operation, of which there are nops.

  For example, if ifn is `IFN_COND_ADD`, the hook returns a value of type type that should be used when ‘`ops[0]`’ and ‘`ops[1]`’ are conditionally added together.

  This hook is only relevant if the target supports conditional patterns like `cond_addm`. The default implementation returns a zero constant of type type.

Target Hook: `bool` TARGET_INSTRUCTION_SELECTION `(function *fun, gimple_stmt_iterator *gsi)` ¶

  This hook allows a target to perform custom instruction selection for an instruction or sequence of instructions before expand to allow expansion to generate more efficient code.

  fun is the current function being considered and gsi is the iterator pointing to the current instruction being optimized. The default implementation does not do any rewriting and returns false. The result of the function should be whether any changes were made to the CFG or not. If a change was made then the gsi should be left at the same position as at the function start. The caller is allowed to change the CFG at any point before the current statement gsi is pointing to but not afterwards.

Target Hook: `tree` TARGET_GOACC_ADJUST_PRIVATE_DECL `(location_t loc, tree var, int level)` ¶

  This hook, if defined, is used by accelerator target back-ends to adjust OpenACC variable declarations that should be made private to the given parallelism level (i.e. `GOMP_DIM_GANG`, `GOMP_DIM_WORKER` or `GOMP_DIM_VECTOR`). A typical use for this hook is to force variable declarations at the `gang` level to reside in GPU shared memory. loc may be used for diagnostic purposes.

  You may also use the `TARGET_GOACC_EXPAND_VAR_DECL` hook if the adjusted variable declaration needs to be expanded to RTL in a non-standard way.

Target Hook: `rtx` TARGET_GOACC_EXPAND_VAR_DECL `(tree var)` ¶

  This hook, if defined, is used by accelerator target back-ends to expand specially handled kinds of `VAR_DECL` expressions. A particular use is to place variables with specific attributes inside special accelerator memories. A return value of `NULL` indicates that the target does not handle this `VAR_DECL`, and normal RTL expanding is resumed.

  Only define this hook if your accelerator target needs to expand certain `VAR_DECL` nodes in a way that differs from the default. You can also adjust private variables at OpenACC device-lowering time using the `TARGET_GOACC_ADJUST_PRIVATE_DECL` target hook.

Target Hook: `tree` TARGET_GOACC_CREATE_WORKER_BROADCAST_RECORD `(tree rec, bool sender, const char *name, unsigned HOST_WIDE_INT offset)` ¶

  Create a record used to propagate local-variable state from an active worker to other workers. A possible implementation might adjust the type of REC to place the new variable in shared GPU memory.

  Presence of this target hook indicates that middle end neutering/broadcasting be used.

Target Hook: `void` TARGET_GOACC_SHARED_MEM_LAYOUT `(unsigned HOST_WIDE_INT *, unsigned HOST_WIDE_INT *, int[], unsigned HOST_WIDE_INT[], unsigned HOST_WIDE_INT[])` ¶

  Lay out a fixed shared-memory region on the target. The LO and HI arguments should be set to a range of addresses that can be used for worker broadcasting. The dimensions, reduction size and gang-private size arguments are for the current offload region.