LLVM API Documentation

MCSubtargetInfo.cpp
Go to the documentation of this file.
00001 //===-- MCSubtargetInfo.cpp - Subtarget Information -----------------------===//
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 #include "llvm/MC/MCSubtargetInfo.h"
00011 #include "llvm/ADT/StringRef.h"
00012 #include "llvm/ADT/Triple.h"
00013 #include "llvm/MC/MCInstrItineraries.h"
00014 #include "llvm/MC/SubtargetFeature.h"
00015 #include "llvm/Support/raw_ostream.h"
00016 #include <algorithm>
00017 
00018 using namespace llvm;
00019 
00020 /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented
00021 /// with feature string). Recompute feature bits and scheduling model.
00022 void
00023 MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
00024   SubtargetFeatures Features(FS);
00025   FeatureBits = Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
00026   InitCPUSchedModel(CPU);
00027 }
00028 
00029 void
00030 MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) {
00031   if (!CPU.empty())
00032     CPUSchedModel = getSchedModelForCPU(CPU);
00033   else
00034     CPUSchedModel = MCSchedModel::GetDefaultSchedModel();
00035 }
00036 
00037 void
00038 MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
00039                                      ArrayRef<SubtargetFeatureKV> PF,
00040                                      ArrayRef<SubtargetFeatureKV> PD,
00041                                      const SubtargetInfoKV *ProcSched,
00042                                      const MCWriteProcResEntry *WPR,
00043                                      const MCWriteLatencyEntry *WL,
00044                                      const MCReadAdvanceEntry *RA,
00045                                      const InstrStage *IS,
00046                                      const unsigned *OC,
00047                                      const unsigned *FP) {
00048   TargetTriple = TT;
00049   ProcFeatures = PF;
00050   ProcDesc = PD;
00051   ProcSchedModels = ProcSched;
00052   WriteProcResTable = WPR;
00053   WriteLatencyTable = WL;
00054   ReadAdvanceTable = RA;
00055 
00056   Stages = IS;
00057   OperandCycles = OC;
00058   ForwardingPaths = FP;
00059 
00060   InitMCProcessorInfo(CPU, FS);
00061 }
00062 
00063 /// ToggleFeature - Toggle a feature and returns the re-computed feature
00064 /// bits. This version does not change the implied bits.
00065 uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) {
00066   FeatureBits ^= FB;
00067   return FeatureBits;
00068 }
00069 
00070 /// ToggleFeature - Toggle a feature and returns the re-computed feature
00071 /// bits. This version will also change all implied bits.
00072 uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
00073   SubtargetFeatures Features;
00074   FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures);
00075   return FeatureBits;
00076 }
00077 
00078 
00079 MCSchedModel
00080 MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
00081   assert(ProcSchedModels && "Processor machine model not available!");
00082 
00083   unsigned NumProcs = ProcDesc.size();
00084 #ifndef NDEBUG
00085   for (size_t i = 1; i < NumProcs; i++) {
00086     assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&
00087            "Processor machine model table is not sorted");
00088   }
00089 #endif
00090 
00091   // Find entry
00092   const SubtargetInfoKV *Found =
00093     std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
00094   if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {
00095     errs() << "'" << CPU
00096            << "' is not a recognized processor for this target"
00097            << " (ignoring processor)\n";
00098     return MCSchedModel::GetDefaultSchedModel();
00099   }
00100   assert(Found->Value && "Missing processor SchedModel value");
00101   return *(const MCSchedModel *)Found->Value;
00102 }
00103 
00104 InstrItineraryData
00105 MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
00106   const MCSchedModel SchedModel = getSchedModelForCPU(CPU);
00107   return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
00108 }
00109 
00110 /// Initialize an InstrItineraryData instance.
00111 void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
00112   InstrItins =
00113     InstrItineraryData(CPUSchedModel, Stages, OperandCycles, ForwardingPaths);
00114 }