1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
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:
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
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
23 * @file builder_misc.h
25 * @brief miscellaneous builder functions
29 ******************************************************************************/
34 Constant
* C(uint8_t i
);
36 Constant
* C(int64_t i
);
37 Constant
* C(uint64_t i
);
38 Constant
* C(uint16_t i
);
39 Constant
* C(uint32_t i
);
42 template <typename Ty
>
43 Constant
* C(const std::initializer_list
<Ty
>& constList
)
45 std::vector
<Constant
*> vConsts
;
46 for (auto i
: constList
)
48 vConsts
.push_back(C((Ty
)i
));
50 return ConstantVector::get(vConsts
);
53 template <typename Ty
>
54 Constant
* CA(LLVMContext
& ctx
, ArrayRef
<Ty
> constList
)
56 return ConstantDataArray::get(ctx
, constList
);
59 template <typename Ty
>
60 Constant
* CInc(uint32_t base
, uint32_t count
)
62 std::vector
<Constant
*> vConsts
;
64 for (uint32_t i
= 0; i
< count
; i
++)
66 vConsts
.push_back(C((Ty
)base
));
69 return ConstantVector::get(vConsts
);
72 Constant
* PRED(bool pred
);
74 Value
* VIMMED1(uint64_t i
);
75 Value
* VIMMED1_16(uint64_t i
);
77 Value
* VIMMED1(int i
);
78 Value
* VIMMED1_16(int i
);
80 Value
* VIMMED1(uint32_t i
);
81 Value
* VIMMED1_16(uint32_t i
);
83 Value
* VIMMED1(float i
);
84 Value
* VIMMED1_16(float i
);
86 Value
* VIMMED1(bool i
);
87 Value
* VIMMED1_16(bool i
);
89 Value
* VUNDEF(Type
* t
);
97 Value
* VUNDEF(Type
* ty
, uint32_t size
);
101 Value
* VBROADCAST(Value
* src
, const llvm::Twine
& name
= "");
102 Value
* VBROADCAST_16(Value
* src
);
104 Value
* VRCP(Value
* va
, const llvm::Twine
& name
= "");
105 Value
* VPLANEPS(Value
* vA
, Value
* vB
, Value
* vC
, Value
*& vX
, Value
*& vY
);
107 uint32_t IMMED(Value
* i
);
108 int32_t S_IMMED(Value
* i
);
111 CALL(Value
* Callee
, const std::initializer_list
<Value
*>& args
, const llvm::Twine
& name
= "");
112 CallInst
* CALL(Value
* Callee
)
114 return CALLA(Callee
);
116 CallInst
* CALL(Value
* Callee
, Value
* arg
);
117 CallInst
* CALL2(Value
* Callee
, Value
* arg1
, Value
* arg2
);
118 CallInst
* CALL3(Value
* Callee
, Value
* arg1
, Value
* arg2
, Value
* arg3
);
120 Value
* MASK(Value
* vmask
);
121 Value
* MASK_16(Value
* vmask
);
123 Value
* VMASK(Value
* mask
);
124 Value
* VMASK_16(Value
* mask
);
126 Value
* VMOVMSK(Value
* mask
);
128 //////////////////////////////////////////////////////////////////////////
129 /// @brief Float / Fixed-point conversions
130 //////////////////////////////////////////////////////////////////////////
132 Value
* VCVT_F32_FIXED_SI(Value
* vFloat
,
134 uint32_t numFracBits
,
135 const llvm::Twine
& name
= "");
136 Value
* VCVT_FIXED_SI_F32(Value
* vFixed
,
138 uint32_t numFracBits
,
139 const llvm::Twine
& name
= "");
141 Value
* VCVT_F32_FIXED_UI(Value
* vFloat
,
143 uint32_t numFracBits
,
144 const llvm::Twine
& name
= "");
145 Value
* VCVT_FIXED_UI_F32(Value
* vFixed
,
147 uint32_t numFracBits
,
148 const llvm::Twine
& name
= "");
150 //////////////////////////////////////////////////////////////////////////
151 /// @brief functions that build IR to call x86 intrinsics directly, or
152 /// emulate them with other instructions if not available on the host
153 //////////////////////////////////////////////////////////////////////////
155 Value
* EXTRACT_16(Value
* x
, uint32_t imm
);
156 Value
* JOIN_16(Value
* a
, Value
* b
);
158 Value
* PSHUFB(Value
* a
, Value
* b
);
159 Value
* PMOVSXBD(Value
* a
);
160 Value
* PMOVSXWD(Value
* a
);
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
* PMAXUD(Value
* a
, Value
* b
);
166 Value
* PMINUD(Value
* a
, Value
* b
);
167 Value
* VABSPS(Value
* a
);
168 Value
* FMADDPS(Value
* a
, Value
* b
, Value
* c
);
170 Value
* ICLAMP(Value
* src
, Value
* low
, Value
* high
, const llvm::Twine
& name
= "");
171 Value
* FCLAMP(Value
* src
, Value
* low
, Value
* high
);
172 Value
* FCLAMP(Value
* src
, float low
, float high
);
174 CallInst
* PRINT(const std::string
& printStr
);
175 CallInst
* PRINT(const std::string
& printStr
, const std::initializer_list
<Value
*>& printArgs
);
177 Value
* VPOPCNT(Value
* a
);
185 Value
* VEXTRACTI128(Value
* a
, Constant
* imm8
);
186 Value
* VINSERTI128(Value
* a
, Value
* b
, Constant
* imm8
);
188 // rdtsc buckets macros
189 void RDTSC_START(Value
* pBucketMgr
, Value
* pId
);
190 void RDTSC_STOP(Value
* pBucketMgr
, Value
* pId
);
192 Value
* CreateEntryAlloca(Function
* pFunc
, Type
* pType
);
193 Value
* CreateEntryAlloca(Function
* pFunc
, Type
* pType
, Value
* pArraySize
);
195 uint32_t GetTypeSize(Type
* pType
);