Commit d5524d52 by Christian Bruel Committed by Christian Bruel

Add ARM/thumb attribute target

	PR target/52144

	* config/arm/arm.opt (THUMB, arm_restrict_it, inline_asm_unified): Save.
	* config/arm/arm-protos.h (arm_valid_target_attribute_tree): Declare.
	(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
	* config/arm/arm.h (SWITCHABLE_TARGET): Define.
	* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
	(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
	(arm_valid_target_attribute_p): Likewise.
	(arm_set_current_function, arm_can_inline_p): Likewise.
	(arm_valid_target_attribute_rec): Likewise.
	(arm_previous_fndecl): New variable.
	(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
	(TARGET_CAN_INLINE_P): Define.
	(arm_asm_trampoline_template): Emit mode.
	(arm_file_start): Don't set unified syntax.
	(arm_declare_function_name): Set unified syntax and mode.
	(arm_option_override): Init target_option_default_node.
	and target_option_current_node.
	* config/arm/arm.md (*call_value_symbol): Set mode when possible.
	(*call_symbol): Likewise.
	* doc/extend.texi: Document ARM/Thumb target attribute.
	* doc/invoke.texi: Likewise.

	* gcc.target/arm/attr_arm.c: New test
	* gcc.target/arm/attr_arm-err.c: New test
	* gcc.target/arm/attr_thumb.c: New test
	* gcc.target/arm/attr_thumb-static.c: New test

From-SVN: r224314
parent eb071c6b
2015-06-09 Christian Bruel <christian.bruel@st.com>
PR target/52144
* config/arm/arm.opt (THUMB, arm_restrict_it, inline_asm_unified): Save.
* config/arm/arm-protos.h (arm_valid_target_attribute_tree): Declare.
(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
* config/arm/arm.h (SWITCHABLE_TARGET): Define.
* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
(arm_valid_target_attribute_p): Likewise.
(arm_set_current_function, arm_can_inline_p): Likewise.
(arm_valid_target_attribute_rec): Likewise.
(arm_previous_fndecl): New variable.
(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
(TARGET_CAN_INLINE_P): Define.
(arm_asm_trampoline_template): Emit mode.
(arm_file_start): Don't set unified syntax.
(arm_declare_function_name): Set unified syntax and mode.
(arm_option_override): Init target_option_default_node.
and target_option_current_node.
* config/arm/arm.md (*call_value_symbol): Set mode when possible.
(*call_symbol): Likewise.
* doc/extend.texi: Document ARM/Thumb target attribute.
* doc/invoke.texi: Likewise.
2015-06-09 Alexandre Oliva <aoliva@redhat.com> 2015-06-09 Alexandre Oliva <aoliva@redhat.com>
Revert: Revert:
......
...@@ -210,6 +210,9 @@ extern int arm_dllexport_p (tree); ...@@ -210,6 +210,9 @@ extern int arm_dllexport_p (tree);
extern int arm_dllimport_p (tree); extern int arm_dllimport_p (tree);
extern void arm_mark_dllexport (tree); extern void arm_mark_dllexport (tree);
extern void arm_mark_dllimport (tree); extern void arm_mark_dllimport (tree);
extern bool arm_change_mode_p (tree);
extern tree arm_valid_target_attribute_tree (tree, struct gcc_options *,
struct gcc_options *);
#endif #endif
extern void arm_pr_long_calls (struct cpp_reader *); extern void arm_pr_long_calls (struct cpp_reader *);
...@@ -326,6 +329,8 @@ extern bool arm_autoinc_modes_ok_p (machine_mode, enum arm_auto_incmodes); ...@@ -326,6 +329,8 @@ extern bool arm_autoinc_modes_ok_p (machine_mode, enum arm_auto_incmodes);
extern void arm_emit_eabi_attribute (const char *, int, int); extern void arm_emit_eabi_attribute (const char *, int, int);
extern void arm_reset_previous_fndecl (void);
/* Defined in gcc/common/config/arm-common.c. */ /* Defined in gcc/common/config/arm-common.c. */
extern const char *arm_rewrite_selected_cpu (const char *name); extern const char *arm_rewrite_selected_cpu (const char *name);
......
...@@ -2258,4 +2258,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); ...@@ -2258,4 +2258,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
#define DRIVER_SELF_SPECS MCPU_MTUNE_NATIVE_SPECS #define DRIVER_SELF_SPECS MCPU_MTUNE_NATIVE_SPECS
#define TARGET_SUPPORTS_WIDE_INT 1 #define TARGET_SUPPORTS_WIDE_INT 1
/* For switching between functions with different target attributes. */
#define SWITCHABLE_TARGET 1
#endif /* ! GCC_ARM_H */ #endif /* ! GCC_ARM_H */
...@@ -7787,6 +7787,13 @@ ...@@ -7787,6 +7787,13 @@
&& !arm_is_long_call_p (SYMBOL_REF_DECL (operands[0]))" && !arm_is_long_call_p (SYMBOL_REF_DECL (operands[0]))"
"* "*
{ {
rtx op = operands[0];
/* Switch mode now when possible. */
if (SYMBOL_REF_DECL (op) && !TREE_PUBLIC (SYMBOL_REF_DECL (op))
&& arm_arch5 && arm_change_mode_p (SYMBOL_REF_DECL (op)))
return NEED_PLT_RELOC ? \"blx%?\\t%a0(PLT)\" : \"blx%?\\t(%a0)\";
return NEED_PLT_RELOC ? \"bl%?\\t%a0(PLT)\" : \"bl%?\\t%a0\"; return NEED_PLT_RELOC ? \"bl%?\\t%a0(PLT)\" : \"bl%?\\t%a0\";
}" }"
[(set_attr "type" "call")] [(set_attr "type" "call")]
...@@ -7804,6 +7811,13 @@ ...@@ -7804,6 +7811,13 @@
&& !arm_is_long_call_p (SYMBOL_REF_DECL (operands[1]))" && !arm_is_long_call_p (SYMBOL_REF_DECL (operands[1]))"
"* "*
{ {
rtx op = operands[1];
/* Switch mode now when possible. */
if (SYMBOL_REF_DECL (op) && !TREE_PUBLIC (SYMBOL_REF_DECL (op))
&& arm_arch5 && arm_change_mode_p (SYMBOL_REF_DECL (op)))
return NEED_PLT_RELOC ? \"blx%?\\t%a0(PLT)\" : \"blx%?\\t(%a0)\";
return NEED_PLT_RELOC ? \"bl%?\\t%a1(PLT)\" : \"bl%?\\t%a1\"; return NEED_PLT_RELOC ? \"bl%?\\t%a1(PLT)\" : \"bl%?\\t%a1\";
}" }"
[(set_attr "type" "call")] [(set_attr "type" "call")]
......
...@@ -182,7 +182,7 @@ Target RejectNegative Joined UInteger Var(arm_structure_size_boundary) Init(DEFA ...@@ -182,7 +182,7 @@ Target RejectNegative Joined UInteger Var(arm_structure_size_boundary) Init(DEFA
Specify the minimum bit alignment of structures Specify the minimum bit alignment of structures
mthumb mthumb
Target Report RejectNegative Mask(THUMB) Target Report RejectNegative Mask(THUMB) Save
Generate code for Thumb state Generate code for Thumb state
mthumb-interwork mthumb-interwork
...@@ -246,7 +246,7 @@ Target Report Var(target_word_relocations) Init(TARGET_DEFAULT_WORD_RELOCATIONS) ...@@ -246,7 +246,7 @@ Target Report Var(target_word_relocations) Init(TARGET_DEFAULT_WORD_RELOCATIONS)
Only generate absolute relocations on word sized values. Only generate absolute relocations on word sized values.
mrestrict-it mrestrict-it
Target Report Var(arm_restrict_it) Init(2) Target Report Var(arm_restrict_it) Init(2) Save
Generate IT blocks appropriate for ARMv8. Generate IT blocks appropriate for ARMv8.
mold-rtx-costs mold-rtx-costs
...@@ -275,5 +275,5 @@ Target Report Var(target_slow_flash_data) Init(0) ...@@ -275,5 +275,5 @@ Target Report Var(target_slow_flash_data) Init(0)
Assume loading data from flash is slower than fetching instructions. Assume loading data from flash is slower than fetching instructions.
masm-syntax-unified masm-syntax-unified
Target Report Var(inline_asm_unified) Init(0) Target Report Var(inline_asm_unified) Init(0) Save
Assume unified syntax for Thumb inline assembly code. Assume unified syntax for Thumb inline assembly code.
...@@ -3098,8 +3098,9 @@ strings separated by commas to specify multiple options, ...@@ -3098,8 +3098,9 @@ strings separated by commas to specify multiple options,
or separate the options with a comma (@samp{,}) within a single string. or separate the options with a comma (@samp{,}) within a single string.
The options supported are specific to each target; refer to @ref{x86 The options supported are specific to each target; refer to @ref{x86
Function Attributes}, @ref{PowerPC Function Attributes}, and Function Attributes}, @ref{PowerPC Function Attributes},
@ref{Nios II Function Attributes}, for details. @ref{ARM Function Attributes},and @ref{Nios II Function Attributes},
for details.
@item unused @item unused
@cindex @code{unused} function attribute @cindex @code{unused} function attribute
...@@ -3448,6 +3449,27 @@ double f2d (float) __attribute__((pcs("aapcs"))); ...@@ -3448,6 +3449,27 @@ double f2d (float) __attribute__((pcs("aapcs")));
Variadic functions always use the @code{"aapcs"} calling convention and Variadic functions always use the @code{"aapcs"} calling convention and
the compiler rejects attempts to specify an alternative. the compiler rejects attempts to specify an alternative.
@item target (@var{options})
@cindex @code{target} function attribute
As discussed in @ref{Common Function Attributes}, this attribute
allows specification of target-specific compilation options.
On ARM, the following options are allowed:
@table @samp
@item thumb
@cindex @code{target("thumb")} function attribute, ARM
Force code generation in the Thumb (T16/T32) ISA, depending on the
architecture level.
@item arm
@cindex @code{target("arm")} function attribute, ARM
Force code generation in the ARM (A32) ISA.
@end table
Functions from different modes can be inlined in the caller's mode.
@end table @end table
@node AVR Function Attributes @node AVR Function Attributes
......
...@@ -13512,6 +13512,10 @@ that executes in ARM state, but the default can be changed by ...@@ -13512,6 +13512,10 @@ that executes in ARM state, but the default can be changed by
configuring GCC with the @option{--with-mode=}@var{state} configuring GCC with the @option{--with-mode=}@var{state}
configure option. configure option.
You can also override the ARM and Thumb mode for each function
by using the @code{target("thumb")} and @code{target("arm")} function attributes
(@pxref{ARM Function Attributes}) or pragmas (@pxref{Function Specific Option Pragmas}).
@item -mtpcs-frame @item -mtpcs-frame
@opindex mtpcs-frame @opindex mtpcs-frame
Generate a stack frame that is compliant with the Thumb Procedure Call Generate a stack frame that is compliant with the Thumb Procedure Call
......
2015-06-09 Christian Bruel <christian.bruel@st.com>
PR target/52144
* gcc.target/arm/attr_arm.c: New test
* gcc.target/arm/attr_arm-err.c: New test
* gcc.target/arm/attr_thumb.c: New test
* gcc.target/arm/attr_thumb-static.c: New test
2015-06-10 Ramana Radhakrishnan <ramana.radhakrishnan@arm.com> 2015-06-10 Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
PR target/66200 PR target/66200
......
/* Check that attribute target arm is rejected for M profile. */
/* { dg-do compile } */
/* { dg-require-effective-target arm_arm_ok } */
/* { dg-skip-if "avoid conflicting multilib options" { *-*-* } { "-march=*" } { "-march=armv6-m" } } */
/* { dg-add-options arm_arch_v6m } */
int __attribute__((target("arm")))
foo(int a)
{ /* { dg-error "does not support" } */
return a ? 1 : 5;
}
/* Check that attribute target arm is recogniwed. */
/* { dg-do compile } */
/* { dg-require-effective-target arm_arm_ok } */
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler ".arm" } } */
/* { dg-final { scan-assembler-not "ite" } } */
int __attribute__((target("arm")))
foo(int a)
{
return a ? 1 : 5;
}
/* Check that a change mode to a static function is correctly handled. */
/* { dg-do run } */
/* { dg-require-effective-target arm_thumb1_ok } */
static void
__attribute__((__noinline__))
foo (void)
{
__asm__ ("");
}
static void
__attribute__((__noinline__))
__attribute__((target("thumb")))
bar (void)
{
__asm__ ("");
}
int main()
{
foo();
bar();
}
/* Check that attribute target thumb is recogniwed. */
/* { dg-do compile } */
/* { dg-require-effective-target arm_thumb2_ok } */
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler ".thumb" } } */
/* { dg-final { scan-assembler "ite" } } */
int __attribute__((target("thumb")))
foo(int a)
{
return a ? 1 : 5;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment