Skip to content

Commit

Permalink
MIPS: allow o32 abi with 64bit CPU and 64 abi with 32bit triple
Browse files Browse the repository at this point in the history
In general, MIPS support ELF format like
   ELF 32-bit LSB relocatable, MIPS, MIPS64 rel2 version 1 (SYSV)
and Linux's VDSO uses it.

Currently clang stop CMDs like
    clang -march=mips64r2 -mabi=32

While it is not needed now, since the the backend support the combination now.

This patch also allows something like
     clang --target=mipsel-linux-gnu -mabi=64
Since the triple can convert to right 64bit one automaticly.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D146269
  • Loading branch information
wzssyqa authored and MaskRay committed May 16, 2023
1 parent 0b1cd03 commit 7983f8a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 33 deletions.
24 changes: 0 additions & 24 deletions clang/lib/Basic/Targets/Mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,37 +238,13 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const {
Diags.Report(diag::err_target_unsupported_cpu_for_micromips) << CPU;
return false;
}
// FIXME: It's valid to use O32 on a 64-bit CPU but the backend can't handle
// this yet. It's better to fail here than on the backend assertion.
if (processorSupportsGPR64() && ABI == "o32") {
Diags.Report(diag::err_target_unsupported_abi) << ABI << CPU;
return false;
}

// 64-bit ABI's require 64-bit CPU's.
if (!processorSupportsGPR64() && (ABI == "n32" || ABI == "n64")) {
Diags.Report(diag::err_target_unsupported_abi) << ABI << CPU;
return false;
}

// FIXME: It's valid to use O32 on a mips64/mips64el triple but the backend
// can't handle this yet. It's better to fail here than on the
// backend assertion.
if (getTriple().isMIPS64() && ABI == "o32") {
Diags.Report(diag::err_target_unsupported_abi_for_triple)
<< ABI << getTriple().str();
return false;
}

// FIXME: It's valid to use N32/N64 on a mips/mipsel triple but the backend
// can't handle this yet. It's better to fail here than on the
// backend assertion.
if (getTriple().isMIPS32() && (ABI == "n32" || ABI == "n64")) {
Diags.Report(diag::err_target_unsupported_abi_for_triple)
<< ABI << getTriple().str();
return false;
}

// -fpxx is valid only for the o32 ABI
if (FPMode == FPXX && (ABI == "n32" || ABI == "n64")) {
Diags.Report(diag::err_unsupported_abi_for_opt) << "-mfpxx" << "o32";
Expand Down
7 changes: 0 additions & 7 deletions clang/test/Driver/mips-abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
// MIPS32R2-O32: "-target-cpu" "mips32r2"
// MIPS32R2-O32: "-target-abi" "o32"
//
// FIXME: This is a valid combination of options but we reject it at the moment
// because the backend can't handle it.
// RUN: not %clang -target mips-linux-gnu -c %s \
// RUN: -march=mips64r2 -mabi=32 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS64R2-O32 %s
// MIPS64R2-O32: error: ABI 'o32' is not supported on CPU 'mips64r2'
//
// RUN: %clang -target mips64-linux-gnu -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS64R2-N64 %s
// RUN: %clang -target mips-img-linux-gnu -mips64r2 -### -c %s 2>&1 \
Expand Down
68 changes: 68 additions & 0 deletions clang/test/Driver/mips-cpu64abi32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/// Check handling the CPU is 64bit while ABI is O32.
/// when build for MIPS platforms.

/// abi-n32
// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=n32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-ABI-N32 %s
// CHECK-ABI-N32: "-target-abi" "n32"

/// abi-64
// RUN: %clang -### -c %s --target=mips-linux-gnu -mabi=64 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-ABI-64 %s
// CHECK-ABI-64: "-target-abi" "n64"


/// -march=mips3
// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips3 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPS3 %s
// CHECK-MIPS-MIPS3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"

/// -march=mips4
// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips4 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPS4 %s
// CHECK-MIPS-MIPS4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"

/// FIXME: MIPS V is not implemented yet.

/// -march=mips64
/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPS64 %s
// CHECK-MIPS-MIPS64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"

/// -march=mips64r2
/// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r2 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPS64R2 %s
// CHECK-MIPS-MIPS64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"

/// -march=mips64r6
// RUN: %clang -### -c %s --target=mips-linux-gnu -march=mips64r6 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPS64R6 %s
// CHECK-MIPS-MIPS64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"


/// mipsisa3
// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips3 -mabi=32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPSISA3 %s
// CHECK-MIPS-MIPSISA3: "-target-cpu" "mips3" {{.*}} "-target-abi" "o32"

/// mipsisa4
// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips4 -mabi=32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPSISA4 %s
// CHECK-MIPS-MIPSISA4: "-target-cpu" "mips4" {{.*}} "-target-abi" "o32"

/// FIXME: MIPS V is not implemented yet.

/// mipsisa64
// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64 -mabi=32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64 %s
// CHECK-MIPS-MIPSISA64: "-target-cpu" "mips64" {{.*}} "-target-abi" "o32"

/// mipsisa64r2
// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r2 -mabi=32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R2 %s
// CHECK-MIPS-MIPSISA64R2: "-target-cpu" "mips64r2" {{.*}} "-target-abi" "o32"

/// mipsisa64r6
// RUN: %clang -### -c %s --target=mips64-linux-gnu -march=mips64r6 -mabi=32 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS-MIPSISA64R6 %s
// CHECK-MIPS-MIPSISA64R6: "-target-cpu" "mips64r6" {{.*}} "-target-abi" "o32"
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MipsSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ MipsSubtarget::MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
report_fatal_error("Code generation for MIPS-V is not implemented", false);

// Check if Architecture and ABI are compatible.
assert(((!isGP64bit() && isABI_O32()) ||
(isGP64bit() && (isABI_N32() || isABI_N64()))) &&
assert(((!isGP64bit() && isABI_O32()) || isGP64bit()) &&
"Invalid Arch & ABI pair.");

if (hasMSA() && !isFP64bit())
Expand Down

0 comments on commit 7983f8a

Please sign in to comment.