Skip to content

Commit 3305754

Browse files
DianaChensys_zuul
authored andcommitted
Add new Relocation Type R_PER_THREAD_PAYLOAD_OFFSET_32
Also refactor vISA::RelocationEntry create API Change-Id: Ic6dcd8971396651d8f1e54e7606d6c33c3588f04
1 parent 294fb63 commit 3305754

File tree

7 files changed

+76
-44
lines changed

7 files changed

+76
-44
lines changed

visa/BuildIR.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,18 @@ class IR_Builder {
16251625
return newImm;
16261626
}
16271627

1628+
//
1629+
// Create immediate operand without looking up hash table. This operand
1630+
// is a relocatable immediate type. Specify the value of this imm field,
1631+
// which will present in the output instruction's imm value.
1632+
//
1633+
G4_Reloc_Imm* createRelocImm(int64_t immval, G4_Type ty)
1634+
{
1635+
G4_Reloc_Imm* newImm;
1636+
newImm = new (mem)G4_Reloc_Imm(immval, ty);
1637+
return newImm;
1638+
}
1639+
16281640
//
16291641
// return the label operand; create one if not found
16301642
//

visa/FlowGraph.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7036,6 +7036,13 @@ FlowGraph::~FlowGraph()
70367036
}
70377037
}
70387038

7039+
RelocationEntry& RelocationEntry::createRelocation(G4_Kernel& kernel, G4_INST& inst,
7040+
int opndPos, const std::string& symbolName, RelocationType type)
7041+
{
7042+
kernel.getRelocationTable().emplace_back(RelocationEntry(&inst, opndPos, type, symbolName));
7043+
return kernel.getRelocationTable().back();
7044+
}
7045+
70397046
KernelDebugInfo* G4_Kernel::getKernelDebugInfo()
70407047
{
70417048
if (kernelDbgInfo == nullptr)
@@ -7399,24 +7406,42 @@ void RelocationEntry::doRelocation(const G4_Kernel& kernel, void* binary, uint32
73997406

74007407
uint32_t RelocationEntry::getTargetOffset(const IR_Builder& builder) const
74017408
{
7402-
// currently we only support relocation on mov instruction
7403-
assert(inst->isMov());
7409+
// instruction being relocated must not be compacted, or the offset need to be re-adjusted
7410+
// FIXME: This only check if vISA force to compact the instruction, it cannot make sure
7411+
// the Binary encoder won't compact it
74047412
assert(inst->isCompactedInst() == false);
7405-
auto src0 = inst->getSrc(0);
7406-
assert(src0->isRelocImm() && ((src0->getType() == Type_UD) || (src0->getType() == Type_UQ)));
74077413

7408-
// When src0 type is 64 bits:
7409-
// On PreGen12:
7410-
// Src0.imm[31:0] mapped to Instruction [95:64]
7411-
// Src0.imm[63:32] mapped to Instruction [127:96]
7412-
// On Gen12+:
7413-
// Src0.imm[31:0] mapped to Instruction [127:96]
7414-
// Src0.imm[63:32] mapped to Instruction [95:64]
7415-
7416-
// When src0 type is 32 bits:
7417-
// Src0.imm[31:0] mapped to instruction [127:96]
7414+
G4_Operand* target_operand = inst->getSrc(opndPos);
7415+
assert(target_operand->isRelocImm());
7416+
7417+
switch (inst->opcode()) {
7418+
case G4_mov:
7419+
// When src0 type is 64 bits:
7420+
// On PreGen12:
7421+
// Src0.imm[31:0] mapped to Instruction [95:64]
7422+
// Src0.imm[63:32] mapped to Instruction [127:96]
7423+
// On Gen12+:
7424+
// Src0.imm[31:0] mapped to Instruction [127:96]
7425+
// Src0.imm[63:32] mapped to Instruction [95:64]
7426+
// When src0 type is 32 bits:
7427+
// Src0.imm[31:0] mapped to instruction [127:96]
7428+
assert((target_operand->getType() == Type_UD) || (target_operand->getType() == Type_UQ));
7429+
assert(opndPos == 0);
7430+
return (target_operand->getType() == Type_UD) ? 12 : 8;
7431+
7432+
case G4_add:
7433+
// add instruction cannot have 64-bit imm
7434+
assert(relocType != R_SYM_ADDR && relocType != R_SYM_ADDR_32_HI);
7435+
assert(opndPos == 1);
7436+
// Src1.imm[31:0] mapped to Instruction [127:96]
7437+
return 12;
7438+
default:
7439+
break;
7440+
}
74187441

7419-
return (src0->getType() == Type_UD) ? 12 : 8;
7442+
// currently we only support relocation on mov or add instruction
7443+
assert(false && "Unreachable");
7444+
return 0;
74207445
}
74217446

74227447
void RelocationEntry::dump() const
@@ -7438,6 +7463,9 @@ void RelocationEntry::dump() const
74387463
case RelocationType::R_SYM_ADDR_32_HI:
74397464
std::cerr << "R_SYM_ADDR_32_HI: symbol name = " << symName;
74407465
break;
7466+
case RelocationType::R_PER_THREAD_PAYLOAD_OFFSET_32:
7467+
std::cerr << "R_PER_THREAD_PAYLOAD_OFFSET_32: symbol name = " << symName;
7468+
break;
74417469
}
74427470
std::cerr << "\n";
74437471
}

