}
}
-struct EnumAttr {
- static bool isSet(const Function &Fn,
- Attribute::AttrKind Kind) {
- return Fn.hasFnAttribute(Kind);
- }
-
- static void set(Function &Fn,
- Attribute::AttrKind Kind, bool Val) {
- if (Val)
- Fn.addFnAttr(Kind);
- else
- Fn.removeFnAttr(Kind);
- }
-};
-
-struct StrBoolAttr {
- static bool isSet(const Function &Fn,
- StringRef Kind) {
- auto A = Fn.getFnAttribute(Kind);
- return A.getValueAsString().equals("true");
- }
-
- static void set(Function &Fn,
- StringRef Kind, bool Val) {
- Fn.addFnAttr(Kind, Val ? "true" : "false");
- }
-};
-
-#define GET_ATTR_NAMES
-#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
- struct ENUM_NAME##Attr : EnumAttr { \
- static enum Attribute::AttrKind getKind() { \
- return llvm::Attribute::ENUM_NAME; \
- } \
- };
-#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
- struct ENUM_NAME##Attr : StrBoolAttr { \
- static StringRef getKind() { return #DISPLAY_NAME; } \
- };
-#include "llvm/IR/Attributes.inc"
-
#define GET_ATTR_COMPAT_FUNC
-#include "llvm/IR/Attributes.inc"
+#include "AttributesCompatFunc.inc"
bool AttributeFuncs::areInlineCompatible(const Function &Caller,
const Function &Callee) {
void emit(raw_ostream &OS);
private:
- void emitTargetIndependentNames(raw_ostream &OS);
+ void emitTargetIndependentEnums(raw_ostream &OS);
+ void emitConversionFn(raw_ostream &OS);
void emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr);
+ void printEnumAttrClasses(raw_ostream &OS,
+ const std::vector<Record *> &Records);
+ void printStrBoolAttrClasses(raw_ostream &OS,
+ const std::vector<Record *> &Records);
+
RecordKeeper &Records;
};
} // End anonymous namespace.
-void Attributes::emitTargetIndependentNames(raw_ostream &OS) {
- OS << "#ifdef GET_ATTR_NAMES\n";
- OS << "#undef GET_ATTR_NAMES\n";
+void Attributes::emitTargetIndependentEnums(raw_ostream &OS) {
+ OS << "#ifdef GET_ATTR_ENUM\n";
+ OS << "#undef GET_ATTR_ENUM\n";
- OS << "#ifndef ATTRIBUTE_ALL\n";
- OS << "#define ATTRIBUTE_ALL(FIRST, SECOND)\n";
- OS << "#endif\n\n";
+ std::vector<Record*> Attrs =
+ Records.getAllDerivedDefinitions("EnumAttr");
- auto Emiter = [&](StringRef KindName, StringRef MacroName) {
- std::vector<Record *> Attrs = Records.getAllDerivedDefinitions(KindName);
+ for (auto A : Attrs)
+ OS << A->getName() << ",\n";
- OS << "#ifndef " << MacroName << "\n";
- OS << "#define " << MacroName << "(FIRST, SECOND) ATTRIBUTE_ALL(FIRST, "
- "SECOND)\n";
- OS << "#endif\n\n";
+ OS << "#endif\n";
+}
- for (auto A : Attrs) {
- OS << "" << MacroName << "(" << A->getName() << ","
- << A->getValueAsString("AttrString") << ")\n";
- }
- OS << "#undef " << MacroName << "\n\n";
- };
+void Attributes::emitConversionFn(raw_ostream &OS) {
+ OS << "#ifdef GET_ATTR_KIND_FROM_NAME\n";
+ OS << "#undef GET_ATTR_KIND_FROM_NAME\n";
- Emiter("EnumAttr", "ATTRIBUTE_ENUM");
- Emiter("StrBoolAttr", "ATTRIBUTE_STRBOOL");
+ std::vector<Record*> Attrs =
+ Records.getAllDerivedDefinitions("EnumAttr");
+
+ OS << "static Attribute::AttrKind getAttrKindFromName(StringRef AttrName) {\n";
+ OS << " return StringSwitch<Attribute::AttrKind>(AttrName)\n";
+
+ for (auto A : Attrs) {
+ OS << " .Case(\"" << A->getValueAsString("AttrString");
+ OS << "\", Attribute::" << A->getName() << ")\n";
+ }
+
+ OS << " .Default(Attribute::None);\n";
+ OS << "}\n\n";
- OS << "#undef ATTRIBUTE_ALL\n";
OS << "#endif\n";
}
OS << "#ifdef GET_ATTR_COMPAT_FUNC\n";
OS << "#undef GET_ATTR_COMPAT_FUNC\n";
+ OS << "struct EnumAttr {\n";
+ OS << " static bool isSet(const Function &Fn,\n";
+ OS << " Attribute::AttrKind Kind) {\n";
+ OS << " return Fn.hasFnAttribute(Kind);\n";
+ OS << " }\n\n";
+ OS << " static void set(Function &Fn,\n";
+ OS << " Attribute::AttrKind Kind, bool Val) {\n";
+ OS << " if (Val)\n";
+ OS << " Fn.addFnAttr(Kind);\n";
+ OS << " else\n";
+ OS << " Fn.removeFnAttr(Kind);\n";
+ OS << " }\n";
+ OS << "};\n\n";
+
+ OS << "struct StrBoolAttr {\n";
+ OS << " static bool isSet(const Function &Fn,\n";
+ OS << " StringRef Kind) {\n";
+ OS << " auto A = Fn.getFnAttribute(Kind);\n";
+ OS << " return A.getValueAsString().equals(\"true\");\n";
+ OS << " }\n\n";
+ OS << " static void set(Function &Fn,\n";
+ OS << " StringRef Kind, bool Val) {\n";
+ OS << " Fn.addFnAttr(Kind, Val ? \"true\" : \"false\");\n";
+ OS << " }\n";
+ OS << "};\n\n";
+
+ printEnumAttrClasses(OS ,Records.getAllDerivedDefinitions("EnumAttr"));
+ printStrBoolAttrClasses(OS , Records.getAllDerivedDefinitions("StrBoolAttr"));
+
OS << "static inline bool hasCompatibleFnAttrs(const Function &Caller,\n"
<< " const Function &Callee) {\n";
OS << " bool Ret = true;\n\n";
OS << "#endif\n";
}
+void Attributes::printEnumAttrClasses(raw_ostream &OS,
+ const std::vector<Record *> &Records) {
+ OS << "// EnumAttr classes\n";
+ for (const auto *R : Records) {
+ OS << "struct " << R->getName() << "Attr : EnumAttr {\n";
+ OS << " static enum Attribute::AttrKind getKind() {\n";
+ OS << " return llvm::Attribute::" << R->getName() << ";\n";
+ OS << " }\n";
+ OS << "};\n";
+ }
+ OS << "\n";
+}
+
+void Attributes::printStrBoolAttrClasses(raw_ostream &OS,
+ const std::vector<Record *> &Records) {
+ OS << "// StrBoolAttr classes\n";
+ for (const auto *R : Records) {
+ OS << "struct " << R->getName() << "Attr : StrBoolAttr {\n";
+ OS << " static StringRef getKind() {\n";
+ OS << " return \"" << R->getValueAsString("AttrString") << "\";\n";
+ OS << " }\n";
+ OS << "};\n";
+ }
+ OS << "\n";
+}
+
void Attributes::emit(raw_ostream &OS) {
- emitTargetIndependentNames(OS);
+ emitTargetIndependentEnums(OS);
+ emitConversionFn(OS);
emitFnAttrCompatCheck(OS, false);
}