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( |
| 138 | Value *Dst, Value *Src, Value *Size, uint32_t ElementSize, MDNode *TBAATag, |
| 139 | MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) { |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 140 | Dst = getCastedInt8PtrValue(Dst); |
| 141 | Src = getCastedInt8PtrValue(Src); |
| 142 | |
Daniel Neilson | 3faabbb | 2017-06-16 14:43:59 +0000 | [diff] [blame^] | 143 | Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; |
| 144 | Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 145 | Module *M = BB->getParent()->getParent(); |
Daniel Neilson | 3faabbb | 2017-06-16 14:43:59 +0000 | [diff] [blame^] | 146 | Value *TheFn = Intrinsic::getDeclaration( |
| 147 | M, Intrinsic::memcpy_element_unordered_atomic, Tys); |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 148 | |
| 149 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
| 150 | |
| 151 | // Set the TBAA info if present. |
| 152 | if (TBAATag) |
| 153 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
| 154 | |
| 155 | // Set the TBAA Struct info if present. |
| 156 | if (TBAAStructTag) |
| 157 | CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag); |
| 158 | |
| 159 | if (ScopeTag) |
| 160 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 161 | |
| 162 | if (NoAliasTag) |
| 163 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 164 | |
| 165 | return CI; |
| 166 | } |
| 167 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 168 | CallInst *IRBuilderBase:: |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 169 | CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 170 | bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag, |
| 171 | MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 172 | Dst = getCastedInt8PtrValue(Dst); |
| 173 | Src = getCastedInt8PtrValue(Src); |
| 174 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 175 | Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 176 | Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 177 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 178 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 179 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 180 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 181 | |
| 182 | // Set the TBAA info if present. |
| 183 | if (TBAATag) |
| 184 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 185 | |
| 186 | if (ScopeTag) |
| 187 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 188 | |
| 189 | if (NoAliasTag) |
| 190 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 191 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 192 | return CI; |
| 193 | } |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 194 | |
Amara Emerson | cf9daa3 | 2017-05-09 10:43:25 +0000 | [diff] [blame] | 195 | static CallInst *getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID, |
| 196 | Value *Src) { |
| 197 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
| 198 | Value *Ops[] = {Src}; |
| 199 | Type *Tys[] = { Src->getType()->getVectorElementType(), Src->getType() }; |
| 200 | auto Decl = Intrinsic::getDeclaration(M, ID, Tys); |
| 201 | return createCallHelper(Decl, Ops, Builder); |
| 202 | } |
| 203 | |
| 204 | CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) { |
| 205 | Module *M = GetInsertBlock()->getParent()->getParent(); |
| 206 | Value *Ops[] = {Acc, Src}; |
| 207 | Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(), |
| 208 | Src->getType()}; |
| 209 | auto Decl = Intrinsic::getDeclaration( |
| 210 | M, Intrinsic::experimental_vector_reduce_fadd, Tys); |
| 211 | return createCallHelper(Decl, Ops, this); |
| 212 | } |
| 213 | |
| 214 | CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) { |
| 215 | Module *M = GetInsertBlock()->getParent()->getParent(); |
| 216 | Value *Ops[] = {Acc, Src}; |
| 217 | Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(), |
| 218 | Src->getType()}; |
| 219 | auto Decl = Intrinsic::getDeclaration( |
| 220 | M, Intrinsic::experimental_vector_reduce_fmul, Tys); |
| 221 | return createCallHelper(Decl, Ops, this); |
| 222 | } |
| 223 | |
| 224 | CallInst *IRBuilderBase::CreateAddReduce(Value *Src) { |
| 225 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_add, |
| 226 | Src); |
| 227 | } |
| 228 | |
| 229 | CallInst *IRBuilderBase::CreateMulReduce(Value *Src) { |
| 230 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_mul, |
| 231 | Src); |
| 232 | } |
| 233 | |
| 234 | CallInst *IRBuilderBase::CreateAndReduce(Value *Src) { |
| 235 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_and, |
| 236 | Src); |
| 237 | } |
| 238 | |
| 239 | CallInst *IRBuilderBase::CreateOrReduce(Value *Src) { |
| 240 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_or, |
| 241 | Src); |
| 242 | } |
| 243 | |
| 244 | CallInst *IRBuilderBase::CreateXorReduce(Value *Src) { |
| 245 | return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_xor, |
| 246 | Src); |
| 247 | } |
| 248 | |
| 249 | CallInst *IRBuilderBase::CreateIntMaxReduce(Value *Src, bool IsSigned) { |
| 250 | auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smax |
| 251 | : Intrinsic::experimental_vector_reduce_umax; |
| 252 | return getReductionIntrinsic(this, ID, Src); |
| 253 | } |
| 254 | |
| 255 | CallInst *IRBuilderBase::CreateIntMinReduce(Value *Src, bool IsSigned) { |
| 256 | auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smin |
| 257 | : Intrinsic::experimental_vector_reduce_umin; |
| 258 | return getReductionIntrinsic(this, ID, Src); |
| 259 | } |
| 260 | |
| 261 | CallInst *IRBuilderBase::CreateFPMaxReduce(Value *Src, bool NoNaN) { |
| 262 | auto Rdx = getReductionIntrinsic( |
| 263 | this, Intrinsic::experimental_vector_reduce_fmax, Src); |
| 264 | if (NoNaN) { |
| 265 | FastMathFlags FMF; |
| 266 | FMF.setNoNaNs(); |
| 267 | Rdx->setFastMathFlags(FMF); |
| 268 | } |
| 269 | return Rdx; |
| 270 | } |
| 271 | |
| 272 | CallInst *IRBuilderBase::CreateFPMinReduce(Value *Src, bool NoNaN) { |
| 273 | auto Rdx = getReductionIntrinsic( |
| 274 | this, Intrinsic::experimental_vector_reduce_fmin, Src); |
| 275 | if (NoNaN) { |
| 276 | FastMathFlags FMF; |
| 277 | FMF.setNoNaNs(); |
| 278 | Rdx->setFastMathFlags(FMF); |
| 279 | } |
| 280 | return Rdx; |
| 281 | } |
| 282 | |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 283 | CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) { |
| 284 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 285 | "lifetime.start only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 286 | Ptr = getCastedInt8PtrValue(Ptr); |
| 287 | if (!Size) |
| 288 | Size = getInt64(-1); |
| 289 | else |
| 290 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 291 | "lifetime.start requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 292 | Value *Ops[] = { Size, Ptr }; |
| 293 | Module *M = BB->getParent()->getParent(); |
Matt Arsenault | f10061e | 2017-04-10 20:18:21 +0000 | [diff] [blame] | 294 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, |
| 295 | { Ptr->getType() }); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 296 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) { |
| 300 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 301 | "lifetime.end only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 302 | Ptr = getCastedInt8PtrValue(Ptr); |
| 303 | if (!Size) |
| 304 | Size = getInt64(-1); |
| 305 | else |
| 306 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 307 | "lifetime.end requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 308 | Value *Ops[] = { Size, Ptr }; |
| 309 | Module *M = BB->getParent()->getParent(); |
Matt Arsenault | f10061e | 2017-04-10 20:18:21 +0000 | [diff] [blame] | 310 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, |
| 311 | { Ptr->getType() }); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 312 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 313 | } |
Hal Finkel | 6f814db | 2014-10-15 23:44:22 +0000 | [diff] [blame] | 314 | |
Anna Thomas | 58d1192 | 2016-07-22 20:57:23 +0000 | [diff] [blame] | 315 | CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) { |
| 316 | |
| 317 | assert(isa<PointerType>(Ptr->getType()) && |
| 318 | "invariant.start only applies to pointers."); |
| 319 | Ptr = getCastedInt8PtrValue(Ptr); |
| 320 | if (!Size) |
| 321 | Size = getInt64(-1); |
| 322 | else |
| 323 | assert(Size->getType() == getInt64Ty() && |
| 324 | "invariant.start requires the size to be an i64"); |
| 325 | |
| 326 | Value *Ops[] = {Size, Ptr}; |
| 327 | // Fill in the single overloaded type: memory object type. |
| 328 | Type *ObjectPtr[1] = {Ptr->getType()}; |
| 329 | Module *M = BB->getParent()->getParent(); |
| 330 | Value *TheFn = |
| 331 | Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr); |
| 332 | return createCallHelper(TheFn, Ops, this); |
| 333 | } |
| 334 | |
Hal Finkel | 6f814db | 2014-10-15 23:44:22 +0000 | [diff] [blame] | 335 | CallInst *IRBuilderBase::CreateAssumption(Value *Cond) { |
| 336 | assert(Cond->getType() == getInt1Ty() && |
| 337 | "an assumption condition must be of type i1"); |
| 338 | |
| 339 | Value *Ops[] = { Cond }; |
| 340 | Module *M = BB->getParent()->getParent(); |
| 341 | Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); |
| 342 | return createCallHelper(FnAssume, Ops, this); |
| 343 | } |
| 344 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 345 | /// \brief Create a call to a Masked Load intrinsic. |
| 346 | /// \p Ptr - base pointer for the load |
| 347 | /// \p Align - alignment of the source location |
| 348 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 349 | /// be accessed in memory |
| 350 | /// \p PassThru - pass-through value that is used to fill the masked-off lanes |
| 351 | /// of the result |
| 352 | /// \p Name - name of the result variable |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 353 | CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, |
| 354 | Value *Mask, Value *PassThru, |
| 355 | const Twine &Name) { |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 356 | PointerType *PtrTy = cast<PointerType>(Ptr->getType()); |
| 357 | Type *DataTy = PtrTy->getElementType(); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 358 | assert(DataTy->isVectorTy() && "Ptr should point to a vector"); |
| 359 | if (!PassThru) |
| 360 | PassThru = UndefValue::get(DataTy); |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 361 | Type *OverloadedTypes[] = { DataTy, PtrTy }; |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 362 | Value *Ops[] = { Ptr, getInt32(Align), Mask, PassThru}; |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 363 | return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, |
| 364 | OverloadedTypes, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 367 | /// \brief Create a call to a Masked Store intrinsic. |
| 368 | /// \p Val - data to be stored, |
| 369 | /// \p Ptr - base pointer for the store |
| 370 | /// \p Align - alignment of the destination location |
| 371 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 372 | /// be accessed in memory |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 373 | CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr, |
| 374 | unsigned Align, Value *Mask) { |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 375 | PointerType *PtrTy = cast<PointerType>(Ptr->getType()); |
| 376 | Type *DataTy = PtrTy->getElementType(); |
| 377 | assert(DataTy->isVectorTy() && "Ptr should point to a vector"); |
| 378 | Type *OverloadedTypes[] = { DataTy, PtrTy }; |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 379 | Value *Ops[] = { Val, Ptr, getInt32(Align), Mask }; |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 380 | return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /// Create a call to a Masked intrinsic, with given intrinsic Id, |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 384 | /// an array of operands - Ops, and an array of overloaded types - |
| 385 | /// OverloadedTypes. |
Pete Cooper | 9e1d335 | 2015-05-20 17:16:39 +0000 | [diff] [blame] | 386 | CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id, |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 387 | ArrayRef<Value *> Ops, |
Artur Pilipenko | 7ad95ec | 2016-06-28 18:27:25 +0000 | [diff] [blame] | 388 | ArrayRef<Type *> OverloadedTypes, |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 389 | const Twine &Name) { |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 390 | Module *M = BB->getParent()->getParent(); |
Pete Cooper | 9e1d335 | 2015-05-20 17:16:39 +0000 | [diff] [blame] | 391 | Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 392 | return createCallHelper(TheFn, Ops, this, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 393 | } |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 394 | |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 395 | /// \brief Create a call to a Masked Gather intrinsic. |
| 396 | /// \p Ptrs - vector of pointers for loading |
| 397 | /// \p Align - alignment for one element |
| 398 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 399 | /// be accessed in memory |
| 400 | /// \p PassThru - pass-through value that is used to fill the masked-off lanes |
| 401 | /// of the result |
| 402 | /// \p Name - name of the result variable |
| 403 | CallInst *IRBuilderBase::CreateMaskedGather(Value *Ptrs, unsigned Align, |
| 404 | Value *Mask, Value *PassThru, |
| 405 | const Twine& Name) { |
| 406 | auto PtrsTy = cast<VectorType>(Ptrs->getType()); |
| 407 | auto PtrTy = cast<PointerType>(PtrsTy->getElementType()); |
| 408 | unsigned NumElts = PtrsTy->getVectorNumElements(); |
| 409 | Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts); |
| 410 | |
| 411 | if (!Mask) |
| 412 | Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context), |
| 413 | NumElts)); |
| 414 | |
Amara Emerson | 4d33c86 | 2017-05-19 10:40:18 +0000 | [diff] [blame] | 415 | if (!PassThru) |
| 416 | PassThru = UndefValue::get(DataTy); |
| 417 | |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 418 | Type *OverloadedTypes[] = {DataTy, PtrsTy}; |
Amara Emerson | 4d33c86 | 2017-05-19 10:40:18 +0000 | [diff] [blame] | 419 | Value * Ops[] = {Ptrs, getInt32(Align), Mask, PassThru}; |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 420 | |
| 421 | // We specify only one type when we create this intrinsic. Types of other |
| 422 | // arguments are derived from this type. |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 423 | return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes, |
| 424 | Name); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /// \brief Create a call to a Masked Scatter intrinsic. |
| 428 | /// \p Data - data to be stored, |
| 429 | /// \p Ptrs - the vector of pointers, where the \p Data elements should be |
| 430 | /// stored |
| 431 | /// \p Align - alignment for one element |
| 432 | /// \p Mask - vector of booleans which indicates what vector lanes should |
| 433 | /// be accessed in memory |
| 434 | CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs, |
| 435 | unsigned Align, Value *Mask) { |
| 436 | auto PtrsTy = cast<VectorType>(Ptrs->getType()); |
| 437 | auto DataTy = cast<VectorType>(Data->getType()); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 438 | unsigned NumElts = PtrsTy->getVectorNumElements(); |
| 439 | |
Tim Northover | 5a1a56c | 2016-02-17 21:16:59 +0000 | [diff] [blame] | 440 | #ifndef NDEBUG |
| 441 | auto PtrTy = cast<PointerType>(PtrsTy->getElementType()); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 442 | assert(NumElts == DataTy->getVectorNumElements() && |
Tim Northover | 5a1a56c | 2016-02-17 21:16:59 +0000 | [diff] [blame] | 443 | PtrTy->getElementType() == DataTy->getElementType() && |
| 444 | "Incompatible pointer and data types"); |
| 445 | #endif |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 446 | |
| 447 | if (!Mask) |
| 448 | Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context), |
| 449 | NumElts)); |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 450 | |
| 451 | Type *OverloadedTypes[] = {DataTy, PtrsTy}; |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 452 | Value * Ops[] = {Data, Ptrs, getInt32(Align), Mask}; |
| 453 | |
| 454 | // We specify only one type when we create this intrinsic. Types of other |
| 455 | // arguments are derived from this type. |
Elad Cohen | ef5798a | 2017-05-03 12:28:54 +0000 | [diff] [blame] | 456 | return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes); |
Elena Demikhovsky | 88e76ca | 2016-02-17 19:23:04 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 459 | template <typename T0, typename T1, typename T2, typename T3> |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 460 | static std::vector<Value *> |
| 461 | getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 462 | Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs, |
| 463 | ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, |
| 464 | ArrayRef<T3> GCArgs) { |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 465 | std::vector<Value *> Args; |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 466 | Args.push_back(B.getInt64(ID)); |
| 467 | Args.push_back(B.getInt32(NumPatchBytes)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 468 | Args.push_back(ActualCallee); |
| 469 | Args.push_back(B.getInt32(CallArgs.size())); |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 470 | Args.push_back(B.getInt32(Flags)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 471 | Args.insert(Args.end(), CallArgs.begin(), CallArgs.end()); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 472 | Args.push_back(B.getInt32(TransitionArgs.size())); |
| 473 | Args.insert(Args.end(), TransitionArgs.begin(), TransitionArgs.end()); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 474 | Args.push_back(B.getInt32(DeoptArgs.size())); |
| 475 | Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end()); |
| 476 | Args.insert(Args.end(), GCArgs.begin(), GCArgs.end()); |
| 477 | |
| 478 | return Args; |
| 479 | } |
| 480 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 481 | template <typename T0, typename T1, typename T2, typename T3> |
| 482 | static CallInst *CreateGCStatepointCallCommon( |
| 483 | IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 484 | Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 485 | ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, |
| 486 | const Twine &Name) { |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 487 | // Extract out the type of the callee. |
| 488 | PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType()); |
| 489 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 490 | "actual callee must be a callable value"); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 491 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 492 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 493 | // Fill in the one generic type'd argument (the function is also vararg) |
| 494 | Type *ArgTypes[] = { FuncPtrType }; |
| 495 | Function *FnStatepoint = |
| 496 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, |
| 497 | ArgTypes); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 498 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 499 | std::vector<llvm::Value *> Args = |
| 500 | getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags, |
| 501 | CallArgs, TransitionArgs, DeoptArgs, GCArgs); |
| 502 | return createCallHelper(FnStatepoint, Args, Builder, Name); |
| 503 | } |
| 504 | |
| 505 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
| 506 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, |
| 507 | ArrayRef<Value *> CallArgs, ArrayRef<Value *> DeoptArgs, |
| 508 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 509 | return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 510 | this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None), |
| 511 | CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 515 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, |
| 516 | ArrayRef<Use> CallArgs, ArrayRef<Use> TransitionArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 517 | ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 518 | return CreateGCStatepointCallCommon<Use, Use, Use, Value *>( |
| 519 | this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs, |
| 520 | DeoptArgs, GCArgs, Name); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 523 | CallInst *IRBuilderBase::CreateGCStatepointCall( |
| 524 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, |
| 525 | ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs, |
| 526 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 527 | return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>( |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 528 | this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None), |
| 529 | CallArgs, None, DeoptArgs, GCArgs, Name); |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | template <typename T0, typename T1, typename T2, typename T3> |
| 533 | static InvokeInst *CreateGCStatepointInvokeCommon( |
| 534 | IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, |
| 535 | Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 536 | uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 537 | ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) { |
| 538 | // Extract out the type of the callee. |
| 539 | PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); |
| 540 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 541 | "actual callee must be a callable value"); |
| 542 | |
| 543 | Module *M = Builder->GetInsertBlock()->getParent()->getParent(); |
| 544 | // Fill in the one generic type'd argument (the function is also vararg) |
| 545 | Function *FnStatepoint = Intrinsic::getDeclaration( |
| 546 | M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); |
| 547 | |
| 548 | std::vector<llvm::Value *> Args = |
| 549 | getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags, |
| 550 | InvokeArgs, TransitionArgs, DeoptArgs, GCArgs); |
| 551 | return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder, |
| 552 | Name); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 556 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
| 557 | BasicBlock *NormalDest, BasicBlock *UnwindDest, |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 558 | ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs, |
| 559 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 560 | return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>( |
| 561 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 562 | uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 563 | DeoptArgs, GCArgs, Name); |
| 564 | } |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 565 | |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 566 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
| 567 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 568 | BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 569 | ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs, |
| 570 | ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 571 | return CreateGCStatepointInvokeCommon<Use, Use, Use, Value *>( |
| 572 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags, |
| 573 | InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 577 | uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, |
| 578 | BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs, |
| 579 | ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) { |
Sanjoy Das | af6980c | 2015-10-07 19:52:12 +0000 | [diff] [blame] | 580 | return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>( |
| 581 | this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, |
Sanjoy Das | 4fd3d40 | 2015-10-08 23:18:33 +0000 | [diff] [blame] | 582 | uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs, |
| 583 | Name); |
Ramkumar Ramachandra | 3408f3e | 2015-02-26 00:35:56 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 586 | CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint, |
| 587 | Type *ResultType, |
| 588 | const Twine &Name) { |
Ramkumar Ramachandra | 75a4f35 | 2015-01-22 20:14:38 +0000 | [diff] [blame] | 589 | Intrinsic::ID ID = Intrinsic::experimental_gc_result; |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 590 | Module *M = BB->getParent()->getParent(); |
| 591 | Type *Types[] = {ResultType}; |
| 592 | Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); |
| 593 | |
| 594 | Value *Args[] = {Statepoint}; |
| 595 | return createCallHelper(FnGCResult, Args, this, Name); |
| 596 | } |
| 597 | |
| 598 | CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint, |
| 599 | int BaseOffset, |
| 600 | int DerivedOffset, |
| 601 | Type *ResultType, |
| 602 | const Twine &Name) { |
| 603 | Module *M = BB->getParent()->getParent(); |
| 604 | Type *Types[] = {ResultType}; |
| 605 | Value *FnGCRelocate = |
| 606 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); |
| 607 | |
| 608 | Value *Args[] = {Statepoint, |
| 609 | getInt32(BaseOffset), |
| 610 | getInt32(DerivedOffset)}; |
| 611 | return createCallHelper(FnGCRelocate, Args, this, Name); |
| 612 | } |
Matt Arsenault | cdb468c | 2017-02-27 23:08:49 +0000 | [diff] [blame] | 613 | |
| 614 | CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, |
| 615 | Value *LHS, Value *RHS, |
| 616 | const Twine &Name) { |
| 617 | Module *M = BB->getParent()->getParent(); |
| 618 | Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() }); |
| 619 | return createCallHelper(Fn, { LHS, RHS }, this, Name); |
| 620 | } |