2011-07-02 04:45:01 +08: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-16 00:17:27 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2011-07-02 04:45:01 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
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-07-11 06:52:15 +08:00
|
|
|
void MCSubtargetInfo::setDefaultFeatures(StringRef CPU) {
|
|
|
|
FeatureBits = getFeatures(CPU, "", ProcDesc, ProcFeatures);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-07-09 13:47:46 +08:00
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version does not change the implied bits.
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version will also change all implied bits.
|
2015-05-26 18:47:10 +08:00
|
|
|
FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) {
|
2011-07-09 13:47:46 +08:00
|
|
|
SubtargetFeatures Features;
|
2014-05-07 04:23:04 +08:00
|
|
|
FeatureBits = Features.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) {
|
|
|
|
SubtargetFeatures Features;
|
|
|
|
FeatureBits = Features.ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
2011-07-09 13:47:46 +08:00
|
|
|
|
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
|
|
|
|
2015-10-18 00:37:11 +08:00
|
|
|
size_t NumProcs = ProcDesc.size();
|
|
|
|
assert(std::is_sorted(ProcSchedModels, ProcSchedModels+NumProcs,
|
|
|
|
[](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
|
2014-01-26 00:56:18 +08:00
|
|
|
const SubtargetInfoKV *Found =
|
|
|
|
std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
|
|
|
|
if (Found == ProcSchedModels+NumProcs || 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 {
|
2014-09-03 01:43:54 +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
|
|
|
|
|
|
|
/// Initialize an InstrItineraryData instance.
|
|
|
|
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
|
|
|
}
|