@@ -897,6 +897,9 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
897
897
898
898
transFPGAFunctionMetadata (BF, F);
899
899
900
+ if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_maximum_registers))
901
+ transFunctionMetadataAsExecutionMode (BF, F);
902
+
900
903
transAuxDataInst (BF, F);
901
904
902
905
SPIRVDBG (dbgs () << " [transFunction] " << *F << " => " ;
@@ -1029,6 +1032,38 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
1029
1032
transMetadataDecorations (FDecoMD, BF);
1030
1033
}
1031
1034
1035
+ void LLVMToSPIRVBase::transFunctionMetadataAsExecutionMode (SPIRVFunction *BF,
1036
+ Function *F) {
1037
+ SmallVector<MDNode *, 1 > RegisterAllocModeMDs;
1038
+ F->getMetadata (" RegisterAllocMode" , RegisterAllocModeMDs);
1039
+
1040
+ for (unsigned I = 0 ; I < RegisterAllocModeMDs.size (); I++) {
1041
+ auto *RegisterAllocMode = RegisterAllocModeMDs[I]->getOperand (0 ).get ();
1042
+ if (isa<MDString>(RegisterAllocMode)) {
1043
+ const StringRef Str = getMDOperandAsString (RegisterAllocModeMDs[I], 0 );
1044
+ const internal::InternalNamedMaximumNumberOfRegisters NamedValue =
1045
+ SPIRVNamedMaximumNumberOfRegistersNameMap::rmap (Str.str ());
1046
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
1047
+ OpExecutionMode, BF,
1048
+ internal::ExecutionModeNamedMaximumRegistersINTEL, NamedValue)));
1049
+ } else if (isa<MDNode>(RegisterAllocMode)) {
1050
+ auto *RegisterAllocNodeMDOp =
1051
+ getMDOperandAsMDNode (RegisterAllocModeMDs[I], 0 );
1052
+ const int Num = getMDOperandAsInt (RegisterAllocNodeMDOp, 0 );
1053
+ auto *Const =
1054
+ BM->addConstant (transType (Type::getInt32Ty (F->getContext ())), Num);
1055
+ BF->addExecutionMode (BM->add (new SPIRVExecutionModeId (
1056
+ BF, internal::ExecutionModeMaximumRegistersIdINTEL, Const->getId ())));
1057
+ } else {
1058
+ const int64_t RegisterAllocVal =
1059
+ mdconst::dyn_extract<ConstantInt>(RegisterAllocMode)->getZExtValue ();
1060
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
1061
+ OpExecutionMode, BF, internal::ExecutionModeMaximumRegistersINTEL,
1062
+ RegisterAllocVal)));
1063
+ }
1064
+ }
1065
+ }
1066
+
1032
1067
void LLVMToSPIRVBase::transAuxDataInst (SPIRVFunction *BF, Function *F) {
1033
1068
auto *BM = BF->getModule ();
1034
1069
if (!BM->preserveAuxData ())
@@ -4766,19 +4801,20 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4766
4801
auto AddSingleArgExecutionMode = [&](ExecutionMode EMode) {
4767
4802
uint32_t Arg = 0 ;
4768
4803
N.get (Arg);
4769
- BF->addExecutionMode (BM->add (new SPIRVExecutionMode (BF, EMode, Arg)));
4804
+ BF->addExecutionMode (
4805
+ BM->add (new SPIRVExecutionMode (OpExecutionMode, BF, EMode, Arg)));
4770
4806
};
4771
4807
4772
4808
switch (EMode) {
4773
4809
case spv::ExecutionModeContractionOff:
4774
- BF->addExecutionMode (BM->add (
4775
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
4810
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4811
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
4776
4812
break ;
4777
4813
case spv::ExecutionModeInitializer:
4778
4814
case spv::ExecutionModeFinalizer:
4779
4815
if (BM->isAllowedToUseVersion (VersionNumber::SPIRV_1_1)) {
4780
- BF->addExecutionMode (BM->add (
4781
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
4816
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4817
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
4782
4818
} else {
4783
4819
getErrorLog ().checkError (false , SPIRVEC_Requires1_1,
4784
4820
" Initializer/Finalizer Execution Mode" );
@@ -4790,15 +4826,16 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4790
4826
unsigned X, Y, Z;
4791
4827
N.get (X).get (Y).get (Z);
4792
4828
BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4793
- BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
4829
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
4794
4830
} break ;
4795
4831
case spv::ExecutionModeMaxWorkgroupSizeINTEL: {
4796
4832
if (BM->isAllowedToUseExtension (
4797
4833
ExtensionID::SPV_INTEL_kernel_attributes)) {
4798
4834
unsigned X, Y, Z;
4799
4835
N.get (X).get (Y).get (Z);
4800
4836
BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4801
- BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
4837
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode), X, Y,
4838
+ Z)));
4802
4839
BM->addExtension (ExtensionID::SPV_INTEL_kernel_attributes);
4803
4840
BM->addCapability (CapabilityKernelAttributesINTEL);
4804
4841
}
@@ -4807,8 +4844,8 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4807
4844
if (!BM->isAllowedToUseExtension (
4808
4845
ExtensionID::SPV_INTEL_kernel_attributes))
4809
4846
break ;
4810
- BF->addExecutionMode (BM->add (
4811
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
4847
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4848
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
4812
4849
BM->addExtension (ExtensionID::SPV_INTEL_kernel_attributes);
4813
4850
BM->addCapability (CapabilityKernelAttributesINTEL);
4814
4851
} break ;
@@ -4851,8 +4888,9 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4851
4888
break ;
4852
4889
unsigned NBarrierCnt = 0 ;
4853
4890
N.get (NBarrierCnt);
4854
- BF->addExecutionMode (new SPIRVExecutionMode (
4855
- BF, static_cast <ExecutionMode>(EMode), NBarrierCnt));
4891
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4892
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode),
4893
+ NBarrierCnt)));
4856
4894
BM->addExtension (ExtensionID::SPV_INTEL_vector_compute);
4857
4895
BM->addCapability (CapabilityVectorComputeINTEL);
4858
4896
} break ;
@@ -4883,8 +4921,8 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4883
4921
} break ;
4884
4922
case spv::internal::ExecutionModeFastCompositeKernelINTEL: {
4885
4923
if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_fast_composite))
4886
- BF->addExecutionMode (BM->add (
4887
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
4924
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
4925
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
4888
4926
} break ;
4889
4927
default :
4890
4928
llvm_unreachable (" invalid execution mode" );
@@ -4929,8 +4967,8 @@ void LLVMToSPIRVBase::transFPContract() {
4929
4967
}
4930
4968
4931
4969
if (DisableContraction) {
4932
- BF->addExecutionMode (BF->getModule ()->add (
4933
- new SPIRVExecutionMode ( BF, spv::ExecutionModeContractionOff)));
4970
+ BF->addExecutionMode (BF->getModule ()->add (new SPIRVExecutionMode (
4971
+ OpExecutionMode, BF, spv::ExecutionModeContractionOff)));
4934
4972
}
4935
4973
}
4936
4974
}
0 commit comments