2017-02-08 23:23:19 +01:00
|
|
|
//===- MCSubtargetInfo.cpp - Subtarget Information ------------------------===//
|
2011-07-01 22:45:01 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2011-07-01 22:45:01 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2017-02-08 23:23:19 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2011-07-01 22:45:01 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2017-02-08 23:23:19 +01:00
|
|
|
#include "llvm/MC/MCSchedule.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2019-03-05 19:54:30 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
2011-07-01 22:45:01 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
2017-02-08 23:23:19 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
2011-07-01 22:45:01 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2019-03-05 19:54:30 +01:00
|
|
|
/// Find KV in array using binary search.
|
2019-03-05 19:54:34 +01:00
|
|
|
template <typename T>
|
|
|
|
static const T *Find(StringRef S, ArrayRef<T> A) {
|
2019-03-05 19:54:30 +01:00
|
|
|
// Binary search the array
|
2019-06-21 07:40:31 +02:00
|
|
|
auto F = llvm::lower_bound(A, S);
|
2019-03-05 19:54:30 +01:00
|
|
|
// If not found then return NULL
|
|
|
|
if (F == A.end() || StringRef(F->Key) != S) return nullptr;
|
|
|
|
// Return the found array item
|
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For each feature that is (transitively) implied by this feature, set it.
|
|
|
|
static
|
|
|
|
void SetImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies,
|
|
|
|
ArrayRef<SubtargetFeatureKV> FeatureTable) {
|
|
|
|
// OR the Implies bits in outside the loop. This allows the Implies for CPUs
|
|
|
|
// which might imply features not in FeatureTable to use this.
|
|
|
|
Bits |= Implies;
|
|
|
|
for (const SubtargetFeatureKV &FE : FeatureTable)
|
|
|
|
if (Implies.test(FE.Value))
|
|
|
|
SetImpliedBits(Bits, FE.Implies.getAsBitset(), FeatureTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For each feature that (transitively) implies this feature, clear it.
|
|
|
|
static
|
|
|
|
void ClearImpliedBits(FeatureBitset &Bits, unsigned Value,
|
|
|
|
ArrayRef<SubtargetFeatureKV> FeatureTable) {
|
|
|
|
for (const SubtargetFeatureKV &FE : FeatureTable) {
|
|
|
|
if (FE.Implies.getAsBitset().test(Value)) {
|
|
|
|
Bits.reset(FE.Value);
|
|
|
|
ClearImpliedBits(Bits, FE.Value, FeatureTable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
|
|
|
|
ArrayRef<SubtargetFeatureKV> FeatureTable) {
|
|
|
|
assert(SubtargetFeatures::hasFlag(Feature) &&
|
|
|
|
"Feature flags should start with '+' or '-'");
|
|
|
|
|
|
|
|
// Find feature in table.
|
|
|
|
const SubtargetFeatureKV *FeatureEntry =
|
|
|
|
Find(SubtargetFeatures::StripFlag(Feature), FeatureTable);
|
|
|
|
// If there is a match
|
|
|
|
if (FeatureEntry) {
|
|
|
|
// Enable/disable feature in bits
|
|
|
|
if (SubtargetFeatures::isEnabled(Feature)) {
|
|
|
|
Bits.set(FeatureEntry->Value);
|
|
|
|
|
|
|
|
// For each feature that this implies, set it.
|
|
|
|
SetImpliedBits(Bits, FeatureEntry->Implies.getAsBitset(), FeatureTable);
|
|
|
|
} else {
|
|
|
|
Bits.reset(FeatureEntry->Value);
|
|
|
|
|
|
|
|
// For each feature that implies this, clear it.
|
|
|
|
ClearImpliedBits(Bits, FeatureEntry->Value, FeatureTable);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errs() << "'" << Feature << "' is not a recognized feature for this target"
|
|
|
|
<< " (ignoring feature)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the length of the longest entry in the table.
|
2019-03-05 19:54:34 +01:00
|
|
|
template <typename T>
|
|
|
|
static size_t getLongestEntryLength(ArrayRef<T> Table) {
|
2019-03-05 19:54:30 +01:00
|
|
|
size_t MaxLen = 0;
|
|
|
|
for (auto &I : Table)
|
|
|
|
MaxLen = std::max(MaxLen, std::strlen(I.Key));
|
|
|
|
return MaxLen;
|
|
|
|
}
|
|
|
|
|
2019-06-14 23:42:21 +02:00
|
|
|
/// Display help for feature and mcpu choices.
|
2019-03-05 19:54:34 +01:00
|
|
|
static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
|
2019-03-05 19:54:30 +01:00
|
|
|
ArrayRef<SubtargetFeatureKV> FeatTable) {
|
2019-06-14 23:42:21 +02:00
|
|
|
// the static variable ensures that the help information only gets
|
|
|
|
// printed once even though a target machine creates multiple subtargets
|
|
|
|
static bool PrintOnce = false;
|
|
|
|
if (PrintOnce) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-05 19:54:30 +01:00
|
|
|
// Determine the length of the longest CPU and Feature entries.
|
|
|
|
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
|
|
|
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
|
|
|
|
|
|
|
|
// Print the CPU table.
|
|
|
|
errs() << "Available CPUs for this target:\n\n";
|
|
|
|
for (auto &CPU : CPUTable)
|
2019-03-05 19:54:34 +01:00
|
|
|
errs() << format(" %-*s - Select the %s processor.\n", MaxCPULen, CPU.Key,
|
|
|
|
CPU.Key);
|
2019-03-05 19:54:30 +01:00
|
|
|
errs() << '\n';
|
|
|
|
|
|
|
|
// Print the Feature table.
|
|
|
|
errs() << "Available features for this target:\n\n";
|
|
|
|
for (auto &Feature : FeatTable)
|
|
|
|
errs() << format(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
|
|
|
|
errs() << '\n';
|
|
|
|
|
|
|
|
errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
|
|
|
|
"For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
|
2019-06-14 23:42:21 +02:00
|
|
|
|
|
|
|
PrintOnce = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Display help for mcpu choices only
|
|
|
|
static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
|
|
|
|
// the static variable ensures that the help information only gets
|
|
|
|
// printed once even though a target machine creates multiple subtargets
|
|
|
|
static bool PrintOnce = false;
|
|
|
|
if (PrintOnce) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the CPU table.
|
|
|
|
errs() << "Available CPUs for this target:\n\n";
|
|
|
|
for (auto &CPU : CPUTable)
|
|
|
|
errs() << "\t" << CPU.Key << "\n";
|
|
|
|
errs() << '\n';
|
|
|
|
|
|
|
|
errs() << "Use -mcpu or -mtune to specify the target's processor.\n"
|
|
|
|
"For example, clang --target=aarch64-unknown-linux-gui "
|
|
|
|
"-mcpu=cortex-a35\n";
|
|
|
|
|
|
|
|
PrintOnce = true;
|
2019-03-05 19:54:30 +01:00
|
|
|
}
|
|
|
|
|
2015-07-11 00:52:15 +02:00
|
|
|
static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
|
2019-03-05 19:54:34 +01:00
|
|
|
ArrayRef<SubtargetSubTypeKV> ProcDesc,
|
2015-07-11 00:52:15 +02:00
|
|
|
ArrayRef<SubtargetFeatureKV> ProcFeatures) {
|
2012-09-18 07:33:15 +02:00
|
|
|
SubtargetFeatures Features(FS);
|
2019-03-05 19:54:30 +01:00
|
|
|
|
|
|
|
if (ProcDesc.empty() || ProcFeatures.empty())
|
|
|
|
return FeatureBitset();
|
|
|
|
|
|
|
|
assert(std::is_sorted(std::begin(ProcDesc), std::end(ProcDesc)) &&
|
|
|
|
"CPU table is not sorted");
|
|
|
|
assert(std::is_sorted(std::begin(ProcFeatures), std::end(ProcFeatures)) &&
|
|
|
|
"CPU features table is not sorted");
|
|
|
|
// Resulting bits
|
|
|
|
FeatureBitset Bits;
|
|
|
|
|
|
|
|
// Check if help is needed
|
|
|
|
if (CPU == "help")
|
|
|
|
Help(ProcDesc, ProcFeatures);
|
|
|
|
|
|
|
|
// Find CPU entry if CPU name is specified.
|
|
|
|
else if (!CPU.empty()) {
|
2019-03-05 19:54:34 +01:00
|
|
|
const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc);
|
2019-03-05 19:54:30 +01:00
|
|
|
|
|
|
|
// If there is a match
|
|
|
|
if (CPUEntry) {
|
|
|
|
// Set the features implied by this CPU feature, if any.
|
|
|
|
SetImpliedBits(Bits, CPUEntry->Implies.getAsBitset(), ProcFeatures);
|
|
|
|
} else {
|
|
|
|
errs() << "'" << CPU << "' is not a recognized processor for this target"
|
|
|
|
<< " (ignoring processor)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through each feature
|
|
|
|
for (const std::string &Feature : Features.getFeatures()) {
|
|
|
|
// Check for help
|
|
|
|
if (Feature == "+help")
|
|
|
|
Help(ProcDesc, ProcFeatures);
|
2019-06-14 23:42:21 +02:00
|
|
|
else if (Feature == "+cpuHelp")
|
|
|
|
cpuHelp(ProcDesc);
|
2019-03-05 19:54:30 +01:00
|
|
|
else
|
|
|
|
ApplyFeatureFlag(Bits, Feature, ProcFeatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Bits;
|
2015-07-11 00:52:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
|
|
|
|
FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
|
2012-09-18 07:33:15 +02:00
|
|
|
if (!CPU.empty())
|
2015-07-11 00:13:43 +02:00
|
|
|
CPUSchedModel = &getSchedModelForCPU(CPU);
|
2012-09-18 07:33:15 +02:00
|
|
|
else
|
2015-07-11 00:13:43 +02:00
|
|
|
CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
|
2012-09-18 07:33:15 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 12:10:19 +01:00
|
|
|
void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) {
|
|
|
|
FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
|
2015-07-11 00:52:15 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 20:23:46 +01:00
|
|
|
MCSubtargetInfo::MCSubtargetInfo(const Triple &TT, StringRef C, StringRef FS,
|
|
|
|
ArrayRef<SubtargetFeatureKV> PF,
|
|
|
|
ArrayRef<SubtargetSubTypeKV> PD,
|
|
|
|
const MCWriteProcResEntry *WPR,
|
|
|
|
const MCWriteLatencyEntry *WL,
|
|
|
|
const MCReadAdvanceEntry *RA,
|
|
|
|
const InstrStage *IS, const unsigned *OC,
|
|
|
|
const unsigned *FP)
|
|
|
|
: TargetTriple(TT), CPU(std::string(C)), ProcFeatures(PF), ProcDesc(PD),
|
|
|
|
WriteProcResTable(WPR), WriteLatencyTable(WL), ReadAdvanceTable(RA),
|
|
|
|
Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
|
2012-09-18 07:33:15 +02:00
|
|
|
InitMCProcessorInfo(CPU, FS);
|
2011-07-07 09:07:08 +02:00
|
|
|
}
|
|
|
|
|
2015-05-26 12:47:10 +02:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) {
|
|
|
|
FeatureBits.flip(FB);
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) {
|
2011-07-09 07:47:46 +02:00
|
|
|
FeatureBits ^= FB;
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 18:13:20 +02:00
|
|
|
FeatureBitset MCSubtargetInfo::SetFeatureBitsTransitively(
|
|
|
|
const FeatureBitset &FB) {
|
|
|
|
SetImpliedBits(FeatureBits, FB, ProcFeatures);
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureBitset MCSubtargetInfo::ClearFeatureBitsTransitively(
|
|
|
|
const FeatureBitset &FB) {
|
|
|
|
for (unsigned I = 0, E = FB.size(); I < E; I++) {
|
|
|
|
if (FB[I]) {
|
|
|
|
FeatureBits.reset(I);
|
|
|
|
ClearImpliedBits(FeatureBits, I, ProcFeatures);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
2019-03-05 19:54:30 +01:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef Feature) {
|
|
|
|
// Find feature in table.
|
|
|
|
const SubtargetFeatureKV *FeatureEntry =
|
|
|
|
Find(SubtargetFeatures::StripFlag(Feature), ProcFeatures);
|
|
|
|
// If there is a match
|
|
|
|
if (FeatureEntry) {
|
|
|
|
if (FeatureBits.test(FeatureEntry->Value)) {
|
|
|
|
FeatureBits.reset(FeatureEntry->Value);
|
|
|
|
// For each feature that implies this, clear it.
|
|
|
|
ClearImpliedBits(FeatureBits, FeatureEntry->Value, ProcFeatures);
|
|
|
|
} else {
|
|
|
|
FeatureBits.set(FeatureEntry->Value);
|
|
|
|
|
|
|
|
// For each feature that this implies, set it.
|
|
|
|
SetImpliedBits(FeatureBits, FeatureEntry->Implies.getAsBitset(),
|
|
|
|
ProcFeatures);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errs() << "'" << Feature << "' is not a recognized feature for this target"
|
|
|
|
<< " (ignoring feature)\n";
|
|
|
|
}
|
|
|
|
|
2011-07-09 07:47:46 +02:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:29:24 +02:00
|
|
|
FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
|
2019-03-05 19:54:30 +01:00
|
|
|
::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
|
2015-06-05 15:29:24 +02:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
2011-07-09 07:47:46 +02:00
|
|
|
|
2017-09-14 22:44:20 +02:00
|
|
|
bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
|
|
|
|
SubtargetFeatures T(FS);
|
|
|
|
FeatureBitset Set, All;
|
|
|
|
for (std::string F : T.getFeatures()) {
|
2019-03-05 19:54:30 +01:00
|
|
|
::ApplyFeatureFlag(Set, F, ProcFeatures);
|
2017-09-14 22:44:20 +02:00
|
|
|
if (F[0] == '-')
|
|
|
|
F[0] = '+';
|
2019-03-05 19:54:30 +01:00
|
|
|
::ApplyFeatureFlag(All, F, ProcFeatures);
|
2017-09-14 22:44:20 +02:00
|
|
|
}
|
|
|
|
return (FeatureBits & All) == Set;
|
|
|
|
}
|
|
|
|
|
2015-07-11 00:13:43 +02:00
|
|
|
const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
|
2019-03-05 19:54:38 +01:00
|
|
|
assert(std::is_sorted(ProcDesc.begin(), ProcDesc.end()) &&
|
2015-10-17 18:37:11 +02:00
|
|
|
"Processor machine model table is not sorted");
|
2011-07-01 22:45:01 +02:00
|
|
|
|
|
|
|
// Find entry
|
2019-03-05 19:54:38 +01:00
|
|
|
const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc);
|
|
|
|
|
|
|
|
if (!CPUEntry) {
|
2015-04-02 06:27:50 +02:00
|
|
|
if (CPU != "help") // Don't error if the user asked for help.
|
|
|
|
errs() << "'" << CPU
|
|
|
|
<< "' is not a recognized processor for this target"
|
|
|
|
<< " (ignoring processor)\n";
|
2014-09-02 19:43:54 +02:00
|
|
|
return MCSchedModel::GetDefaultSchedModel();
|
2014-01-25 17:56:18 +01:00
|
|
|
}
|
2019-03-05 19:54:38 +01:00
|
|
|
assert(CPUEntry->SchedModel && "Missing processor SchedModel value");
|
|
|
|
return *CPUEntry->SchedModel;
|
2012-07-07 06:00:00 +02:00
|
|
|
}
|
2011-07-01 22:45:01 +02:00
|
|
|
|
2012-07-07 06:00:00 +02:00
|
|
|
InstrItineraryData
|
|
|
|
MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
|
2017-09-27 14:48:48 +02:00
|
|
|
const MCSchedModel &SchedModel = getSchedModelForCPU(CPU);
|
2012-07-07 06:00:00 +02:00
|
|
|
return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
|
2011-07-01 22:45:01 +02:00
|
|
|
}
|
2012-09-14 22:26:46 +02:00
|
|
|
|
|
|
|
void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
|
2015-07-11 00:13:43 +02:00
|
|
|
InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
|
|
|
|
ForwardingPaths);
|
2012-09-14 22:26:46 +02:00
|
|
|
}
|
2019-10-09 21:51:48 +02:00
|
|
|
|
|
|
|
Optional<unsigned> MCSubtargetInfo::getCacheSize(unsigned Level) const {
|
|
|
|
return Optional<unsigned>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<unsigned>
|
|
|
|
MCSubtargetInfo::getCacheAssociativity(unsigned Level) const {
|
|
|
|
return Optional<unsigned>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<unsigned> MCSubtargetInfo::getCacheLineSize(unsigned Level) const {
|
|
|
|
return Optional<unsigned>();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCSubtargetInfo::getPrefetchDistance() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCSubtargetInfo::getMaxPrefetchIterationsAhead() const {
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCSubtargetInfo::getMinPrefetchStride() const {
|
|
|
|
return 1;
|
|
|
|
}
|