/src/keystone/llvm/lib/MC/MCSubtargetInfo.cpp
Line | Count | Source |
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/StringRef.h" |
12 | | #include "llvm/ADT/Triple.h" |
13 | | #include "llvm/MC/SubtargetFeature.h" |
14 | | #include "llvm/Support/raw_ostream.h" |
15 | | #include <algorithm> |
16 | | |
17 | | using namespace llvm_ks; |
18 | | |
19 | | static FeatureBitset getFeatures(StringRef CPU, StringRef FS, |
20 | | ArrayRef<SubtargetFeatureKV> ProcDesc, |
21 | 300k | ArrayRef<SubtargetFeatureKV> ProcFeatures) { |
22 | 300k | SubtargetFeatures Features(FS); |
23 | 300k | return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures); |
24 | 300k | } |
25 | | |
26 | 193k | void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) { |
27 | 193k | FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures); |
28 | 193k | if (!CPU.empty() && ProcSchedModels) |
29 | 29.1k | CPUSchedModel = &getSchedModelForCPU(CPU); |
30 | 193k | } |
31 | | |
32 | 106k | void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef FS) { |
33 | 106k | FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures); |
34 | 106k | } |
35 | | |
36 | | MCSubtargetInfo::MCSubtargetInfo( |
37 | | const Triple &TT, StringRef C, StringRef FS, |
38 | | ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD, |
39 | | const SubtargetInfoKV *ProcSched) |
40 | 193k | : TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD), |
41 | 193k | ProcSchedModels(ProcSched) { |
42 | 193k | InitMCProcessorInfo(CPU, FS); |
43 | 193k | } |
44 | | |
45 | | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
46 | | /// bits. This version does not change the implied bits. |
47 | 4.44k | FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) { |
48 | 4.44k | FeatureBits.flip(FB); |
49 | 4.44k | return FeatureBits; |
50 | 4.44k | } |
51 | | |
52 | 3.41k | FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) { |
53 | 3.41k | FeatureBits ^= FB; |
54 | 3.41k | return FeatureBits; |
55 | 3.41k | } |
56 | | |
57 | | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
58 | | /// bits. This version will also change all implied bits. |
59 | 5.13k | FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) { |
60 | 5.13k | SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures); |
61 | 5.13k | return FeatureBits; |
62 | 5.13k | } |
63 | | |
64 | 261k | FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) { |
65 | 261k | SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures); |
66 | 261k | return FeatureBits; |
67 | 261k | } |
68 | | |
69 | 29.1k | const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const { |
70 | 29.1k | assert(ProcSchedModels && "Processor machine model not available!"); |
71 | | |
72 | 29.1k | ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size()); |
73 | | |
74 | 29.1k | assert(std::is_sorted(SchedModels.begin(), SchedModels.end(), |
75 | 29.1k | [](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) { |
76 | 29.1k | return strcmp(LHS.Key, RHS.Key) < 0; |
77 | 29.1k | }) && |
78 | 29.1k | "Processor machine model table is not sorted"); |
79 | | |
80 | | // Find entry |
81 | 29.1k | auto Found = |
82 | 29.1k | std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU); |
83 | | #if 0 |
84 | | if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) { |
85 | | if (CPU != "help") // Don't error if the user asked for help. |
86 | | errs() << "'" << CPU |
87 | | << "' is not a recognized processor for this target" |
88 | | << " (ignoring processor)\n"; |
89 | | return MCSchedModel::GetDefaultSchedModel(); |
90 | | } |
91 | | #endif |
92 | 29.1k | assert(Found->Value && "Missing processor SchedModel value"); |
93 | 29.1k | return *(const MCSchedModel *)Found->Value; |
94 | 29.1k | } |
95 | | |