27class NVPTXReplaceImageHandles {
28 DenseSet<MachineInstr *> InstrsToRemove;
36 bool IsTexture =
false);
42 InstrsToRemove.
clear();
44 for (MachineBasicBlock &
MBB : MF)
45 for (MachineInstr &
MI :
MBB)
52 for (MachineInstr *
MI : InstrsToRemove) {
53 unsigned DefReg =
MI->getOperand(0).getReg();
55 if (MF.getRegInfo().use_nodbg_empty(DefReg))
56 MI->eraseFromParent();
61bool NVPTXReplaceImageHandles::processInstr(MachineInstr &
MI) {
63 const MCInstrDesc &MCID =
MI.getDesc();
68 MachineOperand &TexHandle =
MI.getOperand(4);
69 bool Changed = replaceImageHandle(TexHandle, MF,
true);
72 MachineOperand &SampHandle =
MI.getOperand(5);
73 Changed |= replaceImageHandle(SampHandle, MF,
true);
84 MachineOperand &SurfHandle =
MI.getOperand(VecSize);
86 return replaceImageHandle(SurfHandle, MF);
90 MachineOperand &SurfHandle =
MI.getOperand(0);
92 return replaceImageHandle(SurfHandle, MF);
96 MachineOperand &Handle =
MI.getOperand(1);
98 return replaceImageHandle(Handle, MF);
104bool NVPTXReplaceImageHandles::replaceImageHandle(MachineOperand &
Op,
108 NVPTXMachineFunctionInfo *MFI = MF.
getInfo<NVPTXMachineFunctionInfo>();
110 assert(
Op.isReg() &&
"Handle is not in a reg?");
116 case NVPTX::LD_i64: {
119 const auto &TM =
static_cast<const NVPTXTargetMachine &
>(MF.
getTarget());
120 if (TM.getDrvInterface() == NVPTX::CUDA)
126 InstrsToRemove.insert(&TexHandleDef);
127 Op.ChangeToMCSymbol(Sym);
131 case NVPTX::texsurf_handles: {
136 InstrsToRemove.insert(&TexHandleDef);
137 Op.ChangeToGA(GV, 0);
140 case NVPTX::nvvm_move_i64:
141 case TargetOpcode::COPY: {
142 bool Res = replaceImageHandle(TexHandleDef.
getOperand(1), MF, IsTexture);
144 InstrsToRemove.insert(&TexHandleDef);
153 if (MF.
getSubtarget<NVPTXSubtarget>().getSmVersion() < 30) {
155 F.getContext().diagnose(DiagnosticInfoUnsupported(
156 F,
"image handle must be a kernel parameter or a global on sm_2x",
158 }
else if (IsTexture &&
159 static_cast<const NVPTXTargetMachine &
>(MF.
getTarget())
160 .getDrvInterface() == NVPTX::NVCL) {
163 F.getContext().diagnose(DiagnosticInfoUnsupported(
165 "texture or sampler handle must be a kernel parameter or a global "
166 "in independent texture mode",
175class NVPTXReplaceImageHandlesLegacyPass :
public MachineFunctionPass {
178 NVPTXReplaceImageHandlesLegacyPass() : MachineFunctionPass(
ID) {}
181 return NVPTXReplaceImageHandles().run(MF);
184 StringRef getPassName()
const override {
185 return "NVPTX Replace Image Handles";
188 void getAnalysisUsage(AnalysisUsage &AU)
const override {
195char NVPTXReplaceImageHandlesLegacyPass::ID = 0;
198 return new NVPTXReplaceImageHandlesLegacyPass();
204 if (!NVPTXReplaceImageHandles().
run(MF))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseSet and SmallDenseSet classes.
MachineRegisterInfo & MRI
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
const GlobalValue * getGlobal() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MCSymbol * getMCSymbol() const
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
void addImageHandleSymbol(const MCSymbol *Symbol)
Record that Symbol's handle was replaced with an image reference.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
MachineFunctionPass * createNVPTXReplaceImageHandlesLegacyPass()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
void processInstr(MachineInstr &MI, MachineIRBuilder &MIB, MachineRegisterInfo &MRI, SPIRVGlobalRegistry *GR, SPIRVTypeInst KnownResType)
DWARFExpression::Operation Op