32#define DEBUG_TYPE "gcn-create-vopd"
33STATISTIC(NumVOPDCreated,
"Number of VOPD Insts Created.");
41 class VOPDCombineInfo {
43 VOPDCombineInfo() =
default;
45 : FirstMI(
First), SecondMI(Second) {}
63 return "GCN Create VOPD Instructions";
66 bool doReplace(
const SIInstrInfo *SII, VOPDCombineInfo &CI) {
67 auto *FirstMI = CI.FirstMI;
68 auto *SecondMI = CI.SecondMI;
69 unsigned Opc1 = FirstMI->getOpcode();
70 unsigned Opc2 = SecondMI->getOpcode();
71 unsigned EncodingFamily =
77 "Should have previously determined this as a possible VOPD\n");
79 auto VOPDInst =
BuildMI(*FirstMI->getParent(), FirstMI,
80 FirstMI->getDebugLoc(), SII->get(NewOpcode))
81 .
setMIFlags(FirstMI->getFlags() | SecondMI->getFlags());
83 namespace VOPD = AMDGPU::VOPD;
88 for (
auto CompIdx : VOPD::COMPONENTS) {
89 auto MCOprIdx = InstInfo[CompIdx].getIndexOfDstInMCOperands();
90 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
93 for (
auto CompIdx : VOPD::COMPONENTS) {
94 auto CompSrcOprNum = InstInfo[CompIdx].getCompSrcOperandsNum();
95 for (
unsigned CompSrcIdx = 0; CompSrcIdx < CompSrcOprNum; ++CompSrcIdx) {
96 auto MCOprIdx = InstInfo[CompIdx].getIndexOfSrcInMCOperands(CompSrcIdx);
97 VOPDInst.add(
MI[CompIdx]->getOperand(MCOprIdx));
102 for (
auto CompIdx : VOPD::COMPONENTS)
103 VOPDInst.copyImplicitOps(*
MI[CompIdx]);
106 << *CI.FirstMI <<
"\tY: " << *CI.SecondMI <<
"\n");
108 for (
auto CompIdx : VOPD::COMPONENTS)
109 MI[CompIdx]->eraseFromParent();
124 bool Changed =
false;
128 for (
auto &
MBB : MF) {
131 auto *FirstMI = &*MII;
135 if (FirstMI->isDebugInstr())
137 auto *SecondMI = &*MII;
138 unsigned Opc = FirstMI->getOpcode();
139 unsigned Opc2 = SecondMI->getOpcode();
144 if (FirstCanBeVOPD.
X && SecondCanBeVOPD.
Y)
145 CI = VOPDCombineInfo(FirstMI, SecondMI);
146 else if (FirstCanBeVOPD.
Y && SecondCanBeVOPD.
X)
147 CI = VOPDCombineInfo(SecondMI, FirstMI);
158 for (
auto &CI : ReplaceCandidates) {
159 Changed |= doReplace(SII, CI);
168char GCNCreateVOPD::ID = 0;
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
const GCNSubtarget & getSubtarget() const
void fixImplicitOperands(MachineInstr &MI) const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
CanBeVOPD getCanBeVOPD(unsigned Opc)
unsigned getVOPDOpcode(unsigned Opc)
unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST)
int getVOPDFull(unsigned OpX, unsigned OpY, unsigned EncodingFamily)
VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
bool hasVOPD(const MCSubtargetInfo &STI)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
bool checkVOPDRegConstraints(const SIInstrInfo &TII, const MachineInstr &FirstMI, const MachineInstr &SecondMI)