LLVM 19.0.0git
VectorBuilder.h
Go to the documentation of this file.
1//===- llvm/VectorBuilder.h - Builder for VP Intrinsics ---------*- 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// This file defines the VectorBuilder class, which is used as a convenient way
10// to create VP intrinsics as if they were LLVM instructions with a consistent
11// and simplified interface.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_VECTORBUILDER_H
16#define LLVM_IR_VECTORBUILDER_H
17
19#include <llvm/IR/IRBuilder.h>
20#include <llvm/IR/InstrTypes.h>
21#include <llvm/IR/Instruction.h>
22#include <llvm/IR/Value.h>
23
24namespace llvm {
25
27public:
28 enum class Behavior {
29 // Abort if the requested VP intrinsic could not be created.
30 // This is useful for strict consistency.
32
33 // Return a default-initialized value if the requested VP intrinsic could
34 // not be created.
35 // This is useful for a defensive fallback to non-VP code.
37 };
38
39private:
40 IRBuilderBase &Builder;
41 Behavior ErrorHandling;
42
43 // Explicit mask parameter.
44 Value *Mask;
45 // Explicit vector length parameter.
46 Value *ExplicitVectorLength;
47 // Compile-time vector length.
48 ElementCount StaticVectorLength;
49
50 // Get mask/evl value handles for the current configuration.
51 Value &requestMask();
52 Value &requestEVL();
53
54 void handleError(const char *ErrorMsg) const;
55 template <typename RetType>
56 RetType returnWithError(const char *ErrorMsg) const {
57 handleError(ErrorMsg);
58 return RetType();
59 }
60
61 /// Helper function for creating VP intrinsic call.
62 Value *createVectorInstructionImpl(Intrinsic::ID VPID, Type *ReturnTy,
63 ArrayRef<Value *> VecOpArray,
64 const Twine &Name = Twine());
65
66public:
68 Behavior ErrorHandling = Behavior::ReportAndAbort)
69 : Builder(Builder), ErrorHandling(ErrorHandling), Mask(nullptr),
70 ExplicitVectorLength(nullptr),
71 StaticVectorLength(ElementCount::getFixed(0)) {}
72
73 Module &getModule() const;
74 LLVMContext &getContext() const { return Builder.getContext(); }
75
76 // All-true mask for the currently configured explicit vector length.
78
80 Mask = NewMask;
81 return *this;
82 }
83 VectorBuilder &setEVL(Value *NewExplicitVectorLength) {
84 ExplicitVectorLength = NewExplicitVectorLength;
85 return *this;
86 }
87 VectorBuilder &setStaticVL(unsigned NewFixedVL) {
88 StaticVectorLength = ElementCount::getFixed(NewFixedVL);
89 return *this;
90 }
91 // TODO: setStaticVL(ElementCount) for scalable types.
92
93 // Emit a VP intrinsic call that mimics a regular instruction.
94 // This operation behaves according to the VectorBuilderBehavior.
95 // \p Opcode The functional instruction opcode of the emitted intrinsic.
96 // \p ReturnTy The return type of the operation.
97 // \p VecOpArray The operand list.
98 Value *createVectorInstruction(unsigned Opcode, Type *ReturnTy,
99 ArrayRef<Value *> VecOpArray,
100 const Twine &Name = Twine());
101
102 /// Emit a VP reduction intrinsic call for recurrence kind.
103 /// \param Kind The kind of recurrence
104 /// \param ValTy The type of operand which the reduction operation is
105 /// performed.
106 /// \param VecOpArray The operand list.
108 ArrayRef<Value *> VecOpArray,
109 const Twine &Name = Twine());
110};
111
112} // namespace llvm
113
114#endif // LLVM_IR_VECTORBUILDER_H
std::string Name
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:311
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
LLVMContext & getContext() const
Definition: IRBuilder.h:173
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
LLVMContext & getContext() const
Definition: VectorBuilder.h:74
VectorBuilder(IRBuilderBase &Builder, Behavior ErrorHandling=Behavior::ReportAndAbort)
Definition: VectorBuilder.h:67
VectorBuilder & setStaticVL(unsigned NewFixedVL)
Definition: VectorBuilder.h:87
VectorBuilder & setEVL(Value *NewExplicitVectorLength)
Definition: VectorBuilder.h:83
Module & getModule() const
VectorBuilder & setMask(Value *NewMask)
Definition: VectorBuilder.h:79
Value * createSimpleTargetReduction(RecurKind Kind, Type *ValTy, ArrayRef< Value * > VecOpArray, const Twine &Name=Twine())
Emit a VP reduction intrinsic call for recurrence kind.
Value * createVectorInstruction(unsigned Opcode, Type *ReturnTy, ArrayRef< Value * > VecOpArray, const Twine &Name=Twine())
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
RecurKind
These are the kinds of recurrences that we support.
Definition: IVDescriptors.h:34