LCOV - code coverage report
Current view: top level - lib/MC - MCSubtargetInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 45 45 100.0 %
Date: 2017-09-14 15:23:50 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCSubtargetInfo.cpp - Subtarget Information ------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/MC/MCSubtargetInfo.h"
      11             : #include "llvm/ADT/ArrayRef.h"
      12             : #include "llvm/ADT/StringRef.h"
      13             : #include "llvm/MC/MCInstrItineraries.h"
      14             : #include "llvm/MC/MCSchedule.h"
      15             : #include "llvm/MC/SubtargetFeature.h"
      16             : #include "llvm/Support/raw_ostream.h"
      17             : #include <algorithm>
      18             : #include <cassert>
      19             : #include <cstring>
      20             : 
      21             : using namespace llvm;
      22             : 
      23       92065 : static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
      24             :                                  ArrayRef<SubtargetFeatureKV> ProcDesc,
      25             :                                  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
      26      184130 :   SubtargetFeatures Features(FS);
      27      184129 :   return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
      28             : }
      29             : 
      30       91952 : void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
      31       91952 :   FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
      32       91952 :   if (!CPU.empty())
      33       68038 :     CPUSchedModel = &getSchedModelForCPU(CPU);
      34             :   else
      35       23914 :     CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
      36       91952 : }
      37             : 
      38         113 : void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) {
      39         113 :   FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
      40         113 : }
      41             : 
      42       63587 : MCSubtargetInfo::MCSubtargetInfo(
      43             :     const Triple &TT, StringRef C, StringRef FS,
      44             :     ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD,
      45             :     const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
      46             :     const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
      47       63587 :     const InstrStage *IS, const unsigned *OC, const unsigned *FP)
      48             :     : TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD),
      49             :       ProcSchedModels(ProcSched), WriteProcResTable(WPR), WriteLatencyTable(WL),
      50      190761 :       ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
      51      127174 :   InitMCProcessorInfo(CPU, FS);
      52       63587 : }
      53             : 
      54             : /// ToggleFeature - Toggle a feature and returns the re-computed feature
      55             : /// bits. This version does not change the implied bits.
      56        8169 : FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) {
      57        8169 :   FeatureBits.flip(FB);
      58        8169 :   return FeatureBits;
      59             : }
      60             : 
      61         124 : FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) {
      62         248 :   FeatureBits ^= FB;
      63         124 :   return FeatureBits;
      64             : }
      65             : 
      66             : /// ToggleFeature - Toggle a feature and returns the re-computed feature
      67             : /// bits. This version will also change all implied bits.
      68         259 : FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) {
      69         259 :   SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures);
      70         259 :   return FeatureBits;
      71             : }
      72             : 
      73         410 : FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
      74         410 :   SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
      75         410 :   return FeatureBits;
      76             : }
      77             : 
      78       97809 : const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
      79             :   assert(ProcSchedModels && "Processor machine model not available!");
      80             : 
      81      195618 :   ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size());
      82             : 
      83             :   assert(std::is_sorted(SchedModels.begin(), SchedModels.end(),
      84             :                     [](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) {
      85             :                       return strcmp(LHS.Key, RHS.Key) < 0;
      86             :                     }) &&
      87             :          "Processor machine model table is not sorted");
      88             : 
      89             :   // Find entry
      90             :   auto Found =
      91      195618 :     std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU);
      92      195618 :   if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) {
      93          81 :     if (CPU != "help") // Don't error if the user asked for help.
      94          81 :       errs() << "'" << CPU
      95          81 :              << "' is not a recognized processor for this target"
      96          81 :              << " (ignoring processor)\n";
      97             :     return MCSchedModel::GetDefaultSchedModel();
      98             :   }
      99             :   assert(Found->Value && "Missing processor SchedModel value");
     100       97728 :   return *(const MCSchedModel *)Found->Value;
     101             : }
     102             : 
     103             : InstrItineraryData
     104       25284 : MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
     105       25284 :   const MCSchedModel SchedModel = getSchedModelForCPU(CPU);
     106       50568 :   return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
     107             : }
     108             : 
     109             : /// Initialize an InstrItineraryData instance.
     110      763010 : void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
     111     1526020 :   InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
     112      763010 :                                   ForwardingPaths);
     113      763010 : }

Generated by: LCOV version 1.13