Index: clang/include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticDriverKinds.td +++ clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -118,6 +118,8 @@ "invalid thread pointer reading mode '%0'">; def err_drv_missing_arg_mtp : Error< "missing argument to '%0'">; +def err_drv_invalid_mtpidr : Error< + "invalid thread pointer exception level '%0'">; def err_drv_invalid_libcxx_deployment : Error< "invalid deployment target for -stdlib=libc++ (requires %0 or later)">; def err_drv_invalid_argument_to_fdebug_prefix_map : Error< Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2152,6 +2152,8 @@ foreach i = {1-7,9-15,18,20-28} in def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group, HelpText<"Reserve the "#i#" register (AArch64 only)">; +def mtpidr_EQ : Joined<["-"], "mtpidr=">, Group, Values<"el0,el1,el2,el3">, + HelpText<"Read thread pointer for specified exception level (AArch64 only)">; foreach i = {8-15,18} in def fcall_saved_x#i : Flag<["-"], "fcall-saved-x"#i>, Group, Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -194,6 +194,18 @@ Features.push_back("-neon"); } + if (Arg *A = Args.getLastArg(options::OPT_mtpidr_EQ)) { + StringRef Mtpidr = A->getValue(); + if (Mtpidr == "el3") + Features.push_back("+tpidr-el3"); + else if (Mtpidr == "el2") + Features.push_back("+tpidr-el2"); + else if (Mtpidr == "el1") + Features.push_back("+tpidr-el1"); + else if (Mtpidr != "el0") + D.Diag(diag::err_drv_invalid_mtpidr) << 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: clang/test/Driver/clang-translation.c =================================================================== --- clang/test/Driver/clang-translation.c +++ clang/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 -mtpidr=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 -mtpidr=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 -mtpidr=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 -mtpidr=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