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);
44 if (!dominates(MI, CurrPos))
45 CurMBB->
splice(CurrPos, CurMBB, MI);
51 bool CSEMIRBuilder::canPerformCSEForOpc(
unsigned Opc)
const {
58 void CSEMIRBuilder::profileDstOp(
const DstOp &
Op,
70 void CSEMIRBuilder::profileSrcOp(
const SrcOp &Op,
90 void CSEMIRBuilder::profileEverything(
unsigned Opc,
ArrayRef<DstOp> DstOps,
95 profileMBBOpcode(B, Opc);
97 profileDstOps(DstOps, B);
99 profileSrcOps(SrcOps, B);
106 void *NodeInsertPos) {
108 "Attempting to CSE illegal op");
110 getCSEInfo()->insertInstr(MIBInstr, NodeInsertPos);
115 if (DstOps.
size() == 1)
127 assert(checkCopyToDefsPossible(DstOps) &&
128 "Impossible return a single MIB with copies to multiple defs");
129 if (DstOps.
size() == 1) {
130 const DstOp &Op = DstOps[0];
144 case TargetOpcode::G_ADD:
145 case TargetOpcode::G_AND:
146 case TargetOpcode::G_ASHR:
147 case TargetOpcode::G_LSHR:
148 case TargetOpcode::G_MUL:
149 case TargetOpcode::G_OR:
150 case TargetOpcode::G_SHL:
151 case TargetOpcode::G_SUB:
152 case TargetOpcode::G_XOR:
153 case TargetOpcode::G_UDIV:
154 case TargetOpcode::G_SDIV:
155 case TargetOpcode::G_UREM:
156 case TargetOpcode::G_SREM: {
158 assert(SrcOps.
size() == 2 &&
"Invalid sources");
166 bool CanCopy = checkCopyToDefsPossible(DstOps);
167 if (!canPerformCSEForOpc(Opc))
180 void *InsertPos =
nullptr;
181 profileEverything(Opc, DstOps, SrcOps, Flag, ProfBuilder);
185 return generateCopiesIfRequired(DstOps, MIB);
190 return memoizeMI(NewMIB, InsertPos);
195 constexpr
unsigned Opc = TargetOpcode::G_CONSTANT;
196 if (!canPerformCSEForOpc(Opc))
200 void *InsertPos =
nullptr;
201 profileMBBOpcode(ProfBuilder, Opc);
202 profileDstOp(Res, ProfBuilder);
207 return generateCopiesIfRequired({Res}, MIB);
210 return memoizeMI(NewMIB, InsertPos);
215 constexpr
unsigned Opc = TargetOpcode::G_FCONSTANT;
216 if (!canPerformCSEForOpc(Opc))
220 void *InsertPos =
nullptr;
221 profileMBBOpcode(ProfBuilder, Opc);
222 profileDstOp(Res, ProfBuilder);
227 return generateCopiesIfRequired({Res}, MIB);
230 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.
DstType getDstOpKind() const
unsigned getReg() const
getReg - Returns the register number.
const GISelInstProfileBuilder & addNodeIDImmediate(int64_t Imm) const
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
const GISelInstProfileBuilder & addNodeIDFlag(unsigned Flag) const
const GISelInstProfileBuilder & addNodeIDOpcode(unsigned Opc) const
GISelCSEInfo * getCSEInfo()
Optional< APInt > ConstantFoldBinOp(unsigned Opcode, const unsigned Op1, const unsigned Op2, const MachineRegisterInfo &MRI)
SrcType getSrcOpKind() const
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.
const GISelInstProfileBuilder & addNodeIDRegType(const LLT &Ty) const
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.
MachineRegisterInfo * getMRI()
Getter for MRI.
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].
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.
LLT getLLTTy(const MachineRegisterInfo &MRI) const
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Representation of each machine instruction.
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 TargetRegisterClass * getRegClass() const
const GISelInstProfileBuilder & addNodeIDMBB(const MachineBasicBlock *MBB) const
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.
CmpInst::Predicate getPredicate() const
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
const MachineOperand & getOperand(unsigned i) const