| 1 | //===- SLPReductionUtils.h - SLP reduction match helpers -------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Internal header used by SLPVectorizer.cpp. It declares free reduction |
| 10 | // pattern-match helpers that do not depend on BoUpSLP or any other SLP-private |
| 11 | // type. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H |
| 16 | #define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H |
| 17 | |
| 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | #include "llvm/Analysis/TargetTransformInfo.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class DataLayout; |
| 24 | class FastMathFlags; |
| 25 | class IRBuilderBase; |
| 26 | class Instruction; |
| 27 | class PHINode; |
| 28 | class Type; |
| 29 | class Value; |
| 30 | enum class RecurKind; |
| 31 | } // namespace llvm |
| 32 | |
| 33 | namespace llvm::slpvectorizer { |
| 34 | |
| 35 | struct NarrowedLeafInfo; |
| 36 | |
| 37 | /// The result of matching a boolean bitmask reduction over narrowed leaves. |
| 38 | enum class BoolBitmask { |
| 39 | None, // not a boolean bitmask reduction |
| 40 | NoMask, // bitmask; the absorbed masks are redundant |
| 41 | NeedMask, // bitmask; the absorbed masks must be applied before the zero test |
| 42 | }; |
| 43 | |
| 44 | /// \returns the wide leaf type if the logical and/or reduction \p RdxKind |
| 45 | /// with the i1 root type \p RootTy and the leaf type \p LeafTy is a |
| 46 | /// booleanized reduction (performed in the wide leaf type, bit 0 of the |
| 47 | /// result is the final value), nullptr otherwise. |
| 48 | Type *getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy); |
| 49 | |
| 50 | /// \returns the BoolBitmask match if the or-reduction of the narrowed leaves |
| 51 | /// packs each boolean (0 or 1 after masking) leaf into its own bit position |
| 52 | /// 0..N-1, i.e. it is a bitcast of the per-lane zero tests to an iN integer; |
| 53 | /// BoolBitmask::None otherwise. |
| 54 | BoolBitmask isBoolBitmaskRdx( |
| 55 | RecurKind RdxKind, |
| 56 | const SmallDenseMap<Value *, NarrowedLeafInfo> &NarrowedLeafShifts, |
| 57 | const DataLayout &DL); |
| 58 | |
| 59 | /// Matches \p V as the zero-extended fields, placed one after another from the |
| 60 | /// lowest bit and filling \p V completely. The instructions are looked through |
| 61 | /// up to \p MaxDepth. Appends the fields in the order of their positions to |
| 62 | /// \p Fields and the instructions of the pack to \p Chain. |
| 63 | bool matchPackedFields(Value *V, unsigned MaxDepth, |
| 64 | SmallVectorImpl<Value *> &Fields, |
| 65 | SmallVectorImpl<Instruction *> &Chain); |
| 66 | |
| 67 | /// \returns the first operand of \p I that does not match \p Phi. If |
| 68 | /// the operand is not an instruction, returns nullptr. |
| 69 | Instruction *getNonPhiOperand(Instruction *I, PHINode *Phi); |
| 70 | |
| 71 | /// \returns true if \p I is a candidate instruction for reduction |
| 72 | /// vectorization. |
| 73 | bool isReductionCandidate(Instruction *I); |
| 74 | |
| 75 | /// Emits the booleanized logical and/or reduction of \p Vec with the i1 root |
| 76 | /// \p Root as trunc+bitcast+cmp (all-ones comparison for And, zero for Or) if |
| 77 | /// it is cheaper than the wide reduction plus the result trunc. \returns the |
| 78 | /// i1 result or nullptr if the wide reduction form is cheaper. |
| 79 | Value *tryEmitBoolReduxBitcastCmp(IRBuilderBase &Builder, |
| 80 | const TargetTransformInfo &TTI, |
| 81 | RecurKind RdxKind, Value *Vec, |
| 82 | const Value *Root, FastMathFlags FMF, |
| 83 | TargetTransformInfo::TargetCostKind CostKind); |
| 84 | |
| 85 | } // namespace llvm::slpvectorizer |
| 86 | |
| 87 | #endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H |
| 88 | |