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 or truncated from
532 /// a 64-bit value.
534 return ConstantInt::get(getIntNTy(N), C);
535 }
536
537 /// Get a constant integer value.
539 return ConstantInt::get(Context, AI);
540 }
541
542 //===--------------------------------------------------------------------===//
543 // Type creation methods
544 //===--------------------------------------------------------------------===//
545
546 /// Fetch the type representing a single bit
550
551 /// Fetch the type representing an 8-bit integer.
555
556 /// Fetch the type representing a 16-bit integer.
560
561 /// Fetch the type representing a 32-bit integer.
565
566 /// Fetch the type representing a 64-bit integer.
570
571 /// Fetch the type representing a 128-bit integer.
573
574 /// Fetch the type representing an N-bit integer.
576 return Type::getIntNTy(Context, N);
577 }
578
579 /// Fetch the type representing a 16-bit floating point value.
581 return Type::getHalfTy(Context);
582 }
583
584 /// Fetch the type representing a 16-bit brain floating point value.
587 }
588
589 /// Fetch the type representing a 32-bit floating point value.
592 }
593
594 /// Fetch the type representing a 64-bit floating point value.
597 }
598
599 /// Fetch the type representing void.
601 return Type::getVoidTy(Context);
602 }
603
604 /// Fetch the type representing a pointer.
605 PointerType *getPtrTy(unsigned AddrSpace = 0) {
606 return PointerType::get(Context, AddrSpace);
607 }
608
609 /// Fetch the type of an integer with size at least as big as that of a
610 /// pointer in the given address space.
611 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
612 return DL.getIntPtrType(Context, AddrSpace);
613 }
614
615 /// Fetch the type of an integer that should be used to index GEP operations
616 /// within AddressSpace.
617 IntegerType *getIndexTy(const DataLayout &DL, unsigned AddrSpace) {
618 return DL.getIndexType(Context, AddrSpace);
619 }
620
621 //===--------------------------------------------------------------------===//
622 // Intrinsic creation methods
623 //===--------------------------------------------------------------------===//
624
625 /// Create and insert a memset to the specified pointer and the
626 /// specified value.
627 ///
628 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
629 /// specified, it will be added to the instruction.
631 MaybeAlign Align, bool isVolatile = false,
632 const AAMDNodes &AAInfo = AAMDNodes()) {
633 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
634 }
635
637 MaybeAlign Align, bool isVolatile = false,
638 const AAMDNodes &AAInfo = AAMDNodes());
639
641 Value *Val, Value *Size,
642 bool IsVolatile = false,
643 const AAMDNodes &AAInfo = AAMDNodes());
644
645 /// Create and insert an element unordered-atomic memset of the region of
646 /// memory starting at the given pointer to the given value.
647 ///
648 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
649 /// specified, it will be added to the instruction.
650 CallInst *
652 Align Alignment, uint32_t ElementSize,
653 const AAMDNodes &AAInfo = AAMDNodes()) {
655 Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
656 }
657
658 LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy,
659 Value *AllocSize, Value *ArraySize,
661 Function *MallocF = nullptr,
662 const Twine &Name = "");
663
664 /// CreateMalloc - Generate the IR for a call to malloc:
665 /// 1. Compute the malloc call's argument as the specified type's size,
666 /// possibly multiplied by the array size if the array size is not
667 /// constant 1.
668 /// 2. Call malloc with that argument.
669 LLVM_ABI CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy,
670 Value *AllocSize, Value *ArraySize,
671 Function *MallocF = nullptr,
672 const Twine &Name = "");
673 /// Generate the IR for a call to the builtin free function.
675 ArrayRef<OperandBundleDef> Bundles = {});
676
677 LLVM_ABI CallInst *
678 CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
679 Align Alignment, uint32_t ElementSize,
680 const AAMDNodes &AAInfo = AAMDNodes());
681
682 /// Create and insert a memcpy between the specified pointers.
683 ///
684 /// If the pointers aren't i8*, they will be converted. If alias metadata is
685 /// specified, it will be added to the instruction.
686 /// and noalias tags.
688 MaybeAlign SrcAlign, uint64_t Size,
689 bool isVolatile = false,
690 const AAMDNodes &AAInfo = AAMDNodes()) {
691 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
692 isVolatile, AAInfo);
693 }
694
697 Value *Src, MaybeAlign SrcAlign, Value *Size,
698 bool isVolatile = false,
699 const AAMDNodes &AAInfo = AAMDNodes());
700
702 MaybeAlign SrcAlign, Value *Size,
703 bool isVolatile = false,
704 const AAMDNodes &AAInfo = AAMDNodes()) {
705 return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
706 SrcAlign, Size, isVolatile, AAInfo);
707 }
708
710 MaybeAlign SrcAlign, Value *Size,
711 bool isVolatile = false,
712 const AAMDNodes &AAInfo = AAMDNodes()) {
713 return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
714 SrcAlign, Size, isVolatile, AAInfo);
715 }
716
717 /// Create and insert an element unordered-atomic memcpy between the
718 /// specified pointers.
719 ///
720 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
721 /// respectively.
722 ///
723 /// If the pointers aren't i8*, they will be converted. If alias metadata is
724 /// specified, it will be added to the instruction.
726 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
727 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
728
730 MaybeAlign SrcAlign, uint64_t Size,
731 bool isVolatile = false,
732 const AAMDNodes &AAInfo = AAMDNodes()) {
733 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
734 isVolatile, AAInfo);
735 }
736
738 MaybeAlign SrcAlign, Value *Size,
739 bool isVolatile = false,
740 const AAMDNodes &AAInfo = AAMDNodes()) {
741 return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
742 SrcAlign, Size, isVolatile, AAInfo);
743 }
744
745 /// \brief Create and insert an element unordered-atomic memmove between the
746 /// specified pointers.
747 ///
748 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
749 /// respectively.
750 ///
751 /// If the pointers aren't i8*, they will be converted. If alias metadata is
752 /// specified, it will be added to the instruction.
754 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
755 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
756
757private:
758 CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
759
760public:
761 /// Create a sequential vector fadd reduction intrinsic of the source vector.
762 /// The first parameter is a scalar accumulator value. An unordered reduction
763 /// can be created by adding the reassoc fast-math flag to the resulting
764 /// sequential reduction.
766
767 /// Create a sequential vector fmul reduction intrinsic of the source vector.
768 /// The first parameter is a scalar accumulator value. An unordered reduction
769 /// can be created by adding the reassoc fast-math flag to the resulting
770 /// sequential reduction.
772
773 /// Create a vector int add reduction intrinsic of the source vector.
775
776 /// Create a vector int mul reduction intrinsic of the source vector.
778
779 /// Create a vector int AND reduction intrinsic of the source vector.
781
782 /// Create a vector int OR reduction intrinsic of the source vector.
784
785 /// Create a vector int XOR reduction intrinsic of the source vector.
787
788 /// Create a vector integer max reduction intrinsic of the source
789 /// vector.
790 LLVM_ABI CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
791
792 /// Create a vector integer min reduction intrinsic of the source
793 /// vector.
794 LLVM_ABI CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
795
796 /// Create a vector float max reduction intrinsic of the source
797 /// vector.
799
800 /// Create a vector float min reduction intrinsic of the source
801 /// vector.
803
804 /// Create a vector float maximum reduction intrinsic of the source
805 /// vector. This variant follows the NaN and signed zero semantic of
806 /// llvm.maximum intrinsic.
808
809 /// Create a vector float minimum reduction intrinsic of the source
810 /// vector. This variant follows the NaN and signed zero semantic of
811 /// llvm.minimum intrinsic.
813
814 /// Create a lifetime.start intrinsic.
816
817 /// Create a lifetime.end intrinsic.
819
820 /// Create a call to invariant.start intrinsic.
821 ///
822 /// If the pointer isn't i8* it will be converted.
824 ConstantInt *Size = nullptr);
825
826 /// Create a call to llvm.threadlocal.address intrinsic.
828
829 /// Create a call to Masked Load intrinsic
830 LLVM_ABI CallInst *CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment,
831 Value *Mask, Value *PassThru = nullptr,
832 const Twine &Name = "");
833
834 /// Create a call to Masked Store intrinsic
835 LLVM_ABI CallInst *CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment,
836 Value *Mask);
837
838 /// Create a call to Masked Gather intrinsic
839 LLVM_ABI CallInst *CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment,
840 Value *Mask = nullptr,
841 Value *PassThru = nullptr,
842 const Twine &Name = "");
843
844 /// Create a call to Masked Scatter intrinsic
846 Align Alignment,
847 Value *Mask = nullptr);
848
849 /// Create a call to Masked Expand Load intrinsic
852 Value *Mask = nullptr,
853 Value *PassThru = nullptr,
854 const Twine &Name = "");
855
856 /// Create a call to Masked Compress Store intrinsic
859 Value *Mask = nullptr);
860
861 /// Return an all true boolean vector (mask) with \p NumElts lanes.
866
867 /// Create an assume intrinsic call that allows the optimizer to
868 /// assume that the provided condition will be true.
869 ///
870 /// The optional argument \p OpBundles specifies operand bundles that are
871 /// added to the call instruction.
874
875 /// Create a llvm.experimental.noalias.scope.decl intrinsic call.
876 LLVM_ABI Instruction *CreateNoAliasScopeDeclaration(Value *Scope);
881
882 /// Create a call to the experimental.gc.statepoint intrinsic to
883 /// start a new statepoint sequence.
885 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
886 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
887 ArrayRef<Value *> GCArgs, const Twine &Name = "");
888
889 /// Create a call to the experimental.gc.statepoint intrinsic to
890 /// start a new statepoint sequence.
893 FunctionCallee ActualCallee, uint32_t Flags,
894 ArrayRef<Value *> CallArgs,
895 std::optional<ArrayRef<Use>> TransitionArgs,
896 std::optional<ArrayRef<Use>> DeoptArgs,
897 ArrayRef<Value *> GCArgs, const Twine &Name = "");
898
899 /// Conveninence function for the common case when CallArgs are filled
900 /// in using ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
901 /// .get()'ed to get the Value pointer.
904 FunctionCallee ActualCallee, ArrayRef<Use> CallArgs,
905 std::optional<ArrayRef<Value *>> DeoptArgs,
906 ArrayRef<Value *> GCArgs, const Twine &Name = "");
907
908 /// Create an invoke to the experimental.gc.statepoint intrinsic to
909 /// start a new statepoint sequence.
912 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
913 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
914 std::optional<ArrayRef<Value *>> DeoptArgs,
915 ArrayRef<Value *> GCArgs, const Twine &Name = "");
916
917 /// Create an invoke to the experimental.gc.statepoint intrinsic to
918 /// start a new statepoint sequence.
920 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
921 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
922 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
923 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
924 const Twine &Name = "");
925
926 // Convenience function for the common case when CallArgs are filled in using
927 // ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
928 // get the Value *.
931 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
932 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
933 std::optional<ArrayRef<Value *>> DeoptArgs,
934 ArrayRef<Value *> GCArgs, const Twine &Name = "");
935
936 /// Create a call to the experimental.gc.result intrinsic to extract
937 /// the result from a call wrapped in a statepoint.
938 LLVM_ABI CallInst *CreateGCResult(Instruction *Statepoint, Type *ResultType,
939 const Twine &Name = "");
940
941 /// Create a call to the experimental.gc.relocate intrinsics to
942 /// project the relocated value of one pointer from the statepoint.
943 LLVM_ABI CallInst *CreateGCRelocate(Instruction *Statepoint, int BaseOffset,
944 int DerivedOffset, Type *ResultType,
945 const Twine &Name = "");
946
947 /// Create a call to the experimental.gc.pointer.base intrinsic to get the
948 /// base pointer for the specified derived pointer.
950 const Twine &Name = "");
951
952 /// Create a call to the experimental.gc.get.pointer.offset intrinsic to get
953 /// the offset of the specified derived pointer from its base.
955 const Twine &Name = "");
956
957 /// Create a call to llvm.vscale.<Ty>().
958 Value *CreateVScale(Type *Ty, const Twine &Name = "") {
959 return CreateIntrinsic(Intrinsic::vscale, {Ty}, {}, {}, Name);
960 }
961
962 /// Create an expression which evaluates to the number of elements in \p EC
963 /// at runtime. This can result in poison if type \p Ty is not big enough to
964 /// hold the value.
966
967 /// Create an expression which evaluates to the number of units in \p Size
968 /// at runtime. This works for both units of bits and bytes. This can result
969 /// in poison if type \p Ty is not big enough to hold the value.
971
972 /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
973 LLVM_ABI Value *CreateStepVector(Type *DstType, const Twine &Name = "");
974
975 /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
976 /// type.
978 FMFSource FMFSource = {},
979 const Twine &Name = "");
980
981 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
982 /// first type.
984 Value *RHS, FMFSource FMFSource = {},
985 const Twine &Name = "");
986
987 /// Create a call to intrinsic \p ID with \p Args, mangled using \p Types. If
988 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
989 /// the intrinsic.
992 FMFSource FMFSource = {},
993 const Twine &Name = "");
994
995 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
996 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
997 /// the intrinsic.
998 LLVM_ABI CallInst *CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
1000 FMFSource FMFSource = {},
1001 const Twine &Name = "");
1002
1003 /// Create a call to non-overloaded intrinsic \p ID with \p Args. If
1004 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
1005 /// the intrinsic.
1007 FMFSource FMFSource = {}, const Twine &Name = "") {
1008 return CreateIntrinsic(ID, /*Types=*/{}, Args, FMFSource, Name);
1009 }
1010
1011 /// Create call to the minnum intrinsic.
1013 const Twine &Name = "") {
1014 if (IsFPConstrained) {
1016 Intrinsic::experimental_constrained_minnum, LHS, RHS, FMFSource,
1017 Name);
1018 }
1019
1020 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, FMFSource, Name);
1021 }
1022
1023 /// Create call to the maxnum intrinsic.
1025 const Twine &Name = "") {
1026 if (IsFPConstrained) {
1028 Intrinsic::experimental_constrained_maxnum, LHS, RHS, FMFSource,
1029 Name);
1030 }
1031
1032 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, FMFSource, Name);
1033 }
1034
1035 /// Create call to the minimum intrinsic.
1036 Value *CreateMinimum(Value *LHS, Value *RHS, const Twine &Name = "") {
1037 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1038 }
1039
1040 /// Create call to the maximum intrinsic.
1041 Value *CreateMaximum(Value *LHS, Value *RHS, const Twine &Name = "") {
1042 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1043 }
1044
1045 /// Create call to the minimumnum intrinsic.
1046 Value *CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1047 return CreateBinaryIntrinsic(Intrinsic::minimumnum, LHS, RHS, nullptr,
1048 Name);
1049 }
1050
1051 /// Create call to the maximum intrinsic.
1052 Value *CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1053 return CreateBinaryIntrinsic(Intrinsic::maximumnum, LHS, RHS, nullptr,
1054 Name);
1055 }
1056
1057 /// Create call to the copysign intrinsic.
1059 const Twine &Name = "") {
1060 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1061 Name);
1062 }
1063
1064 /// Create call to the ldexp intrinsic.
1066 const Twine &Name = "") {
1067 assert(!IsFPConstrained && "TODO: Support strictfp");
1068 return CreateIntrinsic(Intrinsic::ldexp, {Src->getType(), Exp->getType()},
1069 {Src, Exp}, FMFSource, Name);
1070 }
1071
1072 /// Create call to the fma intrinsic.
1073 Value *CreateFMA(Value *Factor1, Value *Factor2, Value *Summand,
1074 FMFSource FMFSource = {}, const Twine &Name = "") {
1075 if (IsFPConstrained) {
1077 Intrinsic::experimental_constrained_fma, {Factor1->getType()},
1078 {Factor1, Factor2, Summand}, FMFSource, Name);
1079 }
1080
1081 return CreateIntrinsic(Intrinsic::fma, {Factor1->getType()},
1082 {Factor1, Factor2, Summand}, FMFSource, Name);
1083 }
1084
1085 /// Create a call to the arithmetic_fence intrinsic.
1087 const Twine &Name = "") {
1088 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1089 Name);
1090 }
1091
1092 /// Create a call to the vector.extract intrinsic.
1093 CallInst *CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx,
1094 const Twine &Name = "") {
1095 return CreateIntrinsic(Intrinsic::vector_extract,
1096 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1097 Name);
1098 }
1099
1100 /// Create a call to the vector.extract intrinsic.
1102 const Twine &Name = "") {
1103 return CreateExtractVector(DstType, SrcVec, getInt64(Idx), Name);
1104 }
1105
1106 /// Create a call to the vector.insert intrinsic.
1107 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1108 Value *Idx, const Twine &Name = "") {
1109 return CreateIntrinsic(Intrinsic::vector_insert,
1110 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1111 nullptr, Name);
1112 }
1113
1114 /// Create a call to the vector.extract intrinsic.
1115 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1116 uint64_t Idx, const Twine &Name = "") {
1117 return CreateInsertVector(DstType, SrcVec, SubVec, getInt64(Idx), Name);
1118 }
1119
1120 /// Create a call to llvm.stacksave
1121 CallInst *CreateStackSave(const Twine &Name = "") {
1122 const DataLayout &DL = BB->getDataLayout();
1123 return CreateIntrinsic(Intrinsic::stacksave, {DL.getAllocaPtrType(Context)},
1124 {}, nullptr, Name);
1125 }
1126
1127 /// Create a call to llvm.stackrestore
1128 CallInst *CreateStackRestore(Value *Ptr, const Twine &Name = "") {
1129 return CreateIntrinsic(Intrinsic::stackrestore, {Ptr->getType()}, {Ptr},
1130 nullptr, Name);
1131 }
1132
1133 /// Create a call to llvm.experimental_cttz_elts
1135 bool ZeroIsPoison = true,
1136 const Twine &Name = "") {
1137 return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
1138 {ResTy, Mask->getType()},
1139 {Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
1140 }
1141
1142private:
1143 /// Create a call to a masked intrinsic with given Id.
1144 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1145 ArrayRef<Type *> OverloadedTypes,
1146 const Twine &Name = "");
1147
1148 //===--------------------------------------------------------------------===//
1149 // Instruction creation methods: Terminators
1150 //===--------------------------------------------------------------------===//
1151
1152private:
1153 /// Helper to add branch weight and unpredictable metadata onto an
1154 /// instruction.
1155 /// \returns The annotated instruction.
1156 template <typename InstTy>
1157 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1158 if (Weights)
1159 I->setMetadata(LLVMContext::MD_prof, Weights);
1160 if (Unpredictable)
1161 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1162 return I;
1163 }
1164
1165public:
1166 /// Create a 'ret void' instruction.
1170
1171 /// Create a 'ret <val>' instruction.
1175
1176 /// Create a sequence of N insertvalue instructions,
1177 /// with one Value from the retVals array each, that build a aggregate
1178 /// return value one value at a time, and a ret instruction to return
1179 /// the resulting aggregate value.
1180 ///
1181 /// This is a convenience function for code that uses aggregate return values
1182 /// as a vehicle for having multiple return values.
1183 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
1185 for (unsigned i = 0; i != N; ++i)
1186 V = CreateInsertValue(V, retVals[i], i, "mrv");
1187 return Insert(ReturnInst::Create(Context, V));
1188 }
1189
1190 /// Create an unconditional 'br label X' instruction.
1192 return Insert(BranchInst::Create(Dest));
1193 }
1194
1195 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1196 /// instruction.
1198 MDNode *BranchWeights = nullptr,
1199 MDNode *Unpredictable = nullptr) {
1200 return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
1201 BranchWeights, Unpredictable));
1202 }
1203
1204 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1205 /// instruction. Copy branch meta data if available.
1207 Instruction *MDSrc) {
1208 BranchInst *Br = BranchInst::Create(True, False, Cond);
1209 if (MDSrc) {
1210 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1211 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1212 Br->copyMetadata(*MDSrc, WL);
1213 }
1214 return Insert(Br);
1215 }
1216
1217 /// Create a switch instruction with the specified value, default dest,
1218 /// and with a hint for the number of cases that will be added (for efficient
1219 /// allocation).
1220 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1221 MDNode *BranchWeights = nullptr,
1222 MDNode *Unpredictable = nullptr) {
1223 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1224 BranchWeights, Unpredictable));
1225 }
1226
1227 /// Create an indirect branch instruction with the specified address
1228 /// operand, with an optional hint for the number of destinations that will be
1229 /// added (for efficient allocation).
1230 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1231 return Insert(IndirectBrInst::Create(Addr, NumDests));
1232 }
1233
1234 /// Create an invoke instruction.
1236 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1237 ArrayRef<Value *> Args,
1239 const Twine &Name = "") {
1240 InvokeInst *II =
1241 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1242 if (IsFPConstrained)
1244 return Insert(II, Name);
1245 }
1247 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1248 ArrayRef<Value *> Args = {},
1249 const Twine &Name = "") {
1250 InvokeInst *II =
1251 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1252 if (IsFPConstrained)
1254 return Insert(II, Name);
1255 }
1256
1258 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1260 const Twine &Name = "") {
1261 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1262 NormalDest, UnwindDest, Args, OpBundles, Name);
1263 }
1264
1266 BasicBlock *UnwindDest, ArrayRef<Value *> Args = {},
1267 const Twine &Name = "") {
1268 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1269 NormalDest, UnwindDest, Args, Name);
1270 }
1271
1272 /// \brief Create a callbr instruction.
1274 BasicBlock *DefaultDest,
1275 ArrayRef<BasicBlock *> IndirectDests,
1276 ArrayRef<Value *> Args = {},
1277 const Twine &Name = "") {
1278 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1279 Args), Name);
1280 }
1282 BasicBlock *DefaultDest,
1283 ArrayRef<BasicBlock *> IndirectDests,
1284 ArrayRef<Value *> Args,
1286 const Twine &Name = "") {
1287 return Insert(
1288 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1289 OpBundles), Name);
1290 }
1291
1293 ArrayRef<BasicBlock *> IndirectDests,
1294 ArrayRef<Value *> Args = {},
1295 const Twine &Name = "") {
1296 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1297 DefaultDest, IndirectDests, Args, Name);
1298 }
1300 ArrayRef<BasicBlock *> IndirectDests,
1301 ArrayRef<Value *> Args,
1303 const Twine &Name = "") {
1304 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1305 DefaultDest, IndirectDests, Args, Name);
1306 }
1307
1309 return Insert(ResumeInst::Create(Exn));
1310 }
1311
1313 BasicBlock *UnwindBB = nullptr) {
1314 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1315 }
1316
1318 unsigned NumHandlers,
1319 const Twine &Name = "") {
1320 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1321 Name);
1322 }
1323
1325 const Twine &Name = "") {
1326 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1327 }
1328
1330 ArrayRef<Value *> Args = {},
1331 const Twine &Name = "") {
1332 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1333 }
1334
1338
1342
1343 //===--------------------------------------------------------------------===//
1344 // Instruction creation methods: Binary Operators
1345 //===--------------------------------------------------------------------===//
1346private:
1347 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1348 Value *LHS, Value *RHS,
1349 const Twine &Name,
1350 bool HasNUW, bool HasNSW) {
1352 if (HasNUW) BO->setHasNoUnsignedWrap();
1353 if (HasNSW) BO->setHasNoSignedWrap();
1354 return BO;
1355 }
1356
1357 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1358 FastMathFlags FMF) const {
1359 if (!FPMD)
1360 FPMD = DefaultFPMathTag;
1361 if (FPMD)
1362 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1363 I->setFastMathFlags(FMF);
1364 return I;
1365 }
1366
1367 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1369
1370 if (Rounding)
1371 UseRounding = *Rounding;
1372
1373 std::optional<StringRef> RoundingStr =
1374 convertRoundingModeToStr(UseRounding);
1375 assert(RoundingStr && "Garbage strict rounding mode!");
1376 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1377
1378 return MetadataAsValue::get(Context, RoundingMDS);
1379 }
1380
1381 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1382 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1383 Except.value_or(DefaultConstrainedExcept));
1384 assert(ExceptStr && "Garbage strict exception behavior!");
1385 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1386
1387 return MetadataAsValue::get(Context, ExceptMDS);
1388 }
1389
1390 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1391 assert(CmpInst::isFPPredicate(Predicate) &&
1392 Predicate != CmpInst::FCMP_FALSE &&
1393 Predicate != CmpInst::FCMP_TRUE &&
1394 "Invalid constrained FP comparison predicate!");
1395
1396 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1397 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1398
1399 return MetadataAsValue::get(Context, PredicateMDS);
1400 }
1401
1402public:
1403 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
1404 bool HasNUW = false, bool HasNSW = false) {
1405 if (Value *V =
1406 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1407 return V;
1408 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1409 HasNSW);
1410 }
1411
1412 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1413 return CreateAdd(LHS, RHS, Name, false, true);
1414 }
1415
1416 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1417 return CreateAdd(LHS, RHS, Name, true, false);
1418 }
1419
1420 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
1421 bool HasNUW = false, bool HasNSW = false) {
1422 if (Value *V =
1423 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1424 return V;
1425 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1426 HasNSW);
1427 }
1428
1429 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1430 return CreateSub(LHS, RHS, Name, false, true);
1431 }
1432
1433 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1434 return CreateSub(LHS, RHS, Name, true, false);
1435 }
1436
1437 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1438 bool HasNUW = false, bool HasNSW = false) {
1439 if (Value *V =
1440 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1441 return V;
1442 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1443 HasNSW);
1444 }
1445
1446 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1447 return CreateMul(LHS, RHS, Name, false, true);
1448 }
1449
1450 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1451 return CreateMul(LHS, RHS, Name, true, false);
1452 }
1453
1454 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1455 bool isExact = false) {
1456 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1457 return V;
1458 if (!isExact)
1459 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1460 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1461 }
1462
1463 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1464 return CreateUDiv(LHS, RHS, Name, true);
1465 }
1466
1467 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1468 bool isExact = false) {
1469 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1470 return V;
1471 if (!isExact)
1472 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1473 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1474 }
1475
1476 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1477 return CreateSDiv(LHS, RHS, Name, true);
1478 }
1479
1480 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1481 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1482 return V;
1483 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1484 }
1485
1486 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1487 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1488 return V;
1489 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1490 }
1491
1492 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1493 bool HasNUW = false, bool HasNSW = false) {
1494 if (Value *V =
1495 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1496 return V;
1497 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1498 HasNUW, HasNSW);
1499 }
1500
1501 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1502 bool HasNUW = false, bool HasNSW = false) {
1503 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1504 HasNUW, HasNSW);
1505 }
1506
1507 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1508 bool HasNUW = false, bool HasNSW = false) {
1509 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1510 HasNUW, HasNSW);
1511 }
1512
1513 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1514 bool isExact = false) {
1515 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1516 return V;
1517 if (!isExact)
1518 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1519 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1520 }
1521
1522 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1523 bool isExact = false) {
1524 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1525 }
1526
1528 bool isExact = false) {
1529 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1530 }
1531
1532 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1533 bool isExact = false) {
1534 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1535 return V;
1536 if (!isExact)
1537 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1538 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1539 }
1540
1541 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1542 bool isExact = false) {
1543 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1544 }
1545
1547 bool isExact = false) {
1548 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1549 }
1550
1551 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1552 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1553 return V;
1554 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1555 }
1556
1557 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1558 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1559 }
1560
1561 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1562 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1563 }
1564
1566 assert(!Ops.empty());
1567 Value *Accum = Ops[0];
1568 for (unsigned i = 1; i < Ops.size(); i++)
1569 Accum = CreateAnd(Accum, Ops[i]);
1570 return Accum;
1571 }
1572
1573 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "",
1574 bool IsDisjoint = false) {
1575 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1576 return V;
1577 return Insert(
1578 IsDisjoint ? BinaryOperator::CreateDisjoint(Instruction::Or, LHS, RHS)
1579 : BinaryOperator::CreateOr(LHS, RHS),
1580 Name);
1581 }
1582
1583 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1584 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1585 }
1586
1587 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1588 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1589 }
1590
1592 assert(!Ops.empty());
1593 Value *Accum = Ops[0];
1594 for (unsigned i = 1; i < Ops.size(); i++)
1595 Accum = CreateOr(Accum, Ops[i]);
1596 return Accum;
1597 }
1598
1599 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1600 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1601 return V;
1602 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1603 }
1604
1605 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1606 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1607 }
1608
1609 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1610 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1611 }
1612
1613 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1614 MDNode *FPMD = nullptr) {
1615 return CreateFAddFMF(L, R, {}, Name, FPMD);
1616 }
1617
1619 const Twine &Name = "", MDNode *FPMD = nullptr) {
1620 if (IsFPConstrained)
1621 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1622 L, R, FMFSource, Name, FPMD);
1623
1624 if (Value *V =
1625 Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMFSource.get(FMF)))
1626 return V;
1627 Instruction *I =
1628 setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMFSource.get(FMF));
1629 return Insert(I, Name);
1630 }
1631
1632 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1633 MDNode *FPMD = nullptr) {
1634 return CreateFSubFMF(L, R, {}, Name, FPMD);
1635 }
1636
1638 const Twine &Name = "", MDNode *FPMD = nullptr) {
1639 if (IsFPConstrained)
1640 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1641 L, R, FMFSource, Name, FPMD);
1642
1643 if (Value *V =
1644 Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMFSource.get(FMF)))
1645 return V;
1646 Instruction *I =
1647 setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMFSource.get(FMF));
1648 return Insert(I, Name);
1649 }
1650
1651 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1652 MDNode *FPMD = nullptr) {
1653 return CreateFMulFMF(L, R, {}, Name, FPMD);
1654 }
1655
1657 const Twine &Name = "", MDNode *FPMD = nullptr) {
1658 if (IsFPConstrained)
1659 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1660 L, R, FMFSource, Name, FPMD);
1661
1662 if (Value *V =
1663 Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMFSource.get(FMF)))
1664 return V;
1665 Instruction *I =
1666 setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMFSource.get(FMF));
1667 return Insert(I, Name);
1668 }
1669
1670 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1671 MDNode *FPMD = nullptr) {
1672 return CreateFDivFMF(L, R, {}, Name, FPMD);
1673 }
1674
1676 const Twine &Name = "", MDNode *FPMD = nullptr) {
1677 if (IsFPConstrained)
1678 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1679 L, R, FMFSource, Name, FPMD);
1680
1681 if (Value *V =
1682 Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMFSource.get(FMF)))
1683 return V;
1684 Instruction *I =
1685 setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMFSource.get(FMF));
1686 return Insert(I, Name);
1687 }
1688
1689 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1690 MDNode *FPMD = nullptr) {
1691 return CreateFRemFMF(L, R, {}, Name, FPMD);
1692 }
1693
1695 const Twine &Name = "", MDNode *FPMD = nullptr) {
1696 if (IsFPConstrained)
1697 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1698 L, R, FMFSource, Name, FPMD);
1699
1700 if (Value *V =
1701 Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMFSource.get(FMF)))
1702 return V;
1703 Instruction *I =
1704 setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMFSource.get(FMF));
1705 return Insert(I, Name);
1706 }
1707
1709 Value *LHS, Value *RHS, const Twine &Name = "",
1710 MDNode *FPMathTag = nullptr) {
1711 return CreateBinOpFMF(Opc, LHS, RHS, {}, Name, FPMathTag);
1712 }
1713
1715 FMFSource FMFSource, const Twine &Name = "",
1716 MDNode *FPMathTag = nullptr) {
1717 if (Value *V = Folder.FoldBinOp(Opc, LHS, RHS))
1718 return V;
1720 if (isa<FPMathOperator>(BinOp))
1721 setFPAttrs(BinOp, FPMathTag, FMFSource.get(FMF));
1722 return Insert(BinOp, Name);
1723 }
1724
1725 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "",
1726 Instruction *MDFrom = nullptr) {
1727 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1728 return CreateSelect(Cond1, Cond2,
1729 ConstantInt::getNullValue(Cond2->getType()), Name,
1730 MDFrom);
1731 }
1732
1733 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
1734 Instruction *MDFrom = nullptr) {
1735 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1736 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1737 Cond2, Name, MDFrom);
1738 }
1739
1741 const Twine &Name = "") {
1742 switch (Opc) {
1743 case Instruction::And:
1744 return CreateLogicalAnd(Cond1, Cond2, Name);
1745 case Instruction::Or:
1746 return CreateLogicalOr(Cond1, Cond2, Name);
1747 default:
1748 break;
1749 }
1750 llvm_unreachable("Not a logical operation.");
1751 }
1752
1753 // NOTE: this is sequential, non-commutative, ordered reduction!
1755 assert(!Ops.empty());
1756 Value *Accum = Ops[0];
1757 for (unsigned i = 1; i < Ops.size(); i++)
1758 Accum = CreateLogicalOr(Accum, Ops[i]);
1759 return Accum;
1760 }
1761
1762 /// This function is like @ref CreateIntrinsic for constrained fp
1763 /// intrinsics. It sets the rounding mode and exception behavior of
1764 /// the created intrinsic call according to \p Rounding and \p
1765 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1766 /// defaults if a value equals nullopt/null.
1769 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1770 std::optional<RoundingMode> Rounding = std::nullopt,
1771 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1772
1775 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1776 std::optional<RoundingMode> Rounding = std::nullopt,
1777 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1778
1780 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1781 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1782 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1783
1784 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1785 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1786 /*HasNUW=*/0, HasNSW);
1787 }
1788
1789 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1790 return CreateNeg(V, Name, /*HasNSW=*/true);
1791 }
1792
1793 Value *CreateFNeg(Value *V, const Twine &Name = "",
1794 MDNode *FPMathTag = nullptr) {
1795 return CreateFNegFMF(V, {}, Name, FPMathTag);
1796 }
1797
1799 MDNode *FPMathTag = nullptr) {
1800 if (Value *Res =
1801 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1802 return Res;
1803 return Insert(
1804 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1805 Name);
1806 }
1807
1808 Value *CreateNot(Value *V, const Twine &Name = "") {
1809 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1810 }
1811
1813 Value *V, const Twine &Name = "",
1814 MDNode *FPMathTag = nullptr) {
1815 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1816 return Res;
1818 if (isa<FPMathOperator>(UnOp))
1819 setFPAttrs(UnOp, FPMathTag, FMF);
1820 return Insert(UnOp, Name);
1821 }
1822
1823 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1824 /// Correct number of operands must be passed accordingly.
1826 const Twine &Name = "",
1827 MDNode *FPMathTag = nullptr);
1828
1829 //===--------------------------------------------------------------------===//
1830 // Instruction creation methods: Memory Instructions
1831 //===--------------------------------------------------------------------===//
1832
1833 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1834 Value *ArraySize = nullptr, const Twine &Name = "") {
1835 const DataLayout &DL = BB->getDataLayout();
1836 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1837 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1838 }
1839
1840 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1841 const Twine &Name = "") {
1842 const DataLayout &DL = BB->getDataLayout();
1843 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1844 unsigned AddrSpace = DL.getAllocaAddrSpace();
1845 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1846 }
1847
1848 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1849 /// converting the string to 'bool' for the isVolatile parameter.
1850 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1851 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1852 }
1853
1854 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1855 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1856 }
1857
1858 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1859 const Twine &Name = "") {
1860 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1861 }
1862
1863 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1864 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1865 }
1866
1868 const char *Name) {
1869 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1870 }
1871
1873 const Twine &Name = "") {
1874 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1875 }
1876
1878 bool isVolatile, const Twine &Name = "") {
1879 if (!Align) {
1880 const DataLayout &DL = BB->getDataLayout();
1881 Align = DL.getABITypeAlign(Ty);
1882 }
1883 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1884 }
1885
1887 bool isVolatile = false) {
1888 if (!Align) {
1889 const DataLayout &DL = BB->getDataLayout();
1890 Align = DL.getABITypeAlign(Val->getType());
1891 }
1892 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1893 }
1896 const Twine &Name = "") {
1897 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1898 }
1899
1902 AtomicOrdering SuccessOrdering,
1903 AtomicOrdering FailureOrdering,
1905 if (!Align) {
1906 const DataLayout &DL = BB->getDataLayout();
1907 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1908 }
1909
1910 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1911 FailureOrdering, SSID));
1912 }
1913
1915 Value *Val, MaybeAlign Align,
1916 AtomicOrdering Ordering,
1918 if (!Align) {
1919 const DataLayout &DL = BB->getDataLayout();
1920 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1921 }
1922
1923 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1924 }
1925
1927 const Twine &Name = "",
1929 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, NW))
1930 return V;
1931 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList, NW), Name);
1932 }
1933
1935 const Twine &Name = "") {
1936 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
1937 }
1938
1939 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1940 const Twine &Name = "") {
1941 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1942 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
1943 }
1944
1945 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1946 const Twine &Name = "") {
1947 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1948 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
1949 }
1950
1951 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1952 const Twine &Name = "",
1954 Value *Idxs[] = {
1955 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1956 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1957 };
1958 return CreateGEP(Ty, Ptr, Idxs, Name, NWFlags);
1959 }
1960
1961 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1962 unsigned Idx1, const Twine &Name = "") {
1963 Value *Idxs[] = {
1964 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1965 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1966 };
1967 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
1968 }
1969
1971 const Twine &Name = "") {
1972 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1973 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
1974 }
1975
1977 const Twine &Name = "") {
1978 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1979 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
1980 }
1981
1983 const Twine &Name = "") {
1984 Value *Idxs[] = {
1985 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1986 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1987 };
1988 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::none());
1989 }
1990
1992 uint64_t Idx1, const Twine &Name = "") {
1993 Value *Idxs[] = {
1994 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1995 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1996 };
1997 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
1998 }
1999
2000 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2001 const Twine &Name = "") {
2002 GEPNoWrapFlags NWFlags =
2004 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2005 }
2006
2007 Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
2009 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
2010 }
2011
2013 const Twine &Name = "") {
2014 return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
2016 }
2017
2018 //===--------------------------------------------------------------------===//
2019 // Instruction creation methods: Cast/Conversion Operators
2020 //===--------------------------------------------------------------------===//
2021
2022 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2023 bool IsNUW = false, bool IsNSW = false) {
2024 if (V->getType() == DestTy)
2025 return V;
2026 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2027 return Folded;
2028 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2029 if (IsNUW)
2030 I->setHasNoUnsignedWrap();
2031 if (IsNSW)
2032 I->setHasNoSignedWrap();
2033 return Insert(I, Name);
2034 }
2035
2036 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2037 bool IsNonNeg = false) {
2038 if (V->getType() == DestTy)
2039 return V;
2040 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2041 return Folded;
2042 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2043 if (IsNonNeg)
2044 I->setNonNeg();
2045 return I;
2046 }
2047
2048 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2049 return CreateCast(Instruction::SExt, V, DestTy, Name);
2050 }
2051
2052 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2053 /// the value untouched if the type of V is already DestTy.
2055 const Twine &Name = "") {
2056 assert(V->getType()->isIntOrIntVectorTy() &&
2057 DestTy->isIntOrIntVectorTy() &&
2058 "Can only zero extend/truncate integers!");
2059 Type *VTy = V->getType();
2060 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2061 return CreateZExt(V, DestTy, Name);
2062 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2063 return CreateTrunc(V, DestTy, Name);
2064 return V;
2065 }
2066
2067 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2068 /// the value untouched if the type of V is already DestTy.
2070 const Twine &Name = "") {
2071 assert(V->getType()->isIntOrIntVectorTy() &&
2072 DestTy->isIntOrIntVectorTy() &&
2073 "Can only sign extend/truncate integers!");
2074 Type *VTy = V->getType();
2075 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2076 return CreateSExt(V, DestTy, Name);
2077 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2078 return CreateTrunc(V, DestTy, Name);
2079 return V;
2080 }
2081
2082 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2083 if (IsFPConstrained)
2084 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2085 V, DestTy, nullptr, Name);
2086 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2087 }
2088
2089 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2090 if (IsFPConstrained)
2091 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2092 V, DestTy, nullptr, Name);
2093 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2094 }
2095
2096 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2097 bool IsNonNeg = false) {
2098 if (IsFPConstrained)
2099 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2100 V, DestTy, nullptr, Name);
2101 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2102 return Folded;
2103 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2104 if (IsNonNeg)
2105 I->setNonNeg();
2106 return I;
2107 }
2108
2109 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2110 if (IsFPConstrained)
2111 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2112 V, DestTy, nullptr, Name);
2113 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2114 }
2115
2116 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2117 MDNode *FPMathTag = nullptr) {
2118 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2119 }
2120
2122 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2123 if (IsFPConstrained)
2125 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2126 Name, FPMathTag);
2127 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2128 FMFSource);
2129 }
2130
2131 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2132 MDNode *FPMathTag = nullptr) {
2133 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2134 }
2135
2137 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2138 if (IsFPConstrained)
2139 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2140 V, DestTy, FMFSource, Name, FPMathTag);
2141 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2142 FMFSource);
2143 }
2144 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2145 return CreateCast(Instruction::PtrToAddr, V,
2146 BB->getDataLayout().getAddressType(V->getType()), Name);
2147 }
2149 const Twine &Name = "") {
2150 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2151 }
2152
2154 const Twine &Name = "") {
2155 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2156 }
2157
2159 const Twine &Name = "") {
2160 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2161 }
2162
2164 const Twine &Name = "") {
2165 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2166 }
2167
2168 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2169 Instruction::CastOps CastOp =
2170 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2171 ? Instruction::BitCast
2172 : Instruction::ZExt;
2173 return CreateCast(CastOp, V, DestTy, Name);
2174 }
2175
2176 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2177 Instruction::CastOps CastOp =
2178 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2179 ? Instruction::BitCast
2180 : Instruction::SExt;
2181 return CreateCast(CastOp, V, DestTy, Name);
2182 }
2183
2184 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2185 Instruction::CastOps CastOp =
2186 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2187 ? Instruction::BitCast
2188 : Instruction::Trunc;
2189 return CreateCast(CastOp, V, DestTy, Name);
2190 }
2191
2193 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2194 FMFSource FMFSource = {}) {
2195 if (V->getType() == DestTy)
2196 return V;
2197 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2198 return Folded;
2199 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2200 if (isa<FPMathOperator>(Cast))
2201 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2202 return Insert(Cast, Name);
2203 }
2204
2206 const Twine &Name = "") {
2207 if (V->getType() == DestTy)
2208 return V;
2209 if (auto *VC = dyn_cast<Constant>(V))
2210 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2211 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2212 }
2213
2214 // With opaque pointers enabled, this can be substituted with
2215 // CreateAddrSpaceCast.
2216 // TODO: Replace uses of this method and remove the method itself.
2218 const Twine &Name = "") {
2219 if (V->getType() == DestTy)
2220 return V;
2221
2222 if (auto *VC = dyn_cast<Constant>(V)) {
2223 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2224 Name);
2225 }
2226
2228 Name);
2229 }
2230
2231 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
2232 const Twine &Name = "") {
2233 Instruction::CastOps CastOp =
2234 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2235 ? Instruction::Trunc
2236 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2237 return CreateCast(CastOp, V, DestTy, Name);
2238 }
2239
2241 const Twine &Name = "") {
2242 if (V->getType() == DestTy)
2243 return V;
2244 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2245 return CreatePtrToInt(V, DestTy, Name);
2246 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2247 return CreateIntToPtr(V, DestTy, Name);
2248
2249 return CreateBitCast(V, DestTy, Name);
2250 }
2251
2252 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2253 MDNode *FPMathTag = nullptr) {
2254 Instruction::CastOps CastOp =
2255 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2256 ? Instruction::FPTrunc
2257 : Instruction::FPExt;
2258 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2259 }
2260
2262 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2263 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2264 std::optional<RoundingMode> Rounding = std::nullopt,
2265 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2266
2267 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2268 // compile time error, instead of converting the string to bool for the
2269 // isSigned parameter.
2270 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2271
2272 /// Cast between aggregate types that must have identical structure but may
2273 /// differ in their leaf types. The leaf values are recursively extracted,
2274 /// casted, and then reinserted into a value of type DestTy. The leaf types
2275 /// must be castable using a bitcast or ptrcast, because signedness is
2276 /// not specified.
2278
2279 //===--------------------------------------------------------------------===//
2280 // Instruction creation methods: Compare Instructions
2281 //===--------------------------------------------------------------------===//
2282
2283 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2284 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2285 }
2286
2287 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2288 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2289 }
2290
2291 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2292 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2293 }
2294
2295 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2296 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2297 }
2298
2299 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2300 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2301 }
2302
2303 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2304 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2305 }
2306
2307 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2308 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2309 }
2310
2311 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2312 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2313 }
2314
2315 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2316 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2317 }
2318
2319 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2320 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2321 }
2322
2323 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2324 MDNode *FPMathTag = nullptr) {
2325 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2326 }
2327
2328 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2329 MDNode *FPMathTag = nullptr) {
2330 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2331 }
2332
2333 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2334 MDNode *FPMathTag = nullptr) {
2335 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2336 }
2337
2338 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2339 MDNode *FPMathTag = nullptr) {
2340 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2341 }
2342
2343 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2344 MDNode *FPMathTag = nullptr) {
2345 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2346 }
2347
2348 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2349 MDNode *FPMathTag = nullptr) {
2350 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2351 }
2352
2353 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2354 MDNode *FPMathTag = nullptr) {
2355 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2356 }
2357
2358 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2359 MDNode *FPMathTag = nullptr) {
2360 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2361 }
2362
2363 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2364 MDNode *FPMathTag = nullptr) {
2365 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2366 }
2367
2368 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2369 MDNode *FPMathTag = nullptr) {
2370 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2371 }
2372
2373 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2374 MDNode *FPMathTag = nullptr) {
2375 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2376 }
2377
2378 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2379 MDNode *FPMathTag = nullptr) {
2380 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2381 }
2382
2383 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2384 MDNode *FPMathTag = nullptr) {
2385 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2386 }
2387
2388 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2389 MDNode *FPMathTag = nullptr) {
2390 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2391 }
2392
2394 const Twine &Name = "") {
2395 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2396 return V;
2397 return Insert(new ICmpInst(P, LHS, RHS), Name);
2398 }
2399
2400 // Create a quiet floating-point comparison (i.e. one that raises an FP
2401 // exception only in the case where an input is a signaling NaN).
2402 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2404 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2405 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2406 }
2407
2408 // Create a quiet floating-point comparison (i.e. one that raises an FP
2409 // exception only in the case where an input is a signaling NaN).
2410 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2412 FMFSource FMFSource, const Twine &Name = "",
2413 MDNode *FPMathTag = nullptr) {
2414 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2415 }
2416
2418 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2419 return CmpInst::isFPPredicate(Pred)
2420 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2421 : CreateICmp(Pred, LHS, RHS, Name);
2422 }
2423
2424 // Create a signaling floating-point comparison (i.e. one that raises an FP
2425 // exception whenever an input is any NaN, signaling or quiet).
2426 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2428 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2429 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2430 }
2431
2432private:
2433 // Helper routine to create either a signaling or a quiet FP comparison.
2434 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2435 const Twine &Name, MDNode *FPMathTag,
2436 FMFSource FMFSource, bool IsSignaling);
2437
2438public:
2441 const Twine &Name = "",
2442 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2443
2444 //===--------------------------------------------------------------------===//
2445 // Instruction creation methods: Other Instructions
2446 //===--------------------------------------------------------------------===//
2447
2448 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2449 const Twine &Name = "") {
2450 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2451 if (isa<FPMathOperator>(Phi))
2452 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2453 return Insert(Phi, Name);
2454 }
2455
2456private:
2457 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2458 const Twine &Name = "", FMFSource FMFSource = {},
2459 ArrayRef<OperandBundleDef> OpBundles = {});
2460
2461public:
2463 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2464 MDNode *FPMathTag = nullptr) {
2465 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2466 if (IsFPConstrained)
2468 if (isa<FPMathOperator>(CI))
2469 setFPAttrs(CI, FPMathTag, FMF);
2470 return Insert(CI, Name);
2471 }
2472
2475 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2476 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2477 if (IsFPConstrained)
2479 if (isa<FPMathOperator>(CI))
2480 setFPAttrs(CI, FPMathTag, FMF);
2481 return Insert(CI, Name);
2482 }
2483
2485 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2486 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2487 FPMathTag);
2488 }
2489
2492 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2493 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2494 OpBundles, Name, FPMathTag);
2495 }
2496
2498 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2499 std::optional<RoundingMode> Rounding = std::nullopt,
2500 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2501
2503 Value *False,
2505 const Twine &Name = "");
2506
2508 Value *False,
2511 const Twine &Name = "");
2512
2513 LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
2514 const Twine &Name = "",
2515 Instruction *MDFrom = nullptr);
2516 LLVM_ABI Value *CreateSelectFMF(Value *C, Value *True, Value *False,
2517 FMFSource FMFSource, const Twine &Name = "",
2518 Instruction *MDFrom = nullptr);
2519
2520 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2521 return Insert(new VAArgInst(List, Ty), Name);
2522 }
2523
2525 const Twine &Name = "") {
2526 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2527 return V;
2528 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2529 }
2530
2532 const Twine &Name = "") {
2533 return CreateExtractElement(Vec, getInt64(Idx), Name);
2534 }
2535
2536 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2537 const Twine &Name = "") {
2538 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2539 }
2540
2542 const Twine &Name = "") {
2543 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2544 }
2545
2547 const Twine &Name = "") {
2548 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2549 return V;
2550 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2551 }
2552
2554 const Twine &Name = "") {
2555 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2556 }
2557
2559 const Twine &Name = "") {
2560 SmallVector<int, 16> IntMask;
2562 return CreateShuffleVector(V1, V2, IntMask, Name);
2563 }
2564
2565 /// See class ShuffleVectorInst for a description of the mask representation.
2567 const Twine &Name = "") {
2568 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2569 return V;
2570 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2571 }
2572
2573 /// Create a unary shuffle. The second vector operand of the IR instruction
2574 /// is poison.
2576 const Twine &Name = "") {
2577 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2578 }
2579
2581 const Twine &Name = "");
2582
2584 const Twine &Name = "") {
2585 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2586 return V;
2587 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2588 }
2589
2591 const Twine &Name = "") {
2592 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2593 return V;
2594 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2595 }
2596
2597 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2598 const Twine &Name = "") {
2599 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2600 }
2601
2602 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2603 return Insert(new FreezeInst(V), Name);
2604 }
2605
2606 //===--------------------------------------------------------------------===//
2607 // Utility creation methods
2608 //===--------------------------------------------------------------------===//
2609
2610 /// Return a boolean value testing if \p Arg == 0.
2611 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2612 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2613 }
2614
2615 /// Return a boolean value testing if \p Arg != 0.
2616 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2617 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2618 }
2619
2620 /// Return a boolean value testing if \p Arg < 0.
2621 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2622 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2623 }
2624
2625 /// Return a boolean value testing if \p Arg > -1.
2626 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2628 Name);
2629 }
2630
2631 /// Return the i64 difference between two pointer values, dividing out
2632 /// the size of the pointed-to objects.
2633 ///
2634 /// This is intended to implement C-style pointer subtraction. As such, the
2635 /// pointers must be appropriately aligned for their element types and
2636 /// pointing into the same object.
2638 const Twine &Name = "");
2639
2640 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2641 /// different from pointer to i8, it's casted to pointer to i8 in the same
2642 /// address space before call and casted back to Ptr type after call.
2644
2645 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2646 /// different from pointer to i8, it's casted to pointer to i8 in the same
2647 /// address space before call and casted back to Ptr type after call.
2649
2650 /// Return a vector value that contains the vector V reversed
2651 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2652
2653 /// Return a vector splice intrinsic if using scalable vectors, otherwise
2654 /// return a shufflevector. If the immediate is positive, a vector is
2655 /// extracted from concat(V1, V2), starting at Imm. If the immediate
2656 /// is negative, we extract -Imm elements from V1 and the remaining
2657 /// elements from V2. Imm is a signed integer in the range
2658 /// -VL <= Imm < VL (where VL is the runtime vector length of the
2659 /// source/result vector)
2660 LLVM_ABI Value *CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
2661 const Twine &Name = "");
2662
2663 /// Return a vector value that contains \arg V broadcasted to \p
2664 /// NumElts elements.
2665 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2666 const Twine &Name = "");
2667
2668 /// Return a vector value that contains \arg V broadcasted to \p
2669 /// EC elements.
2671 const Twine &Name = "");
2672
2674 unsigned Dimension,
2675 unsigned LastIndex,
2676 MDNode *DbgInfo);
2677
2679 unsigned FieldIndex,
2680 MDNode *DbgInfo);
2681
2683 unsigned Index,
2684 unsigned FieldIndex,
2685 MDNode *DbgInfo);
2686
2687 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2688
2689private:
2690 /// Helper function that creates an assume intrinsic call that
2691 /// represents an alignment assumption on the provided pointer \p PtrValue
2692 /// with offset \p OffsetValue and alignment value \p AlignValue.
2693 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2694 Value *PtrValue, Value *AlignValue,
2695 Value *OffsetValue);
2696
2697public:
2698 /// Create an assume intrinsic call that represents an alignment
2699 /// assumption on the provided pointer.
2700 ///
2701 /// An optional offset can be provided, and if it is provided, the offset
2702 /// must be subtracted from the provided pointer to get the pointer with the
2703 /// specified alignment.
2705 Value *PtrValue,
2706 unsigned Alignment,
2707 Value *OffsetValue = nullptr);
2708
2709 /// Create an assume intrinsic call that represents an alignment
2710 /// assumption on the provided pointer.
2711 ///
2712 /// An optional offset can be provided, and if it is provided, the offset
2713 /// must be subtracted from the provided pointer to get the pointer with the
2714 /// specified alignment.
2715 ///
2716 /// This overload handles the condition where the Alignment is dependent
2717 /// on an existing value rather than a static value.
2719 Value *PtrValue,
2720 Value *Alignment,
2721 Value *OffsetValue = nullptr);
2722
2723 /// Create an assume intrinsic call that represents an dereferencable
2724 /// assumption on the provided pointer.
2726 Value *SizeValue);
2727};
2728
2729/// This provides a uniform API for creating instructions and inserting
2730/// them into a basic block: either at the end of a BasicBlock, or at a specific
2731/// iterator location in a block.
2732///
2733/// Note that the builder does not expose the full generality of LLVM
2734/// instructions. For access to extra instruction properties, use the mutators
2735/// (e.g. setVolatile) on the instructions after they have been
2736/// created. Convenience state exists to specify fast-math flags and fp-math
2737/// tags.
2738///
2739/// The first template argument specifies a class to use for creating constants.
2740/// This defaults to creating minimally folded constants. The second template
2741/// argument allows clients to specify custom insertion hooks that are called on
2742/// every newly created insertion.
2743template <typename FolderTy = ConstantFolder,
2744 typename InserterTy = IRBuilderDefaultInserter>
2745class IRBuilder : public IRBuilderBase {
2746private:
2747 FolderTy Folder;
2748 InserterTy Inserter;
2749
2750public:
2751 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter,
2752 MDNode *FPMathTag = nullptr,
2753 ArrayRef<OperandBundleDef> OpBundles = {})
2754 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2756
2757 IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag = nullptr,
2758 ArrayRef<OperandBundleDef> OpBundles = {})
2759 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2760 Folder(Folder) {}
2761
2762 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2763 ArrayRef<OperandBundleDef> OpBundles = {})
2764 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2765
2766 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2767 MDNode *FPMathTag = nullptr,
2768 ArrayRef<OperandBundleDef> OpBundles = {})
2769 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2770 FPMathTag, OpBundles),
2771 Folder(Folder) {
2772 SetInsertPoint(TheBB);
2773 }
2774
2775 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2776 ArrayRef<OperandBundleDef> OpBundles = {})
2777 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2778 FPMathTag, OpBundles) {
2779 SetInsertPoint(TheBB);
2780 }
2781
2782 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2783 ArrayRef<OperandBundleDef> OpBundles = {})
2784 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2785 OpBundles) {
2786 SetInsertPoint(IP);
2787 }
2788
2789 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2790 MDNode *FPMathTag = nullptr,
2791 ArrayRef<OperandBundleDef> OpBundles = {})
2792 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2793 FPMathTag, OpBundles),
2794 Folder(Folder) {
2795 SetInsertPoint(TheBB, IP);
2796 }
2797
2799 MDNode *FPMathTag = nullptr,
2800 ArrayRef<OperandBundleDef> OpBundles = {})
2801 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2802 FPMathTag, OpBundles) {
2803 SetInsertPoint(TheBB, IP);
2804 }
2805
2806 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2807 /// or FastMathFlagGuard instead.
2808 IRBuilder(const IRBuilder &) = delete;
2809
2810 InserterTy &getInserter() { return Inserter; }
2811 const InserterTy &getInserter() const { return Inserter; }
2812};
2813
2814template <typename FolderTy, typename InserterTy>
2815IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2818template <typename FolderTy>
2823template <typename FolderTy>
2828
2829
2830// Create wrappers for C Binding types (see CBindingWrapping.h).
2832
2833} // end namespace llvm
2834
2835#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.
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
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.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:483
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
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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)
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:22
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:1476
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2168
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2348
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
Definition IRBuilder.h:1065
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:2427
BasicBlock * BB
Definition IRBuilder.h:146
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1450
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1329
LLVM_ABI Value * CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS, const Twine &Name="")
Return the i64 difference between two pointer values, dividing out the size of the pointed-to objects...
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:1637
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:2299
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2121
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1970
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:1093
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:2373
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2541
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1486
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition IRBuilder.h:1872
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1632
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2403
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition IRBuilder.h:1324
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:2536
void SetNoSanitizeMetadata()
Set nosanitize metadata.
Definition IRBuilder.h:254
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1527
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1901
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:1939
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1833
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition IRBuilder.h:399
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition IRBuilder.h:1121
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1257
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:547
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:2590
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1565
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:1230
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition IRBuilder.h:1206
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1557
void setDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition IRBuilder.h:342
LLVM_ABI Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition IRBuilder.cpp:59
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2490
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:1670
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:1107
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1522
void clearFastMathFlags()
Clear the fast-math flags.
Definition IRBuilder.h:339
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2109
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:1858
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1754
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2524
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="")
Definition IRBuilder.h:1740
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition IRBuilder.h:575
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:2307
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:1867
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2353
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition IRBuilder.h:595
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2054
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:687
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1613
UnreachableInst * CreateUnreachable()
Definition IRBuilder.h:1339
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:2116
LLVM_ABI Value * CreateVectorSplice(Value *V1, Value *V2, int64_t Imm, const Twine &Name="")
Return a vector splice intrinsic if using scalable vectors, otherwise return a shufflevector.
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:2205
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:2144
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:1689
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2583
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1561
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:2597
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2136
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1041
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:2311
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:1235
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:2082
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:1982
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2388
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:202
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2000
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1894
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:617
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1299
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:2048
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2176
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2368
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2153
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:2602
BasicBlock::iterator InsertPt
Definition IRBuilder.h:147
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Create a callbr instruction.
Definition IRBuilder.h:1273
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:1513
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:611
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition IRBuilder.h:562
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition IRBuilder.h:1945
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:1006
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:2007
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2192
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2626
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition IRBuilder.h:1335
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition IRBuilder.h:1312
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2096
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition IRBuilder.h:1172
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1412
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:958
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1546
BasicBlock * GetInsertBlock() const
Definition IRBuilder.h:201
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition IRBuilder.h:580
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:2338
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:567
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition IRBuilder.h:1934
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1446
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:1583
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:2217
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:2575
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:1541
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1454
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2383
FastMathFlags FMF
Definition IRBuilder.h:153
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2287
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1416
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition IRBuilder.h:557
Value * CreateFCmpFMF(CmpInst::Predicate P, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2411
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:1926
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:729
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition IRBuilder.h:1317
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition IRBuilder.h:862
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1812
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1784
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1854
LLVM_ABI CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
InsertPoint saveIP() const
Returns the current insert point.
Definition IRBuilder.h:311
void CollectMetadataToCopy(Instruction *Src, ArrayRef< unsigned > MetadataKinds)
Collect metadata with IDs MetadataKinds from Src which should be added to all created instructions.
Definition IRBuilder.h:262
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1725
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:2553
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1507
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:2566
ReturnInst * CreateAggregateRet(Value *const *retVals, unsigned N)
Create a sequence of N insertvalue instructions, with one Value from the retVals array each,...
Definition IRBuilder.h:1183
LLVM_ABI Value * createIsFPClass(Value *FPNum, unsigned Test)
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2343
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
LLVM_ABI CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:522
LLVM_ABI CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles={})
Generate the IR for a call to the builtin free function.
Value * CreateMaxNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the maxnum intrinsic.
Definition IRBuilder.h:1024
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2240
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2417
const IRBuilderDefaultInserter & Inserter
Definition IRBuilder.h:150
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2252
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2319
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2448
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2473
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1808
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:1220
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2283
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:1714
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2363
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:1036
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition IRBuilder.h:572
Value * CreateCountTrailingZeroElems(Type *ResTy, Value *Mask, bool ZeroIsPoison=true, const Twine &Name="")
Create a call to llvm.experimental_cttz_elts.
Definition IRBuilder.h:1134
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition IRBuilder.h:2621
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:1420
Value * CreateFMA(Value *Factor1, Value *Factor2, Value *Summand, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fma intrinsic.
Definition IRBuilder.h:1073
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2158
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
Definition IRBuilder.h:533
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition IRBuilder.h:1197
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
Value * CreateCopySign(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the copysign intrinsic.
Definition IRBuilder.h:1058
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2291
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:1850
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:651
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1492
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:630
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:2036
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:2558
LLVMContext & getContext() const
Definition IRBuilder.h:203
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2323
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1551
FastMathFlags & getFastMathFlags()
Definition IRBuilder.h:336
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition IRBuilder.h:1167
Value * CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1052
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1429
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition IRBuilder.h:1961
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:1991
Value * CreateMinNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the minnum intrinsic.
Definition IRBuilder.h:1012
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1265
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1101
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1863
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:1403
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2148
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1467
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:2520
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1463
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition IRBuilder.h:590
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition IRBuilder.h:2616
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:877
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2462
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1501
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1914
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:2022
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:605
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1708
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition IRBuilder.h:1191
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2546
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1976
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:1292
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2315
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:1281
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:2295
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:2231
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2358
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:2611
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:701
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2328
CallInst * CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:709
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition IRBuilder.h:1128
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:600
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1246
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:1115
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:1591
Value * CreateFAddFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1618
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1733
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1840
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:1951
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2531
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1886
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1587
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:1046
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.
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:2012
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2131
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:1532
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2484
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1798
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1599
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:2184
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2303
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2393
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:1651
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1877
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1793
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:1573
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:552
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition IRBuilder.h:538
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:1675
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1480
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:2069
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1308
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2163
Type * getBFloatTy()
Fetch the type representing a 16-bit brain floating point value.
Definition IRBuilder.h:585
Value * CreateFMulFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1656
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1605
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:1437
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:1694
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1609
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:1789
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:2333
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:737
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:1433
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2378
CallInst * CreateArithmeticFence(Value *Val, Type *DstType, const Twine &Name="")
Create a call to the arithmetic_fence intrinsic.
Definition IRBuilder.h:1086
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2089
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:2745
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2762
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2757
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2751
InserterTy & getInserter()
Definition IRBuilder.h:2810
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2782
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2766
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2789
const InserterTy & getInserter() const
Definition IRBuilder.h:2811
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2798
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2775
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.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
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:1078
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
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:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:296
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:246
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:280
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:294
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:295
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:230
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:293
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:270
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:300
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:285
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:284
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:283
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:282
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.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
This class represents zero extension of integer types.
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition Types.h:110
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Rounding
Possible values of current rounding mode, which is specified in bits 23:22 of FPCR.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
ExceptionBehavior
Exception behavior used for floating point operations.
Definition FPEnv.h:39
@ ebStrict
This corresponds to "fpexcept.strict".
Definition FPEnv.h:42
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI std::optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition FPEnv.cpp:39
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:1915
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:2182
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:761
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