| 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/Analysis/TargetTransformInfo.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | class FastMathFlags; |
| 22 | class IRBuilderBase; |
| 23 | class Instruction; |
| 24 | class PHINode; |
| 25 | class Type; |
| 26 | class Value; |
| 27 | enum class RecurKind; |
| 28 | } // namespace llvm |
| 29 | |
| 30 | namespace llvm::slpvectorizer { |
| 31 | |
| 32 | /// \returns the wide leaf type if the logical and/or reduction \p RdxKind |
| 33 | /// with the i1 root type \p RootTy and the leaf type \p LeafTy is a |
| 34 | /// booleanized reduction (performed in the wide leaf type, bit 0 of the |
| 35 | /// result is the final value), nullptr otherwise. |
| 36 | Type *getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy); |
| 37 | |
| 38 | /// \returns the first operand of \p I that does not match \p Phi. If |
| 39 | /// the operand is not an instruction, returns nullptr. |
| 40 | Instruction *getNonPhiOperand(Instruction *I, PHINode *Phi); |
| 41 | |
| 42 | /// \returns true if \p I is a candidate instruction for reduction |
| 43 | /// vectorization. |
| 44 | bool isReductionCandidate(Instruction *I); |
| 45 | |
| 46 | /// Emits the booleanized logical and/or reduction of \p Vec with the i1 root |
| 47 | /// \p Root as trunc+bitcast+cmp (all-ones comparison for And, zero for Or) if |
| 48 | /// it is cheaper than the wide reduction plus the result trunc. \returns the |
| 49 | /// i1 result or nullptr if the wide reduction form is cheaper. |
| 50 | Value *tryEmitBoolReduxBitcastCmp(IRBuilderBase &Builder, |
| 51 | const TargetTransformInfo &TTI, |
| 52 | RecurKind RdxKind, Value *Vec, |
| 53 | const Value *Root, FastMathFlags FMF, |
| 54 | TargetTransformInfo::TargetCostKind CostKind); |
| 55 | |
| 56 | } // namespace llvm::slpvectorizer |
| 57 | |
| 58 | #endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H |
| 59 | |