Lines Matching defs:os

186                              raw_ostream &os) {
188 os << availability.getQueryFnRetType() << " ";
193 os << cppNamespace << "::";
196 os << availability.getInterfaceClassName() << "::" << methodName << "() {\n"
201 static bool emitInterfaceDefs(const RecordKeeper &records, raw_ostream &os) {
202 llvm::emitSourceFileHeader("Availability Interface Definitions", os, records);
217 emitInterfaceDef(availability, os);
227 static void emitConceptDecl(const Availability &availability, raw_ostream &os) {
228 os << " class Concept {\n"
237 static void emitModelDecl(const Availability &availability, raw_ostream &os) {
239 os << " template<typename ConcreteOp>\n";
240 os << " class " << modelClass << " : public Concept {\n"
254 os << " template<typename ConcreteModel, typename ConcreteOp>\n";
255 os << " class ExternalModel : public FallbackModel<ConcreteOp> {};\n";
259 raw_ostream &os) {
265 NamespaceEmitter nsEmitter(os, cppNamespace);
266 os << "class " << interfaceName << ";\n\n";
269 os << "namespace detail {\n"
271 emitConceptDecl(availability, os);
272 os << '\n';
273 emitModelDecl(availability, os);
274 os << "};\n} // namespace detail\n\n";
277 os << "/*\n" << availability.getInterfaceDescription().trim() << "\n*/\n";
278 os << llvm::formatv("class {0} : public OpInterface<{1}, detail::{2}> {\n"
284 os << " " << availability.getQueryFnRetType() << " "
286 os << "};\n\n";
289 static bool emitInterfaceDecls(const RecordKeeper &records, raw_ostream &os) {
290 llvm::emitSourceFileHeader("Availability Interface Declarations", os,
306 emitInterfaceDecl(avail, os);
320 [](const RecordKeeper &records, raw_ostream &os) {
321 return emitInterfaceDecls(records, os);
328 [](const RecordKeeper &records, raw_ostream &os) {
329 return emitInterfaceDefs(records, os);
337 raw_ostream &os) {
356 os << formatv("std::optional<{0}> {1}({2} value) {{\n",
360 os << " switch (value) {\n";
364 os << formatv(" case {0}::{1}: { {2} return {3}({4}); }\n", enumName,
370 os << " default: break;\n";
371 os << " }\n"
378 raw_ostream &os) {
398 os << formatv("std::optional<{0}> {1}({2} value) {{\n",
402 os << formatv(
407 os << " switch (value) {\n";
411 os << formatv(" case {0}::{1}: { {2} return {3}({4}); }\n", enumName,
415 os << " default: break;\n";
416 os << " }\n"
422 static void emitEnumDecl(const Record &enumDef, raw_ostream &os) {
432 os << "namespace " << ns << " {\n";
443 os << formatv("std::optional<{0}> {1}({2} value);\n",
450 os << "} // namespace " << ns << "\n";
453 static bool emitEnumDecls(const RecordKeeper &records, raw_ostream &os) {
454 llvm::emitSourceFileHeader("SPIR-V Enum Availability Declarations", os,
459 emitEnumDecl(*def, os);
464 static void emitEnumDef(const Record &enumDef, raw_ostream &os) {
472 os << "namespace " << ns << " {\n";
475 emitAvailabilityQueryForBitEnum(enumDef, os);
477 emitAvailabilityQueryForIntEnum(enumDef, os);
481 os << "} // namespace " << ns << "\n";
482 os << "\n";
485 static bool emitEnumDefs(const RecordKeeper &records, raw_ostream &os) {
486 llvm::emitSourceFileHeader("SPIR-V Enum Availability Definitions", os,
491 emitEnumDef(*def, os);
504 [](const RecordKeeper &records, raw_ostream &os) {
505 return emitEnumDecls(records, os);
512 [](const RecordKeeper &records, raw_ostream &os) {
513 return emitEnumDefs(records, os);
528 /// Generates code to serialize attributes of a SPIRV_Op `op` into `os`. The
534 StringRef attrName, raw_ostream &os) {
535 os << tabs
539 os << tabs
548 os << tabs
555 os << tabs << " for (auto attrElem : llvm::cast<ArrayAttr>(attr)) {\n";
556 os << tabs
561 os << tabs << " }\n";
563 os << tabs
572 os << tabs << formatv(" uint32_t {0} = 0;\n", attrTypeID);
573 os << tabs
577 os << tabs << " return failure();\n";
578 os << tabs << " }\n";
579 os << tabs << formatv(" {0}.push_back(attrTypeID);\n", operandList);
587 os << tabs << "}\n";
590 /// Generates code to serialize the operands of a SPIRV_Op `op` into `os`. The
597 raw_ostream &os) {
625 os << tabs
627 os << tabs << " auto id = getValueID(operand);\n";
628 os << tabs << " assert(id && \"use before def!\");\n";
629 os << tabs << formatv(" {0}.push_back(id);\n", operands);
630 os << tabs << "}\n";
635 tabs, opVar, operands, attr.name, os);
636 os << tabs
646 os << tabs << "{\n";
648 os << tabs
651 os << tabs << " auto argID = getValueID(arg);\n";
652 os << tabs << " if (!argID) {\n";
653 os << tabs
657 os << tabs << " }\n";
658 os << tabs << formatv(" {0}.push_back(argID);\n", operands);
659 os << " }\n";
666 loc, newtabs, opVar, operands, attr->name, os);
667 os << newtabs
670 os << tabs << "}\n";
674 /// Generates code to serializes the result of SPIRV_Op `op` into `os`. The
680 raw_ostream &os) {
683 os << tabs << formatv("uint32_t {0} = 0;\n", resultTypeID);
684 os << tabs
688 os << tabs << " return failure();\n";
689 os << tabs << "}\n";
690 os << tabs << formatv("{0}.push_back({1});\n", operands, resultTypeID);
692 os << tabs << formatv("{0} = getNextID();\n", resultID);
693 os << tabs
695 os << tabs << formatv("{0}.push_back({1});\n", operands, resultID);
706 StringRef resultID, raw_ostream &os) {
709 os << tabs << formatv("for (auto attr : {0}->getAttrs()) {{\n", opVar);
710 os << tabs
713 os << tabs << " continue;\n";
714 os << tabs << " }\n";
715 os << tabs
719 os << tabs << " return failure();\n";
720 os << tabs << " }\n";
721 os << tabs << "}\n";
725 /// Generates code to serialize an SPIRV_Op `op` into `os`.
728 raw_ostream &os) {
736 os << formatv(
754 os << formatv(" return processOpWithoutGrammarAttr({0}, {1}, {2});\n}\n\n",
759 os << formatv(" SmallVector<uint32_t, 4> {0};\n", operands);
760 os << formatv(" SmallVector<StringRef, 2> {0};\n", elidedAttrs);
764 os << formatv(" uint32_t {0} = 0;\n", resultID);
766 resultID, os);
771 elidedAttrs, os);
774 os << formatv(
780 os << formatv(" (void)emitDebugLine(functionBody, {0}.getLoc());\n",
782 os << formatv(" (void)encodeInstructionInto("
788 emitDecorationSerialization(op, " ", opVar, elidedAttrs, resultID, os);
790 os << " return success();\n";
791 os << "}\n\n";
796 static void initDispatchSerializationFn(StringRef opVar, raw_ostream &os) {
797 os << formatv(
807 StringRef opVar, raw_ostream &os) {
808 os << tabs
810 os << tabs
813 os << tabs << "}\n";
818 static void finalizeDispatchSerializationFn(StringRef opVar, raw_ostream &os) {
819 os << formatv(
822 os << "}\n\n";
825 /// Generates code to deserialize the attribute of a SPIRV_Op into `os`. The
832 raw_ostream &os) {
835 os << tabs
844 os << tabs
851 os << tabs << "SmallVector<Attribute, 4> attrListElems;\n";
852 os << tabs << formatv("while ({0} < {1}.size()) {{\n", wordIndex, words);
853 os << tabs
859 os << tabs << "}\n";
860 os << tabs
865 os << tabs
870 os << tabs
883 /// `os`. The generated code gets the type of the result specified at
891 raw_ostream &os) {
894 os << tabs << "{\n";
895 os << tabs << formatv(" if ({0} >= {1}.size()) {{\n", wordIndex, words);
896 os << tabs
901 os << tabs << " }\n";
902 os << tabs << formatv(" auto ty = getType({0}[{1}]);\n", words, wordIndex);
903 os << tabs << " if (!ty) {\n";
904 os << tabs
909 os << tabs << " }\n";
910 os << tabs << formatv(" {0}.push_back(ty);\n", resultTypes);
911 os << tabs << formatv(" {0}++;\n", wordIndex);
912 os << tabs << formatv(" if ({0} >= {1}.size()) {{\n", wordIndex, words);
913 os << tabs
918 os << tabs << " }\n";
919 os << tabs << "}\n";
920 os << tabs << formatv("{0} = {1}[{2}++];\n", valueID, words, wordIndex);
927 /// `os`. The generated code reads the `words` of the binary instruction, from
934 StringRef attributes, raw_ostream &os) {
945 os << tabs
948 os << tabs << formatv("if ({0} < {1}.size())", wordIndex, words);
950 os << " {\n";
951 os << tabs
953 os << tabs << " if (!arg) {\n";
954 os << tabs
959 os << tabs << " }\n";
960 os << tabs << formatv(" {0}.push_back(arg);\n", operands);
962 os << tabs << formatv(" {0}++;\n", wordIndex);
964 os << tabs << "}\n";
966 os << tabs << formatv("if ({0} < {1}.size()) {{\n", wordIndex, words);
971 loc, newtabs, attributes, attr->name, words, wordIndex, os);
972 os << " }\n";
976 os << tabs << formatv("if ({0} != {1}.size()) {{\n", wordIndex, words);
977 os << tabs
983 os << tabs << "}\n\n";
992 raw_ostream &os) {
995 os << tabs << formatv("if (decorations.count({0})) {{\n", valueID);
996 os << tabs
998 os << tabs
1000 os << tabs << "}\n";
1004 /// Generates code to deserialize an SPIRV_Op `op` into `os`.
1007 const Operator &op, raw_ostream &os) {
1017 os << formatv("template <> "
1024 os << formatv(" return processOpWithoutGrammarAttr("
1031 os << formatv(" SmallVector<Type, 1> {0};\n", resultTypes);
1032 os << formatv(" size_t {0} = 0; (void){0};\n", wordIndex);
1033 os << formatv(" uint32_t {0} = 0; (void){0};\n", valueID);
1037 resultTypes, valueID, os);
1039 os << formatv(" SmallVector<Value, 4> {0};\n", operands);
1040 os << formatv(" SmallVector<NamedAttribute, 4> {0};\n", attributes);
1043 operands, attributes, os);
1046 emitDecorationDeserialization(op, " ", valueID, attributes, os);
1048 os << formatv(" Location loc = createFileLineColLoc(opBuilder);\n");
1049 os << formatv(" auto {1} = opBuilder.create<{0}>(loc, {2}, {3}, {4}); "
1054 os << formatv(" valueMap[{0}] = {1}.getResult();\n\n", valueID, opVar);
1061 os << formatv(" if ({0}.hasTrait<OpTrait::IsTerminator>())\n", opVar);
1062 os << formatv(" (void)clearDebugLine();\n");
1063 os << " return success();\n";
1064 os << "}\n\n";
1070 raw_ostream &os) {
1071 os << formatv("LogicalResult spirv::Deserializer::"
1075 os << formatv(" switch ({0}) {{\n", opcode);
1082 raw_ostream &os) {
1083 os << tabs
1086 os << tabs
1094 raw_ostream &os) {
1095 os << " default:\n";
1096 os << " ;\n";
1097 os << " }\n";
1099 os << formatv(" auto {0} = spirv::stringifyOpcode({1});\n", opcodeVar,
1101 os << formatv(" if (!{0}.empty()) {{\n", opcodeVar);
1102 os << formatv(" return emitError(unknownLoc, \"unhandled deserialization "
1105 os << " } else {\n";
1106 os << formatv(" return emitError(unknownLoc, \"unhandled opcode \") << "
1109 os << " }\n";
1110 os << "}\n";
1116 raw_ostream &os) {
1117 os << formatv("LogicalResult spirv::Deserializer::"
1124 raw_ostream &os) {
1139 os);
1163 os << extensionSet.second.str();
1164 os << " default:\n";
1165 os << formatv(
1169 os << " }\n";
1170 os << " }\n";
1173 os << formatv(" return emitError(unknownLoc, \"unhandled deserialization of "
1176 os << "}\n";
1181 static bool emitSerializationFns(const RecordKeeper &records, raw_ostream &os) {
1182 llvm::emitSourceFileHeader("SPIR-V Serialization Utilities/Functions", os,
1216 os << "#ifdef GET_SERIALIZATION_FNS\n\n";
1217 os << serFn.str();
1218 os << dSerFn.str();
1219 os << "#endif // GET_SERIALIZATION_FNS\n\n";
1221 os << "#ifdef GET_DESERIALIZATION_FNS\n\n";
1222 os << deserFn.str();
1223 os << dDesFn.str();
1224 os << "#endif // GET_DESERIALIZATION_FNS\n\n";
1236 [](const RecordKeeper &records, raw_ostream &os) {
1237 return emitSerializationFns(records, os);
1244 static void emitEnumGetAttrNameFnDecl(raw_ostream &os) {
1245 os << formatv("template <typename EnumClass> inline constexpr StringRef "
1250 raw_ostream &os) {
1252 os << formatv("template <> inline StringRef attributeName<{0}>() {{\n",
1254 os << " "
1257 os << " return attrName;\n";
1258 os << "}\n";
1261 static bool emitAttrUtils(const RecordKeeper &records, raw_ostream &os) {
1262 llvm::emitSourceFileHeader("SPIR-V Attribute Utilities", os, records);
1265 os << "#ifndef MLIR_DIALECT_SPIRV_IR_ATTR_UTILS_H_\n";
1266 os << "#define MLIR_DIALECT_SPIRV_IR_ATTR_UTILS_H_\n";
1267 emitEnumGetAttrNameFnDecl(os);
1270 emitEnumGetAttrNameFnDefn(enumAttr, os);
1272 os << "#endif // MLIR_DIALECT_SPIRV_IR_ATTR_UTILS_H\n";
1283 [](const RecordKeeper &records, raw_ostream &os) {
1284 return emitAttrUtils(records, os);
1291 static void emitAvailabilityImpl(const Operator &srcOp, raw_ostream &os) {
1323 os << formatv("{0} {1}::{2}() {{\n", avail.getQueryFnRetType(),
1327 os << formatv(" {0} tblgen_overall = {1};\n", avail.getQueryFnRetType(),
1335 os << " {\n "
1372 os << formatv(" for (unsigned i = 0; "
1375 os << formatv(" {0}::{1} tblgen_attrVal = this->{2}() & "
1379 os << formatv(
1384 os << " {\n";
1385 os << formatv(" auto tblgen_attrVal = this->{0}();\n",
1388 os << formatv(" auto tblgen_instance = {0}::{1}(tblgen_attrVal);\n",
1390 os << " if (tblgen_instance) "
1397 os << " }\n";
1400 os << " return tblgen_overall;\n";
1401 os << "}\n";
1405 static bool emitAvailabilityImpl(const RecordKeeper &records, raw_ostream &os) {
1406 llvm::emitSourceFileHeader("SPIR-V Op Availability Implementations", os,
1413 emitAvailabilityImpl(op, os);
1425 [](const RecordKeeper &records, raw_ostream &os) {
1426 return emitAvailabilityImpl(records, os);
1434 raw_ostream &os) {
1435 llvm::emitSourceFileHeader("SPIR-V Capability Implication", os, records);
1440 os << "ArrayRef<spirv::Capability> "
1451 os << " case spirv::Capability::" << enumerant.getSymbol()
1454 llvm::interleaveComma(impliedCapsDefs, os, [&](const Record *capDef) {
1455 os << "spirv::Capability::" << EnumAttrCase(capDef).getSymbol();
1457 os << "}; return ArrayRef<spirv::Capability>(implies, "
1460 os << " }\n";
1461 os << "}\n";
1474 [](const RecordKeeper &records, raw_ostream &os) {
1475 return emitCapabilityImplication(records, os);