Skip to content

Commit 5f07238

Browse files
pratikasharsys_zuul
authored andcommitted
[Autobackout][FuncReg]Revert of change: c8743fb
Implementation of VISA stack call ABI in generated code. Also update VISA debug info as per ABI. Change-Id: Icc5098d3764d269daad04045352f2c4b773d737e
1 parent a6191f1 commit 5f07238

File tree

9 files changed

+131
-270
lines changed

9 files changed

+131
-270
lines changed

visa/BuildIR.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,6 @@ class IR_Builder
372372
// function call related declares
373373
G4_Declare* be_sp = nullptr;
374374
G4_Declare* be_fp = nullptr;
375-
// Part FDE inst is the move that stores r125.[0-3] to a temp.
376-
// This is used to restore ret %ip, ret EM, and BE ptrs.
377-
G4_INST* savePartFDInst = nullptr;
378-
// FDE spill inst is first spill instruction that writes frame
379-
// descriptor to stack.
380-
G4_INST* FDSpillInst = nullptr;
381375
G4_Declare* tmpFCRet = nullptr;
382376

383377
unsigned short arg_size;
@@ -488,23 +482,12 @@ class IR_Builder
488482

489483
const USE_DEF_ALLOCATOR& getAllocator() const { return useDefAllocator; }
490484

491-
// Following enum describes layout of r125 on entry to a function.
492-
// Ret_IP and Ret_EM may be altered due to callees. They'll be
493-
// restored right before fret.
494-
enum SubRegs_Stackcall
485+
enum SubRegs_SP_FP
495486
{
496-
Ret_IP = 0, // :ud
497-
Ret_EM = 1, // :ud
498-
BE_SP = 2, // :ud
499-
BE_FP = 3, // :ud
500-
FE_FP = 2, // :uq
501-
FE_SP = 3, // :uq
502-
};
503-
504-
enum ArgRet_Stackcall
505-
{
506-
Arg = 28,
507-
Ret = 28
487+
FE_SP = 0, // Can be either :ud or :uq
488+
FE_FP = 1, // Can be either :ud or :uq
489+
BE_SP = 6, // :ud
490+
BE_FP = 7 // :ud
508491
};
509492

510493
// Getter/setter for be_sp and be_fp
@@ -513,7 +496,7 @@ class IR_Builder
513496
if (be_sp == NULL)
514497
{
515498
be_sp = createDeclareNoLookup("be_sp", G4_GRF, 1, 1, Type_UD);
516-
be_sp->getRegVar()->setPhyReg(phyregpool.getGreg(kernel.getFPSPGRF()), SubRegs_Stackcall::BE_SP);
499+
be_sp->getRegVar()->setPhyReg(phyregpool.getGreg(kernel.getFPSPGRF()), SubRegs_SP_FP::BE_SP);
517500
}
518501

519502
return be_sp;
@@ -524,18 +507,12 @@ class IR_Builder
524507
if (be_fp == NULL)
525508
{
526509
be_fp = createDeclareNoLookup("be_fp", G4_GRF, 1, 1, Type_UD);
527-
be_fp->getRegVar()->setPhyReg(phyregpool.getGreg(kernel.getFPSPGRF()), SubRegs_Stackcall::BE_FP);
510+
be_fp->getRegVar()->setPhyReg(phyregpool.getGreg(kernel.getFPSPGRF()), SubRegs_SP_FP::BE_FP);
528511
}
529512

530513
return be_fp;
531514
}
532515

533-
G4_INST* getPartFDSaveInst() const { return savePartFDInst; }
534-
void setPartFDSaveInst(G4_INST* i) { savePartFDInst = i; }
535-
536-
G4_INST* getFDSpillInst() const { return FDSpillInst; }
537-
void setFDSpillInst(G4_INST* i) { FDSpillInst = i; }
538-
539516
G4_Declare* getStackCallArg() const {
540517
return preDefVars.getPreDefinedVar(PreDefinedVarsInternal::ARG);
541518
}

