• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation.   All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * @file builder_misc.h
24 *
25 * @brief miscellaneous builder functions
26 *
27 * Notes:
28 *
29 ******************************************************************************/
30 #pragma once
31 
32 Constant *C(bool i);
33 Constant *C(char i);
34 Constant *C(uint8_t i);
35 Constant *C(int i);
36 Constant *C(int64_t i);
37 Constant *C(uint16_t i);
38 Constant *C(uint32_t i);
39 Constant *C(float i);
40 
41 template<typename Ty>
C(const std::initializer_list<Ty> & constList)42 Constant *C(const std::initializer_list<Ty> &constList)
43 {
44     std::vector<Constant*> vConsts;
45     for(auto i : constList) {
46 
47         vConsts.push_back(C((Ty)i));
48     }
49     return ConstantVector::get(vConsts);
50 }
51 
52 template<typename Ty>
CA(LLVMContext & ctx,ArrayRef<Ty> constList)53 Constant *CA(LLVMContext& ctx, ArrayRef<Ty> constList)
54 {
55     return ConstantDataArray::get(ctx, constList);
56 }
57 
58 Constant *PRED(bool pred);
59 
60 Value *VIMMED1(int i);
61 Value *VIMMED1_16(int i);
62 
63 Value *VIMMED1(uint32_t i);
64 Value *VIMMED1_16(uint32_t i);
65 
66 Value *VIMMED1(float i);
67 Value *VIMMED1_16(float i);
68 
69 Value *VIMMED1(bool i);
70 Value *VIMMED1_16(bool i);
71 
72 Value *VUNDEF(Type* t);
73 
74 Value *VUNDEF_F();
75 Value *VUNDEF_F_16();
76 
77 Value *VUNDEF_I();
78 Value *VUNDEF_I_16();
79 
80 Value *VUNDEF(Type* ty, uint32_t size);
81 
82 Value *VUNDEF_IPTR();
83 
84 Value *VBROADCAST(Value *src, const llvm::Twine& name = "");
85 Value *VBROADCAST_16(Value *src);
86 
87 Value *VRCP(Value *va, const llvm::Twine& name = "");
88 Value *VPLANEPS(Value* vA, Value* vB, Value* vC, Value* &vX, Value* &vY);
89 
90 uint32_t IMMED(Value* i);
91 int32_t S_IMMED(Value* i);
92 
93 Value *GEP(Value* ptr, const std::initializer_list<Value*> &indexList);
94 Value *GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList);
95 Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list<Value*> &indexList);
96 Value *IN_BOUNDS_GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList);
97 
98 CallInst *CALL(Value *Callee, const std::initializer_list<Value*> &args, const llvm::Twine& name = "");
CALL(Value * Callee)99 CallInst *CALL(Value *Callee) { return CALLA(Callee); }
100 CallInst *CALL(Value *Callee, Value* arg);
101 CallInst *CALL2(Value *Callee, Value* arg1, Value* arg2);
102 CallInst *CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3);
103 
104 LoadInst *LOAD(Value *BasePtr, const std::initializer_list<uint32_t> &offset, const llvm::Twine& name = "");
105 LoadInst *LOADV(Value *BasePtr, const std::initializer_list<Value*> &offset, const llvm::Twine& name = "");
106 StoreInst *STORE(Value *Val, Value *BasePtr, const std::initializer_list<uint32_t> &offset);
107 StoreInst *STOREV(Value *Val, Value *BasePtr, const std::initializer_list<Value*> &offset);
108 
VCMPPS_EQ(Value * a,Value * b)109 Value *VCMPPS_EQ(Value* a, Value* b)    { return VCMPPS(a, b, C((uint8_t)_CMP_EQ_OQ)); }
VCMPPS_LT(Value * a,Value * b)110 Value *VCMPPS_LT(Value* a, Value* b)    { return VCMPPS(a, b, C((uint8_t)_CMP_LT_OQ)); }
VCMPPS_LE(Value * a,Value * b)111 Value *VCMPPS_LE(Value* a, Value* b)    { return VCMPPS(a, b, C((uint8_t)_CMP_LE_OQ)); }
VCMPPS_ISNAN(Value * a,Value * b)112 Value *VCMPPS_ISNAN(Value* a, Value* b) { return VCMPPS(a, b, C((uint8_t)_CMP_UNORD_Q)); }
VCMPPS_NEQ(Value * a,Value * b)113 Value *VCMPPS_NEQ(Value* a, Value* b)   { return VCMPPS(a, b, C((uint8_t)_CMP_NEQ_OQ)); }
VCMPPS_GE(Value * a,Value * b)114 Value *VCMPPS_GE(Value* a, Value* b)    { return VCMPPS(a, b, C((uint8_t)_CMP_GE_OQ)); }
VCMPPS_GT(Value * a,Value * b)115 Value *VCMPPS_GT(Value* a, Value* b)    { return VCMPPS(a, b, C((uint8_t)_CMP_GT_OQ)); }
VCMPPS_NOTNAN(Value * a,Value * b)116 Value *VCMPPS_NOTNAN(Value* a, Value* b){ return VCMPPS(a, b, C((uint8_t)_CMP_ORD_Q)); }
117 
118 Value *MASK(Value *vmask);
119 Value *MASK_16(Value *vmask);
120 
121 Value *VMASK(Value *mask);
122 Value *VMASK_16(Value *mask);
123 
124 //////////////////////////////////////////////////////////////////////////
125 /// @brief functions that build IR to call x86 intrinsics directly, or
126 /// emulate them with other instructions if not available on the host
127 //////////////////////////////////////////////////////////////////////////
128 
129 Value *EXTRACT_16(Value *x, uint32_t imm);
130 Value *JOIN_16(Value *a, Value *b);
131 
132 Value *MASKLOADD(Value* src, Value* mask);
133 
134 void Gather4(const SWR_FORMAT format, Value* pSrcBase, Value* byteOffsets,
135                       Value* mask, Value* vGatherComponents[], bool bPackedOutput);
136 
137 Value *GATHERPS(Value *src, Value *pBase, Value *indices, Value *mask, uint8_t scale = 1);
138 Value *GATHERPS_16(Value *src, Value *pBase, Value *indices, Value *mask, uint8_t scale = 1);
139 
140 void GATHER4PS(const SWR_FORMAT_INFO &info, Value* pSrcBase, Value* byteOffsets,
141                Value* mask, Value* vGatherComponents[], bool bPackedOutput);
142 
143 Value *GATHERDD(Value* src, Value* pBase, Value* indices, Value* mask, uint8_t scale = 1);
144 Value *GATHERDD_16(Value *src, Value *pBase, Value *indices, Value *mask, uint8_t scale = 1);
145 
146 void GATHER4DD(const SWR_FORMAT_INFO &info, Value* pSrcBase, Value* byteOffsets,
147                Value* mask, Value* vGatherComponents[], bool bPackedOutput);
148 
149 Value *GATHERPD(Value* src, Value* pBase, Value* indices, Value* mask, uint8_t scale = 1);
150 
151 void SCATTERPS(Value* pDst, Value* vSrc, Value* vOffsets, Value* vMask);
152 
153 void Shuffle8bpcGather4(const SWR_FORMAT_INFO &info, Value* vGatherInput, Value* vGatherOutput[], bool bPackedOutput);
154 void Shuffle16bpcGather4(const SWR_FORMAT_INFO &info, Value* vGatherInput[], Value* vGatherOutput[], bool bPackedOutput);
155 
156 Value *PSHUFB(Value* a, Value* b);
157 Value *PMOVSXBD(Value* a);
158 Value *PMOVSXWD(Value* a);
159 Value *PERMD(Value* a, Value* idx);
160 Value *PERMPS(Value* a, Value* idx);
161 Value *CVTPH2PS(Value* a, const llvm::Twine& name = "");
162 Value *CVTPS2PH(Value* a, Value* rounding);
163 Value *PMAXSD(Value* a, Value* b);
164 Value *PMINSD(Value* a, Value* b);
165 Value *VABSPS(Value* a);
166 Value *FMADDPS(Value* a, Value* b, Value* c);
167 
168 // LLVM removed VPCMPGTD x86 intrinsic.  This emulates that behavior
VPCMPGTD(Value * a,Value * b)169 Value *VPCMPGTD(Value* a, Value* b)
170 {
171     Value* vIndexMask = ICMP_UGT(a,b);
172 
173     // need to set the high bit for x86 intrinsic masks
174     return S_EXT(vIndexMask,VectorType::get(mInt32Ty,JM()->mVWidth));
175 }
176 
177 Value *ICLAMP(Value* src, Value* low, Value* high, const llvm::Twine& name = "");
178 Value *FCLAMP(Value* src, Value* low, Value* high);
179 Value *FCLAMP(Value* src, float low, float high);
180 
181 CallInst *PRINT(const std::string &printStr);
182 CallInst *PRINT(const std::string &printStr,const std::initializer_list<Value*> &printArgs);
183 Value* STACKSAVE();
184 void STACKRESTORE(Value* pSaved);
185 
186 Value* POPCNT(Value* a);
187 
188 Value* DEBUGTRAP();
INT3()189 Value* INT3() { return DEBUGTRAP(); }
190 
191 
192 Value *VEXTRACTI128(Value* a, Constant* imm8);
193 Value *VINSERTI128(Value* a, Value* b, Constant* imm8);
194 
195 // rdtsc buckets macros
196 void RDTSC_START(Value* pBucketMgr, Value* pId);
197 void RDTSC_STOP(Value* pBucketMgr, Value* pId);
198 
199 Value* CreateEntryAlloca(Function* pFunc, Type* pType);
200 Value* CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize);
201 
202 // Static stack allocations for scatter operations
203 Value* pScatterStackSrc{ nullptr };
204 Value* pScatterStackOffsets{ nullptr };
205 
206 
207 uint32_t GetTypeSize(Type* pType);
208