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 | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Function.h" |
| 16 | #include "llvm/IR/GlobalVariable.h" |
| 17 | #include "llvm/IR/IRBuilder.h" |
| 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, |
| 28 | const Twine &Name) { |
Chris Lattner | cf9e8f6 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 29 | Constant *StrConstant = ConstantDataArray::getString(Context, Str); |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 30 | Module &M = *BB->getParent()->getParent(); |
| 31 | GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(), |
Benjamin Kramer | f1fd6e3 | 2011-12-22 14:22:14 +0000 | [diff] [blame] | 32 | true, GlobalValue::PrivateLinkage, |
Hans Wennborg | cbe34b4 | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 33 | StrConstant); |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 34 | GV->setName(Name); |
Nick Lewycky | 561f175 | 2011-04-07 00:14:29 +0000 | [diff] [blame] | 35 | GV->setUnnamedAddr(true); |
Chris Lattner | 17079fc | 2009-12-28 21:28:46 +0000 | [diff] [blame] | 36 | return GV; |
| 37 | } |
Chris Lattner | 7ef1cac | 2009-12-28 21:45:40 +0000 | [diff] [blame] | 38 | |
Chris Lattner | b1907b2 | 2011-07-12 04:14:22 +0000 | [diff] [blame] | 39 | Type *IRBuilderBase::getCurrentFunctionReturnType() const { |
Chris Lattner | 49f9f76 | 2009-12-28 21:50:56 +0000 | [diff] [blame] | 40 | assert(BB && BB->getParent() && "No current function!"); |
| 41 | return BB->getParent()->getReturnType(); |
| 42 | } |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 43 | |
| 44 | Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 45 | PointerType *PT = cast<PointerType>(Ptr->getType()); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 46 | if (PT->getElementType()->isIntegerTy(8)) |
| 47 | return Ptr; |
| 48 | |
| 49 | // Otherwise, we need to insert a bitcast. |
| 50 | PT = getInt8PtrTy(PT->getAddressSpace()); |
| 51 | BitCastInst *BCI = new BitCastInst(Ptr, PT, ""); |
| 52 | BB->getInstList().insert(InsertPt, BCI); |
| 53 | SetInstDebugLocation(BCI); |
| 54 | return BCI; |
| 55 | } |
| 56 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 57 | static CallInst *createCallHelper(Value *Callee, ArrayRef<Value *> Ops, |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 58 | IRBuilderBase *Builder, |
| 59 | const Twine& Name="") { |
| 60 | CallInst *CI = CallInst::Create(Callee, Ops, Name); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 61 | Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(),CI); |
| 62 | Builder->SetInstDebugLocation(CI); |
| 63 | return CI; |
| 64 | } |
| 65 | |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 66 | static InvokeInst *createInvokeHelper(Value *Invokee, BasicBlock *NormalDest, |
| 67 | BasicBlock *UnwindDest, |
| 68 | ArrayRef<Value *> Ops, |
| 69 | IRBuilderBase *Builder, |
| 70 | const Twine &Name = "") { |
| 71 | InvokeInst *II = |
| 72 | InvokeInst::Create(Invokee, NormalDest, UnwindDest, Ops, Name); |
| 73 | Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(), |
| 74 | II); |
| 75 | Builder->SetInstDebugLocation(II); |
| 76 | return II; |
| 77 | } |
| 78 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 79 | CallInst *IRBuilderBase:: |
| 80 | CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 81 | bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag, |
| 82 | MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 83 | Ptr = getCastedInt8PtrValue(Ptr); |
| 84 | Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 85 | Type *Tys[] = { Ptr->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 86 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 87 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 88 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 89 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 90 | |
| 91 | // Set the TBAA info if present. |
| 92 | if (TBAATag) |
| 93 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 94 | |
| 95 | if (ScopeTag) |
| 96 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 97 | |
| 98 | if (NoAliasTag) |
| 99 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 100 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 101 | return CI; |
| 102 | } |
| 103 | |
| 104 | CallInst *IRBuilderBase:: |
| 105 | CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 106 | bool isVolatile, MDNode *TBAATag, MDNode *TBAAStructTag, |
| 107 | MDNode *ScopeTag, MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 108 | Dst = getCastedInt8PtrValue(Dst); |
| 109 | Src = getCastedInt8PtrValue(Src); |
| 110 | |
| 111 | Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 112 | Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 113 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 114 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 115 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 116 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 117 | |
| 118 | // Set the TBAA info if present. |
| 119 | if (TBAATag) |
| 120 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Dan Gohman | 099727f | 2012-09-26 22:17:14 +0000 | [diff] [blame] | 121 | |
| 122 | // Set the TBAA Struct info if present. |
| 123 | if (TBAAStructTag) |
| 124 | CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 125 | |
| 126 | if (ScopeTag) |
| 127 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 128 | |
| 129 | if (NoAliasTag) |
| 130 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 131 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 132 | return CI; |
| 133 | } |
| 134 | |
| 135 | CallInst *IRBuilderBase:: |
| 136 | CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align, |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 137 | bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag, |
| 138 | MDNode *NoAliasTag) { |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 139 | Dst = getCastedInt8PtrValue(Dst); |
| 140 | Src = getCastedInt8PtrValue(Src); |
| 141 | |
| 142 | Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 143 | Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 144 | Module *M = BB->getParent()->getParent(); |
Benjamin Kramer | e6e1933 | 2011-07-14 17:45:39 +0000 | [diff] [blame] | 145 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 146 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 147 | CallInst *CI = createCallHelper(TheFn, Ops, this); |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 148 | |
| 149 | // Set the TBAA info if present. |
| 150 | if (TBAATag) |
| 151 | CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); |
Hal Finkel | 9414665 | 2014-07-24 14:25:39 +0000 | [diff] [blame] | 152 | |
| 153 | if (ScopeTag) |
| 154 | CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); |
| 155 | |
| 156 | if (NoAliasTag) |
| 157 | CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); |
| 158 | |
Chris Lattner | 143a07c | 2010-12-26 22:49:25 +0000 | [diff] [blame] | 159 | return CI; |
| 160 | } |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 161 | |
| 162 | CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) { |
| 163 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 164 | "lifetime.start only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 165 | Ptr = getCastedInt8PtrValue(Ptr); |
| 166 | if (!Size) |
| 167 | Size = getInt64(-1); |
| 168 | else |
| 169 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 170 | "lifetime.start requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 171 | Value *Ops[] = { Size, Ptr }; |
| 172 | Module *M = BB->getParent()->getParent(); |
| 173 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 174 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) { |
| 178 | assert(isa<PointerType>(Ptr->getType()) && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 179 | "lifetime.end only applies to pointers."); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 180 | Ptr = getCastedInt8PtrValue(Ptr); |
| 181 | if (!Size) |
| 182 | Size = getInt64(-1); |
| 183 | else |
| 184 | assert(Size->getType() == getInt64Ty() && |
Bill Wendling | ea6397f | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 185 | "lifetime.end requires the size to be an i64"); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 186 | Value *Ops[] = { Size, Ptr }; |
| 187 | Module *M = BB->getParent()->getParent(); |
| 188 | Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 189 | return createCallHelper(TheFn, Ops, this); |
Nick Lewycky | babca9a | 2011-05-21 23:14:36 +0000 | [diff] [blame] | 190 | } |
Hal Finkel | 6f814db | 2014-10-15 23:44:22 +0000 | [diff] [blame] | 191 | |
| 192 | CallInst *IRBuilderBase::CreateAssumption(Value *Cond) { |
| 193 | assert(Cond->getType() == getInt1Ty() && |
| 194 | "an assumption condition must be of type i1"); |
| 195 | |
| 196 | Value *Ops[] = { Cond }; |
| 197 | Module *M = BB->getParent()->getParent(); |
| 198 | Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); |
| 199 | return createCallHelper(FnAssume, Ops, this); |
| 200 | } |
| 201 | |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 202 | /// Create a call to a Masked Load intrinsic. |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 203 | /// Ptr - the base pointer for the load |
| 204 | /// Align - alignment of the source location |
| 205 | /// Mask - an vector of booleans which indicates what vector lanes should |
| 206 | /// be accessed in memory |
| 207 | /// PassThru - a pass-through value that is used to fill the masked-off lanes |
| 208 | /// of the result |
| 209 | /// Name - name of the result variable |
| 210 | CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, |
| 211 | Value *Mask, Value *PassThru, |
| 212 | const Twine &Name) { |
| 213 | assert(Ptr->getType()->isPointerTy() && "Ptr must be of pointer type"); |
| 214 | // DataTy is the overloaded type |
| 215 | Type *DataTy = cast<PointerType>(Ptr->getType())->getElementType(); |
| 216 | assert(DataTy->isVectorTy() && "Ptr should point to a vector"); |
| 217 | if (!PassThru) |
| 218 | PassThru = UndefValue::get(DataTy); |
| 219 | Value *Ops[] = { Ptr, getInt32(Align), Mask, PassThru}; |
| 220 | return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, DataTy, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /// Create a call to a Masked Store intrinsic. |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 224 | /// Val - the data to be stored, |
| 225 | /// Ptr - the base pointer for the store |
| 226 | /// Align - alignment of the destination location |
| 227 | /// Mask - an vector of booleans which indicates what vector lanes should |
| 228 | /// be accessed in memory |
| 229 | CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr, |
| 230 | unsigned Align, Value *Mask) { |
| 231 | Value *Ops[] = { Val, Ptr, getInt32(Align), Mask }; |
| 232 | // Type of the data to be stored - the only one overloaded type |
| 233 | return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, Val->getType()); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /// Create a call to a Masked intrinsic, with given intrinsic Id, |
| 237 | /// an array of operands - Ops, and one overloaded type - DataTy |
| 238 | CallInst *IRBuilderBase::CreateMaskedIntrinsic(unsigned Id, |
| 239 | ArrayRef<Value *> Ops, |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 240 | Type *DataTy, |
| 241 | const Twine &Name) { |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 242 | Module *M = BB->getParent()->getParent(); |
| 243 | Type *OverloadedTypes[] = { DataTy }; |
| 244 | Value *TheFn = Intrinsic::getDeclaration(M, (Intrinsic::ID)Id, OverloadedTypes); |
Elena Demikhovsky | 84d1997 | 2014-12-30 14:28:14 +0000 | [diff] [blame] | 245 | return createCallHelper(TheFn, Ops, this, Name); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 246 | } |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 247 | |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 248 | static std::vector<Value *> getStatepointArgs(IRBuilderBase &B, |
| 249 | Value *ActualCallee, |
| 250 | ArrayRef<Value *> CallArgs, |
| 251 | ArrayRef<Value *> DeoptArgs, |
| 252 | ArrayRef<Value *> GCArgs) { |
| 253 | std::vector<Value *> Args; |
| 254 | Args.push_back(ActualCallee); |
| 255 | Args.push_back(B.getInt32(CallArgs.size())); |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame^] | 256 | Args.push_back(B.getInt32((unsigned)StatepointFlags::None)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 257 | Args.insert(Args.end(), CallArgs.begin(), CallArgs.end()); |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame^] | 258 | Args.push_back(B.getInt32(0 /* no transition args */)); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 259 | Args.push_back(B.getInt32(DeoptArgs.size())); |
| 260 | Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end()); |
| 261 | Args.insert(Args.end(), GCArgs.begin(), GCArgs.end()); |
| 262 | |
| 263 | return Args; |
| 264 | } |
| 265 | |
| 266 | CallInst *IRBuilderBase::CreateGCStatepointCall(Value *ActualCallee, |
| 267 | ArrayRef<Value *> CallArgs, |
| 268 | ArrayRef<Value *> DeoptArgs, |
| 269 | ArrayRef<Value *> GCArgs, |
| 270 | const Twine &Name) { |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 271 | // Extract out the type of the callee. |
| 272 | PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType()); |
| 273 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 274 | "actual callee must be a callable value"); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 275 | |
Sanjoy Das | 63245b5 | 2015-05-06 02:36:34 +0000 | [diff] [blame] | 276 | Module *M = BB->getParent()->getParent(); |
| 277 | // Fill in the one generic type'd argument (the function is also vararg) |
| 278 | Type *ArgTypes[] = { FuncPtrType }; |
| 279 | Function *FnStatepoint = |
| 280 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, |
| 281 | ArgTypes); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 282 | |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 283 | std::vector<llvm::Value *> Args = |
| 284 | getStatepointArgs(*this, ActualCallee, CallArgs, DeoptArgs, GCArgs); |
| 285 | return createCallHelper(FnStatepoint, Args, this, Name); |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 288 | CallInst *IRBuilderBase::CreateGCStatepointCall(Value *ActualCallee, |
| 289 | ArrayRef<Use> CallArgs, |
| 290 | ArrayRef<Value *> DeoptArgs, |
| 291 | ArrayRef<Value *> GCArgs, |
| 292 | const Twine &Name) { |
Ramkumar Ramachandra | 3408f3e | 2015-02-26 00:35:56 +0000 | [diff] [blame] | 293 | std::vector<Value *> VCallArgs; |
| 294 | for (auto &U : CallArgs) |
| 295 | VCallArgs.push_back(U.get()); |
Sanjoy Das | abe1c68 | 2015-05-06 23:53:09 +0000 | [diff] [blame] | 296 | return CreateGCStatepointCall(ActualCallee, VCallArgs, DeoptArgs, GCArgs, |
| 297 | Name); |
| 298 | } |
| 299 | |
| 300 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
| 301 | Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, |
| 302 | ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs, |
| 303 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 304 | // Extract out the type of the callee. |
| 305 | PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); |
| 306 | assert(isa<FunctionType>(FuncPtrType->getElementType()) && |
| 307 | "actual callee must be a callable value"); |
| 308 | |
| 309 | Module *M = BB->getParent()->getParent(); |
| 310 | // Fill in the one generic type'd argument (the function is also vararg) |
| 311 | Function *FnStatepoint = Intrinsic::getDeclaration( |
| 312 | M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); |
| 313 | |
| 314 | std::vector<llvm::Value *> Args = |
| 315 | getStatepointArgs(*this, ActualInvokee, InvokeArgs, DeoptArgs, GCArgs); |
| 316 | return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, this, |
| 317 | Name); |
| 318 | } |
| 319 | |
| 320 | InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( |
| 321 | Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, |
| 322 | ArrayRef<Use> InvokeArgs, ArrayRef<Value *> DeoptArgs, |
| 323 | ArrayRef<Value *> GCArgs, const Twine &Name) { |
| 324 | std::vector<Value *> VCallArgs; |
| 325 | for (auto &U : InvokeArgs) |
| 326 | VCallArgs.push_back(U.get()); |
| 327 | return CreateGCStatepointInvoke(ActualInvokee, NormalDest, UnwindDest, |
| 328 | VCallArgs, DeoptArgs, GCArgs, Name); |
Ramkumar Ramachandra | 3408f3e | 2015-02-26 00:35:56 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 331 | CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint, |
| 332 | Type *ResultType, |
| 333 | const Twine &Name) { |
Ramkumar Ramachandra | 75a4f35 | 2015-01-22 20:14:38 +0000 | [diff] [blame] | 334 | Intrinsic::ID ID = Intrinsic::experimental_gc_result; |
Philip Reames | 4750dd1 | 2014-12-30 05:55:58 +0000 | [diff] [blame] | 335 | Module *M = BB->getParent()->getParent(); |
| 336 | Type *Types[] = {ResultType}; |
| 337 | Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); |
| 338 | |
| 339 | Value *Args[] = {Statepoint}; |
| 340 | return createCallHelper(FnGCResult, Args, this, Name); |
| 341 | } |
| 342 | |
| 343 | CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint, |
| 344 | int BaseOffset, |
| 345 | int DerivedOffset, |
| 346 | Type *ResultType, |
| 347 | const Twine &Name) { |
| 348 | Module *M = BB->getParent()->getParent(); |
| 349 | Type *Types[] = {ResultType}; |
| 350 | Value *FnGCRelocate = |
| 351 | Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); |
| 352 | |
| 353 | Value *Args[] = {Statepoint, |
| 354 | getInt32(BaseOffset), |
| 355 | getInt32(DerivedOffset)}; |
| 356 | return createCallHelper(FnGCRelocate, Args, this, Name); |
| 357 | } |