visa/BuildIRImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,29 +626,29 @@ void IR_Builder::createPreDefinedVars()
626626
case PreDefinedVarsInternal::ARG:
627627
{
628628
dcl = createDeclareNoLookup(name, G4_INPUT, numEltPerGRF(Type_UD), 32, Type_UD);
629-
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(ArgRet_Stackcall::Arg), 0);
629+
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(28), 0);
630630
break;
631631
}
632632
case PreDefinedVarsInternal::RET:
633633
{
634634
dcl = createDeclareNoLookup(name, G4_GRF, numEltPerGRF(Type_UD), 12, Type_UD);
635-
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(ArgRet_Stackcall::Ret), 0);
635+
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(16), 0);
636636
dcl->setLiveOut();
637637
break;
638638
}
639639
case PreDefinedVarsInternal::FE_SP:
640640
{
641641
unsigned int startReg = kernel.getFPSPGRF();
642642
dcl = createDeclareNoLookup(name, G4_GRF, 1, 1, Type_UQ);
643-
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(startReg), SubRegs_Stackcall::FE_SP);
643+
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(startReg), SubRegs_SP_FP::FE_SP);
644644
break;
645645
}
646646
case PreDefinedVarsInternal::FE_FP:
647647
{
648648
// PREDEFINED_FE_FP
649649
unsigned int startReg = kernel.getFPSPGRF();
650650
dcl = createDeclareNoLookup(name, G4_GRF, 1, 1, Type_UQ);
651-
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(startReg), SubRegs_Stackcall::FE_FP);
651+
dcl->getRegVar()->setPhyReg(phyregpool.getGreg(startReg), SubRegs_SP_FP::FE_FP);
652652
break;
653653
}
654654
case PreDefinedVarsInternal::HW_TID:

visa/DebugInfo.cpp

Lines changed: 23 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,58 +1053,21 @@ void emitDataVarLiveInterval(VISAKernelImpl* visaKernel, LiveIntervalInfo* lrInf
10531053
}
10541054
}
10551055

