@@ -82,29 +82,31 @@ struct VerCapExtAttributeStorage : public AttributeStorage {
8282};
8383
8484struct TargetEnvAttributeStorage : public AttributeStorage {
85- using KeyTy = std::tuple<Attribute, Vendor, DeviceType, uint32_t , Attribute>;
85+ using KeyTy =
86+ std::tuple<Attribute, ClientAPI, Vendor, DeviceType, uint32_t , Attribute>;
8687
87- TargetEnvAttributeStorage (Attribute triple, Vendor vendorID ,
88- DeviceType deviceType, uint32_t deviceID ,
89- Attribute limits)
90- : triple(triple), limits(limits), vendorID(vendorID ),
91- deviceType (deviceType), deviceID(deviceID) {}
88+ TargetEnvAttributeStorage (Attribute triple, ClientAPI clientAPI ,
89+ Vendor vendorID, DeviceType deviceType ,
90+ uint32_t deviceID, Attribute limits)
91+ : triple(triple), limits(limits), clientAPI(clientAPI ),
92+ vendorID (vendorID), deviceType(deviceType), deviceID(deviceID) {}
9293
9394 bool operator ==(const KeyTy &key) const {
94- return key ==
95- std::make_tuple (triple, vendorID, deviceType, deviceID, limits);
95+ return key == std::make_tuple (triple, clientAPI, vendorID, deviceType,
96+ deviceID, limits);
9697 }
9798
9899 static TargetEnvAttributeStorage *
99100 construct (AttributeStorageAllocator &allocator, const KeyTy &key) {
100101 return new (allocator.allocate <TargetEnvAttributeStorage>())
101102 TargetEnvAttributeStorage (std::get<0 >(key), std::get<1 >(key),
102103 std::get<2 >(key), std::get<3 >(key),
103- std::get<4 >(key));
104+ std::get<4 >(key), std::get< 5 >(key) );
104105 }
105106
106107 Attribute triple;
107108 Attribute limits;
109+ ClientAPI clientAPI;
108110 Vendor vendorID;
109111 DeviceType deviceType;
110112 uint32_t deviceID;
@@ -282,14 +284,13 @@ spirv::VerCapExtAttr::verify(function_ref<InFlightDiagnostic()> emitError,
282284// TargetEnvAttr
283285// ===----------------------------------------------------------------------===//
284286
285- spirv::TargetEnvAttr spirv::TargetEnvAttr::get (spirv::VerCapExtAttr triple,
286- Vendor vendorID,
287- DeviceType deviceType,
288- uint32_t deviceID,
289- ResourceLimitsAttr limits) {
287+ spirv::TargetEnvAttr spirv::TargetEnvAttr::get (
288+ spirv::VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI,
289+ Vendor vendorID, DeviceType deviceType, uint32_t deviceID) {
290290 assert (triple && limits && " expected valid triple and limits" );
291291 MLIRContext *context = triple.getContext ();
292- return Base::get (context, triple, vendorID, deviceType, deviceID, limits);
292+ return Base::get (context, triple, clientAPI, vendorID, deviceType, deviceID,
293+ limits);
293294}
294295
295296StringRef spirv::TargetEnvAttr::getKindName () { return " target_env" ; }
@@ -318,6 +319,10 @@ ArrayAttr spirv::TargetEnvAttr::getCapabilitiesAttr() {
318319 return getTripleAttr ().getCapabilitiesAttr ();
319320}
320321
322+ spirv::ClientAPI spirv::TargetEnvAttr::getClientAPI () const {
323+ return getImpl ()->clientAPI ;
324+ }
325+
321326spirv::Vendor spirv::TargetEnvAttr::getVendorID () const {
322327 return getImpl ()->vendorID ;
323328}
@@ -523,6 +528,22 @@ static Attribute parseTargetEnvAttr(DialectAsmParser &parser) {
523528 if (parser.parseAttribute (tripleAttr) || parser.parseComma ())
524529 return {};
525530
531+ auto clientAPI = spirv::ClientAPI::Unknown;
532+ if (succeeded (parser.parseOptionalKeyword (" api" ))) {
533+ if (parser.parseEqual ())
534+ return {};
535+ auto loc = parser.getCurrentLocation ();
536+ StringRef apiStr;
537+ if (parser.parseKeyword (&apiStr))
538+ return {};
539+ if (auto apiSymbol = spirv::symbolizeClientAPI (apiStr))
540+ clientAPI = *apiSymbol;
541+ else
542+ parser.emitError (loc, " unknown client API: " ) << apiStr;
543+ if (parser.parseComma ())
544+ return {};
545+ }
546+
526547 // Parse [vendor[:device-type[:device-id]]]
527548 Vendor vendorID = Vendor::Unknown;
528549 DeviceType deviceType = DeviceType::Unknown;
@@ -531,22 +552,20 @@ static Attribute parseTargetEnvAttr(DialectAsmParser &parser) {
531552 auto loc = parser.getCurrentLocation ();
532553 StringRef vendorStr;
533554 if (succeeded (parser.parseOptionalKeyword (&vendorStr))) {
534- if (auto vendorSymbol = spirv::symbolizeVendor (vendorStr)) {
555+ if (auto vendorSymbol = spirv::symbolizeVendor (vendorStr))
535556 vendorID = *vendorSymbol;
536- } else {
557+ else
537558 parser.emitError (loc, " unknown vendor: " ) << vendorStr;
538- }
539559
540560 if (succeeded (parser.parseOptionalColon ())) {
541561 loc = parser.getCurrentLocation ();
542562 StringRef deviceTypeStr;
543563 if (parser.parseKeyword (&deviceTypeStr))
544564 return {};
545- if (auto deviceTypeSymbol = spirv::symbolizeDeviceType (deviceTypeStr)) {
565+ if (auto deviceTypeSymbol = spirv::symbolizeDeviceType (deviceTypeStr))
546566 deviceType = *deviceTypeSymbol;
547- } else {
567+ else
548568 parser.emitError (loc, " unknown device type: " ) << deviceTypeStr;
549- }
550569
551570 if (succeeded (parser.parseOptionalColon ())) {
552571 loc = parser.getCurrentLocation ();
@@ -563,8 +582,8 @@ static Attribute parseTargetEnvAttr(DialectAsmParser &parser) {
563582 if (parser.parseAttribute (limitsAttr) || parser.parseGreater ())
564583 return {};
565584
566- return spirv::TargetEnvAttr::get (tripleAttr, vendorID, deviceType, deviceID ,
567- limitsAttr );
585+ return spirv::TargetEnvAttr::get (tripleAttr, limitsAttr, clientAPI, vendorID ,
586+ deviceType, deviceID );
568587}
569588
570589Attribute SPIRVDialect::parseAttribute (DialectAsmParser &parser,
@@ -616,6 +635,9 @@ static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer) {
616635static void print (spirv::TargetEnvAttr targetEnv, DialectAsmPrinter &printer) {
617636 printer << spirv::TargetEnvAttr::getKindName () << " <#spirv." ;
618637 print (targetEnv.getTripleAttr (), printer);
638+ auto clientAPI = targetEnv.getClientAPI ();
639+ if (clientAPI != spirv::ClientAPI::Unknown)
640+ printer << " , api=" << clientAPI;
619641 spirv::Vendor vendorID = targetEnv.getVendorID ();
620642 spirv::DeviceType deviceType = targetEnv.getDeviceType ();
621643 uint32_t deviceID = targetEnv.getDeviceID ();
0 commit comments