Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -5488,6 +5488,7 @@ CPU = Name; return true; } + const std::string& getCPU() const { return CPU; } void getDefaultFeatures(llvm::StringMap &Features) const override { // The backend enables certain ABI's by default according to the // architecture. @@ -5712,6 +5713,13 @@ MipsTargetInfoBase::getTargetDefines(Opts, Builder); Builder.defineMacro("__mips", "32"); + Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS32"); + + StringRef CPUStr = StringRef(getCPU()).lower(); + if (CPUStr == "mips32") + Builder.defineMacro("__mips_isa_rev", "1"); + else if (CPUStr == "mips32r2") + Builder.defineMacro("__mips_isa_rev", "2"); if (ABI == "o32") { Builder.defineMacro("__mips_o32"); @@ -5847,6 +5855,13 @@ Builder.defineMacro("__mips", "64"); Builder.defineMacro("__mips64"); Builder.defineMacro("__mips64__"); + Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS64"); + + StringRef CPUStr = StringRef(getCPU()).lower(); + if (CPUStr == "mips64") + Builder.defineMacro("__mips_isa_rev", "1"); + else if (CPUStr == "mips64r2") + Builder.defineMacro("__mips_isa_rev", "2"); if (ABI == "n32") { Builder.defineMacro("__mips_n32"); Index: test/Preprocessor/init.c =================================================================== --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -1776,7 +1776,7 @@ // MIPS64EL:#define _mips 1 // MIPS64EL:#define mips 1 // -// Check MIPS arch macros +// Check MIPS arch and isa macros // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none \ // RUN: < /dev/null \ @@ -1784,6 +1784,8 @@ // // MIPS-ARCH-DEF32:#define _MIPS_ARCH "mips32r2" // MIPS-ARCH-DEF32:#define _MIPS_ARCH_MIPS32R2 1 +// MIPS-ARCH-DEF32:#define _MIPS_ISA _MIPS_ISA_MIPS32 +// MIPS-ARCH-DEF32:#define __mips_isa_rev 2 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-nones \ // RUN: -target-cpu mips32 < /dev/null \ @@ -1791,6 +1793,8 @@ // // MIPS-ARCH-32:#define _MIPS_ARCH "mips32" // MIPS-ARCH-32:#define _MIPS_ARCH_MIPS32 1 +// MIPS-ARCH-32:#define _MIPS_ISA _MIPS_ISA_MIPS32 +// MIPS-ARCH-32:#define __mips_isa_rev 1 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none \ // RUN: -target-cpu mips32r2 < /dev/null \ @@ -1798,6 +1802,8 @@ // // MIPS-ARCH-32R2:#define _MIPS_ARCH "mips32r2" // MIPS-ARCH-32R2:#define _MIPS_ARCH_MIPS32R2 1 +// MIPS-ARCH-32R2:#define _MIPS_ISA _MIPS_ISA_MIPS32 +// MIPS-ARCH-32R2:#define __mips_isa_rev 2 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ // RUN: < /dev/null \ @@ -1805,6 +1811,8 @@ // // MIPS-ARCH-DEF64:#define _MIPS_ARCH "mips64r2" // MIPS-ARCH-DEF64:#define _MIPS_ARCH_MIPS64R2 1 +// MIPS-ARCH-DEF64:#define _MIPS_ISA _MIPS_ISA_MIPS64 +// MIPS-ARCH-DEF64:#define __mips_isa_rev 2 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ // RUN: -target-cpu mips64 < /dev/null \ @@ -1812,6 +1820,8 @@ // // MIPS-ARCH-64:#define _MIPS_ARCH "mips64" // MIPS-ARCH-64:#define _MIPS_ARCH_MIPS64 1 +// MIPS-ARCH-64:#define _MIPS_ISA _MIPS_ISA_MIPS64 +// MIPS-ARCH-64:#define __mips_isa_rev 1 // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \ // RUN: -target-cpu mips64r2 < /dev/null \ @@ -1819,6 +1829,8 @@ // // MIPS-ARCH-64R2:#define _MIPS_ARCH "mips64r2" // MIPS-ARCH-64R2:#define _MIPS_ARCH_MIPS64R2 1 +// MIPS-ARCH-64R2:#define _MIPS_ISA _MIPS_ISA_MIPS64 +// MIPS-ARCH-64R2:#define __mips_isa_rev 2 // // Check MIPS float ABI macros //