2011-07-01 20:45:01 +00:00
|
|
|
//==-- llvm/MC/MCSubtargetInfo.h - Subtarget Information ---------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file describes the subtarget options of a Target machine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_MC_MCSUBTARGETINFO_H
|
|
|
|
#define LLVM_MC_MCSUBTARGETINFO_H
|
2011-07-01 20:45:01 +00:00
|
|
|
|
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2011-07-11 03:57:24 +00:00
|
|
|
#include <string>
|
2011-07-01 20:45:01 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class StringRef;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// MCSubtargetInfo - Generic base class for all target subtargets.
|
|
|
|
///
|
|
|
|
class MCSubtargetInfo {
|
2015-06-10 12:11:26 +00:00
|
|
|
Triple TargetTriple; // Target triple
|
2015-01-26 17:33:30 +00:00
|
|
|
std::string CPU; // CPU being targeted.
|
2014-05-06 20:23:04 +00:00
|
|
|
ArrayRef<SubtargetFeatureKV> ProcFeatures; // Processor feature list
|
|
|
|
ArrayRef<SubtargetFeatureKV> ProcDesc; // Processor descriptions
|
2012-09-14 20:26:41 +00:00
|
|
|
|
|
|
|
// Scheduler machine model
|
|
|
|
const SubtargetInfoKV *ProcSchedModels;
|
|
|
|
const MCWriteProcResEntry *WriteProcResTable;
|
|
|
|
const MCWriteLatencyEntry *WriteLatencyTable;
|
|
|
|
const MCReadAdvanceEntry *ReadAdvanceTable;
|
2015-07-10 22:13:43 +00:00
|
|
|
const MCSchedModel *CPUSchedModel;
|
2012-09-14 20:26:41 +00:00
|
|
|
|
2012-07-07 04:00:00 +00:00
|
|
|
const InstrStage *Stages; // Instruction itinerary stages
|
|
|
|
const unsigned *OperandCycles; // Itinerary operand cycles
|
2012-07-07 03:59:48 +00:00
|
|
|
const unsigned *ForwardingPaths; // Forwarding paths
|
2015-05-26 10:47:10 +00:00
|
|
|
FeatureBitset FeatureBits; // Feature bits for current CPU + FS
|
2011-07-07 07:07:08 +00:00
|
|
|
|
2015-07-10 22:43:42 +00:00
|
|
|
MCSubtargetInfo() = delete;
|
2015-07-10 22:52:15 +00:00
|
|
|
MCSubtargetInfo &operator=(MCSubtargetInfo &&) = delete;
|
|
|
|
MCSubtargetInfo &operator=(const MCSubtargetInfo &) = delete;
|
2015-07-10 22:43:42 +00:00
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
public:
|
2015-07-10 22:52:15 +00:00
|
|
|
MCSubtargetInfo(const MCSubtargetInfo &) = default;
|
2015-07-10 22:43:42 +00:00
|
|
|
MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS,
|
|
|
|
ArrayRef<SubtargetFeatureKV> PF,
|
|
|
|
ArrayRef<SubtargetFeatureKV> PD,
|
|
|
|
const SubtargetInfoKV *ProcSched,
|
|
|
|
const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL,
|
|
|
|
const MCReadAdvanceEntry *RA, const InstrStage *IS,
|
|
|
|
const unsigned *OC, const unsigned *FP);
|
2011-07-07 07:07:08 +00:00
|
|
|
|
2011-07-11 03:57:24 +00:00
|
|
|
/// getTargetTriple - Return the target triple string.
|
2015-06-10 12:11:26 +00:00
|
|
|
const Triple &getTargetTriple() const { return TargetTriple; }
|
2011-07-11 03:57:24 +00:00
|
|
|
|
2015-01-26 17:33:30 +00:00
|
|
|
/// getCPU - Return the CPU string.
|
|
|
|
StringRef getCPU() const {
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
|
2011-07-11 03:57:24 +00:00
|
|
|
/// getFeatureBits - Return the feature bits.
|
2011-07-07 07:07:08 +00:00
|
|
|
///
|
2015-05-26 10:47:10 +00:00
|
|
|
const FeatureBitset& getFeatureBits() const {
|
2011-07-07 07:07:08 +00:00
|
|
|
return FeatureBits;
|
2011-07-01 20:45:01 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 12:20:00 +00:00
|
|
|
/// setFeatureBits - Set the feature bits.
|
|
|
|
///
|
2015-06-09 13:33:26 +00:00
|
|
|
void setFeatureBits(const FeatureBitset &FeatureBits_) {
|
|
|
|
FeatureBits = FeatureBits_;
|
|
|
|
}
|
2014-08-04 12:20:00 +00:00
|
|
|
|
2015-07-10 22:52:15 +00:00
|
|
|
protected:
|
|
|
|
/// Initialize the scheduling model and feature bits.
|
|
|
|
///
|
|
|
|
/// FIXME: Find a way to stick this in the constructor, since it should only
|
|
|
|
/// be called during initialization.
|
2012-09-18 05:33:15 +00:00
|
|
|
void InitMCProcessorInfo(StringRef CPU, StringRef FS);
|
2011-07-07 07:07:08 +00:00
|
|
|
|
2015-07-10 22:52:15 +00:00
|
|
|
public:
|
|
|
|
/// Set the features to the default for the given CPU.
|
|
|
|
void setDefaultFeatures(StringRef CPU);
|
|
|
|
|
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.
|
2015-05-26 10:47:10 +00:00
|
|
|
FeatureBitset ToggleFeature(uint64_t FB);
|
2011-07-09 05:47:46 +00:00
|
|
|
|
|
|
|
/// ToggleFeature - Toggle a feature and returns the re-computed feature
|
2015-05-26 10:47:10 +00:00
|
|
|
/// bits. This version does not change the implied bits.
|
|
|
|
FeatureBitset ToggleFeature(const FeatureBitset& FB);
|
|
|
|
|
|
|
|
/// ToggleFeature - Toggle a set of features and returns the re-computed
|
|
|
|
/// feature bits. This version will also change all implied bits.
|
|
|
|
FeatureBitset ToggleFeature(StringRef FS);
|
2011-07-09 05:47:46 +00:00
|
|
|
|
2015-06-05 13:29:24 +00:00
|
|
|
/// Apply a feature flag and return the re-computed feature bits, including
|
|
|
|
/// all feature bits implied by the flag.
|
|
|
|
FeatureBitset ApplyFeatureFlag(StringRef FS);
|
|
|
|
|
2012-07-07 04:00:00 +00:00
|
|
|
/// getSchedModelForCPU - Get the machine model of a CPU.
|
|
|
|
///
|
2015-07-10 22:13:43 +00:00
|
|
|
const MCSchedModel &getSchedModelForCPU(StringRef CPU) const;
|
2012-07-07 04:00:00 +00:00
|
|
|
|
2015-07-10 22:13:43 +00:00
|
|
|
/// Get the machine model for this subtarget's CPU.
|
|
|
|
const MCSchedModel &getSchedModel() const { return *CPUSchedModel; }
|
2012-09-18 03:18:56 +00:00
|
|
|
|
2012-09-14 20:26:41 +00:00
|
|
|
/// Return an iterator at the first process resource consumed by the given
|
|
|
|
/// scheduling class.
|
|
|
|
const MCWriteProcResEntry *getWriteProcResBegin(
|
|
|
|
const MCSchedClassDesc *SC) const {
|
|
|
|
return &WriteProcResTable[SC->WriteProcResIdx];
|
|
|
|
}
|
|
|
|
const MCWriteProcResEntry *getWriteProcResEnd(
|
|
|
|
const MCSchedClassDesc *SC) const {
|
|
|
|
return getWriteProcResBegin(SC) + SC->NumWriteProcResEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCWriteLatencyEntry *getWriteLatencyEntry(const MCSchedClassDesc *SC,
|
|
|
|
unsigned DefIdx) const {
|
|
|
|
assert(DefIdx < SC->NumWriteLatencyEntries &&
|
|
|
|
"MachineModel does not specify a WriteResource for DefIdx");
|
|
|
|
|
|
|
|
return &WriteLatencyTable[SC->WriteLatencyIdx + DefIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx,
|
|
|
|
unsigned WriteResID) const {
|
2012-10-10 05:43:16 +00:00
|
|
|
// TODO: The number of read advance entries in a class can be significant
|
|
|
|
// (~50). Consider compressing the WriteID into a dense ID of those that are
|
|
|
|
// used by ReadAdvance and representing them as a bitset.
|
2012-09-14 20:26:41 +00:00
|
|
|
for (const MCReadAdvanceEntry *I = &ReadAdvanceTable[SC->ReadAdvanceIdx],
|
|
|
|
*E = I + SC->NumReadAdvanceEntries; I != E; ++I) {
|
|
|
|
if (I->UseIdx < UseIdx)
|
|
|
|
continue;
|
|
|
|
if (I->UseIdx > UseIdx)
|
|
|
|
break;
|
|
|
|
// Find the first WriteResIdx match, which has the highest cycle count.
|
|
|
|
if (!I->WriteResourceID || I->WriteResourceID == WriteResID) {
|
|
|
|
return I->Cycles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
/// getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
|
|
|
|
///
|
|
|
|
InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const;
|
2012-09-14 20:26:46 +00:00
|
|
|
|
|
|
|
/// Initialize an InstrItineraryData instance.
|
|
|
|
void initInstrItins(InstrItineraryData &InstrItins) const;
|
2014-12-02 20:03:22 +00:00
|
|
|
|
|
|
|
/// Check whether the CPU string is valid.
|
2015-07-08 17:41:53 +00:00
|
|
|
bool isCPUStringValid(StringRef CPU) const {
|
2014-12-02 20:03:22 +00:00
|
|
|
auto Found = std::find_if(ProcDesc.begin(), ProcDesc.end(),
|
|
|
|
[=](const SubtargetFeatureKV &KV) {
|
|
|
|
return CPU == KV.Key;
|
|
|
|
});
|
|
|
|
return Found != ProcDesc.end();
|
|
|
|
}
|
2011-07-01 20:45:01 +00:00
|
|
|
};
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End llvm namespace
|
2011-07-01 20:45:01 +00:00
|
|
|
|
|
|
|
#endif
|