Skip to content

Commit 0cd64fd

Browse files
michalkr52igcbot
authored andcommitted
Use ZEBinary relocation tables instead of legacy types
Removed definitions of old relocation table types (m_funcRelocationTable). Changed usages of relocation tables to use the ZEBinary type (m_relocs).
1 parent 554cabd commit 0cd64fd

File tree

12 files changed

+18
-116
lines changed

12 files changed

+18
-116
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,21 +5128,7 @@ void CEncoder::CreateGlobalHostAccessTable(SOpenCLProgramInfo::ZEBinGlobalHostAc
51285128
globalHostAccessTable.push_back(vISA::ZEHostAccessEntry{I.device_name, I.host_name});
51295129
}
51305130

5131-
void CEncoder::CreateRelocationTable(VISAKernel *pMainKernel, void *&buffer, unsigned &bufferSize,
5132-
unsigned &tableEntries) {
5133-
// for patch-token-based binary format
5134-
buffer = nullptr;
5135-
bufferSize = 0;
5136-
tableEntries = 0;
5137-
5138-
// vISA will directly return the buffer with GenRelocEntry layout
5139-
IGC_ASSERT(nullptr != pMainKernel);
5140-
V(pMainKernel->GetGenRelocEntryBuffer(buffer, bufferSize, tableEntries));
5141-
IGC_ASSERT((sizeof(vISA::GenRelocEntry) * tableEntries) == bufferSize);
5142-
}
5143-
51445131
void CEncoder::CreateRelocationTable(VISAKernel *pMainKernel, SProgramOutput::RelocListTy &relocations) {
5145-
// for ZEBinary format
51465132
IGC_ASSERT(nullptr != pMainKernel);
51475133
V(pMainKernel->GetRelocations(relocations));
51485134
}
@@ -5750,25 +5736,20 @@ uint32_t CEncoder::getSpillMemSizeWithFG(const llvm::Function &curFunc, uint32_t
57505736
void CEncoder::createRelocationTables(VISAKernel &pMainKernel) {
57515737
CodeGenContext *context = m_program->GetContext();
57525738
SProgramOutput *pOutput = m_program->ProgramOutput();
5753-
bool ZEBinEnabled = context->enableZEBinary();
5754-
if (ZEBinEnabled) {
5755-
CreateRelocationTable(&pMainKernel, pOutput->m_relocs);
5739+
CreateRelocationTable(&pMainKernel, pOutput->m_relocs);
5740+
if (context->type == ShaderType::OPENCL_SHADER) {
57565741
for (const auto &reloc : pOutput->m_relocs) {
57575742
if (reloc.r_symbol == vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME) {
5758-
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
57595743
auto cl_context = static_cast<OpenCLProgramContext *>(context);
57605744
cl_context->m_programInfo.m_hasCrossThreadOffsetRelocations = true;
57615745
} else if (reloc.r_symbol == vISA::PER_THREAD_OFF_RELOCATION_NAME) {
5762-
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
57635746
auto cl_context = static_cast<OpenCLProgramContext *>(context);
57645747
cl_context->m_programInfo.m_hasPerThreadOffsetRelocations = true;
57655748
}
57665749
}
5767-
} else {
5768-
CreateRelocationTable(&pMainKernel, pOutput->m_funcRelocationTable, pOutput->m_funcRelocationTableSize,
5769-
pOutput->m_funcRelocationTableEntries);
57705750
}
57715751
}
5752+
57725753
const vISA::KernelCostInfo *CEncoder::createKernelCostInfo(VISAKernel &pMainKernel) {
57735754
CodeGenContext *context = m_program->GetContext();
57745755
IGC_ASSERT(context->enableZEBinary());

IGC/Compiler/CISACodeGen/CISABuilder.hpp

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

525-
// CreateSymbolTable, CreateRelocationTable and CreateFuncAttributeTable will
526-
// create symbols, relococations and FuncAttributes in two formats. One in
527-
// given buffer that will be later parsed as patch token based format, another
528-
// as struct type that will be parsed as ZE binary format
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
529528

530529
// CreateSymbolTable
531530
// Note that this function should be called only once even if there are
@@ -543,10 +542,6 @@ class CEncoder {
543542
void CreateLocalSymbol(const std::string &kernelName, vISA::GenSymType type, unsigned offset, unsigned size,
544543
SProgramOutput::ZEBinFuncSymbolTable &symbols);
545544

546-
// CreateRelocationTable
547-
// input/output: buffer, bufferSize, tableEntries: for patch-token-based
548-
// format.
549-
void CreateRelocationTable(VISAKernel *pMainKernel, void *&buffer, unsigned &bufferSize, unsigned &tableEntries);
550545
// input/output: relocations: for ZEBinary foramt
551546
void CreateRelocationTable(VISAKernel *pMainKernel, SProgramOutput::RelocListTy &relocations);
552547

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19277,7 +19277,12 @@ void IGC::EmitPass::emitCanonicalize(llvm::Instruction *inst, const DstModifier
1927719277
}
1927819278

1927919279
void IGC::EmitPass::emitStaticConstantPatchValue(llvm::StaticConstantPatchIntrinsic *staticConstantPatch32) {
19280-
std::string patchName = staticConstantPatch32->getPatchName().str();
19280+
llvm::StringRef nameRef = staticConstantPatch32->getPatchName();
19281+
// Drop null-terminator if present, it shouldn't be included in std::strings.
19282+
if (!nameRef.empty() && nameRef.back() == '\0') {
19283+
nameRef = nameRef.drop_back();
19284+
}
19285+
std::string patchName = nameRef.str();
1928119286
m_encoder->AddVISASymbol(patchName, m_destination);
1928219287
}
1928319288

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ struct SProgramOutput {
137137
unsigned int m_funcSymbolTableSize = 0;
138138
unsigned int m_funcSymbolTableEntries = 0;
139139
ZEBinFuncSymbolTable m_symbols; // duplicated information of m_funcSymbolTable, for zebin
140-
void *m_funcRelocationTable = nullptr;
141-
unsigned int m_funcRelocationTableSize = 0;
142-
unsigned int m_funcRelocationTableEntries = 0;
143-
RelocListTy m_relocs; // duplicated information of m_funcRelocationTable, for zebin
140+
RelocListTy m_relocs;
144141
FuncAttrListTy m_funcAttrs;
145142
void *m_globalHostAccessTable = nullptr;
146143
unsigned int m_globalHostAccessTableSize = 0;
@@ -182,9 +179,6 @@ struct SProgramOutput {
182179
if (m_funcSymbolTable) {
183180
free(m_funcSymbolTable);
184181
}
185-
if (m_funcRelocationTable) {
186-
free(m_funcRelocationTable);
187-
}
188182
if (m_globalHostAccessTable) {
189183
free(m_globalHostAccessTable);
190184
}

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ void CMKernel::RecomputeBTLayout(int numUAVs, int numResources) {
363363

364364
static void setFuncSectionInfo(const GenXOCLRuntimeInfo::KernelInfo &Info,
365365
IGC::SProgramOutput &KernelProgram) {
366-
KernelProgram.m_funcRelocationTable = Info.LegacyFuncRelocations.Buffer;
367-
KernelProgram.m_funcRelocationTableSize = Info.LegacyFuncRelocations.Size;
368-
KernelProgram.m_funcRelocationTableEntries =
369-
Info.LegacyFuncRelocations.Entries;
370366
KernelProgram.m_relocs = Info.Func.Relocations;
371367

372368
vc::validateFunctionSymbolTable(Info.Func.Symbols);

IGC/VectorCompiler/include/vc/GenXCodeGen/GenXOCLRuntimeInfo.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ class GenXOCLRuntimeInfo : public ModulePass {
121121
}
122122
};
123123

124-
struct TableInfo {
125-
void *Buffer = nullptr;
126-
unsigned Size = 0;
127-
unsigned Entries = 0;
128-
};
129-
130-
// Symbols and reloacations are collected in zebin format. Later they are
124+
// Symbols and relocations are collected in zebin format. Later symbols are
131125
// translated into legacy format for patch token generation.
132126
using SymbolSeq = std::vector<vISA::ZESymEntry>;
133127
using RelocationSeq = std::vector<vISA::ZERelocEntry>;
@@ -204,9 +198,6 @@ class GenXOCLRuntimeInfo : public ModulePass {
204198
// but still required for runtime.
205199
struct KernelInfo {
206200
SectionInfo Func;
207-
// Duplicates Func.Relocations. Cannot unify it on VC side since the
208-
// duplication happens on Finalizer side.
209-
TableInfo LegacyFuncRelocations;
210201

211202
// Keeps in the first element name of the FG's head and VISA asm for this FG
212203
// in the second element.

IGC/VectorCompiler/lib/GenXCodeGen/GenXOCLRuntimeInfo.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,11 +917,6 @@ RuntimeInfoCollector::collectFunctionGroupInfo(const FunctionGroup &FG) const {
917917
auto DebugData = getDebugInformation(DBG, KernelFunction);
918918

919919
Info.Func.Relocations = TextSection.Relocations;
920-
// Still have to duplicate function relocations because they are constructed
921-
// inside Finalizer.
922-
CISA_CALL(VK->GetGenRelocEntryBuffer(Info.LegacyFuncRelocations.Buffer,
923-
Info.LegacyFuncRelocations.Size,
924-
Info.LegacyFuncRelocations.Entries));
925920
Info.Func.Symbols =
926921
constructFunctionSymbols(TextSection.Data, /*HasKernel=*/true);
927922

visa/Optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8476,7 +8476,7 @@ void Optimizer::changeMoveType() {
84768476
// new src0 and overwrite the original RelocImm While this optimization
84778477
// should still be able to apply to RelocImm. Once we turn on this
84788478
// optimization for RelocImm, we should update assert in
8479-
// VISAKernelImpl::GetGenRelocEntryBuffer to allow float type
8479+
// VISAKernelImpl::GetRelocations to allow float type
84808480
if (src0->isRelocImm())
84818481
continue;
84828482

visa/VISAKernel.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,14 +1032,7 @@ class VISAKernelImpl : public VISAFunction {
10321032
VISA_BUILDER_API int GetErrorMessage(const char *&errorMsg) const override;
10331033
VISA_BUILDER_API virtual int
10341034
GetGenxDebugInfo(void *&buffer, unsigned int &size) const override;
1035-
/// GetGenRelocEntryBuffer -- allocate and return a buffer of all
1036-
/// GenRelocEntry that are created by vISA
1037-
VISA_BUILDER_API int
1038-
GetGenRelocEntryBuffer(void *&buffer, unsigned int &byteSize,
1039-
unsigned int &numEntries) override;
10401035
/// GetRelocations -- add vISA created relocations into given relocation list
1041-
/// This get the same information as GetGenRelocEntryBuffer, but in different
1042-
/// foramt
10431036
VISA_BUILDER_API int GetRelocations(RelocListType &relocs) override;
10441037
VISA_BUILDER_API int GetGTPinBuffer(void *&buffer, unsigned int &size,
10451038
unsigned int scratchOffset) override;

visa/VISAKernelImpl.cpp

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8754,53 +8754,12 @@ int VISAKernelImpl::GetRelocations(RelocListType &relocs) {
87548754
static_cast<uint32_t>(genOffset + reloc.getTargetOffset(*m_builder));
87558755
relocs.emplace_back(reloc.getType(), offset, reloc.getSymbolName());
87568756

8757-
vASSERT((genOffset != UNDEFINED_GEN_OFFSET) && (offset > genOffset) &&
8758-
(offset < genOffset + BYTES_PER_INST));
8757+
vASSERT((genOffset != UNDEFINED_GEN_OFFSET) && (offset >= genOffset) &&
8758+
(offset < genOffset + BYTES_PER_INST));
87598759
}
87608760
return VISA_SUCCESS;
87618761
}
87628762

8763-
int VISAKernelImpl::GetGenRelocEntryBuffer(void *&buffer,
8764-
unsigned int &byteSize,
8765-
unsigned int &numEntries) {
8766-
G4_Kernel::RelocationTableTy &reloc_table = m_kernel->getRelocationTable();
8767-
numEntries = reloc_table.size();
8768-
byteSize = sizeof(GenRelocEntry) * numEntries;
8769-
8770-
if (reloc_table.empty())
8771-
return VISA_SUCCESS;
8772-
8773-
// allocate the buffer for relocation table
8774-
buffer = allocCodeBlock(byteSize);
8775-
8776-
if (buffer == nullptr)
8777-
return VISA_FAILURE;
8778-
8779-
GenRelocEntry *buffer_p = (GenRelocEntry *)buffer;
8780-
for (const auto &reloc : reloc_table) {
8781-
auto inst = reloc.getInst();
8782-
buffer_p->r_type = reloc.getType();
8783-
buffer_p->r_offset = static_cast<uint32_t>(inst->getGenOffset()) +
8784-
reloc.getTargetOffset(*m_builder);
8785-
8786-
vISA_ASSERT((buffer_p->r_offset >= inst->getGenOffset()) &&
8787-
(buffer_p->r_offset < inst->getGenOffset() + BYTES_PER_INST),
8788-
"Invalid relocation offset returned, offset must be within"
8789-
"the ISA instruction");
8790-
8791-
vISA_ASSERT(reloc.getSymbolName().size() <= MAX_SYMBOL_NAME_LENGTH,
8792-
"Relocation symbol name longer than MAX_SYMBOL_NAME_LENGTH");
8793-
8794-
// clean the buffer first
8795-
memset(buffer_p->r_symbol, 0, MAX_SYMBOL_NAME_LENGTH);
8796-
strcpy_s(buffer_p->r_symbol, MAX_SYMBOL_NAME_LENGTH,
8797-
reloc.getSymbolName().c_str());
8798-
++buffer_p;
8799-
}
8800-
8801-
return VISA_SUCCESS;
8802-
}
8803-
88048763
int VISAKernelImpl::GetGenxDebugInfo(void *&buffer, unsigned int &size) const {
88058764
buffer = m_genx_debug_info_buffer;
88068765
size = m_genx_debug_info_size;

0 commit comments

Comments
 (0)