LLVM  16.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 
18 #include <llvm/IR/IRBuilder.h>
19 #include <llvm/IR/InstrTypes.h>
20 #include <llvm/IR/Instruction.h>
21 #include <llvm/IR/Value.h>
22 
23 namespace llvm {
24 
26 public:
27  enum class Behavior {
28  // Abort if the requested VP intrinsic could not be created.
29  // This is useful for strict consistency.
30  ReportAndAbort = 0,
31 
32  // Return a default-initialized value if the requested VP intrinsic could
33  // not be created.
34  // This is useful for a defensive fallback to non-VP code.
36  };
37 
38 private:
39  IRBuilderBase &Builder;
40  Behavior ErrorHandling;
41 
42  // Explicit mask parameter.
43  Value *Mask;
44  // Explicit vector length parameter.
45  Value *ExplicitVectorLength;
46  // Compile-time vector length.
47  ElementCount StaticVectorLength;
48 
49  // Get mask/evl value handles for the current configuration.
50  Value &requestMask();
51  Value &requestEVL();
52 
53  void handleError(const char *ErrorMsg) const;
54  template <typename RetType>
55  RetType returnWithError(const char *ErrorMsg) const {
56  handleError(ErrorMsg);
57  return RetType();
58  }
59 
60 public:
62  Behavior ErrorHandling = Behavior::ReportAndAbort)
63  : Builder(Builder), ErrorHandling(ErrorHandling), Mask(nullptr),
64  ExplicitVectorLength(nullptr),
65  StaticVectorLength(ElementCount::getFixed(0)) {}
66 
67  Module &getModule() const;
68  LLVMContext &getContext() const { return Builder.getContext(); }
69 
70  // All-true mask for the currently configured explicit vector length.
72 
74  Mask = NewMask;
75  return *this;
76  }
77  VectorBuilder &setEVL(Value *NewExplicitVectorLength) {
78  ExplicitVectorLength = NewExplicitVectorLength;
79  return *this;
80  }
81  VectorBuilder &setStaticVL(unsigned NewFixedVL) {
82  StaticVectorLength = ElementCount::getFixed(NewFixedVL);
83  return *this;
84  }
85  // TODO: setStaticVL(ElementCount) for scalable types.
86 
87  // Emit a VP intrinsic call that mimics a regular instruction.
88  // This operation behaves according to the VectorBuilderBehavior.
89  // \p Opcode The functional instruction opcode of the emitted intrinsic.
90  // \p ReturnTy The return type of the operation.
91  // \p VecOpArray The operand list.
92  Value *createVectorInstruction(unsigned Opcode, Type *ReturnTy,
93  ArrayRef<Value *> VecOpArray,
94  const Twine &Name = Twine());
95 };
96 
97 } // namespace llvm
98 
99 #endif // LLVM_IR_VECTORBUILDER_H
llvm::VectorBuilder::setStaticVL
VectorBuilder & setStaticVL(unsigned NewFixedVL)
Definition: VectorBuilder.h:81
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::ElementCount
Definition: TypeSize.h:404
llvm::VectorBuilder::Behavior
Behavior
Definition: VectorBuilder.h:27
llvm::VectorBuilder::Behavior::ReportAndAbort
@ ReportAndAbort
llvm::VectorBuilder::Behavior::SilentlyReturnNone
@ SilentlyReturnNone
llvm::VectorBuilder::createVectorInstruction
Value * createVectorInstruction(unsigned Opcode, Type *ReturnTy, ArrayRef< Value * > VecOpArray, const Twine &Name=Twine())
Definition: VectorBuilder.cpp:56
llvm::VectorBuilder::getAllTrueMask
Value * getAllTrueMask()
Definition: VectorBuilder.cpp:34
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Instruction.h
InstrTypes.h
llvm::VectorBuilder::setMask
VectorBuilder & setMask(Value *NewMask)
Definition: VectorBuilder.h:73
llvm::VectorBuilder
Definition: VectorBuilder.h:25
llvm::LinearPolySize< ElementCount >::getFixed
static ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:283
llvm::VectorBuilder::VectorBuilder
VectorBuilder(IRBuilderBase &Builder, Behavior ErrorHandling=Behavior::ReportAndAbort)
Definition: VectorBuilder.h:61
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
IRBuilder.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:66
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::VectorBuilder::setEVL
VectorBuilder & setEVL(Value *NewExplicitVectorLength)
Definition: VectorBuilder.h:77
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:94
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::VectorBuilder::getModule
Module & getModule() const
Definition: VectorBuilder.cpp:30
llvm::VectorBuilder::getContext
LLVMContext & getContext() const
Definition: VectorBuilder.h:68
Value.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74