diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 9ff54083c923b..8fa3563334a31 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -465,21 +465,36 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, // set of options. static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags, const std::vector &FeaturesVec) { - // Cannot allow soft-float with Altivec. - if (llvm::is_contained(FeaturesVec, "-hard-float") && - llvm::is_contained(FeaturesVec, "+altivec")) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float" - << "-maltivec"; + auto FindVSXSubfeature = [&](StringRef Feature, StringRef SubOption, + StringRef Option) { + if (llvm::is_contained(FeaturesVec, Feature)) { + Diags.Report(diag::err_opt_not_valid_with_opt) << SubOption << Option; + return true; + } return false; - } + }; - // Cannot allow soft-float with VSX. - if (llvm::is_contained(FeaturesVec, "-hard-float") && - llvm::is_contained(FeaturesVec, "+vsx")) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float" - << "-mvsx"; - return false; + // Cannot allow soft-float with VSX, Altivec, or any + // VSX subfeatures. + bool Found = false; + if (llvm::is_contained(FeaturesVec, "-hard-float")) { + Found |= FindVSXSubfeature("+vsx", "-mvsx", "-msoft-float"); + Found |= FindVSXSubfeature("+altivec", "-maltivec", "-msoft-float"); + Found |= + FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-msoft-float"); + Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-msoft-float"); + Found |= FindVSXSubfeature("+float128", "-mfloat128", "-msoft-float"); + Found |= + FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-msoft-float"); + Found |= FindVSXSubfeature("+paired-vector-memops", + "-mpaired-vector-memops", "-msoft-float"); + Found |= FindVSXSubfeature("+mma", "-mmma", "-msoft-float"); + Found |= FindVSXSubfeature("+crypto", "-mcrypto", "-msoft-float"); + Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector", + "-msoft-float"); } + if (Found) + return false; // Cannot allow VSX with no Altivec. if (llvm::is_contained(FeaturesVec, "+vsx") && @@ -493,21 +508,14 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags, if (!llvm::is_contained(FeaturesVec, "-vsx")) return true; - auto FindVSXSubfeature = [&](StringRef Feature, StringRef Option) { - if (llvm::is_contained(FeaturesVec, Feature)) { - Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx"; - return true; - } - return false; - }; - - bool Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector"); - Found |= FindVSXSubfeature("+direct-move", "-mdirect-move"); - Found |= FindVSXSubfeature("+float128", "-mfloat128"); - Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector"); - Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops"); - Found |= FindVSXSubfeature("+mma", "-mmma"); - Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector"); + Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector", "-mno-vsx"); + Found |= FindVSXSubfeature("+direct-move", "-mdirect-move", "-mno-vsx"); + Found |= FindVSXSubfeature("+float128", "-mfloat128", "-mno-vsx"); + Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector", "-mno-vsx"); + Found |= FindVSXSubfeature("+paired-vector-memops", "-mpaired-vector-memops", + "-mno-vsx"); + Found |= FindVSXSubfeature("+mma", "-mmma", "-mno-vsx"); + Found |= FindVSXSubfeature("+power10-vector", "-mpower10-vector", "-mno-vsx"); // Return false if any vsx subfeatures was found. return !Found; @@ -689,7 +697,6 @@ bool PPCTargetInfo::initFeatureMap( Diags.Report(diag::err_opt_not_valid_with_opt) << "-mprivileged" << CPU; return false; } - return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } @@ -779,13 +786,16 @@ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap &Features, } else { if (Name == "spe") Features["efpu2"] = false; - // If we're disabling altivec or vsx go ahead and disable all of the vsx - // features. - if ((Name == "altivec") || (Name == "vsx")) + // If we're disabling altivec, hard-float, or vsx go ahead and disable all + // of the vsx features. + if ((Name == "altivec") || (Name == "vsx") || (Name == "hard-float")) { + if (Name != "vsx") + Features["altivec"] = Features["crypto"] = false; Features["vsx"] = Features["direct-move"] = Features["power8-vector"] = Features["float128"] = Features["power9-vector"] = Features["paired-vector-memops"] = Features["mma"] = Features["power10-vector"] = false; + } if (Name == "power8-vector") Features["power9-vector"] = Features["paired-vector-memops"] = Features["mma"] = Features["power10-vector"] = false; diff --git a/clang/test/Driver/ppc-dependent-options.cpp b/clang/test/Driver/ppc-dependent-options.cpp index 414ed1e70bb30..46d6beafbc174 100644 --- a/clang/test/Driver/ppc-dependent-options.cpp +++ b/clang/test/Driver/ppc-dependent-options.cpp @@ -89,6 +89,34 @@ // RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \ // RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mpower8-vector %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P8VEC + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mpower9-vector %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P9VEC + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mpower10-vector %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-P10VEC + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mdirect-move %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-DIRECTMOVE + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mmma %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-MMA + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mpaired-vector-memops %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-PAIREDVECMEMOP + +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -std=c++11 -msoft-float -mcrypto %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-CRYPTO + #ifdef __VSX__ static_assert(false, "VSX enabled"); #endif @@ -126,5 +154,13 @@ static_assert(false, "Neither enabled"); // CHECK-NVSX: Neither enabled // CHECK-VSX: VSX enabled // CHECK-NALTI-VSX: error: option '-mvsx' cannot be specified with '-mno-altivec' -// CHECK-SOFTFLT-ALTI: error: option '-msoft-float' cannot be specified with '-maltivec' -// CHECK-SOFTFLT-VSX: error: option '-msoft-float' cannot be specified with '-mvsx' +// CHECK-SOFTFLT-ALTI: error: option '-maltivec' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-VSX: error: option '-mvsx' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-FLOAT128: error: option '-mfloat128' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-P8VEC: error: option '-mpower8-vector' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-P9VEC: error: option '-mpower9-vector' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-P10VEC: error: option '-mpower10-vector' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-DIRECTMOVE: error: option '-mdirect-move' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-MMA: error: option '-mmma' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-PAIREDVECMEMOP: error: option '-mpaired-vector-memops' cannot be specified with '-msoft-float' +// CHECK-SOFTFLT-CRYPTO: error: option '-mcrypto' cannot be specified with '-msoft-float' diff --git a/clang/test/Driver/ppc-soft-float.c b/clang/test/Driver/ppc-soft-float.c new file mode 100644 index 0000000000000..18d768aec0ded --- /dev/null +++ b/clang/test/Driver/ppc-soft-float.c @@ -0,0 +1,28 @@ +// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -msoft-float -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKSOFT +// RUN: %clang -target powerpc64-unknown-unknown -mcpu=pwr10 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECKNOSOFT + +int main () { + return 0; +} + +// CHECKSOFT-DAG: -hard-float +// CHECKSOFT-DAG: -vsx +// CHECKSOFT-DAG: -altivec +// CHECKSOFT-DAG: -direct-move +// CHECKSOFT-DAG: -float128 +// CHECKSOFT-DAG: -mma +// CHECKSOFT-DAG: -paired-vector-memops +// CHECKSOFT-DAG: -power10-vector +// CHECKSOFT-DAG: -power9-vector +// CHECKSOFT-DAG: -power8-vector +// CHECKSOFT-DAG: -crypto + +// CHECKNOSOFT-DAG: +vsx +// CHECKNOSOFT-DAG: +altivec +// CHECKNOSOFT-DAG: +direct-move +// CHECKNOSOFT-DAG: +mma +// CHECKNOSOFT-DAG: +paired-vector-memops +// CHECKNOSOFT-DAG: +power10-vector +// CHECKNOSOFT-DAG: +power9-vector +// CHECKNOSOFT-DAG: +power8-vector +// CHECKNOSOFT-DAG: +crypto