LLVM 24.0.0git
XtensaTargetParser.cpp
Go to the documentation of this file.
1//==-- XtensaTargetParser - Parser for Xtensa 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 Xtensa hardware features
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/Enum.h"
15#include "llvm/ADT/STLExtras.h"
17#include <vector>
18
19namespace llvm {
20
21namespace Xtensa {
26
28#define XTENSA_FEATURE(ID, NAME) {{NAME}, ID},
29#include "llvm/TargetParser/XtensaTargetParser.def"
30};
32
34#define XTENSA_CPU(ENUM, NAME, FEATURES) {{NAME}, {CK_##ENUM, FEATURES}},
35#include "llvm/TargetParser/XtensaTargetParser.def"
36};
38
41#define XTENSA_CPU_ALIAS(NAME, ANAME) .Case(ANAME, NAME)
42#include "llvm/TargetParser/XtensaTargetParser.def"
43 .Default(CPU);
44}
45
48#define XTENSA_CPU_ALIAS(NAME, ANAME) .Case(NAME, ANAME)
49#include "llvm/TargetParser/XtensaTargetParser.def"
50 .Default(CPU);
51}
52
54 CPU = getBaseName(CPU);
55 for (const auto &C : CPUInfos)
56 if (C.name() == CPU)
57 return C.value().Kind;
58 return CK_INVALID;
59}
60
61// Get all features for the CPU
62void getCPUFeatures(StringRef CPU, std::vector<StringRef> &Features) {
63 CPU = getBaseName(CPU);
64 auto I =
65 llvm::find_if(CPUInfos, [&](const auto &CI) { return CI.name() == CPU; });
66 assert(I != std::end(CPUInfos) && "CPU not found!");
67 uint64_t Bits = I->value().Features;
68
69 for (const auto &F : FeatureNames) {
70 if ((Bits & F.value()) == F.value())
71 Features.push_back(F.name());
72 }
73}
74
75// Find all valid CPUs
76void fillValidCPUList(std::vector<StringRef> &Values) {
77 for (const auto &C : CPUInfos) {
78 if (C.value().Kind != CK_INVALID) {
79 Values.emplace_back(C.name());
80 StringRef Name = getAliasName(C.name());
81 if (Name != C.name())
82 Values.emplace_back(Name);
83 }
84 }
85}
86
87} // namespace Xtensa
88} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define BUILD_ENUM_STRINGS(Tab)
Definition Enum.h:120
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains some templates that are useful if you are working with the STL at all.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This file implements a target parser to recognise Xtensa hardware features.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI StringRef getBaseName(StringRef CPU)
LLVM_ABI void fillValidCPUList(SmallVectorImpl< StringRef > &Values)
constexpr EnumStringDef< CPUInfo > CPUInfoDefs[]
constexpr auto FeatureNames
constexpr EnumStringDef< uint64_t > FeatureNameDefs[]
StringRef getAliasName(StringRef CPU)
LLVM_ABI void getCPUFeatures(StringRef CPU, SmallVectorImpl< StringRef > &Features)
LLVM_ABI CPUKind parseCPUKind(StringRef CPU)
constexpr auto CPUInfos
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
Compile-time data representation of enum entries.
Definition Enum.h:47