File: PacketBuilder.h

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (183 lines) | stat: -rw-r--r-- 7,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*========================== begin_copyright_notice ============================

Copyright (C) 2018-2024 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#ifndef PACKET_BUILDER_H
#define PACKET_BUILDER_H

#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"

#include "llvmWrapper/IR/DerivedTypes.h"
#include "llvmWrapper/IR/IRBuilder.h"
#include "llvmWrapper/IR/InstrTypes.h"
#include "llvmWrapper/IR/Module.h"
#include "llvmWrapper/Support/Alignment.h"

#include <deque>
#include <unordered_map>

using namespace llvm;

namespace pktz {
struct PacketBuilder {
public:
  PacketBuilder(Module *MIn, uint32_t Width = 16);
  virtual ~PacketBuilder() {
    if (IRB)
      delete IRB;
  }
  PacketBuilder(const PacketBuilder &) = delete;
  PacketBuilder &operator=(const PacketBuilder &) = delete;

  LLVMContext &getContext() { return M->getContext(); }

  IGCLLVM::Module *M;
  IGCLLVM::IRBuilder<> *IRB;

  uint32_t VWidth;   // vector width target simd

  // Built in types: scalar
  Type *Int1Ty;
  Type *Int8Ty;
  Type *Int16Ty;
  Type *Int32Ty;
  Type *Int64Ty;
  Type *FP32Ty;

  // Built in types: target SIMD
  Type *SimdFP32Ty;
  Type *SimdInt32Ty;

  void setTargetWidth(uint32_t Width);
  Type *getVectorType(Type *Ty);

  Value *VLOG2PS(Value *A);
  Value *VEXP2PS(Value *A);

  Value *ADD(Value *LHS, Value *RHS, const Twine &Name = "",
             bool HasNUW = false, bool HasNSW = false);
  Value *AND(Value *LHS, Value *RHS, const Twine &Name = "");
  Value *AND(Value *LHS, uint64_t RHS, const Twine &Name = "");
  Value *ASHR(Value *LHS, uint64_t RHS, const Twine &Name = "",
              bool IsExact = false);
  Value *EXP2(Value *A, const Twine &Name = "");
  Value *FABS(Value *A, const Twine &Name = "");
  Value *FADD(Value *LHS, Value *RHS, const Twine &Name = "",
              MDNode *FPMathTag = nullptr);
  Value *FCMP_OEQ(Value *LHS, Value *RHS, const Twine &Name = "",
                  MDNode *FPMathTag = nullptr);
  Value *FCMP_OLT(Value *LHS, Value *RHS, const Twine &Name = "",
                  MDNode *FPMathTag = nullptr);
  Value *FCMP_UNO(Value *LHS, Value *RHS, const Twine &Name = "",
                  MDNode *FPMathTag = nullptr);
  Value *FMUL(Value *LHS, Value *RHS, const Twine &Name = "",
              MDNode *FPMathTag = nullptr);
  Value *FP_TO_SI(Value *V, Type *DestTy, const Twine &Name = "");
  Value *FSUB(Value *LHS, Value *RHS, const Twine &Name = "",
              MDNode *FPMathTag = nullptr);
  Value *MUL(Value *LHS, Value *RHS, const Twine &Name = "",
             bool HasNUW = false, bool HasNSW = false);
  Value *NOT(Value *V, const Twine &Name = "");
  Value *OR(Value *LHS, Value *RHS, const Twine &Name = "");
  Value *SHL(Value *LHS, Value *RHS, const Twine &Name = "",
             bool HasNUW = false, bool HasNSW = false);
  Value *SHL(Value *LHS, uint64_t RHS, const Twine &Name = "",
             bool HasNUW = false, bool HasNSW = false);
  Value *SI_TO_FP(Value *V, Type *DestTy, const Twine &Name = "");
  Value *SUB(Value *LHS, Value *RHS, const Twine &Name = "",
             bool HasNUW = false, bool HasNSW = false);
  Value *S_EXT(Value *V, Type *DestTy, const Twine &Name = "");
  Value *TRUNC(Value *V, Type *DestTy, const Twine &Name = "");
  Value *VMAXPS(Value *A, Value *B, const Twine &Name = "");
  Value *VMINPS(Value *A, Value *B, const Twine &Name = "");
  Value *VSQRTPS(Value *A, const Twine &Name = "");
  Value *UI_TO_FP(Value *V, Type *DestTy, const Twine &Name = "");

