LLVM API Documentation
00001 //==-- llvm/MC/MCSubtargetInfo.h - Subtarget Information ---------*- C++ -*-==// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes the subtarget options of a Target machine. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_MC_MCSUBTARGETINFO_H 00015 #define LLVM_MC_MCSUBTARGETINFO_H 00016 00017 #include "llvm/MC/MCInstrItineraries.h" 00018 #include "llvm/MC/SubtargetFeature.h" 00019 #include <string> 00020 00021 namespace llvm { 00022 00023 class StringRef; 00024 00025 //===----------------------------------------------------------------------===// 00026 /// 00027 /// MCSubtargetInfo - Generic base class for all target subtargets. 00028 /// 00029 class MCSubtargetInfo { 00030 std::string TargetTriple; // Target triple 00031 ArrayRef<SubtargetFeatureKV> ProcFeatures; // Processor feature list 00032 ArrayRef<SubtargetFeatureKV> ProcDesc; // Processor descriptions 00033 00034 // Scheduler machine model 00035 const SubtargetInfoKV *ProcSchedModels; 00036 const MCWriteProcResEntry *WriteProcResTable; 00037 const MCWriteLatencyEntry *WriteLatencyTable; 00038 const MCReadAdvanceEntry *ReadAdvanceTable; 00039 MCSchedModel CPUSchedModel; 00040 00041 const InstrStage *Stages; // Instruction itinerary stages 00042 const unsigned *OperandCycles; // Itinerary operand cycles 00043 const unsigned *ForwardingPaths; // Forwarding paths 00044 uint64_t FeatureBits; // Feature bits for current CPU + FS 00045 00046 public: 00047 void InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS, 00048 ArrayRef<SubtargetFeatureKV> PF, 00049 ArrayRef<SubtargetFeatureKV> PD, 00050 const SubtargetInfoKV *ProcSched, 00051 const MCWriteProcResEntry *WPR, 00052 const MCWriteLatencyEntry *WL, 00053 const MCReadAdvanceEntry *RA, 00054 const InstrStage *IS, 00055 const unsigned *OC, const unsigned *FP); 00056 00057 /// getTargetTriple - Return the target triple string. 00058 StringRef getTargetTriple() const { 00059 return TargetTriple; 00060 } 00061 00062 /// getFeatureBits - Return the feature bits. 00063 /// 00064 uint64_t getFeatureBits() const { 00065 return FeatureBits; 00066 } 00067 00068 /// setFeatureBits - Set the feature bits. 00069 /// 00070 void setFeatureBits(uint64_t FeatureBits_) { FeatureBits = FeatureBits_; } 00071 00072 /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented with 00073 /// feature string). Recompute feature bits and scheduling model. 00074 void InitMCProcessorInfo(StringRef CPU, StringRef FS); 00075 00076 /// InitCPUSchedModel - Recompute scheduling model based on CPU. 00077 void InitCPUSchedModel(StringRef CPU); 00078 00079 /// ToggleFeature - Toggle a feature and returns the re-computed feature 00080 /// bits. This version does not change the implied bits. 00081 uint64_t ToggleFeature(uint64_t FB); 00082 00083 /// ToggleFeature - Toggle a feature and returns the re-computed feature 00084 /// bits. This version will also change all implied bits. 00085 uint64_t ToggleFeature(StringRef FS); 00086 00087 /// getSchedModelForCPU - Get the machine model of a CPU. 00088 /// 00089 MCSchedModel getSchedModelForCPU(StringRef CPU) const; 00090 00091 /// getSchedModel - Get the machine model for this subtarget's CPU. 00092 /// 00093 const MCSchedModel &getSchedModel() const { return CPUSchedModel; } 00094 00095 /// Return an iterator at the first process resource consumed by the given 00096 /// scheduling class. 00097 const MCWriteProcResEntry *getWriteProcResBegin( 00098 const MCSchedClassDesc *SC) const { 00099 return &WriteProcResTable[SC->WriteProcResIdx]; 00100 } 00101 const MCWriteProcResEntry *getWriteProcResEnd( 00102 const MCSchedClassDesc *SC) const { 00103 return getWriteProcResBegin(SC) + SC->NumWriteProcResEntries; 00104 } 00105 00106 const MCWriteLatencyEntry *getWriteLatencyEntry(const MCSchedClassDesc *SC, 00107 unsigned DefIdx) const { 00108 assert(DefIdx < SC->NumWriteLatencyEntries && 00109 "MachineModel does not specify a WriteResource for DefIdx"); 00110 00111 return &WriteLatencyTable[SC->WriteLatencyIdx + DefIdx]; 00112 } 00113 00114 int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx, 00115 unsigned WriteResID) const { 00116 // TODO: The number of read advance entries in a class can be significant 00117 // (~50). Consider compressing the WriteID into a dense ID of those that are 00118 // used by ReadAdvance and representing them as a bitset. 00119 for (const MCReadAdvanceEntry *I = &ReadAdvanceTable[SC->ReadAdvanceIdx], 00120 *E = I + SC->NumReadAdvanceEntries; I != E; ++I) { 00121 if (I->UseIdx < UseIdx) 00122 continue; 00123 if (I->UseIdx > UseIdx) 00124 break; 00125 // Find the first WriteResIdx match, which has the highest cycle count. 00126 if (!I->WriteResourceID || I->WriteResourceID == WriteResID) { 00127 return I->Cycles; 00128 } 00129 } 00130 return 0; 00131 } 00132 00133 /// getInstrItineraryForCPU - Get scheduling itinerary of a CPU. 00134 /// 00135 InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const; 00136 00137 /// Initialize an InstrItineraryData instance. 00138 void initInstrItins(InstrItineraryData &InstrItins) const; 00139 }; 00140 00141 } // End llvm namespace 00142 00143 #endif