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
1015 /// \p OverloadTypes. If \p FMFSource is provided, copy fast-math-flags from
1016 /// that instruction to the intrinsic.
1018 ArrayRef<Type *> OverloadTypes,
1019 ArrayRef<Value *> Args,
1020 FMFSource FMFSource = {},
1021 const Twine &Name = "");
1022
1023 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
1024 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
1025 /// the intrinsic.
1026 LLVM_ABI CallInst *CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
1027 ArrayRef<Value *> Args,
1028 FMFSource FMFSource = {},
1029 const Twine &Name = "");
1030
1031 /// Create a call to non-overloaded intrinsic \p ID with \p Args. If
1032 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
1033 /// the intrinsic.
1035 FMFSource FMFSource = {}, const Twine &Name = "") {
1036 return CreateIntrinsic(ID, /*Types=*/{}, Args, FMFSource, Name);
1037 }
1038
1039 /// Create call to the minnum intrinsic.
1041 const Twine &Name = "") {
1042 if (IsFPConstrained) {
1044 Intrinsic::experimental_constrained_minnum, LHS, RHS, FMFSource,
1045 Name);
1046 }
1047
1048 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, FMFSource, Name);
1049 }
1050
1051 /// Create call to the maxnum intrinsic.
1053 const Twine &Name = "") {
1054 if (IsFPConstrained) {
1056 Intrinsic::experimental_constrained_maxnum, LHS, RHS, FMFSource,
1057 Name);
1058 }
1059
1060 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, FMFSource, Name);
1061 }
1062
1063 /// Create call to the minimum intrinsic.
1064 Value *CreateMinimum(Value *LHS, Value *RHS, const Twine &Name = "") {
1065 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1066 }
1067
1068 /// Create call to the maximum intrinsic.
1069 Value *CreateMaximum(Value *LHS, Value *RHS, const Twine &Name = "") {
1070 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1071 }
1072
1073 /// Create call to the minimumnum intrinsic.
1074 Value *CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1075 return CreateBinaryIntrinsic(Intrinsic::minimumnum, LHS, RHS, nullptr,
1076 Name);
1077 }
1078
1079 /// Create call to the maximum intrinsic.
1080 Value *CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1081 return CreateBinaryIntrinsic(Intrinsic::maximumnum, LHS, RHS, nullptr,
1082 Name);
1083 }
1084
1085 /// Create call to the copysign intrinsic.
1087 const Twine &Name = "") {
1088 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1089 Name);
1090 }
1091
1092 /// Create call to the ldexp intrinsic.
1094 const Twine &Name = "") {
1095 assert(!IsFPConstrained && "TODO: Support strictfp");
1096 return CreateIntrinsic(Intrinsic::ldexp, {Src->getType(), Exp->getType()},
1097 {Src, Exp}, FMFSource, Name);
1098 }
1099
1100 /// Create call to the fma intrinsic.
1101 Value *CreateFMA(Value *Factor1, Value *Factor2, Value *Summand,
1102 FMFSource FMFSource = {}, const Twine &Name = "") {
1103 if (IsFPConstrained) {
1105 Intrinsic::experimental_constrained_fma, {Factor1->getType()},
1106 {Factor1, Factor2, Summand}, FMFSource, Name);
1107 }
1108
1109 return CreateIntrinsic(Intrinsic::fma, {Factor1->getType()},
1110 {Factor1, Factor2, Summand}, FMFSource, Name);
1111 }
1112
1113 /// Create a call to the arithmetic_fence intrinsic.
1115 const Twine &Name = "") {
1116 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1117 Name);
1118 }
1119
1120 /// Create a call to the vector.extract intrinsic.
1121 CallInst *CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx,
1122 const Twine &Name = "") {
1123 return CreateIntrinsic(Intrinsic::vector_extract,
1124 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1125 Name);
1126 }
1127
1128 /// Create a call to the vector.extract intrinsic.
1130 const Twine &Name = "") {
1131 return CreateExtractVector(DstType, SrcVec, getInt64(Idx), Name);
1132 }
1133
1134 /// Create a call to the vector.insert intrinsic.
1135 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1136 Value *Idx, const Twine &Name = "") {
1137 return CreateIntrinsic(Intrinsic::vector_insert,
1138 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1139 nullptr, Name);
1140 }
1141
1142 /// Create a call to the vector.extract intrinsic.
1143 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1144 uint64_t Idx, const Twine &Name = "") {
1145 return CreateInsertVector(DstType, SrcVec, SubVec, getInt64(Idx), Name);
1146 }
1147
1148 /// Create a call to llvm.stacksave
1149 CallInst *CreateStackSave(const Twine &Name = "") {
1150 const DataLayout &DL = BB->getDataLayout();
1151 return CreateIntrinsic(Intrinsic::stacksave, {DL.getAllocaPtrType(Context)},
1152 {}, nullptr, Name);
1153 }
1154
1155 /// Create a call to llvm.stackrestore
1156 CallInst *CreateStackRestore(Value *Ptr, const Twine &Name = "") {
1157 return CreateIntrinsic(Intrinsic::stackrestore, {Ptr->getType()}, {Ptr},
1158 nullptr, Name);
1159 }
1160
1161 /// Create a call to llvm.experimental_cttz_elts
1163 bool ZeroIsPoison = true,
1164 const Twine &Name = "") {
1165 return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
1166 {ResTy, Mask->getType()},
1167 {Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
1168 }
1169
1170private:
1171 /// Create a call to a masked intrinsic with given Id.
1172 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1173 ArrayRef<Type *> OverloadedTypes,
1174 const Twine &Name = "");
1175
1176 //===--------------------------------------------------------------------===//
1177 // Instruction creation methods: Terminators
1178 //===--------------------------------------------------------------------===//
1179
1180private:
1181 /// Helper to add branch weight and unpredictable metadata onto an
1182 /// instruction.
1183 /// \returns The annotated instruction.
1184 template <typename InstTy>
1185 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1186 if (Weights)
1187 I->setMetadata(LLVMContext::MD_prof, Weights);
1188 if (Unpredictable)
1189 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1190 return I;
1191 }
1192
1193public:
1194 /// Create a 'ret void' instruction.
1198
1199 /// Create a 'ret <val>' instruction.
1203
1204 /// Create a sequence of N insertvalue instructions, with one Value from the
1205 /// RetVals array each, that build a aggregate return value one value at a
1206 /// time, and a ret instruction to return the resulting aggregate value.
1207 ///
1208 /// This is a convenience function for code that uses aggregate return values
1209 /// as a vehicle for having multiple return values.
1212 for (size_t i = 0, N = RetVals.size(); i != N; ++i)
1213 V = CreateInsertValue(V, RetVals[i], i, "mrv");
1214 return Insert(ReturnInst::Create(Context, V));
1215 }
1216
1217 /// Create an unconditional 'br label X' instruction.
1219 return Insert(UncondBrInst::Create(Dest));
1220 }
1221
1222 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1223 /// instruction.
1225 MDNode *BranchWeights = nullptr,
1226 MDNode *Unpredictable = nullptr) {
1227 return Insert(addBranchMetadata(CondBrInst::Create(Cond, True, False),
1228 BranchWeights, Unpredictable));
1229 }
1230
1231 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1232 /// instruction. Copy branch meta data if available.
1234 Instruction *MDSrc) {
1235 CondBrInst *Br = CondBrInst::Create(Cond, True, False);
1236 if (MDSrc) {
1237 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1238 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1239 Br->copyMetadata(*MDSrc, WL);
1240 }
1241 return Insert(Br);
1242 }
1243
1244 /// Create a switch instruction with the specified value, default dest,
1245 /// and with a hint for the number of cases that will be added (for efficient
1246 /// allocation).
1247 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1248 MDNode *BranchWeights = nullptr,
1249 MDNode *Unpredictable = nullptr) {
1250 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1251 BranchWeights, Unpredictable));
1252 }
1253
1254 /// Create an indirect branch instruction with the specified address
1255 /// operand, with an optional hint for the number of destinations that will be
1256 /// added (for efficient allocation).
1257 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1258 return Insert(IndirectBrInst::Create(Addr, NumDests));
1259 }
1260
1261 /// Create an invoke instruction.
1263 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1264 ArrayRef<Value *> Args,
1266 const Twine &Name = "") {
1267 InvokeInst *II =
1268 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1269 if (IsFPConstrained)
1271 return Insert(II, Name);
1272 }
1274 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1275 ArrayRef<Value *> Args = {},
1276 const Twine &Name = "") {
1277 InvokeInst *II =
1278 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1279 if (IsFPConstrained)
1281 return Insert(II, Name);
1282 }
1283
1285 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1287 const Twine &Name = "") {
1288 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1289 NormalDest, UnwindDest, Args, OpBundles, Name);
1290 }
1291
1293 BasicBlock *UnwindDest, ArrayRef<Value *> Args = {},
1294 const Twine &Name = "") {
1295 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1296 NormalDest, UnwindDest, Args, Name);
1297 }
1298
1299 /// \brief Create a callbr instruction.
1301 BasicBlock *DefaultDest,
1302 ArrayRef<BasicBlock *> IndirectDests,
1303 ArrayRef<Value *> Args = {},
1304 const Twine &Name = "") {
1305 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1306 Args), Name);
1307 }
1309 BasicBlock *DefaultDest,
1310 ArrayRef<BasicBlock *> IndirectDests,
1311 ArrayRef<Value *> Args,
1313 const Twine &Name = "") {
1314 return Insert(
1315 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1316 OpBundles), Name);
1317 }
1318
1320 ArrayRef<BasicBlock *> IndirectDests,
1321 ArrayRef<Value *> Args = {},
1322 const Twine &Name = "") {
1323 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1324 DefaultDest, IndirectDests, Args, Name);
1325 }
1327 ArrayRef<BasicBlock *> IndirectDests,
1328 ArrayRef<Value *> Args,
1330 const Twine &Name = "") {
1331 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1332 DefaultDest, IndirectDests, Args, Name);
1333 }
1334
1336 return Insert(ResumeInst::Create(Exn));
1337 }
1338
1340 BasicBlock *UnwindBB = nullptr) {
1341 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1342 }
1343
1345 unsigned NumHandlers,
1346 const Twine &Name = "") {
1347 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1348 Name);
1349 }
1350
1352 const Twine &Name = "") {
1353 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1354 }
1355
1357 ArrayRef<Value *> Args = {},
1358 const Twine &Name = "") {
1359 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1360 }
1361
1365
1369
1370 //===--------------------------------------------------------------------===//
1371 // Instruction creation methods: Binary Operators
1372 //===--------------------------------------------------------------------===//
1373private:
1374 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1375 Value *LHS, Value *RHS,
1376 const Twine &Name,
1377 bool HasNUW, bool HasNSW) {
1379 if (HasNUW) BO->setHasNoUnsignedWrap();
1380 if (HasNSW) BO->setHasNoSignedWrap();
1381 return BO;
1382 }
1383
1384 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1385 FastMathFlags FMF) const {
1386 if (!FPMD)
1387 FPMD = DefaultFPMathTag;
1388 if (FPMD)
1389 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1390 I->setFastMathFlags(FMF);
1391 return I;
1392 }
1393
1394 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1396
1397 if (Rounding)
1398 UseRounding = *Rounding;
1399
1400 std::optional<StringRef> RoundingStr =
1401 convertRoundingModeToStr(UseRounding);
1402 assert(RoundingStr && "Garbage strict rounding mode!");
1403 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1404
1405 return MetadataAsValue::get(Context, RoundingMDS);
1406 }
1407
1408 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1409 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1410 Except.value_or(DefaultConstrainedExcept));
1411 assert(ExceptStr && "Garbage strict exception behavior!");
1412 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1413
1414 return MetadataAsValue::get(Context, ExceptMDS);
1415 }
1416
1417 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1418 assert(CmpInst::isFPPredicate(Predicate) &&
1419 Predicate != CmpInst::FCMP_FALSE &&
1420 Predicate != CmpInst::FCMP_TRUE &&
1421 "Invalid constrained FP comparison predicate!");
1422
1423 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1424 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1425
1426 return MetadataAsValue::get(Context, PredicateMDS);
1427 }
1428
1429public:
1430 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
1431 bool HasNUW = false, bool HasNSW = false) {
1432 if (Value *V =
1433 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1434 return V;
1435 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1436 HasNSW);
1437 }
1438
1439 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1440 return CreateAdd(LHS, RHS, Name, false, true);
1441 }
1442
1443 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1444 return CreateAdd(LHS, RHS, Name, true, false);
1445 }
1446
1447 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
1448 bool HasNUW = false, bool HasNSW = false) {
1449 if (Value *V =
1450 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1451 return V;
1452 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1453 HasNSW);
1454 }
1455
1456 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1457 return CreateSub(LHS, RHS, Name, false, true);
1458 }
1459
1460 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1461 return CreateSub(LHS, RHS, Name, true, false);
1462 }
1463
1464 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1465 bool HasNUW = false, bool HasNSW = false) {
1466 if (Value *V =
1467 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1468 return V;
1469 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1470 HasNSW);
1471 }
1472
1473 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1474 return CreateMul(LHS, RHS, Name, false, true);
1475 }
1476
1477 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1478 return CreateMul(LHS, RHS, Name, true, false);
1479 }
1480
1481 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1482 bool isExact = false) {
1483 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1484 return V;
1485 if (!isExact)
1486 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1487 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1488 }
1489
1490 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1491 return CreateUDiv(LHS, RHS, Name, true);
1492 }
1493
1494 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1495 bool isExact = false) {
1496 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1497 return V;
1498 if (!isExact)
1499 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1500 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1501 }
1502
1503 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1504 return CreateSDiv(LHS, RHS, Name, true);
1505 }
1506
1507 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1508 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1509 return V;
1510 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1511 }
1512
1513 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1514 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1515 return V;
1516 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1517 }
1518
1519 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1520 bool HasNUW = false, bool HasNSW = false) {
1521 if (Value *V =
1522 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1523 return V;
1524 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1525 HasNUW, HasNSW);
1526 }
1527
1528 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1529 bool HasNUW = false, bool HasNSW = false) {
1530 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1531 HasNUW, HasNSW);
1532 }
1533
1534 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1535 bool HasNUW = false, bool HasNSW = false) {
1536 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1537 HasNUW, HasNSW);
1538 }
1539
1540 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1541 bool isExact = false) {
1542 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1543 return V;
1544 if (!isExact)
1545 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1546 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1547 }
1548
1549 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1550 bool isExact = false) {
1551 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1552 }
1553
1555 bool isExact = false) {
1556 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1557 }
1558
1559 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1560 bool isExact = false) {
1561 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1562 return V;
1563 if (!isExact)
1564 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1565 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1566 }
1567
1568 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1569 bool isExact = false) {
1570 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1571 }
1572
1574 bool isExact = false) {
1575 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1576 }
1577
1578 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1579 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1580 return V;
1581 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1582 }
1583
1584 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1585 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1586 }
1587
1588 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1589 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1590 }
1591
1593 assert(!Ops.empty());
1594 Value *Accum = Ops[0];
1595 for (unsigned i = 1; i < Ops.size(); i++)
1596 Accum = CreateAnd(Accum, Ops[i]);
1597 return Accum;
1598 }
1599
1600 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "",
1601 bool IsDisjoint = false) {
1602 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1603 return V;
1604 return Insert(
1605 IsDisjoint ? BinaryOperator::CreateDisjoint(Instruction::Or, LHS, RHS)
1606 : BinaryOperator::CreateOr(LHS, RHS),
1607 Name);
1608 }
1609
1610 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1611 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1612 }
1613
1614 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1615 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1616 }
1617
1619 assert(!Ops.empty());
1620 Value *Accum = Ops[0];
1621 for (unsigned i = 1; i < Ops.size(); i++)
1622 Accum = CreateOr(Accum, Ops[i]);
1623 return Accum;
1624 }
1625
1626 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1627 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1628 return V;
1629 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1630 }
1631
1632 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1633 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1634 }
1635
1636 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1637 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1638 }
1639
1640 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1641 MDNode *FPMD = nullptr) {
1642 return CreateFAddFMF(L, R, {}, Name, FPMD);
1643 }
1644
1646 const Twine &Name = "", MDNode *FPMD = nullptr) {
1647 if (IsFPConstrained)
1648 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1649 L, R, FMFSource, Name, FPMD);
1650
1651 if (Value *V =
1652 Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMFSource.get(FMF)))
1653 return V;
1654 Instruction *I =
1655 setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMFSource.get(FMF));
1656 return Insert(I, Name);
1657 }
1658
1659 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1660 MDNode *FPMD = nullptr) {
1661 return CreateFSubFMF(L, R, {}, Name, FPMD);
1662 }
1663
1665 const Twine &Name = "", MDNode *FPMD = nullptr) {
1666 if (IsFPConstrained)
1667 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1668 L, R, FMFSource, Name, FPMD);
1669
1670 if (Value *V =
1671 Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMFSource.get(FMF)))
1672 return V;
1673 Instruction *I =
1674 setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMFSource.get(FMF));
1675 return Insert(I, Name);
1676 }
1677
1678 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1679 MDNode *FPMD = nullptr) {
1680 return CreateFMulFMF(L, R, {}, Name, FPMD);
1681 }
1682
1684 const Twine &Name = "", MDNode *FPMD = nullptr) {
1685 if (IsFPConstrained)
1686 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1687 L, R, FMFSource, Name, FPMD);
1688
1689 if (Value *V =
1690 Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMFSource.get(FMF)))
1691 return V;
1692 Instruction *I =
1693 setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMFSource.get(FMF));
1694 return Insert(I, Name);
1695 }
1696
1697 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1698 MDNode *FPMD = nullptr) {
1699 return CreateFDivFMF(L, R, {}, Name, FPMD);
1700 }
1701
1703 const Twine &Name = "", MDNode *FPMD = nullptr) {
1704 if (IsFPConstrained)
1705 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1706 L, R, FMFSource, Name, FPMD);
1707
1708 if (Value *V =
1709 Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMFSource.get(FMF)))
1710 return V;
1711 Instruction *I =
1712 setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMFSource.get(FMF));
1713 return Insert(I, Name);
1714 }
1715
1716 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1717 MDNode *FPMD = nullptr) {
1718 return CreateFRemFMF(L, R, {}, Name, FPMD);
1719 }
1720
1722 const Twine &Name = "", MDNode *FPMD = nullptr) {
1723 if (IsFPConstrained)
1724 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1725 L, R, FMFSource, Name, FPMD);
1726
1727 if (Value *V =
1728 Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMFSource.get(FMF)))
1729 return V;
1730 Instruction *I =
1731 setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMFSource.get(FMF));
1732 return Insert(I, Name);
1733 }
1734
1736 Value *LHS, Value *RHS, const Twine &Name = "",
1737 MDNode *FPMathTag = nullptr) {
1738 return CreateBinOpFMF(Opc, LHS, RHS, {}, Name, FPMathTag);
1739 }
1740
1742 FMFSource FMFSource, const Twine &Name = "",
1743 MDNode *FPMathTag = nullptr) {
1744 if (Value *V = Folder.FoldBinOp(Opc, LHS, RHS))
1745 return V;
1747 if (isa<FPMathOperator>(BinOp))
1748 setFPAttrs(BinOp, FPMathTag, FMFSource.get(FMF));
1749 return Insert(BinOp, Name);
1750 }
1751
1752 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "",
1753 Instruction *MDFrom = nullptr) {
1754 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1755 return CreateSelect(Cond1, Cond2,
1756 ConstantInt::getNullValue(Cond2->getType()), Name,
1757 MDFrom);
1758 }
1759
1760 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
1761 Instruction *MDFrom = nullptr) {
1762 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1763 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1764 Cond2, Name, MDFrom);
1765 }
1766
1768 const Twine &Name = "",
1769 Instruction *MDFrom = nullptr) {
1770 switch (Opc) {
1771 case Instruction::And:
1772 return CreateLogicalAnd(Cond1, Cond2, Name, MDFrom);
1773 case Instruction::Or:
1774 return CreateLogicalOr(Cond1, Cond2, Name, MDFrom);
1775 default:
1776 break;
1777 }
1778 llvm_unreachable("Not a logical operation.");
1779 }
1780
1781 // NOTE: this is sequential, non-commutative, ordered reduction!
1783 assert(!Ops.empty());
1784 Value *Accum = Ops[0];
1785 for (unsigned i = 1; i < Ops.size(); i++)
1786 Accum = CreateLogicalOr(Accum, Ops[i]);
1787 return Accum;
1788 }
1789
1790 /// This function is like @ref CreateIntrinsic for constrained fp
1791 /// intrinsics. It sets the rounding mode and exception behavior of
1792 /// the created intrinsic call according to \p Rounding and \p
1793 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1794 /// defaults if a value equals nullopt/null.
1797 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1798 std::optional<RoundingMode> Rounding = std::nullopt,
1799 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1800
1803 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1804 std::optional<RoundingMode> Rounding = std::nullopt,
1805 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1806
1808 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1809 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1810 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1811
1812 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1813 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1814 /*HasNUW=*/0, HasNSW);
1815 }
1816
1817 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1818 return CreateNeg(V, Name, /*HasNSW=*/true);
1819 }
1820
1821 Value *CreateFNeg(Value *V, const Twine &Name = "",
1822 MDNode *FPMathTag = nullptr) {
1823 return CreateFNegFMF(V, {}, Name, FPMathTag);
1824 }
1825
1827 MDNode *FPMathTag = nullptr) {
1828 if (Value *Res =
1829 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1830 return Res;
1831 return Insert(
1832 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1833 Name);
1834 }
1835
1836 Value *CreateNot(Value *V, const Twine &Name = "") {
1837 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1838 }
1839
1841 Value *V, const Twine &Name = "",
1842 MDNode *FPMathTag = nullptr) {
1843 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1844 return Res;
1846 if (isa<FPMathOperator>(UnOp))
1847 setFPAttrs(UnOp, FPMathTag, FMF);
1848 return Insert(UnOp, Name);
1849 }
1850
1851 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1852 /// Correct number of operands must be passed accordingly.
1854 const Twine &Name = "",
1855 MDNode *FPMathTag = nullptr);
1856
1857 //===--------------------------------------------------------------------===//
1858 // Instruction creation methods: Memory Instructions
1859 //===--------------------------------------------------------------------===//
1860
1861 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1862 Value *ArraySize = nullptr, const Twine &Name = "") {
1863 const DataLayout &DL = BB->getDataLayout();
1864 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1865 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1866 }
1867
1868 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1869 const Twine &Name = "") {
1870 const DataLayout &DL = BB->getDataLayout();
1871 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1872 unsigned AddrSpace = DL.getAllocaAddrSpace();
1873 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1874 }
1875
1876 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1877 /// converting the string to 'bool' for the isVolatile parameter.
1878 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1879 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1880 }
1881
1882 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1883 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1884 }
1885
1886 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1887 const Twine &Name = "") {
1888 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1889 }
1890
1891 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1892 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1893 }
1894
1896 const char *Name) {
1897 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1898 }
1899
1901 const Twine &Name = "") {
1902 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1903 }
1904
1906 bool isVolatile, const Twine &Name = "") {
1907 if (!Align) {
1908 const DataLayout &DL = BB->getDataLayout();
1909 Align = DL.getABITypeAlign(Ty);
1910 }
1911 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1912 }
1913
1915 bool isVolatile = false) {
1916 if (!Align) {
1917 const DataLayout &DL = BB->getDataLayout();
1918 Align = DL.getABITypeAlign(Val->getType());
1919 }
1920 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1921 }
1924 const Twine &Name = "") {
1925 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1926 }
1927
1930 AtomicOrdering SuccessOrdering,
1931 AtomicOrdering FailureOrdering,
1933 if (!Align) {
1934 const DataLayout &DL = BB->getDataLayout();
1935 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1936 }
1937
1938 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1939 FailureOrdering, SSID));
1940 }
1941
1943 Value *Val, MaybeAlign Align,
1944 AtomicOrdering Ordering,
1946 if (!Align) {
1947 const DataLayout &DL = BB->getDataLayout();
1948 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1949 }
1950
1951 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1952 }
1953
1955 ArrayRef<Value *> Indices,
1956 const Twine &Name = "") {
1958 Args.push_back(PtrBase);
1959 llvm::append_range(Args, Indices);
1960
1961 CallInst *Output = CreateIntrinsic(Intrinsic::structured_gep,
1962 {PtrBase->getType()}, Args, {}, Name);
1963 Output->addParamAttr(
1964 0, Attribute::get(getContext(), Attribute::ElementType, BaseType));
1965 return Output;
1966 }
1967
1969 const Twine &Name = "",
1971 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, NW))
1972 return V;
1973 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList, NW), Name);
1974 }
1975
1977 const Twine &Name = "") {
1978 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
1979 }
1980
1981 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1982 const Twine &Name = "") {
1983 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1984 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
1985 }
1986
1987 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1988 const Twine &Name = "") {
1989 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1990 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
1991 }
1992
1993 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1994 const Twine &Name = "",
1996 Value *Idxs[] = {
1997 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1998 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1999 };
2000 return CreateGEP(Ty, Ptr, Idxs, Name, NWFlags);
2001 }
2002
2003 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
2004 unsigned Idx1, const Twine &Name = "") {
2005 Value *Idxs[] = {
2006 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
2007 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
2008 };
2009 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2010 }
2011
2013 const Twine &Name = "") {
2014 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2015 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
2016 }
2017
2019 const Twine &Name = "") {
2020 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2021 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
2022 }
2023
2025 const Twine &Name = "") {
2026 Value *Idxs[] = {
2027 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2028 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2029 };
2030 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::none());
2031 }
2032
2034 uint64_t Idx1, const Twine &Name = "") {
2035 Value *Idxs[] = {
2036 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2037 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2038 };
2039 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2040 }
2041
2042 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2043 const Twine &Name = "") {
2044 GEPNoWrapFlags NWFlags =
2046 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2047 }
2048
2049 Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
2051 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
2052 }
2053
2055 const Twine &Name = "") {
2056 return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
2058 }
2059
2060 //===--------------------------------------------------------------------===//
2061 // Instruction creation methods: Cast/Conversion Operators
2062 //===--------------------------------------------------------------------===//
2063
2064 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2065 bool IsNUW = false, bool IsNSW = false) {
2066 if (V->getType() == DestTy)
2067 return V;
2068 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2069 return Folded;
2070 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2071 if (IsNUW)
2072 I->setHasNoUnsignedWrap();
2073 if (IsNSW)
2074 I->setHasNoSignedWrap();
2075 return Insert(I, Name);
2076 }
2077
2078 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2079 bool IsNonNeg = false) {
2080 if (V->getType() == DestTy)
2081 return V;
2082 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2083 return Folded;
2084 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2085 if (IsNonNeg)
2086 I->setNonNeg();
2087 return I;
2088 }
2089
2090 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2091 return CreateCast(Instruction::SExt, V, DestTy, Name);
2092 }
2093
2094 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2095 /// the value untouched if the type of V is already DestTy.
2097 const Twine &Name = "") {
2098 assert(V->getType()->isIntOrIntVectorTy() &&
2099 DestTy->isIntOrIntVectorTy() &&
2100 "Can only zero extend/truncate integers!");
2101 Type *VTy = V->getType();
2102 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2103 return CreateZExt(V, DestTy, Name);
2104 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2105 return CreateTrunc(V, DestTy, Name);
2106 return V;
2107 }
2108
2109 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2110 /// the value untouched if the type of V is already DestTy.
2112 const Twine &Name = "") {
2113 assert(V->getType()->isIntOrIntVectorTy() &&
2114 DestTy->isIntOrIntVectorTy() &&
2115 "Can only sign extend/truncate integers!");
2116 Type *VTy = V->getType();
2117 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2118 return CreateSExt(V, DestTy, Name);
2119 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2120 return CreateTrunc(V, DestTy, Name);
2121 return V;
2122 }
2123
2124 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2125 if (IsFPConstrained)
2126 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2127 V, DestTy, nullptr, Name);
2128 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2129 }
2130
2131 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2132 if (IsFPConstrained)
2133 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2134 V, DestTy, nullptr, Name);
2135 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2136 }
2137
2138 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2139 bool IsNonNeg = false) {
2140 if (IsFPConstrained)
2141 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2142 V, DestTy, nullptr, Name);
2143 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2144 return Folded;
2145 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2146 if (IsNonNeg)
2147 I->setNonNeg();
2148 return I;
2149 }
2150
2151 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2152 if (IsFPConstrained)
2153 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2154 V, DestTy, nullptr, Name);
2155 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2156 }
2157
2158 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2159 MDNode *FPMathTag = nullptr) {
2160 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2161 }
2162
2164 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2165 if (IsFPConstrained)
2167 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2168 Name, FPMathTag);
2169 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2170 FMFSource);
2171 }
2172
2173 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2174 MDNode *FPMathTag = nullptr) {
2175 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2176 }
2177
2179 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2180 if (IsFPConstrained)
2181 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2182 V, DestTy, FMFSource, Name, FPMathTag);
2183 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2184 FMFSource);
2185 }
2186 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2187 return CreateCast(Instruction::PtrToAddr, V,
2188 BB->getDataLayout().getAddressType(V->getType()), Name);
2189 }
2191 const Twine &Name = "") {
2192 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2193 }
2194
2196 const Twine &Name = "") {
2197 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2198 }
2199
2201 const Twine &Name = "") {
2202 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2203 }
2204
2206 const Twine &Name = "") {
2207 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2208 }
2209
2210 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2211 Instruction::CastOps CastOp =
2212 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2213 ? Instruction::BitCast
2214 : Instruction::ZExt;
2215 return CreateCast(CastOp, V, DestTy, Name);
2216 }
2217
2218 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2219 Instruction::CastOps CastOp =
2220 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2221 ? Instruction::BitCast
2222 : Instruction::SExt;
2223 return CreateCast(CastOp, V, DestTy, Name);
2224 }
2225
2226 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2227 Instruction::CastOps CastOp =
2228 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2229 ? Instruction::BitCast
2230 : Instruction::Trunc;
2231 return CreateCast(CastOp, V, DestTy, Name);
2232 }
2233
2235 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2236 FMFSource FMFSource = {}) {
2237 if (V->getType() == DestTy)
2238 return V;
2239 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2240 return Folded;
2241 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2242 if (isa<FPMathOperator>(Cast))
2243 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2244 return Insert(Cast, Name);
2245 }
2246
2248 const Twine &Name = "") {
2249 if (V->getType() == DestTy)
2250 return V;
2251 if (auto *VC = dyn_cast<Constant>(V))
2252 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2253 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2254 }
2255
2256 // With opaque pointers enabled, this can be substituted with
2257 // CreateAddrSpaceCast.
2258 // TODO: Replace uses of this method and remove the method itself.
2260 const Twine &Name = "") {
2261 if (V->getType() == DestTy)
2262 return V;
2263
2264 if (auto *VC = dyn_cast<Constant>(V)) {
2265 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2266 Name);
2267 }
2268
2270 Name);
2271 }
2272
2273 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
2274 const Twine &Name = "") {
2275 Instruction::CastOps CastOp =
2276 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2277 ? Instruction::Trunc
2278 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2279 return CreateCast(CastOp, V, DestTy, Name);
2280 }
2281
2283 const Twine &Name = "") {
2284 if (V->getType() == DestTy)
2285 return V;
2286 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2287 return CreatePtrToInt(V, DestTy, Name);
2288 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2289 return CreateIntToPtr(V, DestTy, Name);
2290
2291 return CreateBitCast(V, DestTy, Name);
2292 }
2293
2294 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2295 MDNode *FPMathTag = nullptr) {
2296 Instruction::CastOps CastOp =
2297 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2298 ? Instruction::FPTrunc
2299 : Instruction::FPExt;
2300 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2301 }
2302
2304 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2305 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2306 std::optional<RoundingMode> Rounding = std::nullopt,
2307 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2308
2309 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2310 // compile time error, instead of converting the string to bool for the
2311 // isSigned parameter.
2312 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2313
2314 /// Cast between aggregate types that must have identical structure but may
2315 /// differ in their leaf types. The leaf values are recursively extracted,
2316 /// casted, and then reinserted into a value of type DestTy. The leaf types
2317 /// must be castable using a bitcast or ptrcast, because signedness is
2318 /// not specified.
2320
2321 /// Create a chain of casts to convert V to NewTy, preserving the bit pattern
2322 /// of V. This may involve multiple casts (e.g., ptr -> i64 -> <2 x i32>).
2323 /// The created cast instructions are inserted into the current basic block.
2324 /// If no casts are needed, V is returned.
2326 Type *NewTy);
2327
2328 //===--------------------------------------------------------------------===//
2329 // Instruction creation methods: Compare Instructions
2330 //===--------------------------------------------------------------------===//
2331
2332 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2333 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2334 }
2335
2336 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2337 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2338 }
2339
2340 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2341 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2342 }
2343
2344 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2345 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2346 }
2347
2348 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2349 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2350 }
2351
2352 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2353 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2354 }
2355
2356 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2357 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2358 }
2359
2360 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2361 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2362 }
2363
2364 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2365 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2366 }
2367
2368 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2369 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2370 }
2371
2372 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2373 MDNode *FPMathTag = nullptr) {
2374 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2375 }
2376
2377 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2378 MDNode *FPMathTag = nullptr) {
2379 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2380 }
2381
2382 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2383 MDNode *FPMathTag = nullptr) {
2384 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2385 }
2386
2387 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2388 MDNode *FPMathTag = nullptr) {
2389 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2390 }
2391
2392 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2393 MDNode *FPMathTag = nullptr) {
2394 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2395 }
2396
2397 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2398 MDNode *FPMathTag = nullptr) {
2399 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2400 }
2401
2402 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2403 MDNode *FPMathTag = nullptr) {
2404 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2405 }
2406
2407 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2408 MDNode *FPMathTag = nullptr) {
2409 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2410 }
2411
2412 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2413 MDNode *FPMathTag = nullptr) {
2414 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2415 }
2416
2417 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2418 MDNode *FPMathTag = nullptr) {
2419 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2420 }
2421
2422 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2423 MDNode *FPMathTag = nullptr) {
2424 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2425 }
2426
2427 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2428 MDNode *FPMathTag = nullptr) {
2429 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2430 }
2431
2432 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2433 MDNode *FPMathTag = nullptr) {
2434 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2435 }
2436
2437 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2438 MDNode *FPMathTag = nullptr) {
2439 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2440 }
2441
2443 const Twine &Name = "") {
2444 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2445 return V;
2446 return Insert(new ICmpInst(P, LHS, RHS), Name);
2447 }
2448
2449 // Create a quiet floating-point comparison (i.e. one that raises an FP
2450 // exception only in the case where an input is a signaling NaN).
2451 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2453 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2454 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2455 }
2456
2457 // Create a quiet floating-point comparison (i.e. one that raises an FP
2458 // exception only in the case where an input is a signaling NaN).
2459 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2461 FMFSource FMFSource, const Twine &Name = "",
2462 MDNode *FPMathTag = nullptr) {
2463 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2464 }
2465
2467 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2468 return CmpInst::isFPPredicate(Pred)
2469 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2470 : CreateICmp(Pred, LHS, RHS, Name);
2471 }
2472
2473 // Create a signaling floating-point comparison (i.e. one that raises an FP
2474 // exception whenever an input is any NaN, signaling or quiet).
2475 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2477 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2478 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2479 }
2480
2481private:
2482 // Helper routine to create either a signaling or a quiet FP comparison.
2483 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2484 const Twine &Name, MDNode *FPMathTag,
2485 FMFSource FMFSource, bool IsSignaling);
2486
2487public:
2490 const Twine &Name = "",
2491 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2492
2493 //===--------------------------------------------------------------------===//
2494 // Instruction creation methods: Other Instructions
2495 //===--------------------------------------------------------------------===//
2496
2497 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2498 const Twine &Name = "") {
2499 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2500 if (isa<FPMathOperator>(Phi))
2501 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2502 return Insert(Phi, Name);
2503 }
2504
2505private:
2506 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2507 const Twine &Name = "", FMFSource FMFSource = {},
2508 ArrayRef<OperandBundleDef> OpBundles = {});
2509
2510public:
2512 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2513 MDNode *FPMathTag = nullptr) {
2514 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2515 if (IsFPConstrained)
2517 if (isa<FPMathOperator>(CI))
2518 setFPAttrs(CI, FPMathTag, FMF);
2519 return Insert(CI, Name);
2520 }
2521
2524 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2525 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2526 if (IsFPConstrained)
2528 if (isa<FPMathOperator>(CI))
2529 setFPAttrs(CI, FPMathTag, FMF);
2530 return Insert(CI, Name);
2531 }
2532
2534 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2535 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2536 FPMathTag);
2537 }
2538
2541 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2542 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2543 OpBundles, Name, FPMathTag);
2544 }
2545
2547 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2548 std::optional<RoundingMode> Rounding = std::nullopt,
2549 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2550
2552 Value *False,
2554 const Twine &Name = "");
2555
2557 Value *False,
2560 const Twine &Name = "");
2561
2562 LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
2563 const Twine &Name = "",
2564 Instruction *MDFrom = nullptr);
2565 LLVM_ABI Value *CreateSelectFMF(Value *C, Value *True, Value *False,
2566 FMFSource FMFSource, const Twine &Name = "",
2567 Instruction *MDFrom = nullptr);
2568
2569 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2570 return Insert(new VAArgInst(List, Ty), Name);
2571 }
2572
2574 const Twine &Name = "") {
2575 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2576 return V;
2577 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2578 }
2579
2581 const Twine &Name = "") {
2582 return CreateExtractElement(Vec, getInt64(Idx), Name);
2583 }
2584
2585 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2586 const Twine &Name = "") {
2587 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2588 }
2589
2591 const Twine &Name = "") {
2592 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2593 }
2594
2596 const Twine &Name = "") {
2597 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2598 return V;
2599 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2600 }
2601
2603 const Twine &Name = "") {
2604 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2605 }
2606
2608 const Twine &Name = "") {
2609 SmallVector<int, 16> IntMask;
2611 return CreateShuffleVector(V1, V2, IntMask, Name);
2612 }
2613
2614 /// See class ShuffleVectorInst for a description of the mask representation.
2616 const Twine &Name = "") {
2617 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2618 return V;
2619 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2620 }
2621
2622 /// Create a unary shuffle. The second vector operand of the IR instruction
2623 /// is poison.
2625 const Twine &Name = "") {
2626 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2627 }
2628
2630 const Twine &Name = "");
2631
2633 const Twine &Name = "") {
2634 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2635 return V;
2636 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2637 }
2638
2640 const Twine &Name = "") {
2641 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2642 return V;
2643 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2644 }
2645
2646 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2647 const Twine &Name = "") {
2648 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2649 }
2650
2651 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2652 return Insert(new FreezeInst(V), Name);
2653 }
2654
2655 //===--------------------------------------------------------------------===//
2656 // Utility creation methods
2657 //===--------------------------------------------------------------------===//
2658
2659 /// Return a boolean value testing if \p Arg == 0.
2660 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2661 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2662 }
2663
2664 /// Return a boolean value testing if \p Arg != 0.
2665 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2666 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2667 }
2668
2669 /// Return a boolean value testing if \p Arg < 0.
2670 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2671 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2672 }
2673
2674 /// Return a boolean value testing if \p Arg > -1.
2675 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2677 Name);
2678 }
2679
2680 /// Return the difference between two pointer values. The returned value
2681 /// type is the address type of the pointers.
2682 LLVM_ABI Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "",
2683 bool IsNUW = false);
2684
2685 /// Return the difference between two pointer values, dividing out the size
2686 /// of the pointed-to objects. The returned value type is the address type
2687 /// of the pointers.
2688 ///
2689 /// This is intended to implement C-style pointer subtraction. As such, the
2690 /// pointers must be appropriately aligned for their element types and
2691 /// pointing into the same object.
2693 const Twine &Name = "");
2694
2695 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2696 /// different from pointer to i8, it's casted to pointer to i8 in the same
2697 /// address space before call and casted back to Ptr type after call.
2699
2700 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2701 /// different from pointer to i8, it's casted to pointer to i8 in the same
2702 /// address space before call and casted back to Ptr type after call.
2704
2705 /// Return a vector value that contains the vector V reversed
2706 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2707
2708 /// Create a vector.splice.left intrinsic call, or a shufflevector that
2709 /// produces the same result if the result type is a fixed-length vector and
2710 /// \p Offset is a constant.
2712 const Twine &Name = "");
2713
2715 const Twine &Name = "") {
2716 return CreateVectorSpliceLeft(V1, V2, getInt32(Offset), Name);
2717 }
2718
2719 /// Create a vector.splice.right intrinsic call, or a shufflevector that
2720 /// produces the same result if the result type is a fixed-length vector and
2721 /// \p Offset is a constant.
2723 const Twine &Name = "");
2724
2726 const Twine &Name = "") {
2727 return CreateVectorSpliceRight(V1, V2, getInt32(Offset), Name);
2728 }
2729
2730 /// Return a vector value that contains \arg V broadcasted to \p
2731 /// NumElts elements.
2732 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2733 const Twine &Name = "");
2734
2735 /// Return a vector value that contains \arg V broadcasted to \p
2736 /// EC elements.
2738 const Twine &Name = "");
2739
2741 unsigned Dimension,
2742 unsigned LastIndex,
2743 MDNode *DbgInfo);
2744
2746 unsigned FieldIndex,
2747 MDNode *DbgInfo);
2748
2750 unsigned Index,
2751 unsigned FieldIndex,
2752 MDNode *DbgInfo);
2753
2754 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2755
2756private:
2757 /// Helper function that creates an assume intrinsic call that
2758 /// represents an alignment assumption on the provided pointer \p PtrValue
2759 /// with offset \p OffsetValue and alignment value \p AlignValue.
2760 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2761 Value *PtrValue, Value *AlignValue,
2762 Value *OffsetValue);
2763
2764public:
2765 /// Create an assume intrinsic call that represents an alignment
2766 /// assumption on the provided pointer.
2767 ///
2768 /// An optional offset can be provided, and if it is provided, the offset
2769 /// must be subtracted from the provided pointer to get the pointer with the
2770 /// specified alignment.
2772 Value *PtrValue,
2773 unsigned Alignment,
2774 Value *OffsetValue = nullptr);
2775
2776 /// Create an assume intrinsic call that represents an alignment
2777 /// assumption on the provided pointer.
2778 ///
2779 /// An optional offset can be provided, and if it is provided, the offset
2780 /// must be subtracted from the provided pointer to get the pointer with the
2781 /// specified alignment.
2782 ///
2783 /// This overload handles the condition where the Alignment is dependent
2784 /// on an existing value rather than a static value.
2786 Value *PtrValue,
2787 Value *Alignment,
2788 Value *OffsetValue = nullptr);
2789
2790 /// Create an assume intrinsic call that represents an dereferencable
2791 /// assumption on the provided pointer.
2793 Value *SizeValue);
2794};
2795
2796/// This provides a uniform API for creating instructions and inserting
2797/// them into a basic block: either at the end of a BasicBlock, or at a specific
2798/// iterator location in a block.
2799///
2800/// Note that the builder does not expose the full generality of LLVM
2801/// instructions. For access to extra instruction properties, use the mutators
2802/// (e.g. setVolatile) on the instructions after they have been
2803/// created. Convenience state exists to specify fast-math flags and fp-math
2804/// tags.
2805///
2806/// The first template argument specifies a class to use for creating constants.
2807/// This defaults to creating minimally folded constants. The second template
2808/// argument allows clients to specify custom insertion hooks that are called on
2809/// every newly created insertion.
2810template <typename FolderTy = ConstantFolder,
2811 typename InserterTy = IRBuilderDefaultInserter>
2812class IRBuilder : public IRBuilderBase {
2813private:
2814 FolderTy Folder;
2815 InserterTy Inserter;
2816
2817public:
2818 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter,
2819 MDNode *FPMathTag = nullptr,
2820 ArrayRef<OperandBundleDef> OpBundles = {})
2821 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2823
2824 IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag = nullptr,
2825 ArrayRef<OperandBundleDef> OpBundles = {})
2826 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2827 Folder(Folder) {}
2828
2829 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2830 ArrayRef<OperandBundleDef> OpBundles = {})
2831 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2832
2833 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2834 MDNode *FPMathTag = nullptr,
2835 ArrayRef<OperandBundleDef> OpBundles = {})
2836 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2837 FPMathTag, OpBundles),
2838 Folder(Folder) {
2839 SetInsertPoint(TheBB);
2840 }
2841
2842 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2843 ArrayRef<OperandBundleDef> OpBundles = {})
2844 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2845 FPMathTag, OpBundles) {
2846 SetInsertPoint(TheBB);
2847 }
2848
2849 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2850 ArrayRef<OperandBundleDef> OpBundles = {})
2851 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2852 OpBundles) {
2853 SetInsertPoint(IP);
2854 }
2855
2856 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2857 MDNode *FPMathTag = nullptr,
2858 ArrayRef<OperandBundleDef> OpBundles = {})
2859 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2860 FPMathTag, OpBundles),
2861 Folder(Folder) {
2862 SetInsertPoint(TheBB, IP);
2863 }
2864
2866 MDNode *FPMathTag = nullptr,
2867 ArrayRef<OperandBundleDef> OpBundles = {})
2868 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2869 FPMathTag, OpBundles) {
2870 SetInsertPoint(TheBB, IP);
2871 }
2872
2873 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2874 /// or FastMathFlagGuard instead.
2875 IRBuilder(const IRBuilder &) = delete;
2876
2877 InserterTy &getInserter() { return Inserter; }
2878 const InserterTy &getInserter() const { return Inserter; }
2879};
2880
2881template <typename FolderTy, typename InserterTy>
2882IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2885template <typename FolderTy>
2890template <typename FolderTy>
2895
2896
2897// Create wrappers for C Binding types (see CBindingWrapping.h).
2899
2900} // end namespace llvm
2901
2902#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:474
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:1503
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2210
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2397
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
Definition IRBuilder.h:1093
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:2476
BasicBlock * BB
Definition IRBuilder.h:146
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1477
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1356
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:1664
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:2348
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2163
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2012
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:1121
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:2422
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2590
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1513
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition IRBuilder.h:1900
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1659
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2452
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition IRBuilder.h:1351
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:2585
void SetNoSanitizeMetadata()
Set nosanitize metadata.
Definition IRBuilder.h:254
Value * CreateVectorSpliceLeft(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2714
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1554
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1929
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:1981
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1861
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition IRBuilder.h:399
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition IRBuilder.h:1149
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1284
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:2639
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1592
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:1257
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1584
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:2539
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:1697
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:1135
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1549
void clearFastMathFlags()
Clear the fast-math flags.
Definition IRBuilder.h:339
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2151
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:1886
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1782
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2573
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:2356
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:1895
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2402
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:2096
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:1224
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1640
UnreachableInst * CreateUnreachable()
Definition IRBuilder.h:1366
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:2158
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:2247
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:2186
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:1716
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2632
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1588
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:2646
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2178
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1069
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:2360
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:1262
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:2124
Value * CreateVectorSpliceRight(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2725
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2024
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2437
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:202
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2042
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1922
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:1326
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:2090
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2218
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2417
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2195
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:2651
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:1210
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Create a callbr instruction.
Definition IRBuilder.h:1300
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:1540
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:1987
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:1034
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:2049
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2234
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2675
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition IRBuilder.h:1362
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition IRBuilder.h:1339
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2138
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition IRBuilder.h:1200
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1439
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:1573
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:2387
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:1976
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1473
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:1610
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:2259
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:2624
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:1568
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1481
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2432
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:2336
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1443
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:2460
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:1968
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:1344
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:1840
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1812
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1882
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:1218
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
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
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:1752
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:2602
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1534
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:2615
LLVM_ABI Value * createIsFPClass(Value *FPNum, unsigned Test)
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2392
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:1052
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2282
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2466
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1767
const IRBuilderDefaultInserter & Inserter
Definition IRBuilder.h:150
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2294
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2368
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2497
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2522
CondBrInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition IRBuilder.h:1233
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1836
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:1247
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2332
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:1741
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2412
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:1064
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:1162
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition IRBuilder.h:2670
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:1447
Value * CreateFMA(Value *Factor1, Value *Factor2, Value *Summand, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fma intrinsic.
Definition IRBuilder.h:1101
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2200
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:1086
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:2340
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:1878
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:1519
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:2078
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:2607
LLVMContext & getContext() const
Definition IRBuilder.h:203
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2372
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1578
FastMathFlags & getFastMathFlags()
Definition IRBuilder.h:336
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition IRBuilder.h:1195
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:1080
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1456
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition IRBuilder.h:2003
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2033
Value * CreateMinNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the minnum intrinsic.
Definition IRBuilder.h:1040
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1292
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1129
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1891
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:1430
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2190
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1494
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:2569
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1490
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:2665
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:2511
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1528
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1942
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:2064
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:1735
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2595
CallInst * CreateStructuredGEP(Type *BaseType, Value *PtrBase, ArrayRef< Value * > Indices, const Twine &Name="")
Definition IRBuilder.h:1954
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2018
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:1319
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:2364
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:1308
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:2344
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:2273
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2407
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:2660
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:2377
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:1156
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:1273
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:1143
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:1618
Value * CreateFAddFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1645
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1760
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1868
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:1993
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2580
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1914
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1614
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:1074
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:2054
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2173
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:1559
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2533
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1826
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1626
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:2226
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2352
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2442
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:1678
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1905
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1821
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:1600
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:1702
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1507
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:2111
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1335
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2205
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:1683
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1632
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:1464
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:1721
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1636
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:1817
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:2382
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:1460
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2427
CallInst * CreateArithmeticFence(Value *Val, Type *DstType, const Twine &Name="")
Create a call to the arithmetic_fence intrinsic.
Definition IRBuilder.h:1114
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2131
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:2812
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2829
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2824
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2818
InserterTy & getInserter()
Definition IRBuilder.h:2877
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2849
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2833
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2856
const InserterTy & getInserter() const
Definition IRBuilder.h:2878
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2865
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2842
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:255
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.
@ 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 value is 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