LLVM 24.0.0git
SLPReductionUtils.h
Go to the documentation of this file.
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"
21
22namespace llvm {
23class DataLayout;
24class FastMathFlags;
25class IRBuilderBase;
26class Instruction;
27class PHINode;
28class Type;
29class Value;
30enum class RecurKind;
31} // namespace llvm
32
33namespace llvm::slpvectorizer {
34
35struct NarrowedLeafInfo;
36
37/// The result of matching a boolean bitmask reduction over narrowed leaves.
38enum 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.
48Type *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.
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.
63bool matchPackedFields(Value *V, unsigned MaxDepth,
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.
70
71/// \returns true if \p I is a candidate instruction for reduction
72/// vectorization.
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.
81 RecurKind RdxKind, Value *Vec,
82 const Value *Root, FastMathFlags FMF,
84
85} // namespace llvm::slpvectorizer
86
87#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the SmallVector class.
This pass exposes codegen information to IR-level passes.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Common base class shared among various IRBuilders.
Definition IRBuilder.h:111
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
A private "module" namespace for types and utilities used by this pass.
bool matchPackedFields(Value *V, unsigned MaxDepth, SmallVectorImpl< Value * > &Fields, SmallVectorImpl< Instruction * > &Chain)
Matches V as the zero-extended fields, placed one after another from the lowest bit and filling V com...
Type * getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy)
Value * tryEmitBoolReduxBitcastCmp(IRBuilderBase &Builder, const TargetTransformInfo &TTI, RecurKind RdxKind, Value *Vec, const Value *Root, FastMathFlags FMF, const TTI::TargetCostKind CostKind)
Emits the booleanized logical and/or reduction of Vec with the i1 root Root as trunc+bitcast+cmp (all...
BoolBitmask isBoolBitmaskRdx(RecurKind RdxKind, const SmallDenseMap< Value *, NarrowedLeafInfo > &NarrowedLeafShifts, const DataLayout &DL)
Instruction * getNonPhiOperand(Instruction *I, PHINode *Phi)
bool isReductionCandidate(Instruction *I)
BoolBitmask
The result of matching a boolean bitmask reduction over narrowed leaves.
This is an optimization pass for GlobalISel generic memory operations.
TargetTransformInfo TTI
RecurKind
These are the kinds of recurrences that we support.
Narrow reduction leaf: the value, the shift applied after widening and the mask applied in the narrow...
Definition SLPUtils.h:429