LCOV - code coverage report
Current view: top level - lib/MC - MCSubtargetInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 50 51 98.0 %
Date: 2018-09-23 13:06:45 Functions: 12 12 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      139679 : static FeatureBitset getFeatures(StringRef CPU, StringRef FS,
      24             :                                  ArrayRef<SubtargetFeatureKV> ProcDesc,
      25             :                                  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
      26      139679 :   SubtargetFeatures Features(FS);
      27      139679 :   return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
      28             : }
      29             : 
      30      139532 : void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
      31      139532 :   FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
      32      139532 :   if (!CPU.empty())
      33      110546 :     CPUSchedModel = &getSchedModelForCPU(CPU);
      34             :   else
      35       28986 :     CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
      36      139531 : }
      37             : 
      38         147 : void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) {
      39         147 :   FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
      40         147 : }
      41             : 
      42       97505 : 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       97505 :     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      195010 :       ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
      51       97505 :   InitMCProcessorInfo(CPU, FS);
      52       97504 : }
      53             : 
      54       17676 : FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) {
      55       17676 :   FeatureBits.flip(FB);
      56       17676 :   return FeatureBits;
      57             : }
      58             : 
      59         150 : FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) {
      60             :   FeatureBits ^= FB;
      61         150 :   return FeatureBits;
      62             : }
      63             : 
      64         319 : FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) {
      65         319 :   SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures);
      66         319 :   return FeatureBits;
      67             : }
      68             : 
      69         410 : FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
      70         410 :   SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
      71         410 :   return FeatureBits;
      72             : }
      73             : 
      74        7023 : bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
      75        7023 :   SubtargetFeatures T(FS);
      76       21069 :   FeatureBitset Set, All;
      77       14046 :   for (std::string F : T.getFeatures()) {
      78        7023 :     SubtargetFeatures::ApplyFeatureFlag(Set, F, ProcFeatures);
      79        7023 :     if (F[0] == '-')
      80           0 :       F[0] = '+';
      81        7023 :     SubtargetFeatures::ApplyFeatureFlag(All, F, ProcFeatures);
      82             :   }
      83        7023 :   return (FeatureBits & All) == Set;
      84             : }
      85             : 
      86      136066 : const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
      87             :   assert(ProcSchedModels && "Processor machine model not available!");
      88             : 
      89      136066 :   ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size());
      90             : 
      91             :   assert(std::is_sorted(SchedModels.begin(), SchedModels.end(),
      92             :                     [](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) {
      93             :                       return strcmp(LHS.Key, RHS.Key) < 0;
      94             :                     }) &&
      95             :          "Processor machine model table is not sorted");
      96             : 
      97             :   // Find entry
      98             :   auto Found =
      99             :     std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU);
     100      136066 :   if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) {
     101             :     if (CPU != "help") // Don't error if the user asked for help.
     102         173 :       errs() << "'" << CPU
     103         172 :              << "' is not a recognized processor for this target"
     104         172 :              << " (ignoring processor)\n";
     105             :     return MCSchedModel::GetDefaultSchedModel();
     106             :   }
     107             :   assert(Found->Value && "Missing processor SchedModel value");
     108      135893 :   return *(const MCSchedModel *)Found->Value;
     109             : }
     110             : 
     111             : InstrItineraryData
     112       20503 : MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
     113       20503 :   const MCSchedModel &SchedModel = getSchedModelForCPU(CPU);
     114       41006 :   return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
     115             : }
     116             : 
     117     1271597 : void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
     118     2543194 :   InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
     119     1271597 :                                   ForwardingPaths);
     120     1271597 : }

Generated by: LCOV version 1.13