Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RVV 0.7.1] Add pragma about rvv 0.7.1 #1

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,9 @@ class Sema final {
/// Indicate RISC-V SiFive vector builtin functions enabled or not.
bool DeclareRISCVSiFiveVectorBuiltins = false;

/// Indicate RISC-V vector 0.7.1 builtin functions enabled or not.
bool DeclareRISCVV0p7Builtins = false;

private:
std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager;

Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Parse/ParsePragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4042,10 +4042,11 @@ void PragmaRISCVHandler::HandlePragma(Preprocessor &PP,

PP.Lex(Tok);
II = Tok.getIdentifierInfo();
if (!II || !(II->isStr("vector") || II->isStr("sifive_vector"))) {
if (!II || !(II->isStr("vector") || II->isStr("sifive_vector") ||
II->isStr("vector0p7"))) {
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument)
<< PP.getSpelling(Tok) << "riscv" << /*Expected=*/true
<< "'vector' or 'sifive_vector'";
<< "'vector', 'sifive_vector' or 'vector0p7'";
return;
}

Expand All @@ -4060,4 +4061,6 @@ void PragmaRISCVHandler::HandlePragma(Preprocessor &PP,
Actions.DeclareRISCVVBuiltins = true;
else if (II->isStr("sifive_vector"))
Actions.DeclareRISCVSiFiveVectorBuiltins = true;
else if (II->isStr("vector0p7"))
Actions.DeclareRISCVV0p7Builtins = true;
}
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ bool Sema::LookupBuiltin(LookupResult &R) {
}
}

if (DeclareRISCVVBuiltins || DeclareRISCVSiFiveVectorBuiltins) {
if (DeclareRISCVVBuiltins || DeclareRISCVSiFiveVectorBuiltins ||
DeclareRISCVV0p7Builtins) {
if (!RVIntrinsicManager)
RVIntrinsicManager = CreateRISCVIntrinsicManager(*this);

Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/riscv-arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@
// RUN: FileCheck -check-prefix=RV32-V-GOODVERS %s
// RV32-V-GOODVERS: "-target-feature" "+v"

// RUN: %clang --target=riscv32-unknown-elf -march=rv32iv0p7 -### %s -c 2>&1 | \
// RUN: FileCheck -check-prefix=RV32-V0P7-GOODVERS %s
// RV32-V0P7-GOODVERS: "-target-feature" "+v0p7"

// RUN: %clang --target=riscv32-unknown-elf -march=rv32iv1p0_zvl32b0p1 -### %s -c 2>&1 | \
// RUN: FileCheck -check-prefix=RV32-ZVL-BADVERS %s
// RV32-ZVL-BADVERS: error: invalid arch name 'rv32iv1p0_zvl32b0p1'
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Preprocessor/riscv-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@
// CHECK-V-EXT: __riscv_v 1000000{{$}}
// CHECK-V-EXT: __riscv_vector 1

// RUN: %clang -target riscv32-unknown-linux-gnu \
// RUN: -march=rv32iv0p7 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-V0P7-EXT %s
// RUN: %clang -target riscv64-unknown-linux-gnu \
// RUN: -march=rv64iv0p7 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-V0P7-EXT %s
// CHECK-V0P7-EXT: __riscv_v 7000{{$}}
// CHECK-V0P7-EXT: __riscv_vector 1

// RUN: %clang -target riscv32-unknown-linux-gnu \
// RUN: -march=rv32izfhmin1p0 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZFHMIN-EXT %s
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Sema/riscv-bad-intrinsic-pragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: 2>&1 | FileCheck %s

#pragma clang riscv intrinsic vvvv
// CHECK: warning: unexpected argument 'vvvv' to '#pragma riscv'; expected 'vector' or 'sifive_vector' [-Wignored-pragmas]
// CHECK: warning: unexpected argument 'vvvv' to '#pragma riscv'; expected 'vector', 'sifive_vector' or 'vector0p7' [-Wignored-pragmas]

#pragma clang riscv what + 3241
// CHECK: warning: unexpected argument 'what' to '#pragma riscv'; expected 'intrinsic' [-Wignored-pragmas]
Expand Down
67 changes: 55 additions & 12 deletions llvm/lib/Support/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
{"svpbmt", RISCVExtensionVersion{1, 0}},

{"v", RISCVExtensionVersion{1, 0}},
{"v", RISCVExtensionVersion{0, 7}},

// vendor-defined ('X') extensions
{"xcvbitmanip", RISCVExtensionVersion{1, 0}},
Expand Down Expand Up @@ -258,6 +259,18 @@ findDefaultVersion(StringRef ExtName) {
return std::nullopt;
}

static const RISCVSupportedExtension *
findExtensionIn(llvm::ArrayRef<RISCVSupportedExtension> ExtensionInfos,
StringRef Ext, unsigned MajorVersion, unsigned MinorVersion) {
auto Range = std::equal_range(ExtensionInfos.begin(), ExtensionInfos.end(),
Ext, LessExtName());
for (auto I = Range.first, E = Range.second; I != E; ++I)
if (I->Version.Major == MajorVersion && I->Version.Minor == MinorVersion) {
return I;
}
return ExtensionInfos.end();
}

void RISCVISAInfo::addExtension(StringRef ExtName, unsigned MajorVersion,
unsigned MinorVersion) {
RISCVExtensionInfo Ext;
Expand Down Expand Up @@ -324,11 +337,8 @@ bool RISCVISAInfo::isSupportedExtension(StringRef Ext, unsigned MajorVersion,
unsigned MinorVersion) {
for (auto ExtInfo : {ArrayRef(SupportedExtensions),
ArrayRef(SupportedExperimentalExtensions)}) {
auto Range =
std::equal_range(ExtInfo.begin(), ExtInfo.end(), Ext, LessExtName());
for (auto I = Range.first, E = Range.second; I != E; ++I)
if (I->Version.Major == MajorVersion && I->Version.Minor == MinorVersion)
return true;
return findExtensionIn(ExtInfo, Ext, MajorVersion, MinorVersion) !=
ExtInfo.end();
}

return false;
Expand Down Expand Up @@ -428,7 +438,18 @@ void RISCVISAInfo::toFeatures(
if (isExperimentalExtension(ExtName)) {
Features.push_back(StrAlloc("+experimental-" + ExtName));
} else {
Features.push_back(StrAlloc("+" + ExtName));
auto Major = Ext.second.MajorVersion;
auto Minor = Ext.second.MinorVersion;
if (ExtName == "v" && Major == 0 && Minor == 7) {
// Append the version number only when 0.7.1 is specified.
// Otherwise, do not change anything, for the following reasons:
// - Better compatibility with upstream LLVM.
// - Most of the RISC-V code assumes the default version of V is 1.0.
// NOTE: keep this in sync with RISCVISAInfo::parseFeatures
Features.push_back(
StrAlloc("+" + ExtName + utostr(Major) + "p" + utostr(Minor)));
} else
Features.push_back(StrAlloc("+" + ExtName));
}
}
if (AddAllExtensions) {
Expand Down Expand Up @@ -570,8 +591,23 @@ RISCVISAInfo::parseFeatures(unsigned XLen,
auto ExtensionInfos = Experimental
? ArrayRef(SupportedExperimentalExtensions)
: ArrayRef(SupportedExtensions);
auto ExtensionInfoIterator =
llvm::lower_bound(ExtensionInfos, ExtName, LessExtName());
auto ExtensionInfoIterator = ExtensionInfos.end();

if (ExtName.startswith("v")) {
auto Major = 1u;
auto Minor = 0u;
auto Versions = ExtName.drop_front(1);
if (Versions.size() == 3) {
Major = Versions[0] - '0';
Minor = Versions[2] - '0';
ExtName = "v"; // stripping the trailing version
}

ExtensionInfoIterator =
findExtensionIn(ExtensionInfos, ExtName, Major, Minor);
} else
ExtensionInfoIterator =
llvm::lower_bound(ExtensionInfos, ExtName, LessExtName());

// Not all features is related to ISA extension, like `relax` or
// `save-restore`, skip those feature.
Expand Down Expand Up @@ -1214,10 +1250,17 @@ std::vector<std::string> RISCVISAInfo::toFeatureVector() const {
continue;
if (!isSupportedExtension(ExtName))
continue;
std::string Feature = isExperimentalExtension(ExtName)
? "+experimental-" + ExtName
: "+" + ExtName;
FeatureVector.push_back(Feature);
auto Major = Ext.second.MajorVersion;
auto Minor = Ext.second.MinorVersion;
if (ExtName == "v" && Major == 0 && Minor == 7) {
std::string Feature = "+" + ExtName + utostr(Major) + "p" + utostr(Minor);
FeatureVector.push_back(Feature);
} else {
std::string Feature = isExperimentalExtension(ExtName)
? "+experimental-" + ExtName
: "+" + ExtName;
FeatureVector.push_back(Feature);
}
}
return FeatureVector;
}
Expand Down