33#define DEBUG_TYPE "gcn-create-vopd"
34STATISTIC(NumVOPDCreated,
"Number of VOPD Insts Created.");
42 class VOPDCombineInfo {
44 VOPDCombineInfo() =
default;
47 : FirstMI(
First), SecondMI(Second), IsVOPD3(VOPD3) {}
49 MachineInstr *FirstMI;
50 MachineInstr *SecondMI;
55 const GCNSubtarget *ST =
nullptr;
57 bool doReplace(
const SIInstrInfo *SII, VOPDCombineInfo &CI) {
58 auto *FirstMI = CI.FirstMI;
59 auto *SecondMI = CI.SecondMI;
60 unsigned Opc1 = FirstMI->getOpcode();
61 unsigned Opc2 = SecondMI->getOpcode();
62 unsigned EncodingFamily =
66 EncodingFamily, CI.IsVOPD3);
68 "Should have previously determined this as a possible VOPD\n");
70 auto VOPDInst =
BuildMI(*FirstMI->getParent(), FirstMI,
71 FirstMI->getDebugLoc(), SII->get(NewOpcode))
72 .
setMIFlags(FirstMI->getFlags() | SecondMI->getFlags());
74 namespace VOPD = AMDGPU::VOPD;
75 MachineInstr *
MI[] = {FirstMI, SecondMI};
79 for (
auto CompIdx : VOPD::COMPONENTS) {
80 auto MCOprIdx = InstInfo[CompIdx].getIndexOfDstInMCOperands();
81 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
84 const AMDGPU::OpName Mods[2][3] = {
85 {AMDGPU::OpName::src0X_modifiers, AMDGPU::OpName::vsrc1X_modifiers,
86 AMDGPU::OpName::vsrc2X_modifiers},
87 {AMDGPU::OpName::src0Y_modifiers, AMDGPU::OpName::vsrc1Y_modifiers,
88 AMDGPU::OpName::vsrc2Y_modifiers}};
89 const AMDGPU::OpName SrcMods[3] = {AMDGPU::OpName::src0_modifiers,
90 AMDGPU::OpName::src1_modifiers,
91 AMDGPU::OpName::src2_modifiers};
92 const unsigned VOPDOpc = VOPDInst->getOpcode();
94 for (
auto CompIdx : VOPD::COMPONENTS) {
95 auto CompSrcOprNum = InstInfo[CompIdx].getCompSrcOperandsNum();
96 bool IsVOP3 = SII->
isVOP3(*
MI[CompIdx]);
97 for (
unsigned CompSrcIdx = 0; CompSrcIdx < CompSrcOprNum; ++CompSrcIdx) {
99 const MachineOperand *
Mod =
101 VOPDInst.addImm(
Mod ?
Mod->getImm() : 0);
104 InstInfo[CompIdx].getIndexOfSrcInMCOperands(CompSrcIdx, IsVOP3);
105 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
107 if (
MI[CompIdx]->getOpcode() == AMDGPU::V_CNDMASK_B32_e32 && CI.IsVOPD3)
108 VOPDInst.addReg(AMDGPU::VCC_LO);
113 VOPDInst.addImm(BitOp2);
117 for (
auto CompIdx : VOPD::COMPONENTS)
118 VOPDInst.copyImplicitOps(*
MI[CompIdx]);
121 << *CI.FirstMI <<
"\tY: " << *CI.SecondMI <<
"\n");
123 for (
auto CompIdx : VOPD::COMPONENTS)
124 MI[CompIdx]->eraseFromParent();
130 bool run(MachineFunction &MF) {
136 const SIInstrInfo *SII = ST->getInstrInfo();
141 for (
auto &
MBB : MF) {
144 auto *FirstMI = &*MII;
148 if (FirstMI->isDebugInstr())
150 auto *SecondMI = &*MII;
154 VOPDCombineInfo(Match->MIX, Match->MIY, Match->IsVOPD3));
159 for (
auto &CI : ReplaceCandidates) {
170 GCNCreateVOPDLegacy() : MachineFunctionPass(ID) {}
172 void getAnalysisUsage(AnalysisUsage &AU)
const override {
177 StringRef getPassName()
const override {
178 return "GCN Create VOPD Instructions";
180 bool runOnMachineFunction(MachineFunction &MF)
override {
184 return GCNCreateVOPD().run(MF);
193 if (!GCNCreateVOPD().
run(MF))
198char 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 SmallVector class.
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)
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.