llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-risc-v Author: Luke Lau (lukel97) <details> <summary>Changes</summary> In #<!-- -->77277, we would like to be able to reuse the logic for calculating the vscale_range in Flang. This is currently in clang::TargetInfo which is quite C specific, and given that only two targets implement getVScaleRange, it doesn't seem worthwhile trying to shoehorn clang::TargetInfo into Flang. This instead moves the logic into llvm/Frontend/Driver where it can be shared by both (provided that a RISCVISAInfo is passed in: we don't want to have to recompute it every time). --- Full diff: https://github.com/llvm/llvm-project/pull/77327.diff 5 Files Affected: - (modified) clang/lib/Basic/CMakeLists.txt (+1) - (modified) clang/lib/Basic/Targets/RISCV.cpp (+3-18) - (added) llvm/include/llvm/Frontend/Driver/RISCV.h (+27) - (modified) llvm/lib/Frontend/Driver/CMakeLists.txt (+1) - (added) llvm/lib/Frontend/Driver/RISCV.cpp (+37) ``````````diff diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index 2e218ba7c84cca..8ab960c7212f88 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS Support TargetParser FrontendOpenMP + FrontendDriver ) find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index 6bc57a83a2d5ae..b090a9b167a202 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Frontend/Driver/RISCV.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/RISCVTargetParser.h" #include <optional> @@ -321,24 +322,8 @@ bool RISCVTargetInfo::initFeatureMap( std::optional<std::pair<unsigned, unsigned>> RISCVTargetInfo::getVScaleRange(const LangOptions &LangOpts) const { - // 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) - VScaleMax = VScaleMin; - return std::pair<unsigned, unsigned>(VScaleMin ? VScaleMin : 1, VScaleMax); - } - - if (VScaleMin > 0) { - unsigned VScaleMax = ISAInfo->getMaxVLen() / llvm::RISCV::RVVBitsPerBlock; - return std::make_pair(VScaleMin, VScaleMax); - } - - return std::nullopt; + return llvm::driver::riscv::getVScaleRange(*ISAInfo, LangOpts.VScaleMin, + LangOpts.VScaleMax); } /// Return true if has this feature, need to sync with handleTargetFeatures. diff --git a/llvm/include/llvm/Frontend/Driver/RISCV.h b/llvm/include/llvm/Frontend/Driver/RISCV.h new file mode 100644 index 00000000000000..1f81f089087b51 --- /dev/null +++ b/llvm/include/llvm/Frontend/Driver/RISCV.h @@ -0,0 +1,27 @@ +//===--- RISCV.h ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines RISC-V frontend logic common to clang and flang +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_FRONTEND_DRIVER_RISCV_H +#define LLVM_FRONTEND_DRIVER_RISCV_H + +#include "llvm/Support/RISCVISAInfo.h" +#include <optional> + +namespace llvm::driver::riscv { + +std::optional<std::pair<unsigned, unsigned>> +getVScaleRange(const RISCVISAInfo &ISAInfo, unsigned ExplicitMin, + unsigned ExplicitMax); + +} // namespace llvm::driver::riscv + +#endif diff --git a/llvm/lib/Frontend/Driver/CMakeLists.txt b/llvm/lib/Frontend/Driver/CMakeLists.txt index 23de4994a300d8..ac0bc27a248a36 100644 --- a/llvm/lib/Frontend/Driver/CMakeLists.txt +++ b/llvm/lib/Frontend/Driver/CMakeLists.txt @@ -1,5 +1,6 @@ add_llvm_component_library(LLVMFrontendDriver CodeGenOptions.cpp + RISCV.cpp ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/Driver diff --git a/llvm/lib/Frontend/Driver/RISCV.cpp b/llvm/lib/Frontend/Driver/RISCV.cpp new file mode 100644 index 00000000000000..dfe07fb74550fd --- /dev/null +++ b/llvm/lib/Frontend/Driver/RISCV.cpp @@ -0,0 +1,37 @@ +//===--- RISCV.cpp - Shared RISC-V frontend logic -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/Frontend/Driver/RISCV.h" +#include "llvm/TargetParser/RISCVTargetParser.h" + +namespace llvm::driver::riscv { + +std::optional<std::pair<unsigned, unsigned>> +getVScaleRange(const RISCVISAInfo &ISAInfo, unsigned ExplicitMin, + unsigned ExplicitMax) { + // RISCV::RVVBitsPerBlock is 64. + unsigned VScaleMin = ISAInfo.getMinVLen() / RISCV::RVVBitsPerBlock; + + if (ExplicitMin || ExplicitMax) { + // Treat Zvl*b as a lower bound on vscale. + VScaleMin = std::max(VScaleMin, ExplicitMin); + unsigned VScaleMax = ExplicitMax; + if (VScaleMax != 0 && VScaleMax < VScaleMin) + VScaleMax = VScaleMin; + return std::pair<unsigned, unsigned>(VScaleMin ? VScaleMin : 1, VScaleMax); + } + + if (VScaleMin > 0) { + unsigned VScaleMax = ISAInfo.getMaxVLen() / RISCV::RVVBitsPerBlock; + return std::make_pair(VScaleMin, VScaleMax); + } + + return std::nullopt; +} + +} // namespace llvm::driver::riscv `````````` </details> https://github.com/llvm/llvm-project/pull/77327 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits