@@ -4953,16 +4953,14 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
4953
4953
auto Iter = stackFuncMap.find (VFDef);
4954
4954
IGC_ASSERT_MESSAGE (Iter != stackFuncMap.end (), " vISA function not found" );
4955
4955
4956
- vISA::GenSymEntry fEntry ;
4957
- IGC_ASSERT (F.getName ().size () <= vISA::MAX_SYMBOL_NAME_LENGTH);
4958
- strcpy_s (fEntry .s_name , vISA::MAX_SYMBOL_NAME_LENGTH, F.getName ().str ().c_str ());
4959
- fEntry .s_name [vISA::MAX_SYMBOL_NAME_LENGTH - 1 ] = 0 ; // ensure null termination when buffer is too small
4956
+ vISA::ZESymEntry fEntry ;
4957
+ fEntry .s_name = F.getName ().str ();
4960
4958
4961
4959
// Query vISA for the function's byte offset within the compiled module
4962
4960
// The actual binary offset data should point to the function definition
4963
4961
VISAFunction *visaFunc = Iter->second ;
4964
4962
fEntry .s_type = vISA::GenSymType::S_FUNC;
4965
- fEntry .s_offset = (uint32_t )visaFunc->getGenOffset ();
4963
+ fEntry .s_offset = (size_t )visaFunc->getGenOffset ();
4966
4964
fEntry .s_size = (uint32_t )visaFunc->getGenSize ();
4967
4965
4968
4966
symbolTableList.push_back (std::make_pair (&F, fEntry ));
@@ -4980,10 +4978,8 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
4980
4978
}
4981
4979
}
4982
4980
4983
- vISA::GenSymEntry fEntry ;
4984
- IGC_ASSERT (F.getName ().size () <= vISA::MAX_SYMBOL_NAME_LENGTH);
4985
- strcpy_s (fEntry .s_name , vISA::MAX_SYMBOL_NAME_LENGTH, F.getName ().str ().c_str ());
4986
- fEntry .s_name [vISA::MAX_SYMBOL_NAME_LENGTH - 1 ] = 0 ; // ensure null termination when buffer is too small
4981
+ vISA::ZESymEntry fEntry ;
4982
+ fEntry .s_name = F.getName ().str ();
4987
4983
4988
4984
if (F.isDeclaration ()) {
4989
4985
// If the function is only declared, set as undefined type
@@ -4997,7 +4993,7 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
4997
4993
// Query vISA for the function's byte offset within the compiled module
4998
4994
VISAFunction *visaFunc = Iter->second ;
4999
4995
fEntry .s_type = vISA::GenSymType::S_FUNC;
5000
- fEntry .s_offset = (uint32_t )visaFunc->getGenOffset ();
4996
+ fEntry .s_offset = (size_t )visaFunc->getGenOffset ();
5001
4997
fEntry .s_size = (uint32_t )visaFunc->getGenSize ();
5002
4998
}
5003
4999
symbolTableList.push_back (std::make_pair (&F, fEntry ));
@@ -5026,20 +5022,20 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
5026
5022
unsigned addrSpace = pGlobal->getType ()->getAddressSpace ();
5027
5023
IGC_ASSERT (name.size () <= vISA::MAX_SYMBOL_NAME_LENGTH);
5028
5024
5029
- vISA::GenSymEntry sEntry ;
5030
- strcpy_s (sEntry .s_name , vISA::MAX_SYMBOL_NAME_LENGTH, name.str ().c_str ());
5025
+ vISA::ZESymEntry sEntry ;
5026
+ sEntry .s_name = name.str ();
5027
+
5031
5028
MDNode *md = pGlobal->getMetadata (" ConstSampler" );
5032
5029
if (md) {
5033
5030
// Constant Sampler: s_offset contains the sampler ID
5034
5031
sEntry .s_type = vISA::GenSymType::S_CONST_SAMPLER;
5035
5032
sEntry .s_size = 0 ;
5036
5033
sEntry .s_offset = static_cast <size_t >(global.second );
5037
5034
} else {
5038
- uint32_t type = vISA::GenSymType::S_GLOBAL_VAR_CONST;
5035
+ vISA::GenSymType type = vISA::GenSymType::S_GLOBAL_VAR_CONST;
5039
5036
// For Zebin always use constant type for string constants
5040
5037
// because of the relaxed address space requirement of
5041
5038
// printf strings.
5042
- IGC_ASSERT (modMD->stringConstants .empty () || m_program->GetContext ()->enableZEBinary ());
5043
5039
if (addrSpace == ADDRESS_SPACE_GLOBAL && !modMD->stringConstants .count (pGlobal))
5044
5040
type = vISA::GenSymType::S_GLOBAL_VAR;
5045
5041
if (!pGlobal->hasInitializer ())
@@ -5054,68 +5050,48 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
5054
5050
}
5055
5051
}
5056
5052
5057
- void CEncoder::CreateSymbolTable (void *&buffer, unsigned &bufferSize, unsigned &tableEntries) {
5058
- buffer = nullptr ;
5059
- bufferSize = 0 ;
5060
- tableEntries = 0 ;
5061
-
5062
- ValueToSymbolList symbolTableList;
5063
- CreateSymbolTable (symbolTableList);
5064
-
5065
- // Get the data for patch token
5066
- if (!symbolTableList.empty ()) {
5067
- std::vector<vISA::GenSymEntry> tempBufferData;
5068
- // Collect the data just for the symbol table entries
5069
- for (const auto &I : symbolTableList) {
5070
- auto symbolEntry = I.second ;
5071
- tempBufferData.push_back (symbolEntry);
5072
- }
5073
-
5074
- tableEntries = tempBufferData.size ();
5075
- bufferSize = tableEntries * sizeof (vISA::GenSymEntry);
5076
- buffer = malloc (bufferSize);
5077
- IGC_ASSERT_MESSAGE (nullptr != buffer, " Symbol table cannot be allocated" );
5078
- memcpy_s (buffer, bufferSize, tempBufferData.data (), bufferSize);
5079
- }
5080
- }
5081
-
5082
- void CEncoder::CreateSymbolTable (SProgramOutput::ZEBinFuncSymbolTable &funcSyms,
5083
- SOpenCLProgramInfo::ZEBinProgramSymbolTable &programSyms) {
5084
- ValueToSymbolList symbolTableList;
5085
- CreateSymbolTable (symbolTableList);
5086
- ModuleMetaData *modMD = m_program->GetContext ()->getModuleMetaData ();
5087
-
5088
- // Get the data for zebin
5053
+ void CEncoder::CreateFunctionSymbolTable (ValueToSymbolList &symbolTableList,
5054
+ SProgramOutput::ZEBinFuncSymbolTable &funcSyms) {
5089
5055
for (const auto &I : symbolTableList) {
5090
5056
Value *symbolValue = I.first ;
5091
5057
auto symbolEntry = I.second ;
5092
5058
5093
5059
if (Function *F = dyn_cast<Function>(symbolValue)) {
5094
5060
funcSyms.function .emplace_back ((vISA::GenSymType)symbolEntry.s_type , symbolEntry.s_offset , symbolEntry.s_size ,
5095
- F->getName ().str ());
5061
+ F->getName ().str ());
5096
5062
} else if (GlobalVariable *G = dyn_cast<GlobalVariable>(symbolValue)) {
5097
- // const sampler
5063
+ // Const sampler
5098
5064
if (symbolEntry.s_type == vISA::GenSymType::S_CONST_SAMPLER) {
5099
5065
funcSyms.sampler .emplace_back ((vISA::GenSymType)symbolEntry.s_type , symbolEntry.s_offset , symbolEntry.s_size ,
5100
5066
G->getName ().str ());
5101
5067
}
5102
- // global variables, including external variables (S_UNDEF)
5103
- else if (symbolEntry.s_type == vISA::GenSymType::S_GLOBAL_VAR ||
5104
- symbolEntry.s_type == vISA::GenSymType::S_UNDEF) {
5068
+ }
5069
+ }
5070
+ }
5071
+
5072
+ void CEncoder::CreateProgramSymbolTable (ValueToSymbolList &symbolTableList,
5073
+ SOpenCLProgramInfo::ZEBinProgramSymbolTable &programSyms) {
5074
+ ModuleMetaData *modMD = m_program->GetContext ()->getModuleMetaData ();
5075
+
5076
+ for (const auto &I : symbolTableList) {
5077
+ Value *symbolValue = I.first ;
5078
+ auto symbolEntry = I.second ;
5079
+
5080
+ if (GlobalVariable* G = dyn_cast<GlobalVariable>(symbolValue)) {
5081
+ // Global variables, including external variables (S_UNDEF)
5082
+ if (symbolEntry.s_type == vISA::GenSymType::S_GLOBAL_VAR || symbolEntry.s_type == vISA::GenSymType::S_UNDEF) {
5105
5083
programSyms.global .emplace_back ((vISA::GenSymType)symbolEntry.s_type , symbolEntry.s_offset , symbolEntry.s_size ,
5106
- G->getName ().str ());
5084
+ G->getName ().str ());
5107
5085
}
5108
- // global constants and string literals
5086
+ // Global constants and string literals
5109
5087
else {
5110
5088
if (modMD->stringConstants .count (G)) {
5111
5089
programSyms.globalStringConst .emplace_back ((vISA::GenSymType)symbolEntry.s_type , symbolEntry.s_offset ,
5112
- symbolEntry.s_size , G->getName ().str ());
5090
+ symbolEntry.s_size , G->getName ().str ());
5113
5091
} else
5114
5092
programSyms.globalConst .emplace_back ((vISA::GenSymType)symbolEntry.s_type , symbolEntry.s_offset ,
5115
- symbolEntry.s_size , G->getName ().str ());
5093
+ symbolEntry.s_size , G->getName ().str ());
5116
5094
}
5117
- } else {
5118
- IGC_ASSERT (0 );
5119
5095
}
5120
5096
}
5121
5097
}
@@ -5168,23 +5144,6 @@ void CEncoder::CreateFuncAttributeTable(VISAKernel *pMainKernel, GenXFunctionGro
5168
5144
}
5169
5145
}
5170
5146
5171
- void CEncoder::CreateGlobalHostAccessTable (void *&buffer, unsigned &bufferSize, unsigned &tableEntries) {
5172
- buffer = nullptr ;
5173
- bufferSize = 0 ;
5174
- tableEntries = 0 ;
5175
-
5176
- HostAccessList hostAccessList;
5177
- CreateGlobalHostAccessTable (hostAccessList);
5178
-
5179
- if (!hostAccessList.empty ()) {
5180
- tableEntries = hostAccessList.size ();
5181
- bufferSize = tableEntries * sizeof (vISA::HostAccessEntry);
5182
- buffer = malloc (bufferSize);
5183
- IGC_ASSERT_MESSAGE (nullptr != buffer, " Host access table cannot be allocated" );
5184
- memcpy_s (buffer, bufferSize, hostAccessList.data (), bufferSize);
5185
- }
5186
- }
5187
-
5188
5147
void CEncoder::CreateGlobalHostAccessTable (HostAccessList &hostAccessList) {
5189
5148
ModuleMetaData *modMD = m_program->GetContext ()->getModuleMetaData ();
5190
5149
@@ -5787,68 +5746,67 @@ void CEncoder::createSymbolAndGlobalHostAccessTables(bool hasSymbolTable, VISAKe
5787
5746
unsigned int scratchOffset) {
5788
5747
CodeGenContext *context = m_program->GetContext ();
5789
5748
SProgramOutput *pOutput = m_program->ProgramOutput ();
5790
- bool ZEBinEnabled = context->enableZEBinary ();
5791
5749
vISA::FINALIZER_INFO *jitInfo = nullptr ;
5792
5750
pMainKernel.GetJitInfo (jitInfo);
5793
5751
if (hasSymbolTable) {
5794
- if (ZEBinEnabled) {
5795
- // we can only support zebin symbols for OPENCL_SHADER for now
5796
- IGC_ASSERT (context->type == ShaderType::OPENCL_SHADER);
5797
- auto cl_context = static_cast <OpenCLProgramContext *>(context);
5798
- CreateSymbolTable (pOutput->m_symbols , cl_context->m_programInfo .m_zebinSymbolTable );
5799
- // Set up per-function GTPIN information for indirect functions.
5800
- for (auto &sym : pOutput->m_symbols .function ) {
5801
- void *buffer = nullptr ;
5802
- unsigned size = 0 ;
5803
- if (sym.s_type != vISA::GenSymType::S_UNDEF) {
5804
- IGC_ASSERT (vbuilder->GetVISAKernel (sym.s_name ) != nullptr );
5805
- vbuilder->GetVISAKernel (sym.s_name )->GetGTPinBuffer (buffer, size, scratchOffset);
5806
- pOutput->m_FuncGTPinInfoList .push_back ({sym.s_name , buffer, size});
5807
- }
5808
- }
5809
- CreateGlobalHostAccessTable (cl_context->m_programInfo .m_zebinGlobalHostAccessTable );
5810
- } else {
5811
- CreateSymbolTable (pOutput->m_funcSymbolTable , pOutput->m_funcSymbolTableSize , pOutput->m_funcSymbolTableEntries );
5752
+ ValueToSymbolList symbolTableList;
5753
+ CreateSymbolTable (symbolTableList);
5754
+ CreateFunctionSymbolTable (symbolTableList, pOutput->m_symbols );
5812
5755
5813
- CreateGlobalHostAccessTable (pOutput->m_globalHostAccessTable , pOutput->m_globalHostAccessTableSize ,
5814
- pOutput->m_globalHostAccessTableEntries );
5756
+ if (context->type == ShaderType::OPENCL_SHADER) {
5757
+ auto cl_context = static_cast <OpenCLProgramContext *>(context);
5758
+ CreateProgramSymbolTable (symbolTableList, cl_context->m_programInfo .m_zebinSymbolTable );
5815
5759
}
5816
- }
5817
5760
5818
- if (ZEBinEnabled) {
5819
- // create symbols for kernel.
5820
- // The kernel Symbol has the same name as the kernel, and offset
5821
- // pointed to 0.
5822
- CreateLocalSymbol (m_program->entry ->getName ().str (), vISA::GenSymType::S_KERNEL, 0 ,
5823
- (unsigned )pMainKernel.getGenSize (), pOutput->m_symbols );
5824
-
5825
- // Emit symbol "_entry' as the actual kernel start. Maybe we can
5826
- // consider to use the value of the _main label in this case. Now
5827
- // set the symbol value as the max offset next to the per-thread
5828
- // prolog, the cross-thread prolog, or the compute-FFID prolog.
5829
- unsigned actual_kernel_start_off =
5830
- std::max (std::max (jitInfo->offsetToSkipPerThreadDataLoad , jitInfo->offsetToSkipCrossThreadDataLoad ),
5831
- jitInfo->offsetToSkipSetFFIDGP1 );
5832
- CreateLocalSymbol (" _entry" , vISA::GenSymType::S_NOTYPE, actual_kernel_start_off, 0 , pOutput->m_symbols );
5833
-
5834
- // Create local function symbols for direct stackcall functions.
5835
- for (auto &stackFunc : stackFuncMap) {
5836
- Function *func = stackFunc.first ;
5837
- if (func->hasFnAttribute (" referenced-indirectly" ))
5838
- continue ;
5839
-
5840
- const std::string funcName = func->getName ().str ();
5841
- VISAFunction *visaFunc = stackFunc.second ;
5842
- CreateLocalSymbol (funcName, vISA::GenSymType::S_FUNC, (uint32_t )visaFunc->getGenOffset (),
5843
- (uint32_t )visaFunc->getGenSize (), pOutput->m_symbols );
5844
- // Set up per-function GTPIN information for direct stackcall
5845
- // functions as well.
5761
+ // Set up per-function GTPIN information for indirect functions.
5762
+ for (auto &sym : pOutput->m_symbols .function ) {
5846
5763
void *buffer = nullptr ;
5847
5764
unsigned size = 0 ;
5848
- visaFunc->GetGTPinBuffer (buffer, size, 0 );
5849
- pOutput->m_FuncGTPinInfoList .push_back ({funcName, buffer, size});
5765
+ if (sym.s_type != vISA::GenSymType::S_UNDEF) {
5766
+ IGC_ASSERT (vbuilder->GetVISAKernel (sym.s_name ) != nullptr );
5767
+ vbuilder->GetVISAKernel (sym.s_name )->GetGTPinBuffer (buffer, size, scratchOffset);
5768
+ pOutput->m_FuncGTPinInfoList .push_back ({sym.s_name , buffer, size});
5769
+ }
5770
+ }
5771
+
5772
+ if (context->type == ShaderType::OPENCL_SHADER) {
5773
+ auto cl_context = static_cast <OpenCLProgramContext *>(context);
5774
+ CreateGlobalHostAccessTable (cl_context->m_programInfo .m_zebinGlobalHostAccessTable );
5850
5775
}
5851
5776
}
5777
+
5778
+ // create symbols for kernel.
5779
+ // The kernel Symbol has the same name as the kernel, and offset
5780
+ // pointed to 0.
5781
+ CreateLocalSymbol (m_program->entry ->getName ().str (), vISA::GenSymType::S_KERNEL, 0 ,
5782
+ (unsigned )pMainKernel.getGenSize (), pOutput->m_symbols );
5783
+
5784
+ // Emit symbol "_entry' as the actual kernel start. Maybe we can
5785
+ // consider to use the value of the _main label in this case. Now
5786
+ // set the symbol value as the max offset next to the per-thread
5787
+ // prolog, the cross-thread prolog, or the compute-FFID prolog.
5788
+ unsigned actual_kernel_start_off =
5789
+ std::max (std::max (jitInfo->offsetToSkipPerThreadDataLoad , jitInfo->offsetToSkipCrossThreadDataLoad ),
5790
+ jitInfo->offsetToSkipSetFFIDGP1 );
5791
+ CreateLocalSymbol (" _entry" , vISA::GenSymType::S_NOTYPE, actual_kernel_start_off, 0 , pOutput->m_symbols );
5792
+
5793
+ // Create local function symbols for direct stackcall functions.
5794
+ for (auto &stackFunc : stackFuncMap) {
5795
+ Function *func = stackFunc.first ;
5796
+ if (func->hasFnAttribute (" referenced-indirectly" ))
5797
+ continue ;
5798
+
5799
+ const std::string funcName = func->getName ().str ();
5800
+ VISAFunction *visaFunc = stackFunc.second ;
5801
+ CreateLocalSymbol (funcName, vISA::GenSymType::S_FUNC, (uint32_t )visaFunc->getGenOffset (),
5802
+ (uint32_t )visaFunc->getGenSize (), pOutput->m_symbols );
5803
+ // Set up per-function GTPIN information for direct stackcall
5804
+ // functions as well.
5805
+ void *buffer = nullptr ;
5806
+ unsigned size = 0 ;
5807
+ visaFunc->GetGTPinBuffer (buffer, size, 0 );
5808
+ pOutput->m_FuncGTPinInfoList .push_back ({funcName, buffer, size});
5809
+ }
5852
5810
}
5853
5811
5854
5812
void CEncoder::SetKernelRetryState (CodeGenContext *context, vISA::FINALIZER_INFO *jitInfo,
0 commit comments