Skip to content

Commit

Permalink
Avoid iteration in updateExpandedIntrinsic
Browse files Browse the repository at this point in the history
Avoid iterating multiple times to find insertion slots for intrinsics.
  • Loading branch information
stefan-il authored and igcbot committed Dec 9, 2024
1 parent 115cf8c commit 5fb4c17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
25 changes: 14 additions & 11 deletions visa/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ void KernelDebugInfo::updateCallStackLiveIntervals() {
}

void KernelDebugInfo::updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill,
G4_INST *inst) {
INST_LIST &insts) {
// This function looks up all caller/callee save code added.
// Once it finds "spillOrFill", it adds inst to it. This is
// because VISA now uses spill/fill intrinsics to model
Expand All @@ -1936,14 +1936,14 @@ void KernelDebugInfo::updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill,
for (auto &k : callerSaveRestore) {
for (auto it = k.second.first.begin(); it != k.second.first.end(); ++it) {
if ((*it) == spillOrFill) {
k.second.first.insert(it, inst);
k.second.first.insert(it, insts.begin(), insts.end());
return;
}
}

for (auto it = k.second.second.begin(); it != k.second.second.end(); ++it) {
if ((*it) == spillOrFill) {
k.second.second.insert(it, inst);
k.second.second.insert(it, insts.begin(), insts.end());
return;
}
}
Expand All @@ -1952,15 +1952,15 @@ void KernelDebugInfo::updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill,
for (auto it = calleeSaveRestore.first.begin();
it != calleeSaveRestore.first.end(); ++it) {
if ((*it) == spillOrFill) {
calleeSaveRestore.first.insert(it, inst);
calleeSaveRestore.first.insert(it, insts.begin(), insts.end());
return;
}
}

for (auto it = calleeSaveRestore.second.begin();
it != calleeSaveRestore.second.end(); ++it) {
if ((*it) == spillOrFill) {
calleeSaveRestore.second.insert(it, inst);
calleeSaveRestore.second.insert(it, insts.begin(), insts.end());
return;
}
}
Expand All @@ -1969,20 +1969,23 @@ void KernelDebugInfo::updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill,
// caller be fp restore is a fill intrinsic that reads from FDE. it is
// expanded to a regular fill instruction. so update the pointer to new
// instruction.
setCallerBEFPRestoreInst(inst);
setCallerBEFPRestoreInst(insts.back());
}

if (spillOrFill == getCallerSPRestoreInst()) {
setCallerSPRestoreInst(inst);
setCallerSPRestoreInst(insts.back());
}

if (spillOrFill == getCallerBEFPSaveInst()) {
setCallerBEFPSaveInst(inst);
setCallerBEFPSaveInst(insts.back());
}

if (spillOrFill == getCESaveInst() &&
inst->isSend()) {
setSaveCEInst(inst);
if (spillOrFill == getCESaveInst()) {
for (auto *inst: insts) {
if (inst->isSend()){
setSaveCEInst(inst);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion visa/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class KernelDebugInfo {
void setCESaveOffset(uint16_t Off) { CEStoreOffset = Off; }
uint16_t getCESaveOffset() const { return CEStoreOffset; }

void updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill, G4_INST *inst);
void updateExpandedIntrinsic(G4_InstIntrinsic *spillOrFill, INST_LIST &insts);
void addCallerSaveInst(G4_BB *fcallBB, G4_INST *inst);
void addCallerRestoreInst(G4_BB *fcallBB, G4_INST *inst);
void addCalleeSaveInst(G4_INST *inst);
Expand Down
28 changes: 10 additions & 18 deletions visa/SpillManagerGMRF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4840,10 +4840,8 @@ void GlobalRA::expandSpillLSC(G4_BB *bb, INST_LIST_ITER &instIt) {
}

if (inst->getFP() && kernel.getOption(vISA_GenerateDebugInfo)) {
for (auto newInst : builder->instList) {
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), newInst);
}
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), builder->instList);
}

// Call WA and NoMask WA are mutual exclusive.
Expand Down Expand Up @@ -4950,10 +4948,8 @@ void GlobalRA::expandScatterSpillLSC(G4_BB *bb, INST_LIST_ITER &instIt) {
payload->getTopDcl()->getName(), builder->getGRFSize()));

if (inst->getFP() && kernel.getOption(vISA_GenerateDebugInfo)) {
for (auto newInst : builder->instList) {
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), newInst);
}
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), builder->instList);
}

splice(bb, instIt, builder->instList, inst->getVISAId());
Expand Down Expand Up @@ -5046,10 +5042,8 @@ void GlobalRA::expandFillLSC(G4_BB *bb, INST_LIST_ITER &instIt) {
}

if (inst->getFP() && kernel.getOption(vISA_GenerateDebugInfo)) {
for (auto newInst : builder->instList) {
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asFillIntrinsic(), newInst);
}
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asFillIntrinsic(), builder->instList);
}

// Call WA and NoMask WA are mutual exclusive.
Expand Down Expand Up @@ -5323,10 +5317,9 @@ void GlobalRA::expandSpillStackcall(uint32_t numRows, uint32_t offset,
}

if (kernel.getOption(vISA_GenerateDebugInfo)) {
INST_LIST expandedInsts = {hdrSetInst, spillSends};
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), hdrSetInst);
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asSpillIntrinsic(), spillSends);
inst->asSpillIntrinsic(), expandedInsts);
}

numRowsOword -= payloadSizeInOwords;
Expand Down Expand Up @@ -5583,10 +5576,9 @@ void GlobalRA::expandFillStackcall(uint32_t numRows, uint32_t offset,
bb->insertBefore(fillIt, fillSends);

if (kernel.getOption(vISA_GenerateDebugInfo)) {
INST_LIST expandedInsts = {hdrSetInst, fillSends};
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asFillIntrinsic(), hdrSetInst);
kernel.getKernelDebugInfo()->updateExpandedIntrinsic(
inst->asFillIntrinsic(), fillSends);
inst->asFillIntrinsic(), expandedInsts);
}

numRowsOword -= respSizeInOwords;
Expand Down

0 comments on commit 5fb4c17

Please sign in to comment.