2017-02-09 06:23:19 +08:00
|
|
|
//===- MCSubtargetInfo.cpp - Subtarget Information ------------------------===//
|
2011-07-02 04:45:01 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2017-02-09 06:23:19 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2011-07-02 04:45:01 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2017-02-09 06:23:19 +08:00
|
|
|
#include "llvm/MC/MCSchedule.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2011-07-02 04:45:01 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
2017-02-09 06:23:19 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-07-11 06:52:15 +08:00
|
|
|
static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
|
|
|
|
ArrayRef<SubtargetFeatureKV> ProcDesc,
|
|
|
|
ArrayRef<SubtargetFeatureKV> ProcFeatures) {
|
2012-09-18 13:33:15 +08:00
|
|
|
SubtargetFeatures Features(FS);
|
2015-07-11 06:52:15 +08:00
|
|
|
return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
|
|
|
|
FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
|
2012-09-18 13:33:15 +08:00
|
|
|
if (!CPU.empty())
|
2015-07-11 06:13:43 +08:00
|
|
|
CPUSchedModel = &getSchedModelForCPU(CPU);
|
2012-09-18 13:33:15 +08:00
|
|
|
else
|
2015-07-11 06:13:43 +08:00
|
|
|
CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
|
2012-09-18 13:33:15 +08:00
|
|
|
}
|
|
|
|
|
2015-11-16 19:10:19 +08:00
|
|
|
void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) {
|
|
|
|
FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
|
2015-07-11 06:52:15 +08:00
|
|
|
}
|
|
|
|
|
2015-07-11 06:43:42 +08:00
|
|
|
MCSubtargetInfo::MCSubtargetInfo(
|
2015-09-16 00:17:27 +08:00
|
|
|
const Triple &TT, StringRef C, StringRef FS,
|
2015-06-10 20:11:26 +08:00
|
|
|
ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD,
|
|
|
|
const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
|
|
|
|
const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
|
2015-07-11 06:43:42 +08:00
|
|
|
const InstrStage *IS, const unsigned *OC, const unsigned *FP)
|
2015-09-16 00:17:27 +08:00
|
|
|
: TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD),
|
2015-07-11 06:43:42 +08:00
|
|
|
ProcSchedModels(ProcSched), WriteProcResTable(WPR), WriteLatencyTable(WL),
|
|
|
|
ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
|
2012-09-18 13:33:15 +08:00
|
|
|
InitMCProcessorInfo(CPU, FS);
|
2011-07-07 15:07:08 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 18:47:10 +08:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) {
|
|
|
|
FeatureBits.flip(FB);
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) {
|
2011-07-09 13:47:46 +08:00
|
|
|
FeatureBits ^= FB;
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
2015-05-26 18:47:10 +08:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) {
|
2016-01-05 18:25:56 +08:00
|
|
|
SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures);
|
2011-07-09 13:47:46 +08:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
2015-06-05 21:29:24 +08:00
|
|
|
FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
|
2016-01-05 18:25:56 +08:00
|
|
|
SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
|
2015-06-05 21:29:24 +08:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
2011-07-09 13:47:46 +08:00
|
|
|
|
2017-09-15 04:44:20 +08:00
|
|
|
bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
|
|
|
|
SubtargetFeatures T(FS);
|
|
|
|
FeatureBitset Set, All;
|
|
|
|
for (std::string F : T.getFeatures()) {
|
|
|
|
SubtargetFeatures::ApplyFeatureFlag(Set, F, ProcFeatures);
|
|
|
|
if (F[0] == '-')
|
|
|
|
F[0] = '+';
|
|
|
|
SubtargetFeatures::ApplyFeatureFlag(All, F, ProcFeatures);
|
|
|
|
}
|
|
|
|
return (FeatureBits & All) == Set;
|
|
|
|
}
|
|
|
|
|
2015-07-11 06:13:43 +08:00
|
|
|
const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
|
2012-09-15 04:26:41 +08:00
|
|
|
assert(ProcSchedModels && "Processor machine model not available!");
|
2011-07-02 04:45:01 +08:00
|
|
|
|
2016-01-03 16:45:36 +08:00
|
|
|
ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size());
|
|
|
|
|
|
|
|
assert(std::is_sorted(SchedModels.begin(), SchedModels.end(),
|
2015-10-18 00:37:11 +08:00
|
|
|
[](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) {
|
|
|
|
return strcmp(LHS.Key, RHS.Key) < 0;
|
|
|
|
}) &&
|
|
|
|
"Processor machine model table is not sorted");
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
// Find entry
|
2016-01-03 16:45:36 +08:00
|
|
|
auto Found =
|
|
|
|
std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU);
|
|
|
|
if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) {
|
2015-04-02 12:27:50 +08: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-03 01:43:54 +08:00
|
|
|
return MCSchedModel::GetDefaultSchedModel();
|
2014-01-26 00:56:18 +08:00
|
|
|
}
|
2012-07-07 12:00:00 +08:00
|
|
|
assert(Found->Value && "Missing processor SchedModel value");
|
2014-09-03 01:43:54 +08:00
|
|
|
return *(const MCSchedModel *)Found->Value;
|
2012-07-07 12:00:00 +08:00
|
|
|
}
|
2011-07-02 04:45:01 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
InstrItineraryData
|
|
|
|
MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
|
2017-09-27 20:48:48 +08:00
|
|
|
const MCSchedModel &SchedModel = getSchedModelForCPU(CPU);
|
2012-07-07 12:00:00 +08:00
|
|
|
return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
|
2011-07-02 04:45:01 +08:00
|
|
|
}
|
2012-09-15 04:26:46 +08:00
|
|
|
|
|
|
|
void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
|
2015-07-11 06:13:43 +08:00
|
|
|
InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
|
|
|
|
ForwardingPaths);
|
2012-09-15 04:26:46 +08:00
|
|
|
}
|