LLVM: lib/MC/MCSubtargetInfo.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

18#include

19#include

20#include

21#include

22

23using namespace llvm;

24

25

26template

28

30

31 if (F == A.end() || StringRef(F->Key) != S) return nullptr;

32

33 return F;

34}

35

36

37static

40

41

42 Bits |= Implies;

44 if (Implies.test(FE.Value))

45 SetImpliedBits(Bits, FE.Implies.getAsBitset(), FeatureTable);

46}

47

48

49static

53 if (FE.Implies.getAsBitset().test(Value)) {

54 Bits.reset(FE.Value);

56 }

57 }

58}

59

63 "Feature flags should start with '+' or '-'");

64

65

68

69 if (FeatureEntry) {

70

72 Bits.set(FeatureEntry->Value);

73

74

76 } else {

77 Bits.reset(FeatureEntry->Value);

78

79

81 }

82 } else {

83 errs() << "'" << Feature << "' is not a recognized feature for this target"

84 << " (ignoring feature)\n";

85 }

86}

87

88

90 size_t MaxLen = 0;

91 for (auto &I : Table)

92 MaxLen = std::max(MaxLen, std::strlen(I.Key));

93 return MaxLen;

94}

95

97 size_t MaxLen = 0;

99 MaxLen = std::max(MaxLen, I.size());

100 return MaxLen;

101}

102

103

106

107

108 static bool PrintOnce = false;

109 if (PrintOnce) {

110 return;

111 }

112

113

116

117

118 errs() << "Available CPUs for this target:\n\n";

119 for (auto &CPUName : CPUNames) {

120

121

122

123 if (CPUName == "apple-latest")

124 continue;

125 errs() << format(" %-*s - Select the %s processor.\n", MaxCPULen,

126 CPUName.str().c_str(), CPUName.str().c_str());

127 }

128 errs() << '\n';

129

130

131 errs() << "Available features for this target:\n\n";

132 for (auto &Feature : FeatTable)

133 errs() << format(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);

134 errs() << '\n';

135

136 errs() << "Use +feature to enable a feature, or -feature to disable it.\n"

137 "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";

138

139 PrintOnce = true;

140}

141

142

144

145

146 static bool PrintOnce = false;

147 if (PrintOnce) {

148 return;

149 }

150

151

152 errs() << "Available CPUs for this target:\n\n";

153 for (auto &CPU : CPUNames) {

154

155

156

157 if (CPU == "apple-latest")

158 continue;

159 errs() << "\t" << CPU << "\n";

160 }

161 errs() << '\n';

162

163 errs() << "Use -mcpu or -mtune to specify the target's processor.\n"

164 "For example, clang --target=aarch64-unknown-linux-gnu "

165 "-mcpu=cortex-a35\n";

166

167 PrintOnce = true;

168}

169

176

177 if (ProcDesc.empty() || ProcFeatures.empty())

179

182

184

185

186 if (CPU == "help")

187 Help(ProcNames, ProcFeatures);

188

189

190 else if (!CPU.empty()) {

192

193

194 if (CPUEntry) {

195

197 } else {

198 errs() << "'" << CPU << "' is not a recognized processor for this target"

199 << " (ignoring processor)\n";

200 }

201 }

202

203 if (!TuneCPU.empty()) {

205

206

207 if (CPUEntry) {

208

210 } else if (TuneCPU != CPU) {

211 errs() << "'" << TuneCPU << "' is not a recognized processor for this "

212 << "target (ignoring processor)\n";

213 }

214 }

215

216

217 for (const std::string &Feature : Features.getFeatures()) {

218

219 if (Feature == "+help")

220 Help(ProcNames, ProcFeatures);

221 else if (Feature == "+cpuhelp")

223 else

225 }

226

227 return Bits;

228}

229

232 FeatureBits =

233 getFeatures(*this, CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);

234 FeatureString = std::string(FS);

235

236 if (!TuneCPU.empty())

238 else

240}

241

244 FeatureBits =

245 getFeatures(*this, CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);

246 FeatureString = std::string(FS);

247}

248

254 const InstrStage *IS, const unsigned *OC, const unsigned *FP)

255 : TargetTriple(TT), CPU(std::string(C)), TuneCPU(std::string(TC)),

256 ProcNames(PN), ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),

257 WriteLatencyTable(WL), ReadAdvanceTable(RA), Stages(IS),

258 OperandCycles(OC), ForwardingPaths(FP) {

260}

261

263 FeatureBits.flip(FB);

264 return FeatureBits;

265}

266

268 FeatureBits ^= FB;

