From a8f7d9dd926d61c92dbe194e9b6f51a9c015cea5 Mon Sep 17 00:00:00 2001 From: Yunzhong Gao Date: Tue, 24 Sep 2013 19:00:58 +0000 Subject: [PATCH] Adding -mtbm and -mno-tbm command line options to the clang front end for the x86 TBM instruction set. Also adding a __TBM__ macro if the TBM feature is enabled. Otherwise there should be no functionality change to existing features. Phabricator code review is located here: http://llvm-reviews.chandlerc.com/D1693 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191326 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 2 ++ lib/Basic/Targets.cpp | 15 +++++++++++++-- test/Preprocessor/predefined-arch-macros.c | 2 ++ test/Preprocessor/x86_target_features.c | 10 +++++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 419719d06e..962ead5757 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -979,6 +979,7 @@ def mno_rdrnd : Flag<["-"], "mno-rdrnd">, Group; def mno_bmi : Flag<["-"], "mno-bmi">, Group; def mno_bmi2 : Flag<["-"], "mno-bmi2">, Group; def mno_popcnt : Flag<["-"], "mno-popcnt">, Group; +def mno_tbm : Flag<["-"], "mno-tbm">, Group; def mno_fma4 : Flag<["-"], "mno-fma4">, Group; def mno_fma : Flag<["-"], "mno-fma">, Group; def mno_xop : Flag<["-"], "mno-xop">, Group; @@ -1038,6 +1039,7 @@ def mrdrnd : Flag<["-"], "mrdrnd">, Group; def mbmi : Flag<["-"], "mbmi">, Group; def mbmi2 : Flag<["-"], "mbmi2">, Group; def mpopcnt : Flag<["-"], "mpopcnt">, Group; +def mtbm : Flag<["-"], "mtbm">, Group; def mfma4 : Flag<["-"], "mfma4">, Group; def mfma : Flag<["-"], "mfma">, Group; def mxop : Flag<["-"], "mxop">, Group; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index a9512d2fe1..f1a1454410 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -1586,6 +1586,7 @@ class X86TargetInfo : public TargetInfo { bool HasRTM; bool HasPRFCHW; bool HasRDSEED; + bool HasTBM; bool HasFMA; bool HasF16C; bool HasAVX512CD, HasAVX512ER, HasAVX512PF; @@ -1748,8 +1749,8 @@ public: : TargetInfo(Triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow), XOPLevel(NoXOP), HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasRDRND(false), HasBMI(false), HasBMI2(false), HasPOPCNT(false), - HasRTM(false), HasPRFCHW(false), HasRDSEED(false), HasFMA(false), - HasF16C(false), HasAVX512CD(false), HasAVX512ER(false), + HasRTM(false), HasPRFCHW(false), HasRDSEED(false), HasTBM(false), + HasFMA(false), HasF16C(false), HasAVX512CD(false), HasAVX512ER(false), HasAVX512PF(false), HasSHA(false), CPU(CK_Generic), FPMath(FP_Default) { BigEndian = false; LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; @@ -2127,6 +2128,7 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap &Features) const { setFeatureEnabledImpl(Features, "bmi", true); setFeatureEnabledImpl(Features, "fma", true); setFeatureEnabledImpl(Features, "f16c", true); + setFeatureEnabledImpl(Features, "tbm", true); break; case CK_C3_2: setFeatureEnabledImpl(Features, "sse", true); @@ -2367,6 +2369,11 @@ bool X86TargetInfo::HandleTargetFeatures(std::vector &Features, continue; } + if (Feature == "tbm") { + HasTBM = true; + continue; + } + if (Feature == "fma") { HasFMA = true; continue; @@ -2642,6 +2649,9 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, if (HasRDSEED) Builder.defineMacro("__RDSEED__"); + if (HasTBM) + Builder.defineMacro("__TBM__"); + switch (XOPLevel) { case XOP: Builder.defineMacro("__XOP__"); @@ -2749,6 +2759,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const { .Case("bmi2", HasBMI2) .Case("fma", HasFMA) .Case("fma4", XOPLevel >= FMA4) + .Case("tbm", HasTBM) .Case("lzcnt", HasLZCNT) .Case("rdrnd", HasRDRND) .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow) diff --git a/test/Preprocessor/predefined-arch-macros.c b/test/Preprocessor/predefined-arch-macros.c index d21ba5a1b1..bcfe90f29c 100644 --- a/test/Preprocessor/predefined-arch-macros.c +++ b/test/Preprocessor/predefined-arch-macros.c @@ -1326,6 +1326,7 @@ // CHECK_BDVER2_M32: #define __SSE_MATH__ 1 // CHECK_BDVER2_M32: #define __SSE__ 1 // CHECK_BDVER2_M32: #define __SSSE3__ 1 +// CHECK_BDVER2_M32: #define __TBM__ 1 // CHECK_BDVER2_M32: #define __XOP__ 1 // CHECK_BDVER2_M32: #define __bdver2 1 // CHECK_BDVER2_M32: #define __bdver2__ 1 @@ -1356,6 +1357,7 @@ // CHECK_BDVER2_M64: #define __SSE_MATH__ 1 // CHECK_BDVER2_M64: #define __SSE__ 1 // CHECK_BDVER2_M64: #define __SSSE3__ 1 +// CHECK_BDVER2_M64: #define __TBM__ 1 // CHECK_BDVER2_M64: #define __XOP__ 1 // CHECK_BDVER2_M64: #define __amd64 1 // CHECK_BDVER2_M64: #define __amd64__ 1 diff --git a/test/Preprocessor/x86_target_features.c b/test/Preprocessor/x86_target_features.c index 0cbda296ab..2d4e316d47 100644 --- a/test/Preprocessor/x86_target_features.c +++ b/test/Preprocessor/x86_target_features.c @@ -202,4 +202,12 @@ // SHANOSSSE2-NOT: #define __SHA__ 1 // SHANOSSSE2-NOT: #define __SSE2__ 1 -// SHANOSSSE2-NOT: #define __SSE3__ 1 \ No newline at end of file +// SHANOSSSE2-NOT: #define __SSE3__ 1 + +// RUN: %clang -target i386-unknown-unknown -march=atom -mtbm -x c -E -dM -o - %s | FileCheck --check-prefix=TBM %s + +// TBM: #define __TBM__ 1 + +// RUN: %clang -target i386-unknown-unknown -march=bdver2 -mno-tbm -x c -E -dM -o - %s | FileCheck --check-prefix=NOTBM %s + +// NOTBM-NOT: #define __TBM__ 1 -- 2.40.0