Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2016,8 +2016,8 @@ HelpText<"Disallow generation of data access to code sections (ARM only)">; def mno_execute_only : Flag<["-"], "mno-execute-only">, Group, HelpText<"Allow generation of data access to code sections (ARM only)">; -def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, Values<"soft, cp15">, - HelpText<"Read thread pointer from coprocessor register (ARM only)">; +def mtp_mode_EQ : Joined<["-"], "mtp=">, Group, Values<"soft,cp15,el0,el1,el2,el3">, + HelpText<"Thread pointer access method (AArch32/AArch64 only)">; def mpure_code : Flag<["-"], "mpure-code">, Alias; // Alias for GCC compatibility def mno_pure_code : Flag<["-"], "mno-pure-code">, Alias; def mtvos_version_min_EQ : Joined<["-"], "mtvos-version-min=">, Group; Index: lib/Driver/ToolChains/Arch/AArch64.cpp =================================================================== --- lib/Driver/ToolChains/Arch/AArch64.cpp +++ lib/Driver/ToolChains/Arch/AArch64.cpp @@ -194,6 +194,18 @@ Features.push_back("-neon"); } + if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) { + StringRef Mtp = A->getValue(); + if (Mtp == "el3") + Features.push_back("+tpidr-el3"); + else if (Mtp == "el2") + Features.push_back("+tpidr-el2"); + else if (Mtp == "el1") + Features.push_back("+tpidr-el1"); + else if (Mtp != "el0") + D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args); + } + // En/disable crc if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) { if (A->getOption().matches(options::OPT_mcrc)) Index: test/Driver/clang-translation.c =================================================================== --- test/Driver/clang-translation.c +++ test/Driver/clang-translation.c @@ -120,6 +120,36 @@ // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s // ARMv7_THREAD_POINTER_NON-NOT: "-target-feature" "+read-tp-hard" +// RUN: %clang -target aarch64-linux -### -S %s -arch armv8a 2>&1 | \ +// RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_NON %s +// ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el1" +// ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el2" +// ARMv8_THREAD_POINTER_NON-NOT: "-target-feature" "+tpidr-el3" + +// RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el0 2>&1 | \ +// RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL0 %s +// ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el1" +// ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el2" +// ARMv8_THREAD_POINTER_EL0-NOT: "-target-feature" "+tpidr-el3" + +// RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el1 2>&1 | \ +// RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL1 %s +// ARMv8_THREAD_POINTER_EL1: "-target-feature" "+tpidr-el1" +// ARMv8_THREAD_POINTER_EL1-NOT: "-target-feature" "+tpidr-el2" +// ARMv8_THREAD_POINTER_EL1-NOT: "-target-feature" "+tpidr-el3" + +// RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el2 2>&1 | \ +// RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL2 %s +// ARMv8_THREAD_POINTER_EL2-NOT: "-target-feature" "+tpidr-el1" +// ARMv8_THREAD_POINTER_EL2: "-target-feature" "+tpidr-el2" +// ARMv8_THREAD_POINTER_EL2-NOT: "-target-feature" "+tpidr-el3" + +// RUN: %clang -target aarch64-linux -### -S %s -arch armv8a -mtp=el3 2>&1 | \ +// RUN: FileCheck -check-prefix=ARMv8_THREAD_POINTER_EL3 %s +// ARMv8_THREAD_POINTER_EL3-NOT: "-target-feature" "+tpidr-el1" +// ARMv8_THREAD_POINTER_EL3-NOT: "-target-feature" "+tpidr-el2" +// ARMv8_THREAD_POINTER_EL3: "-target-feature" "+tpidr-el3" + // RUN: %clang -target powerpc64-unknown-linux-gnu \ // RUN: -### -S %s -mcpu=G5 2>&1 | FileCheck -check-prefix=PPCG5 %s // PPCG5: clang