22 #define DEBUG_TYPE "gi-combiner" 30 cl::desc(
"Force all indexed operations to be " 31 "legal for the GlobalISel combiner"));
37 : Builder(B),
MRI(Builder.getMF().getRegInfo()), Observer(Observer),
100 if ((SrcRC == DstRC) && (SrcBank == DstBank))
103 if (!DstBank && !DstRC)
116 bool IsUndef =
false;
128 "Invalid instruction");
138 assert(Def &&
"Operand not defined");
140 case TargetOpcode::G_BUILD_VECTOR:
147 case TargetOpcode::G_IMPLICIT_DEF: {
156 "All undefs should have the same type");
160 EltIdx != EltEnd; ++EltIdx)
204 "Invalid instruction kind");
211 unsigned DstNumElts = DstType.
isVector() ? DstType.getNumElements() : 1;
229 if (DstNumElts < 2 * SrcNumElts && DstNumElts != 1)
234 if (DstNumElts % SrcNumElts != 0)
240 unsigned NumConcat = DstNumElts / SrcNumElts;
243 for (
unsigned i = 0; i != DstNumElts; ++i) {
250 if ((Idx % SrcNumElts != (i % SrcNumElts)) ||
251 (ConcatSrcs[i / SrcNumElts] >= 0 &&
252 ConcatSrcs[i / SrcNumElts] != (
int)(Idx / SrcNumElts)))
255 ConcatSrcs[i / SrcNumElts] = Idx / SrcNumElts;
262 for (
auto Src : ConcatSrcs) {
297 const LLT &TyForCandidate,
298 unsigned OpcodeForCandidate,
303 return {TyForCandidate, OpcodeForCandidate, MIForCandidate};
314 if (OpcodeForCandidate == TargetOpcode::G_ANYEXT &&
317 else if (CurrentUse.
ExtendOpcode == TargetOpcode::G_ANYEXT &&
318 OpcodeForCandidate != TargetOpcode::G_ANYEXT)
319 return {TyForCandidate, OpcodeForCandidate, MIForCandidate};
323 if (CurrentUse.
Ty == TyForCandidate) {
325 OpcodeForCandidate == TargetOpcode::G_ZEXT)
327 else if (CurrentUse.
ExtendOpcode == TargetOpcode::G_ZEXT &&
328 OpcodeForCandidate == TargetOpcode::G_SEXT)
329 return {TyForCandidate, OpcodeForCandidate, MIForCandidate};
338 return {TyForCandidate, OpcodeForCandidate, MIForCandidate};
349 static void InsertInsnsWithoutSideEffectsBeforeUse(
361 InsertBB = PredBB->
getMBB();
368 Inserter(InsertBB, std::next(InsertPt), UseMO);
395 if (MI.
getOpcode() != TargetOpcode::G_LOAD &&
396 MI.
getOpcode() != TargetOpcode::G_SEXTLOAD &&
397 MI.
getOpcode() != TargetOpcode::G_ZEXTLOAD)
401 assert(LoadValue.isReg() &&
"Result wasn't a register?");
404 if (!LoadValueTy.isScalar())
412 if (LoadValueTy.getSizeInBits() < 8)
425 unsigned PreferredOpcode = MI.
getOpcode() == TargetOpcode::G_LOAD
426 ? TargetOpcode::G_ANYEXT
427 : MI.
getOpcode() == TargetOpcode::G_SEXTLOAD
428 ? TargetOpcode::G_SEXT
429 : TargetOpcode::G_ZEXT;
430 Preferred = {
LLT(), PreferredOpcode,
nullptr};
432 if (
UseMI.getOpcode() == TargetOpcode::G_SEXT ||
433 UseMI.getOpcode() == TargetOpcode::G_ZEXT ||
434 UseMI.getOpcode() == TargetOpcode::G_ANYEXT) {
435 Preferred = ChoosePreferredUse(Preferred,
446 assert(Preferred.
Ty != LoadValueTy &&
"Extending to same type?");
464 if (PreviouslyEmitted) {
474 EmittedInsns[InsertIntoBB] = NewMI;
481 ? TargetOpcode::G_SEXTLOAD
483 ? TargetOpcode::G_ZEXTLOAD
484 : TargetOpcode::G_LOAD));
492 for (
auto *UseMO : Uses) {
498 UseMI->
getOpcode() == TargetOpcode::G_ANYEXT) {
502 if (UseDstReg != ChosenDstReg) {
503 if (Preferred.
Ty == UseDstTy) {
515 UseMO->getParent()->eraseFromParent();
540 InsertInsnsWithoutSideEffectsBeforeUse(
Builder, MI, *UseMO,
549 UseMO->getParent()->eraseFromParent();
555 InsertInsnsWithoutSideEffectsBeforeUse(
Builder, MI, *UseMO, InsertTruncAt);
564 if (&DefMI == &UseMI)
569 for (; &*I != &DefMI && &*I != &
UseMI; ++
I)
570 return &*I == &DefMI;
591 assert(Opcode == TargetOpcode::G_LOAD || Opcode == TargetOpcode::G_SEXTLOAD ||
592 Opcode == TargetOpcode::G_ZEXTLOAD || Opcode == TargetOpcode::G_STORE);
597 if (BaseDef && BaseDef->
getOpcode() == TargetOpcode::G_FRAME_INDEX)
600 LLVM_DEBUG(
dbgs() <<
"Searching for post-indexing opportunity for: " << MI);
603 if (
Use.getOpcode() != TargetOpcode::G_PTR_ADD)
606 Offset =
Use.getOperand(2).getReg();
608 !TLI.isIndexingLegal(MI, Base, Offset,
false,
MRI)) {
609 LLVM_DEBUG(
dbgs() <<
" Ignoring candidate with illegal addrmode: " 618 if (!OffsetDef || !
dominates(*OffsetDef, MI)) {
619 LLVM_DEBUG(
dbgs() <<
" Ignoring candidate with offset after mem-op: " 628 bool MemOpDominatesAddrUses =
true;
631 MemOpDominatesAddrUses =
false;
636 if (!MemOpDominatesAddrUses) {
638 dbgs() <<
" Ignoring candidate as memop does not dominate uses: " 644 Addr =
Use.getOperand(0).getReg();
658 assert(Opcode == TargetOpcode::G_LOAD || Opcode == TargetOpcode::G_SEXTLOAD ||
659 Opcode == TargetOpcode::G_ZEXTLOAD || Opcode == TargetOpcode::G_STORE);
670 LLVM_DEBUG(
dbgs() <<
"Found potential pre-indexed load_store: " << MI);
673 !TLI.isIndexingLegal(MI, Base, Offset,
true,
MRI)) {
679 if (BaseDef->
getOpcode() == TargetOpcode::G_FRAME_INDEX) {
680 LLVM_DEBUG(
dbgs() <<
" Skipping, frame index would need copy anyway.");
684 if (MI.
getOpcode() == TargetOpcode::G_STORE) {
687 LLVM_DEBUG(
dbgs() <<
" Skipping, storing base so need copy anyway.");
694 LLVM_DEBUG(
dbgs() <<
" Skipping, does not dominate all addr uses");
704 LLVM_DEBUG(
dbgs() <<
" Skipping, does not dominate all addr uses.");
723 if (Opcode != TargetOpcode::G_LOAD && Opcode != TargetOpcode::G_SEXTLOAD &&
724 Opcode != TargetOpcode::G_ZEXTLOAD && Opcode != TargetOpcode::G_STORE)
727 MatchInfo.
IsPre = findPreIndexCandidate(MI, MatchInfo.
Addr, MatchInfo.
Base,
729 if (!MatchInfo.
IsPre &&
730 !findPostIndexCandidate(MI, MatchInfo.
Addr, MatchInfo.
Base,
742 bool IsStore = Opcode == TargetOpcode::G_STORE;
745 case TargetOpcode::G_LOAD:
746 NewOpcode = TargetOpcode::G_INDEXED_LOAD;
748 case TargetOpcode::G_SEXTLOAD:
749 NewOpcode = TargetOpcode::G_INDEXED_SEXTLOAD;
751 case TargetOpcode::G_ZEXTLOAD:
752 NewOpcode = TargetOpcode::G_INDEXED_ZEXTLOAD;
754 case TargetOpcode::G_STORE:
755 NewOpcode = TargetOpcode::G_INDEXED_STORE;
780 if (MI.
getOpcode() != TargetOpcode::G_BR)
800 if (BrIt == MBB->
begin())
802 assert(std::next(BrIt) == MBB->
end() &&
"expected G_BR to be a terminator");
805 if (BrCond->getOpcode() != TargetOpcode::G_BRCOND)
813 if (!CmpMI || CmpMI->
getOpcode() != TargetOpcode::G_ICMP ||
858 std::vector<LLT> &MemOps,
unsigned Limit, uint64_t
Size,
unsigned DstAlign,
859 unsigned SrcAlign,
bool IsMemset,
bool ZeroMemset,
bool MemcpyStrSrc,
860 bool AllowOverlap,
unsigned DstAS,
unsigned SrcAS,
869 if (SrcAlign != 0 && SrcAlign < DstAlign)
873 ZeroMemset, MemcpyStrSrc, FuncAttributes);
887 unsigned NumMemOps = 0;
890 while (TySize > Size) {
899 assert(NewTySize > 0 &&
"Could not find appropriate type");
906 if (NumMemOps && AllowOverlap && NewTySize < Size &&
917 if (++NumMemOps > Limit)
920 MemOps.push_back(Ty);
939 if (!Ty.
isVector() && ValVRegAndVal) {
940 unsigned KnownVal = ValVRegAndVal->Value;
959 assert(ExtType == Ty &&
"Vector memset value type not supported yet");
964 unsigned KnownLen,
unsigned Align,
968 auto &DL = MF.getDataLayout();
971 assert(KnownLen != 0 &&
"Have a zero length memset length!");
973 bool DstAlignCanChange =
false;
979 DstAlignCanChange =
true;
981 unsigned Limit = TLI.getMaxStoresPerMemset(OptSize);
982 std::vector<LLT> MemOps;
988 bool IsZeroVal = ValVRegAndVal && ValVRegAndVal->Value == 0;
991 MemOps, Limit, KnownLen, (DstAlignCanChange ? 0 : Align), 0,
995 MF.getFunction().getAttributes(), TLI))
998 if (DstAlignCanChange) {
1001 unsigned NewAlign = (
unsigned)DL.getABITypeAlignment(IRTy);
1002 if (NewAlign > Align) {
1013 LLT LargestTy = MemOps[0];
1014 for (
unsigned i = 1; i < MemOps.size(); i++)
1016 LargestTy = MemOps[i];
1029 unsigned DstOff = 0;
1030 unsigned Size = KnownLen;
1031 for (
unsigned I = 0;
I < MemOps.size();
I++) {
1034 if (TySize > Size) {
1037 assert(
I == MemOps.size() - 1 &&
I != 0);
1038 DstOff -= TySize -
Size;
1048 TLI.isTruncateFree(LargestVT, VT))
1078 unsigned DstAlign,
unsigned SrcAlign,
1082 auto &DL = MF.getDataLayout();
1085 assert(KnownLen != 0 &&
"Have a zero length memcpy length!");
1087 bool DstAlignCanChange =
false;
1090 unsigned Alignment =
MinAlign(DstAlign, SrcAlign);
1094 DstAlignCanChange =
true;
1100 unsigned Limit = TLI.getMaxStoresPerMemcpy(OptSize);
1101 std::vector<LLT> MemOps;
1109 MemOps, Limit, KnownLen, (DstAlignCanChange ? 0 : Alignment),
1113 !IsVolatile, DstPtrInfo.getAddrSpace(),
1114 SrcPtrInfo.
getAddrSpace(), MF.getFunction().getAttributes(), TLI))
1117 if (DstAlignCanChange) {
1120 unsigned NewAlign = (
unsigned)DL.getABITypeAlignment(IRTy);
1126 while (NewAlign > Alignment &&
1127 DL.exceedsNaturalStackAlignment(Align(NewAlign)))
1130 if (NewAlign > Alignment) {
1131 Alignment = NewAlign;
1139 LLVM_DEBUG(
dbgs() <<
"Inlining memcpy: " << MI <<
" into loads & stores\n");
1147 unsigned CurrOffset = 0;
1149 unsigned Size = KnownLen;
1150 for (
auto CopyTy : MemOps) {
1153 if (CopyTy.getSizeInBytes() >
Size)
1154 CurrOffset -= CopyTy.getSizeInBytes() -
Size;
1158 MF.getMachineMemOperand(&SrcMMO, CurrOffset, CopyTy.getSizeInBytes());
1160 MF.getMachineMemOperand(&DstMMO, CurrOffset, CopyTy.getSizeInBytes());
1165 if (CurrOffset != 0) {
1170 auto LdVal = MIB.
buildLoad(CopyTy, LoadPtr, *LoadMMO);
1176 CurrOffset += CopyTy.getSizeInBytes();
1177 Size -= CopyTy.getSizeInBytes();
1186 unsigned DstAlign,
unsigned SrcAlign,
1190 auto &DL = MF.getDataLayout();
1193 assert(KnownLen != 0 &&
"Have a zero length memmove length!");
1195 bool DstAlignCanChange =
false;
1198 unsigned Alignment =
MinAlign(DstAlign, SrcAlign);
1202 DstAlignCanChange =
true;
1204 unsigned Limit = TLI.getMaxStoresPerMemmove(OptSize);
1205 std::vector<LLT> MemOps;
1216 MemOps, Limit, KnownLen, (DstAlignCanChange ? 0 : Alignment),
1220 false, DstPtrInfo.getAddrSpace(),
1221 SrcPtrInfo.
getAddrSpace(), MF.getFunction().getAttributes(), TLI))
1224 if (DstAlignCanChange) {
1227 unsigned NewAlign = (
unsigned)DL.getABITypeAlignment(IRTy);
1233 while (NewAlign > Alignment &&
1234 DL.exceedsNaturalStackAlignment(Align(NewAlign)))
1237 if (NewAlign > Alignment) {
1238 Alignment = NewAlign;
1246 LLVM_DEBUG(
dbgs() <<
"Inlining memmove: " << MI <<
" into loads & stores\n");
1252 unsigned CurrOffset = 0;
1255 for (
auto CopyTy : MemOps) {
1258 MF.getMachineMemOperand(&SrcMMO, CurrOffset, CopyTy.getSizeInBytes());
1262 if (CurrOffset != 0) {
1268 CurrOffset += CopyTy.getSizeInBytes();
1272 for (
unsigned I = 0;
I < MemOps.size(); ++
I) {
1273 LLT CopyTy = MemOps[
I];
1276 MF.getMachineMemOperand(&DstMMO, CurrOffset, CopyTy.
getSizeInBytes());
1279 if (CurrOffset != 0) {
1296 assert((ID == Intrinsic::memcpy || ID == Intrinsic::memmove ||
1297 ID == Intrinsic::memset) &&
1298 "Expected a memcpy like intrinsic");
1308 unsigned SrcAlign = 0;
1313 if (ID != Intrinsic::memset) {
1316 SrcAlign = MemOp->getBaseAlignment();
1323 unsigned KnownLen = LenVRegAndVal->Value;
1325 if (KnownLen == 0) {
1330 if (MaxLen && KnownLen > MaxLen)
1333 if (ID == Intrinsic::memcpy)
1334 return optimizeMemcpy(MI, Dst, Src, KnownLen, DstAlign, SrcAlign, IsVolatile);
1335 if (ID == Intrinsic::memmove)
1336 return optimizeMemmove(MI, Dst, Src, KnownLen, DstAlign, SrcAlign, IsVolatile);
1337 if (ID == Intrinsic::memset)
1338 return optimizeMemset(MI, Dst, Src, KnownLen, DstAlign, IsVolatile);
1350 if (MI.
getOpcode() != TargetOpcode::G_PTR_ADD)
1360 if (!Add2Def || Add2Def->
getOpcode() != TargetOpcode::G_PTR_ADD)
1370 MatchInfo.
Imm = MaybeImmVal->Value + MaybeImm2Val->Value;
1371 MatchInfo.
Base = Base;
1377 assert(MI.
getOpcode() == TargetOpcode::G_PTR_ADD &&
"Expected G_PTR_ADD");
1380 auto NewOffset = MIB.buildConstant(OffsetTy, MatchInfo.
Imm);
ArrayRef< int > getShuffleMask() const
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool dominates(MachineInstr &DefMI, MachineInstr &UseMI)
Returns true if DefMI dominates UseMI.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
bool matchCombineExtendingLoads(MachineInstr &MI, PreferredTuple &MatchInfo)
MachineBasicBlock * getMBB() const
This class represents lattice values for constants.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
Register getReg(unsigned Idx) const
Get the register for the operand index.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
unsigned getScalarSizeInBits() const
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
void push_back(const T &Elt)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool matchCombineIndexedLoadStore(MachineInstr &MI, IndexedLoadStoreMatchInfo &MatchInfo)
bool tryCombine(MachineInstr &MI)
Try to transform MI by using all of the above combine functions.
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTR_ADD Op0, Op1.
static cl::opt< bool > ForceLegalIndexing("force-legal-indexing", cl::Hidden, cl::init(false), cl::desc("Force all indexed operations to be " "legal for the GlobalISel combiner"))
static Type * getTypeForLLT(LLT Ty, LLVMContext &C)
virtual const TargetLowering * getTargetLowering() const
LLT getScalarType() const
bool constrainRegAttrs(unsigned Reg, unsigned ConstrainingReg, unsigned MinNumRegs=0)
Constrain the register class or the register bank of the virtual register Reg (and low-level type) to...
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
void applyElideBrByInvertingCond(MachineInstr &MI)
bool matchCombineShuffleVector(MachineInstr &MI, SmallVectorImpl< Register > &Ops)
Check if the G_SHUFFLE_VECTOR MI can be replaced by a concat_vectors.
unsigned const TargetRegisterInfo * TRI
GISelChangeObserver & Observer
uint64_t getBaseAlignment() const
Return the minimum known alignment in bytes of the base address, without the offset.
void applyCombineConcatVectors(MachineInstr &MI, bool IsUndef, const ArrayRef< Register > Ops)
Replace MI with a flattened build_vector with Ops or an implicit_def if IsUndef is true...
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
unsigned getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
void applyCombineCopy(MachineInstr &MI)
bool tryElideBrByInvertingCond(MachineInstr &MI)
void applyCombineExtendingLoads(MachineInstr &MI, PreferredTuple &MatchInfo)
virtual LLT getOptimalMemOpLLT(uint64_t, unsigned, unsigned, bool, bool, bool, const AttributeList &) const
LLT returning variant.
A description of a memory reference used in the backend.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineIRBuilder & Builder
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool matchElideBrByInvertingCond(MachineInstr &MI)
static Register getMemsetValue(Register Val, LLT Ty, MachineIRBuilder &MIB)
void applyCombineShuffleVector(MachineInstr &MI, const ArrayRef< Register > Ops)
Replace MI with a concat_vectors with Ops.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void setReg(Register Reg)
Change the register this operand corresponds to.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
void finishedChangingAllUsesOfReg()
All instructions reported as changing by changingAllUsesOfReg() have finished being changed...
MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
initializer< Ty > init(const Ty &Val)
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
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")
unsigned const MachineRegisterInfo * MRI
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This is an important class for using LLVM in a threaded context.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder & UseMI
size_t size() const
size - Get the array size.
MachineInstrBuilder buildBuildVector(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, unsigned Align=1, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, bool *=nullptr) const
Determine if the target supports unaligned memory accesses.
Helper class to build MachineInstr.
void setMBB(MachineBasicBlock *MBB)
MachineDominatorTree * MDT
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
bool tryCombineExtendingLoads(MachineInstr &MI)
If MI is extend that consumes the result of a load, try to combine it.
const Triple & getTargetTriple() const
const RegisterBank * getRegBankOrNull(unsigned Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
Optional< ValueAndVReg > getConstantVRegValWithLookThrough(unsigned VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool HandleFConstants=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_F/CONSTANT (LookThro...
const Function * getFunction() const
Return the function this instruction belongs to.
MachineRegisterInfo & MRI
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
virtual void erasingInstr(MachineInstr &MI)=0
An instruction is about to be erased.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC Op.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
This class contains a discriminated union of information about pointers in memory operands...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static const char *const Magic
static bool shouldLowerMemFuncForSize(const MachineFunction &MF)
bool tryCombineCopy(MachineInstr &MI)
If MI is COPY, try to combine it.
void changingAllUsesOfReg(const MachineRegisterInfo &MRI, unsigned Reg)
All the instructions using the given register are being changed.
void replaceRegWith(MachineRegisterInfo &MRI, Register FromReg, Register ToReg) const
MachineRegisterInfo::replaceRegWith() and inform the observer of the changes.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
bool matchPtrAddImmedChain(MachineInstr &MI, PtrAddChain &MatchInfo)
bool matchCombineConcatVectors(MachineInstr &MI, bool &IsUndef, SmallVectorImpl< Register > &Ops)
Check if the G_CONCAT_VECTORS MI is undef or if it can be flattened into a build_vector.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, Optional< unsigned > Flags=None)
Build and insert Res = G_MUL Op0, Op1.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
iterator_range< use_iterator > use_operands(unsigned Reg) const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
MachineInstrBuilder MachineInstrBuilder & DefMI
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
bool matchCombineCopy(MachineInstr &MI)
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Promote Memory to Register
const TargetInstrInfo & getTII()
Register cloneVirtualRegister(Register VReg, StringRef Name="")
Create and return a new virtual register in the function with the same attributes as the given regist...
This class implements the register bank concept.
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void applyCombineIndexedLoadStore(MachineInstr &MI, IndexedLoadStoreMatchInfo &MatchInfo)
Class for arbitrary precision integers.
virtual void changingInstr(MachineInstr &MI)=0
This instruction is about to be mutated in some way.
static bool findGISelOptimalMemOpLowering(std::vector< LLT > &MemOps, unsigned Limit, uint64_t Size, unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, bool AllowOverlap, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes, const TargetLowering &TLI)
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
bool tryCombineShuffleVector(MachineInstr &MI)
Try to combine G_SHUFFLE_VECTOR into G_CONCAT_VECTORS.
bool isPredecessor(MachineInstr &DefMI, MachineInstr &UseMI)
Returns true if DefMI precedes UseMI or they are the same instruction.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
void setPredicate(unsigned Predicate)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
bool tryCombineMemCpyFamily(MachineInstr &MI, unsigned MaxLen=0)
Optimize memcpy intrinsics et al, e.g.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator_range< use_instr_iterator > use_instructions(unsigned Reg) const
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getIntrinsicID() const
Returns the Intrinsic::ID for this instruction.
uint64_t PowerOf2Floor(uint64_t A)
Returns the power of two which is less than or equal to the given value.
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
LLVM Value Representation.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool applyPtrAddImmedChain(MachineInstr &MI, PtrAddChain &MatchInfo)
MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
print Print MemDeps of function
MachineInstrBuilder buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
Register getReg() const
getReg - Returns the register number.
CombinerHelper(GISelChangeObserver &Observer, MachineIRBuilder &B, GISelKnownBits *KB=nullptr, MachineDominatorTree *MDT=nullptr)
const MachineOperand & getOperand(unsigned i) const
bool tryCombineConcatVectors(MachineInstr &MI)
If MI is G_CONCAT_VECTORS, try to combine it.
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
virtual void changedInstr(MachineInstr &MI)=0
This instruction was mutated in some way.
Wrapper class representing virtual and physical registers.
This file describes how to lower LLVM code to machine code.
mmo_iterator memoperands_end() const
Access to memory operands of the instruction.
void replaceRegOpWith(MachineRegisterInfo &MRI, MachineOperand &FromRegOp, Register ToReg) const
Replace a single register operand with a new register and inform the observer of the changes...
unsigned getPredicate() const
bool tryCombineIndexedLoadStore(MachineInstr &MI)
Combine MI into a pre-indexed or post-indexed load/store operation if legal and the surrounding code ...