]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Transforms/Vectorize/VPlanBuilder.h
MFV r328225: 8603 rename zilog's "zl_writer_lock" to "zl_issuer_lock"
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Transforms / Vectorize / VPlanBuilder.h
1 //===- VPlanBuilder.h - A VPlan utility for constructing VPInstructions ---===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file provides a VPlan-based builder utility analogous to IRBuilder.
12 /// It provides an instruction-level API for generating VPInstructions while
13 /// abstracting away the Recipe manipulation details.
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_BUILDER_H
17 #define LLVM_TRANSFORMS_VECTORIZE_VPLAN_BUILDER_H
18
19 #include "VPlan.h"
20
21 namespace llvm {
22
23 class VPBuilder {
24 private:
25   VPBasicBlock *BB = nullptr;
26   VPBasicBlock::iterator InsertPt = VPBasicBlock::iterator();
27
28   VPInstruction *createInstruction(unsigned Opcode,
29                                    std::initializer_list<VPValue *> Operands) {
30     VPInstruction *Instr = new VPInstruction(Opcode, Operands);
31     BB->insert(Instr, InsertPt);
32     return Instr;
33   }
34
35 public:
36   VPBuilder() {}
37
38   /// \brief This specifies that created VPInstructions should be appended to
39   /// the end of the specified block.
40   void setInsertPoint(VPBasicBlock *TheBB) {
41     assert(TheBB && "Attempting to set a null insert point");
42     BB = TheBB;
43     InsertPt = BB->end();
44   }
45
46   VPValue *createNot(VPValue *Operand) {
47     return createInstruction(VPInstruction::Not, {Operand});
48   }
49
50   VPValue *createAnd(VPValue *LHS, VPValue *RHS) {
51     return createInstruction(Instruction::BinaryOps::And, {LHS, RHS});
52   }
53
54   VPValue *createOr(VPValue *LHS, VPValue *RHS) {
55     return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS});
56   }
57 };
58
59 } // namespace llvm
60
61 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_BUILDER_H