Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 1 | //===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the IRBuilder class, which is used as a convenient way |
| 11 | // to create LLVM instructions with a consistent and simplified interface. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 15 | #include "llvm/IR/IRBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Function.h" |
| 17 | #include "llvm/IR/GlobalVariable.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Intrinsics.h" |
| 19 | #include "llvm/IR/LLVMContext.h" |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Statepoint.h" |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
| 23 | /// CreateGlobalString - Make a new global variable with an initializer that |
Dan Gohman | 97c5902 | 2010-02-10 20:04:19 +0000 | [diff] [blame] | 24 | /// has array of i8 type filled in with the nul terminated string value |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 25 | /// specified. If Name is specified, it is the name of the global variable |
| 26 | /// created. |
David Blaikie | aa41cd5 | 2015-04-03 21:33:42 +0000 | [diff] [blame] | 27 | GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str, |
Tobias Grosser | cdb8914 | 2015-06-19 02:12:07 +0000 | [diff] [blame] | 28 | const Twine &Name, |
| 29 | unsigned AddressSpace) { |
Chris Lattner | cf9e8f6 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 30 | Constant *StrConstant = ConstantDataArray::getString(Context, Str); |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 31 | Module &M = *BB->getParent()->getParent(); |
| 32 | GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(), |
Benjamin Kramer | f1fd6e3 | 2011-12-22 14:22:14 +0000 | [diff] [blame] | 33 | true, GlobalValue::PrivateLinkage, |
Tobias Grosser | cdb8914 | 2015-06-19 02:12:07 +0000 | [diff] [blame] | 34 | StrConstant, Name, nullptr, |
| 35 | GlobalVariable::NotThreadLocal, |
| 36 | AddressSpace); |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 37 | GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 38 | return GV; |
| 39 | } |
Chris Lattner | 7ef1cac | 2009-12-28 21:45:40 +0000 | [diff] [blame] | 40 | |
Chris Lattner | b1907b2 | 2011-07-12 04:14:22 +0000 | [diff] [blame] | 41 | Type *IRBuilderBase::getCurrentFunctionReturnType() const { |
Chris Lattner | 49f9f76 | 2009-12-28 21:50:56 +0000 | [diff] [blame] | 42 | assert(BB && BB->getParent() && "No current function!"); |
| 43 | return BB->getParent()->getReturnType(); |
| 44 | } |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 45 | |
| 46 | Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 47 | PointerType *PT = cast<PointerType>(Ptr->getType()); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 48 | if (PT->getElementType()->isIntegerTy(8)) |
| 49 | return Ptr; |
| 50 | |
| 51 | // Otherwise, we need to insert a bitcast. |
| 52 | PT = getInt8PtrTy(PT->getAddressSpace()); |
| 53 | BitCastInst *BCI = new BitCastInst(Ptr, PT, ""); |
| 54 | BB->getInstList().insert(InsertPt, BCI); |
| 55 | SetInstDebugLocation(BCI); |
| 56 | return BCI; |
| 57 | } |
| 58 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 59 | static CallInst *createCallHelper(Value *Callee, ArrayRef<Value *> Ops, |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 60 | IRBuilderBase *Builder, |
| 61 | const Twine& Name="") { |
| 62 | CallInst *CI = CallInst::Create(Callee, Ops, Name); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 63 | Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(),CI); |
| 64 | Builder->SetInstDebugLocation(CI); |
| 65 | return CI; |
| 66 | } |
| 67 | |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 68 | static InvokeInst *createInvokeHelper(Value *Invokee, BasicBlock *NormalDest, |
| 69 | BasicBlock *UnwindDest, |
| 70 | ArrayRef<Value *> Ops, |
| 71 | IRBuilderBase *Builder, |
| 72 | const Twine &Name = "") { |
| 73 | InvokeInst *II = |
| 74 | InvokeInst::Create(Invokee, NormalDest, UnwindDest, Ops, Name); |
| 75 | Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(), |
| 76 | II); |
| 77 | Builder->SetInstDebugLocation(II); |
| 78 | return II; |
| 79 | } |
| 80 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 81 | CallInst *IRBuilderBase:: |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 82 | CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 83 | bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag, |
| 84 | MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 85 | Ptr = getCastedInt8PtrValue(Ptr); |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 86 | Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 87 | Type *Tys[] = { Ptr->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 88 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 89 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 90 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 91 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 92 | |
| 93 | // Set the TBAA info if present. |
| 94 | if (TBAATag) |
| 95 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 96 | |
| 97 | if (ScopeTag) |
| 98 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 99 | |
| 100 | if (NoAliasTag) |
| 101 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 102 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 103 | return CI; |
| 104 | } |
| 105 | |
| 106 | CallInst *IRBuilderBase:: |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 107 | CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 108 | bool isVolatile, MDNode *TBAATag, MDNode *TBAAStructTag, |
| 109 | MDNode *ScopeTag, MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 110 | Dst = getCastedInt8PtrValue(Dst); |
| 111 | Src = getCastedInt8PtrValue(Src); |
| 112 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 113 | Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 114 | Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 115 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 116 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 117 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 118 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 119 | |
| 120 | // Set the TBAA info if present. |
| 121 | if (TBAATag) |
| 122 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Dan Gohman | 099727f | 2012-09-26 22:17:14 +0000 | [diff] [blame] | 123 | |
| 124 | // Set the TBAA Struct info if present. |
| 125 | if (TBAAStructTag) |
| 126 | CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 127 | |
| 128 | if (ScopeTag) |
| 129 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 130 | |
| 131 | if (NoAliasTag) |
| 132 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 133 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 134 | return CI; |
| 135 | } |
| 136 | |
Daniel Neilson | 3faabbb | 2017-06-16 14:43:59 +0000 | [diff] [blame] | 137 | CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy( |
Daniel Neilson | 6e4aa1e | 2017-11-10 19:38:12 +0000 | [diff] [blame^] | 138 | Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size, |
| 139 | uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag, |
| 140 | MDNode *ScopeTag, MDNode *NoAliasTag) { |
| 141 | assert(DstAlign >= ElementSize && |
| 142 | "Pointer alignment must be at least element size"); |
| 143 | assert(SrcAlign >= ElementSize && |
| 144 | "Pointer alignment must be at least element size"); |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 145 | Dst = getCastedInt8PtrValue(Dst); |
| 146 | Src = getCastedInt8PtrValue(Src); |
| 147 | |
Daniel Neilson | 3faabbb | 2017-06-16 14:43:59 +0000 | [diff] [blame] | 148 | Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; |
| 149 | Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 150 | Module *M = BB->getParent()->getParent(); |
Daniel Neilson | 3faabbb | 2017-06-16 14:43:59 +0000 | [diff] [blame] | 151 | Value *TheFn = Intrinsic::getDeclaration( |
| 152 | M, Intrinsic::memcpy_element_unordered_atomic, Tys); |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 153 | |
| 154 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
| 155 | |
Daniel Neilson | 6e4aa1e | 2017-11-10 19:38:12 +0000 | [diff] [blame^] | 156 | // Set the alignment of the pointer args. |
| 157 | CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign)); |
| 158 | CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign)); |
| 159 | |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 160 | // Set the TBAA info if present. |
| 161 | if (TBAATag) |
| 162 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
| 163 | |
| 164 | // Set the TBAA Struct info if present. |
| 165 | if (TBAAStructTag) |
| 166 | CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag); |
| 167 | |
| 168 | if (ScopeTag) |
| 169 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 170 | |
| 171 | if (NoAliasTag) |
| 172 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 173 | |
| 174 | return CI; |
| 175 | } |
| 176 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 177 | CallInst *IRBuilderBase:: |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 178 | CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 179 | bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag, |
| 180 | MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 181 | Dst = getCastedInt8PtrValue(Dst); |
| 182 | Src = getCastedInt8PtrValue(Src); |
| 183 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 184 | Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 185 | Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 186 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 187 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 188 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 189 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 190 | |
| 191 | // Set the TBAA info if present. |
| 192 | if (TBAATag) |
| 193 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 194 | |
| 195 | if (ScopeTag) |
| 196 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 197 | |
| 198 | if (NoAliasTag) |
| 199 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 200 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 201 | return CI; |
| 202 | } |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 203 | |
Amara Emerson | cf9daa3 | 2017-05-09 10:43:25 +0000 | [diff] [blame] | 204 | static CallInst *getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID, |
| 205 | Value *Src) { |
| 206 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
| 207 | Value *Ops[] = {Src}; |
| 208 | Type *Tys[] = { Src->getType()->getVectorElementType(), Src->getType() }; |
| 209 | auto Decl = Intrinsic::getDeclaration(M, ID, Tys); |
| 210 | return createCallHelper(Decl, Ops, Builder); |
| 211 | } |
| 212 | |
| 213 | CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) { |
| 214 | Module *M = GetInsertBlock()->getParent()->getParent(); |
| 215 | Value *Ops[] = {Acc, Src}; |
| 216 | Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(), |
| 217 | Src->getType()}; |
| 218 | auto Decl = Intrinsic::getDeclaration( |
| 219 | M, Intrinsic::experimental_vector_reduce_fadd, Tys); |
| 220 | return createCallHelper(Decl, Ops, this); |
| 221 | } |
| 222 | |
| 223 | CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) { |
| 224 | Module *M = GetInsertBlock()->getParent()->getParent(); |
| 225 | Value *Ops[] = {Acc, Src}; |
| 226 | Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(), |
| 227 | Src->getType()}; |
| 228 | auto Decl = Intrinsic::getDeclaration( |
| 229 | M, Intrinsic::experimental_vector_reduce_fmul, Tys); |
| 230 | return createCallHelper(Decl, Ops, this); |
| 231 | } |
| 232 | |
| 233 | CallInst *IRBuilderBase::CreateAddReduce(Value *Src) { |
| 234 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_add, |
| 235 | Src); |
| 236 | } |
| 237 | |
| 238 | CallInst *IRBuilderBase::CreateMulReduce(Value *Src) { |
| 239 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_mul, |
| 240 | Src); |
| 241 | } |
| 242 | |
| 243 | CallInst *IRBuilderBase::CreateAndReduce(Value *Src) { |
| 244 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_and, |
| 245 | Src); |
| 246 | } |
| 247 | |
| 248 | CallInst *IRBuilderBase::CreateOrReduce(Value *Src) { |
| 249 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_or, |
| 250 | Src); |
| 251 | } |
| 252 | |
| 253 | CallInst *IRBuilderBase::CreateXorReduce(Value *Src) { |
| 254 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_xor, |
| 255 | Src); |
| 256 | } |
| 257 | |
| 258 | CallInst *IRBuilderBase::CreateIntMaxReduce(Value *Src, bool IsSigned) { |
| 259 | auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smax |
| 260 | : Intrinsic::experimental_vector_reduce_umax; |
| 261 | return getReductionIntrinsic(this, ID, Src); |
| 262 | } |
| 263 | |
| 264 | CallInst *IRBuilderBase::CreateIntMinReduce(Value *Src, bool IsSigned) { |
| 265 | auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smin |
| 266 | : Intrinsic::experimental_vector_reduce_umin; |
| 267 | return getReductionIntrinsic(this, ID, Src); |
| 268 | } |
| 269 | |
| 270 | CallInst *IRBuilderBase::CreateFPMaxReduce(Value *Src, bool NoNaN) { |
| 271 | auto Rdx = getReductionIntrinsic( |
| 272 | this, Intrinsic::experimental_vector_reduce_fmax, Src); |
| 273 | if (NoNaN) { |
| 274 | FastMathFlags FMF; |
| 275 | FMF.setNoNaNs(); |
| 276 | Rdx->setFastMathFlags(FMF); |
| 277 | } |
| 278 | return Rdx; |
| 279 | } |
| 280 | |
| 281 | CallInst *IRBuilderBase::CreateFPMinReduce(Value *Src, bool NoNaN) { |
| 282 | auto Rdx = getReductionIntrinsic( |
| 283 | this, Intrinsic::experimental_vector_reduce_fmin, Src); |
| 284 | if (NoNaN) { |
| 285 | FastMathFlags FMF; |
| 286 | FMF.setNoNaNs(); |
| 287 | Rdx->setFastMathFlags(FMF); |
| 288 | } |
| 289 | return Rdx; |
| 290 | } |
| 291 | |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 292 | CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) { |
| 293 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 294 | "lifetime.start only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 295 | Ptr = getCastedInt8PtrValue(Ptr); |
| 296 | if (!Size) |
| 297 | Size = getInt64(-1); |
| 298 | else |
| 299 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 300 | "lifetime.start requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 301 | Value *Ops[] = { Size, Ptr }; |
| 302 | Module *M = BB->getParent()->getParent(); |
Matt Arsenault | f10061e | 2017-04-10 20:18:21 +0000 | [diff] [blame] | 303 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, |
| 304 | { Ptr->getType() }); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 305 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) { |
| 309 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 310 | "lifetime.end only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 311 | Ptr = getCastedInt8PtrValue(Ptr); |
| 312 | if (!Size) |
| 313 | Size = getInt64(-1); |
| 314 | else |
| 315 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 316 | "lifetime.end requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 317 | Value *Ops[] = { Size, Ptr }; |
| 318 | Module *M = BB->getParent()->getParent(); |
Matt Arsenault | f10061e | 2017-04-10 20:18:21 +0000 | [diff] [blame] | 319 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, |
| 320 | { Ptr->getType() }); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 321 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 322 | } |
Hal Finkel | 6f814db | 2014-10-15 23:44:22 +0000 | [diff] [blame] | 323 | |
Anna Thomas | 58d1192 | 2016-07-22 20:57:23 +0000 | [diff] [blame] | 324 | CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) { |
| 325 | |
| 326 | assert(isa<PointerType>(Ptr->getType()) && |
| 327 | "invariant.start only applies to pointers."); |
| 328 | Ptr = getCastedInt8PtrValue(Ptr); |
| 329 | if (!Size) |
| 330 | Size = getInt64(-1); |
| 331 | else |
| 332 | assert(Size->getType() == getInt64Ty() && |
| 333 | "invariant.start requires the size to be an i64"); |
| 334 | |
| 335 | Value *Ops[] = {Size, Ptr}; |
| 336 | // Fill in the single overloaded type: memory object type. |
| 337 | Type *ObjectPtr[1] = {Ptr->getType()}; |
| 338 | Module *M = BB->getParent()->getParent(); |
| 339 | Value *TheFn = |
| 340 | Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr); |
| 341 | return createCallHelper(TheFn, Ops, this); |
| 342 | } |
| 343 | |
Hal Finkel | 6f814db | 2014-10-15 23:44:22 +0000 | [diff] [blame] | 344 | CallInst *IRBuilderBase::CreateAssumption(Value *Cond) { |
| 345 | assert(Cond->getType() == getInt1Ty() && |
| 346 | "an assumption condition must be of type i1"); |
| 347 | |
| 348 | Value *Ops[] = { Cond }; |
| 349 | Module *M = BB->getParent()->getParent(); |
| 350 | Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); |
| 351 | return createCallHelper(FnAssume, Ops, this); |
| 352 | } |
| 353 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 354 | /// \brief Create a call to a Masked Load intrinsic. |
| 355 | /// \p Ptr - base pointer for the load |
| 356 | /// \p Align - alignment of the source location |
| 357 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 358 | /// be accessed in memory |
| 359 | /// \p PassThru - pass-through value that is used to fill the masked-off lanes |
| 360 | /// of the result |
| 361 | /// \p Name - name of the result variable |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 362 | CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, |
| 363 | Value *Mask, Value *PassThru, |
| 364 | const Twine &Name) { |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 365 | PointerType *PtrTy = cast<PointerType>(Ptr->getType()); |
| 366 | Type *DataTy = PtrTy->getElementType(); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 367 | assert(DataTy->isVectorTy() && "Ptr should point to a vector"); |
Ayal Zaks | e841b21 | 2017-07-31 13:21:42 +0000 | [diff] [blame] | 368 | assert(Mask && "Mask should not be all-ones (null)"); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 369 | if (!PassThru) |
| 370 | PassThru = UndefValue::get(DataTy); |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 371 | Type *OverloadedTypes[] = { DataTy, PtrTy }; |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 372 | Value *Ops[] = { Ptr, getInt32(Align), Mask, PassThru}; |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 373 | return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, |
| 374 | OverloadedTypes, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 377 | /// \brief Create a call to a Masked Store intrinsic. |
| 378 | /// \p Val - data to be stored, |
| 379 | /// \p Ptr - base pointer for the store |
| 380 | /// \p Align - alignment of the destination location |
| 381 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 382 | /// be accessed in memory |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 383 | CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr, |
| 384 | unsigned Align, Value *Mask) { |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 385 | PointerType *PtrTy = cast<PointerType>(Ptr->getType()); |
| 386 | Type *DataTy = PtrTy->getElementType(); |
| 387 | assert(DataTy->isVectorTy() && "Ptr should point to a vector"); |
Ayal Zaks | e841b21 | 2017-07-31 13:21:42 +0000 | [diff] [blame] | 388 | assert(Mask && "Mask should not be all-ones (null)"); |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 389 | Type *OverloadedTypes[] = { DataTy, PtrTy }; |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 390 | Value *Ops[] = { Val, Ptr, getInt32(Align), Mask }; |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 391 | return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /// Create a call to a Masked intrinsic, with given intrinsic Id, |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 395 | /// an array of operands - Ops, and an array of overloaded types - |
| 396 | /// OverloadedTypes. |
Pete Cooper | 9e1d335 | 2015-05-20 17:16:39 +0000 | [diff] [blame] | 397 | CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id, |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 398 | ArrayRef<Value *> Ops, |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 399 | ArrayRef<Type *> OverloadedTypes, |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 400 | const Twine &Name) { |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 401 | Module *M = BB->getParent()->getParent(); |
Pete Cooper | 9e1d335 | 2015-05-20 17:16:39 +0000 | [diff] [blame] | 402 | Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 403 | return createCallHelper(TheFn, Ops, this, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 404 | } |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 405 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 406 | /// \brief Create a call to a Masked Gather intrinsic. |
| 407 | /// \p Ptrs - vector of pointers for loading |
| 408 | /// \p Align - alignment for one element |
| 409 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 410 | /// be accessed in memory |
| 411 | /// \p PassThru - pass-through value that is used to fill the masked-off lanes |
| 412 | /// of the result |
| 413 | /// \p Name - name of the result variable |
| 414 | CallInst *IRBuilderBase::CreateMaskedGather(Value *Ptrs, unsigned Align, |
| 415 | Value *Mask, Value *PassThru, |
| 416 | const Twine& Name) { |
| 417 | auto PtrsTy = cast<VectorType>(Ptrs->getType()); |
| 418 | auto PtrTy = cast<PointerType>(PtrsTy->getElementType()); |
| 419 | unsigned NumElts = PtrsTy->getVectorNumElements(); |
| 420 | Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts); |
| 421 | |
| 422 | if (!Mask) |
| 423 | Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context), |
| 424 | NumElts)); |
| 425 | |
Amara Emerson | 4d33c86 | 2017-05-19 10:40:18 +0000 | [diff] [blame] | 426 | if (!PassThru) |
| 427 | PassThru = UndefValue::get(DataTy); |
| 428 | |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 429 | Type *OverloadedTypes[] = {DataTy, PtrsTy}; |
Amara Emerson | 4d33c86 | 2017-05-19 10:40:18 +0000 | [diff] [blame] | 430 | Value * Ops[] = {Ptrs, getInt32(Align), Mask, PassThru}; |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 431 | |
| 432 | // We specify only one type when we create this intrinsic. Types of other |
| 433 | // arguments are derived from this type. |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 434 | return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes, |
| 435 | Name); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /// \brief Create a call to a Masked Scatter intrinsic. |
| 439 | /// \p Data - data to be stored, |
| 440 | /// \p Ptrs - the vector of pointers, where the \p Data elements should be |
| 441 | /// stored |
| 442 | /// \p Align - alignment for one element |
| 443 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 444 | /// be accessed in memory |
| 445 | CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs, |
| 446 | unsigned Align, Value *Mask) { |
| 447 | auto PtrsTy = cast<VectorType>(Ptrs->getType()); |
| 448 | auto DataTy = cast<VectorType>(Data->getType()); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 449 | unsigned NumElts = PtrsTy->getVectorNumElements(); |
| 450 | |
Tim Northover | 5a1a56c | 2016-02-17 21:16:59 +0000 | [diff] [blame] | 451 | #ifndef NDEBUG |
| 452 | auto PtrTy = cast<PointerType>(PtrsTy->getElementType()); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 453 | assert(NumElts == DataTy->getVectorNumElements() && |
Tim Northover | 5a1a56c | 2016-02-17 21:16:59 +0000 | [diff] [blame] | 454 | PtrTy->getElementType() == DataTy->getElementType() && |
| 455 | "Incompatible pointer and data types"); |
| 456 | #endif |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 457 | |
| 458 | if (!Mask) |
| 459 | Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context), |
| 460 | NumElts)); |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 461 | |
| 462 | Type *OverloadedTypes[] = {DataTy, PtrsTy}; |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 463 | Value * Ops[] = {Data, Ptrs, getInt32(Align), Mask}; |
| 464 | |
| 465 | // We specify only one type when we create this intrinsic. Types of other |
| 466 | // arguments are derived from this type. |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 467 | return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 470 | template <typename T0, typename T1, typename T2, typename T3> |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 471 | static std::vector<Value *> |
| 472 | getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 473 | Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs, |
| 474 | ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, |
| 475 | ArrayRef<T3> GCArgs) { |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 476 | std::vector<Value *> Args; |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 477 | Args.push_back(B.getInt64(ID)); |
| 478 | Args.push_back(B.getInt32(NumPatchBytes)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 479 | Args.push_back(ActualCallee); |
| 480 | Args.push_back(B.getInt32(CallArgs.size())); |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 481 | Args.push_back(B.getInt32(Flags)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 482 | Args.insert(Args.end(), CallArgs.begin(), CallArgs.end()); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 483 | Args.push_back(B.getInt32(TransitionArgs.size())); |
| 484 | Args.insert(Args.end(), TransitionArgs.begin(), TransitionArgs.end()); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 485 | Args.push_back(B.getInt32(DeoptArgs.size())); |
| 486 | Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end()); |
| 487 | Args.insert(Args.end(), GCArgs.begin(), GCArgs.end()); |
| 488 | |
| 489 | return Args; |
| 490 | } |
| 491 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 492 | template <typename T0, typename T1, typename T2, typename T3> |
| 493 | static CallInst *CreateGCStatepointCallCommon( |
| 494 | IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 495 | Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 496 | ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, |
| 497 | const Twine &Name) { |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 498 | // Extract out the type of the callee. |
| 499 | PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType()); |
| 500 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 501 | "actual callee must be a callable value"); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 502 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 503 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 504 | // Fill in the one generic type'd argument (the function is also vararg) |
| 505 | Type *ArgTypes[] = { FuncPtrType }; |
| 506 | Function *FnStatepoint = |
| 507 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, |
| 508 | ArgTypes); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 509 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 510 | std::vector<llvm::Value *> Args = |
| 511 | getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags, |
| 512 | CallArgs, TransitionArgs, DeoptArgs, GCArgs); |
| 513 | return createCallHelper(FnStatepoint, Args, Builder, Name); |
| 514 | } |
| 515 | |
| 516 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
| 517 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, |
| 518 | ArrayRef<Value *> CallArgs, ArrayRef<Value *> DeoptArgs, |
| 519 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 520 | return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 521 | this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None), |
| 522 | CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 526 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, |
| 527 | ArrayRef<Use> CallArgs, ArrayRef<Use> TransitionArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 528 | ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 529 | return CreateGCStatepointCallCommon<Use, Use, Use, Value *>( |
| 530 | this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs, |
| 531 | DeoptArgs, GCArgs, Name); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 534 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
| 535 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, |
| 536 | ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs, |
| 537 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 538 | return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 539 | this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None), |
| 540 | CallArgs, None, DeoptArgs, GCArgs, Name); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | template <typename T0, typename T1, typename T2, typename T3> |
| 544 | static InvokeInst *CreateGCStatepointInvokeCommon( |
| 545 | IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, |
| 546 | Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 547 | uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 548 | ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) { |
| 549 | // Extract out the type of the callee. |
| 550 | PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); |
| 551 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 552 | "actual callee must be a callable value"); |
| 553 | |
| 554 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
| 555 | // Fill in the one generic type'd argument (the function is also vararg) |
| 556 | Function *FnStatepoint = Intrinsic::getDeclaration( |
| 557 | M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); |
| 558 | |
| 559 | std::vector<llvm::Value *> Args = |
| 560 | getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags, |
| 561 | InvokeArgs, TransitionArgs, DeoptArgs, GCArgs); |
| 562 | return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder, |
| 563 | Name); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 567 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
| 568 | BasicBlock *NormalDest, BasicBlock *UnwindDest, |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 569 | ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs, |
| 570 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 571 | return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>( |
| 572 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 573 | uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 574 | DeoptArgs, GCArgs, Name); |
| 575 | } |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 576 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 577 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
| 578 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 579 | BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 580 | ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs, |
| 581 | ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 582 | return CreateGCStatepointInvokeCommon<Use, Use, Use, Value *>( |
| 583 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags, |
| 584 | InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 588 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
| 589 | BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs, |
| 590 | ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 591 | return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>( |
| 592 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 593 | uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs, |
| 594 | Name); |
Ramkumar Ramachandra | 3408f3e | 2015-02-26 00:35:56 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 597 | CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint, |
| 598 | Type *ResultType, |
| 599 | const Twine &Name) { |
Ramkumar Ramachandra | 75a4f35 | 2015-01-22 20:14:38 +0000 | [diff] [blame] | 600 | Intrinsic::ID ID = Intrinsic::experimental_gc_result; |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 601 | Module *M = BB->getParent()->getParent(); |
| 602 | Type *Types[] = {ResultType}; |
| 603 | Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); |
| 604 | |
| 605 | Value *Args[] = {Statepoint}; |
| 606 | return createCallHelper(FnGCResult, Args, this, Name); |
| 607 | } |
| 608 | |
| 609 | CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint, |
| 610 | int BaseOffset, |
| 611 | int DerivedOffset, |
| 612 | Type *ResultType, |
| 613 | const Twine &Name) { |
| 614 | Module *M = BB->getParent()->getParent(); |
| 615 | Type *Types[] = {ResultType}; |
| 616 | Value *FnGCRelocate = |
| 617 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); |
| 618 | |
| 619 | Value *Args[] = {Statepoint, |
| 620 | getInt32(BaseOffset), |
| 621 | getInt32(DerivedOffset)}; |
| 622 | return createCallHelper(FnGCRelocate, Args, this, Name); |
| 623 | } |
Matt Arsenault | cdb468c | 2017-02-27 23:08:49 +0000 | [diff] [blame] | 624 | |
| 625 | CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, |
| 626 | Value *LHS, Value *RHS, |
| 627 | const Twine &Name) { |
| 628 | Module *M = BB->getParent()->getParent(); |
| 629 | Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() }); |
| 630 | return createCallHelper(Fn, { LHS, RHS }, this, Name); |
| 631 | } |