2011-07-01 20:45:01 +00: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"
|
2011-07-11 03:57:24 +00:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2011-07-01 20:45:01 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2012-07-07 04:00:00 +00:00
|
|
|
MCSchedModel MCSchedModel::DefaultSchedModel; // For unknown processors.
|
|
|
|
|
2012-10-03 06:47:18 +00:00
|
|
|
/// InitMCProcessorInfo - Set or change the CPU (optionally supplemented
|
2012-09-18 05:33:15 +00:00
|
|
|
/// with feature string). Recompute feature bits and scheduling model.
|
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
|
|
|
|
SubtargetFeatures Features(FS);
|
2014-05-06 20:23:04 +00:00
|
|
|
FeatureBits = Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
|
2013-09-18 05:54:09 +00:00
|
|
|
InitCPUSchedModel(CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) {
|
2012-09-18 05:33:15 +00:00
|
|
|
if (!CPU.empty())
|
|
|
|
CPUSchedModel = getSchedModelForCPU(CPU);
|
|
|
|
else
|
|
|
|
CPUSchedModel = &MCSchedModel::DefaultSchedModel;
|
|
|
|
}
|
|
|
|
|
2011-07-11 03:57:24 +00:00
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
|
2014-05-06 20:23:04 +00:00
|
|
|
ArrayRef<SubtargetFeatureKV> PF,
|
|
|
|
ArrayRef<SubtargetFeatureKV> PD,
|
2012-07-07 04:00:00 +00:00
|
|
|
const SubtargetInfoKV *ProcSched,
|
2012-09-18 03:18:56 +00:00
|
|
|
const MCWriteProcResEntry *WPR,
|
|
|
|
const MCWriteLatencyEntry *WL,
|
|
|
|
const MCReadAdvanceEntry *RA,
|
2011-07-11 03:57:24 +00:00
|
|
|
const InstrStage *IS,
|
|
|
|
const unsigned *OC,
|
2014-05-06 20:23:04 +00:00
|
|
|
const unsigned *FP) {
|
2011-07-11 03:57:24 +00:00
|
|
|
TargetTriple = TT;
|
2011-07-07 07:07:08 +00:00
|
|
|
ProcFeatures = PF;
|
|
|
|
ProcDesc = PD;
|
2012-09-14 20:26:41 +00:00
|
|
|
ProcSchedModels = ProcSched;
|
2012-09-18 03:18:56 +00:00
|
|
|
WriteProcResTable = WPR;
|
|
|
|
WriteLatencyTable = WL;
|
|
|
|
ReadAdvanceTable = RA;
|
|
|
|
|
2011-07-07 07:07:08 +00:00
|
|
|
Stages = IS;
|
|
|
|
OperandCycles = OC;
|
2012-07-07 03:59:48 +00:00
|
|
|
ForwardingPaths = FP;
|
2011-07-07 07:07:08 +00:00
|
|
|
|
2012-09-18 05:33:15 +00:00
|
|
|
InitMCProcessorInfo(CPU, FS);
|
2011-07-07 07:07:08 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 05:47:46 +00:00
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version does not change the implied bits.
|
|
|
|
uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) {
|
|
|
|
FeatureBits ^= FB;
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
|
|
|
/// bits. This version will also change all implied bits.
|
|
|
|
uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
|
|
|
|
SubtargetFeatures Features;
|
2014-05-06 20:23:04 +00:00
|
|
|
FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures);
|
2011-07-09 05:47:46 +00:00
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-05 21:43:57 +00:00
|
|
|
const MCSchedModel *
|
2012-07-07 04:00:00 +00:00
|
|
|
MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
|
2012-09-14 20:26:41 +00:00
|
|
|
assert(ProcSchedModels && "Processor machine model not available!");
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2014-05-06 20:23:04 +00:00
|
|
|
unsigned NumProcs = ProcDesc.size();
|
2011-07-01 20:45:01 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
for (size_t i = 1; i < NumProcs; i++) {
|
2012-09-14 20:26:41 +00:00
|
|
|
assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&
|
2012-07-07 04:00:00 +00:00
|
|
|
"Processor machine model table is not sorted");
|
2011-07-01 20:45:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Find entry
|
2014-01-25 16:56:18 +00:00
|
|
|
const SubtargetInfoKV *Found =
|
|
|
|
std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
|
|
|
|
if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {
|
|
|
|
errs() << "'" << CPU
|
|
|
|
<< "' is not a recognized processor for this target"
|
|
|
|
<< " (ignoring processor)\n";
|
2012-07-07 04:00:00 +00:00
|
|
|
return &MCSchedModel::DefaultSchedModel;
|
2014-01-25 16:56:18 +00:00
|
|
|
}
|
2012-07-07 04:00:00 +00:00
|
|
|
assert(Found->Value && "Missing processor SchedModel value");
|
2012-09-05 21:43:57 +00:00
|
|
|
return (const MCSchedModel *)Found->Value;
|
2012-07-07 04:00:00 +00:00
|
|
|
}
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2012-07-07 04:00:00 +00:00
|
|
|
InstrItineraryData
|
|
|
|
MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
|
2012-09-05 21:43:57 +00:00
|
|
|
const MCSchedModel *SchedModel = getSchedModelForCPU(CPU);
|
2012-07-07 04:00:00 +00:00
|
|
|
return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
|
2011-07-01 20:45:01 +00:00
|
|
|
}
|
2012-09-14 20:26:46 +00:00
|
|
|
|
|
|
|
/// Initialize an InstrItineraryData instance.
|
|
|
|
void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
|
|
|
|
InstrItins =
|
2012-09-18 04:03:34 +00:00
|
|
|
InstrItineraryData(CPUSchedModel, Stages, OperandCycles, ForwardingPaths);
|
2012-09-14 20:26:46 +00:00
|
|
|
}
|