32#define DEBUG_TYPE "gcn-create-vopd"
33STATISTIC(NumVOPDCreated,
"Number of VOPD Insts Created.");
41 class VOPDCombineInfo {
43 VOPDCombineInfo() =
default;
46 : FirstMI(
First), SecondMI(Second), IsVOPD3(VOPD3) {}
48 MachineInstr *FirstMI;
49 MachineInstr *SecondMI;
54 const GCNSubtarget *ST =
nullptr;
56 bool doReplace(
const SIInstrInfo *SII, VOPDCombineInfo &CI) {
57 auto *FirstMI = CI.FirstMI;
58 auto *SecondMI = CI.SecondMI;
59 unsigned Opc1 = FirstMI->getOpcode();
60 unsigned Opc2 = SecondMI->getOpcode();
61 unsigned EncodingFamily =
65 EncodingFamily, CI.IsVOPD3);
67 "Should have previously determined this as a possible VOPD\n");
69 auto VOPDInst =
BuildMI(*FirstMI->getParent(), FirstMI,
70 FirstMI->getDebugLoc(), SII->get(NewOpcode))
71 .
setMIFlags(FirstMI->getFlags() | SecondMI->getFlags());
73 namespace VOPD = AMDGPU::VOPD;
74 MachineInstr *
MI[] = {FirstMI, SecondMI};
78 for (
auto CompIdx : VOPD::COMPONENTS) {
79 auto MCOprIdx = InstInfo[CompIdx].getIndexOfDstInMCOperands();
80 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
83 const AMDGPU::OpName Mods[2][3] = {
84 {AMDGPU::OpName::src0X_modifiers, AMDGPU::OpName::vsrc1X_modifiers,
85 AMDGPU::OpName::vsrc2X_modifiers},
86 {AMDGPU::OpName::src0Y_modifiers, AMDGPU::OpName::vsrc1Y_modifiers,
87 AMDGPU::OpName::vsrc2Y_modifiers}};
88 const AMDGPU::OpName SrcMods[3] = {AMDGPU::OpName::src0_modifiers,
89 AMDGPU::OpName::src1_modifiers,
90 AMDGPU::OpName::src2_modifiers};
91 const unsigned VOPDOpc = VOPDInst->getOpcode();
93 for (
auto CompIdx : VOPD::COMPONENTS) {
94 auto CompSrcOprNum = InstInfo[CompIdx].getCompSrcOperandsNum();
95 bool IsVOP3 = SII->
isVOP3(*
MI[CompIdx]);
96 for (
unsigned CompSrcIdx = 0; CompSrcIdx < CompSrcOprNum; ++CompSrcIdx) {
98 const MachineOperand *
Mod =
100 VOPDInst.addImm(
Mod ?
Mod->getImm() : 0);
103 InstInfo[CompIdx].getIndexOfSrcInMCOperands(CompSrcIdx, IsVOP3);
104 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
106 if (
MI[CompIdx]->
getOpcode() == AMDGPU::V_CNDMASK_B32_e32 && CI.IsVOPD3)
107 VOPDInst.addReg(AMDGPU::VCC_LO);
112 VOPDInst.addImm(BitOp2);
116 for (
auto CompIdx : VOPD::COMPONENTS)
117 VOPDInst.copyImplicitOps(*
MI[CompIdx]);
120 << *CI.FirstMI <<
"\tY: " << *CI.SecondMI <<
"\n");
122 for (
auto CompIdx : VOPD::COMPONENTS)
123 MI[CompIdx]->eraseFromParent();
135 const SIInstrInfo *SII = ST->getInstrInfo();
140 for (
auto &
MBB : MF) {
143 auto *FirstMI = &*MII;
147 if (FirstMI->isDebugInstr())
149 auto *SecondMI = &*MII;
153 VOPDCombineInfo(Match->MIX, Match->MIY, Match->IsVOPD3));
158 for (
auto &CI : ReplaceCandidates) {
169 GCNCreateVOPDLegacy() : MachineFunctionPass(ID) {}
171 void getAnalysisUsage(AnalysisUsage &AU)
const override {
176 StringRef getPassName()
const override {
177 return "GCN Create VOPD Instructions";
183 return GCNCreateVOPD().run(MF);
192 if (!GCNCreateVOPD().
run(MF))
197char GCNCreateVOPDLegacy::ID = 0;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Interface definition for SIInstrInfo.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
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.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Representation of each machine instruction.
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.
const GCNSubtarget & getSubtarget() const
static bool isVOP3(const MCInstrDesc &Desc)
void fixImplicitOperands(MachineInstr &MI) const
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, AMDGPU::OpName OperandName) const
Returns the operand named Op.
void push_back(const T &Elt)
unsigned getVOPDOpcode(unsigned Opc, bool VOPD3)
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, OpName NamedIdx)
unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST)
unsigned getBitOp2(unsigned Opc)
VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
bool hasVOPD(const MCSubtargetInfo &STI)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily, bool VOPD3)
DXILDebugInfoMap run(Module &M)
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Mod
The access may modify the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
std::optional< VOPDMatchInfo > tryMatchVOPDPair(const SIInstrInfo &TII, MachineInstr &FirstMI, MachineInstr &SecondMI)
Check whether FirstMI and SecondMI can be combined into a VOPD instruction.