Skip to content

Commit 4c55256

Browse files
fangliu2020igcbot
authored andcommitted
[IGC vISA] update vISA ABI v3 according to latest spec
Update vISA ABI v3 according to latest spec
1 parent 8440909 commit 4c55256

File tree

6 files changed

+58
-32
lines changed

6 files changed

+58
-32
lines changed

IGC/DebugInfo/DwarfDebug.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,14 @@ class DwarfDebug {
758758
// r[MAX-GRF - 3]
759759
static const unsigned int SpecialGRFOff_VISAABI_1 = 3;
760760
static const unsigned int SpecialGRFOff_VISAABI_2_3 = 1;
761-
static const unsigned int RetIpSubReg_1_2_3 = 0;
762-
static const unsigned int RetEMSubReg_1_2 = 1;
763-
static const unsigned int RetEMSubReg_3 = 2;
764-
static const unsigned int BESPSubReg_1_2 = 2;
765-
static const unsigned int BESPSubReg_3 = 4;
766-
static const unsigned int BEFPSubReg_1_2 = 3;
767-
static const unsigned int BEFPSubReg_3 = 6;
761+
static const unsigned int RetIpSubReg_1_2 = 0; // :ud
762+
static const unsigned int RetIpSubReg_3 = 4; // :ud
763+
static const unsigned int RetEMSubReg_1_2 = 1; // :ud
764+
static const unsigned int RetEMSubReg_3 = 6; // :ud
765+
static const unsigned int BESPSubReg_1_2 = 2; // :ud
766+
static const unsigned int BESPSubReg_3 = 2; // :ud
767+
static const unsigned int BEFPSubReg_1_2 = 3; // :ud
768+
static const unsigned int BEFPSubReg_3 = 0; // :ud
768769

769770
uint32_t GetSpecialGRF() {
770771
if (!EmitSettings.ZeBinCompatible)

visa/BuildCISAIRImpl.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ int CISA_IR_Builder::Compile(const char *isaasmFileName, bool emit_visa_only) {
16611661
VISAKernelImpl *mainKernel = nullptr;
16621662
KernelListTy::iterator iter = kernel_begin();
16631663
KernelListTy::iterator iend = kernel_end();
1664+
bool hasEarlyExit = false;
16641665
for (int i = 0; iter != iend; iter++, i++) {
16651666
VISAKernelImpl *kernel = (*iter);
16661667
if ((uint32_t)i < localScheduleStartKernelId ||
@@ -1712,13 +1713,17 @@ int CISA_IR_Builder::Compile(const char *isaasmFileName, bool emit_visa_only) {
17121713
}
17131714
int status = kernel->compileFastPath();
17141715
if (status != VISA_SUCCESS) {
1715-
stopTimer(TimerID::TOTAL);
1716-
if (status == VISA_EARLY_EXIT)
1717-
// Consider early exit to still be a success as test run
1718-
// lines may check exit status.
1719-
status = VISA_SUCCESS;
1720-
return status;
1716+
if (status == VISA_EARLY_EXIT) {
1717+
// Consider stackcall or muti-kernel cases, need to continue
1718+
// to compile next one until the last one.
1719+
hasEarlyExit = true;
1720+
continue;
1721+
} else {
1722+
stopTimer(TimerID::TOTAL);
1723+
return status;
1724+
}
17211725
}
1726+
17221727
if (kernel->getIsPayload()) {
17231728
// Remove payload live-outs from the kernel after the compilation since
17241729
// they will not be outputs anymore after stitching.
@@ -1733,6 +1738,14 @@ int CISA_IR_Builder::Compile(const char *isaasmFileName, bool emit_visa_only) {
17331738
}
17341739
}
17351740
}
1741+
1742+
if (hasEarlyExit) {
1743+
// Consider early exit to still be a success as test run
1744+
// lines may check exit status.
1745+
status = VISA_SUCCESS;
1746+
return status;
1747+
}
1748+
17361749
// Here we change the payload section as the main kernel in
17371750
// m_kernelsAndFunctions During stitching, all functions will be cloned and
17381751
// stitched to the main kernel. Demoting the shader body to a function type

visa/G4_Kernel.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,15 @@ unsigned StackCallABI::getNumCalleeSaveRegs() const {
843843
uint32_t StackCallABI::numReservedABIGRF() const {
844844
if (version == StackCallABIVersion::VER_1)
845845
return 3;
846-
else {
847-
// for ABI version > 1,
846+
else if (version == StackCallABIVersion::VER_2) {
848847
if (kernel->getOption(vISA_PreserveR0InR0))
849848
return 2;
850849
return 3;
851850
}
851+
else {
852+
// for ABI version > 2
853+
return 1;
854+
}
852855
}
853856

854857
uint32_t StackCallABI::getFPSPGRF() const {
@@ -862,11 +865,14 @@ uint32_t StackCallABI::getFPSPGRF() const {
862865

863866
uint32_t StackCallABI::getSpillHeaderGRF() const {
864867
// For ABI V1 return r126.
865-
// For ABI V2, V3 return r126.
868+
// For ABI V2 return r126.
869+
// For ABI V3 return r127.
866870
if (version == StackCallABIVersion::VER_1)
867871
return getStackCallStartReg() + SpillHeaderGRF;
868-
else
872+
else if (version == StackCallABIVersion::VER_2)
869873
return (kernel->getNumRegTotal() - 1) - SpillHeaderGRF;
874+
else
875+
return kernel->stackCall.getFPSPGRF();
870876
}
871877

872878
uint32_t StackCallABI::getThreadHeaderGRF() const {

visa/G4_Kernel.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class StackCallABI {
284284
// Class contains sub-regs for chosen ABI version.
285285
// Values are initialized by ctor. For eg,
286286
// As per ABI v1, v2 BE_FP is in sub-reg 3 whereas
287-
// as per ABI v3, BE_FP is in sub-reg 6.
287+
// as per ABI v3, BE_FP is in sub-reg 0.
288288
struct SubRegs_Stackcall {
289289
unsigned int Ret_IP = 0;
290290
unsigned int Ret_EM = 0;
@@ -330,10 +330,10 @@ class StackCallABI {
330330
static constexpr unsigned int SubRegs_Stackcall_v1_v2_FE_SP = 3; // :uq
331331

332332
// For VISA ABI v3
333-
static constexpr unsigned int SubRegs_Stackcall_v3_Ret_IP = 0; // :uq
334-
static constexpr unsigned int SubRegs_Stackcall_v3_Ret_EM = 2; // :ud
335-
static constexpr unsigned int SubRegs_Stackcall_v3_BE_SP = 4; // :ud
336-
static constexpr unsigned int SubRegs_Stackcall_v3_BE_FP = 6; // :ud
333+
static constexpr unsigned int SubRegs_Stackcall_v3_BE_FP = 0; // :ud
334+
static constexpr unsigned int SubRegs_Stackcall_v3_BE_SP = 2; // :ud
335+
static constexpr unsigned int SubRegs_Stackcall_v3_Ret_IP = 4; // :ud
336+
static constexpr unsigned int SubRegs_Stackcall_v3_Ret_EM = 6; // :ud
337337
static constexpr unsigned int SubRegs_Stackcall_v3_FE_FP = 4; // :uq
338338
static constexpr unsigned int SubRegs_Stackcall_v3_FE_SP = 5; // :uq
339339

@@ -365,7 +365,7 @@ class StackCallABI {
365365
static constexpr unsigned int FrameDescriptorOfsets_v3_FE_SP =
366366
SubRegs_Stackcall_v3_FE_SP * 8;
367367
static constexpr unsigned int FrameDescriptorOfsets_v3_Ret_IP =
368-
SubRegs_Stackcall_v3_Ret_IP * 8;
368+
SubRegs_Stackcall_v3_Ret_IP * 4;
369369
static constexpr unsigned int FrameDescriptorOfsets_v3_Ret_EM =
370370
SubRegs_Stackcall_v3_Ret_EM * 4;
371371
static constexpr unsigned int FrameDescriptorOfsets_v3_BE_FP =

visa/GraphColor.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7893,15 +7893,19 @@ void GlobalRA::addStoreRestoreToReturn() {
78937893
G4_Operand *oldFPSrc =
78947894
builder.createSrc(oldFPDcl->getRegVar(), 0, 0, rd, Type_UD);
78957895

7896-
auto SRDecl =
7897-
builder.createHardwiredDeclare(size, Type_UD, kernel.stackCall.getFPSPGRF(),
7898-
kernel.stackCall.subRegs.Ret_IP);
7899-
addVarToRA(SRDecl);
7900-
SRDecl->setName(builder.getNameString(24, "SR_BEStack"));
7896+
unsigned saveRestoreSubReg =
7897+
kernel.stackCall.getVersion() == StackCallABI::StackCallABIVersion::VER_3
7898+
? kernel.stackCall.subRegs.BE_FP
7899+
: kernel.stackCall.subRegs.Ret_IP;
7900+
auto saveRestoreDecl = builder.createHardwiredDeclare(
7901+
size, Type_UD, kernel.stackCall.getFPSPGRF(), saveRestoreSubReg);
7902+
addVarToRA(saveRestoreDecl);
7903+
saveRestoreDecl->setName(builder.getNameString(24, "SR_BEStack"));
79017904
G4_DstRegRegion *FPdst =
7902-
builder.createDst(SRDecl->getRegVar(), 0, 0, 1, Type_UD);
7905+
builder.createDst(saveRestoreDecl->getRegVar(), 0, 0, 1, Type_UD);
79037906
rd = builder.getRegionStride1();
7904-
G4_Operand *FPsrc = builder.createSrc(SRDecl->getRegVar(), 0, 0, rd, Type_UD);
7907+
G4_Operand *FPsrc =
7908+
builder.createSrc(saveRestoreDecl->getRegVar(), 0, 0, rd, Type_UD);
79057909

79067910
saveBE_FPInst = builder.createMov(size == 4 ? g4::SIMD4 : g4::SIMD8, oldFPDst,
79077911
FPsrc, InstOpt_WriteEnable, false);

visa/RegAlloc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ void FlowGraph::setABIForStackCallFunctionCalls() {
21072107
const char *n = builder->getNameString(25, "FCALL_RET_LOC_%d", call_id++);
21082108

21092109
G4_INST *fcall = bb->back();
2110-
// Set call dst to r125.0
2110+
// Set call dst to fpspGRF
21112111
G4_Declare *r1_dst = builder->createDeclare(
21122112
n, G4_GRF, builder->numEltPerGRF<Type_UD>(), 1, Type_UD);
21132113
r1_dst->getRegVar()->setPhyReg(
@@ -2864,7 +2864,9 @@ void GlobalRA::verifySpillFill() {
28642864

28652865
static void replaceSSO(G4_Kernel &kernel) {
28662866
// Invoke function only for XeHP_SDV and later
2867-
// Replace SSO with r126.7 (scratch reg)
2867+
// Replace SSO with r126.7:ud (scratch reg) up to VISA ABI v2
2868+
if (!kernel.fg.builder->getSpillSurfaceOffset())
2869+
return;
28682870

28692871
auto dst = kernel.fg.builder->createDst(
28702872
kernel.fg.getScratchRegDcl()->getRegVar(), 0, 7, 1, Type_UD);

0 commit comments

Comments
 (0)