File: PacketBuilder_misc.cpp

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 (124 lines) | stat: -rw-r--r-- 3,929 bytes parent folder | download | duplicates (2)
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
/*========================== begin_copyright_notice ============================

Copyright (C) 2018-2024 Intel Corporation

SPDX-License-Identifier: MIT

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

#include "PacketBuilder.h"
#include "Probe/Assertion.h"

#include "llvmWrapper/IR/DerivedTypes.h"
#include "llvmWrapper/Support/TypeSize.h"

namespace pktz {
Constant *PacketBuilder::C(int Val) {
  return ConstantInt::get(IRB->getInt32Ty(), Val);
}

Constant *PacketBuilder::C(uint32_t Val) {
  return ConstantInt::get(IRB->getInt32Ty(), Val);
}

Constant *PacketBuilder::C(float Val) {
  return ConstantFP::get(IRB->getFloatTy(), Val);
}

Value *PacketBuilder::VIMMED1(int Val) {
  return ConstantVector::getSplat(IGCLLVM::getElementCount(VWidth),
                                  cast<ConstantInt>(C(Val)));
}

Value *PacketBuilder::VIMMED1(uint32_t Val) {
  return ConstantVector::getSplat(IGCLLVM::getElementCount(VWidth),
                                  cast<ConstantInt>(C(Val)));
}

Value *PacketBuilder::VIMMED1(float Val) {
  return ConstantVector::getSplat(IGCLLVM::getElementCount(VWidth),
                                  cast<ConstantFP>(C(Val)));
}

Value *PacketBuilder::VBROADCAST(Value *Src, const llvm::Twine &Name) {
  // check if Src is already a vector
  if (Src->getType()->isVectorTy()) {
    if (auto *CV = dyn_cast<ConstantVector>(Src)) {
      if (CV->getSplatValue()) {
        return VECTOR_SPLAT(VWidth *
                                cast<IGCLLVM::FixedVectorType>(Src->getType())
                                    ->getNumElements(),
                            CV->getSplatValue(), Name);
      }
    }
    return Src;
  }
  return VECTOR_SPLAT(VWidth, Src, Name);
}

CallInst *PacketBuilder::CALL(Value *Callee,
                              const std::initializer_list<Value *> &ArgsList,
                              const llvm::Twine &Name) {
  std::vector<Value *> Args;
  for (auto *Arg : ArgsList)
    Args.push_back(Arg);
  return CALLA(Callee, Args, Name);
}

//////////////////////////////////////////////////////////////////////////
/// @brief C functions called by LLVM IR
//////////////////////////////////////////////////////////////////////////

uint32_t PacketBuilder::getTypeSize(Type *Ty) {
  if (Ty->isStructTy()) {
    uint32_t NumElems = Ty->getStructNumElements();
    auto *ElemTy = Ty->getStructElementType(0);
    return NumElems * getTypeSize(ElemTy);
  }
  if (Ty->isArrayTy()) {
    uint32_t NumElems = Ty->getArrayNumElements();
    auto *ElemTy = Ty->getArrayElementType();
    return NumElems * getTypeSize(ElemTy);
  }
  if (Ty->isIntegerTy()) {
    uint32_t BitSize = Ty->getIntegerBitWidth();
    return BitSize / 8;
  }
  if (Ty->isFloatTy())
    return 4;
  if (Ty->isHalfTy())
    return 2;
  if (Ty->isDoubleTy())
    return 8;
  IGC_ASSERT_MESSAGE(0, "Unimplemented type.");
  return 0;
}

Value *PacketBuilder::BITCAST(Value *V, Type *DestTy, const Twine &Name) {
  return IRB->CreateBitCast(V, DestTy, Name);
}

CallInst *PacketBuilder::CALLA(Value *Callee, ArrayRef<Value *> Args,
                               const Twine &Name, MDNode *FPMathTag) {
  return IRB->CreateCall(Callee, Args, Name, FPMathTag);
}

Value *PacketBuilder::CAST(Instruction::CastOps Op, Value *V, Type *DestTy,
                           const Twine &Name) {
  return IRB->CreateCast(Op, V, DestTy, Name);
}

Value *PacketBuilder::SELECT(Value *C, Value *True, Value *False,
                             const Twine &Name, Instruction *MDFrom) {
  return IRB->CreateSelect(C, True, False, Name, MDFrom);
}

Value *PacketBuilder::VECTOR_SPLAT(unsigned NumElts, Value *V,
                                   const Twine &Name) {
  return IRB->CreateVectorSplat(NumElts, V, Name);
}

Value *PacketBuilder::VEXTRACT(Value *Vec, uint64_t Idx, const Twine &Name) {
  return IRB->CreateExtractElement(Vec, Idx, Name);
}
} // namespace pktz