16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
54 using MaskType = std::uint_fast32_t;
56 constexpr static unsigned SupportedOp[] = {
57 Instruction::Add, Instruction::FAdd, Instruction::Sub, Instruction::FSub,
58 Instruction::Mul, Instruction::Shl, Instruction::AShr, Instruction::And,
59 Instruction::Or, Instruction::Xor};
61 "SupportedOp is not sorted.");
82 static std::pair<Constant *, unsigned>
84 struct InterchangeableInfo {
87 MaskType Mask = MainOpBIT | XorBIT | OrBIT | AndBIT | SubBIT | AddBIT |
88 MulBIT | AShrBIT | ShlBIT | FSubBIT | FAddBIT;
93 MaskType SeenBefore = 0;
98 bool trySet(MaskType OpcodeInMaskForm, MaskType InterchangeableMask);
99 bool equal(
unsigned Opcode) {
100 return Opcode ==
I->getOpcode() && trySet(MainOpBIT, MainOpBIT);
102 unsigned getOpcode()
const;
103 bool hasDefinedOpcode()
const {
return (Mask & SeenBefore) > 0; }
108 InterchangeableInfo MainOp;
109 InterchangeableInfo AltOp;
116 : MainOp(MainOp), AltOp(AltOp) {}
122 return MainOp.hasCandidateOpcode(Opcode);
129 return !
hasAltOp() || AltOp.hasDefinedOpcode();
132 return MainOp.getOperand(
I);
142 using MaskType = std::uint16_t;
145 static constexpr MaskType AllPreds = (1 << NumPreds) - 1;
147 MaskType Mask = AllPreds;
151 MaskType SeenBefore = 0;
161 static APInt getFamilyConstant(
bool IsComplement,
const APInt &K,
213 bool HasCopyables =
false;
216 unsigned CopyableOpIdx = 0;
220 bool AbsorbCopyableFMulOrFAdd =
false;
224 assert(
valid() &&
"InstructionsState is invalid.");
229 assert(
valid() &&
"InstructionsState is invalid.");
272 return (
getOpcode() == Instruction::ICmp ||
278 bool valid()
const {
return MainOp && AltOp; }
284 bool HasCopyables =
false)
285 : MainOp(MainOp), AltOp(AltOp), HasCopyables(HasCopyables),
307 assert(
valid() &&
"InstructionsState is invalid.");
313 assert(
valid() &&
"InstructionsState is invalid.");
314 return CopyableOpIdx;
319 assert((Idx == 0 || Idx == 2) &&
"Unexpected copyable operand index.");
326 assert(
valid() &&
"InstructionsState is invalid.");
327 return AbsorbCopyableFMulOrFAdd;
332 AbsorbCopyableFMulOrFAdd = Absorb;
356std::pair<Instruction *, SmallVector<Value *>>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLE
signed less or equal
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
This instruction compares its operands according to the predicate given to the constructor.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
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.
Provides information about what library functions are available for the current target.
LLVM Value Representation.
SmallVector< Value * > getOperand(const Instruction *I) const
bool hasDefinedMainOpcode() const
unsigned getAltOpcode() const
bool hasDefinedAltOpcode() const
bool add(const Instruction *I)
bool hasCandidateOpcode(unsigned Opcode) const
Checks if the list of potential opcodes includes Opcode.
BinOpSameOpcodeHelper(const Instruction *MainOp, const Instruction *AltOp=nullptr)
unsigned getMainOpcode() const
Helper class that determines whether a list of integer comparisons can share a single predicate.
static CmpInst::Predicate getSharedPredicate(ArrayRef< Value * > VL, const ICmpInst *Preferred)
Returns the predicate the whole list can share, or BAD_ICMP_PREDICATE when it cannot share a natively...
CmpInst::Predicate getPredicate(const ICmpInst *Preferred) const
Returns the shared predicate, preferring the predicate of Preferred when the whole list can use it,...
bool add(const ICmpInst *CI)
Intersects the convertible predicate set of CI with the running set.
static ConstantInt * getAdjustedConstant(const CmpInst *CI, CmpInst::Predicate Pred)
Returns the adjusted constant operand expressing CI with the predicate Pred, or nullptr if not conver...
static bool canConvertTo(const CmpInst *CI, CmpInst::Predicate Pred)
Checks if the comparison CI can be expressed with the predicate Pred by adjusting its constant operan...
Instruction * getMainOp() const
Instruction * getMatchingMainOpOrAltOp(Instruction *I) const
Checks if the instruction matches either the main or alternate opcode.
bool areInstructionsWithCopyableElements() const
Checks if the state represents copyable instructions.
void setAbsorbCopyableFMulOrFAdd(bool Absorb)
Sets the absorbed-fmul/fadd modeling for copyable fmuls/fadds.
unsigned getAltOpcode() const
bool isCmpOp() const
Checks if main/alt instructions are cmp operations.
static InstructionsState invalid()
static bool isSameOperation(const Instruction *I, const Instruction *Op)
Checks if I is the same operation as Op, distinguishing calls by intrinsic ID (all calls share the Ca...
bool valid() const
Checks if the current state is valid, i.e. has non-null MainOp.
bool isExpandedBinOp(Value *V) const
Checks if the value V is a transformed instruction, compatible either with main or alternate ops.
bool isAddSubLikeOp() const
Checks if main/alt instructions are add/sub/fadd/fsub operations.
bool isShiftOp() const
Checks if main/alt instructions are shift operations.
bool isExpandedOperand(Instruction *I, unsigned Idx) const
Checks if the operand at index Idx of instruction I is an expanded operand.
bool isCopyableElement(Value *V) const
Checks if the value is a copyable element.
bool hasAbsorbedCopyableFMulOrFAdd() const
Checks if copyable fmuls/fadds are absorbed as fmuladd(a, b, -0.0) or fmuladd(1.0,...
bool isAltShuffle() const
Some of the instructions in the list have alternate opcodes.
void setCopyableOpIdx(unsigned Idx)
Sets the index of the operand the copyable value is modeled in.
Instruction * getAltOp() const
InstructionsState()=delete
InstructionsState(Instruction *MainOp, Instruction *AltOp, bool HasCopyables=false)
bool isNonSchedulable(Value *V) const
Checks if the value is non-schedulable.
unsigned getCopyableOpIdx() const
Returns the index of the operand the copyable value is modeled in.
bool isBitwiseLogicOp() const
Checks if main/alt instructions are bitwise logic operations.
bool isMulDivLikeOp() const
Checks if main/alt instructions are mul/div/rem/fmul/fdiv/frem operations.
unsigned getOpcode() const
The main/alternate opcodes for the list of instructions.
A private "module" namespace for types and utilities used by this pass.
SmallVector< SmallVector< Value * > > scanAltAssociativeOperands(const InstructionsState &S, const TargetLibraryInfo &TLI, ArrayRef< Value * > VL, ArrayRef< Value * > Op0, ArrayRef< Value * > Op1, SmallVectorImpl< Value * > &ReassocScalars, SmallBitVector &SubLanes)
Peel the per-lane associative chains of an alternate node into operand columns.
std::pair< Instruction *, SmallVector< Value * > > convertTo(Instruction *I, const InstructionsState &S)
bool isAlternateInstruction(Instruction *I, Instruction *MainOp, Instruction *AltOp, const TargetLibraryInfo &TLI)
Checks if the specified instruction I is an alternate operation for the given MainOp and AltOp instru...
bool isValidForAlternation(unsigned Opcode)
bool hasOnlyAbsorbableCopyableFMulOrFAdds(ArrayRef< Value * > VL)
Checks if every copyable in VL is an absorbable fmul/fadd: the binops die instead of being computed a...
InstructionsState getSameOpcode(ArrayRef< Value * > VL, const TargetLibraryInfo &TLI)
bool isAbsorbableCopyableFMulOrFAdd(const InstructionsState &S, Value *V)
Checks if V is a copyable single-use fmul/fadd, absorbable as fmuladd(a, b, -0.0) or fmuladd(1....
bool isAbsorbableFMulOrFAdd(ArrayRef< Value * > VL, Value *V)
Checks if V is a single-use fmul/fadd with operands outside VL.
This is an optimization pass for GlobalISel generic memory operations.
@ LLVM_MARK_AS_BITMASK_ENUM
constexpr bool is_sorted_constexpr(R &&Range, Cmp C=Cmp{})
Check if elements in a range R are sorted with respect to a comparator C.
DWARFExpression::Operation Op
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.