LLVM 19.0.0git
IRBuilder.h
Go to the documentation of this file.
1//===- llvm/IRBuilder.h - Builder for LLVM Instructions ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the IRBuilder class, which is used as a convenient way
10// to create LLVM instructions with a consistent and simplified interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_IRBUILDER_H
15#define LLVM_IR_IRBUILDER_H
16
17#include "llvm-c/Types.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/Twine.h"
22#include "llvm/IR/BasicBlock.h"
23#include "llvm/IR/Constant.h"
25#include "llvm/IR/Constants.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/DebugLoc.h"
29#include "llvm/IR/FPEnv.h"
30#include "llvm/IR/Function.h"
32#include "llvm/IR/InstrTypes.h"
33#include "llvm/IR/Instruction.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/LLVMContext.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/Operator.h"
39#include "llvm/IR/Type.h"
40#include "llvm/IR/Value.h"
41#include "llvm/IR/ValueHandle.h"
45#include <cassert>
46#include <cstdint>
47#include <functional>
48#include <optional>
49#include <utility>
50
51namespace llvm {
52
53class APInt;
54class Use;
55
56/// This provides the default implementation of the IRBuilder
57/// 'InsertHelper' method that is called whenever an instruction is created by
58/// IRBuilder and needs to be inserted.
59///
60/// By default, this inserts the instruction at the insertion point.
62public:
64
65 virtual void InsertHelper(Instruction *I, const Twine &Name,
66 BasicBlock *BB,
67 BasicBlock::iterator InsertPt) const {
68 if (BB)
69 I->insertInto(BB, InsertPt);
70 I->setName(Name);
71 }
72};
73
74/// Provides an 'InsertHelper' that calls a user-provided callback after
75/// performing the default insertion.
77 std::function<void(Instruction *)> Callback;
78
79public:
81
82 IRBuilderCallbackInserter(std::function<void(Instruction *)> Callback)
83 : Callback(std::move(Callback)) {}
84
86 BasicBlock *BB,
87 BasicBlock::iterator InsertPt) const override {
89 Callback(I);
90 }
91};
92
93/// Common base class shared among various IRBuilders.
95 /// Pairs of (metadata kind, MDNode *) that should be added to all newly
96 /// created instructions, like !dbg metadata.
98
99 /// Add or update the an entry (Kind, MD) to MetadataToCopy, if \p MD is not
100 /// null. If \p MD is null, remove the entry with \p Kind.
101 void AddOrRemoveMetadataToCopy(unsigned Kind, MDNode *MD) {
102 if (!MD) {
103 erase_if(MetadataToCopy, [Kind](const std::pair<unsigned, MDNode *> &KV) {
104 return KV.first == Kind;
105 });
106 return;
107 }
108
109 for (auto &KV : MetadataToCopy)
110 if (KV.first == Kind) {
111 KV.second = MD;
112 return;
113 }
114
115 MetadataToCopy.emplace_back(Kind, MD);
116 }
117
118protected:
124
127
128 bool IsFPConstrained = false;
131
133
134public:
136 const IRBuilderDefaultInserter &Inserter, MDNode *FPMathTag,
138 : Context(context), Folder(Folder), Inserter(Inserter),
139 DefaultFPMathTag(FPMathTag), DefaultOperandBundles(OpBundles) {
141 }
142
143 /// Insert and return the specified instruction.
144 template<typename InstTy>
145 InstTy *Insert(InstTy *I, const Twine &Name = "") const {
148 return I;
149 }
150
151 /// No-op overload to handle constants.
152 Constant *Insert(Constant *C, const Twine& = "") const {
153 return C;
154 }
155
156 Value *Insert(Value *V, const Twine &Name = "") const {
157 if (Instruction *I = dyn_cast<Instruction>(V))
158 return Insert(I, Name);
159 assert(isa<Constant>(V));
160 return V;
161 }
162
163 //===--------------------------------------------------------------------===//
164 // Builder configuration methods
165 //===--------------------------------------------------------------------===//
166
167 /// Clear the insertion point: created instructions will not be
168 /// inserted into a block.
170 BB = nullptr;
172 }
173
174 BasicBlock *GetInsertBlock() const { return BB; }
176 LLVMContext &getContext() const { return Context; }
177
178 /// This specifies that created instructions should be appended to the
179 /// end of the specified block.
181 BB = TheBB;
182 InsertPt = BB->end();
183 }
184
185 /// This specifies that created instructions should be inserted before
186 /// the specified instruction.
188 BB = I->getParent();
189 InsertPt = I->getIterator();
190 assert(InsertPt != BB->end() && "Can't read debug loc from end()");
191 SetCurrentDebugLocation(I->getStableDebugLoc());
192 }
193
194 /// This specifies that created instructions should be inserted at the
195 /// specified point.
197 BB = TheBB;
198 InsertPt = IP;
199 if (IP != TheBB->end())
200 SetCurrentDebugLocation(IP->getStableDebugLoc());
201 }
202
203 /// This specifies that created instructions should be inserted at
204 /// the specified point, but also requires that \p IP is dereferencable.
206 BB = IP->getParent();
207 InsertPt = IP;
208 SetCurrentDebugLocation(IP->getStableDebugLoc());
209 }
210
211 /// This specifies that created instructions should inserted at the beginning
212 /// end of the specified function, but after already existing static alloca
213 /// instructions that are at the start.
215 BB = &F->getEntryBlock();
217 }
218
219 /// Set location information used by debugging information.
221 AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
222 }
223
224 /// Set nosanitize metadata.
226 AddOrRemoveMetadataToCopy(llvm::LLVMContext::MD_nosanitize,
227 llvm::MDNode::get(getContext(), std::nullopt));
228 }
229
230 /// Collect metadata with IDs \p MetadataKinds from \p Src which should be
231 /// added to all created instructions. Entries present in MedataDataToCopy but
232 /// not on \p Src will be dropped from MetadataToCopy.
234 ArrayRef<unsigned> MetadataKinds) {
235 for (unsigned K : MetadataKinds)
236 AddOrRemoveMetadataToCopy(K, Src->getMetadata(K));
237 }
238
239 /// Get location information used by debugging information.
241
242 /// If this builder has a current debug location, set it on the
243 /// specified instruction.
245
246 /// Add all entries in MetadataToCopy to \p I.
248 for (const auto &KV : MetadataToCopy)
249 I->setMetadata(KV.first, KV.second);
250 }
251
252 /// Get the return type of the current function that we're emitting
253 /// into.
255
256 /// InsertPoint - A saved insertion point.
258 BasicBlock *Block = nullptr;
260
261 public:
262 /// Creates a new insertion point which doesn't point to anything.
263 InsertPoint() = default;
264
265 /// Creates a new insertion point at the given location.
267 : Block(InsertBlock), Point(InsertPoint) {}
268
269 /// Returns true if this insert point is set.
270 bool isSet() const { return (Block != nullptr); }
271
272 BasicBlock *getBlock() const { return Block; }
273 BasicBlock::iterator getPoint() const { return Point; }
274 };
275
276 /// Returns the current insert point.
279 }
280
281 /// Returns the current insert point, clearing it in the process.
285 return IP;
286 }
287
288 /// Sets the current insert point to a previously-saved location.
290 if (IP.isSet())
291 SetInsertPoint(IP.getBlock(), IP.getPoint());
292 else
294 }
295
296 /// Get the floating point math metadata being used.
298
299 /// Get the flags to be applied to created floating point ops
301
303
304 /// Clear the fast-math flags.
306
307 /// Set the floating point math metadata to be used.
308 void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
309
310 /// Set the fast-math flags to be used with generated fp-math operators
311 void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
312
313 /// Enable/Disable use of constrained floating point math. When
314 /// enabled the CreateF<op>() calls instead create constrained
315 /// floating point intrinsic calls. Fast math flags are unaffected
316 /// by this setting.
317 void setIsFPConstrained(bool IsCon) { IsFPConstrained = IsCon; }
318
319 /// Query for the use of constrained floating point math
321
322 /// Set the exception handling to be used with constrained floating point
324#ifndef NDEBUG
325 std::optional<StringRef> ExceptStr =
327 assert(ExceptStr && "Garbage strict exception behavior!");
328#endif
329 DefaultConstrainedExcept = NewExcept;
330 }
331
332 /// Set the rounding mode handling to be used with constrained floating point
334#ifndef NDEBUG
335 std::optional<StringRef> RoundingStr =
336 convertRoundingModeToStr(NewRounding);
337 assert(RoundingStr && "Garbage strict rounding mode!");
338#endif
339 DefaultConstrainedRounding = NewRounding;
340 }
341
342 /// Get the exception handling used with constrained floating point
345 }
346
347 /// Get the rounding mode handling used with constrained floating point
350 }
351
353 assert(BB && "Must have a basic block to set any function attributes!");
354
355 Function *F = BB->getParent();
356 if (!F->hasFnAttribute(Attribute::StrictFP)) {
357 F->addFnAttr(Attribute::StrictFP);
358 }
359 }
360
362 I->addFnAttr(Attribute::StrictFP);
363 }
364
366 DefaultOperandBundles = OpBundles;
367 }
368
369 //===--------------------------------------------------------------------===//
370 // RAII helpers.
371 //===--------------------------------------------------------------------===//
372
373 // RAII object that stores the current insertion point and restores it
374 // when the object is destroyed. This includes the debug location.
376 IRBuilderBase &Builder;
379 DebugLoc DbgLoc;
380
381 public:
383 : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
384 DbgLoc(B.getCurrentDebugLocation()) {}
385
388
390 Builder.restoreIP(InsertPoint(Block, Point));
391 Builder.SetCurrentDebugLocation(DbgLoc);
392 }
393 };
394
395 // RAII object that stores the current fast math settings and restores
396 // them when the object is destroyed.
398 IRBuilderBase &Builder;
399 FastMathFlags FMF;
400 MDNode *FPMathTag;
401 bool IsFPConstrained;
402 fp::ExceptionBehavior DefaultConstrainedExcept;
403 RoundingMode DefaultConstrainedRounding;
404
405 public:
407 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag),
408 IsFPConstrained(B.IsFPConstrained),
409 DefaultConstrainedExcept(B.DefaultConstrainedExcept),
410 DefaultConstrainedRounding(B.DefaultConstrainedRounding) {}
411
414
416 Builder.FMF = FMF;
417 Builder.DefaultFPMathTag = FPMathTag;
418 Builder.IsFPConstrained = IsFPConstrained;
419 Builder.DefaultConstrainedExcept = DefaultConstrainedExcept;
420 Builder.DefaultConstrainedRounding = DefaultConstrainedRounding;
421 }
422 };
423
424 // RAII object that stores the current default operand bundles and restores
425 // them when the object is destroyed.
427 IRBuilderBase &Builder;
428 ArrayRef<OperandBundleDef> DefaultOperandBundles;
429
430 public:
432 : Builder(B), DefaultOperandBundles(B.DefaultOperandBundles) {}
433
436
438 Builder.DefaultOperandBundles = DefaultOperandBundles;
439 }
440 };
441
442
443 //===--------------------------------------------------------------------===//
444 // Miscellaneous creation methods.
445 //===--------------------------------------------------------------------===//
446
447 /// Make a new global variable with initializer type i8*
448 ///
449 /// Make a new global variable with an initializer that has array of i8 type
450 /// filled in with the null terminated string value specified. The new global
451 /// variable will be marked mergable with any others of the same contents. If
452 /// Name is specified, it is the name of the global variable created.
453 ///
454 /// If no module is given via \p M, it is take from the insertion point basic
455 /// block.
457 unsigned AddressSpace = 0,
458 Module *M = nullptr);
459
460 /// Get a constant value representing either true or false.
462 return ConstantInt::get(getInt1Ty(), V);
463 }
464
465 /// Get the constant value for i1 true.
468 }
469
470 /// Get the constant value for i1 false.
473 }
474
475 /// Get a constant 8-bit value.
477 return ConstantInt::get(getInt8Ty(), C);
478 }
479
480 /// Get a constant 16-bit value.
482 return ConstantInt::get(getInt16Ty(), C);
483 }
484
485 /// Get a constant 32-bit value.
487 return ConstantInt::get(getInt32Ty(), C);
488 }
489
490 /// Get a constant 64-bit value.
492 return ConstantInt::get(getInt64Ty(), C);
493 }
494
495 /// Get a constant N-bit value, zero extended or truncated from
496 /// a 64-bit value.
498 return ConstantInt::get(getIntNTy(N), C);
499 }
500
501 /// Get a constant integer value.
503 return ConstantInt::get(Context, AI);
504 }
505
506 //===--------------------------------------------------------------------===//
507 // Type creation methods
508 //===--------------------------------------------------------------------===//
509
510 /// Fetch the type representing a single bit
512 return Type::getInt1Ty(Context);
513 }
514
515 /// Fetch the type representing an 8-bit integer.
517 return Type::getInt8Ty(Context);
518 }
519
520 /// Fetch the type representing a 16-bit integer.
523 }
524
525 /// Fetch the type representing a 32-bit integer.
528 }
529
530 /// Fetch the type representing a 64-bit integer.
533 }
534
535 /// Fetch the type representing a 128-bit integer.
537
538 /// Fetch the type representing an N-bit integer.
540 return Type::getIntNTy(Context, N);
541 }
542
543 /// Fetch the type representing a 16-bit floating point value.
545 return Type::getHalfTy(Context);
546 }
547
548 /// Fetch the type representing a 16-bit brain floating point value.
551 }
552
553 /// Fetch the type representing a 32-bit floating point value.
556 }
557
558 /// Fetch the type representing a 64-bit floating point value.
561 }
562
563 /// Fetch the type representing void.
565 return Type::getVoidTy(Context);
566 }
567
568 /// Fetch the type representing a pointer.
569 PointerType *getPtrTy(unsigned AddrSpace = 0) {
570 return PointerType::get(Context, AddrSpace);
571 }
572
573 /// Fetch the type of an integer with size at least as big as that of a
574 /// pointer in the given address space.
575 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
576 return DL.getIntPtrType(Context, AddrSpace);
577 }
578
579 /// Fetch the type of an integer that should be used to index GEP operations
580 /// within AddressSpace.
581 IntegerType *getIndexTy(const DataLayout &DL, unsigned AddrSpace) {
582 return DL.getIndexType(Context, AddrSpace);
583 }
584
585 //===--------------------------------------------------------------------===//
586 // Intrinsic creation methods
587 //===--------------------------------------------------------------------===//
588
589 /// Create and insert a memset to the specified pointer and the
590 /// specified value.
591 ///
592 /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
593 /// specified, it will be added to the instruction. Likewise with alias.scope
594 /// and noalias tags.
596 MaybeAlign Align, bool isVolatile = false,
597 MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
598 MDNode *NoAliasTag = nullptr) {
599 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
600 TBAATag, ScopeTag, NoAliasTag);
601 }
602
604 bool isVolatile = false, MDNode *TBAATag = nullptr,
605 MDNode *ScopeTag = nullptr,
606 MDNode *NoAliasTag = nullptr);
607
608 CallInst *CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val,
609 Value *Size, bool IsVolatile = false,
610 MDNode *TBAATag = nullptr,
611 MDNode *ScopeTag = nullptr,
612 MDNode *NoAliasTag = nullptr);
613
614 /// Create and insert an element unordered-atomic memset of the region of
615 /// memory starting at the given pointer to the given value.
616 ///
617 /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
618 /// specified, it will be added to the instruction. Likewise with alias.scope
619 /// and noalias tags.
621 uint64_t Size, Align Alignment,
622 uint32_t ElementSize,
623 MDNode *TBAATag = nullptr,
624 MDNode *ScopeTag = nullptr,
625 MDNode *NoAliasTag = nullptr) {
627 Align(Alignment), ElementSize,
628 TBAATag, ScopeTag, NoAliasTag);
629 }
630
631 CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize,
632 Value *ArraySize, ArrayRef<OperandBundleDef> OpB,
633 Function *MallocF = nullptr, const Twine &Name = "");
634
635 /// CreateMalloc - Generate the IR for a call to malloc:
636 /// 1. Compute the malloc call's argument as the specified type's size,
637 /// possibly multiplied by the array size if the array size is not
638 /// constant 1.
639 /// 2. Call malloc with that argument.
640 CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize,
641 Value *ArraySize, Function *MallocF = nullptr,
642 const Twine &Name = "");
643 /// Generate the IR for a call to the builtin free function.
644 CallInst *CreateFree(Value *Source,
645 ArrayRef<OperandBundleDef> Bundles = std::nullopt);
646
648 Value *Size, Align Alignment,
649 uint32_t ElementSize,
650 MDNode *TBAATag = nullptr,
651 MDNode *ScopeTag = nullptr,
652 MDNode *NoAliasTag = nullptr);
653
654 /// Create and insert a memcpy between the specified pointers.
655 ///
656 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
657 /// specified, it will be added to the instruction. Likewise with alias.scope
658 /// and noalias tags.
660 MaybeAlign SrcAlign, uint64_t Size,
661 bool isVolatile = false, MDNode *TBAATag = nullptr,
662 MDNode *TBAAStructTag = nullptr,
663 MDNode *ScopeTag = nullptr,
664 MDNode *NoAliasTag = nullptr) {
665 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
666 isVolatile, TBAATag, TBAAStructTag, ScopeTag,
667 NoAliasTag);
668 }
669
671 Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
672 MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
673 MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
674 MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr);
675
677 MaybeAlign SrcAlign, Value *Size,
678 bool isVolatile = false, MDNode *TBAATag = nullptr,
679 MDNode *TBAAStructTag = nullptr,
680 MDNode *ScopeTag = nullptr,
681 MDNode *NoAliasTag = nullptr) {
682 return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
683 SrcAlign, Size, isVolatile, TBAATag,
684 TBAAStructTag, ScopeTag, NoAliasTag);
685 }
686
687 CallInst *
689 MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
690 MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
691 MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr) {
692 return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
693 SrcAlign, Size, isVolatile, TBAATag,
694 TBAAStructTag, ScopeTag, NoAliasTag);
695 }
696
697 /// Create and insert an element unordered-atomic memcpy between the
698 /// specified pointers.
699 ///
700 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
701 ///
702 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
703 /// specified, it will be added to the instruction. Likewise with alias.scope
704 /// and noalias tags.
706 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
707 uint32_t ElementSize, MDNode *TBAATag = nullptr,
708 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
709 MDNode *NoAliasTag = nullptr);
710
712 MaybeAlign SrcAlign, uint64_t Size,
713 bool isVolatile = false, MDNode *TBAATag = nullptr,
714 MDNode *ScopeTag = nullptr,
715 MDNode *NoAliasTag = nullptr) {
716 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
717 isVolatile, TBAATag, ScopeTag, NoAliasTag);
718 }
719
721 MaybeAlign SrcAlign, Value *Size,
722 bool isVolatile = false, MDNode *TBAATag = nullptr,
723 MDNode *ScopeTag = nullptr,
724 MDNode *NoAliasTag = nullptr) {
725 return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
726 SrcAlign, Size, isVolatile, TBAATag,
727 /*TBAAStructTag=*/nullptr, ScopeTag,
728 NoAliasTag);
729 }
730
731 /// \brief Create and insert an element unordered-atomic memmove between the
732 /// specified pointers.
733 ///
734 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
735 /// respectively.
736 ///
737 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
738 /// specified, it will be added to the instruction. Likewise with alias.scope
739 /// and noalias tags.
741 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
742 uint32_t ElementSize, MDNode *TBAATag = nullptr,
743 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
744 MDNode *NoAliasTag = nullptr);
745
746private:
747 CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
748
749public:
750 /// Create a sequential vector fadd reduction intrinsic of the source vector.
751 /// The first parameter is a scalar accumulator value. An unordered reduction
752 /// can be created by adding the reassoc fast-math flag to the resulting
753 /// sequential reduction.
755
756 /// Create a sequential vector fmul reduction intrinsic of the source vector.
757 /// The first parameter is a scalar accumulator value. An unordered reduction
758 /// can be created by adding the reassoc fast-math flag to the resulting
759 /// sequential reduction.
761
762 /// Create a vector int add reduction intrinsic of the source vector.
764
765 /// Create a vector int mul reduction intrinsic of the source vector.
767
768 /// Create a vector int AND reduction intrinsic of the source vector.
770
771 /// Create a vector int OR reduction intrinsic of the source vector.
773
774 /// Create a vector int XOR reduction intrinsic of the source vector.
776
777 /// Create a vector integer max reduction intrinsic of the source
778 /// vector.
779 CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
780
781 /// Create a vector integer min reduction intrinsic of the source
782 /// vector.
783 CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
784
785 /// Create a vector float max reduction intrinsic of the source
786 /// vector.
788
789 /// Create a vector float min reduction intrinsic of the source
790 /// vector.
792
793 /// Create a vector float maximum reduction intrinsic of the source
794 /// vector. This variant follows the NaN and signed zero semantic of
795 /// llvm.maximum intrinsic.
797
798 /// Create a vector float minimum reduction intrinsic of the source
799 /// vector. This variant follows the NaN and signed zero semantic of
800 /// llvm.minimum intrinsic.
802
803 /// Create a lifetime.start intrinsic.
804 ///
805 /// If the pointer isn't i8* it will be converted.
807
808 /// Create a lifetime.end intrinsic.
809 ///
810 /// If the pointer isn't i8* it will be converted.
812
813 /// Create a call to invariant.start intrinsic.
814 ///
815 /// If the pointer isn't i8* it will be converted.
817
818 /// Create a call to llvm.threadlocal.address intrinsic.
820
821 /// Create a call to Masked Load intrinsic
822 CallInst *CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask,
823 Value *PassThru = nullptr, const Twine &Name = "");
824
825 /// Create a call to Masked Store intrinsic
826 CallInst *CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment,
827 Value *Mask);
828
829 /// Create a call to Masked Gather intrinsic
830 CallInst *CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment,
831 Value *Mask = nullptr, Value *PassThru = nullptr,
832 const Twine &Name = "");
833
834 /// Create a call to Masked Scatter intrinsic
835 CallInst *CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment,
836 Value *Mask = nullptr);
837
838 /// Create a call to Masked Expand Load intrinsic
839 CallInst *CreateMaskedExpandLoad(Type *Ty, Value *Ptr, Value *Mask = nullptr,
840 Value *PassThru = nullptr,
841 const Twine &Name = "");
842
843 /// Create a call to Masked Compress Store intrinsic
845 Value *Mask = nullptr);
846
847 /// Return an all true boolean vector (mask) with \p NumElts lanes.
850 return Constant::getAllOnesValue(VTy);
851 }
852
853 /// Create an assume intrinsic call that allows the optimizer to
854 /// assume that the provided condition will be true.
855 ///
856 /// The optional argument \p OpBundles specifies operand bundles that are
857 /// added to the call instruction.
858 CallInst *
860 ArrayRef<OperandBundleDef> OpBundles = std::nullopt);
861
862 /// Create a llvm.experimental.noalias.scope.decl intrinsic call.
866 MetadataAsValue::get(Context, ScopeTag));
867 }
868
869 /// Create a call to the experimental.gc.statepoint intrinsic to
870 /// start a new statepoint sequence.
872 FunctionCallee ActualCallee,
873 ArrayRef<Value *> CallArgs,
874 std::optional<ArrayRef<Value *>> DeoptArgs,
875 ArrayRef<Value *> GCArgs,
876 const Twine &Name = "");
877
878 /// Create a call to the experimental.gc.statepoint intrinsic to
879 /// start a new statepoint sequence.
881 FunctionCallee ActualCallee, uint32_t Flags,
882 ArrayRef<Value *> CallArgs,
883 std::optional<ArrayRef<Use>> TransitionArgs,
884 std::optional<ArrayRef<Use>> DeoptArgs,
885 ArrayRef<Value *> GCArgs,
886 const Twine &Name = "");
887
888 /// Conveninence function for the common case when CallArgs are filled
889 /// in using ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
890 /// .get()'ed to get the Value pointer.
892 FunctionCallee ActualCallee,
893 ArrayRef<Use> CallArgs,
894 std::optional<ArrayRef<Value *>> DeoptArgs,
895 ArrayRef<Value *> GCArgs,
896 const Twine &Name = "");
897
898 /// Create an invoke to the experimental.gc.statepoint intrinsic to
899 /// start a new statepoint sequence.
900 InvokeInst *
902 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
903 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
904 std::optional<ArrayRef<Value *>> DeoptArgs,
905 ArrayRef<Value *> GCArgs, const Twine &Name = "");
906
907 /// Create an invoke to the experimental.gc.statepoint intrinsic to
908 /// start a new statepoint sequence.
910 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
911 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
912 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
913 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
914 const Twine &Name = "");
915
916 // Convenience function for the common case when CallArgs are filled in using
917 // ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
918 // get the Value *.
919 InvokeInst *
921 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
922 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
923 std::optional<ArrayRef<Value *>> DeoptArgs,
924 ArrayRef<Value *> GCArgs, const Twine &Name = "");
925
926 /// Create a call to the experimental.gc.result intrinsic to extract
927 /// the result from a call wrapped in a statepoint.
929 Type *ResultType,
930 const Twine &Name = "");
931
932 /// Create a call to the experimental.gc.relocate intrinsics to
933 /// project the relocated value of one pointer from the statepoint.
935 int BaseOffset,
936 int DerivedOffset,
937 Type *ResultType,
938 const Twine &Name = "");
939
940 /// Create a call to the experimental.gc.pointer.base intrinsic to get the
941 /// base pointer for the specified derived pointer.
942 CallInst *CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name = "");
943
944 /// Create a call to the experimental.gc.get.pointer.offset intrinsic to get
945 /// the offset of the specified derived pointer from its base.
946 CallInst *CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name = "");
947
948 /// Create a call to llvm.vscale, multiplied by \p Scaling. The type of VScale
949 /// will be the same type as that of \p Scaling.
950 Value *CreateVScale(Constant *Scaling, const Twine &Name = "");
951
952 /// Create an expression which evaluates to the number of elements in \p EC
953 /// at runtime.
955
956 /// Create an expression which evaluates to the number of units in \p Size
957 /// at runtime. This works for both units of bits and bytes.
959
960 /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
961 Value *CreateStepVector(Type *DstType, const Twine &Name = "");
962
963 /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
964 /// type.
966 Instruction *FMFSource = nullptr,
967 const Twine &Name = "");
968
969 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
970 /// first type.
972 Instruction *FMFSource = nullptr,
973 const Twine &Name = "");
974
975 /// Create a call to intrinsic \p ID with \p Args, mangled using \p Types. If
976 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
977 /// the intrinsic.
980 Instruction *FMFSource = nullptr,
981 const Twine &Name = "");
982
983 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
984 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
985 /// the intrinsic.
988 Instruction *FMFSource = nullptr,
989 const Twine &Name = "");
990
991 /// Create call to the minnum intrinsic.
993 if (IsFPConstrained) {
995 Intrinsic::experimental_constrained_minnum, LHS, RHS, nullptr, Name);
996 }
997
998 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, nullptr, Name);
999 }
1000
1001 /// Create call to the maxnum intrinsic.
1003 if (IsFPConstrained) {
1005 Intrinsic::experimental_constrained_maxnum, LHS, RHS, nullptr, Name);
1006 }
1007
1008 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, nullptr, Name);
1009 }
1010
1011 /// Create call to the minimum intrinsic.
1013 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1014 }
1015
1016 /// Create call to the maximum intrinsic.
1018 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1019 }
1020
1021 /// Create call to the copysign intrinsic.
1023 Instruction *FMFSource = nullptr,
1024 const Twine &Name = "") {
1025 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1026 Name);
1027 }
1028
1029 /// Create a call to the arithmetic_fence intrinsic.
1031 const Twine &Name = "") {
1032 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1033 Name);
1034 }
1035
1036 /// Create a call to the vector.extract intrinsic.
1038 const Twine &Name = "") {
1039 return CreateIntrinsic(Intrinsic::vector_extract,
1040 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1041 Name);
1042 }
1043
1044 /// Create a call to the vector.insert intrinsic.
1045 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1046 Value *Idx, const Twine &Name = "") {
1047 return CreateIntrinsic(Intrinsic::vector_insert,
1048 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1049 nullptr, Name);
1050 }
1051
1052 /// Create a call to llvm.stacksave
1054 const DataLayout &DL = BB->getModule()->getDataLayout();
1055 return CreateIntrinsic(Intrinsic::stacksave, {DL.getAllocaPtrType(Context)},
1056 {}, nullptr, Name);
1057 }
1058
1059 /// Create a call to llvm.stackrestore
1061 return CreateIntrinsic(Intrinsic::stackrestore, {Ptr->getType()}, {Ptr},
1062 nullptr, Name);
1063 }
1064
1065private:
1066 /// Create a call to a masked intrinsic with given Id.
1067 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1068 ArrayRef<Type *> OverloadedTypes,
1069 const Twine &Name = "");
1070
1071 //===--------------------------------------------------------------------===//
1072 // Instruction creation methods: Terminators
1073 //===--------------------------------------------------------------------===//
1074
1075private:
1076 /// Helper to add branch weight and unpredictable metadata onto an
1077 /// instruction.
1078 /// \returns The annotated instruction.
1079 template <typename InstTy>
1080 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1081 if (Weights)
1082 I->setMetadata(LLVMContext::MD_prof, Weights);
1083 if (Unpredictable)
1084 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1085 return I;
1086 }
1087
1088public:
1089 /// Create a 'ret void' instruction.
1092 }
1093
1094 /// Create a 'ret <val>' instruction.
1096 return Insert(ReturnInst::Create(Context, V));
1097 }
1098
1099 /// Create a sequence of N insertvalue instructions,
1100 /// with one Value from the retVals array each, that build a aggregate
1101 /// return value one value at a time, and a ret instruction to return
1102 /// the resulting aggregate value.
1103 ///
1104 /// This is a convenience function for code that uses aggregate return values
1105 /// as a vehicle for having multiple return values.
1106 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
1108 for (unsigned i = 0; i != N; ++i)
1109 V = CreateInsertValue(V, retVals[i], i, "mrv");
1110 return Insert(ReturnInst::Create(Context, V));
1111 }
1112
1113 /// Create an unconditional 'br label X' instruction.
1115 return Insert(BranchInst::Create(Dest));
1116 }
1117
1118 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1119 /// instruction.
1121 MDNode *BranchWeights = nullptr,
1122 MDNode *Unpredictable = nullptr) {
1123 return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
1124 BranchWeights, Unpredictable));
1125 }
1126
1127 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1128 /// instruction. Copy branch meta data if available.
1130 Instruction *MDSrc) {
1131 BranchInst *Br = BranchInst::Create(True, False, Cond);
1132 if (MDSrc) {
1133 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1134 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1135 Br->copyMetadata(*MDSrc, WL);
1136 }
1137 return Insert(Br);
1138 }
1139
1140 /// Create a switch instruction with the specified value, default dest,
1141 /// and with a hint for the number of cases that will be added (for efficient
1142 /// allocation).
1143 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1144 MDNode *BranchWeights = nullptr,
1145 MDNode *Unpredictable = nullptr) {
1146 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1147 BranchWeights, Unpredictable));
1148 }
1149
1150 /// Create an indirect branch instruction with the specified address
1151 /// operand, with an optional hint for the number of destinations that will be
1152 /// added (for efficient allocation).
1153 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1154 return Insert(IndirectBrInst::Create(Addr, NumDests));
1155 }
1156
1157 /// Create an invoke instruction.
1159 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1160 ArrayRef<Value *> Args,
1162 const Twine &Name = "") {
1163 InvokeInst *II =
1164 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1165 if (IsFPConstrained)
1167 return Insert(II, Name);
1168 }
1170 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1171 ArrayRef<Value *> Args = std::nullopt,
1172 const Twine &Name = "") {
1173 InvokeInst *II =
1174 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1175 if (IsFPConstrained)
1177 return Insert(II, Name);
1178 }
1179
1181 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1183 const Twine &Name = "") {
1184 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1185 NormalDest, UnwindDest, Args, OpBundles, Name);
1186 }
1187
1189 BasicBlock *UnwindDest,
1190 ArrayRef<Value *> Args = std::nullopt,
1191 const Twine &Name = "") {
1192 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1193 NormalDest, UnwindDest, Args, Name);
1194 }
1195
1196 /// \brief Create a callbr instruction.
1198 BasicBlock *DefaultDest,
1199 ArrayRef<BasicBlock *> IndirectDests,
1200 ArrayRef<Value *> Args = std::nullopt,
1201 const Twine &Name = "") {
1202 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1203 Args), Name);
1204 }
1206 BasicBlock *DefaultDest,
1207 ArrayRef<BasicBlock *> IndirectDests,
1208 ArrayRef<Value *> Args,
1210 const Twine &Name = "") {
1211 return Insert(
1212 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1213 OpBundles), Name);
1214 }
1215
1217 ArrayRef<BasicBlock *> IndirectDests,
1218 ArrayRef<Value *> Args = std::nullopt,
1219 const Twine &Name = "") {
1220 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1221 DefaultDest, IndirectDests, Args, Name);
1222 }
1224 ArrayRef<BasicBlock *> IndirectDests,
1225 ArrayRef<Value *> Args,
1227 const Twine &Name = "") {
1228 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1229 DefaultDest, IndirectDests, Args, Name);
1230 }
1231
1233 return Insert(ResumeInst::Create(Exn));
1234 }
1235
1237 BasicBlock *UnwindBB = nullptr) {
1238 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1239 }
1240
1242 unsigned NumHandlers,
1243 const Twine &Name = "") {
1244 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1245 Name);
1246 }
1247
1249 const Twine &Name = "") {
1250 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1251 }
1252
1254 ArrayRef<Value *> Args = std::nullopt,
1255 const Twine &Name = "") {
1256 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1257 }
1258
1260 return Insert(CatchReturnInst::Create(CatchPad, BB));
1261 }
1262
1264 return Insert(new UnreachableInst(Context));
1265 }
1266
1267 //===--------------------------------------------------------------------===//
1268 // Instruction creation methods: Binary Operators
1269 //===--------------------------------------------------------------------===//
1270private:
1271 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1272 Value *LHS, Value *RHS,
1273 const Twine &Name,
1274 bool HasNUW, bool HasNSW) {
1276 if (HasNUW) BO->setHasNoUnsignedWrap();
1277 if (HasNSW) BO->setHasNoSignedWrap();
1278 return BO;
1279 }
1280
1281 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1282 FastMathFlags FMF) const {
1283 if (!FPMD)
1284 FPMD = DefaultFPMathTag;
1285 if (FPMD)
1286 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1287 I->setFastMathFlags(FMF);
1288 return I;
1289 }
1290
1291 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1293
1294 if (Rounding)
1295 UseRounding = *Rounding;
1296
1297 std::optional<StringRef> RoundingStr =
1298 convertRoundingModeToStr(UseRounding);
1299 assert(RoundingStr && "Garbage strict rounding mode!");
1300 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1301
1302 return MetadataAsValue::get(Context, RoundingMDS);
1303 }
1304
1305 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1306 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1307 Except.value_or(DefaultConstrainedExcept));
1308 assert(ExceptStr && "Garbage strict exception behavior!");
1309 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1310
1311 return MetadataAsValue::get(Context, ExceptMDS);
1312 }
1313
1314 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1315 assert(CmpInst::isFPPredicate(Predicate) &&
1316 Predicate != CmpInst::FCMP_FALSE &&
1317 Predicate != CmpInst::FCMP_TRUE &&
1318 "Invalid constrained FP comparison predicate!");
1319
1320 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1321 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1322
1323 return MetadataAsValue::get(Context, PredicateMDS);
1324 }
1325
1326public:
1328 bool HasNUW = false, bool HasNSW = false) {
1329 if (Value *V =
1330 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1331 return V;
1332 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1333 HasNSW);
1334 }
1335
1337 return CreateAdd(LHS, RHS, Name, false, true);
1338 }
1339
1341 return CreateAdd(LHS, RHS, Name, true, false);
1342 }
1343
1345 bool HasNUW = false, bool HasNSW = false) {
1346 if (Value *V =
1347 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1348 return V;
1349 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1350 HasNSW);
1351 }
1352
1354 return CreateSub(LHS, RHS, Name, false, true);
1355 }
1356
1358 return CreateSub(LHS, RHS, Name, true, false);
1359 }
1360
1362 bool HasNUW = false, bool HasNSW = false) {
1363 if (Value *V =
1364 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1365 return V;
1366 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1367 HasNSW);
1368 }
1369
1371 return CreateMul(LHS, RHS, Name, false, true);
1372 }
1373
1375 return CreateMul(LHS, RHS, Name, true, false);
1376 }
1377
1379 bool isExact = false) {
1380 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1381 return V;
1382 if (!isExact)
1383 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1384 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1385 }
1386
1388 return CreateUDiv(LHS, RHS, Name, true);
1389 }
1390
1392 bool isExact = false) {
1393 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1394 return V;
1395 if (!isExact)
1396 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1397 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1398 }
1399
1401 return CreateSDiv(LHS, RHS, Name, true);
1402 }
1403
1405 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1406 return V;
1407 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1408 }
1409
1411 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1412 return V;
1413 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1414 }
1415
1417 bool HasNUW = false, bool HasNSW = false) {
1418 if (Value *V =
1419 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1420 return V;
1421 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1422 HasNUW, HasNSW);
1423 }
1424
1425 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1426 bool HasNUW = false, bool HasNSW = false) {
1427 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1428 HasNUW, HasNSW);
1429 }
1430
1432 bool HasNUW = false, bool HasNSW = false) {
1433 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1434 HasNUW, HasNSW);
1435 }
1436
1438 bool isExact = false) {
1439 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1440 return V;
1441 if (!isExact)
1442 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1443 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1444 }
1445
1446 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1447 bool isExact = false) {
1448 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1449 }
1450
1452 bool isExact = false) {
1453 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1454 }
1455
1457 bool isExact = false) {
1458 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1459 return V;
1460 if (!isExact)
1461 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1462 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1463 }
1464
1465 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1466 bool isExact = false) {
1467 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1468 }
1469
1471 bool isExact = false) {
1472 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1473 }
1474
1476 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1477 return V;
1478 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1479 }
1480
1481 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1482 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1483 }
1484
1486 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1487 }
1488
1490 assert(!Ops.empty());
1491 Value *Accum = Ops[0];
1492 for (unsigned i = 1; i < Ops.size(); i++)
1493 Accum = CreateAnd(Accum, Ops[i]);
1494 return Accum;
1495 }
1496
1498 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1499 return V;
1500 return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1501 }
1502
1503 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1504 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1505 }
1506
1508 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1509 }
1510
1512 assert(!Ops.empty());
1513 Value *Accum = Ops[0];
1514 for (unsigned i = 1; i < Ops.size(); i++)
1515 Accum = CreateOr(Accum, Ops[i]);
1516 return Accum;
1517 }
1518
1520 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1521 return V;
1522 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1523 }
1524
1525 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1526 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1527 }
1528
1530 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1531 }
1532
1533 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1534 MDNode *FPMD = nullptr) {
1535 if (IsFPConstrained)
1536 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1537 L, R, nullptr, Name, FPMD);
1538
1539 if (Value *V = Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMF))
1540 return V;
1541 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF);
1542 return Insert(I, Name);
1543 }
1544
1545 /// Copy fast-math-flags from an instruction rather than using the builder's
1546 /// default FMF.
1548 const Twine &Name = "") {
1549 if (IsFPConstrained)
1550 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1551 L, R, FMFSource, Name);
1552
1553 FastMathFlags FMF = FMFSource->getFastMathFlags();
1554 if (Value *V = Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMF))
1555 return V;
1556 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr, FMF);
1557 return Insert(I, Name);
1558 }
1559
1560 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1561 MDNode *FPMD = nullptr) {
1562 if (IsFPConstrained)
1563 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1564 L, R, nullptr, Name, FPMD);
1565
1566 if (Value *V = Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMF))
1567 return V;
1568 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF);
1569 return Insert(I, Name);
1570 }
1571
1572 /// Copy fast-math-flags from an instruction rather than using the builder's
1573 /// default FMF.
1575 const Twine &Name = "") {
1576 if (IsFPConstrained)
1577 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1578 L, R, FMFSource, Name);
1579
1580 FastMathFlags FMF = FMFSource->getFastMathFlags();
1581 if (Value *V = Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMF))
1582 return V;
1583 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr, FMF);
1584 return Insert(I, Name);
1585 }
1586
1587 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1588 MDNode *FPMD = nullptr) {
1589 if (IsFPConstrained)
1590 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1591 L, R, nullptr, Name, FPMD);
1592
1593 if (Value *V = Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMF))
1594 return V;
1595 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF);
1596 return Insert(I, Name);
1597 }
1598
1599 /// Copy fast-math-flags from an instruction rather than using the builder's
1600 /// default FMF.
1602 const Twine &Name = "") {
1603 if (IsFPConstrained)
1604 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1605 L, R, FMFSource, Name);
1606
1607 FastMathFlags FMF = FMFSource->getFastMathFlags();
1608 if (Value *V = Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMF))
1609 return V;
1610 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr, FMF);
1611 return Insert(I, Name);
1612 }
1613
1614 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1615 MDNode *FPMD = nullptr) {
1616 if (IsFPConstrained)
1617 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1618 L, R, nullptr, Name, FPMD);
1619
1620 if (Value *V = Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMF))
1621 return V;
1622 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF);
1623 return Insert(I, Name);
1624 }
1625
1626 /// Copy fast-math-flags from an instruction rather than using the builder's
1627 /// default FMF.
1629 const Twine &Name = "") {
1630 if (IsFPConstrained)
1631 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1632 L, R, FMFSource, Name);
1633
1634 FastMathFlags FMF = FMFSource->getFastMathFlags();
1635 if (Value *V = Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMF))
1636 return V;
1637 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr, FMF);
1638 return Insert(I, Name);
1639 }
1640
1641 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1642 MDNode *FPMD = nullptr) {
1643 if (IsFPConstrained)
1644 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1645 L, R, nullptr, Name, FPMD);
1646
1647 if (Value *V = Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMF)) return V;
1648 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF);
1649 return Insert(I, Name);
1650 }
1651
1652 /// Copy fast-math-flags from an instruction rather than using the builder's
1653 /// default FMF.
1655 const Twine &Name = "") {
1656 if (IsFPConstrained)
1657 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1658 L, R, FMFSource, Name);
1659
1660 FastMathFlags FMF = FMFSource->getFastMathFlags();
1661 if (Value *V = Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMF)) return V;
1662 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr, FMF);
1663 return Insert(I, Name);
1664 }
1665
1667 Value *LHS, Value *RHS, const Twine &Name = "",
1668 MDNode *FPMathTag = nullptr) {
1669 if (Value *V = Folder.FoldBinOp(Opc, LHS, RHS)) return V;
1670 Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1671 if (isa<FPMathOperator>(BinOp))
1672 setFPAttrs(BinOp, FPMathTag, FMF);
1673 return Insert(BinOp, Name);
1674 }
1675
1676 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "") {
1677 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1678 return CreateSelect(Cond1, Cond2,
1680 }
1681
1682 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "") {
1683 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1684 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1685 Cond2, Name);
1686 }
1687
1689 const Twine &Name = "") {
1690 switch (Opc) {
1691 case Instruction::And:
1692 return CreateLogicalAnd(Cond1, Cond2, Name);
1693 case Instruction::Or:
1694 return CreateLogicalOr(Cond1, Cond2, Name);
1695 default:
1696 break;
1697 }
1698 llvm_unreachable("Not a logical operation.");
1699 }
1700
1701 // NOTE: this is sequential, non-commutative, ordered reduction!
1703 assert(!Ops.empty());
1704 Value *Accum = Ops[0];
1705 for (unsigned i = 1; i < Ops.size(); i++)
1706 Accum = CreateLogicalOr(Accum, Ops[i]);
1707 return Accum;
1708 }
1709
1711 Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource = nullptr,
1712 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1713 std::optional<RoundingMode> Rounding = std::nullopt,
1714 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1715
1717 Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource = nullptr,
1718 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1719 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1720
1721 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1722 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1723 /*HasNUW=*/0, HasNSW);
1724 }
1725
1726 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1727 return CreateNeg(V, Name, /*HasNSW=*/true);
1728 }
1729
1730 Value *CreateFNeg(Value *V, const Twine &Name = "",
1731 MDNode *FPMathTag = nullptr) {
1732 if (Value *Res = Folder.FoldUnOpFMF(Instruction::FNeg, V, FMF))
1733 return Res;
1734 return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMF),
1735 Name);
1736 }
1737
1738 /// Copy fast-math-flags from an instruction rather than using the builder's
1739 /// default FMF.
1741 const Twine &Name = "") {
1742 FastMathFlags FMF = FMFSource->getFastMathFlags();
1743 if (Value *Res = Folder.FoldUnOpFMF(Instruction::FNeg, V, FMF))
1744 return Res;
1745 return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), nullptr, FMF),
1746 Name);
1747 }
1748
1749 Value *CreateNot(Value *V, const Twine &Name = "") {
1750 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1751 }
1752
1754 Value *V, const Twine &Name = "",
1755 MDNode *FPMathTag = nullptr) {
1756 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1757 return Res;
1758 Instruction *UnOp = UnaryOperator::Create(Opc, V);
1759 if (isa<FPMathOperator>(UnOp))
1760 setFPAttrs(UnOp, FPMathTag, FMF);
1761 return Insert(UnOp, Name);
1762 }
1763
1764 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1765 /// Correct number of operands must be passed accordingly.
1766 Value *CreateNAryOp(unsigned Opc, ArrayRef<Value *> Ops,
1767 const Twine &Name = "", MDNode *FPMathTag = nullptr);
1768
1769 //===--------------------------------------------------------------------===//
1770 // Instruction creation methods: Memory Instructions
1771 //===--------------------------------------------------------------------===//
1772
1773 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1774 Value *ArraySize = nullptr, const Twine &Name = "") {
1775 const DataLayout &DL = BB->getModule()->getDataLayout();
1776 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1777 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1778 }
1779
1780 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1781 const Twine &Name = "") {
1782 const DataLayout &DL = BB->getModule()->getDataLayout();
1783 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1784 unsigned AddrSpace = DL.getAllocaAddrSpace();
1785 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1786 }
1787
1788 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1789 /// converting the string to 'bool' for the isVolatile parameter.
1790 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1791 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1792 }
1793
1794 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1795 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1796 }
1797
1798 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1799 const Twine &Name = "") {
1800 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1801 }
1802
1803 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1804 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1805 }
1806
1808 const char *Name) {
1809 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1810 }
1811
1813 const Twine &Name = "") {
1814 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1815 }
1816
1818 bool isVolatile, const Twine &Name = "") {
1819 if (!Align) {
1820 const DataLayout &DL = BB->getModule()->getDataLayout();
1821 Align = DL.getABITypeAlign(Ty);
1822 }
1823 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1824 }
1825
1827 bool isVolatile = false) {
1828 if (!Align) {
1829 const DataLayout &DL = BB->getModule()->getDataLayout();
1830 Align = DL.getABITypeAlign(Val->getType());
1831 }
1832 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1833 }
1836 const Twine &Name = "") {
1837 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1838 }
1839
1842 AtomicOrdering SuccessOrdering,
1843 AtomicOrdering FailureOrdering,
1845 if (!Align) {
1846 const DataLayout &DL = BB->getModule()->getDataLayout();
1847 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1848 }
1849
1850 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1851 FailureOrdering, SSID));
1852 }
1853
1855 Value *Val, MaybeAlign Align,
1856 AtomicOrdering Ordering,
1858 if (!Align) {
1859 const DataLayout &DL = BB->getModule()->getDataLayout();
1860 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1861 }
1862
1863 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1864 }
1865
1867 const Twine &Name = "", bool IsInBounds = false) {
1868 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, IsInBounds))
1869 return V;
1870 return Insert(IsInBounds
1872 : GetElementPtrInst::Create(Ty, Ptr, IdxList),
1873 Name);
1874 }
1875
1877 const Twine &Name = "") {
1878 return CreateGEP(Ty, Ptr, IdxList, Name, /* IsInBounds */ true);
1879 }
1880
1881 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1882 const Twine &Name = "") {
1883 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1884
1885 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, /*IsInBounds=*/false))
1886 return V;
1887
1889 }
1890
1892 const Twine &Name = "") {
1893 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1894
1895 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, /*IsInBounds=*/true))
1896 return V;
1897
1899 }
1900
1901 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1902 const Twine &Name = "") {
1903 Value *Idxs[] = {
1904 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1905 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1906 };
1907
1908 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, /*IsInBounds=*/false))
1909 return V;
1910
1911 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1912 }
1913
1915 unsigned Idx1, const Twine &Name = "") {
1916 Value *Idxs[] = {
1917 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1918 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1919 };
1920
1921 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, /*IsInBounds=*/true))
1922 return V;
1923
1925 }
1926
1928 const Twine &Name = "") {
1929 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1930
1931 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, /*IsInBounds=*/false))
1932 return V;
1933
1935 }
1936
1938 const Twine &Name = "") {
1939 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1940
1941 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, /*IsInBounds=*/true))
1942 return V;
1943
1945 }
1946
1948 const Twine &Name = "") {
1949 Value *Idxs[] = {
1950 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1951 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1952 };
1953
1954 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, /*IsInBounds=*/false))
1955 return V;
1956
1957 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1958 }
1959
1961 uint64_t Idx1, const Twine &Name = "") {
1962 Value *Idxs[] = {
1963 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1964 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1965 };
1966
1967 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, /*IsInBounds=*/true))
1968 return V;
1969
1971 }
1972
1974 const Twine &Name = "") {
1975 return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1976 }
1977
1979 bool IsInBounds = false) {
1980 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, IsInBounds);
1981 }
1982
1984 const Twine &Name = "") {
1985 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, /*IsInBounds*/ true);
1986 }
1987
1988 /// Same as CreateGlobalString, but return a pointer with "i8*" type
1989 /// instead of a pointer to array of i8.
1990 ///
1991 /// If no module is given via \p M, it is take from the insertion point basic
1992 /// block.
1994 unsigned AddressSpace = 0,
1995 Module *M = nullptr) {
1997 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1998 Constant *Indices[] = {Zero, Zero};
2000 Indices);
2001 }
2002
2003 //===--------------------------------------------------------------------===//
2004 // Instruction creation methods: Cast/Conversion Operators
2005 //===--------------------------------------------------------------------===//
2006
2007 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2008 bool IsNUW = false, bool IsNSW = false) {
2009 if (V->getType() == DestTy)
2010 return V;
2011 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2012 return Folded;
2013 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2014 if (IsNUW)
2015 I->setHasNoUnsignedWrap();
2016 if (IsNSW)
2017 I->setHasNoSignedWrap();
2018 return Insert(I, Name);
2019 }
2020
2021 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2022 bool IsNonNeg = false) {
2023 if (V->getType() == DestTy)
2024 return V;
2025 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2026 return Folded;
2027 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2028 if (IsNonNeg)
2029 I->setNonNeg();
2030 return I;
2031 }
2032
2033 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2034 return CreateCast(Instruction::SExt, V, DestTy, Name);
2035 }
2036
2037 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2038 /// the value untouched if the type of V is already DestTy.
2040 const Twine &Name = "") {
2041 assert(V->getType()->isIntOrIntVectorTy() &&
2042 DestTy->isIntOrIntVectorTy() &&
2043 "Can only zero extend/truncate integers!");
2044 Type *VTy = V->getType();
2045 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2046 return CreateZExt(V, DestTy, Name);
2047 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2048 return CreateTrunc(V, DestTy, Name);
2049 return V;
2050 }
2051
2052 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2053 /// the value untouched if the type of V is already DestTy.
2055 const Twine &Name = "") {
2056 assert(V->getType()->isIntOrIntVectorTy() &&
2057 DestTy->isIntOrIntVectorTy() &&
2058 "Can only sign extend/truncate integers!");
2059 Type *VTy = V->getType();
2060 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2061 return CreateSExt(V, DestTy, Name);
2062 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2063 return CreateTrunc(V, DestTy, Name);
2064 return V;
2065 }
2066
2067 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2068 if (IsFPConstrained)
2069 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2070 V, DestTy, nullptr, Name);
2071 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2072 }
2073
2074 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2075 if (IsFPConstrained)
2076 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2077 V, DestTy, nullptr, Name);
2078 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2079 }
2080
2081 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2082 bool IsNonNeg = false) {
2083 if (IsFPConstrained)
2084 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2085 V, DestTy, nullptr, Name);
2086 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2087 return Folded;
2088 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2089 if (IsNonNeg)
2090 I->setNonNeg();
2091 return I;
2092 }
2093
2094 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2095 if (IsFPConstrained)
2096 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2097 V, DestTy, nullptr, Name);
2098 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2099 }
2100
2102 const Twine &Name = "") {
2103 if (IsFPConstrained)
2105 Intrinsic::experimental_constrained_fptrunc, V, DestTy, nullptr,
2106 Name);
2107 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
2108 }
2109
2110 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
2111 if (IsFPConstrained)
2112 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2113 V, DestTy, nullptr, Name);
2114 return CreateCast(Instruction::FPExt, V, DestTy, Name);
2115 }
2116
2118 const Twine &Name = "") {
2119 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2120 }
2121
2123 const Twine &Name = "") {
2124 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2125 }
2126
2128 const Twine &Name = "") {
2129 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2130 }
2131
2133 const Twine &Name = "") {
2134 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2135 }
2136
2137 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2138 Instruction::CastOps CastOp =
2139 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2140 ? Instruction::BitCast
2141 : Instruction::ZExt;
2142 return CreateCast(CastOp, V, DestTy, Name);
2143 }
2144
2145 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2146 Instruction::CastOps CastOp =
2147 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2148 ? Instruction::BitCast
2149 : Instruction::SExt;
2150 return CreateCast(CastOp, V, DestTy, Name);
2151 }
2152
2153 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2154 Instruction::CastOps CastOp =
2155 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2156 ? Instruction::BitCast
2157 : Instruction::Trunc;
2158 return CreateCast(CastOp, V, DestTy, Name);
2159 }
2160
2162 const Twine &Name = "") {
2163 if (V->getType() == DestTy)
2164 return V;
2165 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2166 return Folded;
2167 return Insert(CastInst::Create(Op, V, DestTy), Name);
2168 }
2169
2171 const Twine &Name = "") {
2172 if (V->getType() == DestTy)
2173 return V;
2174 if (auto *VC = dyn_cast<Constant>(V))
2175 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2176 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2177 }
2178
2179 // With opaque pointers enabled, this can be substituted with
2180 // CreateAddrSpaceCast.
2181 // TODO: Replace uses of this method and remove the method itself.
2183 const Twine &Name = "") {
2184 if (V->getType() == DestTy)
2185 return V;
2186
2187 if (auto *VC = dyn_cast<Constant>(V)) {
2189 Name);
2190 }
2191
2193 Name);
2194 }
2195
2197 const Twine &Name = "") {
2198 Instruction::CastOps CastOp =
2199 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2200 ? Instruction::Trunc
2201 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2202 return CreateCast(CastOp, V, DestTy, Name);
2203 }
2204
2206 const Twine &Name = "") {
2207 if (V->getType() == DestTy)
2208 return V;
2209 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2210 return CreatePtrToInt(V, DestTy, Name);
2211 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2212 return CreateIntToPtr(V, DestTy, Name);
2213
2214 return CreateBitCast(V, DestTy, Name);
2215 }
2216
2217 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
2218 Instruction::CastOps CastOp =
2219 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2220 ? Instruction::FPTrunc
2221 : Instruction::FPExt;
2222 return CreateCast(CastOp, V, DestTy, Name);
2223 }
2224
2226 Intrinsic::ID ID, Value *V, Type *DestTy,
2227 Instruction *FMFSource = nullptr, const Twine &Name = "",
2228 MDNode *FPMathTag = nullptr,
2229 std::optional<RoundingMode> Rounding = std::nullopt,
2230 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2231
2232 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2233 // compile time error, instead of converting the string to bool for the
2234 // isSigned parameter.
2235 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2236
2237 //===--------------------------------------------------------------------===//
2238 // Instruction creation methods: Compare Instructions
2239 //===--------------------------------------------------------------------===//
2240
2243 }
2244
2247 }
2248
2251 }
2252
2255 }
2256
2259 }
2260
2263 }
2264
2267 }
2268
2271 }
2272
2275 }
2276
2279 }
2280
2282 MDNode *FPMathTag = nullptr) {
2283 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2284 }
2285
2287 MDNode *FPMathTag = nullptr) {
2288 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2289 }
2290
2292 MDNode *FPMathTag = nullptr) {
2293 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2294 }
2295
2297 MDNode *FPMathTag = nullptr) {
2298 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2299 }
2300
2302 MDNode *FPMathTag = nullptr) {
2303 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2304 }
2305
2307 MDNode *FPMathTag = nullptr) {
2308 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2309 }
2310
2312 MDNode *FPMathTag = nullptr) {
2313 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2314 }
2315
2317 MDNode *FPMathTag = nullptr) {
2318 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2319 }
2320
2322 MDNode *FPMathTag = nullptr) {
2323 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2324 }
2325
2327 MDNode *FPMathTag = nullptr) {
2328 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2329 }
2330
2332 MDNode *FPMathTag = nullptr) {
2333 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2334 }
2335
2337 MDNode *FPMathTag = nullptr) {
2338 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2339 }
2340
2342 MDNode *FPMathTag = nullptr) {
2343 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2344 }
2345
2347 MDNode *FPMathTag = nullptr) {
2348 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2349 }
2350
2352 const Twine &Name = "") {
2353 if (auto *V = Folder.FoldICmp(P, LHS, RHS))
2354 return V;
2355 return Insert(new ICmpInst(P, LHS, RHS), Name);
2356 }
2357
2358 // Create a quiet floating-point comparison (i.e. one that raises an FP
2359 // exception only in the case where an input is a signaling NaN).
2360 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2362 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2363 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, false);
2364 }
2365
2367 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2368 return CmpInst::isFPPredicate(Pred)
2369 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2370 : CreateICmp(Pred, LHS, RHS, Name);
2371 }
2372
2373 // Create a signaling floating-point comparison (i.e. one that raises an FP
2374 // exception whenever an input is any NaN, signaling or quiet).
2375 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2377 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2378 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, true);
2379 }
2380
2381private:
2382 // Helper routine to create either a signaling or a quiet FP comparison.
2383 Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2384 const Twine &Name, MDNode *FPMathTag,
2385 bool IsSignaling);
2386
2387public:
2390 const Twine &Name = "",
2391 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2392
2393 //===--------------------------------------------------------------------===//
2394 // Instruction creation methods: Other Instructions
2395 //===--------------------------------------------------------------------===//
2396
2397 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2398 const Twine &Name = "") {
2399 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2400 if (isa<FPMathOperator>(Phi))
2401 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2402 return Insert(Phi, Name);
2403 }
2404
2405private:
2406 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2407 const Twine &Name = "",
2408 Instruction *FMFSource = nullptr,
2409 ArrayRef<OperandBundleDef> OpBundles = {});
2410
2411public:
2413 ArrayRef<Value *> Args = std::nullopt,
2414 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2415 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2416 if (IsFPConstrained)
2418 if (isa<FPMathOperator>(CI))
2419 setFPAttrs(CI, FPMathTag, FMF);
2420 return Insert(CI, Name);
2421 }
2422
2425 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2426 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2427 if (IsFPConstrained)
2429 if (isa<FPMathOperator>(CI))
2430 setFPAttrs(CI, FPMathTag, FMF);
2431 return Insert(CI, Name);
2432 }
2433
2435 ArrayRef<Value *> Args = std::nullopt,
2436 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2437 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2438 FPMathTag);
2439 }
2440
2443 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2444 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2445 OpBundles, Name, FPMathTag);
2446 }
2447
2449 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2450 std::optional<RoundingMode> Rounding = std::nullopt,
2451 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2452
2453 Value *CreateSelect(Value *C, Value *True, Value *False,
2454 const Twine &Name = "", Instruction *MDFrom = nullptr);
2455
2457 return Insert(new VAArgInst(List, Ty), Name);
2458 }
2459
2461 const Twine &Name = "") {
2462 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2463 return V;
2465 }
2466
2468 const Twine &Name = "") {
2469 return CreateExtractElement(Vec, getInt64(Idx), Name);
2470 }
2471
2473 const Twine &Name = "") {
2474 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2475 }
2476
2478 const Twine &Name = "") {
2479 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2480 }
2481
2483 const Twine &Name = "") {
2484 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2485 return V;
2486 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2487 }
2488
2490 const Twine &Name = "") {
2491 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2492 }
2493
2495 const Twine &Name = "") {
2496 SmallVector<int, 16> IntMask;
2497 ShuffleVectorInst::getShuffleMask(cast<Constant>(Mask), IntMask);
2498 return CreateShuffleVector(V1, V2, IntMask, Name);
2499 }
2500
2501 /// See class ShuffleVectorInst for a description of the mask representation.
2503 const Twine &Name = "") {
2504 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2505 return V;
2506 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2507 }
2508
2509 /// Create a unary shuffle. The second vector operand of the IR instruction
2510 /// is poison.
2512 const Twine &Name = "") {
2513 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2514 }
2515
2517 const Twine &Name = "") {
2518 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2519 return V;
2520 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2521 }
2522
2524 const Twine &Name = "") {
2525 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2526 return V;
2527 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2528 }
2529
2530 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2531 const Twine &Name = "") {
2532 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2533 }
2534
2535 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2536 return Insert(new FreezeInst(V), Name);
2537 }
2538
2539 //===--------------------------------------------------------------------===//
2540 // Utility creation methods
2541 //===--------------------------------------------------------------------===//
2542
2543 /// Return a boolean value testing if \p Arg == 0.
2544 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2545 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2546 }
2547
2548 /// Return a boolean value testing if \p Arg != 0.
2549 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2550 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2551 }
2552
2553 /// Return a boolean value testing if \p Arg < 0.
2554 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2556 }
2557
2558 /// Return a boolean value testing if \p Arg > -1.
2559 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2561 Name);
2562 }
2563
2564 /// Return the i64 difference between two pointer values, dividing out
2565 /// the size of the pointed-to objects.
2566 ///
2567 /// This is intended to implement C-style pointer subtraction. As such, the
2568 /// pointers must be appropriately aligned for their element types and
2569 /// pointing into the same object.
2570 Value *CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS,
2571 const Twine &Name = "");
2572
2573 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2574 /// different from pointer to i8, it's casted to pointer to i8 in the same
2575 /// address space before call and casted back to Ptr type after call.
2577
2578 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2579 /// different from pointer to i8, it's casted to pointer to i8 in the same
2580 /// address space before call and casted back to Ptr type after call.
2582
2583 /// Return a vector value that contains the vector V reversed
2584 Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2585
2586 /// Return a vector splice intrinsic if using scalable vectors, otherwise
2587 /// return a shufflevector. If the immediate is positive, a vector is
2588 /// extracted from concat(V1, V2), starting at Imm. If the immediate
2589 /// is negative, we extract -Imm elements from V1 and the remaining
2590 /// elements from V2. Imm is a signed integer in the range
2591 /// -VL <= Imm < VL (where VL is the runtime vector length of the
2592 /// source/result vector)
2593 Value *CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
2594 const Twine &Name = "");
2595
2596 /// Return a vector value that contains \arg V broadcasted to \p
2597 /// NumElts elements.
2598 Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "");
2599
2600 /// Return a vector value that contains \arg V broadcasted to \p
2601 /// EC elements.
2602 Value *CreateVectorSplat(ElementCount EC, Value *V, const Twine &Name = "");
2603
2605 unsigned Dimension, unsigned LastIndex,
2606 MDNode *DbgInfo);
2607
2608 Value *CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex,
2609 MDNode *DbgInfo);
2610
2612 unsigned Index, unsigned FieldIndex,
2613 MDNode *DbgInfo);
2614
2615 Value *createIsFPClass(Value *FPNum, unsigned Test);
2616
2617private:
2618 /// Helper function that creates an assume intrinsic call that
2619 /// represents an alignment assumption on the provided pointer \p PtrValue
2620 /// with offset \p OffsetValue and alignment value \p AlignValue.
2621 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2622 Value *PtrValue, Value *AlignValue,
2623 Value *OffsetValue);
2624
2625public:
2626 /// Create an assume intrinsic call that represents an alignment
2627 /// assumption on the provided pointer.
2628 ///
2629 /// An optional offset can be provided, and if it is provided, the offset
2630 /// must be subtracted from the provided pointer to get the pointer with the
2631 /// specified alignment.
2633 unsigned Alignment,
2634 Value *OffsetValue = nullptr);
2635
2636 /// Create an assume intrinsic call that represents an alignment
2637 /// assumption on the provided pointer.
2638 ///
2639 /// An optional offset can be provided, and if it is provided, the offset
2640 /// must be subtracted from the provided pointer to get the pointer with the
2641 /// specified alignment.
2642 ///
2643 /// This overload handles the condition where the Alignment is dependent
2644 /// on an existing value rather than a static value.
2646 Value *Alignment,
2647 Value *OffsetValue = nullptr);
2648};
2649
2650/// This provides a uniform API for creating instructions and inserting
2651/// them into a basic block: either at the end of a BasicBlock, or at a specific
2652/// iterator location in a block.
2653///
2654/// Note that the builder does not expose the full generality of LLVM
2655/// instructions. For access to extra instruction properties, use the mutators
2656/// (e.g. setVolatile) on the instructions after they have been
2657/// created. Convenience state exists to specify fast-math flags and fp-math
2658/// tags.
2659///
2660/// The first template argument specifies a class to use for creating constants.
2661/// This defaults to creating minimally folded constants. The second template
2662/// argument allows clients to specify custom insertion hooks that are called on
2663/// every newly created insertion.
2664template <typename FolderTy = ConstantFolder,
2665 typename InserterTy = IRBuilderDefaultInserter>
2666class IRBuilder : public IRBuilderBase {
2667private:
2668 FolderTy Folder;
2669 InserterTy Inserter;
2670
2671public:
2672 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter = InserterTy(),
2673 MDNode *FPMathTag = nullptr,
2674 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2675 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2676 Folder(Folder), Inserter(Inserter) {}
2677
2678 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2679 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2680 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2681
2682 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2683 MDNode *FPMathTag = nullptr,
2684 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2685 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2686 FPMathTag, OpBundles),
2687 Folder(Folder) {
2688 SetInsertPoint(TheBB);
2689 }
2690
2691 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2692 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2693 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2694 FPMathTag, OpBundles) {
2695 SetInsertPoint(TheBB);
2696 }
2697
2698 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2699 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2700 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2701 OpBundles) {
2702 SetInsertPoint(IP);
2703 }
2704
2705 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2706 MDNode *FPMathTag = nullptr,
2707 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2708 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2709 FPMathTag, OpBundles),
2710 Folder(Folder) {
2711 SetInsertPoint(TheBB, IP);
2712 }
2713
2715 MDNode *FPMathTag = nullptr,
2716 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2717 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2718 FPMathTag, OpBundles) {
2719 SetInsertPoint(TheBB, IP);
2720 }
2721
2722 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2723 /// or FastMathFlagGuard instead.
2724 IRBuilder(const IRBuilder &) = delete;
2725
2726 InserterTy &getInserter() { return Inserter; }
2727 const InserterTy &getInserter() const { return Inserter; }
2728};
2729
2730template <typename FolderTy, typename InserterTy>
2731IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2734template <typename FolderTy>
2739template <typename FolderTy>
2744
2745
2746// Create wrappers for C Binding types (see CBindingWrapping.h).
2748
2749} // end namespace llvm
2750
2751#endif // LLVM_IR_IRBUILDER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
std::string Name
uint64_t Size
static bool isSigned(unsigned int Opcode)
This file contains the declarations of entities that describe floating point environment and related ...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:76
an instruction to allocate memory on the stack
Definition: Instructions.h:59
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
Value handle that asserts if the Value is deleted.
Definition: ValueHandle.h:264
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:539
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:748
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:760
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
iterator end()
Definition: BasicBlock.h:443
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:206
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:165
const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Definition: BasicBlock.cpp:423
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:289
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a binary instruction, given the opcode and the two operands.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1494
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, BasicBlock::iterator InsertBefore)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB, BasicBlock::iterator InsertBefore)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:993
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:996
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:1010
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:1022
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:1023
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:999
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:1008
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:997
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:998
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:1017
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:1016
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:1020
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:1007
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:1001
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:1004
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:1018
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:1005
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:1000
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:1002
@ ICMP_EQ
equal
Definition: InstrTypes.h:1014
@ ICMP_NE
not equal
Definition: InstrTypes.h:1015
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:1021
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:1009
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:1019
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:1006
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition: InstrTypes.h:995
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:1003
bool isFPPredicate() const
Definition: InstrTypes.h:1122
static StringRef getPredicateName(Predicate P)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1226
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:849
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:856
This is an important base class in LLVM.
Definition: Constant.h:41
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:417
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:370
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
A debug info location.
Definition: DebugLoc.h:33
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
void clear()
Definition: FMF.h:61
An instruction for ordering other memory operations.
Definition: Instructions.h:460
This class represents a freeze function that returns random concrete value if an operand is either a ...
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
Class to represent function types.
Definition: DerivedTypes.h:103
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Create an "inbounds" getelementptr.
Type * getValueType() const
Definition: GlobalValue.h:296
This instruction compares its operands according to the predicate given to the constructor.
FastMathFlagGuard(const FastMathFlagGuard &)=delete
FastMathFlagGuard & operator=(const FastMathFlagGuard &)=delete
InsertPointGuard & operator=(const InsertPointGuard &)=delete
InsertPointGuard(const InsertPointGuard &)=delete
InsertPoint - A saved insertion point.
Definition: IRBuilder.h:257
InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
Creates a new insertion point at the given location.
Definition: IRBuilder.h:266
BasicBlock * getBlock() const
Definition: IRBuilder.h:272
InsertPoint()=default
Creates a new insertion point which doesn't point to anything.
bool isSet() const
Returns true if this insert point is set.
Definition: IRBuilder.h:270
BasicBlock::iterator getPoint() const
Definition: IRBuilder.h:273
OperandBundlesGuard(const OperandBundlesGuard &)=delete
OperandBundlesGuard & operator=(const OperandBundlesGuard &)=delete
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:94
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1400
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2137
CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memcpy between the specified pointers.
Definition: IRBuilder.cpp:256
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2306
Value * CreateFAddFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1547
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:461
Value * CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2376
CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Definition: IRBuilder.cpp:704
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1169
BasicBlock * BB
Definition: IRBuilder.h:119
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1374
CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
Definition: IRBuilder.cpp:913
Value * CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS, const Twine &Name="")
Return the i64 difference between two pointer values, dividing out the size of the pointed-to objects...
Definition: IRBuilder.cpp:1126
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:437
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:417
CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
Definition: IRBuilder.cpp:686
Value * CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maxnum intrinsic.
Definition: IRBuilder.h:1002
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2257
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1927
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Create a callbr instruction.
Definition: IRBuilder.h:1197
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1188
Value * CreateVScale(Constant *Scaling, const Twine &Name="")
Create a call to llvm.vscale, multiplied by Scaling.
Definition: IRBuilder.cpp:88
RoundingMode DefaultConstrainedRounding
Definition: IRBuilder.h:130
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1137
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition: IRBuilder.h:1037
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2331
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2477
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2217
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1410
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition: IRBuilder.h:1812
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1560
Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
Definition: IRBuilder.cpp:921
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2361
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition: IRBuilder.h:1248
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2472
void SetNoSanitizeMetadata()
Set nosanitize metadata.
Definition: IRBuilder.h:225
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1451
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1841
CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
Definition: IRBuilder.cpp:538
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1881
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1773
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition: IRBuilder.h:365
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition: IRBuilder.h:1053
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:1180
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:511
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1901
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.h:676
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:2523
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1489
IndirectBrInst * CreateIndirectBr(Value *Addr, unsigned NumDests=10)
Create an indirect branch instruction with the specified address operand, with an optional hint for t...
Definition: IRBuilder.h:1153
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:1129
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1481
void setDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition: IRBuilder.h:308
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition: IRBuilder.cpp:58
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2441
Value * CreateFMulFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1601
CallInst * CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.pointer.base intrinsic to get the base pointer for the specified...
Definition: IRBuilder.cpp:895
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1614
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", bool IsInBounds=false)
Definition: IRBuilder.h:1978
CallInst * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition: IRBuilder.h:1045
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1446
void clearFastMathFlags()
Clear the fast-math flags.
Definition: IRBuilder.h:305
Value * CreateFSubFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1574
Value * CreateFDivFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1628
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2094
CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef< Value * > CallArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create a call to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
Definition: IRBuilder.cpp:783
LoadInst * CreateLoad(Type *Ty, Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1798
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1702
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2460
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1688
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition: IRBuilder.h:539
void setDefaultConstrainedExcept(fp::ExceptionBehavior NewExcept)
Set the exception handling to be used with constrained floating point.
Definition: IRBuilder.h:323
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2265
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2101
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition: IRBuilder.h:1807
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2311
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition: IRBuilder.h:559
Constant * CreateGlobalStringPtr(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr)
Same as CreateGlobalString, but return a pointer with "i8*" type instead of a pointer to array of i8.
Definition: IRBuilder.h:1993
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:2039
Value * CreateFRemFMF(Value *L, Value *R, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1654
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1533
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:1263
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr)
Make a new global variable with initializer type i8*.
Definition: IRBuilder.cpp:43
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:481
CallInst * CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, const Twine &Name="", std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Definition: IRBuilder.cpp:1072
CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles=std::nullopt)
Generate the IR for a call to the builtin free function.
Definition: IRBuilder.cpp:353
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:441
Value * CreateVectorSplice(Value *V1, Value *V2, int64_t Imm, const Twine &Name="")
Return a vector splice intrinsic if using scalable vectors, otherwise return a shufflevector.
Definition: IRBuilder.cpp:1186
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2170
void setDefaultConstrainedRounding(RoundingMode NewRounding)
Set the rounding mode handling to be used with constrained floating point.
Definition: IRBuilder.h:333
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.cpp:1214
Value * CreateFRem(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1641
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:2516
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1485
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition: IRBuilder.h:466
Value * Insert(Value *V, const Twine &Name="") const
Definition: IRBuilder.h:156
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
Definition: IRBuilder.h:2530
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Definition: IRBuilder.cpp:932
Value * CreateFNegFMF(Value *V, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Definition: IRBuilder.h:1740
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition: IRBuilder.h:1017
Value * CreateMinNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minnum intrinsic.
Definition: IRBuilder.h:992
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1282
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
Definition: IRBuilder.cpp:1328
CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
Definition: IRBuilder.cpp:578
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2269
CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Definition: IRBuilder.cpp:1084
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
Definition: IRBuilder.h:595
LLVMContext & Context
Definition: IRBuilder.h:121
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:1110
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
Definition: IRBuilder.h:1158
RoundingMode getDefaultConstrainedRounding()
Get the rounding mode handling used with constrained floating point.
Definition: IRBuilder.h:348
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2067
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1947
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2346
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:175
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1973
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1834
IntegerType * getIndexTy(const DataLayout &DL, unsigned AddrSpace)
Fetch the type of an integer that should be used to index GEP operations within AddressSpace.
Definition: IRBuilder.h:581
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:1223
CallInst * CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.get.pointer.offset intrinsic to get the offset of the specified ...
Definition: IRBuilder.cpp:904
fp::ExceptionBehavior getDefaultConstrainedExcept()
Get the exception handling used with constrained floating point.
Definition: IRBuilder.h:343
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2033
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2145
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2326
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2122
Value * CreateTypeSize(Type *DstType, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
Definition: IRBuilder.cpp:104
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:433
Value * CreateFreeze(Value *V, const Twine &Name="")
Definition: IRBuilder.h:2535
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:120
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1437
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type of an integer with size at least as big as that of a pointer in the given address spac...
Definition: IRBuilder.h:575
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:526
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1891
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:476
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition: IRBuilder.h:2559
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition: IRBuilder.h:1259
CallInst * CreateConstrainedFPUnroundedBinOp(Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource=nullptr, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Definition: IRBuilder.cpp:988
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition: IRBuilder.h:1236
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition: IRBuilder.h:2081
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:1095
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1336
bool getIsFPConstrained()
Query for the use of constrained floating point math.
Definition: IRBuilder.h:320
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1470
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:174
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.h:720
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition: IRBuilder.h:544
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Definition: IRBuilder.h:311
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2296
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:220
void SetInsertPointPastAllocas(Function *F)
This specifies that created instructions should inserted at the beginning end of the specified functi...
Definition: IRBuilder.h:214
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:531
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition: IRBuilder.h:1876
CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.cpp:219
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1370
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition: IRBuilder.h:282
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1503
Value * CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2182
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Definition: IRBuilder.cpp:1170
Value * CreateShuffleVector(Value *V, ArrayRef< int > Mask, const Twine &Name="")
Create a unary shuffle.
Definition: IRBuilder.h:2511
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:449
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1465
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1378
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2341
FastMathFlags FMF
Definition: IRBuilder.h:126
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2245
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1340
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition: IRBuilder.h:521
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:491
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition: IRBuilder.h:1241
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition: IRBuilder.h:848
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1753
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition: IRBuilder.h:1721
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:1794
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:445
CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
Definition: IRBuilder.cpp:301
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:277
void CollectMetadataToCopy(Instruction *Src, ArrayRef< unsigned > MetadataKinds)
Collect metadata with IDs MetadataKinds from Src which should be added to all created instructions.
Definition: IRBuilder.h:233
CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:469
void SetInsertPoint(BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point,...
Definition: IRBuilder.h:205
CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:473
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2489
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1431
Value * CreateShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask, const Twine &Name="")
See class ShuffleVectorInst for a description of the mask representation.
Definition: IRBuilder.h:2502
ReturnInst * CreateAggregateRet(Value *const *retVals, unsigned N)
Create a sequence of N insertvalue instructions, with one Value from the retVals array each,...
Definition: IRBuilder.h:1106
Value * createIsFPClass(Value *FPNum, unsigned Test)
Definition: IRBuilder.cpp:1309
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2301
CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:465
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:486
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2434
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2205
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2366
const IRBuilderDefaultInserter & Inserter
Definition: IRBuilder.h:123
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2277
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition: IRBuilder.h:2397
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2423
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1749
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Definition: IRBuilder.h:1143
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2241
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:145
CallInst * CreateConstrainedFPBinOp(Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource=nullptr, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Definition: IRBuilder.cpp:969
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2321
void setIsFPConstrained(bool IsCon)
Enable/Disable use of constrained floating point math.
Definition: IRBuilder.h:317
DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition: IRBuilder.cpp:63
Value * CreateMinimum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minimum intrinsic.
Definition: IRBuilder.h:1012
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition: IRBuilder.h:536
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition: IRBuilder.h:2554
Constant * Insert(Constant *C, const Twine &="") const
No-op overload to handle constants.
Definition: IRBuilder.h:152
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1344
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2127
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
Definition: IRBuilder.h:497
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:1120
IRBuilderBase(LLVMContext &context, const IRBuilderFolder &Folder, const IRBuilderDefaultInserter &Inserter, MDNode *FPMathTag, ArrayRef< OperandBundleDef > OpBundles)
Definition: IRBuilder.h:135
void AddMetadataToInst(Instruction *I) const
Add all entries in MetadataToCopy to I.
Definition: IRBuilder.h:247
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2249
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition: IRBuilder.h:1790
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1416
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition: IRBuilder.h:300
Value * CreateNAryOp(unsigned Opc, ArrayRef< Value * > Ops, const Twine &Name="", MDNode *FPMathTag=nullptr)
Create either a UnaryOperator or BinaryOperator depending on Opc.
Definition: IRBuilder.cpp:1005
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition: IRBuilder.h:2021
CallInst * CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.h:688
CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Definition: IRBuilder.cpp:551
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2494
LLVMContext & getContext() const
Definition: IRBuilder.h:176
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2281
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1475
FastMathFlags & getFastMathFlags()
Definition: IRBuilder.h:302
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:1090
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1353
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1914
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1960
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1263
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1803
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:453
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:598
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1327
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2117
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1391
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:471
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition: IRBuilder.h:2456
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1387
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition: IRBuilder.h:554
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition: IRBuilder.h:2549
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
Definition: IRBuilder.h:196
Instruction * CreateNoAliasScopeDeclaration(MDNode *ScopeTag)
Definition: IRBuilder.h:864
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1425
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1854
CallInst * CreateGCResult(Instruction *Statepoint, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.result intrinsic to extract the result from a call wrapped in a ...
Definition: IRBuilder.cpp:872
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1253
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition: IRBuilder.h:2007
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:496
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1497
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition: IRBuilder.h:569
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1666
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition: IRBuilder.h:1114
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1676
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Definition: IRBuilder.cpp:99
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2482
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1937
fp::ExceptionBehavior DefaultConstrainedExcept
Definition: IRBuilder.h:129
CallInst * CreateConstrainedFPCast(Intrinsic::ID ID, Value *V, Type *DestTy, Instruction *FMFSource=nullptr, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Definition: IRBuilder.cpp:1020
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition: IRBuilder.h:169
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2273
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition: IRBuilder.h:481
MDNode * DefaultFPMathTag
Definition: IRBuilder.h:125
CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memmove between the specified pointers.
Definition: IRBuilder.cpp:372
ArrayRef< OperandBundleDef > DefaultOperandBundles
Definition: IRBuilder.h:132
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2161
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:1205
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2253
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition: IRBuilder.h:297
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:2196
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2316
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:289
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
Definition: IRBuilder.h:2544
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2286
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition: IRBuilder.h:1060
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:459
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition: IRBuilder.h:180
Type * getVoidTy()
Fetch the type representing void.
Definition: IRBuilder.h:564
Value * CreateOr(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1511
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1780
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2467
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition: IRBuilder.h:1826
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1507
void setConstrainedFPCallAttr(CallBase *I)
Definition: IRBuilder.h:361
InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
Definition: IRBuilder.cpp:839
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2412
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1216
const IRBuilderFolder & Folder
Definition: IRBuilder.h:122
Value * CreateInBoundsPtrAdd(Value *Ptr, Value *Offset, const Twine &Name="")
Definition: IRBuilder.h:1983
Value * CreateIntCast(Value *, Type *, const char *)=delete
CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.cpp:164
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1456
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition: IRBuilder.h:620
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2110
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1519
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:425
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2153
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2261
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", bool IsInBounds=false)
Definition: IRBuilder.h:1866
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2351
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1682
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1587
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1817
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1730
void setConstrainedFPFunctionAttr()
Definition: IRBuilder.h:352
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.cpp:70
void SetInsertPoint(Instruction *I)
This specifies that created instructions should be inserted before the specified instruction.
Definition: IRBuilder.h:187
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:516
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition: IRBuilder.h:502
CallInst * CreateGCRelocate(Instruction *Statepoint, int BaseOffset, int DerivedOffset, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.relocate intrinsics to project the relocated value of one pointe...
Definition: IRBuilder.cpp:883
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1404
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Definition: IRBuilder.cpp:109
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memcpy between the specified pointers.
Definition: IRBuilder.h:659
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.h:711
Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1234
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:2054
ResumeInst * CreateResume(Value *Exn)
Definition: IRBuilder.h:1232
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2132
Type * getBFloatTy()
Fetch the type representing a 16-bit brain floating point value.
Definition: IRBuilder.h:549
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1525
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Definition: IRBuilder.cpp:511
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1361
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
Definition: IRBuilder.cpp:562
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
Definition: IRBuilder.cpp:661
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1529
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1726
CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:477
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2291
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1153
CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
Definition: IRBuilder.cpp:630
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1357
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2336
CallInst * CreateArithmeticFence(Value *Val, Type *DstType, const Twine &Name="")
Create a call to the arithmetic_fence intrinsic.
Definition: IRBuilder.h:1030
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2074
Value * CreateCopySign(Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create call to the copysign intrinsic.
Definition: IRBuilder.h:1022
Provides an 'InsertHelper' that calls a user-provided callback after performing the default insertion...
Definition: IRBuilder.h:76
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const override
Definition: IRBuilder.h:85
IRBuilderCallbackInserter(std::function< void(Instruction *)> Callback)
Definition: IRBuilder.h:82
This provides the default implementation of the IRBuilder 'InsertHelper' method that is called whenev...
Definition: IRBuilder.h:61
virtual void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const
Definition: IRBuilder.h:65
IRBuilderFolder - Interface for constant folding in IRBuilder.
virtual Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const =0
virtual Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const =0
virtual Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const =0
virtual Value * FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
virtual Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const =0
virtual Value * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const =0
virtual Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const =0
virtual Value * CreatePointerCast(Constant *C, Type *DestTy) const =0
virtual Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const =0
virtual Value * FoldExtractElement(Value *Vec, Value *Idx) const =0
virtual Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const =0
virtual Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, bool IsInBounds=false) const =0
virtual Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const =0
virtual Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const =0
virtual Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const =0
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2666
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter=InserterTy(), MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2672
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2705
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2698
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2678
InserterTy & getInserter()
Definition: IRBuilder.h:2726
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2714
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2682
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2691
const InserterTy & getInserter() const
Definition: IRBuilder.h:2727
Indirect Branch Instruction.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, BasicBlock::iterator InsertBefore)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr, BasicBlock::iterator InsertBefore)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Class to represent integer types.
Definition: DerivedTypes.h:40
Invoke instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
An instruction for reading from memory.
Definition: Instructions.h:184
Metadata node.
Definition: Metadata.h:1067
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:600
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:103
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:293
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Class to represent pointers.
Definition: DerivedTypes.h:646