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