1 //===-- X86TargetParser - Parser for X86 features ---------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements a target parser to recognise X86 hardware features. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/Support/X86TargetParser.h" 14 #include "llvm/ADT/StringSwitch.h" 15 #include "llvm/ADT/Triple.h" 16 17 using namespace llvm; 18 19 bool checkCPUKind(llvm::X86::CPUKind Kind, bool Only64Bit) { 20 using namespace X86; 21 // Perform any per-CPU checks necessary to determine if this CPU is 22 // acceptable. 23 switch (Kind) { 24 case CK_None: 25 // No processor selected! 26 return false; 27 #define PROC(ENUM, STRING, IS64BIT) \ 28 case CK_##ENUM: \ 29 return IS64BIT || !Only64Bit; 30 #include "llvm/Support/X86TargetParser.def" 31 } 32 llvm_unreachable("Unhandled CPU kind"); 33 } 34 35 X86::CPUKind llvm::X86::parseArchX86(StringRef CPU, bool Only64Bit) { 36 X86::CPUKind Kind = llvm::StringSwitch<CPUKind>(CPU) 37 #define PROC(ENUM, STRING, IS64BIT) .Case(STRING, CK_##ENUM) 38 #define PROC_ALIAS(ENUM, ALIAS) .Case(ALIAS, CK_##ENUM) 39 #include "llvm/Support/X86TargetParser.def" 40 .Default(CK_None); 41 42 if (!checkCPUKind(Kind, Only64Bit)) 43 Kind = CK_None; 44 45 return Kind; 46 } 47 48 void llvm::X86::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, 49 bool Only64Bit) { 50 #define PROC(ENUM, STRING, IS64BIT) \ 51 if (IS64BIT || !Only64Bit) \ 52 Values.emplace_back(STRING); 53 // For aliases we need to lookup the CPUKind to get the 64-bit ness. 54 #define PROC_ALIAS(ENUM, ALIAS) \ 55 if (checkCPUKind(CK_##ENUM, Only64Bit)) \ 56 Values.emplace_back(ALIAS); 57 #include "llvm/Support/X86TargetParser.def" 58 } 59