File indexing completed on 2026-05-10 08:44:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_IR_VECTORBUILDER_H
0016 #define LLVM_IR_VECTORBUILDER_H
0017
0018 #include <llvm/IR/IRBuilder.h>
0019 #include <llvm/IR/InstrTypes.h>
0020 #include <llvm/IR/Instruction.h>
0021 #include <llvm/IR/Value.h>
0022
0023 namespace llvm {
0024
0025 class VectorBuilder {
0026 public:
0027 enum class Behavior {
0028
0029
0030 ReportAndAbort = 0,
0031
0032
0033
0034
0035 SilentlyReturnNone = 1,
0036 };
0037
0038 private:
0039 IRBuilderBase &Builder;
0040 Behavior ErrorHandling;
0041
0042
0043 Value *Mask;
0044
0045 Value *ExplicitVectorLength;
0046
0047 ElementCount StaticVectorLength;
0048
0049
0050 Value &requestMask();
0051 Value &requestEVL();
0052
0053 void handleError(const char *ErrorMsg) const;
0054 template <typename RetType>
0055 RetType returnWithError(const char *ErrorMsg) const {
0056 handleError(ErrorMsg);
0057 return RetType();
0058 }
0059
0060
0061 Value *createVectorInstructionImpl(Intrinsic::ID VPID, Type *ReturnTy,
0062 ArrayRef<Value *> VecOpArray,
0063 const Twine &Name = Twine());
0064
0065 public:
0066 VectorBuilder(IRBuilderBase &Builder,
0067 Behavior ErrorHandling = Behavior::ReportAndAbort)
0068 : Builder(Builder), ErrorHandling(ErrorHandling), Mask(nullptr),
0069 ExplicitVectorLength(nullptr),
0070 StaticVectorLength(ElementCount::getFixed(0)) {}
0071
0072 Module &getModule() const;
0073 LLVMContext &getContext() const { return Builder.getContext(); }
0074
0075
0076 Value *getAllTrueMask();
0077
0078 VectorBuilder &setMask(Value *NewMask) {
0079 Mask = NewMask;
0080 return *this;
0081 }
0082 VectorBuilder &setEVL(Value *NewExplicitVectorLength) {
0083 ExplicitVectorLength = NewExplicitVectorLength;
0084 return *this;
0085 }
0086 VectorBuilder &setStaticVL(unsigned NewFixedVL) {
0087 StaticVectorLength = ElementCount::getFixed(NewFixedVL);
0088 return *this;
0089 }
0090
0091
0092
0093
0094
0095
0096
0097 Value *createVectorInstruction(unsigned Opcode, Type *ReturnTy,
0098 ArrayRef<Value *> VecOpArray,
0099 const Twine &Name = Twine());
0100
0101
0102
0103
0104
0105
0106 Value *createSimpleReduction(Intrinsic::ID RdxID, Type *ValTy,
0107 ArrayRef<Value *> VecOpArray,
0108 const Twine &Name = Twine());
0109 };
0110
0111 }
0112
0113 #endif