  //#include "PacketBuilder_misc.h"
  Constant *C(int Val);
  Constant *C(uint32_t Val);
  Constant *C(float Val);

  template <typename T> Constant *C(const std::initializer_list<T> &ConstList) {
    std::vector<Constant *> Consts;
    for (T Val : ConstList) {
      Consts.push_back(C(Val));
    }
    return ConstantVector::get(Consts);
  }

  template <typename T> Constant *CInc(uint32_t Base, uint32_t Count) {
    std::vector<Constant *> Consts;
    for (uint32_t Idx = 0; Idx < Count; Idx++) {
      Consts.push_back(C(static_cast<T>(Base + Idx)));
    }
    return ConstantVector::get(Consts);
  }

  Value *VIMMED1(int Val);
  Value *VIMMED1(uint32_t Val);
  Value *VIMMED1(float Val);

  Value *VBROADCAST(Value *Src, const llvm::Twine &Name = "");

  CallInst *CALL(Value *Callee, const std::initializer_list<Value *> &ArgsList,
                 const llvm::Twine &Name = "");

  //////////////////////////////////////////////////////////////////////////
  /// @brief functions that build IR to call x86 intrinsics directly, or
  /// emulate them with other instructions if not available on the host
  //////////////////////////////////////////////////////////////////////////

  uint32_t getTypeSize(Type *Ty);

  Value *BITCAST(Value *V, Type *DestTy, const Twine &Name = "");
  CallInst *CALLA(Value *Callee, ArrayRef<Value *> Args = None,
                  const Twine &Name = "", MDNode *FPMathTag = nullptr);
  Value *CAST(Instruction::CastOps Op, Value *V, Type *DestTy,
              const Twine &Name = "");
  ReturnInst *RET(Value *V) { return IRB->CreateRet(V); }
  Value *SELECT(Value *C, Value *True, Value *False, const Twine &Name = "",
                Instruction *MDFrom = nullptr);
  Value *VECTOR_SPLAT(unsigned NumElts, Value *V, const Twine &Name = "");
  Value *VEXTRACT(Value *Vec, uint64_t Idx, const Twine &Name = "");

  // #include "PacketBuilder_mem.h"
protected:
  void assertMemoryUsageParams(Value *Ptr);

public:
  GetElementPtrInst *GEP(Type *Ty, Value *Ptr,
                         const std::initializer_list<uint32_t> &IndexList,
                         const Twine &Name = "");
  GetElementPtrInst *GEPA(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
                          const Twine &Name = "");
  LoadInst *LOAD(Type *Ty, Value *Ptr, const Twine &Name = "");
  LoadInst *LOAD(Type *Ty, Value *BasePtr,
                 const std::initializer_list<uint32_t> &IndexList,
                 const llvm::Twine &Name = "");
  LoadInst *ALIGNED_LOAD(Type *Ty, Value *Ptr, IGCLLVM::Align Align,
                         const Twine &Name = "");
  AllocaInst *ALLOCA(Type *Ty, Value *ArraySize = nullptr,
                     const Twine &Name = "");
  Value *INT_TO_PTR(Value *V, Type *DestTy, const Twine &Name = "");
  CallInst *MASKED_GATHER(Type *Ty, Value *Ptrs, unsigned Align, Value *Mask = nullptr,
                          Value *PassThru = nullptr, const Twine &Name = "");
  CallInst *MASKED_SCATTER(Value *Val, Value *Ptrs, unsigned Align,
                           Value *Mask = nullptr);
  CallInst *MASKED_STORE(Value *Val, Value *Ptr, unsigned Align, Value *Mask);
  StoreInst *STORE(Value *Val, Value *Ptr, bool IsVolatile = false);
};
} // end of namespace pktz

#endif // PACKET_BUILDER_H