1//===- TargetFeaturesEmitter.h- Generate CPU Target features ----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Defines the TargetFeaturesEmitter class, which is used to export
10// CPU target features and CPU subtypes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_UTILS_TABLEGEN_BASIC_EMITTARGETFEATURE_H
15#define LLVM_UTILS_TABLEGEN_BASIC_EMITTARGETFEATURE_H
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/TableGen/Record.h"
19
20namespace llvm {
21/// Sorting predicate to sort record pointers by their
22/// FieldName field.
23struct LessRecordFieldFieldName {
24 bool operator()(const Record *Rec1, const Record *Rec2) const {
25 return Rec1->getValueAsString(FieldName: "FieldName") <
26 Rec2->getValueAsString(FieldName: "FieldName");
27 }
28};
29
30using FeatureMapTy = DenseMap<const Record *, unsigned>;
31
32class TargetFeaturesEmitter {
33protected:
34 const RecordKeeper &Records;
35 std::string Target;
36
37public:
38 TargetFeaturesEmitter(const RecordKeeper &R);
39 static void printFeatureMask(raw_ostream &OS,
40 ArrayRef<const Record *> FeatureList,
41 const FeatureMapTy &FeatureMap);
42 FeatureMapTy enumeration(raw_ostream &OS);
43 void printFeatureKeyValues(raw_ostream &OS, const FeatureMapTy &FeatureMap);
44 void printCPUKeyValues(raw_ostream &OS, const FeatureMapTy &FeatureMap);
45 virtual void run(raw_ostream &O);
46 virtual ~TargetFeaturesEmitter() {};
47};
48} // namespace llvm
49#endif
50