LoongArch: Enable switchable target
commit8657d76d583f0f87000e9003ba75922f2bbe4455
authorYang Yujie <yangyujie@loongson.cn>
Mon, 8 Apr 2024 08:45:13 +0000 (8 16:45 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Tue, 9 Apr 2024 09:03:15 +0000 (9 17:03 +0800)
tree241cba80e6cd82311c079a8b2fe49fb514181a34
parent73fb0a6153f4781587c925c56683b61632e63dee
LoongArch: Enable switchable target

This patch fixes the back-end context switching in cases where functions
should be built with their own target contexts instead of the
global one, such as LTO linking and functions with target attributes (TBD).

PR target/113233

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_reg_init):
Reinitialize the loongarch_regno_mode_ok cache.
(loongarch_option_override): Same.
(loongarch_save_restore_target_globals): Restore target globals.
(loongarch_set_current_function): Restore the target contexts
for functions.
(TARGET_SET_CURRENT_FUNCTION): Define.
* config/loongarch/loongarch.h (SWITCHABLE_TARGET): Enable
switchable target context.
* config/loongarch/loongarch-builtins.cc (loongarch_init_builtins):
Initialize all builtin functions at startup.
(loongarch_expand_builtin): Turn assertion of builtin availability
into a test.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Define condition loongarch_sx_as.
* gcc.dg/lto/pr113233_0.c: New test.
gcc/config/loongarch/loongarch-builtins.cc
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.h
gcc/testsuite/gcc.dg/lto/pr113233_0.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp