[flang-commits] [flang] [Flang][RISCV] Set vscale_range based off zvl*b (PR #77277)
Philip Reames via flang-commits
flang-commits at lists.llvm.org
Wed Jan 10 10:15:32 PST 2024
================
@@ -712,13 +714,55 @@ void CodeGenAction::lowerHLFIRToFIR() {
static std::optional<std::pair<unsigned, unsigned>>
getVScaleRange(CompilerInstance &ci) {
const auto &langOpts = ci.getInvocation().getLangOpts();
- if (langOpts.VScaleMin || langOpts.VScaleMax)
- return std::pair<unsigned, unsigned>(
- langOpts.VScaleMin ? langOpts.VScaleMin : 1, langOpts.VScaleMax);
+ const auto targetOpts = ci.getInvocation().getTargetOpts();
+ const llvm::Triple triple(targetOpts.triple);
+
+ if (triple.isAArch64()) {
+ if (langOpts.VScaleMin || langOpts.VScaleMax)
+ return std::pair<unsigned, unsigned>(
+ langOpts.VScaleMin ? langOpts.VScaleMin : 1, langOpts.VScaleMax);
+
+ std::string featuresStr = ci.getTargetFeatures();
+ if (featuresStr.find("+sve") != std::string::npos)
+ return std::pair<unsigned, unsigned>(1, 16);
+ } else if (triple.isRISCV()) {
+ auto parseResult = llvm::RISCVISAInfo::parseFeatures(
+ triple.isRISCV64() ? 64 : 32, targetOpts.featuresAsWritten);
+ if (!parseResult) {
+ std::string buffer;
+ llvm::raw_string_ostream outputErrMsg(buffer);
+ handleAllErrors(parseResult.takeError(), [&](llvm::StringError &errMsg) {
+ outputErrMsg << errMsg.getMessage();
+ });
+ ci.getDiagnostics().Report(clang::diag::err_invalid_feature_combination)
+ << outputErrMsg.str();
+ return std::nullopt;
+ }
+
+ llvm::RISCVISAInfo *const isaInfo = parseResult->get();
- std::string featuresStr = ci.getTargetFeatures();
- if (featuresStr.find("+sve") != std::string::npos)
- return std::pair<unsigned, unsigned>(1, 16);
+ // RISCV::RVVBitsPerBlock is 64.
+ unsigned vscaleMin = isaInfo->getMinVLen() / llvm::RISCV::RVVBitsPerBlock;
+
+ if (langOpts.VScaleMin || langOpts.VScaleMax) {
+ // Treat Zvl*b as a lower bound on vscale.
+ vscaleMin = std::max(vscaleMin, langOpts.VScaleMin);
+ unsigned vscaleMax = langOpts.VScaleMax;
+ if (vscaleMax != 0 && vscaleMax < vscaleMin)
----------------
preames wrote:
This case feels like it should be a user error message. I was somewhat tempted to ask for that in this review, and then realized that consistent behavior with clang was probably more important overall. Might be something work exploring (for both flang and clang) in a follow up review.
https://github.com/llvm/llvm-project/pull/77277
More information about the flang-commits
mailing list