1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 21:13:02 +02:00
llvm-mirror/unittests/Support/TargetParserTest.cpp
Saleem Abdulrasool c01530fd2f Support: correct AArch64 TargetParser implementation
The architecture enumeration is shared across ARM and AArch64.  However, the
data is not.  The code incorrectly would index into the array using the
architecture index which was offset by the ARMv7 architecture enumeration.  We
do not have a marker for indicating the architectural family to which the
enumeration belongs so we cannot be clever about offsetting the index (at least
it is not immediately apparent to me).  Instead, fall back to the tried-and-true
method of slowly iterating the array (its not a large array, so the impact of
this is not too high).

Because of the incorrect indexing, if we were lucky, we would crash, but usually
we would return an invalid StringRef.  We did not have any tests for the AArch64
target parser previously;.  Extend the previous tests I had added for ARM to
cover AArch64 for ensuring that we return expected StringRefs.

Take the opportunity to change some iterator types to references.

This work is needed to support parsing `.arch name` directives in the AArch64
target asm parser.

llvm-svn: 272145
2016-06-08 14:30:00 +00:00

93 lines
3.5 KiB
C++

//===----------- TargetParser.cpp - Target Parser -------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "llvm/Support/TargetParser.h"
using namespace llvm;
namespace {
static const unsigned kAArch64ArchKinds[] = {
#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, \
ARCH_BASE_EXT) \
llvm::ARM::ID,
#include "llvm/Support/AArch64TargetParser.def"
#undef AARCH64_ARCH
};
template <typename T, size_t N>
bool contains(const T (&array)[N], const T element) {
return std::find(std::begin(array), std::end(array), element) !=
std::end(array);
}
TEST(TargetParserTest, ARMArchName) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE(AK == ARM::AK_LAST ? ARM::getArchName(AK).empty()
: !ARM::getArchName(AK).empty());
}
TEST(TargetParserTest, ARMCPUAttr) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_LAST)
? ARM::getCPUAttr(AK).empty()
: !ARM::getCPUAttr(AK).empty());
}
TEST(TargetParserTest, ARMSubArch) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_IWMMXT ||
AK == ARM::AK_IWMMXT2 || AK == ARM::AK_LAST)
? ARM::getSubArch(AK).empty()
: !ARM::getSubArch(AK).empty());
}
TEST(TargetParserTest, ARMFPUName) {
for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
FK <= ARM::FPUKind::FK_LAST;
FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
EXPECT_TRUE(FK == ARM::FK_LAST ? ARM::getFPUName(FK).empty()
: !ARM::getFPUName(FK).empty());
}
TEST(TargetParserTest, AArch64ArchName) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
? !AArch64::getArchName(AK).empty()
: AArch64::getArchName(AK).empty());
}
TEST(TargetParserTest, AArch64CPUAttr) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
? !AArch64::getCPUAttr(AK).empty()
: AArch64::getCPUAttr(AK).empty());
}
TEST(TargetParserTest, AArch64SubArch) {
for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
AK <= ARM::ArchKind::AK_LAST;
AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
EXPECT_TRUE(contains(kAArch64ArchKinds, static_cast<unsigned>(AK))
? !AArch64::getSubArch(AK).empty()
: AArch64::getSubArch(AK).empty());
}
}