blob: b1b86fe61e0fd0d5fbfe00e86b91ef6dcc86485e [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 Chengffc0e732011-07-09 05:47:46 +000051/// ToggleFeature - Toggle a feature and returns the re-computed feature
52/// bits. This version does not change the implied bits.
53uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) {
54 FeatureBits ^= FB;
55 return FeatureBits;
56}
57
58/// ToggleFeature - Toggle a feature and returns the re-computed feature
59/// bits. This version will also change all implied bits.
60uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
61 SubtargetFeatures Features;
62 FeatureBits = Features.ToggleFeature(FeatureBits, FS,
63 ProcFeatures, NumFeatures);
64 return FeatureBits;
65}
66
67
Evan Cheng94214702011-07-01 20:45:01 +000068InstrItineraryData
69MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
70 assert(ProcItins && "Instruction itineraries information not available!");
71
72#ifndef NDEBUG
73 for (size_t i = 1; i < NumProcs; i++) {
74 assert(strcmp(ProcItins[i - 1].Key, ProcItins[i].Key) < 0 &&
75 "Itineraries table is not sorted");
76 }
77#endif
78
79 // Find entry
80 SubtargetInfoKV KV;
81 KV.Key = CPU.data();
82 const SubtargetInfoKV *Found =
83 std::lower_bound(ProcItins, ProcItins+NumProcs, KV);
84 if (Found == ProcItins+NumProcs || StringRef(Found->Key) != CPU) {
85 errs() << "'" << CPU
86 << "' is not a recognized processor for this target"
87 << " (ignoring processor)\n";
88 return InstrItineraryData();
89 }
90
91 return InstrItineraryData(Stages, OperandCycles, ForwardingPathes,
92 (InstrItinerary *)Found->Value);
93}