vhscampos created this revision. Herald added subscribers: cfe-commits, danielkiss, kristof.beyls. Herald added a project: clang. vhscampos added a child revision: D82949: [Driver][ARM] Disable bf16 when hardware FP support is missing. vhscampos added a reviewer: chill.
A list of target features is disabled when there is no hardware floating-point support. This is the case when one of the following options is passed to clang: - -mfloat-abi=soft - -mfpu=none This option list is missing, however, the extension "+nofp" that can be specified in -march flags, such as "-march=armv8-a+nofp". This patch also disables unsupported target features when nofp is passed to -march. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D82948 Files: clang/lib/Driver/ToolChains/Arch/ARM.cpp Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -285,6 +285,35 @@ (NoMVE == F.rend() || std::distance(MVE, NoMVE) > 0); } +static void appendNoFPUnsupportedFeatures(const arm::FloatABI ABI, + const unsigned FPUID, + const StringRef &ArchName, + std::vector<StringRef> &Features) { + auto checkFPDisabledInArchName = [](const StringRef &ArchName) { + SmallVector<StringRef, 8> Split; + ArchName.split(Split, '+', -1, false); + return llvm::any_of( + Split, [](const StringRef &Extension) { return Extension == "nofp"; }); + }; + + if (ABI == arm::FloatABI::Soft) { + llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features); + + // Disable all features relating to hardware FP, not already disabled by the + // above call. + Features.insert(Features.end(), + {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"}); + } else if (FPUID == llvm::ARM::FK_NONE || + checkFPDisabledInArchName(ArchName)) { + // -mfpu=none or -march=armvX+nofp is *very* similar to -mfloat-abi=soft, + // only that it should not disable MVE-I. + Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"}); + if (!hasIntegerMVE(Features)) { + Features.emplace_back("-fpregs"); + } + } +} + void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, ArgStringList &CmdArgs, std::vector<StringRef> &Features, bool ForAS) { @@ -455,23 +484,10 @@ Features.push_back("+fullfp16"); } - // Setting -msoft-float/-mfloat-abi=soft effectively disables the FPU (GCC - // ignores the -mfpu options in this case). - // Note that the ABI can also be set implicitly by the target selected. - if (ABI == arm::FloatABI::Soft) { - llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features); - - // Disable all features relating to hardware FP, not already disabled by the - // above call. - Features.insert(Features.end(), - {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"}); - } else if (FPUID == llvm::ARM::FK_NONE) { - // -mfpu=none is *very* similar to -mfloat-abi=soft, only that it should not - // disable MVE-I. - Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"}); - if (!hasIntegerMVE(Features)) - Features.emplace_back("-fpregs"); - } + // Setting -msoft-float/-mfloat-abi=soft, -mfpu=none, or adding +nofp to + // -march effectively disables the FPU (GCC ignores the -mfpu options in this + // case). Note that the ABI can also be set implicitly by the target selected. + appendNoFPUnsupportedFeatures(ABI, FPUID, ArchName, Features); // En/disable crc code generation. if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -285,6 +285,35 @@ (NoMVE == F.rend() || std::distance(MVE, NoMVE) > 0); } +static void appendNoFPUnsupportedFeatures(const arm::FloatABI ABI, + const unsigned FPUID, + const StringRef &ArchName, + std::vector<StringRef> &Features) { + auto checkFPDisabledInArchName = [](const StringRef &ArchName) { + SmallVector<StringRef, 8> Split; + ArchName.split(Split, '+', -1, false); + return llvm::any_of( + Split, [](const StringRef &Extension) { return Extension == "nofp"; }); + }; + + if (ABI == arm::FloatABI::Soft) { + llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features); + + // Disable all features relating to hardware FP, not already disabled by the + // above call. + Features.insert(Features.end(), + {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"}); + } else if (FPUID == llvm::ARM::FK_NONE || + checkFPDisabledInArchName(ArchName)) { + // -mfpu=none or -march=armvX+nofp is *very* similar to -mfloat-abi=soft, + // only that it should not disable MVE-I. + Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"}); + if (!hasIntegerMVE(Features)) { + Features.emplace_back("-fpregs"); + } + } +} + void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, ArgStringList &CmdArgs, std::vector<StringRef> &Features, bool ForAS) { @@ -455,23 +484,10 @@ Features.push_back("+fullfp16"); } - // Setting -msoft-float/-mfloat-abi=soft effectively disables the FPU (GCC - // ignores the -mfpu options in this case). - // Note that the ABI can also be set implicitly by the target selected. - if (ABI == arm::FloatABI::Soft) { - llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features); - - // Disable all features relating to hardware FP, not already disabled by the - // above call. - Features.insert(Features.end(), - {"-dotprod", "-fp16fml", "-mve", "-mve.fp", "-fpregs"}); - } else if (FPUID == llvm::ARM::FK_NONE) { - // -mfpu=none is *very* similar to -mfloat-abi=soft, only that it should not - // disable MVE-I. - Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-mve.fp"}); - if (!hasIntegerMVE(Features)) - Features.emplace_back("-fpregs"); - } + // Setting -msoft-float/-mfloat-abi=soft, -mfpu=none, or adding +nofp to + // -march effectively disables the FPU (GCC ignores the -mfpu options in this + // case). Note that the ABI can also be set implicitly by the target selected. + appendNoFPUnsupportedFeatures(ABI, FPUID, ArchName, Features); // En/disable crc code generation. if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits