From cb0ac3d1fbe29e6c0be2a24c56c06a3b26ce0e39 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 26 Sep 2014 17:54:59 +0000 Subject: R600/SI: Partially move operand legalization to post-isel hook. Disable the SGPR usage restriction parts of the DAG legalizeOperands. It now should only be doing immediate folding until it can be replaced later. The real legalization work is now done by the other SIInstrInfo::legalizeOperands llvm-svn: 218531 --- llvm/lib/Target/R600/SIISelLowering.cpp | 66 ++++----------------------------- 1 file changed, 8 insertions(+), 58 deletions(-) (limited to 'llvm/lib/Target/R600/SIISelLowering.cpp') diff --git a/llvm/lib/Target/R600/SIISelLowering.cpp b/llvm/lib/Target/R600/SIISelLowering.cpp index 8a3ab46ad22..417356d800f 100644 --- a/llvm/lib/Target/R600/SIISelLowering.cpp +++ b/llvm/lib/Target/R600/SIISelLowering.cpp @@ -1648,57 +1648,6 @@ bool SITargetLowering::fitsRegClass(SelectionDAG &DAG, const SDValue &Op, return TRI->getRegClass(RegClass)->hasSubClassEq(RC); } -/// \brief Make sure that we don't exeed the number of allowed scalars -void SITargetLowering::ensureSRegLimit(SelectionDAG &DAG, SDValue &Operand, - unsigned RegClass, - bool &ScalarSlotUsed) const { - - if (!isVSrc(RegClass)) - return; - - // First map the operands register class to a destination class - switch (RegClass) { - case AMDGPU::VSrc_32RegClassID: - case AMDGPU::VCSrc_32RegClassID: - RegClass = AMDGPU::VReg_32RegClassID; - break; - case AMDGPU::VSrc_64RegClassID: - case AMDGPU::VCSrc_64RegClassID: - RegClass = AMDGPU::VReg_64RegClassID; - break; - default: - llvm_unreachable("Unknown vsrc reg class"); - } - - // Nothing to do if they fit naturally - if (fitsRegClass(DAG, Operand, RegClass)) - return; - - // If the scalar slot isn't used yet use it now - if (!ScalarSlotUsed) { - ScalarSlotUsed = true; - return; - } - - // This is a conservative aproach. It is possible that we can't determine the - // correct register class and copy too often, but better safe than sorry. - - SDNode *Node; - // We can't use COPY_TO_REGCLASS with FrameIndex arguments. - if (isa(Operand) || - isa(Operand)) { - unsigned Opcode = Operand.getValueType() == MVT::i32 ? - AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64; - Node = DAG.getMachineNode(Opcode, SDLoc(), Operand.getValueType(), - Operand); - } else { - SDValue RC = DAG.getTargetConstant(RegClass, MVT::i32); - Node = DAG.getMachineNode(TargetOpcode::COPY_TO_REGCLASS, SDLoc(), - Operand.getValueType(), Operand, RC); - } - Operand = SDValue(Node, 0); -} - /// \returns true if \p Node's operands are different from the SDValue list /// \p Ops static bool isNodeChanged(const SDNode *Node, const std::vector &Ops) { @@ -1710,8 +1659,9 @@ static bool isNodeChanged(const SDNode *Node, const std::vector &Ops) { return false; } -/// \brief Try to commute instructions and insert copies in order to satisfy the -/// operand constraints. +/// TODO: This needs to be removed. It's current primary purpose is to fold +/// immediates into operands when legal. The legalization parts are redundant +/// with SIInstrInfo::legalizeOperands which is called in a post-isel hook. SDNode *SITargetLowering::legalizeOperands(MachineSDNode *Node, SelectionDAG &DAG) const { // Original encoding (either e32 or e64) @@ -1784,11 +1734,9 @@ SDNode *SITargetLowering::legalizeOperands(MachineSDNode *Node, // Is this a VSrc or SSrc operand? unsigned RegClass = Desc->OpInfo[Op].RegClass; if (isVSrc(RegClass) || isSSrc(RegClass)) { - // Try to fold the immediates - if (!foldImm(Ops[i], Immediate, ScalarSlotUsed)) { - // Folding didn't work, make sure we don't hit the SReg limit. - ensureSRegLimit(DAG, Ops[i], RegClass, ScalarSlotUsed); - } + // Try to fold the immediates. If this ends up with multiple constant bus + // uses, it will be legalized later. + foldImm(Ops[i], Immediate, ScalarSlotUsed); continue; } @@ -1938,6 +1886,8 @@ void SITargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, const SIInstrInfo *TII = static_cast( getTargetMachine().getSubtargetImpl()->getInstrInfo()); + TII->legalizeOperands(MI); + if (TII->isMIMG(MI->getOpcode())) { unsigned VReg = MI->getOperand(0).getReg(); unsigned Writemask = MI->getOperand(1).getImm(); -- cgit v1.2.3