• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------- TargetParser.cpp - Target Parser -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "gtest/gtest.h"
11 #include "llvm/Support/TargetParser.h"
12 
13 using namespace llvm;
14 
15 namespace {
16 static const unsigned kAArch64ArchKinds[] = {
17 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU,        \
18                      ARCH_BASE_EXT)                                            \
19   llvm::ARM::ID,
20 #include "llvm/Support/AArch64TargetParser.def"
21 #undef AARCH64_ARCH
22 };
23 
24 template <typename T, size_t N>
contains(const T (& array)[N],const T element)25 bool contains(const T (&array)[N], const T element) {
26   return std::find(std::begin(array), std::end(array), element) !=
27          std::end(array);
28 }
29 
TEST(TargetParserTest,ARMArchName)30 TEST(TargetParserTest, ARMArchName) {
31   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
32        AK <= ARM::ArchKind::AK_LAST;
33        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
34     EXPECT_TRUE(AK == ARM::AK_LAST ? ARM::getArchName(AK).empty()
35                                    : !ARM::getArchName(AK).empty());
36 }
37 
TEST(TargetParserTest,ARMCPUAttr)38 TEST(TargetParserTest, ARMCPUAttr) {
39   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
40        AK <= ARM::ArchKind::AK_LAST;
41        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
42     EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_LAST)
43                     ? ARM::getCPUAttr(AK).empty()
44                     : !ARM::getCPUAttr(AK).empty());
45 }
46 
TEST(TargetParserTest,ARMSubArch)47 TEST(TargetParserTest, ARMSubArch) {
48   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
49        AK <= ARM::ArchKind::AK_LAST;
50        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
51     EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_IWMMXT ||
52                  AK == ARM::AK_IWMMXT2 || AK == ARM::AK_LAST)
53                     ? ARM::getSubArch(AK).empty()
54                     : !ARM::getSubArch(AK).empty());
55 }
56 
TEST(TargetParserTest,ARMFPUName)57 TEST(TargetParserTest, ARMFPUName) {
58   for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
59        FK <= ARM::FPUKind::FK_LAST;
60        FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
61     EXPECT_TRUE(FK == ARM::FK_LAST ? ARM::getFPUName(FK).empty()
62                                    : !ARM::getFPUName(FK).empty());
63 }
64 
TEST(TargetParserTest,AArch64ArchName)65 TEST(TargetParserTest, AArch64ArchName) {
66   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
67        AK <= ARM::ArchKind::AK_LAST;
68        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
69     EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
70                     ? !AArch64::getArchName(AK).empty()
71                     : AArch64::getArchName(AK).empty());
72 }
73 
TEST(TargetParserTest,AArch64CPUAttr)74 TEST(TargetParserTest, AArch64CPUAttr) {
75   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
76        AK <= ARM::ArchKind::AK_LAST;
77        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
78     EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
79                     ? !AArch64::getCPUAttr(AK).empty()
80                     : AArch64::getCPUAttr(AK).empty());
81 }
82 
TEST(TargetParserTest,AArch64SubArch)83 TEST(TargetParserTest, AArch64SubArch) {
84   for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
85        AK <= ARM::ArchKind::AK_LAST;
86        AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
87     EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
88                     ? !AArch64::getSubArch(AK).empty()
89                     : AArch64::getSubArch(AK).empty());
90 }
91 }
92 
93