Skip to content

Commit de9a873

Browse files
committed
[X86] Split up getShuffleComment into printShuffleMask and printDstRegisterName helpers. NFC.
This will allow us to easily use printDstRegisterName for other mask predicate destination registers, and printout shuffle masks from other instruction types.
1 parent 58f3a77 commit de9a873

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

llvm/lib/Target/X86/X86MCInstLower.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,51 +1412,33 @@ static unsigned getSrcIdx(const MachineInstr* MI, unsigned SrcIdx) {
14121412
return SrcIdx;
14131413
}
14141414

1415-
static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx,
1416-
unsigned SrcOp2Idx, ArrayRef<int> Mask) {
1417-
std::string Comment;
1418-
1419-
// Compute the name for a register. This is really goofy because we have
1420-
// multiple instruction printers that could (in theory) use different
1421-
// names. Fortunately most people use the ATT style (outside of Windows)
1422-
// and they actually agree on register naming here. Ultimately, this is
1423-
// a comment, and so its OK if it isn't perfect.
1424-
auto GetRegisterName = [](MCRegister Reg) -> StringRef {
1425-
return X86ATTInstPrinter::getRegisterName(Reg);
1426-
};
1427-
1415+
static void printDstRegisterName(raw_ostream &CS, const MachineInstr *MI,
1416+
unsigned SrcOpIdx) {
14281417
const MachineOperand &DstOp = MI->getOperand(0);
1429-
const MachineOperand &SrcOp1 = MI->getOperand(SrcOp1Idx);
1430-
const MachineOperand &SrcOp2 = MI->getOperand(SrcOp2Idx);
1431-
1432-
StringRef DstName = DstOp.isReg() ? GetRegisterName(DstOp.getReg()) : "mem";
1433-
StringRef Src1Name =
1434-
SrcOp1.isReg() ? GetRegisterName(SrcOp1.getReg()) : "mem";
1435-
StringRef Src2Name =
1436-
SrcOp2.isReg() ? GetRegisterName(SrcOp2.getReg()) : "mem";
1437-
1438-
// One source operand, fix the mask to print all elements in one span.
1439-
SmallVector<int, 8> ShuffleMask(Mask);
1440-
if (Src1Name == Src2Name)
1441-
for (int i = 0, e = ShuffleMask.size(); i != e; ++i)
1442-
if (ShuffleMask[i] >= e)
1443-
ShuffleMask[i] -= e;
1444-
1445-
raw_string_ostream CS(Comment);
1446-
CS << DstName;
1418+
CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg());
14471419

14481420
// Handle AVX512 MASK/MASXZ write mask comments.
14491421
// MASK: zmmX {%kY}
14501422
// MASKZ: zmmX {%kY} {z}
14511423
if (X86II::isKMasked(MI->getDesc().TSFlags)) {
1452-
const MachineOperand &WriteMaskOp = MI->getOperand(SrcOp1Idx - 1);
1453-
CS << " {%" << GetRegisterName(WriteMaskOp.getReg()) << "}";
1424+
const MachineOperand &WriteMaskOp = MI->getOperand(SrcOpIdx - 1);
1425+
CS << " {%";
1426+
CS << X86ATTInstPrinter::getRegisterName(WriteMaskOp.getReg());
1427+
CS << "}";
14541428
if (!X86II::isKMergeMasked(MI->getDesc().TSFlags)) {
14551429
CS << " {z}";
14561430
}
14571431
}
1432+
}
14581433

1459-
CS << " = ";
1434+
static void printShuffleMask(raw_ostream &CS, StringRef Src1Name,
1435+
StringRef Src2Name, ArrayRef<int> Mask) {
1436+
// One source operand, fix the mask to print all elements in one span.
1437+
SmallVector<int, 8> ShuffleMask(Mask);
1438+
if (Src1Name == Src2Name)
1439+
for (int i = 0, e = ShuffleMask.size(); i != e; ++i)
1440+
if (ShuffleMask[i] >= e)
1441+
ShuffleMask[i] -= e;
14601442

14611443
for (int i = 0, e = ShuffleMask.size(); i != e; ++i) {
14621444
if (i != 0)
@@ -1487,6 +1469,25 @@ static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx,
14871469
CS << ']';
14881470
--i; // For loop increments element #.
14891471
}
1472+
}
1473+
1474+
static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx,
1475+
unsigned SrcOp2Idx, ArrayRef<int> Mask) {
1476+
std::string Comment;
1477+
1478+
const MachineOperand &SrcOp1 = MI->getOperand(SrcOp1Idx);
1479+
const MachineOperand &SrcOp2 = MI->getOperand(SrcOp2Idx);
1480+
StringRef Src1Name = SrcOp1.isReg()
1481+
? X86ATTInstPrinter::getRegisterName(SrcOp1.getReg())
1482+
: "mem";
1483+
StringRef Src2Name = SrcOp2.isReg()
1484+
? X86ATTInstPrinter::getRegisterName(SrcOp2.getReg())
1485+
: "mem";
1486+
1487+
raw_string_ostream CS(Comment);
1488+
printDstRegisterName(CS, MI, SrcOp1Idx);
1489+
CS << " = ";
1490+
printShuffleMask(CS, Src1Name, Src2Name, Mask);
14901491
CS.flush();
14911492

14921493
return Comment;

0 commit comments

Comments
 (0)