Skip to content

Commit 42f1fcd

Browse files
aratajewsys_zuul
authored and
sys_zuul
committed
Fix offset calculation for indirect function calls
Change-Id: I71e52dd1928a3b011369237f352cc7ae2881593c
1 parent 60d49f8 commit 42f1fcd

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

visa/VISAKernelImpl.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,44 @@ void VISAKernelImpl::adjustIndirectCallOffset()
256256
{
257257
// for every indirect call, count # of instructions inserted
258258
// between call and the first add
259-
uint32_t num_sync = 0;
259+
uint64_t sync_offset = 0;
260260
G4_INST* first_add = nullptr;
261261
INST_LIST::reverse_iterator it = bb->rbegin();
262262
// skip call itself
263263
++it;
264264
for (; it != bb->rend(); ++it)
265265
{
266266
G4_INST* inst = *it;
267-
if (inst->opcode() == G4_sync_nop) {
268-
++num_sync;
267+
G4_opcode op = inst->opcode();
268+
if (op == G4_sync_allrd || op == G4_sync_allwr)
269+
{
270+
inst->setNoCompacted();
271+
sync_offset += 16;
272+
continue;
273+
}
274+
else if (op == G4_sync_nop) {
275+
inst->setCompacted();
276+
sync_offset += 8;
269277
continue;
270-
} else if (inst->opcode() == G4_add) {
271-
if (first_add == nullptr) {
278+
}
279+
else if (op == G4_add)
280+
{
281+
if (first_add == nullptr)
282+
{
272283
first_add = inst;
273284
continue;
274-
} else {
285+
}
286+
else
287+
{
275288
break;
276289
}
277290
}
278291
// instructions between call and add could only be
279-
// sync.nop
292+
// sync.nop, sync.allrd or sync.allwr
280293
assert(0);
281294
}
282-
// assume that the sync.nop must be compacted, the instruction
283-
// length is 8
284295
assert(first_add->getSrc(1)->isImm());
285-
int64_t adjust_off = first_add->getSrc(1)->asImm()->getInt()
286-
- num_sync * 8;
296+
int64_t adjust_off = first_add->getSrc(1)->asImm()->getInt() - sync_offset;
287297
first_add->setSrc(m_builder->createImm(adjust_off, Type_D), 1);
288298
}
289299
}

0 commit comments

Comments
 (0)