Skip to content

Commit 7c6de8c

Browse files
michalkr52igcbot
authored andcommitted
Use ZEBinary symbol tables instead of legacy types
Changed usages of legacy symbol table structures (m_funcSymbolTable) to ZEBinary structures (m_symbols). Removed VC/LegacyInfoGeneration source files, as they're not needed after deprecating legacy relocations and symbols.
1 parent d0eb845 commit 7c6de8c

File tree

10 files changed

+122
-265
lines changed

10 files changed

+122
-265
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 84 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4953,16 +4953,14 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
49534953
auto Iter = stackFuncMap.find(VFDef);
49544954
IGC_ASSERT_MESSAGE(Iter != stackFuncMap.end(), "vISA function not found");
49554955

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();
49604958

49614959
// Query vISA for the function's byte offset within the compiled module
49624960
// The actual binary offset data should point to the function definition
49634961
VISAFunction *visaFunc = Iter->second;
49644962
fEntry.s_type = vISA::GenSymType::S_FUNC;
4965-
fEntry.s_offset = (uint32_t)visaFunc->getGenOffset();
4963+
fEntry.s_offset = (size_t)visaFunc->getGenOffset();
49664964
fEntry.s_size = (uint32_t)visaFunc->getGenSize();
49674965

49684966
symbolTableList.push_back(std::make_pair(&F, fEntry));
@@ -4980,10 +4978,8 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
49804978
}
49814979
}
49824980

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();
49874983

49884984
if (F.isDeclaration()) {
49894985
// If the function is only declared, set as undefined type
@@ -4997,7 +4993,7 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
49974993
// Query vISA for the function's byte offset within the compiled module
49984994
VISAFunction *visaFunc = Iter->second;
49994995
fEntry.s_type = vISA::GenSymType::S_FUNC;
5000-
fEntry.s_offset = (uint32_t)visaFunc->getGenOffset();
4996+
fEntry.s_offset = (size_t)visaFunc->getGenOffset();
50014997
fEntry.s_size = (uint32_t)visaFunc->getGenSize();
50024998
}
50034999
symbolTableList.push_back(std::make_pair(&F, fEntry));
@@ -5026,20 +5022,20 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
50265022
unsigned addrSpace = pGlobal->getType()->getAddressSpace();
50275023
IGC_ASSERT(name.size() <= vISA::MAX_SYMBOL_NAME_LENGTH);
50285024

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+
50315028
MDNode *md = pGlobal->getMetadata("ConstSampler");
50325029
if (md) {
50335030
// Constant Sampler: s_offset contains the sampler ID
50345031
sEntry.s_type = vISA::GenSymType::S_CONST_SAMPLER;
50355032
sEntry.s_size = 0;
50365033
sEntry.s_offset = static_cast<size_t>(global.second);
50375034
} else {
5038-
uint32_t type = vISA::GenSymType::S_GLOBAL_VAR_CONST;
5035+
vISA::GenSymType type = vISA::GenSymType::S_GLOBAL_VAR_CONST;
50395036
// For Zebin always use constant type for string constants
50405037
// because of the relaxed address space requirement of
50415038
// printf strings.
5042-
IGC_ASSERT(modMD->stringConstants.empty() || m_program->GetContext()->enableZEBinary());
50435039
if (addrSpace == ADDRESS_SPACE_GLOBAL && !modMD->stringConstants.count(pGlobal))
50445040
type = vISA::GenSymType::S_GLOBAL_VAR;
50455041
if (!pGlobal->hasInitializer())
@@ -5054,68 +5050,48 @@ void CEncoder::CreateSymbolTable(ValueToSymbolList &symbolTableList) {
50545050
}
50555051
}
50565052

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) {
50895055
for (const auto &I : symbolTableList) {
50905056
Value *symbolValue = I.first;
50915057
auto symbolEntry = I.second;
50925058

50935059
if (Function *F = dyn_cast<Function>(symbolValue)) {
50945060
funcSyms.function.emplace_back((vISA::GenSymType)symbolEntry.s_type, symbolEntry.s_offset, symbolEntry.s_size,
5095-
F->getName().str());
5061+
F->getName().str());
50965062
} else if (GlobalVariable *G = dyn_cast<GlobalVariable>(symbolValue)) {
5097-
// const sampler
5063+
// Const sampler
50985064
if (symbolEntry.s_type == vISA::GenSymType::S_CONST_SAMPLER) {
50995065
funcSyms.sampler.emplace_back((vISA::GenSymType)symbolEntry.s_type, symbolEntry.s_offset, symbolEntry.s_size,
51005066
G->getName().str());
51015067
}
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) {
51055083
programSyms.global.emplace_back((vISA::GenSymType)symbolEntry.s_type, symbolEntry.s_offset, symbolEntry.s_size,
5106-
G->getName().str());
5084+
G->getName().str());
51075085
}
5108-
// global constants and string literals
5086+
// Global constants and string literals
51095087
else {
51105088
if (modMD->stringConstants.count(G)) {
51115089
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());
51135091
} else
51145092
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());
51165094
}
5117-
} else {
5118-
IGC_ASSERT(0);
51195095
}
51205096
}
51215097
}
@@ -5168,23 +5144,6 @@ void CEncoder::CreateFuncAttributeTable(VISAKernel *pMainKernel, GenXFunctionGro
51685144
}
51695145
}
51705146

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-
51885147
void CEncoder::CreateGlobalHostAccessTable(HostAccessList &hostAccessList) {
51895148
ModuleMetaData *modMD = m_program->GetContext()->getModuleMetaData();
51905149

@@ -5787,68 +5746,67 @@ void CEncoder::createSymbolAndGlobalHostAccessTables(bool hasSymbolTable, VISAKe
57875746
unsigned int scratchOffset) {
57885747
CodeGenContext *context = m_program->GetContext();
57895748
SProgramOutput *pOutput = m_program->ProgramOutput();
5790-
bool ZEBinEnabled = context->enableZEBinary();
57915749
vISA::FINALIZER_INFO *jitInfo = nullptr;
57925750
pMainKernel.GetJitInfo(jitInfo);
57935751
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);
58125755

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);
58155759
}
5816-
}
58175760

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) {
58465763
void *buffer = nullptr;
58475764
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);
58505775
}
58515776
}
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+
}
58525810
}
58535811

