Skip to content

Commit 1df496c

Browse files
weiyu-chenigcbot
authored andcommitted
Refactor operand alignment check
1 parent 330acbf commit 1df496c

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

visa/BuildIR.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,11 @@ class IR_Builder
588588

589589
//
590590
// Check if opnd is or can be made "alignByte"-byte aligned.
591-
// These functions will change the underlying variable's alignment
592-
// (e.g., make a scalar variable GRF-aligned) when possible to satisfy
593-
// the alignment
591+
// It will change the underlying variable's alignment
592+
// (e.g., make a scalar variable GRF-aligned) when possible to satisfy the alignment
594593
bool isOpndAligned(G4_Operand* opnd, int alignByte) const;
595-
bool isOpndAligned(G4_Operand *opnd, unsigned short &offset, int align_byte) const;
594+
// Use this version if you want to know the fixed subreg offset for the operand even if it's not aligned.
595+
std::tuple<bool, uint16_t> isOpndAlignedTo(G4_Operand *opnd, int align_byte) const;
596596

597597
void setIsKernel(bool value) { isKernel = value; }
598598
bool getIsKernel() const { return isKernel; }

visa/BuildIRImpl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ void IR_Builder::bindInputDecl(G4_Declare* dcl, int offset)
164164
}
165165

166166
// check if an operand is aligned to <align_byte>
167-
bool IR_Builder::isOpndAligned(
168-
G4_Operand *opnd, unsigned short &offset, int align_byte) const
167+
std::tuple<bool, uint16_t> IR_Builder::isOpndAlignedTo(
168+
G4_Operand *opnd, int align_byte) const
169169
{
170-
offset = 0;
170+
uint16_t offset = 0;
171171
bool isAligned = true;
172172

173173
switch (opnd->getKind())
@@ -209,7 +209,7 @@ bool IR_Builder::isOpndAligned(
209209
}
210210
if (!isAligned)
211211
{
212-
return isAligned;
212+
return std::make_tuple(isAligned, offset);
213213
}
214214

215215
if (opnd->isDstRegRegion())
@@ -230,7 +230,7 @@ bool IR_Builder::isOpndAligned(
230230
}
231231
if (offset % align_byte != 0)
232232
{
233-
return false;
233+
return std::make_tuple(false, offset);
234234
}
235235
// Only alignment of the top dcl can be changed.
236236
if (dcl && dcl->getRegFile() == G4_GRF)
@@ -355,14 +355,14 @@ bool IR_Builder::isOpndAligned(
355355
default:
356356
break;
357357
}
358-
return isAligned;
358+
return std::make_tuple(isAligned, offset);
359359
}
360360

361361

362362
bool IR_Builder::isOpndAligned(G4_Operand* opnd, int alignByte) const
363363
{
364-
uint16_t offset = 0; // ignored
365-
return isOpndAligned(opnd, offset, alignByte);
364+
auto [isAligned, offset] = isOpndAlignedTo(opnd, alignByte);
365+
return isAligned;
366366
}
367367

368368

visa/HWConformity.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,8 @@ bool HWConformity::fixDstAlignment(INST_LIST_ITER i, G4_BB* bb, G4_Type extype,
15911591
bool dstHFMixModeInst = inst->getDst()->getType() == builder.getMixModeType() && extype == Type_F;
15921592
bool dstNotAlignedToExecType = exec_size > 1 && (dst_elsize * h_stride) < extypesize &&
15931593
!(builder.hasMixMode() && dstHFMixModeInst);
1594-
unsigned short dst_byte_offset;
1595-
builder.isOpndAligned(dst, dst_byte_offset, extypesize);
1594+
1595+
auto [isAligned, dst_byte_offset] = builder.isOpndAlignedTo(dst, extypesize);
15961596
if (!((dst_byte_offset % extypesize == 0) ||
15971597
(byteDst &&
15981598
(dst_byte_offset % extypesize == 1))
@@ -4736,8 +4736,7 @@ void HWConformity::fixSendInst(G4_BB* bb)
47364736
}
47374737
}
47384738

4739-
uint16_t offset = 0;
4740-
if (!builder.isOpndAligned(inst->getDst(), offset, numEltPerGRF(Type_UB)))
4739+
if (!builder.isOpndAligned(inst->getDst(), numEltPerGRF(Type_UB)))
47414740
{
47424741
replaceDst(i, inst->getDst()->getType(), GRFALIGN);
47434742
}

visa/ReduceExecSize.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,8 @@ bool HWConformity::reduceExecSize(INST_LIST_ITER iter, G4_BB* bb)
452452
if (dstRegionSize <= 16)
453453
{
454454
// see if we can make the dst fit in one oword
455-
unsigned short dstOffset = 0;
456-
bool dstOwordAligned = false;
457455
int dstAlign = Round_Up_Pow2(dstRegionSize);
458-
dstOwordAligned = builder.isOpndAligned(dst, dstOffset, dstAlign);
456+
auto [dstOwordAligned, dstOffset] = builder.isOpndAlignedTo(dst, dstAlign);
459457
if (!dstOwordAligned)
460458
{
461459
// If we can align dst to its size, it must fit in one OWord
@@ -467,7 +465,7 @@ bool HWConformity::reduceExecSize(INST_LIST_ITER iter, G4_BB* bb)
467465
// technically if dst and src are both evenly split the instruction is
468466
// still ok, but this case should be rare so we ignore it
469467
G4_DstRegRegion* newDst = insertMovAfter(iter, dst, dst->getType(), bb);
470-
bool alignTmpDst = builder.isOpndAligned(newDst, dstOffset, 16);
468+
bool alignTmpDst = builder.isOpndAligned(newDst, 16);
471469
MUST_BE_TRUE(alignTmpDst, "must be able to oword align tmp dst");
472470
inst->setDest(newDst);
473471
return true;

0 commit comments

Comments
 (0)