269 return FeatureBits;

270}

271

275 return FeatureBits;

276}

277

280 for (unsigned I = 0, E = FB.size(); I < E; I++) {

281 if (FB[I]) {

282 FeatureBits.reset(I);

284 }

285 }

286 return FeatureBits;

287}

288

290

293

294 if (FeatureEntry) {

295 if (FeatureBits.test(FeatureEntry->Value)) {

296 FeatureBits.reset(FeatureEntry->Value);

297

299 } else {

300 FeatureBits.set(FeatureEntry->Value);

301

302

304 ProcFeatures);

305 }

306 } else {

307 errs() << "'" << Feature << "' is not a recognized feature for this target"

308 << " (ignoring feature)\n";

309 }

310

311 return FeatureBits;

312}

313

316 return FeatureBits;

317}

318

321 return all_of(T.getFeatures(), [this](const std::string &F) {

322 assert(SubtargetFeatures::hasFlag(F) &&

323 "Feature flags should start with '+' or '-'");

324 const SubtargetFeatureKV *FeatureEntry =

325 Find(SubtargetFeatures::StripFlag(F), ProcFeatures);

326 if (!FeatureEntry)

327 report_fatal_error(Twine("'") + F +

328 "' is not a recognized feature for this target");

329

330 return FeatureBits.test(FeatureEntry->Value) ==

331 SubtargetFeatures::isEnabled(F);

332 });

333}

334

337 "Processor machine model table is not sorted");

338

339

341

342 if (!CPUEntry) {

343 if (CPU != "help")

344 errs() << "'" << CPU

345 << "' is not a recognized processor for this target"

346 << " (ignoring processor)\n";

348 }

349 assert(CPUEntry->SchedModel && "Missing processor SchedModel value");

351}

352

358

361 ForwardingPaths);

362}

363

364std::vector

366 std::vector EnabledFeatures;

368 return FeatureBits.test(FeatureKV.Value);

369 };

370 llvm::copy_if(ProcFeatures, std::back_inserter(EnabledFeatures), IsEnabled);

371 return EnabledFeatures;

372}

373

375 return std::nullopt;

376}

377

378std::optional

380 return std::nullopt;

381}

382

383std::optional

385 return std::nullopt;

386}

387

391

393 return UINT_MAX;

394}

395

399

401 unsigned NumStridedMemAccesses,

402 unsigned NumPrefetches,

403 bool HasCall) const {

404 return 1;

405}

406

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, ArrayRef< SubtargetFeatureKV > FeatureTable)

Definition MCSubtargetInfo.cpp:60

static const T * Find(StringRef S, ArrayRef< T > A)

Find KV in array using binary search.

Definition MCSubtargetInfo.cpp:27

static void SetImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies, ArrayRef< SubtargetFeatureKV > FeatureTable)

For each feature that is (transitively) implied by this feature, set it.

Definition MCSubtargetInfo.cpp:38

static void Help(ArrayRef< StringRef > CPUNames, ArrayRef< SubtargetFeatureKV > FeatTable)

Display help for feature and mcpu choices.

Definition MCSubtargetInfo.cpp:104

static void cpuHelp(ArrayRef< StringRef > CPUNames)

Display help for mcpu choices only.

Definition MCSubtargetInfo.cpp:143

static size_t getLongestEntryLength(ArrayRef< SubtargetFeatureKV > Table)

Return the length of the longest entry in the table.

Definition MCSubtargetInfo.cpp:89

static void ClearImpliedBits(FeatureBitset &Bits, unsigned Value, ArrayRef< SubtargetFeatureKV > FeatureTable)

For each feature that (transitively) implies this feature, clear it.

Definition MCSubtargetInfo.cpp:50

static FeatureBitset getFeatures(MCSubtargetInfo &STI, StringRef CPU, StringRef TuneCPU, StringRef FS, ArrayRef< StringRef > ProcNames, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)

Definition MCSubtargetInfo.cpp:170

SI optimize exec mask operations pre RA

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

bool empty() const

empty - Check if the array is empty.

const FeatureBitset & getAsBitset() const

Container class for subtarget features.

constexpr bool test(unsigned I) const

constexpr FeatureBitset & flip(unsigned I)

constexpr size_t size() const

Itinerary data supplied by a subtarget to be used by a target.

Generic base class for all target subtargets.

virtual unsigned getCacheLineSize() const

Return the target cache line size in bytes.

bool checkFeatures(StringRef FS) const

Check whether the subtarget features are enabled/disabled as per the provided string,...

Definition MCSubtargetInfo.cpp:319

