Node:Target Attributes, Next:, Previous:Mode Switching, Up:Target Macros



Defining target-specific uses of __attribute__

Target-specific attributes may be defined for functions, data and types. These are described using the following target hooks; they also need to be documented in extend.texi.

const struct attribute_spec * TARGET_ATTRIBUTE_TABLE Target Hook
If defined, this target hook points to an array of struct attribute_spec (defined in tree.h) specifying the machine specific attributes for this target and some of the restrictions on the entities to which these attributes are applied and the arguments they take.

int TARGET_COMP_TYPE_ATTRIBUTES (tree type1, tree type2) Target Hook
If defined, this target hook is a function which returns zero if the attributes on type1 and type2 are incompatible, one if they are compatible, and two if they are nearly compatible (which causes a warning to be generated). If this is not defined, machine-specific attributes are supposed always to be compatible.

void TARGET_SET_DEFAULT_TYPE_ATTRIBUTES (tree type) Target Hook
If defined, this target hook is a function which assigns default attributes to newly defined type.

tree TARGET_MERGE_TYPE_ATTRIBUTES (tree type1, tree type2) Target Hook
Define this target hook if the merging of type attributes needs special handling. If defined, the result is a list of the combined TYPE_ATTRIBUTES of type1 and type2. It is assumed that comptypes has already been called and returned 1. This function may call merge_attributes to handle machine-independent merging.

tree TARGET_MERGE_DECL_ATTRIBUTES (tree olddecl, tree newdecl) Target Hook
Define this target hook if the merging of decl attributes needs special handling. If defined, the result is a list of the combined DECL_ATTRIBUTES of olddecl and newdecl. newdecl is a duplicate declaration of olddecl. Examples of when this is needed are when one attribute overrides another, or when an attribute is nullified by a subsequent definition. This function may call merge_attributes to handle machine-independent merging.

If the only target-specific handling you require is dllimport for Windows targets, you should define the macro TARGET_DLLIMPORT_DECL_ATTRIBUTES. This links in a function called merge_dllimport_decl_attributes which can then be defined as the expansion of TARGET_MERGE_DECL_ATTRIBUTES. This is done in i386/cygwin.h and i386/i386.c, for example.

void TARGET_INSERT_ATTRIBUTES (tree node, tree *attr_ptr) Target Hook
Define this target hook if you want to be able to add attributes to a decl when it is being created. This is normally useful for back ends which wish to implement a pragma by using the attributes which correspond to the pragma's effect. The node argument is the decl which is being created. The attr_ptr argument is a pointer to the attribute list for this decl. The list itself should not be modified, since it may be shared with other decls, but attributes may be chained on the head of the list and *attr_ptr modified to point to the new attributes, or a copy of the list may be made if further changes are needed.

bool TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P (tree fndecl) Target Hook
This target hook returns true if it is ok to inline fndecl into the current function, despite its having target-specific attributes, false otherwise. By default, if a function has a target specific attribute attached to it, it will not be inlined.