[RISCV] Make use of the required features in BuiltinInfo to store that V extension builtins require 'experimental-v'.

Use that to print the diagnostic in SemaChecking instead of
listing all of the builtins in a switch.

With the required features, IR generation will also be able
to error on this. Checking this here allows us to have a RISCV
focused error message.

Reviewed By: HsiangKai

Differential Revision: https://reviews.llvm.org/D97826
This commit is contained in:
Craig Topper 2021-03-03 16:21:23 -08:00
parent 584cb67d2d
commit 201ebf211f
3 changed files with 15 additions and 12 deletions

View File

@ -11,8 +11,12 @@
//
//===----------------------------------------------------------------------===//
#if defined(BUILTIN) && !defined(RISCVV_BUILTIN)
#define RISCVV_BUILTIN(ID, TYPE, ATTRS) BUILTIN(ID, TYPE, ATTRS)
#if defined(BUILTIN) && !defined(TARGET_BUILTIN)
# define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
#endif
#if defined(TARGET_BUILTIN) && !defined(RISCVV_BUILTIN)
#define RISCVV_BUILTIN(ID, TYPE, ATTRS) TARGET_BUILTIN(ID, TYPE, ATTRS, "experimental-v")
#endif
RISCVV_BUILTIN(__builtin_rvv_vadd_vv_i8m1_vl, "q8Scq8Scq8Scz", "n")

View File

@ -201,6 +201,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
const Builtin::Info RISCVTargetInfo::BuiltinInfo[] = {
#define BUILTIN(ID, TYPE, ATTRS) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
{#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE},
#include "clang/Basic/BuiltinsRISCV.def"
};

View File

@ -3392,16 +3392,13 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
switch (BuiltinID) {
default:
break;
#define RISCVV_BUILTIN(ID, TYPE, ATTRS) case RISCV::BI##ID:
#include "clang/Basic/BuiltinsRISCV.def"
if (!TI.hasFeature("experimental-v"))
return Diag(TheCall->getBeginLoc(), diag::err_riscvv_builtin_requires_v)
<< TheCall->getSourceRange();
break;
}
// CodeGenFunction can also detect this, but this gives a better error
// message.
StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
if (Features.find("experimental-v") != StringRef::npos &&
!TI.hasFeature("experimental-v"))
return Diag(TheCall->getBeginLoc(), diag::err_riscvv_builtin_requires_v)
<< TheCall->getSourceRange();
return false;
}