14#ifndef LLVM_CODEGEN_GLOBALISEL_UTILS_H
15#define LLVM_CODEGEN_GLOBALISEL_UTILS_H
58#define GISEL_VECREDUCE_CASES_ALL \
59 case TargetOpcode::G_VECREDUCE_SEQ_FADD: \
60 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: \
61 case TargetOpcode::G_VECREDUCE_FADD: \
62 case TargetOpcode::G_VECREDUCE_FMUL: \
63 case TargetOpcode::G_VECREDUCE_FMAX: \
64 case TargetOpcode::G_VECREDUCE_FMIN: \
65 case TargetOpcode::G_VECREDUCE_FMAXIMUM: \
66 case TargetOpcode::G_VECREDUCE_FMINIMUM: \
67 case TargetOpcode::G_VECREDUCE_ADD: \
68 case TargetOpcode::G_VECREDUCE_MUL: \
69 case TargetOpcode::G_VECREDUCE_AND: \
70 case TargetOpcode::G_VECREDUCE_OR: \
71 case TargetOpcode::G_VECREDUCE_XOR: \
72 case TargetOpcode::G_VECREDUCE_SMAX: \
73 case TargetOpcode::G_VECREDUCE_SMIN: \
74 case TargetOpcode::G_VECREDUCE_UMAX: \
75 case TargetOpcode::G_VECREDUCE_UMIN:
77#define GISEL_VECREDUCE_CASES_NONSEQ \
78 case TargetOpcode::G_VECREDUCE_FADD: \
79 case TargetOpcode::G_VECREDUCE_FMUL: \
80 case TargetOpcode::G_VECREDUCE_FMAX: \
81 case TargetOpcode::G_VECREDUCE_FMIN: \
82 case TargetOpcode::G_VECREDUCE_FMAXIMUM: \
83 case TargetOpcode::G_VECREDUCE_FMINIMUM: \
84 case TargetOpcode::G_VECREDUCE_ADD: \
85 case TargetOpcode::G_VECREDUCE_MUL: \
86 case TargetOpcode::G_VECREDUCE_AND: \
87 case TargetOpcode::G_VECREDUCE_OR: \
88 case TargetOpcode::G_VECREDUCE_XOR: \
89 case TargetOpcode::G_VECREDUCE_SMAX: \
90 case TargetOpcode::G_VECREDUCE_SMIN: \
91 case TargetOpcode::G_VECREDUCE_UMAX: \
92 case TargetOpcode::G_VECREDUCE_UMIN:
99 const TargetInstrInfo &
TII,
112 const MachineFunction &MF,
const TargetRegisterInfo &
TRI,
113 MachineRegisterInfo &MRI,
const TargetInstrInfo &
TII,
114 const RegisterBankInfo &RBI, MachineInstr &InsertPt,
128 const MachineFunction &MF,
const TargetRegisterInfo &
TRI,
129 MachineRegisterInfo &MRI,
const TargetInstrInfo &
TII,
130 const RegisterBankInfo &RBI, MachineInstr &InsertPt,
const MCInstrDesc &
II,
131 MachineOperand &RegMO,
unsigned OpIdx);
141 const TargetInstrInfo &
TII,
142 const TargetRegisterInfo &
TRI,
143 const RegisterBankInfo &RBI);
148 MachineRegisterInfo &MRI);
153 const MachineRegisterInfo &MRI);
158 MachineOptimizationRemarkEmitter &
MORE,
159 MachineOptimizationRemarkMissed &R);
162 MachineOptimizationRemarkEmitter &
MORE,
163 const char *
PassName, StringRef Msg,
164 const MachineInstr &
MI);
169 MachineOptimizationRemarkEmitter &
MORE,
170 MachineOptimizationRemarkMissed &R);
186 const MachineRegisterInfo &MRI);
200 bool LookThroughInstrs =
true);
206 bool LookThroughInstrs =
true,
bool LookThroughAnyExt =
false);
209 std::tuple<Register, Register, uint64_t, Align, bool, std::vector<LLT>>;
217 Align &Alignment,
bool &DstAlignCanChange,
218 std::vector<LLT> &MemOps);
227LLVM_ABI std::optional<FPValueAndVReg>
230 bool LookThroughInstrs =
true);
252LLVM_ABI std::optional<DefinitionAndSourceRegister>
312 const MachineRegisterInfo &MRI);
315 const MachineRegisterInfo &MRI);
321 const MachineRegisterInfo &MRI);
325 const MachineRegisterInfo &MRI);
330 const MachineRegisterInfo &MRI);
334 const MachineRegisterInfo &MRI);
341 const MachineRegisterInfo &MRI);
343LLVM_ABI std::optional<SmallVector<APInt>>
345 unsigned DstScalarSizeInBits,
unsigned ExtOp,
346 const MachineRegisterInfo &MRI);
355 GISelValueTracking *ValueTracking =
nullptr,
356 bool OrNegative =
false);
359 const MachinePointerInfo &MPO);
368 MachineFunction &MF,
const TargetInstrInfo &
TII, MCRegister PhysReg,
417 bool isReg()
const {
return IsReg; }
418 bool isCst()
const {
return !IsReg; }
450 const MachineRegisterInfo &MRI);
454LLVM_ABI std::optional<FPValueAndVReg>
456 bool AllowUndef =
true);
461 const MachineRegisterInfo &MRI,
462 int64_t SplatValue,
bool AllowUndef);
467 const MachineRegisterInfo &MRI,
468 const APInt &SplatValue,
474 const MachineRegisterInfo &MRI,
475 int64_t SplatValue,
bool AllowUndef);
480 const MachineRegisterInfo &MRI,
481 const APInt &SplatValue,
487 const MachineRegisterInfo &MRI,
488 bool AllowUndef =
false);
493 const MachineRegisterInfo &MRI,
494 bool AllowUndef =
false);
503 const MachineRegisterInfo &MRI,
505 bool AllowOpaqueConstants =
true);
512 const MachineRegisterInfo &MRI,
513 bool AllowUndefs =
false);
518 const MachineRegisterInfo &MRI,
519 bool AllowUndefs =
false);
540LLVM_ABI std::optional<RegOrConstant>
546 const MachineRegisterInfo &MRI);
553 const MachineRegisterInfo &MRI);
560 const MachineRegisterInfo &MRI);
567 std::function<
bool(
const Constant *ConstVal)> Match,
568 bool AllowUndefs =
false);
573 bool IsVector,
bool IsFP);
577 bool IsVector,
bool IsFP);
611 bool ConsiderFlagsAndMetadata =
true);
615 bool ConsiderFlagsAndMetadata =
true);
667 : Kind(Kind), Value(Value) {};
675 LLVM_ABI static std::optional<GIConstant>
708 Values.push_back(
Value);
716 "Expected fixed vector or scalar constant");
717 return Values.begin();
720 const_iterator
end()
const {
722 "Expected fixed vector or scalar constant");
728 return Values.size();
734 LLVM_ABI static std::optional<GFConstant>
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
Implement a low-level type suitable for MachineInstr level instruction selection.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
static const char PassName[]
Class for arbitrary precision integers.
Represent the analysis usage information of a pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
ConstantFP - Floating Point Values [float, double].
const_iterator begin() const
static LLVM_ABI std::optional< GFConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
GFConstant(const APFloat &Value, GFConstantKind Kind)
GFConstant(ArrayRef< APFloat > Values)
GFConstantKind getKind() const
Returns the kind of of this constant, e.g, Scalar.
LLVM_ABI APFloat getScalarValue() const
Returns the value, if this constant is a scalar.
const_iterator end() const
LLVM_ABI APInt getScalarValue() const
Returns the value, if this constant is a scalar.
GIConstant(const APInt &Value, GIConstantKind Kind)
static LLVM_ABI std::optional< GIConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
GIConstantKind getKind() const
Returns the kind of of this constant, e.g, Scalar.
GIConstant(ArrayRef< APInt > Values)
This is an important class for using LLVM in a threaded context.
Describe properties that are true of each instruction in the target description file.
MCRegisterClass - Base class of TargetRegisterClass.
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Analysis providing profile information.
RegOrConstant(Register Reg)
RegOrConstant(int64_t Cst)
Holds all the information related to register banks.
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Target-Independent Code Generator Pass Configuration Options.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Register getFunctionLiveInPhysReg(MachineFunction &MF, const TargetInstrInfo &TII, MCRegister PhysReg, const TargetRegisterClass &RC, const DebugLoc &DL, LLT RegTy=LLT())
Return a virtual register corresponding to the incoming argument register PhysReg.
LLVM_ABI std::optional< SmallVector< APInt > > ConstantFoldICmp(unsigned Pred, const Register Op1, const Register Op2, unsigned DstScalarSizeInBits, unsigned ExtOp, const MachineRegisterInfo &MRI)
LLVM_ABI bool isBuildVectorAllZeros(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
LLVM_ABI Type * getTypeForLLT(LLT Ty, LLVMContext &C)
Get the type back from LLT.
LLVM_ABI Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
LLVM_ABI MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
LLVM_ABI const ConstantFP * getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI)
LLVM_ABI bool canCreatePoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
LLVM_ABI std::optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
RelativeUniformCounterPtr Values
LLVM_ABI std::optional< APFloat > ConstantFoldIntToFloat(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
LLVM_ABI std::optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
LLVM_ABI bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
LLVM_ABI std::optional< APFloat > ConstantFoldFPBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
LLVM_ABI void constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
LLVM_ABI std::optional< APInt > ConstantFoldExtOp(unsigned Opcode, const Register Op1, uint64_t Imm, const MachineRegisterInfo &MRI)
LLVM_ABI std::optional< RegOrConstant > getVectorSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI)
GISelWorkList< 4 > SmallInstListTy
LLVM_ABI std::optional< APInt > isConstantOrConstantSplatVector(MachineInstr &MI, const MachineRegisterInfo &MRI)
Determines if MI defines a constant integer or a splat vector of constant integers.
LLVM_ABI bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
LLVM_ABI bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg, std::function< bool(const Constant *ConstVal)> Match, bool AllowUndefs=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant G_B...
LLVM_ABI void reportGISelWarning(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel warning as a missed optimization remark to the LLVMContext's diagnostic stream.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
LLVM_ABI bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Returns true if given the TargetLowering's boolean contents information, the value Val contains a tru...
LLVM_ABI LLVM_READNONE LLT getLCMType(LLT OrigTy, LLT TargetTy)
Return the least common multiple type of OrigTy and TargetTy, by changing the number of vector elemen...
LLVM_ABI std::optional< int64_t > getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
LLVM_ABI std::optional< APInt > ConstantFoldBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI const APInt & getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI)
VReg is defined by a G_CONSTANT, return the corresponding value.
LLVM_ABI bool isConstantOrConstantVector(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowFP=true, bool AllowOpaqueConstants=true)
Return true if the specified instruction is known to be a constant, or a vector of constants.
LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg, MachineRegisterInfo &MRI)
Check if DstReg can be replaced with SrcReg depending on the register constraints.
LLVM_ABI void saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver, SmallInstListTy &DeadInstChain)
LLVM_ABI void reportGISelFailure(MachineFunction &MF, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext's diagnostic stream.
std::tuple< Register, Register, uint64_t, Align, bool, std::vector< LLT > > MemCpyFamilyLoweringInfo
LLVM_ABI std::optional< ValueAndVReg > getAnyConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool LookThroughAnyExt=false)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT or G_FCONST...
LLVM_ABI bool isBuildVectorAllOnes(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
LLVM_ABI bool canCreateUndefOrPoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
canCreateUndefOrPoison returns true if Op can create undef or poison from non-undef & non-poison oper...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI SmallVector< APInt > ConstantFoldVectorBinop(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Tries to constant fold a vector binop with sources Op1 and Op2.
LLVM_ABI std::optional< FPValueAndVReg > getFConstantSplat(Register VReg, const MachineRegisterInfo &MRI, bool AllowUndef=true)
Returns a floating point scalar constant of a build vector splat if it exists.
LLVM_ABI std::optional< APInt > ConstantFoldCastOp(unsigned Opcode, LLT DstTy, const Register Op0, const MachineRegisterInfo &MRI)
LLVM_ABI void extractParts(Register Reg, LLT Ty, int NumParts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Helper function to split a wide generic register into bitwise blocks with the given Type (which impli...
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
LLVM_ABI bool canLowerMemCpyFamily(const MachineInstr &MI, const MachineRegisterInfo &MRI, unsigned MaxLen, Register &Dst, Register &Src, uint64_t &KnownLen, Align &Alignment, bool &DstAlignCanChange, std::vector< LLT > &MemOps)
Matcher for memcpy-like instructions.
LLVM_ABI LLVM_READNONE LLT getCoverTy(LLT OrigTy, LLT TargetTy)
Return smallest type that covers both OrigTy and TargetTy and is multiple of TargetTy.
LLVM_ABI unsigned getInverseGMinMaxOpcode(unsigned MinMaxOpc)
Returns the inverse opcode of MinMaxOpc, which is a generic min/max opcode like G_SMIN.
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
LLVM_ABI std::optional< FPValueAndVReg > getFConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_FCONSTANT returns it...
LLVM_ABI bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
LLVM_ABI std::optional< APFloat > isConstantOrConstantSplatVectorFP(MachineInstr &MI, const MachineRegisterInfo &MRI)
Determines if MI defines a float constant integer or a splat vector of float constant integers.
LLVM_ABI APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
LLVM_ABI bool isBuildVectorConstantSplat(const Register Reg, const MachineRegisterInfo &MRI, int64_t SplatValue, bool AllowUndef)
Return true if the specified register is defined by G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all ...
LLVM_ABI void eraseInstr(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
LLVM_ABI Register constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, Register Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
LLVM_ABI int64_t getICmpTrueVal(const TargetLowering &TLI, bool IsVector, bool IsFP)
Returns an integer representing true, as defined by the TargetBooleanContents.
LLVM_ABI std::optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
LLVM_ABI bool isPreISelGenericFloatingPointOpcode(unsigned Opc)
Returns whether opcode Opc is a pre-isel generic floating-point opcode, having only floating-point op...
LLVM_ABI std::optional< DefinitionAndSourceRegister > getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, and underlying value Register folding away any copies.
LLVM_ABI SmallVector< APInt > ConstantFoldUnaryIntOp(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
Tries to constant fold a unary integer operation (G_CTLZ, G_CTTZ, G_CTPOP and their _ZERO_POISON vari...
LLVM_ABI void eraseInstrs(ArrayRef< MachineInstr * > DeadInstrs, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return true if the given value is known to have exactly one bit set when defined.
LLVM_ABI Register getSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the source register for Reg, folding away any trivial copies.
LLVM_ABI LLVM_READNONE LLT getGCDType(LLT OrigTy, LLT TargetTy)
Return a type where the total size is the greatest common divisor of OrigTy and TargetTy.
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
LLVM_ABI std::optional< int64_t > getIConstantSplatSExtVal(const Register Reg, const MachineRegisterInfo &MRI)
LLVM_ABI bool isAssertMI(const MachineInstr &MI)
Returns true if the instruction MI is one of the assert instructions.
LLVM_ABI void extractVectorParts(Register Reg, unsigned NumElts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Version which handles irregular sub-vector splits.
LLVM_ABI int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
LLVM_ABI bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn't have oth...
MCRegisterClass TargetRegisterClass
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Simple struct used to hold a Register value and the instruction which defines it.
This class contains a discriminated union of information about pointers in memory operands,...
Simple struct used to hold a constant integer value and a virtual register.