llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-mips Author: Brad Smith (brad0) <details> <summary>Changes</summary> __mips and _MIPS_ISA were set from the ABI only, so -march=mips1 to -march=mips5 got __mips 32 or 64 and _MIPS_ISA_MIPS32 or _MIPS_ISA_MIPS64. Code that checks for MIPS I, such as for the load delay slot or the missing ll/sc, could not tell. Do what GCC does: __mips is 1 to 5 for MIPS I to MIPS V and 32 or 64 for MIPS32 and MIPS64, and _MIPS_ISA follows it. __mips64 stays based on the ABI. __mips_isa_rev is now only defined for MIPS32 and MIPS64, as GCC does, instead of being defined as 0 for the older ISAs. --- Full diff: https://github.com/llvm/llvm-project/pull/244951.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/Mips.cpp (+25-10) - (modified) clang/lib/Basic/Targets/Mips.h (+1) - (modified) clang/test/Preprocessor/init-mips.c (+74) ``````````diff diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp index 76c9081567053..3a9c783dbea5c 100644 --- a/clang/lib/Basic/Targets/Mips.cpp +++ b/clang/lib/Basic/Targets/Mips.cpp @@ -68,6 +68,21 @@ void MipsTargetInfo::fillValidCPUList( Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames)); } +StringRef MipsTargetInfo::getISALevel() const { + return llvm::StringSwitch<StringRef>(getCPU()) + .Case("mips1", "1") + .Case("mips2", "2") + .Cases({"mips3", "r5900"}, "3") + .Case("mips4", "4") + .Case("mips5", "5") + .Cases({"mips32", "mips32r2", "mips32r3", "mips32r5", "mips32r6", "p5600"}, + "32") + .Cases({"mips64", "mips64r2", "mips64r3", "mips64r5", "mips64r6", + "octeon", "octeon+", "i6400", "i6500"}, + "64") + .Default(ABI == "o32" ? "32" : "64"); +} + unsigned MipsTargetInfo::getISARev() const { return llvm::StringSwitch<unsigned>(getCPU()) .Cases({"mips32", "mips64"}, 1) @@ -93,20 +108,20 @@ void MipsTargetInfo::getTargetDefines(const LangOptions &Opts, if (Opts.GNUMode) Builder.defineMacro("mips"); - if (ABI == "o32") { - Builder.defineMacro("__mips", "32"); - Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS32"); - } else { - Builder.defineMacro("__mips", "64"); + // Like GCC, __mips and _MIPS_ISA give the ISA level: 1 to 5 for MIPS I to + // MIPS V, and 32 or 64 for any revision of MIPS32 or MIPS64. + StringRef ISALevel = getISALevel(); + Builder.defineMacro("__mips", ISALevel); + Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS" + ISALevel); + + if (ABI != "o32") { Builder.defineMacro("__mips64"); Builder.defineMacro("__mips64__"); - Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS64"); } - const std::string ISARev = std::to_string(getISARev()); - - if (!ISARev.empty()) - Builder.defineMacro("__mips_isa_rev", ISARev); + // __mips_isa_rev is only defined for MIPS32 and MIPS64. + if (unsigned ISARev = getISARev()) + Builder.defineMacro("__mips_isa_rev", Twine(ISARev)); if (ABI == "o32") { Builder.defineMacro("__mips_o32"); diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h index 2f251c7eb8690..e21d70c0ddc28 100644 --- a/clang/lib/Basic/Targets/Mips.h +++ b/clang/lib/Basic/Targets/Mips.h @@ -176,6 +176,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo { return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } + StringRef getISALevel() const; unsigned getISARev() const; void getTargetDefines(const LangOptions &Opts, diff --git a/clang/test/Preprocessor/init-mips.c b/clang/test/Preprocessor/init-mips.c index c829eebdc9ec9..78391a73d40c0 100644 --- a/clang/test/Preprocessor/init-mips.c +++ b/clang/test/Preprocessor/init-mips.c @@ -1671,6 +1671,80 @@ // MIPS-ARCH-I6500:#define __mips_isa_rev 6 // MIPS-ARCH-I6500:#define __mips_nan2008 1 +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none \ +// RUN: -target-cpu mips1 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-1 %s +// +// MIPS-ARCH-1:#define _MIPS_ARCH "mips1" +// MIPS-ARCH-1:#define _MIPS_ARCH_MIPS1 1 +// MIPS-ARCH-1:#define _MIPS_ISA _MIPS_ISA_MIPS1 +// MIPS-ARCH-1:#define __mips 1 +// MIPS-ARCH-1-NOT:#define __mips_isa_rev {{.*}} + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none \ +// RUN: -target-cpu mips2 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-2 %s +// +// MIPS-ARCH-2:#define _MIPS_ARCH "mips2" +// MIPS-ARCH-2:#define _MIPS_ARCH_MIPS2 1 +// MIPS-ARCH-2:#define _MIPS_ISA _MIPS_ISA_MIPS2 +// MIPS-ARCH-2:#define __mips 2 +// MIPS-ARCH-2-NOT:#define __mips_isa_rev {{.*}} + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ +// RUN: -target-cpu mips3 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-3 %s +// +// MIPS-ARCH-3:#define _MIPS_ARCH "mips3" +// MIPS-ARCH-3:#define _MIPS_ARCH_MIPS3 1 +// MIPS-ARCH-3:#define _MIPS_ISA _MIPS_ISA_MIPS3 +// MIPS-ARCH-3:#define __mips 3 +// MIPS-ARCH-3:#define __mips64 1 +// MIPS-ARCH-3-NOT:#define __mips_isa_rev {{.*}} + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ +// RUN: -target-cpu mips4 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-4 %s +// +// MIPS-ARCH-4:#define _MIPS_ARCH "mips4" +// MIPS-ARCH-4:#define _MIPS_ARCH_MIPS4 1 +// MIPS-ARCH-4:#define _MIPS_ISA _MIPS_ISA_MIPS4 +// MIPS-ARCH-4:#define __mips 4 +// MIPS-ARCH-4:#define __mips64 1 +// MIPS-ARCH-4-NOT:#define __mips_isa_rev {{.*}} + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ +// RUN: -target-cpu mips5 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-5 %s +// +// MIPS-ARCH-5:#define _MIPS_ARCH "mips5" +// MIPS-ARCH-5:#define _MIPS_ARCH_MIPS5 1 +// MIPS-ARCH-5:#define _MIPS_ISA _MIPS_ISA_MIPS5 +// MIPS-ARCH-5:#define __mips 5 +// MIPS-ARCH-5:#define __mips64 1 +// MIPS-ARCH-5-NOT:#define __mips_isa_rev {{.*}} + +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mipsel-none-none \ +// RUN: -target-cpu r5900 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-R5900 %s +// +// MIPS-ARCH-R5900:#define _MIPS_ARCH "r5900" +// MIPS-ARCH-R5900:#define _MIPS_ARCH_R5900 1 +// MIPS-ARCH-R5900:#define _MIPS_ISA _MIPS_ISA_MIPS3 +// MIPS-ARCH-R5900:#define __mips 3 +// MIPS-ARCH-R5900-NOT:#define __mips_isa_rev {{.*}} + +// A MIPS64 CPU with the O32 ABI is still MIPS64. +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ +// RUN: -target-abi o32 -target-cpu mips64r2 < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS-ARCH-64R2-O32 %s +// +// MIPS-ARCH-64R2-O32:#define _MIPS_ISA _MIPS_ISA_MIPS64 +// MIPS-ARCH-64R2-O32:#define __mips 64 +// MIPS-ARCH-64R2-O32-NOT:#define __mips64 {{.*}} +// MIPS-ARCH-64R2-O32:#define __mips_isa_rev 2 + // Check MIPS float ABI macros // // RUN: %clang_cc1 -E -dM -ffreestanding \ `````````` </details> https://github.com/llvm/llvm-project/pull/244951 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
