a51aad05a06bde52acd449c29bcc8cd1f547e840
[mesa.git] / src / gallium / drivers / swr / rasterizer / jitter / builder_misc.h
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>
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>
53 Constant *CA(LLVMContext& ctx, ArrayRef<Ty> constList)
54 {
55 return ConstantDataArray::get(ctx, constList);
56 }
57
58 template<typename Ty>
59 Constant *CInc(uint32_t base, uint32_t count)
60 {
61 std::vector<Constant*> vConsts;
62
63 for(uint32_t i = 0; i < count; i++) {
64 vConsts.push_back(C((Ty)base));
65 base++;
66 }
67 return ConstantVector::get(vConsts);
68 }
69
70 Constant *PRED(bool pred);
71
72 Value *VIMMED1(int i);
73 Value *VIMMED1_16(int i);
74
75 Value *VIMMED1(uint32_t i);
76 Value *VIMMED1_16(uint32_t i);
77
78 Value *VIMMED1(float i);
79 Value *VIMMED1_16(float i);
80
81 Value *VIMMED1(bool i);
82 Value *VIMMED1_16(bool i);
83
84 Value *VUNDEF(Type* t);
85
86 Value *VUNDEF_F();
87 Value *VUNDEF_F_16();
88
89 Value *VUNDEF_I();
90 Value *VUNDEF_I_16();
91
92 Value *VUNDEF(Type* ty, uint32_t size);
93
94 Value *VUNDEF_IPTR();
95
96 Value *VBROADCAST(Value *src, const llvm::Twine& name = "");
97 Value *VBROADCAST_16(Value *src);
98
99 Value *VRCP(Value *va, const llvm::Twine& name = "");
100 Value *VPLANEPS(Value* vA, Value* vB, Value* vC, Value* &vX, Value* &vY);
101
102 uint32_t IMMED(Value* i);
103 int32_t S_IMMED(Value* i);
104
105 CallInst *CALL(Value *Callee, const std::initializer_list<Value*> &args, const llvm::Twine& name = "");
106 CallInst *CALL(Value *Callee) { return CALLA(Callee); }
107 CallInst *CALL(Value *Callee, Value* arg);
108 CallInst *CALL2(Value *Callee, Value* arg1, Value* arg2);
109 CallInst *CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3);
110
111 Value *MASK(Value *vmask);
112 Value *MASK_16(Value *vmask);
113
114 Value *VMASK(Value *mask);
115 Value *VMASK_16(Value *mask);
116
117 Value *VMOVMSK(Value *mask);
118
119 //////////////////////////////////////////////////////////////////////////
120 /// @brief functions that build IR to call x86 intrinsics directly, or
121 /// emulate them with other instructions if not available on the host
122 //////////////////////////////////////////////////////////////////////////
123
124 Value *EXTRACT_16(Value *x, uint32_t imm);
125 Value *JOIN_16(Value *a, Value *b);
126
127 Value *PSHUFB(Value* a, Value* b);
128 Value *PMOVSXBD(Value* a);
129 Value *PMOVSXWD(Value* a);
130 Value *CVTPH2PS(Value* a, const llvm::Twine& name = "");
131 Value *CVTPS2PH(Value* a, Value* rounding);
132 Value *PMAXSD(Value* a, Value* b);
133 Value *PMINSD(Value* a, Value* b);
134 Value *PMAXUD(Value* a, Value* b);
135 Value *PMINUD(Value* a, Value* b);
136 Value *VABSPS(Value* a);
137 Value *FMADDPS(Value* a, Value* b, Value* c);
138
139 Value *ICLAMP(Value* src, Value* low, Value* high, const llvm::Twine& name = "");
140 Value *FCLAMP(Value* src, Value* low, Value* high);
141 Value *FCLAMP(Value* src, float low, float high);
142
143 CallInst *PRINT(const std::string &printStr);
144 CallInst *PRINT(const std::string &printStr,const std::initializer_list<Value*> &printArgs);
145
146 Value* VPOPCNT(Value* a);
147
148 Value* INT3() { return DEBUGTRAP(); }
149
150
151 Value *VEXTRACTI128(Value* a, Constant* imm8);
152 Value *VINSERTI128(Value* a, Value* b, Constant* imm8);
153
154 // rdtsc buckets macros
155 void RDTSC_START(Value* pBucketMgr, Value* pId);
156 void RDTSC_STOP(Value* pBucketMgr, Value* pId);
157
158 Value* CreateEntryAlloca(Function* pFunc, Type* pType);
159 Value* CreateEntryAlloca(Function* pFunc, Type* pType, Value* pArraySize);
160
161 uint32_t GetTypeSize(Type* pType);