Skip to content

[RISCV] Deduplicate version struct in RISCVISAInfo. NFC #77645

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

Merged
merged 3 commits into from
Jan 11, 2024
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
5 changes: 2 additions & 3 deletions clang/lib/Basic/Targets/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
auto ExtName = Extension.first;
auto ExtInfo = Extension.second;

Builder.defineMacro(
Twine("__riscv_", ExtName),
Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
Builder.defineMacro(Twine("__riscv_", ExtName),
Twine(getVersionValue(ExtInfo.Major, ExtInfo.Minor)));
}

if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ static void mergeArch(RISCVISAInfo::OrderedExtensionMap &mergedExts,
} else {
for (const auto &ext : info.getExtensions()) {
if (auto it = mergedExts.find(ext.first); it != mergedExts.end()) {
if (std::tie(it->second.MajorVersion, it->second.MinorVersion) >=
std::tie(ext.second.MajorVersion, ext.second.MinorVersion))
if (std::tie(it->second.Major, it->second.Minor) >=
std::tie(ext.second.Major, ext.second.Minor))
continue;
}
mergedExts[ext.first] = ext.second;
Expand Down
16 changes: 8 additions & 8 deletions llvm/include/llvm/Support/RISCVISAInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
#include <vector>

namespace llvm {
struct RISCVExtensionInfo {
unsigned MajorVersion;
unsigned MinorVersion;
};

void riscvExtensionsHelp(StringMap<StringRef> DescMap);

class RISCVISAInfo {
public:
RISCVISAInfo(const RISCVISAInfo &) = delete;
RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;

/// Represents the major and version number components of a RISC-V extension.
struct ExtensionVersion {
unsigned Major;
unsigned Minor;
};

static bool compareExtension(const std::string &LHS, const std::string &RHS);

/// Helper class for OrderedExtensionMap.
Expand All @@ -41,7 +42,7 @@ class RISCVISAInfo {

/// OrderedExtensionMap is std::map, it's specialized to keep entries
/// in canonical order of extension.
typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
typedef std::map<std::string, ExtensionVersion, ExtensionComparator>
OrderedExtensionMap;

RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
Expand Down Expand Up @@ -104,8 +105,7 @@ class RISCVISAInfo {

OrderedExtensionMap Exts;

void addExtension(StringRef ExtName, unsigned MajorVersion,
unsigned MinorVersion);
void addExtension(StringRef ExtName, ExtensionVersion Version);

Error checkDependency();

Expand Down
Loading