Skip to content

Commit 1953c7e

Browse files
committed
[NFC][RISCV] Extract utility to calculate value through MajorVersion and MinorVersion
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D139025
1 parent d20101d commit 1953c7e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ std::string RISCVTargetInfo::convertConstraint(const char *&Constraint) const {
118118
return R;
119119
}
120120

121+
static unsigned getVersionValue(unsigned MajorVersion, unsigned MinorVersion) {
122+
return MajorVersion * 1000000 + MinorVersion * 1000;
123+
}
124+
121125
void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
122126
MacroBuilder &Builder) const {
123127
Builder.defineMacro("__ELF__");
@@ -153,10 +157,10 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
153157
for (auto &Extension : ISAInfo->getExtensions()) {
154158
auto ExtName = Extension.first;
155159
auto ExtInfo = Extension.second;
156-
unsigned Version =
157-
(ExtInfo.MajorVersion * 1000000) + (ExtInfo.MinorVersion * 1000);
158160

159-
Builder.defineMacro(Twine("__riscv_", ExtName), Twine(Version));
161+
Builder.defineMacro(
162+
Twine("__riscv_", ExtName),
163+
Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
160164
}
161165

162166
if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))
@@ -194,8 +198,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
194198
if (ISAInfo->hasExtension("zve32x")) {
195199
Builder.defineMacro("__riscv_vector");
196200
// Currently we support the v0.10 RISC-V V intrinsics.
197-
unsigned Version = (0 * 1000000) + (10 * 1000);
198-
Builder.defineMacro("__riscv_v_intrinsic", Twine(Version));
201+
Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 10)));
199202
}
200203
}
201204

0 commit comments

Comments
 (0)