visa/FlowGraph.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PhyRegSummary;
5353
//
5454

5555
class G4_BB;
56+
class G4_Kernel;
5657
class FlowGraph;
5758
class KernelDebugInfo;
5859
class VarSplitPass;
@@ -672,7 +673,6 @@ typedef std::pair<BB_LIST_ITER, BB_LIST_ITER> GRAPH_CUT_BOUNDS;
672673
namespace vISA
673674
{
674675

675-
class G4_Kernel; // forward declaration
676676
class FlowGraph
677677
{
678678
// Data
@@ -1363,11 +1363,8 @@ class RelocationEntry
13631363
inst(i), opndPos(pos), relocType(type), symName(symbolName){}
13641364

13651365
public:
1366-
static RelocationEntry createSymbolAddrReloc(G4_INST* inst, int opndPos, const std::string& symbolName, RelocationType type)
1367-
{
1368-
RelocationEntry entry(inst, opndPos, type, symbolName);
1369-
return entry;
1370-
}
1366+
static RelocationEntry& createRelocation(G4_Kernel& kernel, G4_INST& inst,
1367+
int opndPos, const std::string& symbolName, RelocationType type);
13711368

13721369
G4_INST* getInst() const
13731370
{
@@ -1389,6 +1386,8 @@ class RelocationEntry
13891386
return "R_SYM_ADDR_32";
13901387
case RelocationType::R_SYM_ADDR_32_HI:
13911388
return "R_SYM_ADDR_32_HI";
1389+
case RelocationType::R_PER_THREAD_PAYLOAD_OFFSET_32:
1390+
return "R_PER_THREAD_PAYLOAD_OFFSET_32";
13921391
default:
13931392
assert(false && "unhandled relocation type");
13941393
return "";
@@ -1402,12 +1401,6 @@ class RelocationEntry
14021401

14031402
const std::string& getSymbolName() const
14041403
{
1405-
bool isValidRelocType =
1406-
relocType == RelocationType::R_SYM_ADDR ||
1407-
relocType == RelocationType::R_SYM_ADDR_32 ||
1408-
relocType == RelocationType::R_SYM_ADDR_32_HI;
1409-
1410-
assert(isValidRelocType && "invalid relocation type");
14111404
return symName;
14121405
}
14131406

@@ -1627,11 +1620,6 @@ class G4_Kernel
16271620
m_hasIndirectCall = true;
16281621
}
16291622

1630-
void addRelocation(RelocationEntry& entry)
1631-
{
1632-
relocationTable.push_back(entry);
1633-
}
1634-
16351623
RelocationTableTy& getRelocationTable()
16361624
{
16371625
return relocationTable;

visa/Gen4_IR.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,9 +2720,15 @@ class G4_Reloc_Imm : public G4_Imm
27202720
void *operator new(size_t sz, Mem_Manager& m){ return m.alloc(sz); }
27212721
bool isRelocImm() const override { return true; }
27222722

2723+
// G4_Reloc_Imm is the relocation target field. If the value is not given,
2724+
// a magic number 0x6e10ca2e will present in final output
27232725
G4_Reloc_Imm(G4_Type ty) : G4_Imm((int64_t)0x6e10ca2e, ty)
27242726
{
27252727
}
2728+
2729+
G4_Reloc_Imm(int64_t val, G4_Type ty) : G4_Imm(val, ty)
2730+
{
2731+
}
27262732
};
27272733

27282734
//

visa/TranslationInterface.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,8 +2424,7 @@ int IR_Builder::translateVISACFSymbolInst(const std::string& symbolName, G4_DstR
24242424
auto* privateMemPatch = createRelocImm(Type_UD);
24252425
dst->setType(Type_UD);
24262426
G4_INST* mov = createMov(1, dst, privateMemPatch, InstOpt_WriteEnable, true);
2427-
RelocationEntry relocEntry = RelocationEntry::createSymbolAddrReloc(mov, 0, symbolName, GenRelocType::R_SYM_ADDR_32);
2428-
kernel.addRelocation(relocEntry);
2427+
RelocationEntry::createRelocation(kernel, *mov, 0, symbolName, GenRelocType::R_SYM_ADDR_32);
24292428
}
24302429
else if (noInt64() || needSwap64ImmLoHi())
24312430
{
@@ -2440,11 +2439,8 @@ int IR_Builder::translateVISACFSymbolInst(const std::string& symbolName, G4_DstR
24402439
auto dstHi = createDst(dst->getBase(), dst->getRegOff(), dst->getSubRegOff() * 2 + 1, 1, Type_UD);
24412440
G4_INST* movHi = createMov(1, dstHi, funcAddrHigh, InstOpt_WriteEnable, true);
24422441

2443-
RelocationEntry relocEntryLo = RelocationEntry::createSymbolAddrReloc(movLo, 0, symbolName, GenRelocType::R_SYM_ADDR_32);
2444-
kernel.addRelocation(relocEntryLo);
2445-
2446-
RelocationEntry relocEntryHi = RelocationEntry::createSymbolAddrReloc(movHi, 0, symbolName, GenRelocType::R_SYM_ADDR_32_HI);
2447-
kernel.addRelocation(relocEntryHi);
2442+
RelocationEntry::createRelocation(kernel, *movLo, 0, symbolName, GenRelocType::R_SYM_ADDR_32);
2443+
RelocationEntry::createRelocation(kernel, *movHi, 0, symbolName, GenRelocType::R_SYM_ADDR_32_HI);
24482444

24492445
}
24502446
else
@@ -2453,8 +2449,7 @@ int IR_Builder::translateVISACFSymbolInst(const std::string& symbolName, G4_DstR
24532449
auto funcAddr = createRelocImm(Type_UQ);
24542450
auto movInst = createMov(1, dst, funcAddr, InstOpt_WriteEnable, true);
24552451

2456-
RelocationEntry relocEntry = RelocationEntry::createSymbolAddrReloc(movInst, 0, symbolName, GenRelocType::R_SYM_ADDR);
2457-
kernel.addRelocation(relocEntry);
2452+
RelocationEntry::createRelocation(kernel, *movInst, 0, symbolName, GenRelocType::R_SYM_ADDR);
24582453
}
24592454

24602455
#if defined(MEASURE_COMPILATION_TIME) && defined(TIME_IR_CONSTRUCTION)

visa/VISAKernelImpl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8065,6 +8065,8 @@ int VISAKernelImpl::GetGenRelocEntryBuffer(void *&buffer, unsigned int &byteSize
80658065
assert((buffer_p->r_offset > inst->getGenOffset()) && (buffer_p->r_offset < inst->getGenOffset() + BYTES_PER_INST));
80668066

80678067
assert(reloc.getSymbolName().size() <= MAX_SYMBOL_NAME_LENGTH);
8068+
// clean the buffer first
8069+
memset(buffer_p->r_symbol, '0', MAX_SYMBOL_NAME_LENGTH);
80688070
strcpy_s(buffer_p->r_symbol, MAX_SYMBOL_NAME_LENGTH, reloc.getSymbolName().c_str());
80698071
++buffer_p;
80708072
}

visa/include/RelocationInfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ typedef struct {
6161
/// GenRelocType - Specify the relocation's type
6262
enum GenRelocType {
6363
R_NONE = 0,
64-
R_SYM_ADDR = 1, //64-bit type address
65-
R_SYM_ADDR_32 = 2, //lower 32-bit of 64-bit address.
66-
R_SYM_ADDR_32_HI = 3 //higher 32bits of 64-bit address
64+
R_SYM_ADDR = 1, // 64-bit type address
65+
R_SYM_ADDR_32 = 2, // 32-bit address or lower 32-bit of a 64-bit address.
66+
R_SYM_ADDR_32_HI = 3, // higher 32bits of 64-bit address
67+
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4 // 32-bit field of payload offset of per-thread data
6768
};
6869

6970
/// GenRelocEntry - An relocation table entry

0 commit comments

Comments
 (0)