LLVM
8.0.1
|
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 "SIRegisterInfo.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <list>
#include <map>
#include <tuple>
#include <utility>
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: %0 <sgpr> = SCALAR_INST %1 <vsrc> = COPY %0 <sgpr> ... BRANCH cond BB1, BB2 BB1: %2 <vgpr> = VECTOR_INST %3 <vsrc> = COPY %2 <vgpr> BB2: %4 <vsrc> = PHI %1 <vsrc>, <bb.0>, %3 <vrsc>, <bb.1> %5 <vgpr> = VECTOR_INST %4 <vsrc>
The coalescer will begin at BB0 and eliminate its copy, then the resulting code will look like this:
BB0: %0 <sgpr> = SCALAR_INST ... BRANCH cond BB1, BB2 BB1: %2 <vgpr> = VECTOR_INST %3 <vsrc> = COPY %2 <vgpr> BB2: %4 <sgpr> = PHI %0 <sgpr>, <bb.0>, %3 <vsrc>, <bb.1> %5 <vgpr> = VECTOR_INST %4 <sgpr>
Now that the result of the PHI instruction is an SGPR, the register allocator is now forced to constrain the register class of %3 to <sgpr> so we end up with final code like this:
BB0: %0 <sgpr> = SCALAR_INST ... BRANCH cond BB1, BB2 BB1: %2 <vgpr> = VECTOR_INST %3 <sgpr> = COPY %2 <vgpr> BB2: %4 <sgpr> = PHI %0 <sgpr>, <bb.0>, %3 <sgpr>, <bb.1> %5 <vgpr> = VECTOR_INST %4 <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.
Definition at line 102 of file SIFixSGPRCopies.cpp.
|
static |
Definition at line 235 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().
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 161 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getOperand(), llvm::SIRegisterInfo::getPhysRegClass(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), and llvm::TargetRegisterInfo::isVirtualRegister().
Referenced by foldVGPRCopyIntoRegSequence(), and hoistAndMergeSGPRInits().
|
static |
Definition at line 342 of file SIFixSGPRCopies.cpp.
References E, llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getFirstTerminator(), and I.
Referenced by predsHasDivergentTerminator().
|
static |
Definition at line 147 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineFunction::getRegInfo(), llvm::SIRegisterInfo::hasVGPRs(), llvm::MachineOperand::isReg(), llvm::TargetRegisterInfo::isVirtualRegister(), and MRI.
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 447 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::addImplicitDefUseOperands(), llvm::any_of(), assert(), llvm::MachineBasicBlock::begin(), llvm::MachineFunction::begin(), C, llvm::MachineOperand::ChangeToImmediate(), llvm::MachineRegisterInfo::clearKillFlags(), llvm::dbgs(), llvm::MachineRegisterInfo::def_instructions(), DefMI, llvm::MachineDominatorTree::dominates(), E, EnableM0Merge, llvm::MachineBasicBlock::end(), llvm::MachineFunction::end(), llvm::MachineInstr::eraseFromParent(), llvm::MachineDominatorTree::findNearestCommonDominator(), foldVGPRCopyIntoRegSequence(), From, getCopyRegClasses(), llvm::MachineOperand::getImm(), llvm::GCNSubtarget::getInstrInfo(), llvm::MachineOperand::getMBB(), llvm::MachineInstr::getNumExplicitOperands(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::SIInstrInfo::getOpRegClass(), llvm::TargetMachine::getOptLevel(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::MachineFunction::getRegInfo(), llvm::GCNSubtarget::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), llvm::MachineFunction::getTarget(), hasVGPROperands(), llvm::SIRegisterInfo::hasVGPRs(), I, isReachable(), isSafeToFoldImmIntoCopy(), llvm::SIRegisterInfo::isSGPRClass(), isSGPRToVGPRCopy(), isVGPRToSGPRCopy(), llvm::TargetRegisterInfo::isVirtualRegister(), LLVM_DEBUG, MI, llvm::SIInstrInfo::moveToVALU(), MRI, llvm::CodeGenOpt::None, phiHasBreakDef(), phiHasVGPROperands(), predsHasDivergentTerminator(), llvm::printMBBReference(), llvm::MachineDominatorTree::properlyDominates(), llvm::SmallVectorTemplateBase< T >::push_back(), Reg, llvm::MachineInstr::setDesc(), llvm::ARM_MB::ST, TII, TRI, tryChangeVGPRtoSGPRinCopy(), and llvm::SIInstrFlags::WQM.
INITIALIZE_PASS_BEGIN | ( | SIFixSGPRCopies | , |
DEBUG_TYPE | , | ||
"SI Fix SGPR copies" | , | ||
false | , | ||
false | |||
) |
|
static |
Definition at line 422 of file SIFixSGPRCopies.cpp.
References llvm::MachineDominatorTree::dominates(), llvm::MachineInstr::getParent(), and searchPredecessors().
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 352 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().
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 190 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::hasVGPRs(), and llvm::SIRegisterInfo::isSGPRClass().
Referenced by foldVGPRCopyIntoRegSequence(), and hoistAndMergeSGPRInits().
|
static |
Definition at line 183 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::hasVGPRs(), and llvm::SIRegisterInfo::isSGPRClass().
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 318 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(), llvm::SmallSet< T, N, C >::insert(), and Reg.
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 306 of file SIFixSGPRCopies.cpp.
References llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::SIRegisterInfo::hasVGPRs(), and Reg.
Referenced by hoistAndMergeSGPRInits().
|
static |
Definition at line 413 of file SIFixSGPRCopies.cpp.
References hasTerminatorThatModifiesExec(), and searchPredecessors().
Referenced by hoistAndMergeSGPRInits().
bool searchPredecessors | ( | const MachineBasicBlock * | MBB, |
const MachineBasicBlock * | CutOff, | ||
UnaryPredicate | Predicate | ||
) |
Definition at line 387 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 197 of file SIFixSGPRCopies.cpp.
References llvm::SIRegisterInfo::getEquivalentSGPRClass(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getOperandNo(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::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(), and hoistAndMergeSGPRInits().
Definition at line 136 of file SIFixSGPRCopies.cpp.
DEBUG_TYPE |
Definition at line 136 of file SIFixSGPRCopies.cpp.
|
static |
Referenced by hoistAndMergeSGPRInits().
Definition at line 136 of file SIFixSGPRCopies.cpp.