1 //===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the IRBuilder class, which is used as a convenient way
11 // to create LLVM instructions with a consistent and simplified interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_IRBUILDER_H
16 #define LLVM_IR_IRBUILDER_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/IR/BasicBlock.h"
22 #include "llvm/IR/ConstantFolder.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/IR/LLVMContext.h"
26 #include "llvm/IR/Operator.h"
27 #include "llvm/IR/ValueHandle.h"
28 #include "llvm/Support/CBindingWrapping.h"
33 /// \brief This provides the default implementation of the IRBuilder
34 /// 'InsertHelper' method that is called whenever an instruction is created by
35 /// IRBuilder and needs to be inserted.
37 /// By default, this inserts the instruction at the insertion point.
38 template <bool preserveNames = true>
39 class IRBuilderDefaultInserter {
41 void InsertHelper(Instruction *I, const Twine &Name,
42 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
43 if (BB) BB->getInstList().insert(InsertPt, I);
49 /// \brief Common base class shared among various IRBuilders.
51 DebugLoc CurDbgLocation;
54 BasicBlock::iterator InsertPt;
57 MDNode *DefaultFPMathTag;
61 IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr)
62 : Context(context), DefaultFPMathTag(FPMathTag), FMF() {
63 ClearInsertionPoint();
66 //===--------------------------------------------------------------------===//
67 // Builder configuration methods
68 //===--------------------------------------------------------------------===//
70 /// \brief Clear the insertion point: created instructions will not be
71 /// inserted into a block.
72 void ClearInsertionPoint() {
77 BasicBlock *GetInsertBlock() const { return BB; }
78 BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
79 LLVMContext &getContext() const { return Context; }
81 /// \brief This specifies that created instructions should be appended to the
82 /// end of the specified block.
83 void SetInsertPoint(BasicBlock *TheBB) {
88 /// \brief This specifies that created instructions should be inserted before
89 /// the specified instruction.
90 void SetInsertPoint(Instruction *I) {
93 assert(I != BB->end() && "Can't read debug loc from end()");
94 SetCurrentDebugLocation(I->getDebugLoc());
97 /// \brief This specifies that created instructions should be inserted at the
99 void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
104 /// \brief Find the nearest point that dominates this use, and specify that
105 /// created instructions should be inserted at this point.
106 void SetInsertPoint(Use &U) {
107 Instruction *UseInst = cast<Instruction>(U.getUser());
108 if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
109 BasicBlock *PredBB = Phi->getIncomingBlock(U);
110 assert(U != PredBB->getTerminator() && "critical edge not split");
111 SetInsertPoint(PredBB, PredBB->getTerminator());
114 SetInsertPoint(UseInst);
117 /// \brief Set location information used by debugging information.
118 void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
120 /// \brief Get location information used by debugging information.
121 const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
123 /// \brief If this builder has a current debug location, set it on the
124 /// specified instruction.
125 void SetInstDebugLocation(Instruction *I) const {
126 if (!CurDbgLocation.isUnknown())
127 I->setDebugLoc(CurDbgLocation);
130 /// \brief Get the return type of the current function that we're emitting
132 Type *getCurrentFunctionReturnType() const;
134 /// InsertPoint - A saved insertion point.
137 BasicBlock::iterator Point;
140 /// \brief Creates a new insertion point which doesn't point to anything.
141 InsertPoint() : Block(nullptr) {}
143 /// \brief Creates a new insertion point at the given location.
144 InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
145 : Block(InsertBlock), Point(InsertPoint) {}
147 /// \brief Returns true if this insert point is set.
148 bool isSet() const { return (Block != nullptr); }
150 llvm::BasicBlock *getBlock() const { return Block; }
151 llvm::BasicBlock::iterator getPoint() const { return Point; }
154 /// \brief Returns the current insert point.
155 InsertPoint saveIP() const {
156 return InsertPoint(GetInsertBlock(), GetInsertPoint());
159 /// \brief Returns the current insert point, clearing it in the process.
160 InsertPoint saveAndClearIP() {
161 InsertPoint IP(GetInsertBlock(), GetInsertPoint());
162 ClearInsertionPoint();
166 /// \brief Sets the current insert point to a previously-saved location.
167 void restoreIP(InsertPoint IP) {
169 SetInsertPoint(IP.getBlock(), IP.getPoint());
171 ClearInsertionPoint();
174 /// \brief Get the floating point math metadata being used.
175 MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
177 /// \brief Get the flags to be applied to created floating point ops
178 FastMathFlags getFastMathFlags() const { return FMF; }
180 /// \brief Clear the fast-math flags.
181 void clearFastMathFlags() { FMF.clear(); }
183 /// \brief Set the floating point math metadata to be used.
184 void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
186 /// \brief Set the fast-math flags to be used with generated fp-math operators
187 void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
189 //===--------------------------------------------------------------------===//
191 //===--------------------------------------------------------------------===//
193 // \brief RAII object that stores the current insertion point and restores it
194 // when the object is destroyed. This includes the debug location.
195 class InsertPointGuard {
196 IRBuilderBase &Builder;
197 AssertingVH<BasicBlock> Block;
198 BasicBlock::iterator Point;
201 InsertPointGuard(const InsertPointGuard &) = delete;
202 InsertPointGuard &operator=(const InsertPointGuard &) = delete;
205 InsertPointGuard(IRBuilderBase &B)
206 : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
207 DbgLoc(B.getCurrentDebugLocation()) {}
209 ~InsertPointGuard() {
210 Builder.restoreIP(InsertPoint(Block, Point));
211 Builder.SetCurrentDebugLocation(DbgLoc);
215 // \brief RAII object that stores the current fast math settings and restores
216 // them when the object is destroyed.
217 class FastMathFlagGuard {
218 IRBuilderBase &Builder;
222 FastMathFlagGuard(const FastMathFlagGuard &) = delete;
223 FastMathFlagGuard &operator=(
224 const FastMathFlagGuard &) = delete;
227 FastMathFlagGuard(IRBuilderBase &B)
228 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
230 ~FastMathFlagGuard() {
232 Builder.DefaultFPMathTag = FPMathTag;
236 //===--------------------------------------------------------------------===//
237 // Miscellaneous creation methods.
238 //===--------------------------------------------------------------------===//
240 /// \brief Make a new global variable with initializer type i8*
242 /// Make a new global variable with an initializer that has array of i8 type
243 /// filled in with the null terminated string value specified. The new global
244 /// variable will be marked mergable with any others of the same contents. If
245 /// Name is specified, it is the name of the global variable created.
246 Value *CreateGlobalString(StringRef Str, const Twine &Name = "");
248 /// \brief Get a constant value representing either true or false.
249 ConstantInt *getInt1(bool V) {
250 return ConstantInt::get(getInt1Ty(), V);
253 /// \brief Get the constant value for i1 true.
254 ConstantInt *getTrue() {
255 return ConstantInt::getTrue(Context);
258 /// \brief Get the constant value for i1 false.
259 ConstantInt *getFalse() {
260 return ConstantInt::getFalse(Context);
263 /// \brief Get a constant 8-bit value.
264 ConstantInt *getInt8(uint8_t C) {
265 return ConstantInt::get(getInt8Ty(), C);
268 /// \brief Get a constant 16-bit value.
269 ConstantInt *getInt16(uint16_t C) {
270 return ConstantInt::get(getInt16Ty(), C);
273 /// \brief Get a constant 32-bit value.
274 ConstantInt *getInt32(uint32_t C) {
275 return ConstantInt::get(getInt32Ty(), C);
278 /// \brief Get a constant 64-bit value.
279 ConstantInt *getInt64(uint64_t C) {
280 return ConstantInt::get(getInt64Ty(), C);
283 /// \brief Get a constant N-bit value, zero extended or truncated from
285 ConstantInt *getIntN(unsigned N, uint64_t C) {
286 return ConstantInt::get(getIntNTy(N), C);
289 /// \brief Get a constant integer value.
290 ConstantInt *getInt(const APInt &AI) {
291 return ConstantInt::get(Context, AI);
294 //===--------------------------------------------------------------------===//
295 // Type creation methods
296 //===--------------------------------------------------------------------===//
298 /// \brief Fetch the type representing a single bit
299 IntegerType *getInt1Ty() {
300 return Type::getInt1Ty(Context);
303 /// \brief Fetch the type representing an 8-bit integer.
304 IntegerType *getInt8Ty() {
305 return Type::getInt8Ty(Context);
308 /// \brief Fetch the type representing a 16-bit integer.
309 IntegerType *getInt16Ty() {
310 return Type::getInt16Ty(Context);
313 /// \brief Fetch the type representing a 32-bit integer.
314 IntegerType *getInt32Ty() {
315 return Type::getInt32Ty(Context);
318 /// \brief Fetch the type representing a 64-bit integer.
319 IntegerType *getInt64Ty() {
320 return Type::getInt64Ty(Context);
323 /// \brief Fetch the type representing an N-bit integer.
324 IntegerType *getIntNTy(unsigned N) {
325 return Type::getIntNTy(Context, N);
328 /// \brief Fetch the type representing a 16-bit floating point value.
330 return Type::getHalfTy(Context);
333 /// \brief Fetch the type representing a 32-bit floating point value.
335 return Type::getFloatTy(Context);
338 /// \brief Fetch the type representing a 64-bit floating point value.
339 Type *getDoubleTy() {
340 return Type::getDoubleTy(Context);
343 /// \brief Fetch the type representing void.
345 return Type::getVoidTy(Context);
348 /// \brief Fetch the type representing a pointer to an 8-bit integer value.
349 PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
350 return Type::getInt8PtrTy(Context, AddrSpace);
353 /// \brief Fetch the type representing a pointer to an integer value.
354 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
355 return DL.getIntPtrType(Context, AddrSpace);
358 //===--------------------------------------------------------------------===//
359 // Intrinsic creation methods
360 //===--------------------------------------------------------------------===//
362 /// \brief Create and insert a memset to the specified pointer and the
365 /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
366 /// specified, it will be added to the instruction. Likewise with alias.scope
367 /// and noalias tags.
368 CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
369 bool isVolatile = false, MDNode *TBAATag = nullptr,
370 MDNode *ScopeTag = nullptr,
371 MDNode *NoAliasTag = nullptr) {
372 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
373 TBAATag, ScopeTag, NoAliasTag);
376 CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
377 bool isVolatile = false, MDNode *TBAATag = nullptr,
378 MDNode *ScopeTag = nullptr,
379 MDNode *NoAliasTag = nullptr);
381 /// \brief Create and insert a memcpy between the specified pointers.
383 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
384 /// specified, it will be added to the instruction. Likewise with alias.scope
385 /// and noalias tags.
386 CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
387 bool isVolatile = false, MDNode *TBAATag = nullptr,
388 MDNode *TBAAStructTag = nullptr,
389 MDNode *ScopeTag = nullptr,
390 MDNode *NoAliasTag = nullptr) {
391 return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag,
392 TBAAStructTag, ScopeTag, NoAliasTag);
395 CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
396 bool isVolatile = false, MDNode *TBAATag = nullptr,
397 MDNode *TBAAStructTag = nullptr,
398 MDNode *ScopeTag = nullptr,
399 MDNode *NoAliasTag = nullptr);
401 /// \brief Create and insert a memmove between the specified
404 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
405 /// specified, it will be added to the instruction. Likewise with alias.scope
406 /// and noalias tags.
407 CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
408 bool isVolatile = false, MDNode *TBAATag = nullptr,
409 MDNode *ScopeTag = nullptr,
410 MDNode *NoAliasTag = nullptr) {
411 return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile,
412 TBAATag, ScopeTag, NoAliasTag);
415 CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
416 bool isVolatile = false, MDNode *TBAATag = nullptr,
417 MDNode *ScopeTag = nullptr,
418 MDNode *NoAliasTag = nullptr);
420 /// \brief Create a lifetime.start intrinsic.
422 /// If the pointer isn't i8* it will be converted.
423 CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
425 /// \brief Create a lifetime.end intrinsic.
427 /// If the pointer isn't i8* it will be converted.
428 CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
430 /// \brief Create a call to Masked Load intrinsic
431 CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
432 Value *PassThru = 0, const Twine &Name = "");
434 /// \brief Create a call to Masked Store intrinsic
435 CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
438 /// \brief Create an assume intrinsic call that allows the optimizer to
439 /// assume that the provided condition will be true.
440 CallInst *CreateAssumption(Value *Cond);
442 /// \brief Create a call to the experimental.gc.statepoint intrinsic to
443 /// start a new statepoint sequence.
444 CallInst *CreateGCStatepoint(Value *ActualCallee,
445 ArrayRef<Value *> CallArgs,
446 ArrayRef<Value *> DeoptArgs,
447 ArrayRef<Value *> GCArgs,
448 const Twine &Name = "");
450 // Conveninence function for the common case when CallArgs are filled in using
451 // makeArrayRef(CS.arg_begin(), .arg_end()); Use needs to be .get()'ed to get
453 CallInst *CreateGCStatepoint(Value *ActualCallee, ArrayRef<Use> CallArgs,
454 ArrayRef<Value *> DeoptArgs,
455 ArrayRef<Value *> GCArgs,
456 const Twine &Name = "");
458 /// \brief Create a call to the experimental.gc.result intrinsic to extract
459 /// the result from a call wrapped in a statepoint.
460 CallInst *CreateGCResult(Instruction *Statepoint,
462 const Twine &Name = "");
464 /// \brief Create a call to the experimental.gc.relocate intrinsics to
465 /// project the relocated value of one pointer from the statepoint.
466 CallInst *CreateGCRelocate(Instruction *Statepoint,
470 const Twine &Name = "");
473 /// \brief Create a call to a masked intrinsic with given Id.
474 /// Masked intrinsic has only one overloaded type - data type.
475 CallInst *CreateMaskedIntrinsic(unsigned Id, ArrayRef<Value *> Ops,
476 Type *DataTy, const Twine &Name = "");
478 Value *getCastedInt8PtrValue(Value *Ptr);
481 /// \brief This provides a uniform API for creating instructions and inserting
482 /// them into a basic block: either at the end of a BasicBlock, or at a specific
483 /// iterator location in a block.
485 /// Note that the builder does not expose the full generality of LLVM
486 /// instructions. For access to extra instruction properties, use the mutators
487 /// (e.g. setVolatile) on the instructions after they have been
488 /// created. Convenience state exists to specify fast-math flags and fp-math
491 /// The first template argument handles whether or not to preserve names in the
492 /// final instruction output. This defaults to on. The second template argument
493 /// specifies a class to use for creating constants. This defaults to creating
494 /// minimally folded constants. The third template argument allows clients to
495 /// specify custom insertion hooks that are called on every newly created
497 template<bool preserveNames = true, typename T = ConstantFolder,
498 typename Inserter = IRBuilderDefaultInserter<preserveNames> >
499 class IRBuilder : public IRBuilderBase, public Inserter {
502 IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter(),
503 MDNode *FPMathTag = nullptr)
504 : IRBuilderBase(C, FPMathTag), Inserter(I), Folder(F) {
507 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr)
508 : IRBuilderBase(C, FPMathTag), Folder() {
511 explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr)
512 : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
513 SetInsertPoint(TheBB);
516 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr)
517 : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
518 SetInsertPoint(TheBB);
521 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr)
522 : IRBuilderBase(IP->getContext(), FPMathTag), Folder() {
524 SetCurrentDebugLocation(IP->getDebugLoc());
527 explicit IRBuilder(Use &U, MDNode *FPMathTag = nullptr)
528 : IRBuilderBase(U->getContext(), FPMathTag), Folder() {
530 SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
533 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F,
534 MDNode *FPMathTag = nullptr)
535 : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
536 SetInsertPoint(TheBB, IP);
539 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
540 MDNode *FPMathTag = nullptr)
541 : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
542 SetInsertPoint(TheBB, IP);
545 /// \brief Get the constant folder being used.
546 const T &getFolder() { return Folder; }
548 /// \brief Return true if this builder is configured to actually add the
549 /// requested names to IR created through it.
550 bool isNamePreserving() const { return preserveNames; }
552 /// \brief Insert and return the specified instruction.
553 template<typename InstTy>
554 InstTy *Insert(InstTy *I, const Twine &Name = "") const {
555 this->InsertHelper(I, Name, BB, InsertPt);
556 this->SetInstDebugLocation(I);
560 /// \brief No-op overload to handle constants.
561 Constant *Insert(Constant *C, const Twine& = "") const {
565 //===--------------------------------------------------------------------===//
566 // Instruction creation methods: Terminators
567 //===--------------------------------------------------------------------===//
570 /// \brief Helper to add branch weight metadata onto an instruction.
571 /// \returns The annotated instruction.
572 template <typename InstTy>
573 InstTy *addBranchWeights(InstTy *I, MDNode *Weights) {
575 I->setMetadata(LLVMContext::MD_prof, Weights);
580 /// \brief Create a 'ret void' instruction.
581 ReturnInst *CreateRetVoid() {
582 return Insert(ReturnInst::Create(Context));
585 /// \brief Create a 'ret <val>' instruction.
586 ReturnInst *CreateRet(Value *V) {
587 return Insert(ReturnInst::Create(Context, V));
590 /// \brief Create a sequence of N insertvalue instructions,
591 /// with one Value from the retVals array each, that build a aggregate
592 /// return value one value at a time, and a ret instruction to return
593 /// the resulting aggregate value.
595 /// This is a convenience function for code that uses aggregate return values
596 /// as a vehicle for having multiple return values.
597 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
598 Value *V = UndefValue::get(getCurrentFunctionReturnType());
599 for (unsigned i = 0; i != N; ++i)
600 V = CreateInsertValue(V, retVals[i], i, "mrv");
601 return Insert(ReturnInst::Create(Context, V));
604 /// \brief Create an unconditional 'br label X' instruction.
605 BranchInst *CreateBr(BasicBlock *Dest) {
606 return Insert(BranchInst::Create(Dest));
609 /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
611 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
612 MDNode *BranchWeights = nullptr) {
613 return Insert(addBranchWeights(BranchInst::Create(True, False, Cond),
617 /// \brief Create a switch instruction with the specified value, default dest,
618 /// and with a hint for the number of cases that will be added (for efficient
620 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
621 MDNode *BranchWeights = nullptr) {
622 return Insert(addBranchWeights(SwitchInst::Create(V, Dest, NumCases),
626 /// \brief Create an indirect branch instruction with the specified address
627 /// operand, with an optional hint for the number of destinations that will be
628 /// added (for efficient allocation).
629 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
630 return Insert(IndirectBrInst::Create(Addr, NumDests));
633 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
634 BasicBlock *UnwindDest, const Twine &Name = "") {
635 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, None),
638 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
639 BasicBlock *UnwindDest, Value *Arg1,
640 const Twine &Name = "") {
641 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Arg1),
644 InvokeInst *CreateInvoke3(Value *Callee, BasicBlock *NormalDest,
645 BasicBlock *UnwindDest, Value *Arg1,
646 Value *Arg2, Value *Arg3,
647 const Twine &Name = "") {
648 Value *Args[] = { Arg1, Arg2, Arg3 };
649 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
652 /// \brief Create an invoke instruction.
653 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
654 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
655 const Twine &Name = "") {
656 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
660 ResumeInst *CreateResume(Value *Exn) {
661 return Insert(ResumeInst::Create(Exn));
664 UnreachableInst *CreateUnreachable() {
665 return Insert(new UnreachableInst(Context));
668 //===--------------------------------------------------------------------===//
669 // Instruction creation methods: Binary Operators
670 //===--------------------------------------------------------------------===//
672 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
673 Value *LHS, Value *RHS,
675 bool HasNUW, bool HasNSW) {
676 BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
677 if (HasNUW) BO->setHasNoUnsignedWrap();
678 if (HasNSW) BO->setHasNoSignedWrap();
682 Instruction *AddFPMathAttributes(Instruction *I,
684 FastMathFlags FMF) const {
686 FPMathTag = DefaultFPMathTag;
688 I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
689 I->setFastMathFlags(FMF);
693 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
694 bool HasNUW = false, bool HasNSW = false) {
695 if (Constant *LC = dyn_cast<Constant>(LHS))
696 if (Constant *RC = dyn_cast<Constant>(RHS))
697 return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
698 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
701 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
702 return CreateAdd(LHS, RHS, Name, false, true);
704 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
705 return CreateAdd(LHS, RHS, Name, true, false);
707 Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
708 MDNode *FPMathTag = nullptr) {
709 if (Constant *LC = dyn_cast<Constant>(LHS))
710 if (Constant *RC = dyn_cast<Constant>(RHS))
711 return Insert(Folder.CreateFAdd(LC, RC), Name);
712 return Insert(AddFPMathAttributes(BinaryOperator::CreateFAdd(LHS, RHS),
713 FPMathTag, FMF), Name);
715 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
716 bool HasNUW = false, bool HasNSW = false) {
717 if (Constant *LC = dyn_cast<Constant>(LHS))
718 if (Constant *RC = dyn_cast<Constant>(RHS))
719 return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
720 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
723 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
724 return CreateSub(LHS, RHS, Name, false, true);
726 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
727 return CreateSub(LHS, RHS, Name, true, false);
729 Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
730 MDNode *FPMathTag = nullptr) {
731 if (Constant *LC = dyn_cast<Constant>(LHS))
732 if (Constant *RC = dyn_cast<Constant>(RHS))
733 return Insert(Folder.CreateFSub(LC, RC), Name);
734 return Insert(AddFPMathAttributes(BinaryOperator::CreateFSub(LHS, RHS),
735 FPMathTag, FMF), Name);
737 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
738 bool HasNUW = false, bool HasNSW = false) {
739 if (Constant *LC = dyn_cast<Constant>(LHS))
740 if (Constant *RC = dyn_cast<Constant>(RHS))
741 return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
742 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
745 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
746 return CreateMul(LHS, RHS, Name, false, true);
748 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
749 return CreateMul(LHS, RHS, Name, true, false);
751 Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
752 MDNode *FPMathTag = nullptr) {
753 if (Constant *LC = dyn_cast<Constant>(LHS))
754 if (Constant *RC = dyn_cast<Constant>(RHS))
755 return Insert(Folder.CreateFMul(LC, RC), Name);
756 return Insert(AddFPMathAttributes(BinaryOperator::CreateFMul(LHS, RHS),
757 FPMathTag, FMF), Name);
759 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
760 bool isExact = false) {
761 if (Constant *LC = dyn_cast<Constant>(LHS))
762 if (Constant *RC = dyn_cast<Constant>(RHS))
763 return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
765 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
766 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
768 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
769 return CreateUDiv(LHS, RHS, Name, true);
771 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
772 bool isExact = false) {
773 if (Constant *LC = dyn_cast<Constant>(LHS))
774 if (Constant *RC = dyn_cast<Constant>(RHS))
775 return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
777 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
778 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
780 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
781 return CreateSDiv(LHS, RHS, Name, true);
783 Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
784 MDNode *FPMathTag = nullptr) {
785 if (Constant *LC = dyn_cast<Constant>(LHS))
786 if (Constant *RC = dyn_cast<Constant>(RHS))
787 return Insert(Folder.CreateFDiv(LC, RC), Name);
788 return Insert(AddFPMathAttributes(BinaryOperator::CreateFDiv(LHS, RHS),
789 FPMathTag, FMF), Name);
791 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
792 if (Constant *LC = dyn_cast<Constant>(LHS))
793 if (Constant *RC = dyn_cast<Constant>(RHS))
794 return Insert(Folder.CreateURem(LC, RC), Name);
795 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
797 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
798 if (Constant *LC = dyn_cast<Constant>(LHS))
799 if (Constant *RC = dyn_cast<Constant>(RHS))
800 return Insert(Folder.CreateSRem(LC, RC), Name);
801 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
803 Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
804 MDNode *FPMathTag = nullptr) {
805 if (Constant *LC = dyn_cast<Constant>(LHS))
806 if (Constant *RC = dyn_cast<Constant>(RHS))
807 return Insert(Folder.CreateFRem(LC, RC), Name);
808 return Insert(AddFPMathAttributes(BinaryOperator::CreateFRem(LHS, RHS),
809 FPMathTag, FMF), Name);
812 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
813 bool HasNUW = false, bool HasNSW = false) {
814 if (Constant *LC = dyn_cast<Constant>(LHS))
815 if (Constant *RC = dyn_cast<Constant>(RHS))
816 return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
817 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
820 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
821 bool HasNUW = false, bool HasNSW = false) {
822 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
825 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
826 bool HasNUW = false, bool HasNSW = false) {
827 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
831 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
832 bool isExact = false) {
833 if (Constant *LC = dyn_cast<Constant>(LHS))
834 if (Constant *RC = dyn_cast<Constant>(RHS))
835 return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
837 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
838 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
840 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
841 bool isExact = false) {
842 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
844 Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
845 bool isExact = false) {
846 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
849 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
850 bool isExact = false) {
851 if (Constant *LC = dyn_cast<Constant>(LHS))
852 if (Constant *RC = dyn_cast<Constant>(RHS))
853 return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
855 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
856 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
858 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
859 bool isExact = false) {
860 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
862 Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
863 bool isExact = false) {
864 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
867 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
868 if (Constant *RC = dyn_cast<Constant>(RHS)) {
869 if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isAllOnesValue())
870 return LHS; // LHS & -1 -> LHS
871 if (Constant *LC = dyn_cast<Constant>(LHS))
872 return Insert(Folder.CreateAnd(LC, RC), Name);
874 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
876 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
877 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
879 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
880 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
883 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
884 if (Constant *RC = dyn_cast<Constant>(RHS)) {
885 if (RC->isNullValue())
886 return LHS; // LHS | 0 -> LHS
887 if (Constant *LC = dyn_cast<Constant>(LHS))
888 return Insert(Folder.CreateOr(LC, RC), Name);
890 return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
892 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
893 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
895 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
896 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
899 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
900 if (Constant *LC = dyn_cast<Constant>(LHS))
901 if (Constant *RC = dyn_cast<Constant>(RHS))
902 return Insert(Folder.CreateXor(LC, RC), Name);
903 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
905 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
906 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
908 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
909 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
912 Value *CreateBinOp(Instruction::BinaryOps Opc,
913 Value *LHS, Value *RHS, const Twine &Name = "",
914 MDNode *FPMathTag = nullptr) {
915 if (Constant *LC = dyn_cast<Constant>(LHS))
916 if (Constant *RC = dyn_cast<Constant>(RHS))
917 return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
918 llvm::Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
919 if (isa<FPMathOperator>(BinOp))
920 BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);
921 return Insert(BinOp, Name);
924 Value *CreateNeg(Value *V, const Twine &Name = "",
925 bool HasNUW = false, bool HasNSW = false) {
926 if (Constant *VC = dyn_cast<Constant>(V))
927 return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
928 BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
929 if (HasNUW) BO->setHasNoUnsignedWrap();
930 if (HasNSW) BO->setHasNoSignedWrap();
933 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
934 return CreateNeg(V, Name, false, true);
936 Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
937 return CreateNeg(V, Name, true, false);
939 Value *CreateFNeg(Value *V, const Twine &Name = "",
940 MDNode *FPMathTag = nullptr) {
941 if (Constant *VC = dyn_cast<Constant>(V))
942 return Insert(Folder.CreateFNeg(VC), Name);
943 return Insert(AddFPMathAttributes(BinaryOperator::CreateFNeg(V),
944 FPMathTag, FMF), Name);
946 Value *CreateNot(Value *V, const Twine &Name = "") {
947 if (Constant *VC = dyn_cast<Constant>(V))
948 return Insert(Folder.CreateNot(VC), Name);
949 return Insert(BinaryOperator::CreateNot(V), Name);
952 //===--------------------------------------------------------------------===//
953 // Instruction creation methods: Memory Instructions
954 //===--------------------------------------------------------------------===//
956 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
957 const Twine &Name = "") {
958 return Insert(new AllocaInst(Ty, ArraySize), Name);
960 // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
961 // converting the string to 'bool' for the isVolatile parameter.
962 LoadInst *CreateLoad(Value *Ptr, const char *Name) {
963 return Insert(new LoadInst(Ptr), Name);
965 LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
966 return Insert(new LoadInst(Ptr), Name);
968 LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
969 return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
971 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
972 return Insert(new StoreInst(Val, Ptr, isVolatile));
974 // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
975 // correctly, instead of converting the string to 'bool' for the isVolatile
977 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
978 LoadInst *LI = CreateLoad(Ptr, Name);
979 LI->setAlignment(Align);
982 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align,
983 const Twine &Name = "") {
984 LoadInst *LI = CreateLoad(Ptr, Name);
985 LI->setAlignment(Align);
988 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
989 const Twine &Name = "") {
990 LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
991 LI->setAlignment(Align);
994 StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
995 bool isVolatile = false) {
996 StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
997 SI->setAlignment(Align);
1000 FenceInst *CreateFence(AtomicOrdering Ordering,
1001 SynchronizationScope SynchScope = CrossThread,
1002 const Twine &Name = "") {
1003 return Insert(new FenceInst(Context, Ordering, SynchScope), Name);
1006 CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
1007 AtomicOrdering SuccessOrdering,
1008 AtomicOrdering FailureOrdering,
1009 SynchronizationScope SynchScope = CrossThread) {
1010 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1011 FailureOrdering, SynchScope));
1013 AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val,
1014 AtomicOrdering Ordering,
1015 SynchronizationScope SynchScope = CrossThread) {
1016 return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SynchScope));
1018 Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1019 const Twine &Name = "") {
1020 return CreateGEP(nullptr, Ptr, IdxList, Name);
1022 Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1023 const Twine &Name = "") {
1024 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1025 // Every index must be constant.
1027 for (i = 0, e = IdxList.size(); i != e; ++i)
1028 if (!isa<Constant>(IdxList[i]))
1031 return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
1033 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1035 Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1036 const Twine &Name = "") {
1037 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1038 // Every index must be constant.
1040 for (i = 0, e = IdxList.size(); i != e; ++i)
1041 if (!isa<Constant>(IdxList[i]))
1044 return Insert(Folder.CreateInBoundsGetElementPtr(PC, IdxList), Name);
1046 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, IdxList), Name);
1048 Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1049 if (Constant *PC = dyn_cast<Constant>(Ptr))
1050 if (Constant *IC = dyn_cast<Constant>(Idx))
1051 return Insert(Folder.CreateGetElementPtr(PC, IC), Name);
1052 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1054 Value *CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1055 if (Constant *PC = dyn_cast<Constant>(Ptr))
1056 if (Constant *IC = dyn_cast<Constant>(Idx))
1057 return Insert(Folder.CreateInBoundsGetElementPtr(PC, IC), Name);
1058 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1060 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1061 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1063 if (Constant *PC = dyn_cast<Constant>(Ptr))
1064 return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
1066 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1068 Value *CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0,
1069 const Twine &Name = "") {
1070 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1072 if (Constant *PC = dyn_cast<Constant>(Ptr))
1073 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
1075 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1077 Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
1078 const Twine &Name = "") {
1080 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1081 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1084 if (Constant *PC = dyn_cast<Constant>(Ptr))
1085 return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
1087 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1089 Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
1090 const Twine &Name = "") {
1092 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1093 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1096 if (Constant *PC = dyn_cast<Constant>(Ptr))
1097 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
1099 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1101 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1102 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1104 if (Constant *PC = dyn_cast<Constant>(Ptr))
1105 return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
1107 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1109 Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
1110 const Twine &Name = "") {
1111 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1113 if (Constant *PC = dyn_cast<Constant>(Ptr))
1114 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
1116 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1118 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1119 const Twine &Name = "") {
1121 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1122 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1125 if (Constant *PC = dyn_cast<Constant>(Ptr))
1126 return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
1128 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1130 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1131 const Twine &Name = "") {
1133 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1134 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1137 if (Constant *PC = dyn_cast<Constant>(Ptr))
1138 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
1140 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1142 Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
1143 return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
1146 /// \brief Same as CreateGlobalString, but return a pointer with "i8*" type
1147 /// instead of a pointer to array of i8.
1148 Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "") {
1149 Value *gv = CreateGlobalString(Str, Name);
1150 Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1151 Value *Args[] = { zero, zero };
1152 return CreateInBoundsGEP(gv, Args, Name);
1155 //===--------------------------------------------------------------------===//
1156 // Instruction creation methods: Cast/Conversion Operators
1157 //===--------------------------------------------------------------------===//
1159 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1160 return CreateCast(Instruction::Trunc, V, DestTy, Name);
1162 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1163 return CreateCast(Instruction::ZExt, V, DestTy, Name);
1165 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1166 return CreateCast(Instruction::SExt, V, DestTy, Name);
1168 /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
1169 /// the value untouched if the type of V is already DestTy.
1170 Value *CreateZExtOrTrunc(Value *V, Type *DestTy,
1171 const Twine &Name = "") {
1172 assert(V->getType()->isIntOrIntVectorTy() &&
1173 DestTy->isIntOrIntVectorTy() &&
1174 "Can only zero extend/truncate integers!");
1175 Type *VTy = V->getType();
1176 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1177 return CreateZExt(V, DestTy, Name);
1178 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1179 return CreateTrunc(V, DestTy, Name);
1182 /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
1183 /// the value untouched if the type of V is already DestTy.
1184 Value *CreateSExtOrTrunc(Value *V, Type *DestTy,
1185 const Twine &Name = "") {
1186 assert(V->getType()->isIntOrIntVectorTy() &&
1187 DestTy->isIntOrIntVectorTy() &&
1188 "Can only sign extend/truncate integers!");
1189 Type *VTy = V->getType();
1190 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1191 return CreateSExt(V, DestTy, Name);
1192 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1193 return CreateTrunc(V, DestTy, Name);
1196 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1197 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1199 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1200 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1202 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1203 return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1205 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1206 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1208 Value *CreateFPTrunc(Value *V, Type *DestTy,
1209 const Twine &Name = "") {
1210 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1212 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1213 return CreateCast(Instruction::FPExt, V, DestTy, Name);
1215 Value *CreatePtrToInt(Value *V, Type *DestTy,
1216 const Twine &Name = "") {
1217 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1219 Value *CreateIntToPtr(Value *V, Type *DestTy,
1220 const Twine &Name = "") {
1221 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1223 Value *CreateBitCast(Value *V, Type *DestTy,
1224 const Twine &Name = "") {
1225 return CreateCast(Instruction::BitCast, V, DestTy, Name);
1227 Value *CreateAddrSpaceCast(Value *V, Type *DestTy,
1228 const Twine &Name = "") {
1229 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1231 Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
1232 const Twine &Name = "") {
1233 if (V->getType() == DestTy)
1235 if (Constant *VC = dyn_cast<Constant>(V))
1236 return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1237 return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1239 Value *CreateSExtOrBitCast(Value *V, Type *DestTy,
1240 const Twine &Name = "") {
1241 if (V->getType() == DestTy)
1243 if (Constant *VC = dyn_cast<Constant>(V))
1244 return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1245 return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1247 Value *CreateTruncOrBitCast(Value *V, Type *DestTy,
1248 const Twine &Name = "") {
1249 if (V->getType() == DestTy)
1251 if (Constant *VC = dyn_cast<Constant>(V))
1252 return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1253 return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1255 Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy,
1256 const Twine &Name = "") {
1257 if (V->getType() == DestTy)
1259 if (Constant *VC = dyn_cast<Constant>(V))
1260 return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1261 return Insert(CastInst::Create(Op, V, DestTy), Name);
1263 Value *CreatePointerCast(Value *V, Type *DestTy,
1264 const Twine &Name = "") {
1265 if (V->getType() == DestTy)
1267 if (Constant *VC = dyn_cast<Constant>(V))
1268 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1269 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1272 Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
1273 const Twine &Name = "") {
1274 if (V->getType() == DestTy)
1277 if (Constant *VC = dyn_cast<Constant>(V)) {
1278 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1282 return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(V, DestTy),
1286 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1287 const Twine &Name = "") {
1288 if (V->getType() == DestTy)
1290 if (Constant *VC = dyn_cast<Constant>(V))
1291 return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1292 return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1295 Value *CreateBitOrPointerCast(Value *V, Type *DestTy,
1296 const Twine &Name = "") {
1297 if (V->getType() == DestTy)
1299 if (V->getType()->isPointerTy() && DestTy->isIntegerTy())
1300 return CreatePtrToInt(V, DestTy, Name);
1301 if (V->getType()->isIntegerTy() && DestTy->isPointerTy())
1302 return CreateIntToPtr(V, DestTy, Name);
1304 return CreateBitCast(V, DestTy, Name);
1307 // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1308 // compile time error, instead of converting the string to bool for the
1309 // isSigned parameter.
1310 Value *CreateIntCast(Value *, Type *, const char *) = delete;
1312 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1313 if (V->getType() == DestTy)
1315 if (Constant *VC = dyn_cast<Constant>(V))
1316 return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1317 return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1320 //===--------------------------------------------------------------------===//
1321 // Instruction creation methods: Compare Instructions
1322 //===--------------------------------------------------------------------===//
1324 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1325 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1327 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1328 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1330 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1331 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1333 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1334 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1336 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1337 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1339 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1340 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1342 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1343 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1345 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1346 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1348 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1349 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1351 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1352 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1355 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1356 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name);
1358 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1359 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name);
1361 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1362 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name);
1364 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1365 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name);
1367 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1368 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name);
1370 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "") {
1371 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name);
1373 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "") {
1374 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name);
1376 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "") {
1377 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name);
1379 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1380 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name);
1382 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1383 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name);
1385 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1386 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name);
1388 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1389 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name);
1391 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1392 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name);
1394 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1395 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name);
1398 Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1399 const Twine &Name = "") {
1400 if (Constant *LC = dyn_cast<Constant>(LHS))
1401 if (Constant *RC = dyn_cast<Constant>(RHS))
1402 return Insert(Folder.CreateICmp(P, LC, RC), Name);
1403 return Insert(new ICmpInst(P, LHS, RHS), Name);
1405 Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1406 const Twine &Name = "") {
1407 if (Constant *LC = dyn_cast<Constant>(LHS))
1408 if (Constant *RC = dyn_cast<Constant>(RHS))
1409 return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1410 return Insert(new FCmpInst(P, LHS, RHS), Name);
1413 //===--------------------------------------------------------------------===//
1414 // Instruction creation methods: Other Instructions
1415 //===--------------------------------------------------------------------===//
1417 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1418 const Twine &Name = "") {
1419 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1422 CallInst *CreateCall(Value *Callee, const Twine &Name = "") {
1423 return Insert(CallInst::Create(Callee), Name);
1425 CallInst *CreateCall(Value *Callee, Value *Arg, const Twine &Name = "") {
1426 return Insert(CallInst::Create(Callee, Arg), Name);
1428 CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
1429 const Twine &Name = "") {
1430 Value *Args[] = { Arg1, Arg2 };
1431 return Insert(CallInst::Create(Callee, Args), Name);
1433 CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1434 const Twine &Name = "") {
1435 Value *Args[] = { Arg1, Arg2, Arg3 };
1436 return Insert(CallInst::Create(Callee, Args), Name);
1438 CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1439 Value *Arg4, const Twine &Name = "") {
1440 Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
1441 return Insert(CallInst::Create(Callee, Args), Name);
1443 CallInst *CreateCall5(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
1444 Value *Arg4, Value *Arg5, const Twine &Name = "") {
1445 Value *Args[] = { Arg1, Arg2, Arg3, Arg4, Arg5 };
1446 return Insert(CallInst::Create(Callee, Args), Name);
1449 CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
1450 const Twine &Name = "") {
1451 return Insert(CallInst::Create(Callee, Args), Name);
1454 Value *CreateSelect(Value *C, Value *True, Value *False,
1455 const Twine &Name = "") {
1456 if (Constant *CC = dyn_cast<Constant>(C))
1457 if (Constant *TC = dyn_cast<Constant>(True))
1458 if (Constant *FC = dyn_cast<Constant>(False))
1459 return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1460 return Insert(SelectInst::Create(C, True, False), Name);
1463 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1464 return Insert(new VAArgInst(List, Ty), Name);
1467 Value *CreateExtractElement(Value *Vec, Value *Idx,
1468 const Twine &Name = "") {
1469 if (Constant *VC = dyn_cast<Constant>(Vec))
1470 if (Constant *IC = dyn_cast<Constant>(Idx))
1471 return Insert(Folder.CreateExtractElement(VC, IC), Name);
1472 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1475 Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
1476 const Twine &Name = "") {
1477 if (Constant *VC = dyn_cast<Constant>(Vec))
1478 if (Constant *NC = dyn_cast<Constant>(NewElt))
1479 if (Constant *IC = dyn_cast<Constant>(Idx))
1480 return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1481 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1484 Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
1485 const Twine &Name = "") {
1486 if (Constant *V1C = dyn_cast<Constant>(V1))
1487 if (Constant *V2C = dyn_cast<Constant>(V2))
1488 if (Constant *MC = dyn_cast<Constant>(Mask))
1489 return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1490 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1493 Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef<int> IntMask,
1494 const Twine &Name = "") {
1495 size_t MaskSize = IntMask.size();
1496 SmallVector<Constant*, 8> MaskVec(MaskSize);
1497 for (size_t i = 0; i != MaskSize; ++i)
1498 MaskVec[i] = getInt32(IntMask[i]);
1499 Value *Mask = ConstantVector::get(MaskVec);
1500 return CreateShuffleVector(V1, V2, Mask, Name);
1503 Value *CreateExtractValue(Value *Agg,
1504 ArrayRef<unsigned> Idxs,
1505 const Twine &Name = "") {
1506 if (Constant *AggC = dyn_cast<Constant>(Agg))
1507 return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1508 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1511 Value *CreateInsertValue(Value *Agg, Value *Val,
1512 ArrayRef<unsigned> Idxs,
1513 const Twine &Name = "") {
1514 if (Constant *AggC = dyn_cast<Constant>(Agg))
1515 if (Constant *ValC = dyn_cast<Constant>(Val))
1516 return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1517 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1520 LandingPadInst *CreateLandingPad(Type *Ty, Value *PersFn, unsigned NumClauses,
1521 const Twine &Name = "") {
1522 return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses), Name);
1525 //===--------------------------------------------------------------------===//
1526 // Utility creation methods
1527 //===--------------------------------------------------------------------===//
1529 /// \brief Return an i1 value testing if \p Arg is null.
1530 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
1531 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
1535 /// \brief Return an i1 value testing if \p Arg is not null.
1536 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
1537 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
1541 /// \brief Return the i64 difference between two pointer values, dividing out
1542 /// the size of the pointed-to objects.
1544 /// This is intended to implement C-style pointer subtraction. As such, the
1545 /// pointers must be appropriately aligned for their element types and
1546 /// pointing into the same object.
1547 Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
1548 assert(LHS->getType() == RHS->getType() &&
1549 "Pointer subtraction operand types must match!");
1550 PointerType *ArgType = cast<PointerType>(LHS->getType());
1551 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1552 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1553 Value *Difference = CreateSub(LHS_int, RHS_int);
1554 return CreateExactSDiv(Difference,
1555 ConstantExpr::getSizeOf(ArgType->getElementType()),
1559 /// \brief Return a vector value that contains \arg V broadcasted to \p
1560 /// NumElts elements.
1561 Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
1562 assert(NumElts > 0 && "Cannot splat to an empty vector!");
1564 // First insert it into an undef vector so we can shuffle it.
1565 Type *I32Ty = getInt32Ty();
1566 Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
1567 V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
1568 Name + ".splatinsert");
1570 // Shuffle the value across the desired number of elements.
1571 Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
1572 return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
1575 /// \brief Return a value that has been extracted from a larger integer type.
1576 Value *CreateExtractInteger(const DataLayout &DL, Value *From,
1577 IntegerType *ExtractedTy, uint64_t Offset,
1578 const Twine &Name) {
1579 IntegerType *IntTy = cast<IntegerType>(From->getType());
1580 assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
1581 DL.getTypeStoreSize(IntTy) &&
1582 "Element extends past full value");
1583 uint64_t ShAmt = 8 * Offset;
1585 if (DL.isBigEndian())
1586 ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
1587 DL.getTypeStoreSize(ExtractedTy) - Offset);
1589 V = CreateLShr(V, ShAmt, Name + ".shift");
1591 assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
1592 "Cannot extract to a larger integer!");
1593 if (ExtractedTy != IntTy) {
1594 V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
1599 /// \brief Create an assume intrinsic call that represents an alignment
1600 /// assumption on the provided pointer.
1602 /// An optional offset can be provided, and if it is provided, the offset
1603 /// must be subtracted from the provided pointer to get the pointer with the
1604 /// specified alignment.
1605 CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
1607 Value *OffsetValue = nullptr) {
1608 assert(isa<PointerType>(PtrValue->getType()) &&
1609 "trying to create an alignment assumption on a non-pointer?");
1611 PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
1612 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1613 Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
1615 Value *Mask = ConstantInt::get(IntPtrTy,
1616 Alignment > 0 ? Alignment - 1 : 0);
1618 bool IsOffsetZero = false;
1619 if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
1620 IsOffsetZero = CI->isZero();
1622 if (!IsOffsetZero) {
1623 if (OffsetValue->getType() != IntPtrTy)
1624 OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
1626 PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
1630 Value *Zero = ConstantInt::get(IntPtrTy, 0);
1631 Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
1632 Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
1634 return CreateAssumption(InvCond);
1638 // Create wrappers for C Binding types (see CBindingWrapping.h).
1639 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)