diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -111,7 +111,11 @@ DiagnosticsEngine &Diags) override; bool hasExtIntType() const override { return true; } + + Optional> + getVScaleRange(const LangOptions &LangOpts) const override; }; + class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { public: RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -335,6 +335,20 @@ return true; } +Optional> +RISCVTargetInfo::getVScaleRange(const LangOptions &LangOpts) const { + if (!HasV) + return None; + // VLEN is defined in v0.10 to be at least 128 bits and at most 65536 bits, + // and vscale is VLEN/64. + // FIXME: v1.0 removes the minimum value. + // FIXME: The backend can be told about the more specific minimum/maximum + // VLEN but the frontend can't access this information. + unsigned VLENMin = 128; + unsigned VLENMax = 65536; + return std::make_pair(VLENMin / 64, VLENMax / 64); +} + bool RISCV32TargetInfo::isValidCPUName(StringRef Name) const { return llvm::RISCV::checkCPUKind(llvm::RISCV::parseCPUKind(Name), /*Is64Bit=*/false); diff --git a/clang/test/CodeGen/riscv-vscale-range.c b/clang/test/CodeGen/riscv-vscale-range.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/riscv-vscale-range.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple riscv64 -target-feature +experimental-v -S -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: @func() #0 +// CHECK: attributes #0 = { {{.*}} vscale_range(2,1024) {{.*}} } +void func() {}