2011-07-01 22:45:01 +02:00
|
|
|
//===-- MCSubtargetInfo.cpp - Subtarget Information -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-09-15 18:17:27 +02:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2011-07-01 22:45:01 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-07-11 00:52:15 +02:00
|
|
|
static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
|
|
|
|
ArrayRef<SubtargetFeatureKV> ProcDesc,
|
|
|
|
ArrayRef<SubtargetFeatureKV> ProcFeatures) {
|
2012-09-18 07:33:15 +02:00
|
|
|
SubtargetFeatures Features(FS);
|
2015-07-11 00:52:15 +02:00
|
|
|
return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-11 00:43:42 +02:00
|
|
|
MCSubtargetInfo::MCSubtargetInfo(
|
2015-09-15 18:17:27 +02:00
|
|
|
const Triple &TT, StringRef C, StringRef FS,
|
2015-06-10 14:11:26 +02:00
|
|
|
ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD,
|
|
|
|
const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
|
|
|
|
const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
|
2015-07-11 00:43:42 +02:00
|
|
|
const InstrStage *IS, const unsigned *OC, const unsigned *FP)
|
2015-09-15 18:17:27 +02:00
|
|
|
: TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD),
|
2015-07-11 00:43:42 +02:00
|
|
|
ProcSchedModels(ProcSched), 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
|
|
|
}
|
|
|
|
|
2011-07-09 07:47:46 +02:00
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version does not change the implied bits.
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version will also change all implied bits.
|
2015-05-26 12:47:10 +02:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) {
|
2016-01-05 11:25:56 +01:00
|
|
|
SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures);
|
2011-07-09 07:47:46 +02:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:29:24 +02:00
|
|
|
FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
|
2016-01-05 11:25:56 +01:00
|
|
|
SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
|
2015-06-05 15:29:24 +02:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
2011-07-09 07:47:46 +02:00
|
|
|
|
2015-07-11 00:13:43 +02:00
|
|
|
const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
|
2012-09-14 22:26:41 +02:00
|
|
|
assert(ProcSchedModels && "Processor machine model not available!");
|
2011-07-01 22:45:01 +02:00
|
|
|
|
2016-01-03 09:45:36 +01:00
|
|
|
ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size());
|
|
|
|
|
|
|
|
assert(std::is_sorted(SchedModels.begin(), SchedModels.end(),
|
2015-10-17 18:37:11 +02:00
|
|
|
[](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) {
|
|
|
|
return strcmp(LHS.Key, RHS.Key) < 0;
|
|
|
|
}) &&
|
|
|
|
"Processor machine model table is not sorted");
|
2011-07-01 22:45:01 +02:00
|
|
|
|
|
|
|
// Find entry
|
2016-01-03 09:45:36 +01:00
|
|
|
auto Found =
|
|
|
|
std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU);
|
|
|
|
if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) {
|
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
|
|
|
}
|
2012-07-07 06:00:00 +02:00
|
|
|
assert(Found->Value && "Missing processor SchedModel value");
|
2014-09-02 19:43:54 +02:00
|
|
|
return *(const MCSchedModel *)Found->Value;
|
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 {
|
2014-09-02 19:43:54 +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
|
|
|
|
|
|
|
/// Initialize an InstrItineraryData instance.
|
|
|
|
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
|
|
|
}
|