Compute feature bits at time of MCSubtargetInfo initialization.
[oota-llvm.git] / lib / MC / MCSubtargetInfo.cpp
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/MC/MCInstrItineraries.h"
12 #include "llvm/MC/SubtargetFeature.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include <algorithm>
16
17 using namespace llvm;
18
19 void MCSubtargetInfo::InitMCSubtargetInfo(StringRef CPU, StringRef FS,
20                                           const SubtargetFeatureKV *PF,
21                                           const SubtargetFeatureKV *PD,
22                                           const SubtargetInfoKV *PI,
23                                           const InstrStage *IS,
24                                           const unsigned *OC,
25                                           const unsigned *FP,
26                                           unsigned NF, unsigned NP) {
27   ProcFeatures = PF;
28   ProcDesc = PD;
29   ProcItins = PI;
30   Stages = IS;
31   OperandCycles = OC;
32   ForwardingPathes = FP;
33   NumFeatures = NF;
34   NumProcs = NP;
35
36   SubtargetFeatures Features(FS);
37   FeatureBits = Features.getFeatureBits(CPU, ProcDesc, NumProcs,
38                                         ProcFeatures, NumFeatures);
39 }
40
41
42 /// ReInitMCSubtargetInfo - Change CPU (and optionally supplemented with
43 /// feature string) and recompute feature bits.
44 uint64_t MCSubtargetInfo::ReInitMCSubtargetInfo(StringRef CPU, StringRef FS) {
45   SubtargetFeatures Features(FS);
46   FeatureBits = Features.getFeatureBits(CPU, ProcDesc, NumProcs,
47                                         ProcFeatures, NumFeatures);
48   return FeatureBits;
49 }
50
51 InstrItineraryData
52 MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
53   assert(ProcItins && "Instruction itineraries information not available!");
54
55 #ifndef NDEBUG
56   for (size_t i = 1; i < NumProcs; i++) {
57     assert(strcmp(ProcItins[i - 1].Key, ProcItins[i].Key) < 0 &&
58            "Itineraries table is not sorted");
59   }
60 #endif
61
62   // Find entry
63   SubtargetInfoKV KV;
64   KV.Key = CPU.data();
65   const SubtargetInfoKV *Found =
66     std::lower_bound(ProcItins, ProcItins+NumProcs, KV);
67   if (Found == ProcItins+NumProcs || StringRef(Found->Key) != CPU) {
68     errs() << "'" << CPU
69            << "' is not a recognized processor for this target"
70            << " (ignoring processor)\n";
71     return InstrItineraryData();
72   }
73
74   return InstrItineraryData(Stages, OperandCycles, ForwardingPathes,
75                             (InstrItinerary *)Found->Value);
76 }