[clang] 1953c7e - [NFC][RISCV] Extract utility to calculate value through MajorVersion and MinorVersion

via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 20 02:35:15 PST 2022


Author: eopXD
Date: 2022-12-20T02:35:10-08:00
New Revision: 1953c7e03b086e0680545980ef1c9461a7513e29

URL: https://github.com/llvm/llvm-project/commit/1953c7e03b086e0680545980ef1c9461a7513e29
DIFF: https://github.com/llvm/llvm-project/commit/1953c7e03b086e0680545980ef1c9461a7513e29.diff

LOG: [NFC][RISCV] Extract utility to calculate value through MajorVersion and MinorVersion

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139025

Added: 
    

Modified: 
    clang/lib/Basic/Targets/RISCV.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index 1b244c9b2f253..31817b8b60cb7 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -118,6 +118,10 @@ std::string RISCVTargetInfo::convertConstraint(const char *&Constraint) const {
   return R;
 }
 
+static unsigned getVersionValue(unsigned MajorVersion, unsigned MinorVersion) {
+  return MajorVersion * 1000000 + MinorVersion * 1000;
+}
+
 void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
                                        MacroBuilder &Builder) const {
   Builder.defineMacro("__ELF__");
@@ -153,10 +157,10 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
   for (auto &Extension : ISAInfo->getExtensions()) {
     auto ExtName = Extension.first;
     auto ExtInfo = Extension.second;
-    unsigned Version =
-        (ExtInfo.MajorVersion * 1000000) + (ExtInfo.MinorVersion * 1000);
 
-    Builder.defineMacro(Twine("__riscv_", ExtName), Twine(Version));
+    Builder.defineMacro(
+        Twine("__riscv_", ExtName),
+        Twine(getVersionValue(ExtInfo.MajorVersion, ExtInfo.MinorVersion)));
   }
 
   if (ISAInfo->hasExtension("m") || ISAInfo->hasExtension("zmmul"))
@@ -194,8 +198,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
   if (ISAInfo->hasExtension("zve32x")) {
     Builder.defineMacro("__riscv_vector");
     // Currently we support the v0.10 RISC-V V intrinsics.
-    unsigned Version = (0 * 1000000) + (10 * 1000);
-    Builder.defineMacro("__riscv_v_intrinsic", Twine(Version));
+    Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 10)));
   }
 }
 


        


More information about the cfe-commits mailing list