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"
|
2011-07-11 05:57:24 +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;
|
|
|
|
|
2012-07-07 06:00:00 +02:00
|
|
|
MCSchedModel MCSchedModel::DefaultSchedModel; // For unknown processors.
|
|
|
|
|
2012-10-03 08:47:18 +02:00
|
|
|
/// InitMCProcessorInfo - Set or change the CPU (optionally supplemented
|
2012-09-18 07:33:15 +02:00
|
|
|
/// with feature string). Recompute feature bits and scheduling model.
|
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
|
|
|
|
SubtargetFeatures Features(FS);
|
|
|
|
FeatureBits = Features.getFeatureBits(CPU, ProcDesc, NumProcs,
|
|
|
|
ProcFeatures, NumFeatures);
|
|
|
|
|
2013-09-18 07:54:09 +02:00
|
|
|
InitCPUSchedModel(CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) {
|
2012-09-18 07:33:15 +02:00
|
|
|
if (!CPU.empty())
|
|
|
|
CPUSchedModel = getSchedModelForCPU(CPU);
|
|
|
|
else
|
|
|
|
CPUSchedModel = &MCSchedModel::DefaultSchedModel;
|
|
|
|
}
|
|
|
|
|
2011-07-11 05:57:24 +02:00
|
|
|
void
|
|
|
|
MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
|
|
|
|
const SubtargetFeatureKV *PF,
|
|
|
|
const SubtargetFeatureKV *PD,
|
2012-07-07 06:00:00 +02:00
|
|
|
const SubtargetInfoKV *ProcSched,
|
2012-09-18 05:18:56 +02:00
|
|
|
const MCWriteProcResEntry *WPR,
|
|
|
|
const MCWriteLatencyEntry *WL,
|
|
|
|
const MCReadAdvanceEntry *RA,
|
2011-07-11 05:57:24 +02:00
|
|
|
const InstrStage *IS,
|
|
|
|
const unsigned *OC,
|
|
|
|
const unsigned *FP,
|
|
|
|
unsigned NF, unsigned NP) {
|
|
|
|
TargetTriple = TT;
|
2011-07-07 09:07:08 +02:00
|
|
|
ProcFeatures = PF;
|
|
|
|
ProcDesc = PD;
|
2012-09-14 22:26:41 +02:00
|
|
|
ProcSchedModels = ProcSched;
|
2012-09-18 05:18:56 +02:00
|
|
|
WriteProcResTable = WPR;
|
|
|
|
WriteLatencyTable = WL;
|
|
|
|
ReadAdvanceTable = RA;
|
|
|
|
|
2011-07-07 09:07:08 +02:00
|
|
|
Stages = IS;
|
|
|
|
OperandCycles = OC;
|
2012-07-07 05:59:48 +02:00
|
|
|
ForwardingPaths = FP;
|
2011-07-07 09:07:08 +02:00
|
|
|
NumFeatures = NF;
|
|
|
|
NumProcs = NP;
|
|
|
|
|
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.
|
|
|
|
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;
|
|
|
|
FeatureBits = Features.ToggleFeature(FeatureBits, FS,
|
|
|
|
ProcFeatures, NumFeatures);
|
|
|
|
return FeatureBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-05 23:43:57 +02:00
|
|
|
const MCSchedModel *
|
2012-07-07 06:00:00 +02:00
|
|
|
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
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (size_t i = 1; i < NumProcs; i++) {
|
2012-09-14 22:26:41 +02:00
|
|
|
assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&
|
2012-07-07 06:00:00 +02:00
|
|
|
"Processor machine model table is not sorted");
|
2011-07-01 22:45:01 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Find entry
|
|
|
|
const SubtargetInfoKV *Found =
|
2013-10-14 00:09:26 +02:00
|
|
|
std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
|
2012-09-14 22:26:41 +02:00
|
|
|
if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {
|
2011-07-01 22:45:01 +02:00
|
|
|
errs() << "'" << CPU
|
|
|
|
<< "' is not a recognized processor for this target"
|
|
|
|
<< " (ignoring processor)\n";
|
2012-07-07 06:00:00 +02:00
|
|
|
return &MCSchedModel::DefaultSchedModel;
|
2011-07-01 22:45:01 +02:00
|
|
|
}
|
2012-07-07 06:00:00 +02:00
|
|
|
assert(Found->Value && "Missing processor SchedModel value");
|
2012-09-05 23:43:57 +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 {
|
2012-09-05 23:43:57 +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 {
|
|
|
|
InstrItins =
|
2012-09-18 06:03:34 +02:00
|
|
|
InstrItineraryData(CPUSchedModel, Stages, OperandCycles, ForwardingPaths);
|
2012-09-14 22:26:46 +02:00
|
|
|
}
|