Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / utils / LibcTableGenUtil / APIIndexer.h
blobd530dc7174555c03cf927e109f65d76206f7d346
1 //===-- A class to index libc API listed in tablegen files ------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H
10 #define LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/TableGen/Record.h"
15 #include <optional>
16 #include <string>
17 #include <unordered_map>
18 #include <unordered_set>
20 namespace llvm_libc {
22 class APIIndexer {
23 private:
24 std::optional<llvm::StringRef> StdHeader;
26 // TableGen classes in spec.td.
27 llvm::Record *NamedTypeClass;
28 llvm::Record *PtrTypeClass;
29 llvm::Record *RestrictedPtrTypeClass;
30 llvm::Record *ConstTypeClass;
31 llvm::Record *StructClass;
32 llvm::Record *StandardSpecClass;
33 llvm::Record *PublicAPIClass;
35 bool isaNamedType(llvm::Record *Def);
36 bool isaStructType(llvm::Record *Def);
37 bool isaPtrType(llvm::Record *Def);
38 bool isaConstType(llvm::Record *Def);
39 bool isaRestrictedPtrType(llvm::Record *Def);
40 bool isaStandardSpec(llvm::Record *Def);
41 bool isaPublicAPI(llvm::Record *Def);
43 void indexStandardSpecDef(llvm::Record *StandardSpec);
44 void indexPublicAPIDef(llvm::Record *PublicAPI);
45 void index(llvm::RecordKeeper &Records);
47 public:
48 using NameToRecordMapping = std::unordered_map<std::string, llvm::Record *>;
49 using NameSet = std::unordered_set<std::string>;
51 // This indexes all headers, not just a specified one.
52 explicit APIIndexer(llvm::RecordKeeper &Records) : StdHeader(std::nullopt) {
53 index(Records);
56 APIIndexer(llvm::StringRef Header, llvm::RecordKeeper &Records)
57 : StdHeader(Header) {
58 index(Records);
61 // Mapping from names to records defining them.
62 NameToRecordMapping MacroSpecMap;
63 NameToRecordMapping TypeSpecMap;
64 NameToRecordMapping EnumerationSpecMap;
65 NameToRecordMapping FunctionSpecMap;
66 NameToRecordMapping MacroDefsMap;
67 NameToRecordMapping ObjectSpecMap;
69 std::unordered_map<std::string, std::string> FunctionToHeaderMap;
70 std::unordered_map<std::string, std::string> ObjectToHeaderMap;
72 NameSet RequiredTypes;
73 NameSet Structs;
74 NameSet Enumerations;
75 NameSet Functions;
76 NameSet Objects;
77 NameSet PublicHeaders;
79 std::string getTypeAsString(llvm::Record *TypeRecord);
82 } // namespace llvm_libc
84 #endif // LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H