1056-
template<class T>
1057-
void emitFrameDescriptorOffsetLiveInterval(LiveIntervalInfo* lrInfo, StackCall::FrameDescriptorOfsets memOffset, T& t)
1058-
{
1059-
// Used to emit fields of Frame Descriptor
1060-
// location = [start, end) @ BE_FP+offset
1061-
std::vector<std::pair<uint32_t, uint32_t>> lrs;
1062-
if (lrInfo)
1063-
lrInfo->getLiveIntervals(lrs);
1064-
else
1065-
return;
1066-
1067-
uint32_t start = 0, end = 0;
1068-
if (lrs.size() > 0)
1069-
{
1070-
start = lrs.front().first;
1071-
end = lrs.back().second;
1072-
}
1073-
1074-
std::sort(lrs.begin(), lrs.end(), [](std::pair<uint32_t, uint32_t>& a, std::pair<uint32_t, uint32_t>& b) { return a.first < b.first; });
1075-
1076-
emitDataUInt16(1, t);
1077-
1078-
emitDataUInt32(start, t);
1079-
emitDataUInt32(end, t);
1080-
1081-
emitDataUInt8((uint8_t)VARMAP_PREG_FILE_GRF, t);
1082-
1083-
emitDataUInt8((uint8_t)VARMAP_PREG_FILE_MEMORY, t);
1084-
1085-
emitDataUInt32((uint32_t)memOffset, t);
1086-
}
1087-
10881056
void populateUniqueSubs(G4_Kernel* kernel, std::unordered_map<G4_BB*, bool>& uniqueSubs)
10891057
{
10901058
// Traverse kernel and populate all unique subs.
10911059
// Iterating over all BBs of kernel visits all
10921060
// subroutine call sites.
1093-
auto isStackObj = kernel->fg.getHasStackCalls() || kernel->fg.getIsStackCallFunc();
10941061
for (auto bb : kernel->fg)
10951062
{
10961063
if (&bb->getParent() != &kernel->fg)
10971064
continue;
10981065

1099-
if (bb->isEndWithCall())
1066+
if (bb->isEndWithCall() &&
1067+
!kernel->getKernelDebugInfo()->isFcallWithSaveRestore(bb))
11001068
{
1101-
if (!isStackObj || // definitely a subroutine since kernel has no stack calls
1102-
(isStackObj && // a subroutine iff call dst != pre-defined reg as per ABI
1103-
bb->back()->getDst()->getTopDcl()->getRegVar()->getPhyReg()->asGreg()->getRegNum() != kernel->getFPSPGRF()))
1104-
{
1105-
// This is a subroutine call
1106-
uniqueSubs[bb->Succs.front()] = false;
1107-
}
1069+
// This is a subroutine call
1070+
uniqueSubs[bb->Succs.front()] = false;
11081071
}
11091072
}
11101073
}
@@ -1242,16 +1205,16 @@ void SaveRestoreManager::sieveInstructions(CallerOrCallee c)
12421205
// Remove temp movs emitted for send header
12431206
// creation since they are not technically
12441207
// caller save
1245-
if (entry.first < visaKernel->getKernel()->calleeSaveStart() &&
1246-
entry.first >= 0 &&
1208+
if (entry.first < CALLEE_SAVE_START &&
1209+
entry.first >= CALLER_SAVE_START &&
12471210
entry.second.first == SaveRestoreInfo::RegOrMem::MemOffBEFP)
12481211
{
12491212
removeEntry = false;
12501213
}
12511214
}
12521215
else if (c == CallerOrCallee::Callee)
12531216
{
1254-
if (entry.first >= visaKernel->getKernel()->calleeSaveStart() &&
1217+
if (entry.first >= CALLEE_SAVE_START &&
12551218
entry.second.first == SaveRestoreInfo::RegOrMem::MemOffBEFP)
12561219
{
12571220
removeEntry = false;
@@ -1445,7 +1408,7 @@ void emitDataCallFrameInfo(VISAKernelImpl* visaKernel, T& t)
14451408
if (befpLIInfo)
14461409
{
14471410
emitDataUInt8((uint8_t)1, t);
1448-
uint32_t idx = kernel->getKernelDebugInfo()->getVarIndex(kernel->fg.framePtrDcl);
1411+
uint32_t idx = kernel->getKernelDebugInfo()->getVarIndex(befpDcl);
14491412
emitDataVarLiveInterval(visaKernel, befpLIInfo, idx, sizeof(uint32_t), t);
14501413
}
14511414
else
@@ -1465,8 +1428,8 @@ void emitDataCallFrameInfo(VISAKernelImpl* visaKernel, T& t)
14651428
if (callerfpLIInfo)
14661429
{
14671430
emitDataUInt8((uint8_t)1, t);
1468-
// Caller's be_fp is stored in frame descriptor
1469-
emitFrameDescriptorOffsetLiveInterval(callerfpLIInfo, StackCall::FrameDescriptorOfsets::BE_FP, t);
1431+
uint32_t idx = kernel->getKernelDebugInfo()->getVarIndex(callerfpdcl);
1432+
emitDataVarLiveInterval(visaKernel, callerfpLIInfo, idx, sizeof(uint32_t), t);
14701433
}
14711434
else
14721435
{
@@ -1485,7 +1448,8 @@ void emitDataCallFrameInfo(VISAKernelImpl* visaKernel, T& t)
14851448
if (fretVarLIInfo)
14861449
{
14871450
emitDataUInt8((uint8_t)1, t);
1488-
emitFrameDescriptorOffsetLiveInterval(fretVarLIInfo, StackCall::FrameDescriptorOfsets::Ret_IP, t);
1451+
uint32_t idx = kernel->getKernelDebugInfo()->getVarIndex(fretVar);
1452+
emitDataVarLiveInterval(visaKernel, fretVarLIInfo, idx, sizeof(uint32_t), t);
14891453
}
14901454
else
14911455
{
@@ -1970,29 +1934,6 @@ void KernelDebugInfo::computeDebugInfo(std::list<G4_BB*>& stackCallEntryBBs)
19701934
{
19711935
updateCallStackLiveIntervals();
19721936
}
1973-
else
1974-
{
1975-
updateCallStackMain();
1976-
}
1977-
}
1978-
1979-
void KernelDebugInfo::updateCallStackMain()
1980-
{
1981-
if (!getKernel().fg.getHasStackCalls())
1982-
return;
1983-
1984-
// Set live-interval for BE_FP
1985-
auto befp = getBEFP();
1986-
if (befp)
1987-
{
1988-
uint32_t start = 0;
1989-
if (getBEFPSetupInst())
1990-
{
1991-
start = (uint32_t)getBEFPSetupInst()->getGenOffset() +
1992-
(uint32_t)getBinInstSize(getBEFPSetupInst());
1993-
}
1994-
updateDebugInfo(getKernel(), befp, start, mapCISAIndexGenOffset.back().second);
1995-
}
19961937
}
19971938

19981939
void KernelDebugInfo::updateCallStackLiveIntervals()
@@ -2023,30 +1964,24 @@ void KernelDebugInfo::updateCallStackLiveIntervals()
20231964
{
20241965
reloc_offset = (reloc_offset == 0) ?
20251966
(uint32_t)insts->getGenOffset() : reloc_offset;
1967+
}
1968+
1969+
if ((insts->isReturn() || insts->opcode() == G4_jmpi) &&
1970+
insts->getSrc(0)->asSrcRegRegion()->getBase()->asRegVar()->getDeclare()->getRootDeclare()
1971+
== fretVar)
1972+
{
1973+
end = (uint32_t)insts->getGenOffset();
20261974
break;
20271975
}
20281976
}
2029-
if (reloc_offset > 0)
1977+
if (end > 0)
1978+
{
20301979
break;
2031-
}
2032-
2033-
uint32_t start = 0;
2034-
if (getBEFPSetupInst())
2035-
{
2036-
// Frame descriptor can be addressed once once BE_FP is defined
2037-
start = (uint32_t)getBEFPSetupInst()->getGenOffset() +
2038-
getBinInstSize(getBEFPSetupInst());
2039-
}
2040-
2041-
if (getCallerBEFPRestoreInst())
2042-
{
2043-
end = (uint32_t)getCallerBEFPRestoreInst()->getGenOffset();
1980+
}
20441981
}
20451982

20461983
MUST_BE_TRUE(end >= reloc_offset, "Failed to update live-interval for retval");
2047-
MUST_BE_TRUE(start >= reloc_offset, "Failed to update start for retval");
2048-
MUST_BE_TRUE(end >= start, "end less then start for retval");
2049-
for (uint32_t i = start - reloc_offset; i <= end - reloc_offset; i++)
1984+
for (uint32_t i = 0; i <= end - reloc_offset; i++)
20501985
{
20511986
updateDebugInfo(*kernel, fretVar, i);
20521987
}

visa/DebugInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434
#include "GraphColor.h"
3535
#include <unordered_map>
3636

37+
#define CALLER_SAVE_START 1
38+
#define CALLEE_SAVE_START 60
3739
namespace vISA
3840
{
3941
class G4_Declare;
@@ -277,7 +279,6 @@ class KernelDebugInfo
277279
void generateCISAByteOffsetFromOffset();
278280
void updateRelocOffset();
279281
void updateCallStackLiveIntervals();
280-
void updateCallStackMain();
281282
void generateGenISAToVISAIndex();
282283

283284
void computeDebugInfo(std::list<G4_BB*>& stackCallEntryBBs);

0 commit comments

Comments
 (0)