OSDN Git Service

[Triple] Add isRISCV function
authorAlex Bradbury <asb@lowrisc.org>
Mon, 8 Jul 2019 14:52:36 +0000 (14:52 +0000)
committerAlex Bradbury <asb@lowrisc.org>
Mon, 8 Jul 2019 14:52:36 +0000 (14:52 +0000)
This matches isARM, isThumb, isAArch64 and similar helpers. Future commits
which clean-up code that currently checks for Triple::riscv32 ||
Triple::riscv64.

Differential Revision: https://reviews.llvm.org/D54215
Patch by Simon Cook.
Test case added by Alex Bradbury.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365327 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Triple.h
unittests/ADT/TripleTest.cpp

index 926039c..edeb31e 100644 (file)
@@ -725,6 +725,11 @@ public:
     return getArch() == Triple::ppc64 || getArch() == Triple::ppc64le;
   }
 
+  /// Tests whether the target is RISC-V (32- and 64-bit).
+  bool isRISCV() const {
+    return getArch() == Triple::riscv32 || getArch() == Triple::riscv64;
+  }
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
     return !isOSBinFormatMachO();
index b0f089a..556d9b9 100644 (file)
@@ -876,11 +876,13 @@ TEST(TripleTest, BitWidthPredicates) {
   EXPECT_FALSE(T.isArch16Bit());
   EXPECT_TRUE(T.isArch32Bit());
   EXPECT_FALSE(T.isArch64Bit());
+  EXPECT_TRUE(T.isRISCV());
 
   T.setArch(Triple::riscv64);
   EXPECT_FALSE(T.isArch16Bit());
   EXPECT_FALSE(T.isArch32Bit());
   EXPECT_TRUE(T.isArch64Bit());
+  EXPECT_TRUE(T.isRISCV());
 }
 
 TEST(TripleTest, BitWidthArchVariants) {