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