LLVM 23.0.0git
TargetParser.cpp
Go to the documentation of this file.
1//===-- TargetParser - Parser for target 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 hardware features such as
10// FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/ArrayRef.h"
16
17using namespace llvm;
18
19/// Find KV in array using binary search.
20static const BasicSubtargetSubTypeKV *
22 // Binary search the array
24 // If not found then return NULL
25 if (F == A.end() || StringRef(F->Key) != S)
26 return nullptr;
27 // Return the found array item
28 return F;
29}
30
31/// For each feature that is (transitively) implied by this feature, set it.
32static void setImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies,
34 // OR the Implies bits in outside the loop. This allows the Implies for CPUs
35 // which might imply features not in FeatureTable to use this.
36 Bits |= Implies;
37 for (const auto &FE : FeatureTable)
38 if (Implies.test(FE.Value))
39 setImpliedBits(Bits, FE.Implies.getAsBitset(), FeatureTable);
40}
41
42std::optional<llvm::StringMap<bool>> llvm::getCPUDefaultTargetFeatures(
45 if (CPU.empty())
46 return std::nullopt;
47
48 const BasicSubtargetSubTypeKV *CPUEntry = ::find(CPU, ProcDesc);
49 if (!CPUEntry)
50 return std::nullopt;
51
52 // Set the features implied by this CPU feature if there is a match.
53 FeatureBitset Bits;
54 llvm::StringMap<bool> DefaultFeatures;
55 setImpliedBits(Bits, CPUEntry->Implies.getAsBitset(), ProcFeatures);
56
57 [[maybe_unused]] unsigned BitSize = Bits.size();
58 for (const BasicSubtargetFeatureKV &FE : ProcFeatures) {
59 assert(FE.Value < BitSize && "Target Feature is out of range");
60 if (Bits[FE.Value])
61 DefaultFeatures[FE.Key] = true;
62 }
63 return DefaultFeatures;
64}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define F(x, y, z)
Definition MD5.cpp:54
static void setImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies, ArrayRef< BasicSubtargetFeatureKV > FeatureTable)
For each feature that is (transitively) implied by this feature, set it.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const FeatureBitset & getAsBitset() const
Container class for subtarget features.
constexpr bool test(unsigned I) const
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1764
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2051
LLVM_ABI std::optional< llvm::StringMap< bool > > getCPUDefaultTargetFeatures(StringRef CPU, ArrayRef< BasicSubtargetSubTypeKV > ProcDesc, ArrayRef< BasicSubtargetFeatureKV > ProcFeatures)
Used to provide key value pairs for feature and CPU bit flags.
FeatureBitArray Implies
K-V bit mask.