LLVM 23.0.0git
SLPUtils.h
Go to the documentation of this file.
1//===- SLPUtils.h - SLP Vectorizer free utility 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 helper
10// functions that do not depend on BoUpSLP, InstructionsState, or any other
11// SLP-private type. Splitting them out keeps SLPVectorizer.cpp focused on
12// the build / legality / cost / codegen pipeline.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
18
19#include "llvm/ADT/ArrayRef.h"
20
21#include <optional>
22
23namespace llvm {
24class Instruction;
25class Type;
26class Value;
27} // namespace llvm
28
29namespace llvm::slpvectorizer {
30
31/// \returns True if the value is a constant (but not globals/constant
32/// expressions).
33bool isConstant(Value *V);
34
35/// Checks if \p V is one of vector-like instructions, i.e. undef,
36/// insertelement/extractelement with constant indices for fixed vector type
37/// or extractvalue instruction.
39
40/// \returns the number of elements for Ty.
41unsigned getNumElements(Type *Ty);
42
43/// Returns power-of-2 number of elements in a single register (part), given
44/// the total number of elements \p Size and number of registers (parts) \p
45/// NumParts.
46unsigned getPartNumElems(unsigned Size, unsigned NumParts);
47
48/// Returns correct remaining number of elements, considering total amount
49/// \p Size, (power-of-2 number) of elements in a single register
50/// \p PartNumElems and current register (part) \p Part.
51unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part);
52
53/// \returns True if all of the instructions in \p VL are in the same block.
55
56/// \returns True if all of the values in \p VL are constants (but not
57/// globals/constant expressions).
59
60/// \returns True if all of the values in \p VL are identical or some of them
61/// are UndefValue.
63
64/// \returns True if all of the values in \p VL use the same opcode.
65/// For comparison instructions, also checks if predicates match.
66/// PoisonValues are considered matching. Interchangeable instructions are
67/// not considered.
69
70/// \returns Optional element Idx for Extract{Value,Element} instructions.
71std::optional<unsigned> getExtractIndex(const Instruction *E);
72
73/// \returns True iff every value in \p VL has the same Type as the first.
75
76/// \returns inserting or extracting index of InsertElement / ExtractElement
77/// instruction, using \p Offset as base offset for index. Only instantiated
78/// for InsertElementInst and ExtractElementInst (see SLPUtils.cpp).
79template <typename T>
80std::optional<unsigned> getInsertExtractIndex(const Value *Inst,
81 unsigned Offset);
82
83} // namespace llvm::slpvectorizer
84
85#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
std::optional< unsigned > getExtractIndex(const Instruction *E)
Definition SLPUtils.cpp:123
std::optional< unsigned > getInsertExtractIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:153
bool allSameType(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:147
bool allSameOpcode(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:105
bool isSplat(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:90
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:46
unsigned getPartNumElems(unsigned Size, unsigned NumParts)
Returns power-of-2 number of elements in a single register (part), given the total number of elements...
Definition SLPUtils.cpp:54
bool allConstant(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:84
bool allSameBlock(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:62
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
Definition SLPUtils.cpp:29
unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part)
Returns correct remaining number of elements, considering total amount Size, (power-of-2 number) of e...
Definition SLPUtils.cpp:58
bool isConstant(Value *V)
Definition SLPUtils.cpp:25
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:573
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
ArrayRef(const T &OneElt) -> ArrayRef< T >