@@ -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+
70397046KernelDebugInfo* G4_Kernel::getKernelDebugInfo ()
70407047{
70417048 if (kernelDbgInfo == nullptr )
@@ -7399,24 +7406,42 @@ void RelocationEntry::doRelocation(const G4_Kernel& kernel, void* binary, uint32
73997406
74007407uint32_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
74227447void 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}
0 commit comments