@@ -76,18 +76,20 @@ getSymbolicOperandRequirements(SPIRV::OperandCategory::OperandCategory Category,
7676 SPIRV::RequirementHandler &Reqs) {
7777 static AvoidCapabilitiesSet
7878 AvoidCaps; // contains capabilities to avoid if there is another option
79- unsigned ReqMinVer = getSymbolicOperandMinVersion (Category, i);
80- unsigned ReqMaxVer = getSymbolicOperandMaxVersion (Category, i);
81- unsigned TargetVer = ST.getSPIRVVersion ();
82- bool MinVerOK = !ReqMinVer || !TargetVer || TargetVer >= ReqMinVer;
83- bool MaxVerOK = !ReqMaxVer || !TargetVer || TargetVer <= ReqMaxVer;
79+
80+ VersionTuple ReqMinVer = getSymbolicOperandMinVersion (Category, i);
81+ VersionTuple ReqMaxVer = getSymbolicOperandMaxVersion (Category, i);
82+ VersionTuple SPIRVVersion = ST.getSPIRVVersion ();
83+ bool MinVerOK = SPIRVVersion.empty () || SPIRVVersion >= ReqMinVer;
84+ bool MaxVerOK =
85+ ReqMaxVer.empty () || SPIRVVersion.empty () || SPIRVVersion <= ReqMaxVer;
8486 CapabilityList ReqCaps = getSymbolicOperandCapabilities (Category, i);
8587 ExtensionList ReqExts = getSymbolicOperandExtensions (Category, i);
8688 if (ReqCaps.empty ()) {
8789 if (ReqExts.empty ()) {
8890 if (MinVerOK && MaxVerOK)
8991 return {true , {}, {}, ReqMinVer, ReqMaxVer};
90- return {false , {}, {}, 0 , 0 };
92+ return {false , {}, {}, VersionTuple (), VersionTuple () };
9193 }
9294 } else if (MinVerOK && MaxVerOK) {
9395 if (ReqCaps.size () == 1 ) {
@@ -118,9 +120,13 @@ getSymbolicOperandRequirements(SPIRV::OperandCategory::OperandCategory Category,
118120 if (llvm::all_of (ReqExts, [&ST](const SPIRV::Extension::Extension &Ext) {
119121 return ST.canUseExtension (Ext);
120122 })) {
121- return {true , {}, ReqExts, 0 , 0 }; // TODO: add versions to extensions.
123+ return {true ,
124+ {},
125+ ReqExts,
126+ VersionTuple (),
127+ VersionTuple ()}; // TODO: add versions to extensions.
122128 }
123- return {false , {}, {}, 0 , 0 };
129+ return {false , {}, {}, VersionTuple (), VersionTuple () };
124130}
125131
126132void SPIRVModuleAnalysis::setBaseInfo (const Module &M) {
@@ -510,25 +516,25 @@ void SPIRV::RequirementHandler::addRequirements(
510516
511517 addExtensions (Req.Exts );
512518
513- if (Req.MinVer ) {
514- if (MaxVersion && Req.MinVer > MaxVersion) {
519+ if (! Req.MinVer . empty () ) {
520+ if (! MaxVersion. empty () && Req.MinVer > MaxVersion) {
515521 LLVM_DEBUG (dbgs () << " Conflicting version requirements: >= " << Req.MinVer
516522 << " and <= " << MaxVersion << " \n " );
517523 report_fatal_error (" Adding SPIR-V requirements that can't be satisfied." );
518524 }
519525
520- if (MinVersion == 0 || Req.MinVer > MinVersion)
526+ if (MinVersion. empty () || Req.MinVer > MinVersion)
521527 MinVersion = Req.MinVer ;
522528 }
523529
524- if (Req.MaxVer ) {
525- if (MinVersion && Req.MaxVer < MinVersion) {
530+ if (! Req.MaxVer . empty () ) {
531+ if (! MinVersion. empty () && Req.MaxVer < MinVersion) {
526532 LLVM_DEBUG (dbgs () << " Conflicting version requirements: <= " << Req.MaxVer
527533 << " and >= " << MinVersion << " \n " );
528534 report_fatal_error (" Adding SPIR-V requirements that can't be satisfied." );
529535 }
530536
531- if (MaxVersion == 0 || Req.MaxVer < MaxVersion)
537+ if (MaxVersion. empty () || Req.MaxVer < MaxVersion)
532538 MaxVersion = Req.MaxVer ;
533539 }
534540}
@@ -539,22 +545,22 @@ void SPIRV::RequirementHandler::checkSatisfiable(
539545 bool IsSatisfiable = true ;
540546 auto TargetVer = ST.getSPIRVVersion ();
541547
542- if (MaxVersion && TargetVer && MaxVersion < TargetVer) {
548+ if (! MaxVersion. empty () && ! TargetVer. empty () && MaxVersion < TargetVer) {
543549 LLVM_DEBUG (
544550 dbgs () << " Target SPIR-V version too high for required features\n "
545551 << " Required max version: " << MaxVersion << " target version "
546552 << TargetVer << " \n " );
547553 IsSatisfiable = false ;
548554 }
549555
550- if (MinVersion && TargetVer && MinVersion > TargetVer) {
556+ if (! MinVersion. empty () && ! TargetVer. empty () && MinVersion > TargetVer) {
551557 LLVM_DEBUG (dbgs () << " Target SPIR-V version too low for required features\n "
552558 << " Required min version: " << MinVersion
553559 << " target version " << TargetVer << " \n " );
554560 IsSatisfiable = false ;
555561 }
556562
557- if (MinVersion && MaxVersion && MinVersion > MaxVersion) {
563+ if (! MinVersion. empty () && ! MaxVersion. empty () && MinVersion > MaxVersion) {
558564 LLVM_DEBUG (
559565 dbgs ()
560566 << " Version is too low for some features and too high for others.\n "
@@ -632,20 +638,21 @@ void RequirementHandler::initAvailableCapabilitiesForOpenCL(
632638 addAvailableCaps ({Capability::ImageBasic, Capability::LiteralSampler,
633639 Capability::Image1D, Capability::SampledBuffer,
634640 Capability::ImageBuffer});
635- if (ST.isAtLeastOpenCLVer (20 ))
641+ if (ST.isAtLeastOpenCLVer (VersionTuple ( 2 , 0 ) ))
636642 addAvailableCaps ({Capability::ImageReadWrite});
637643 }
638- if (ST.isAtLeastSPIRVVer (11 ) && ST.isAtLeastOpenCLVer (22 ))
644+ if (ST.isAtLeastSPIRVVer (VersionTuple (1 , 1 )) &&
645+ ST.isAtLeastOpenCLVer (VersionTuple (2 , 2 )))
639646 addAvailableCaps ({Capability::SubgroupDispatch, Capability::PipeStorage});
640- if (ST.isAtLeastSPIRVVer (13 ))
647+ if (ST.isAtLeastSPIRVVer (VersionTuple ( 1 , 3 ) ))
641648 addAvailableCaps ({Capability::GroupNonUniform,
642649 Capability::GroupNonUniformVote,
643650 Capability::GroupNonUniformArithmetic,
644651 Capability::GroupNonUniformBallot,
645652 Capability::GroupNonUniformClustered,
646653 Capability::GroupNonUniformShuffle,
647654 Capability::GroupNonUniformShuffleRelative});
648- if (ST.isAtLeastSPIRVVer (14 ))
655+ if (ST.isAtLeastSPIRVVer (VersionTuple ( 1 , 4 ) ))
649656 addAvailableCaps ({Capability::DenormPreserve, Capability::DenormFlushToZero,
650657 Capability::SignedZeroInfNanPreserve,
651658 Capability::RoundingModeRTE,
@@ -1162,7 +1169,8 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
11621169 auto Node = M.getNamedMetadata (" spirv.ExecutionMode" );
11631170 if (Node) {
11641171 // SPV_KHR_float_controls is not available until v1.4
1165- bool RequireFloatControls = false , VerLower14 = !ST.isAtLeastSPIRVVer (14 );
1172+ bool RequireFloatControls = false ,
1173+ VerLower14 = !ST.isAtLeastSPIRVVer (VersionTuple (1 , 4 ));
11661174 for (unsigned i = 0 ; i < Node->getNumOperands (); i++) {
11671175 MDNode *MDN = cast<MDNode>(Node->getOperand (i));
11681176 const MDOperand &MDOp = MDN->getOperand (1 );
0 commit comments