@@ -335,16 +335,15 @@ LogicalResult ProfileInfoDepot::populatationDispatch(Operation *op) {
335
335
// ===----------------------------------------------------------------------===//
336
336
337
337
template <typename T>
338
- FailureOr<SmallVector<T>>
339
- TosaProfileCompliance::getOperatorDefinition (Operation *op,
340
- CheckCondition &condition) {
338
+ FailureOr<OpComplianceInfo<T>>
339
+ TosaProfileCompliance::getOperatorDefinition (Operation *op) {
341
340
const std::string opName = op->getName ().getStringRef ().str ();
342
341
const auto complianceMap = getProfileComplianceMap<T>();
343
342
const auto it = complianceMap.find (opName);
344
343
if (it == complianceMap.end ())
345
344
return {};
346
345
347
- return findMatchedProfile <T>(op, it->second , condition );
346
+ return findMatchedEntry <T>(op, it->second );
348
347
}
349
348
350
349
template <typename T>
@@ -356,22 +355,21 @@ LogicalResult TosaProfileCompliance::checkProfileOrExtension(
356
355
if (specRequiredModeSet.size () == 0 )
357
356
return success ();
358
357
359
- CheckCondition condition = CheckCondition::invalid;
360
- const auto maybeOpRequiredMode = getOperatorDefinition<T>(op, condition);
361
- if (failed (maybeOpRequiredMode)) {
358
+ const auto maybeOpDefinition = getOperatorDefinition<T>(op);
359
+ if (failed (maybeOpDefinition)) {
362
360
// Operators such as control-flow and shape ops do not have an operand type
363
361
// restriction. When the profile compliance information of operation is not
364
362
// found, confirm if the target have enabled the profile required from the
365
363
// specification.
366
- int mode_count = 0 ;
364
+ int modeCount = 0 ;
367
365
for (const auto &cands : specRequiredModeSet) {
368
366
if (targetEnv.allowsAnyOf (cands))
369
367
return success ();
370
- mode_count += cands.size ();
368
+ modeCount += cands.size ();
371
369
}
372
370
373
371
op->emitOpError () << " illegal: requires"
374
- << (mode_count > 1 ? " any of " : " " ) << " ["
372
+ << (modeCount > 1 ? " any of " : " " ) << " ["
375
373
<< llvm::join (stringifyProfile<T>(specRequiredModeSet),
376
374
" , " )
377
375
<< " ] but not enabled in target\n " ;
@@ -381,7 +379,10 @@ LogicalResult TosaProfileCompliance::checkProfileOrExtension(
381
379
382
380
// Find the required profiles or extensions according to the operand type
383
381
// combination.
384
- const auto opRequiredMode = maybeOpRequiredMode.value ();
382
+ const auto opDefinition = maybeOpDefinition.value ();
383
+ const SmallVector<T> opRequiredMode = opDefinition.mode ;
384
+ const CheckCondition condition = opDefinition.condition ;
385
+
385
386
if (opRequiredMode.size () == 0 ) {
386
387
// No matched restriction found.
387
388
return success ();
@@ -437,6 +438,21 @@ LogicalResult TosaProfileCompliance::checkProfileOrExtension(
437
438
}
438
439
}
439
440
441
+ // Ensure the matched op compliance version does not exceed the target
442
+ // specification version.
443
+ const VersionedTypeInfo versionedTypeInfo =
444
+ opDefinition.operandTypeInfoSet [0 ];
445
+ const TosaSpecificationVersion complianceVersion{versionedTypeInfo.second };
446
+ const TosaSpecificationVersion targetVersion{targetEnv.getSpecVersion ()};
447
+ if (!targetVersion.isBackwardsCompatibleWith (complianceVersion)) {
448
+ op->emitOpError () << " illegal: requires the target specification version ("
449
+ << stringifyVersion (targetVersion)
450
+ << " ) be backwards compatible with the op compliance "
451
+ " specification version ("
452
+ << stringifyVersion (complianceVersion) << " )\n " ;
453
+ return failure ();
454
+ }
455
+
440
456
return success ();
441
457
}
442
458
@@ -461,14 +477,14 @@ TosaProfileCompliance::checkExtension(Operation *op,
461
477
}
462
478
463
479
LogicalResult TosaProfileCompliance::checkInvalid (Operation *op) {
464
- CheckCondition condition = CheckCondition::invalid;
465
- const auto maybeProfDef = getOperatorDefinition<Profile>(op, condition);
466
- const auto maybeExtDef = getOperatorDefinition<Extension>(op, condition);
480
+ const auto maybeProfDef = getOperatorDefinition<Profile>(op);
481
+ const auto maybeExtDef = getOperatorDefinition<Extension>(op);
467
482
if (failed (maybeProfDef) && failed (maybeExtDef))
468
483
return success ();
469
484
470
- const bool hasEntry = (succeeded (maybeProfDef) && !maybeProfDef->empty ()) ||
471
- (succeeded (maybeExtDef) && !maybeExtDef->empty ());
485
+ const bool hasEntry =
486
+ (succeeded (maybeProfDef) && !maybeProfDef->mode .empty ()) ||
487
+ (succeeded (maybeExtDef) && !maybeExtDef->mode .empty ());
472
488
if (!hasEntry) {
473
489
std::string message;
474
490
llvm::raw_string_ostream os (message);
@@ -488,7 +504,9 @@ LogicalResult TosaProfileCompliance::checkInvalid(Operation *op) {
488
504
SmallVector<TypeInfo> bestTypeInfo;
489
505
const auto searchBestMatch = [&](auto map) {
490
506
for (const auto &complianceInfos : map[opName]) {
491
- for (const auto &typeInfos : complianceInfos.operandTypeInfoSet ) {
507
+ for (const auto &versionedTypeInfos :
508
+ complianceInfos.operandTypeInfoSet ) {
509
+ const SmallVector<TypeInfo> typeInfos = versionedTypeInfos.first ;
492
510
const int matches = llvm::count_if (
493
511
llvm::zip_equal (current, typeInfos), [&](const auto zipType) {
494
512
return isSameTypeInfo (std::get<0 >(zipType),
@@ -520,9 +538,8 @@ LogicalResult TosaProfileCompliance::checkInvalid(Operation *op) {
520
538
// Find the profiles or extensions requirement according to the signature of
521
539
// type of the operand list.
522
540
template <typename T>
523
- SmallVector<T> TosaProfileCompliance::findMatchedProfile (
524
- Operation *op, SmallVector<OpComplianceInfo<T>> compInfo,
525
- CheckCondition &condition) {
541
+ OpComplianceInfo<T> TosaProfileCompliance::findMatchedEntry (
542
+ Operation *op, SmallVector<OpComplianceInfo<T>> compInfo) {
526
543
assert (compInfo.size () != 0 &&
527
544
" profile-based compliance information is empty" );
528
545
@@ -533,27 +550,30 @@ SmallVector<T> TosaProfileCompliance::findMatchedProfile(
533
550
return {};
534
551
535
552
for (size_t i = 0 ; i < compInfo.size (); i++) {
536
- SmallVector<SmallVector<TypeInfo>> sets = compInfo[i].operandTypeInfoSet ;
537
- for (SmallVector<TypeInfo> expected : sets) {
553
+ SmallVector<VersionedTypeInfo> sets = compInfo[i].operandTypeInfoSet ;
554
+ for (const auto &set : sets) {
555
+ SmallVector<TypeInfo> expected = set.first ;
538
556
assert (present.size () == expected.size () &&
539
557
" the entries for profile-based compliance do not match between "
540
558
" the generated metadata and the type definition retrieved from "
541
559
" the operation" );
542
560
543
- bool is_found = true ;
561
+ bool isFound = true ;
544
562
// Compare the type signature between the given operation and the
545
563
// compliance metadata.
546
564
for (size_t j = 0 ; j < expected.size (); j++) {
547
565
if (!isSameTypeInfo (present[j], expected[j])) {
548
566
// Verify the next mode set from the list.
549
- is_found = false ;
567
+ isFound = false ;
550
568
break ;
551
569
}
552
570
}
553
571
554
- if (is_found == true ) {
555
- condition = compInfo[i].condition ;
556
- return compInfo[i].mode ;
572
+ if (isFound == true ) {
573
+ SmallVector<VersionedTypeInfo> typeInfoSet{set};
574
+ OpComplianceInfo<T> info{compInfo[i].mode , typeInfoSet,
575
+ compInfo[i].condition };
576
+ return info;
557
577
}
558
578
}
559
579
}
0 commit comments