Skip to content

Commit 79889fe

Browse files
authored
[RISCV] Deduplicate version struct in RISCVISAInfo. NFC (llvm#77645)
We have two structs for representing the version of an extension in RISCVISAInfo, RISCVExtensionInfo and RISCVExtensionVersion, both with the exact same fields. This patch deduplicates them.
1 parent e3993e0 commit 79889fe

File tree

5 files changed

+221
-221
lines changed

5 files changed

+221
-221
lines changed

clang/lib/Basic/Targets/RISCV.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
163163
auto ExtName = Extension.first;
164164
auto ExtInfo = Extension.second;
165165

166-
Builder.defineMacro(
167-
Twine("__riscv_", ExtName),
168-
Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
166+
Builder.defineMacro(Twine("__riscv_", ExtName),
167+
Twine(getVersionValue(ExtInfo.Major, ExtInfo.Minor)));
169168
}
170169

171170
if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))

lld/ELF/Arch/RISCV.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,8 @@ static void mergeArch(RISCVISAInfo::OrderedExtensionMap &mergedExts,
957957
} else {
958958
for (const auto &ext : info.getExtensions()) {
959959
if (auto it = mergedExts.find(ext.first); it != mergedExts.end()) {
960-
if (std::tie(it->second.MajorVersion, it->second.MinorVersion) >=
961-
std::tie(ext.second.MajorVersion, ext.second.MinorVersion))
960+
if (std::tie(it->second.Major, it->second.Minor) >=
961+
std::tie(ext.second.Major, ext.second.Minor))
962962
continue;
963963
}
964964
mergedExts[ext.first] = ext.second;

llvm/include/llvm/Support/RISCVISAInfo.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
#include <vector>
1919

2020
namespace llvm {
21-
struct RISCVExtensionInfo {
22-
unsigned MajorVersion;
23-
unsigned MinorVersion;
24-
};
25-
2621
void riscvExtensionsHelp(StringMap<StringRef> DescMap);
2722

2823
class RISCVISAInfo {
2924
public:
3025
RISCVISAInfo(const RISCVISAInfo &) = delete;
3126
RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
3227

28+
/// Represents the major and version number components of a RISC-V extension.
29+
struct ExtensionVersion {
30+
unsigned Major;
31+
unsigned Minor;
32+
};
33+
3334
static bool compareExtension(const std::string &LHS, const std::string &RHS);
3435

3536
/// Helper class for OrderedExtensionMap.
@@ -41,7 +42,7 @@ class RISCVISAInfo {
4142

4243
/// OrderedExtensionMap is std::map, it's specialized to keep entries
4344
/// in canonical order of extension.
44-
typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
45+
typedef std::map<std::string, ExtensionVersion, ExtensionComparator>
4546
OrderedExtensionMap;
4647

4748
RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
@@ -104,8 +105,7 @@ class RISCVISAInfo {
104105

105106
OrderedExtensionMap Exts;
106107

107-
void addExtension(StringRef ExtName, unsigned MajorVersion,
108-
unsigned MinorVersion);
108+
void addExtension(StringRef ExtName, ExtensionVersion Version);
109109

110110
Error checkDependency();
111111

0 commit comments

Comments
 (0)