1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00
llvm-mirror/lib/Support/X86TargetParser.cpp
Craig Topper 461e54845b [X86] Move CPUKind enum from clang to llvm/lib/Support. NFCI
Similar to what some other targets have done. This information
could be reused by other frontends so doesn't make sense to live
in clang.

-Rename CK_Generic to CK_None to better reflect its illegalness.
-Move function for translating from string to enum into llvm.
-Call checkCPUKind directly from the string to enum translation
and update CPU kind to CK_None accordinly. Caller will use CK_None
as sentinel for bad CPU.

I'm planning to move all the CPU to feature mapping out next. As
part of that I want to devise a better way to express CPUs inheriting
features from an earlier CPU. Allowing this to be expressed in a
less rigid way than just falling through a switch. Or using gotos
as we've had to do lately.

Differential Revision: https://reviews.llvm.org/D81439
2020-06-09 12:52:41 -07:00

59 lines
2.2 KiB
C++

//===-- X86TargetParser - Parser for X86 features ---------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements a target parser to recognise X86 hardware features.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/X86TargetParser.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
using namespace llvm;
bool checkCPUKind(llvm::X86::CPUKind Kind, bool Only64Bit) {
using namespace X86;
// Perform any per-CPU checks necessary to determine if this CPU is
// acceptable.
switch (Kind) {
case CK_None:
// No processor selected!
return false;
#define PROC(ENUM, STRING, IS64BIT) \
case CK_##ENUM: \
return IS64BIT || !Only64Bit;
#include "llvm/Support/X86TargetParser.def"
}
llvm_unreachable("Unhandled CPU kind");
}
X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) {
X86::CPUKind Kind = llvm::StringSwitch<CPUKind>(CPU)
#define PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM)
#define PROC_ALIAS(ENUM, ALIAS) .Case(ALIAS, CK_##ENUM)
#include "llvm/Support/X86TargetParser.def"
.Default(CK_None);
if (!checkCPUKind(Kind, Only64Bit))
Kind = CK_None;
return Kind;
}
void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
bool Only64Bit) {
#define PROC(ENUM, STRING, IS64BIT) \
if (IS64BIT || !Only64Bit) \
Values.emplace_back(STRING);
// For aliases we need to lookup the CPUKind to get the 64-bit ness.
#define PROC_ALIAS(ENUM, ALIAS) \
if (checkCPUKind(CK_##ENUM, Only64Bit)) \
Values.emplace_back(ALIAS);
#include "llvm/Support/X86TargetParser.def"
}