blob: 3bb20b07f31d1a13bcdb7a2c6cc701026637d190 [file] [log] [blame]
Evan Cheng94214702011-07-01 20:45:01 +00001//===-- 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
17using namespace llvm;
18
Evan Cheng0ddff1b2011-07-07 07:07:08 +000019void 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.
44uint64_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
Evan Cheng94214702011-07-01 20:45:01 +000051InstrItineraryData
52MCSubtargetInfo::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}