@@ -901,7 +901,10 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
901
901
902
902
transFPGAFunctionMetadata (BF, F);
903
903
904
- transFunctionMetadataAsUserSemanticDecoration (BF, F);
904
+ if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_maximum_registers))
905
+ transFunctionMetadataAsExecutionMode (BF, F);
906
+ else
907
+ transFunctionMetadataAsUserSemanticDecoration (BF, F);
905
908
906
909
transAuxDataInst (BF, F);
907
910
@@ -1035,6 +1038,38 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
1035
1038
transMetadataDecorations (FDecoMD, BF);
1036
1039
}
1037
1040
1041
+ void LLVMToSPIRVBase::transFunctionMetadataAsExecutionMode (SPIRVFunction *BF,
1042
+ Function *F) {
1043
+ SmallVector<MDNode *, 1 > RegisterAllocModeMDs;
1044
+ F->getMetadata (" RegisterAllocMode" , RegisterAllocModeMDs);
1045
+
1046
+ for (unsigned I = 0 ; I < RegisterAllocModeMDs.size (); I++) {
1047
+ auto *RegisterAllocMode = RegisterAllocModeMDs[I]->getOperand (0 ).get ();
1048
+ if (isa<MDString>(RegisterAllocMode)) {
1049
+ StringRef Str = getMDOperandAsString (RegisterAllocModeMDs[I], 0 );
1050
+ NamedMaximumNumberOfRegisters NamedValue =
1051
+ SPIRVNamedMaximumNumberOfRegistersNameMap::rmap (Str.str ());
1052
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
1053
+ OpExecutionMode, BF, ExecutionModeNamedMaximumRegistersINTEL,
1054
+ NamedValue)));
1055
+ } else if (isa<MDNode>(RegisterAllocMode)) {
1056
+ auto *RegisterAllocNodeMDOp =
1057
+ getMDOperandAsMDNode (RegisterAllocModeMDs[I], 0 );
1058
+ int Num = getMDOperandAsInt (RegisterAllocNodeMDOp, 0 );
1059
+ auto *Const =
1060
+ BM->addConstant (transType (Type::getInt32Ty (F->getContext ())), Num);
1061
+ BF->addExecutionMode (BM->add (new SPIRVExecutionModeId (
1062
+ BF, ExecutionModeMaximumRegistersIdINTEL, Const->getId ())));
1063
+ } else {
1064
+ int64_t RegisterAllocVal =
1065
+ mdconst::dyn_extract<ConstantInt>(RegisterAllocMode)->getZExtValue ();
1066
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
1067
+ OpExecutionMode, BF, ExecutionModeMaximumRegistersINTEL,
1068
+ RegisterAllocVal)));
1069
+ }
1070
+ }
1071
+ }
1072
+
1038
1073
void LLVMToSPIRVBase::transFunctionMetadataAsUserSemanticDecoration (
1039
1074
SPIRVFunction *BF, Function *F) {
1040
1075
if (auto *RegisterAllocModeMD = F->getMetadata (" RegisterAllocMode" )) {
@@ -4996,19 +5031,20 @@ bool LLVMToSPIRVBase::transExecutionMode() {
4996
5031
auto AddSingleArgExecutionMode = [&](ExecutionMode EMode) {
4997
5032
uint32_t Arg = ~0u ;
4998
5033
N.get (Arg);
4999
- BF->addExecutionMode (BM->add (new SPIRVExecutionMode (BF, EMode, Arg)));
5034
+ BF->addExecutionMode (
5035
+ BM->add (new SPIRVExecutionMode (OpExecutionMode, BF, EMode, Arg)));
5000
5036
};
5001
5037
5002
5038
switch (EMode) {
5003
5039
case spv::ExecutionModeContractionOff:
5004
- BF->addExecutionMode (BM->add (
5005
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
5040
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5041
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
5006
5042
break ;
5007
5043
case spv::ExecutionModeInitializer:
5008
5044
case spv::ExecutionModeFinalizer:
5009
5045
if (BM->isAllowedToUseVersion (VersionNumber::SPIRV_1_1)) {
5010
- BF->addExecutionMode (BM->add (
5011
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
5046
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5047
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
5012
5048
} else {
5013
5049
getErrorLog ().checkError (false , SPIRVEC_Requires1_1,
5014
5050
" Initializer/Finalizer Execution Mode" );
@@ -5020,15 +5056,16 @@ bool LLVMToSPIRVBase::transExecutionMode() {
5020
5056
unsigned X = 0 , Y = 0 , Z = 0 ;
5021
5057
N.get (X).get (Y).get (Z);
5022
5058
BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5023
- BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
5059
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
5024
5060
} break ;
5025
5061
case spv::ExecutionModeMaxWorkgroupSizeINTEL: {
5026
5062
if (BM->isAllowedToUseExtension (
5027
5063
ExtensionID::SPV_INTEL_kernel_attributes)) {
5028
5064
unsigned X = 0 , Y = 0 , Z = 0 ;
5029
5065
N.get (X).get (Y).get (Z);
5030
5066
BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5031
- BF, static_cast <ExecutionMode>(EMode), X, Y, Z)));
5067
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode), X, Y,
5068
+ Z)));
5032
5069
BM->addExtension (ExtensionID::SPV_INTEL_kernel_attributes);
5033
5070
BM->addCapability (CapabilityKernelAttributesINTEL);
5034
5071
}
@@ -5037,8 +5074,8 @@ bool LLVMToSPIRVBase::transExecutionMode() {
5037
5074
if (!BM->isAllowedToUseExtension (
5038
5075
ExtensionID::SPV_INTEL_kernel_attributes))
5039
5076
break ;
5040
- BF->addExecutionMode (BM->add (
5041
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
5077
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5078
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
5042
5079
BM->addExtension (ExtensionID::SPV_INTEL_kernel_attributes);
5043
5080
BM->addCapability (CapabilityKernelAttributesINTEL);
5044
5081
} break ;
@@ -5068,8 +5105,9 @@ bool LLVMToSPIRVBase::transExecutionMode() {
5068
5105
break ;
5069
5106
unsigned NBarrierCnt = 0 ;
5070
5107
N.get (NBarrierCnt);
5071
- BF->addExecutionMode (new SPIRVExecutionMode (
5072
- BF, static_cast <ExecutionMode>(EMode), NBarrierCnt));
5108
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5109
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode),
5110
+ NBarrierCnt)));
5073
5111
BM->addExtension (ExtensionID::SPV_INTEL_vector_compute);
5074
5112
BM->addCapability (CapabilityVectorComputeINTEL);
5075
5113
} break ;
@@ -5099,8 +5137,8 @@ bool LLVMToSPIRVBase::transExecutionMode() {
5099
5137
} break ;
5100
5138
case spv::internal::ExecutionModeFastCompositeKernelINTEL: {
5101
5139
if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_fast_composite))
5102
- BF->addExecutionMode (BM->add (
5103
- new SPIRVExecutionMode ( BF, static_cast <ExecutionMode>(EMode))));
5140
+ BF->addExecutionMode (BM->add (new SPIRVExecutionMode (
5141
+ OpExecutionMode, BF, static_cast <ExecutionMode>(EMode))));
5104
5142
} break ;
5105
5143
default :
5106
5144
llvm_unreachable (" invalid execution mode" );
@@ -5145,8 +5183,8 @@ void LLVMToSPIRVBase::transFPContract() {
5145
5183
}
5146
5184
5147
5185
if (DisableContraction) {
5148
- BF->addExecutionMode (BF->getModule ()->add (
5149
- new SPIRVExecutionMode ( BF, spv::ExecutionModeContractionOff)));
5186
+ BF->addExecutionMode (BF->getModule ()->add (new SPIRVExecutionMode (
5187
+ OpExecutionMode, BF, spv::ExecutionModeContractionOff)));
5150
5188
}
5151
5189
}
5152
5190
}
0 commit comments