gcc/config.gcc | 18 +++++++++++++++++-
gcc/config/loongarch/loongarch-opts.cc | 2 +-
gcc/doc/install.texi | 2 +-
gcc/doc/invoke.texi | 3 ++-
.../loongarch/vect-frint-no-inexact.c | 2 +-
.../loongarch/vect-frint-scalar-no-inexact.c | 2 +-
.../gcc.target/loongarch/vect-frint-scalar.c | 2 +-
.../gcc.target/loongarch/vect-frint.c | 2 +-
.../loongarch/vect-ftint-no-inexact.c | 2 +-
.../gcc.target/loongarch/vect-ftint.c | 2 +-
10 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c678b801f70..b0fa43b5eba 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5118,7 +5118,7 @@ case "${target}" in
;;
loongarch*-*)
- supported_defaults="abi arch tune fpu simd multilib-default
strict-align-lib tls"
+ supported_defaults="abi arch tune fpu simd multilib-default
strict-align-lib tls cmodel"
# Local variables
unset \
@@ -5539,6 +5539,22 @@ case "${target}" in
# Remove the excessive appending comma.
loongarch_multilib_list_c=${loongarch_multilib_list_c%,}
loongarch_multilib_list_make=${loongarch_multilib_list_make%,}
+
+ # Handle --with-cmodel.
+ # Make sure --with-cmodel is valid. If it was not specified,
+ # use medium as the default value.
+ case "${with_cmodel}" in
+ "" | medium)
+ tm_defines="${tm_defines}
TARGET_DEFAULT_CMODEL=CMODEL_MEDIUM"
+ ;;
+ normal)
+ tm_defines="${tm_defines}
TARGET_DEFAULT_CMODEL=CMODEL_NORMAL"
+ ;;
+ *)
+ echo "invalid option for --with-cmodel: '${with_cmodel}', available
values are 'medium' and 'normal'" 1>&2
+ exit 1
+ ;;
+ esac
;;
nds32*-*-*)
diff --git a/gcc/config/loongarch/loongarch-opts.cc
b/gcc/config/loongarch/loongarch-opts.cc
index 6e72084b9be..cacfe370345 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -540,7 +540,7 @@ fallback:
/* 5. Target code model */
- t.cmodel = constrained.cmodel ? target->cmodel : CMODEL_NORMAL;
+ t.cmodel = constrained.cmodel ? target->cmodel : TARGET_DEFAULT_CMODEL;
switch (t.cmodel)
{
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 50cefa1c4d7..d1068dc25ad 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1615,7 +1615,7 @@ Use little endian by default. Provide a multilib for big
endian.
@item --with-cmodel=@var{cmodel}
Specify what code model to use by default.
-Currently only implemented for riscv*-*-*.
+Currently only implemented for loongarch*-*-* and riscv*-*-*.
@item --enable-threads
Specify that the target
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 32b9c48f155..c50590471a8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -28520,6 +28520,8 @@ be within 2GB addressing space.
@item medium
The text segment and data segment must be within 2GB addressing space.
+This is the default code model unless GCC has been configured with
+@option{--with-cmodel=} specifying a different default code model.
@item large (Not implemented yet)
@@ -28528,7 +28530,6 @@ This mode does not limit the size of the code segment and data segment.
The @option{-mcmodel=extreme} option is incompatible with @option{-fplt}
and/or @option{-mexplicit-relocs=none}.
@end table
-The default code model is @code{normal}.
@item -mexplicit-relocs=@var{style}
Set when to use assembler relocation operators when dealing with symbolic
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-frint-no-inexact.c
b/gcc/testsuite/gcc.target/loongarch/vect-frint-no-inexact.c
index 7bbaf1fba5a..e20eaea205a 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-frint-no-inexact.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-frint-no-inexact.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-fno-fp-int-builtin-inexact -mlasx" } */
+/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-fno-fp-int-builtin-inexact -mlasx -mcmodel=normal" } */
#include "vect-frint.c"
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar-no-inexact.c b/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar-no-inexact.c
index 002e3b92df7..d5f0933537d 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar-no-inexact.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar-no-inexact.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mlsx -fno-fp-int-builtin-inexact" } */
+/* { dg-options "-O2 -mlsx -fno-fp-int-builtin-inexact -mcmodel=normal" } */
#include "vect-frint-scalar.c"
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar.c b/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar.c
index dbcb9065ad4..171ba98f00b 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-frint-scalar.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mlsx -ffp-int-builtin-inexact" } */
+/* { dg-options "-O2 -mlsx -ffp-int-builtin-inexact -mcmodel=normal" } */
#define test(func, suffix) \
__typeof__ (1.##suffix) \
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-frint.c
b/gcc/testsuite/gcc.target/loongarch/vect-frint.c
index 6bf211e7e98..bda041bdf91 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-frint.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-frint.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-ffp-int-builtin-inexact -mlasx" } */
+/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-ffp-int-builtin-inexact -mlasx -mcmodel=normal" } */
float out_x[8];
double out_y[4];
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-ftint-no-inexact.c
b/gcc/testsuite/gcc.target/loongarch/vect-ftint-no-inexact.c
index 61918beef5c..3fa97531d59 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-ftint-no-inexact.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-ftint-no-inexact.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-fno-fp-int-builtin-inexact -mlasx" } */
+/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-fno-fp-int-builtin-inexact -mlasx -mcmodel=normal" } */
#include "vect-ftint.c"
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-ftint.c b/gcc/testsuite/gcc.target/loongarch/vect-ftint.c
index c4962ed1774..96da3cd7b57 100644
--- a/gcc/testsuite/gcc.target/loongarch/vect-ftint.c
+++ b/gcc/testsuite/gcc.target/loongarch/vect-ftint.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-ffp-int-builtin-inexact -mlasx" } */
+/* { dg-options "-O2 -mabi=lp64d -mdouble-float -fno-math-errno
-ffp-int-builtin-inexact -mlasx -mcmodel=normal" } */
int out_x[8];
long out_y[4];