MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / gen_enum_param_list_macro

Function gen_enum_param_list_macro

imperative/tablegen/targets/macros.cpp:6–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5namespace mlir::tblgen {
6bool gen_enum_param_list_macro(raw_ostream& os, llvm::RecordKeeper& keeper) {
7 std::vector<std::pair<std::string, std::string>> enums;
8 std::vector<std::pair<std::string, std::string>> bit_enums;
9 Environment env;
10 foreach_operator(keeper, [&](MgbOp& op) {
11 for (auto&& i : op.getAttributes()) {
12 if (auto attr = llvm::dyn_cast<MgbEnumAttr>(&i.attr)) {
13 auto insert = [&](const MgbEnumAttr& attr) {
14 auto&& item = std::make_pair(
15 attr.getParentNamespace(), attr.getEnumName());
16 if (env.enumAlias
17 .emplace(attr.getBaseRecord()->getID(), std::move(item))
18 .second) {
19 if (attr.getEnumCombinedFlag()) {
20 bit_enums.emplace_back(item);
21 } else {
22 enums.emplace_back(item);
23 }
24 }
25 };
26 if (auto alias = llvm::dyn_cast<MgbAliasAttr>(attr)) {
27 auto&& aliasBase = alias->getAliasBase();
28 insert(llvm::cast<MgbEnumAttr>(aliasBase));
29 } else {
30 insert(*attr);
31 }
32 }
33 }
34 });
35 os << "#define FOR_EACH_ENUM_PARAM(cb)";
36 for (auto&& i : enums) {
37 os << formatv(" \\\n cb({0}::{1});", i.first, i.second);
38 }
39 os << "\n";
40 os << "#define FOR_EACH_BIT_COMBINED_ENUM_PARAM(cb)";
41 for (auto&& i : bit_enums) {
42 os << formatv(" \\\n cb({0}::{1});", i.first, i.second);
43 }
44 os << "\n";
45 return false;
46}
47} // namespace mlir::tblgen

Callers

nothing calls this directly

Calls 8

foreach_operatorFunction · 0.85
getParentNamespaceMethod · 0.80
getEnumNameMethod · 0.80
getBaseRecordMethod · 0.80
getEnumCombinedFlagMethod · 0.80
emplace_backMethod · 0.80
getAliasBaseMethod · 0.80
emplaceMethod · 0.45

Tested by

no test coverage detected