58545812
void CEncoder::SetKernelRetryState(CodeGenContext *context, vISA::FINALIZER_INFO *jitInfo,

IGC/Compiler/CISACodeGen/CISABuilder.hpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -522,38 +522,31 @@ class CEncoder {
522522
// save compile time by avoiding retry if the amount of spill is (very) small
523523
bool AvoidRetryOnSmallSpill() const;
524524

525-
// CreateSymbolTable will create symbols in two formats. One in given buffer that will be
526-
// later parsed as patch token based format, another as struct type that will be parsed
527-
// as ZE binary format
528-
529525
// CreateSymbolTable
530526
// Note that this function should be called only once even if there are
531527
// multiple kernels in a program. Current IGC flow will create all symbols in
532528
// the first kernel and all the other kernels won't contain symbols
533-
typedef std::vector<std::pair<llvm::Value *, vISA::GenSymEntry>> ValueToSymbolList;
529+
typedef std::vector<std::pair<llvm::Value *, vISA::ZESymEntry>> ValueToSymbolList;
534530
void CreateSymbolTable(ValueToSymbolList &symbolTableList);
535-
// input/output: buffer, bufferSize, tableEntries: for patch-token-based
536-
// format.
537-
void CreateSymbolTable(void *&buffer, unsigned &bufferSize, unsigned &tableEntries);
538-
// input/output: symbols: for ZEBinary foramt
539-
void CreateSymbolTable(SProgramOutput::ZEBinFuncSymbolTable &funcSyms,
540-
SOpenCLProgramInfo::ZEBinProgramSymbolTable &programSyms);
541-
// Create local symbols for kernels. This is ZEBinary format only.
531+
// Create function symbols
532+
void CreateFunctionSymbolTable(ValueToSymbolList &symbolTableList, SProgramOutput::ZEBinFuncSymbolTable &funcSyms);
533+
// Create program symbols
534+
void CreateProgramSymbolTable(ValueToSymbolList &symbolTableList,
535+
SOpenCLProgramInfo::ZEBinProgramSymbolTable &programSyms);
536+
// Create local symbols for kernels
542537
void CreateLocalSymbol(const std::string &kernelName, vISA::GenSymType type, unsigned offset, unsigned size,
543538
SProgramOutput::ZEBinFuncSymbolTable &symbols);
544539

545-
// input/output: relocations: for ZEBinary foramt
540+
// input/output: relocations
546541
void CreateRelocationTable(VISAKernel *pMainKernel, SProgramOutput::RelocListTy &relocations);
547542

548543
// CreateFuncAttributeTable
549544
void CreateFuncAttributeTable(VISAKernel *pMainKernel, GenXFunctionGroupAnalysis *pFga);
550545

551546
// CreateGlobalHostAccessTable
552547
typedef std::vector<vISA::HostAccessEntry> HostAccessList;
553-
void CreateGlobalHostAccessTable(void *&buffer, unsigned &bufferSize, unsigned &tableEntries);
554-
// input/output: hostAccessMap: for patch-token-based format.
555548
void CreateGlobalHostAccessTable(HostAccessList &hostAccessMap);
556-
// input/output: global host access names: for ZEBinary format
549+
// input/output: global host access names
557550
void CreateGlobalHostAccessTable(SOpenCLProgramInfo::ZEBinGlobalHostAccessTable &globalHostAccessTable);
558551

559552
uint32_t getGRFSize() const;
@@ -622,11 +615,10 @@ class CEncoder {
622615
// setup m_retryManager according to jitinfo and other factors
623616
void SetKernelRetryState(CodeGenContext *context, vISA::FINALIZER_INFO *jitInfo, GenXFunctionGroupAnalysis *&pFGA);
624617

625-
/// create symbol tables and GlobalHostAccessTable according to if it's zebin
626-
/// or patch-token formats
618+
/// create symbol tables and GlobalHostAccessTable
627619
void createSymbolAndGlobalHostAccessTables(bool hasSymbolTable, VISAKernel &pMainKernel, unsigned int scratchOffset);
628620

629-
/// create relocation according to if it's zebin or patch-token formats
621+
/// create relocation tables according
630622
void createRelocationTables(VISAKernel &pMainKernel);
631623

632624
/// Estimate vISA stack size according to FunctionGroup information.

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,7 @@ bool EmitPass::isSymbolTableRequired(llvm::Function *F) {
475475
pGlobal->removeDeadConstantUsers();
476476

477477
// Check if relocation is required by checking uses
478-
479-
// FIXME: Ideally we should emit symtab for the global if
480-
// there's an user in both ZEBIN and PT.
481-
if (m_pCtx->enableZEBinary() && !pGlobal->user_empty())
478+
if (!pGlobal->user_empty())
482479
return true;
483480

484481
for (auto user : pGlobal->users()) {

0 commit comments

Comments
 (0)