virtual std::optional< unsigned > getCacheSize(unsigned Level) const

Return the cache size in bytes for the given level of cache.

Definition MCSubtargetInfo.cpp:374

virtual bool shouldPrefetchAddressSpace(unsigned AS) const

Definition MCSubtargetInfo.cpp:407

const MCSchedModel & getSchedModelForCPU(StringRef CPU) const

Get the machine model of a CPU.

Definition MCSubtargetInfo.cpp:335

virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const

Return the minimum stride necessary to trigger software prefetching.

Definition MCSubtargetInfo.cpp:400

virtual bool enableWritePrefetching() const

Definition MCSubtargetInfo.cpp:396

virtual unsigned getMaxPrefetchIterationsAhead() const

Return the maximum prefetch distance in terms of loop iterations.

Definition MCSubtargetInfo.cpp:392

virtual unsigned getPrefetchDistance() const

Return the preferred prefetch distance in terms of instructions.

Definition MCSubtargetInfo.cpp:388

std::vector< SubtargetFeatureKV > getEnabledProcessorFeatures() const

Return the list of processor features currently enabled.

Definition MCSubtargetInfo.cpp:365

FeatureBitset ApplyFeatureFlag(StringRef FS)

Apply a feature flag and return the re-computed feature bits, including all feature bits implied by t...

Definition MCSubtargetInfo.cpp:314

virtual std::optional< unsigned > getCacheAssociativity(unsigned Level) const

Return the cache associatvity for the given level of cache.

Definition MCSubtargetInfo.cpp:379

FeatureBitset SetFeatureBitsTransitively(const FeatureBitset &FB)

Set/clear additional feature bits, including all other bits they imply.

Definition MCSubtargetInfo.cpp:272

InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const

Get scheduling itinerary of a CPU.

Definition MCSubtargetInfo.cpp:354

void setDefaultFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)

Set the features to the default for the given CPU and TuneCPU, with ano appended feature string.

Definition MCSubtargetInfo.cpp:242

FeatureBitset ToggleFeature(uint64_t FB)

Toggle a feature and return the re-computed feature bits.

Definition MCSubtargetInfo.cpp:262

void InitMCProcessorInfo(StringRef CPU, StringRef TuneCPU, StringRef FS)

Initialize the scheduling model and feature bits.

Definition MCSubtargetInfo.cpp:230

void initInstrItins(InstrItineraryData &InstrItins) const

Initialize an InstrItineraryData instance.

Definition MCSubtargetInfo.cpp:359

FeatureBitset ClearFeatureBitsTransitively(const FeatureBitset &FB)

Definition MCSubtargetInfo.cpp:278

const MCSchedModel & getSchedModel() const

Get the machine model for this subtarget's CPU.

StringRef - Represent a constant reference to a string, i.e.

constexpr bool empty() const

empty - Check if the string is empty.

Manages the enabling and disabling of subtarget specific features.

const std::vector< std::string > & getFeatures() const

Returns the vector of individual subtarget features.

static bool hasFlag(StringRef Feature)

Determine if a feature has a flag; '+' or '-'.

static StringRef StripFlag(StringRef Feature)

Return string stripped of flag.

static bool isEnabled(StringRef Feature)

Return true if enable flag; '+'.

Triple - Helper class for working with autoconf configuration names.

LLVM Value Representation.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

bool all_of(R &&range, UnaryPredicate P)

Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.

OutputIt copy_if(R &&Range, OutputIt Out, UnaryPredicate P)

Provide wrappers to std::copy_if which take ranges instead of having to pass begin/end explicitly.

bool is_sorted(R &&Range, Compare C)

Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

LLVM_ABI raw_fd_ostream & errs()

This returns a reference to a raw_ostream for standard error.

auto lower_bound(R &&Range, T &&Value)

Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...

Implement std::hash so that hash_code can be used in STL containers.

These values represent a non-pipelined step in the execution of an instruction.

Specify the number of cycles allowed after instruction issue before a particular use operand reads it...

Machine model for scheduling, bundling, and heuristics.

static LLVM_ABI const MCSchedModel Default

Returns the default initialized model.

Specify the latency in cpu cycles for a particular scheduling class and def index.

Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...

Used to provide key value pairs for feature and CPU bit flags.

unsigned Value

K-V integer value.

FeatureBitArray Implies

K-V bit mask.

Used to provide key value pairs for feature and CPU bit flags.

const MCSchedModel * SchedModel

FeatureBitArray Implies

K-V bit mask.

FeatureBitArray TuneImplies

K-V bit mask.