From: Chandler Carruth Date: Wed, 24 Sep 2014 03:06:37 +0000 (+0000) Subject: [x86] More refactoring of the shuffle comment emission. The previous X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f00b50b6efb368a24ad54e1f15504d77306035f8;p=oota-llvm.git [x86] More refactoring of the shuffle comment emission. The previous attempt didn't work out so well. It looks like it will be much better for introducing extra logic to find a shuffle mask if the finding logic is totally separate. This also makes it easy to sink the opcode logic completely out of the routine so we don't re-dispatch across it. Still no functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218363 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86MCInstLower.cpp b/lib/Target/X86/X86MCInstLower.cpp index 3c5c3c9127c..f01e86cf366 100644 --- a/lib/Target/X86/X86MCInstLower.cpp +++ b/lib/Target/X86/X86MCInstLower.cpp @@ -864,49 +864,33 @@ PrevCrossBBInst(MachineBasicBlock::const_iterator MBBI) { return --MBBI; } -static std::string getShuffleComment(int Opcode, const MachineOperand &DstOp, - const MachineOperand &SrcOp, - const MachineOperand &MaskOp, - ArrayRef Constants) { - std::string Comment; - SmallVector Mask; - +static const Constant *getShuffleMaskConstant(const MachineInstr &MI, + const MachineOperand &DstOp, + const MachineOperand &SrcOp, + const MachineOperand &MaskOp) { if (!MaskOp.isCPI()) - return Comment; + return nullptr; + ArrayRef Constants = + MI.getParent()->getParent()->getConstantPool()->getConstants(); const MachineConstantPoolEntry &MaskConstantEntry = Constants[MaskOp.getIndex()]; // Bail if this is a machine constant pool entry, we won't be able to dig out // anything useful. if (MaskConstantEntry.isMachineConstantPoolEntry()) - return Comment; + return nullptr; auto *C = dyn_cast(MaskConstantEntry.Val.ConstVal); - if (!C) - return Comment; - - assert(MaskConstantEntry.getType() == C->getType() && + assert((!C || MaskConstantEntry.getType() == C->getType()) && "Expected a constant of the same type!"); + return C; +} - switch (Opcode) { - case X86::PSHUFBrm: - case X86::VPSHUFBrm: - DecodePSHUFBMask(C, Mask); - break; - case X86::VPERMILPSrm: - case X86::VPERMILPDrm: - case X86::VPERMILPSYrm: - case X86::VPERMILPDYrm: - DecodeVPERMILPMask(C, Mask); - break; - } - - if (Mask.empty()) - return Comment; - - assert(Mask.size() == C->getType()->getVectorNumElements() && - "Shuffle mask has a different size than its type!"); +static std::string getShuffleComment(const MachineOperand &DstOp, + const MachineOperand &SrcOp, + ArrayRef 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 @@ -1116,25 +1100,41 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { // a constant shuffle mask. We won't be able to do this at the MC layer // because the mask isn't an immediate. case X86::PSHUFBrm: - case X86::VPSHUFBrm: + case X86::VPSHUFBrm: { + if (!OutStreamer.isVerboseAsm()) + break; + assert(MI->getNumOperands() > 5 && + "We should always have at least 5 operands!"); + const MachineOperand &DstOp = MI->getOperand(0); + const MachineOperand &SrcOp = MI->getOperand(1); + const MachineOperand &MaskOp = MI->getOperand(5); + + if (auto *C = getShuffleMaskConstant(*MI, DstOp, SrcOp, MaskOp)) { + SmallVector Mask; + DecodePSHUFBMask(C, Mask); + if (!Mask.empty()) + OutStreamer.AddComment(getShuffleComment(DstOp, SrcOp, Mask)); + } + break; + } case X86::VPERMILPSrm: case X86::VPERMILPDrm: case X86::VPERMILPSYrm: case X86::VPERMILPDYrm: { if (!OutStreamer.isVerboseAsm()) break; - // All of these instructions accept a constant pool operand as their fifth. assert(MI->getNumOperands() > 5 && "We should always have at least 5 operands!"); const MachineOperand &DstOp = MI->getOperand(0); const MachineOperand &SrcOp = MI->getOperand(1); const MachineOperand &MaskOp = MI->getOperand(5); - std::string Comment = getShuffleComment( - MI->getOpcode(), DstOp, SrcOp, MaskOp, - MI->getParent()->getParent()->getConstantPool()->getConstants()); - if (!Comment.empty()) - OutStreamer.AddComment(Comment); + if (auto *C = getShuffleMaskConstant(*MI, DstOp, SrcOp, MaskOp)) { + SmallVector Mask; + DecodeVPERMILPMask(C, Mask); + if (!Mask.empty()) + OutStreamer.AddComment(getShuffleComment(DstOp, SrcOp, Mask)); + } break; } }