diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2024-02-05 14:47:52 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2024-02-05 16:23:15 +0000 |
commit | de9a87301aefda9538eab7fcd563cc6ceec44e0a (patch) | |
tree | 38e1f56d3d76b9ef9c2d7c4db189f930eadb918c | |
parent | 58f3a77efb633d56a48e031240fc8a37ba2b7557 (diff) | |
download | llvm-de9a87301aefda9538eab7fcd563cc6ceec44e0a.zip llvm-de9a87301aefda9538eab7fcd563cc6ceec44e0a.tar.gz llvm-de9a87301aefda9538eab7fcd563cc6ceec44e0a.tar.bz2 |
[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.
-rw-r--r-- | llvm/lib/Target/X86/X86MCInstLower.cpp | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp index aa060de..c3038cc 100644 --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1412,51 +1412,33 @@ static unsigned getSrcIdx(const MachineInstr* MI, unsigned SrcIdx) { return SrcIdx; } -static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx, - unsigned SrcOp2Idx, ArrayRef<int> Mask) { - std::string Comment; - - // Compute the name for a register. This is really goofy because we have - // multiple instruction printers that could (in theory) use different - // names. Fortunately most people use the ATT style (outside of Windows) - // and they actually agree on register naming here. Ultimately, this is - // a comment, and so its OK if it isn't perfect. - auto GetRegisterName = [](MCRegister Reg) -> StringRef { - return X86ATTInstPrinter::getRegisterName(Reg); - }; - +static void printDstRegisterName(raw_ostream &CS, const MachineInstr *MI, + unsigned SrcOpIdx) { const MachineOperand &DstOp = MI->getOperand(0); - const MachineOperand &SrcOp1 = MI->getOperand(SrcOp1Idx); - const MachineOperand &SrcOp2 = MI->getOperand(SrcOp2Idx); - - StringRef DstName = DstOp.isReg() ? GetRegisterName(DstOp.getReg()) : "mem"; - StringRef Src1Name = - SrcOp1.isReg() ? GetRegisterName(SrcOp1.getReg()) : "mem"; - StringRef Src2Name = - SrcOp2.isReg() ? GetRegisterName(SrcOp2.getReg()) : "mem"; - - // One source operand, fix the mask to print all elements in one span. - SmallVector<int, 8> ShuffleMask(Mask); - if (Src1Name == Src2Name) - for (int i = 0, e = ShuffleMask.size(); i != e; ++i) - if (ShuffleMask[i] >= e) - ShuffleMask[i] -= e; - - raw_string_ostream CS(Comment); - CS << DstName; + CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg()); // Handle AVX512 MASK/MASXZ write mask comments. // MASK: zmmX {%kY} // MASKZ: zmmX {%kY} {z} if (X86II::isKMasked(MI->getDesc().TSFlags)) { - const MachineOperand &WriteMaskOp = MI->getOperand(SrcOp1Idx - 1); - CS << " {%" << GetRegisterName(WriteMaskOp.getReg()) << "}"; + const MachineOperand &WriteMaskOp = MI->getOperand(SrcOpIdx - 1); + CS << " {%"; + CS << X86ATTInstPrinter::getRegisterName(WriteMaskOp.getReg()); + CS << "}"; if (!X86II::isKMergeMasked(MI->getDesc().TSFlags)) { CS << " {z}"; } } +} - CS << " = "; +static void printShuffleMask(raw_ostream &CS, StringRef Src1Name, + StringRef Src2Name, ArrayRef<int> Mask) { + // One source operand, fix the mask to print all elements in one span. + SmallVector<int, 8> ShuffleMask(Mask); + if (Src1Name == Src2Name) + for (int i = 0, e = ShuffleMask.size(); i != e; ++i) + if (ShuffleMask[i] >= e) + ShuffleMask[i] -= e; for (int i = 0, e = ShuffleMask.size(); i != e; ++i) { if (i != 0) @@ -1487,6 +1469,25 @@ static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx, CS << ']'; --i; // For loop increments element #. } +} + +static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx, + unsigned SrcOp2Idx, ArrayRef<int> Mask) { + std::string Comment; + + const MachineOperand &SrcOp1 = MI->getOperand(SrcOp1Idx); + const MachineOperand &SrcOp2 = MI->getOperand(SrcOp2Idx); + StringRef Src1Name = SrcOp1.isReg() + ? X86ATTInstPrinter::getRegisterName(SrcOp1.getReg()) + : "mem"; + StringRef Src2Name = SrcOp2.isReg() + ? X86ATTInstPrinter::getRegisterName(SrcOp2.getReg()) + : "mem"; + + raw_string_ostream CS(Comment); + printDstRegisterName(CS, MI, SrcOp1Idx); + CS << " = "; + printShuffleMask(CS, Src1Name, Src2Name, Mask); CS.flush(); return Comment; |