25 assert(
A->getParent() ==
B->getParent() &&
26 "Iterators should be in same block");
29 for (; &*
I !=
A && &*
I !=
B; ++
I)
36 void *&NodeInsertPos) {
38 assert(CSEInfo &&
"Can't get here without setting CSEInfo");
41 CSEInfo->getMachineInstrIfExists(
ID, CurMBB, NodeInsertPos);
50 }
else if (!dominates(
MI, CurrPos)) {
58 bool CSEMIRBuilder::canPerformCSEForOpc(
unsigned Opc)
const {
65 void CSEMIRBuilder::profileDstOp(
const DstOp &
Op,
67 switch (
Op.getDstOpKind()) {
69 B.addNodeIDRegType(
Op.getRegClass());
73 B.addNodeIDReg(
Op.getReg());
77 B.addNodeIDRegType(
Op.getLLTTy(*
getMRI()));
82 void CSEMIRBuilder::profileSrcOp(
const SrcOp &
Op,
84 switch (
Op.getSrcOpKind()) {
86 B.addNodeIDImmediate(static_cast<int64_t>(
Op.getImm()));
89 B.addNodeIDImmediate(static_cast<int64_t>(
Op.getPredicate()));
92 B.addNodeIDRegType(
Op.getReg());
102 B.addNodeIDOpcode(Opc);
105 void CSEMIRBuilder::profileEverything(
unsigned Opc,
ArrayRef<DstOp> DstOps,
110 profileMBBOpcode(
B, Opc);
112 profileDstOps(DstOps,
B);
114 profileSrcOps(SrcOps,
B);
117 B.addNodeIDFlag(*Flags);
121 void *NodeInsertPos) {
123 "Attempting to CSE illegal op");
125 getCSEInfo()->insertInstr(MIBInstr, NodeInsertPos);
130 if (DstOps.
size() == 1)
142 assert(checkCopyToDefsPossible(DstOps) &&
143 "Impossible return a single MIB with copies to multiple defs");
144 if (DstOps.
size() == 1) {
174 case TargetOpcode::G_ADD:
175 case TargetOpcode::G_AND:
176 case TargetOpcode::G_ASHR:
177 case TargetOpcode::G_LSHR:
178 case TargetOpcode::G_MUL:
179 case TargetOpcode::G_OR:
180 case TargetOpcode::G_SHL:
181 case TargetOpcode::G_SUB:
182 case TargetOpcode::G_XOR:
183 case TargetOpcode::G_UDIV:
184 case TargetOpcode::G_SDIV:
185 case TargetOpcode::G_UREM:
186 case TargetOpcode::G_SREM: {
188 assert(SrcOps.
size() == 2 &&
"Invalid sources");
195 case TargetOpcode::G_SEXT_INREG: {
196 assert(DstOps.
size() == 1 &&
"Invalid dst ops");
197 assert(SrcOps.
size() == 2 &&
"Invalid src ops");
198 const DstOp &Dst = DstOps[0];
199 const SrcOp &Src0 = SrcOps[0];
200 const SrcOp &Src1 = SrcOps[1];
207 bool CanCopy = checkCopyToDefsPossible(DstOps);
208 if (!canPerformCSEForOpc(Opc))
221 void *InsertPos =
nullptr;
222 profileEverything(Opc, DstOps, SrcOps,
Flag, ProfBuilder);
226 return generateCopiesIfRequired(DstOps, MIB);
231 return memoizeMI(NewMIB, InsertPos);
236 constexpr
unsigned Opc = TargetOpcode::G_CONSTANT;
237 if (!canPerformCSEForOpc(Opc))
247 void *InsertPos =
nullptr;
248 profileMBBOpcode(ProfBuilder, Opc);
249 profileDstOp(Res, ProfBuilder);
254 return generateCopiesIfRequired({Res}, MIB);
258 return memoizeMI(NewMIB, InsertPos);
263 constexpr
unsigned Opc = TargetOpcode::G_FCONSTANT;
264 if (!canPerformCSEForOpc(Opc))
274 void *InsertPos =
nullptr;
275 profileMBBOpcode(ProfBuilder, Opc);
276 profileDstOp(Res, ProfBuilder);
281 return generateCopiesIfRequired({Res}, MIB);
284 return memoizeMI(NewMIB, InsertPos);
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
static MachineOperand CreateCImm(const ConstantInt *CI)
This class represents lattice values for constants.
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Register getReg(unsigned Idx) const
Get the register for the operand index.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
GISelChangeObserver * Observer
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Optional< APInt > ConstantFoldBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
GISelCSEInfo * getCSEInfo()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val) override
Build and insert Res = G_FCONSTANT Val.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
MachineFunction & getMF()
Getter for the function we currently build.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool shouldCSE(unsigned Opc) const
void handleRemoveInst(MachineInstr *MI)
Remove this inst from the CSE map.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
MachineInstrBundleIterator< MachineInstr > iterator
MachineRegisterInfo * getMRI()
Getter for MRI.
Abstract class that contains various methods for clients to notify about changes.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
static MachineOperand CreateFPImm(const ConstantFP *CFP)
size_t size() const
size - Get the array size.
This file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
ConstantFP - Floating Point Values [float, double].
void countOpcodeHit(unsigned Opc)
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
This is the shared class of boolean and integer constants.
virtual MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
DebugLoc getDebugLoc()
Get the current instruction's debug location.
LLT getLLTTy(const MachineRegisterInfo &MRI) const
virtual void changingInstr(MachineInstr &MI)=0
This instruction is about to be mutated in some way.
void setDebugLoc(DebugLoc dl)
Replace current source information with new such.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Representation of each machine instruction.
MachineIRBuilderState & getState()
Getter for the State.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val) override
Build and insert Res = G_CONSTANT Val.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef< DstOp > DstOps, ArrayRef< SrcOp > SrcOps, Optional< unsigned > Flag=None) override
const GISelInstProfileBuilder & addNodeIDMachineOperand(const MachineOperand &MO) const
MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
Optional< APInt > ConstantFoldExtOp(unsigned Opcode, const Register Op1, uint64_t Imm, const MachineRegisterInfo &MRI)
virtual void changedInstr(MachineInstr &MI)=0
This instruction was mutated in some way.