16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
51 using MaskType = std::uint_fast32_t;
53 constexpr static unsigned SupportedOp[] = {
54 Instruction::Add, Instruction::FAdd, Instruction::Sub, Instruction::FSub,
55 Instruction::Mul, Instruction::Shl, Instruction::AShr, Instruction::And,
56 Instruction::Or, Instruction::Xor};
58 "SupportedOp is not sorted.");
79 static std::pair<Constant *, unsigned>
81 struct InterchangeableInfo {
84 MaskType Mask = MainOpBIT | XorBIT | OrBIT | AndBIT | SubBIT | AddBIT |
85 MulBIT | AShrBIT | ShlBIT | FSubBIT | FAddBIT;
90 MaskType SeenBefore = 0;
95 bool trySet(MaskType OpcodeInMaskForm, MaskType InterchangeableMask);
96 bool equal(
unsigned Opcode) {
97 return Opcode ==
I->getOpcode() && trySet(MainOpBIT, MainOpBIT);
99 unsigned getOpcode()
const;
100 bool hasDefinedOpcode()
const {
return (Mask & SeenBefore) > 0; }
105 InterchangeableInfo MainOp;
106 InterchangeableInfo AltOp;
113 : MainOp(MainOp), AltOp(AltOp) {}
119 return MainOp.hasCandidateOpcode(Opcode);
126 return !
hasAltOp() || AltOp.hasDefinedOpcode();
129 return MainOp.getOperand(
I);
160 bool HasCopyables =
false;
163 unsigned CopyableOpIdx = 0;
167 bool AbsorbCopyableFMulOrFAdd =
false;
171 assert(
valid() &&
"InstructionsState is invalid.");
176 assert(
valid() &&
"InstructionsState is invalid.");
219 return (
getOpcode() == Instruction::ICmp ||
225 bool valid()
const {
return MainOp && AltOp; }
231 bool HasCopyables =
false)
232 : MainOp(MainOp), AltOp(AltOp), HasCopyables(HasCopyables),
254 assert(
valid() &&
"InstructionsState is invalid.");
260 assert(
valid() &&
"InstructionsState is invalid.");
261 return CopyableOpIdx;
266 assert((Idx == 0 || Idx == 2) &&
"Unexpected copyable operand index.");
273 assert(
valid() &&
"InstructionsState is invalid.");
274 return AbsorbCopyableFMulOrFAdd;
279 AbsorbCopyableFMulOrFAdd = Absorb;
303std::pair<Instruction *, SmallVector<Value *>>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is an important base class in LLVM.
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
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.