|
LLVM
5.0.0
|
Copies from VGPR to SGPR registers are illegal and the register coalescer will sometimes generate these illegal copies in situations like this: More...
#include "AMDGPU.h"#include "AMDGPUSubtarget.h"#include "SIInstrInfo.h"#include "llvm/ADT/DenseSet.h"#include "llvm/CodeGen/MachineDominators.h"#include "llvm/CodeGen/MachineFunctionPass.h"#include "llvm/CodeGen/MachineInstrBuilder.h"#include "llvm/CodeGen/MachineRegisterInfo.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Target/TargetMachine.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "si-fix-sgpr-copies" |
Variables | |
| static cl::opt< bool > | EnableM0Merge ("amdgpu-enable-merge-m0", cl::desc("Merge and hoist M0 initializations"), cl::init(false)) |
| DEBUG_TYPE | |
| SI Fix SGPR | copies |
| SI Fix SGPR | false |
Copies from VGPR to SGPR registers are illegal and the register coalescer will sometimes generate these illegal copies in situations like this:
Register Class <vsrc> is the union of <vgpr> and <sgpr>
BB0: vreg0 <sgpr> = SCALAR_INST vreg1 <vsrc> = COPY vreg0 <sgpr> ... BRANCH cond BB1, BB2 BB1: vreg2 <vgpr> = VECTOR_INST vreg3 <vsrc> = COPY vreg2 <vgpr> BB2: vreg4 <vsrc> = PHI vreg1 <vsrc>, <BB#0>, vreg3 <vrsc>, <BB#1> vreg5 <vgpr> = VECTOR_INST vreg4 <vsrc>
The coalescer will begin at BB0 and eliminate its copy, then the resulting code will look like this:
BB0: vreg0 <sgpr> = SCALAR_INST ... BRANCH cond BB1, BB2 BB1: vreg2 <vgpr> = VECTOR_INST vreg3 <vsrc> = COPY vreg2 <vgpr> BB2: vreg4 <sgpr> = PHI vreg0 <sgpr>, <BB#0>, vreg3 <vsrc>, <BB#1> vreg5 <vgpr> = VECTOR_INST vreg4 <sgpr>
Now that the result of the PHI instruction is an SGPR, the register allocator is now forced to constrain the register class of vreg3 to <sgpr> so we end up with final code like this:
BB0: vreg0 <sgpr> = SCALAR_INST ... BRANCH cond BB1, BB2 BB1: vreg2 <vgpr> = VECTOR_INST vreg3 <sgpr> = COPY vreg2 <vgpr> BB2: vreg4 <sgpr> = PHI vreg0 <sgpr>, <BB#0>, vreg3 <sgpr>, <BB#1> vreg5 <vgpr> = VECTOR_INST vreg4 <sgpr>
Now this code contains an illegal copy from a VGPR to an SGPR.
In order to avoid this problem, this pass searches for PHI instructions which define a <vsrc> register and constrains its definition class to <vgpr> if the user of the PHI's definition register is a vector instruction. If the PHI's definition class is constrained to <vgpr> then the coalescer will be unable to perform the COPY removal from the above example which ultimately led to the creation of an illegal COPY.
Definition in file SIFixSGPRCopies.cpp.
| #define DEBUG_TYPE "si-fix-sgpr-copies" |
Definition at line 82 of file SIFixSGPRCopies.cpp.
|
static |
Definition at line 215 of file SIFixSGPRCopies.cpp.
References llvm::ARM_AM::add, assert(), llvm::BuildMI(), llvm::MachineRegisterInfo::createVirtualRegister(), llvm::MachineInstr::eraseFromParent(), getCopyRegClasses(), llvm::MachineInstr::getDebugLoc(), llvm::SIRegisterInfo::getEquivalentVGPRClass(), llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineOperand::getSubReg(), llvm::SIRegisterInfo::getSubRegClass(), llvm::MachineRegisterInfo::hasOneUse(), I, llvm::MachineInstr::isCopy(), llvm::TargetRegisterInfo::isPhysicalRegister(), llvm::MachineInstr::isRegSequence(), llvm::SIRegisterInfo::isSGPRClass(), isSGPRToVGPRCopy(), MI, N, llvm::MachineOperand::setReg(), llvm::MachineRegisterInfo::setRegClass(), SubReg, tryChangeVGPRtoSGPRinCopy(), and llvm::MachineRegisterInfo::use_instr_begin().
|
static |
Definition at line 143 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getOperand(), llvm::SIRegisterInfo::getPhysRegClass(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), and llvm::TargetRegisterInfo::isVirtualRegister().
Referenced by foldVGPRCopyIntoRegSequence().
|
static |
Definition at line 325 of file SIFixSGPRCopies.cpp.
References E, llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getFirstTerminator(), and I.
Referenced by predsHasDivergentTerminator().
|
static |
Definition at line 129 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getParent(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineFunction::getRegInfo(), llvm::SIRegisterInfo::hasVGPRs(), llvm::MachineOperand::isReg(), llvm::TargetRegisterInfo::isVirtualRegister(), and MRI.
|
static |
Definition at line 429 of file SIFixSGPRCopies.cpp.
References llvm::any_of(), assert(), C, llvm::MachineRegisterInfo::clearKillFlags(), llvm::dbgs(), DEBUG, llvm::MachineRegisterInfo::def_instructions(), llvm::MachineDominatorTree::dominates(), E, llvm::MachineInstr::eraseFromParent(), llvm::MachineDominatorTree::findNearestCommonDominator(), llvm::MachineOperand::getImm(), llvm::MachineBasicBlock::getNumber(), llvm::MachineInstr::getParent(), llvm::MachineBasicBlock::getParent(), I, isReachable(), MI, llvm::MachineDominatorTree::properlyDominates(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
| INITIALIZE_PASS_BEGIN | ( | SIFixSGPRCopies | , |
| DEBUG_TYPE | , | ||
| "SI Fix SGPR copies" | , | ||
| false | , | ||
| false | |||
| ) |
|
static |
Definition at line 404 of file SIFixSGPRCopies.cpp.
References llvm::MachineDominatorTree::dominates(), llvm::MachineInstr::getParent(), and searchPredecessors().
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 335 of file SIFixSGPRCopies.cpp.
References llvm::MachineOperand::getImm(), llvm::SIInstrInfo::getNamedOperand(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getSubReg(), llvm::MachineOperand::isImm(), and llvm::MachineInstr::isMoveImmediate().
|
static |
Definition at line 171 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::hasVGPRs(), and llvm::SIRegisterInfo::isSGPRClass().
Referenced by foldVGPRCopyIntoRegSequence().
|
static |
Definition at line 165 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::hasVGPRs(), and llvm::SIRegisterInfo::isSGPRClass().
|
static |
Definition at line 298 of file SIFixSGPRCopies.cpp.
References llvm::SmallSet< T, N, C >::count(), llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getVRegDef(), and llvm::SmallSet< T, N, C >::insert().
|
static |
Definition at line 286 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), and llvm::SIRegisterInfo::hasVGPRs().
|
static |
Definition at line 395 of file SIFixSGPRCopies.cpp.
References hasTerminatorThatModifiesExec(), and searchPredecessors().
| bool searchPredecessors | ( | const MachineBasicBlock * | MBB, |
| const MachineBasicBlock * | CutOff, | ||
| UnaryPredicate | Predicate | ||
| ) |
Definition at line 368 of file SIFixSGPRCopies.cpp.
References llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), llvm::MachineBasicBlock::pred_begin(), and llvm::MachineBasicBlock::pred_end().
Referenced by isReachable(), and predsHasDivergentTerminator().
|
static |
Definition at line 177 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::getEquivalentSGPRClass(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getOperandNo(), llvm::MachineInstr::getParent(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineFunction::getRegInfo(), llvm::SIInstrInfo::isOperandLegal(), llvm::TargetRegisterInfo::isVirtualRegister(), MRI, llvm::MachineRegisterInfo::reg_nodbg_operands(), llvm::MachineRegisterInfo::setRegClass(), and UseMI.
Referenced by foldVGPRCopyIntoRegSequence().
Definition at line 117 of file SIFixSGPRCopies.cpp.
| DEBUG_TYPE |
Definition at line 117 of file SIFixSGPRCopies.cpp.
|
static |
Definition at line 117 of file SIFixSGPRCopies.cpp.
1.8.6