LLVM 22.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
831 Value *Mask, Value *PassThru = nullptr,
832 const Twine &Name = "");
833
834 /// Create a call to Masked Store intrinsic
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
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 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1727 return CreateSelect(Cond1, Cond2,
1728 ConstantInt::getNullValue(Cond2->getType()), Name);
1729 }
1730
1731 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "") {
1732 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1733 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1734 Cond2, Name);
1735 }
1736
1738 const Twine &Name = "") {
1739 switch (Opc) {
1740 case Instruction::And:
1741 return CreateLogicalAnd(Cond1, Cond2, Name);
1742 case Instruction::Or:
1743 return CreateLogicalOr(Cond1, Cond2, Name);
1744 default:
1745 break;
1746 }
1747 llvm_unreachable("Not a logical operation.");
1748 }
1749
1750 // NOTE: this is sequential, non-commutative, ordered reduction!
1752 assert(!Ops.empty());
1753 Value *Accum = Ops[0];
1754 for (unsigned i = 1; i < Ops.size(); i++)
1755 Accum = CreateLogicalOr(Accum, Ops[i]);
1756 return Accum;
1757 }
1758
1759 /// This function is like @ref CreateIntrinsic for constrained fp
1760 /// intrinsics. It sets the rounding mode and exception behavior of
1761 /// the created intrinsic call according to \p Rounding and \p
1762 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1763 /// defaults if a value equals nullopt/null.
1766 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1767 std::optional<RoundingMode> Rounding = std::nullopt,
1768 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1769
1772 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1773 std::optional<RoundingMode> Rounding = std::nullopt,
1774 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1775
1777 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1778 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1779 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1780
1781 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1782 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1783 /*HasNUW=*/0, HasNSW);
1784 }
1785
1786 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1787 return CreateNeg(V, Name, /*HasNSW=*/true);
1788 }
1789
1790 Value *CreateFNeg(Value *V, const Twine &Name = "",
1791 MDNode *FPMathTag = nullptr) {
1792 return CreateFNegFMF(V, {}, Name, FPMathTag);
1793 }
1794
1796 MDNode *FPMathTag = nullptr) {
1797 if (Value *Res =
1798 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1799 return Res;
1800 return Insert(
1801 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1802 Name);
1803 }
1804
1805 Value *CreateNot(Value *V, const Twine &Name = "") {
1806 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1807 }
1808
1810 Value *V, const Twine &Name = "",
1811 MDNode *FPMathTag = nullptr) {
1812 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1813 return Res;
1815 if (isa<FPMathOperator>(UnOp))
1816 setFPAttrs(UnOp, FPMathTag, FMF);
1817 return Insert(UnOp, Name);
1818 }
1819
1820 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1821 /// Correct number of operands must be passed accordingly.
1823 const Twine &Name = "",
1824 MDNode *FPMathTag = nullptr);
1825
1826 //===--------------------------------------------------------------------===//
1827 // Instruction creation methods: Memory Instructions
1828 //===--------------------------------------------------------------------===//
1829
1830 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1831 Value *ArraySize = nullptr, const Twine &Name = "") {
1832 const DataLayout &DL = BB->getDataLayout();
1833 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1834 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1835 }
1836
1837 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1838 const Twine &Name = "") {
1839 const DataLayout &DL = BB->getDataLayout();
1840 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1841 unsigned AddrSpace = DL.getAllocaAddrSpace();
1842 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1843 }
1844
1845 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1846 /// converting the string to 'bool' for the isVolatile parameter.
1847 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1848 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1849 }
1850
1851 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1852 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1853 }
1854
1855 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1856 const Twine &Name = "") {
1857 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1858 }
1859
1860 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1861 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1862 }
1863
1865 const char *Name) {
1866 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1867 }
1868
1870 const Twine &Name = "") {
1871 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1872 }
1873
1875 bool isVolatile, const Twine &Name = "") {
1876 if (!Align) {
1877 const DataLayout &DL = BB->getDataLayout();
1878 Align = DL.getABITypeAlign(Ty);
1879 }
1880 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1881 }
1882
1884 bool isVolatile = false) {
1885 if (!Align) {
1886 const DataLayout &DL = BB->getDataLayout();
1887 Align = DL.getABITypeAlign(Val->getType());
1888 }
1889 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1890 }
1893 const Twine &Name = "") {
1894 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1895 }
1896
1899 AtomicOrdering SuccessOrdering,
1900 AtomicOrdering FailureOrdering,
1902 if (!Align) {
1903 const DataLayout &DL = BB->getDataLayout();
1904 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1905 }
1906
1907 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1908 FailureOrdering, SSID));
1909 }
1910
1912 Value *Val, MaybeAlign Align,
1913 AtomicOrdering Ordering,
1915 if (!Align) {
1916 const DataLayout &DL = BB->getDataLayout();
1917 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1918 }
1919
1920 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1921 }
1922
1924 const Twine &Name = "",
1926 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, NW))
1927 return V;
1928 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList, NW), Name);
1929 }
1930
1932 const Twine &Name = "") {
1933 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
1934 }
1935
1936 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1937 const Twine &Name = "") {
1938 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1939
1940 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1941 return V;
1942
1943 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1944 }
1945
1947 const Twine &Name = "") {
1948 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1949
1950 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
1951 return V;
1952
1953 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1954 }
1955
1956 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1957 const Twine &Name = "",
1959 Value *Idxs[] = {
1960 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1961 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1962 };
1963
1964 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, NWFlags))
1965 return V;
1966
1967 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs, NWFlags), Name);
1968 }
1969
1971 unsigned Idx1, const Twine &Name = "") {
1972 Value *Idxs[] = {
1973 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1974 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1975 };
1976
1977 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
1978 return V;
1979
1980 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1981 }
1982
1984 const Twine &Name = "") {
1985 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1986
1987 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1988 return V;
1989
1990 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1991 }
1992
1994 const Twine &Name = "") {
1995 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1996
1997 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
1998 return V;
1999
2000 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
2001 }
2002
2004 const Twine &Name = "") {
2005 Value *Idxs[] = {
2006 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2007 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2008 };
2009
2010 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::none()))
2011 return V;
2012
2013 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
2014 }
2015
2017 uint64_t Idx1, const Twine &Name = "") {
2018 Value *Idxs[] = {
2019 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2020 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2021 };
2022
2023 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
2024 return V;
2025
2026 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
2027 }
2028
2029 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2030 const Twine &Name = "") {
2031 GEPNoWrapFlags NWFlags =
2033 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2034 }
2035
2038 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
2039 }
2040
2042 const Twine &Name = "") {
2043 return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
2045 }
2046
2047 /// Same as CreateGlobalString, but return a pointer with "i8*" type
2048 /// instead of a pointer to array of i8.
2049 ///
2050 /// If no module is given via \p M, it is take from the insertion point basic
2051 /// block.
2052 LLVM_DEPRECATED("Use CreateGlobalString instead", "CreateGlobalString")
2054 unsigned AddressSpace = 0,
2055 Module *M = nullptr, bool AddNull = true) {
2056 GlobalVariable *GV =
2057 CreateGlobalString(Str, Name, AddressSpace, M, AddNull);
2058 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
2059 Constant *Indices[] = {Zero, Zero};
2061 Indices);
2062 }
2063
2064 //===--------------------------------------------------------------------===//
2065 // Instruction creation methods: Cast/Conversion Operators
2066 //===--------------------------------------------------------------------===//
2067
2068 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2069 bool IsNUW = false, bool IsNSW = false) {
2070 if (V->getType() == DestTy)
2071 return V;
2072 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2073 return Folded;
2074 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2075 if (IsNUW)
2076 I->setHasNoUnsignedWrap();
2077 if (IsNSW)
2078 I->setHasNoSignedWrap();
2079 return Insert(I, Name);
2080 }
2081
2082 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2083 bool IsNonNeg = false) {
2084 if (V->getType() == DestTy)
2085 return V;
2086 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2087 return Folded;
2088 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2089 if (IsNonNeg)
2090 I->setNonNeg();
2091 return I;
2092 }
2093
2094 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2095 return CreateCast(Instruction::SExt, V, DestTy, Name);
2096 }
2097
2098 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2099 /// the value untouched if the type of V is already DestTy.
2101 const Twine &Name = "") {
2102 assert(V->getType()->isIntOrIntVectorTy() &&
2103 DestTy->isIntOrIntVectorTy() &&
2104 "Can only zero extend/truncate integers!");
2105 Type *VTy = V->getType();
2106 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2107 return CreateZExt(V, DestTy, Name);
2108 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2109 return CreateTrunc(V, DestTy, Name);
2110 return V;
2111 }
2112
2113 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2114 /// the value untouched if the type of V is already DestTy.
2116 const Twine &Name = "") {
2117 assert(V->getType()->isIntOrIntVectorTy() &&
2118 DestTy->isIntOrIntVectorTy() &&
2119 "Can only sign extend/truncate integers!");
2120 Type *VTy = V->getType();
2121 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2122 return CreateSExt(V, DestTy, Name);
2123 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2124 return CreateTrunc(V, DestTy, Name);
2125 return V;
2126 }
2127
2128 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2129 if (IsFPConstrained)
2130 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2131 V, DestTy, nullptr, Name);
2132 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2133 }
2134
2135 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2136 if (IsFPConstrained)
2137 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2138 V, DestTy, nullptr, Name);
2139 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2140 }
2141
2142 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2143 bool IsNonNeg = false) {
2144 if (IsFPConstrained)
2145 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2146 V, DestTy, nullptr, Name);
2147 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2148 return Folded;
2149 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2150 if (IsNonNeg)
2151 I->setNonNeg();
2152 return I;
2153 }
2154
2155 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2156 if (IsFPConstrained)
2157 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2158 V, DestTy, nullptr, Name);
2159 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2160 }
2161
2162 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2163 MDNode *FPMathTag = nullptr) {
2164 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2165 }
2166
2168 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2169 if (IsFPConstrained)
2171 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2172 Name, FPMathTag);
2173 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2174 FMFSource);
2175 }
2176
2177 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2178 MDNode *FPMathTag = nullptr) {
2179 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2180 }
2181
2183 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2184 if (IsFPConstrained)
2185 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2186 V, DestTy, FMFSource, Name, FPMathTag);
2187 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2188 FMFSource);
2189 }
2190 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2191 return CreateCast(Instruction::PtrToInt, V,
2192 BB->getDataLayout().getAddressType(V->getType()), Name);
2193 }
2195 const Twine &Name = "") {
2196 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2197 }
2198
2200 const Twine &Name = "") {
2201 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2202 }
2203
2205 const Twine &Name = "") {
2206 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2207 }
2208
2210 const Twine &Name = "") {
2211 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2212 }
2213
2214 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2215 Instruction::CastOps CastOp =
2216 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2217 ? Instruction::BitCast
2218 : Instruction::ZExt;
2219 return CreateCast(CastOp, V, DestTy, Name);
2220 }
2221
2222 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2223 Instruction::CastOps CastOp =
2224 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2225 ? Instruction::BitCast
2226 : Instruction::SExt;
2227 return CreateCast(CastOp, V, DestTy, Name);
2228 }
2229
2230 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2231 Instruction::CastOps CastOp =
2232 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2233 ? Instruction::BitCast
2234 : Instruction::Trunc;
2235 return CreateCast(CastOp, V, DestTy, Name);
2236 }
2237
2239 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2240 FMFSource FMFSource = {}) {
2241 if (V->getType() == DestTy)
2242 return V;
2243 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2244 return Folded;
2245 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2246 if (isa<FPMathOperator>(Cast))
2247 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2248 return Insert(Cast, Name);
2249 }
2250
2252 const Twine &Name = "") {
2253 if (V->getType() == DestTy)
2254 return V;
2255 if (auto *VC = dyn_cast<Constant>(V))
2256 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2257 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2258 }
2259
2260 // With opaque pointers enabled, this can be substituted with
2261 // CreateAddrSpaceCast.
2262 // TODO: Replace uses of this method and remove the method itself.
2264 const Twine &Name = "") {
2265 if (V->getType() == DestTy)
2266 return V;
2267
2268 if (auto *VC = dyn_cast<Constant>(V)) {
2269 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2270 Name);
2271 }
2272
2274 Name);
2275 }
2276
2278 const Twine &Name = "") {
2279 Instruction::CastOps CastOp =
2280 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2281 ? Instruction::Trunc
2282 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2283 return CreateCast(CastOp, V, DestTy, Name);
2284 }
2285
2287 const Twine &Name = "") {
2288 if (V->getType() == DestTy)
2289 return V;
2290 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2291 return CreatePtrToInt(V, DestTy, Name);
2292 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2293 return CreateIntToPtr(V, DestTy, Name);
2294
2295 return CreateBitCast(V, DestTy, Name);
2296 }
2297
2298 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2299 MDNode *FPMathTag = nullptr) {
2300 Instruction::CastOps CastOp =
2301 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2302 ? Instruction::FPTrunc
2303 : Instruction::FPExt;
2304 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2305 }
2306
2308 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2309 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2310 std::optional<RoundingMode> Rounding = std::nullopt,
2311 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2312
2313 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2314 // compile time error, instead of converting the string to bool for the
2315 // isSigned parameter.
2316 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2317
2318 /// Cast between aggregate types that must have identical structure but may
2319 /// differ in their leaf types. The leaf values are recursively extracted,
2320 /// casted, and then reinserted into a value of type DestTy. The leaf types
2321 /// must be castable using a bitcast or ptrcast, because signedness is
2322 /// not specified.
2324
2325 //===--------------------------------------------------------------------===//
2326 // Instruction creation methods: Compare Instructions
2327 //===--------------------------------------------------------------------===//
2328
2329 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2330 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2331 }
2332
2333 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2334 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2335 }
2336
2337 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2338 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2339 }
2340
2341 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2342 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2343 }
2344
2345 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2346 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2347 }
2348
2349 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2350 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2351 }
2352
2353 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2354 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2355 }
2356
2357 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2358 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2359 }
2360
2361 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2362 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2363 }
2364
2365 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2366 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2367 }
2368
2369 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2370 MDNode *FPMathTag = nullptr) {
2371 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2372 }
2373
2374 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2375 MDNode *FPMathTag = nullptr) {
2376 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2377 }
2378
2379 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2380 MDNode *FPMathTag = nullptr) {
2381 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2382 }
2383
2384 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2385 MDNode *FPMathTag = nullptr) {
2386 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2387 }
2388
2389 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2390 MDNode *FPMathTag = nullptr) {
2391 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2392 }
2393
2394 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2395 MDNode *FPMathTag = nullptr) {
2396 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2397 }
2398
2399 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2400 MDNode *FPMathTag = nullptr) {
2401 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2402 }
2403
2404 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2405 MDNode *FPMathTag = nullptr) {
2406 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2407 }
2408
2409 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2410 MDNode *FPMathTag = nullptr) {
2411 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2412 }
2413
2414 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2415 MDNode *FPMathTag = nullptr) {
2416 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2417 }
2418
2419 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2420 MDNode *FPMathTag = nullptr) {
2421 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2422 }
2423
2424 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2425 MDNode *FPMathTag = nullptr) {
2426 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2427 }
2428
2429 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2430 MDNode *FPMathTag = nullptr) {
2431 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2432 }
2433
2434 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2435 MDNode *FPMathTag = nullptr) {
2436 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2437 }
2438
2440 const Twine &Name = "") {
2441 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2442 return V;
2443 return Insert(new ICmpInst(P, LHS, RHS), Name);
2444 }
2445
2446 // Create a quiet floating-point comparison (i.e. one that raises an FP
2447 // exception only in the case where an input is a signaling NaN).
2448 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2450 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2451 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2452 }
2453
2454 // Create a quiet floating-point comparison (i.e. one that raises an FP
2455 // exception only in the case where an input is a signaling NaN).
2456 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2458 FMFSource FMFSource, const Twine &Name = "",
2459 MDNode *FPMathTag = nullptr) {
2460 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2461 }
2462
2464 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2465 return CmpInst::isFPPredicate(Pred)
2466 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2467 : CreateICmp(Pred, LHS, RHS, Name);
2468 }
2469
2470 // Create a signaling floating-point comparison (i.e. one that raises an FP
2471 // exception whenever an input is any NaN, signaling or quiet).
2472 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2474 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2475 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2476 }
2477
2478private:
2479 // Helper routine to create either a signaling or a quiet FP comparison.
2480 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2481 const Twine &Name, MDNode *FPMathTag,
2482 FMFSource FMFSource, bool IsSignaling);
2483
2484public:
2487 const Twine &Name = "",
2488 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2489
2490 //===--------------------------------------------------------------------===//
2491 // Instruction creation methods: Other Instructions
2492 //===--------------------------------------------------------------------===//
2493
2494 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2495 const Twine &Name = "") {
2496 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2497 if (isa<FPMathOperator>(Phi))
2498 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2499 return Insert(Phi, Name);
2500 }
2501
2502private:
2503 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2504 const Twine &Name = "", FMFSource FMFSource = {},
2505 ArrayRef<OperandBundleDef> OpBundles = {});
2506
2507public:
2509 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2510 MDNode *FPMathTag = nullptr) {
2511 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2512 if (IsFPConstrained)
2514 if (isa<FPMathOperator>(CI))
2515 setFPAttrs(CI, FPMathTag, FMF);
2516 return Insert(CI, Name);
2517 }
2518
2521 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2522 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2523 if (IsFPConstrained)
2525 if (isa<FPMathOperator>(CI))
2526 setFPAttrs(CI, FPMathTag, FMF);
2527 return Insert(CI, Name);
2528 }
2529
2531 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2532 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2533 FPMathTag);
2534 }
2535
2538 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2539 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2540 OpBundles, Name, FPMathTag);
2541 }
2542
2544 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2545 std::optional<RoundingMode> Rounding = std::nullopt,
2546 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2547
2548 LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
2549 const Twine &Name = "",
2550 Instruction *MDFrom = nullptr);
2551 LLVM_ABI Value *CreateSelectFMF(Value *C, Value *True, Value *False,
2552 FMFSource FMFSource, const Twine &Name = "",
2553 Instruction *MDFrom = nullptr);
2554
2555 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2556 return Insert(new VAArgInst(List, Ty), Name);
2557 }
2558
2560 const Twine &Name = "") {
2561 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2562 return V;
2563 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2564 }
2565
2567 const Twine &Name = "") {
2568 return CreateExtractElement(Vec, getInt64(Idx), Name);
2569 }
2570
2571 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2572 const Twine &Name = "") {
2573 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2574 }
2575
2577 const Twine &Name = "") {
2578 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2579 }
2580
2582 const Twine &Name = "") {
2583 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2584 return V;
2585 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2586 }
2587
2589 const Twine &Name = "") {
2590 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2591 }
2592
2594 const Twine &Name = "") {
2595 SmallVector<int, 16> IntMask;
2597 return CreateShuffleVector(V1, V2, IntMask, Name);
2598 }
2599
2600 /// See class ShuffleVectorInst for a description of the mask representation.
2602 const Twine &Name = "") {
2603 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2604 return V;
2605 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2606 }
2607
2608 /// Create a unary shuffle. The second vector operand of the IR instruction
2609 /// is poison.
2611 const Twine &Name = "") {
2612 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2613 }
2614
2616 const Twine &Name = "");
2617
2619 const Twine &Name = "") {
2620 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2621 return V;
2622 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2623 }
2624
2626 const Twine &Name = "") {
2627 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2628 return V;
2629 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2630 }
2631
2632 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2633 const Twine &Name = "") {
2634 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2635 }
2636
2637 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2638 return Insert(new FreezeInst(V), Name);
2639 }
2640
2641 //===--------------------------------------------------------------------===//
2642 // Utility creation methods
2643 //===--------------------------------------------------------------------===//
2644
2645 /// Return a boolean value testing if \p Arg == 0.
2646 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2647 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2648 }
2649
2650 /// Return a boolean value testing if \p Arg != 0.
2651 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2652 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2653 }
2654
2655 /// Return a boolean value testing if \p Arg < 0.
2656 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2657 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2658 }
2659
2660 /// Return a boolean value testing if \p Arg > -1.
2661 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2663 Name);
2664 }
2665
2666 /// Return the i64 difference between two pointer values, dividing out
2667 /// the size of the pointed-to objects.
2668 ///
2669 /// This is intended to implement C-style pointer subtraction. As such, the
2670 /// pointers must be appropriately aligned for their element types and
2671 /// pointing into the same object.
2673 const Twine &Name = "");
2674
2675 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2676 /// different from pointer to i8, it's casted to pointer to i8 in the same
2677 /// address space before call and casted back to Ptr type after call.
2679
2680 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2681 /// different from pointer to i8, it's casted to pointer to i8 in the same
2682 /// address space before call and casted back to Ptr type after call.
2684
2685 /// Return a vector value that contains the vector V reversed
2686 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2687
2688 /// Return a vector splice intrinsic if using scalable vectors, otherwise
2689 /// return a shufflevector. If the immediate is positive, a vector is
2690 /// extracted from concat(V1, V2), starting at Imm. If the immediate
2691 /// is negative, we extract -Imm elements from V1 and the remaining
2692 /// elements from V2. Imm is a signed integer in the range
2693 /// -VL <= Imm < VL (where VL is the runtime vector length of the
2694 /// source/result vector)
2695 LLVM_ABI Value *CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
2696 const Twine &Name = "");
2697
2698 /// Return a vector value that contains \arg V broadcasted to \p
2699 /// NumElts elements.
2700 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2701 const Twine &Name = "");
2702
2703 /// Return a vector value that contains \arg V broadcasted to \p
2704 /// EC elements.
2706 const Twine &Name = "");
2707
2709 unsigned Dimension,
2710 unsigned LastIndex,
2711 MDNode *DbgInfo);
2712
2714 unsigned FieldIndex,
2715 MDNode *DbgInfo);
2716
2718 unsigned Index,
2719 unsigned FieldIndex,
2720 MDNode *DbgInfo);
2721
2722 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2723
2724private:
2725 /// Helper function that creates an assume intrinsic call that
2726 /// represents an alignment assumption on the provided pointer \p PtrValue
2727 /// with offset \p OffsetValue and alignment value \p AlignValue.
2728 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2729 Value *PtrValue, Value *AlignValue,
2730 Value *OffsetValue);
2731
2732public:
2733 /// Create an assume intrinsic call that represents an alignment
2734 /// assumption on the provided pointer.
2735 ///
2736 /// An optional offset can be provided, and if it is provided, the offset
2737 /// must be subtracted from the provided pointer to get the pointer with the
2738 /// specified alignment.
2740 Value *PtrValue,
2741 unsigned Alignment,
2742 Value *OffsetValue = nullptr);
2743
2744 /// Create an assume intrinsic call that represents an alignment
2745 /// assumption on the provided pointer.
2746 ///
2747 /// An optional offset can be provided, and if it is provided, the offset
2748 /// must be subtracted from the provided pointer to get the pointer with the
2749 /// specified alignment.
2750 ///
2751 /// This overload handles the condition where the Alignment is dependent
2752 /// on an existing value rather than a static value.
2754 Value *PtrValue,
2755 Value *Alignment,
2756 Value *OffsetValue = nullptr);
2757
2758 /// Create an assume intrinsic call that represents an dereferencable
2759 /// assumption on the provided pointer.
2761 Value *SizeValue);
2762};
2763
2764/// This provides a uniform API for creating instructions and inserting
2765/// them into a basic block: either at the end of a BasicBlock, or at a specific
2766/// iterator location in a block.
2767///
2768/// Note that the builder does not expose the full generality of LLVM
2769/// instructions. For access to extra instruction properties, use the mutators
2770/// (e.g. setVolatile) on the instructions after they have been
2771/// created. Convenience state exists to specify fast-math flags and fp-math
2772/// tags.
2773///
2774/// The first template argument specifies a class to use for creating constants.
2775/// This defaults to creating minimally folded constants. The second template
2776/// argument allows clients to specify custom insertion hooks that are called on
2777/// every newly created insertion.
2778template <typename FolderTy = ConstantFolder,
2779 typename InserterTy = IRBuilderDefaultInserter>
2780class IRBuilder : public IRBuilderBase {
2781private:
2782 FolderTy Folder;
2783 InserterTy Inserter;
2784
2785public:
2786 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter,
2787 MDNode *FPMathTag = nullptr,
2788 ArrayRef<OperandBundleDef> OpBundles = {})
2789 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2791
2792 IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag = nullptr,
2793 ArrayRef<OperandBundleDef> OpBundles = {})
2794 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2795 Folder(Folder) {}
2796
2797 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2798 ArrayRef<OperandBundleDef> OpBundles = {})
2799 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2800
2801 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2802 MDNode *FPMathTag = nullptr,
2803 ArrayRef<OperandBundleDef> OpBundles = {})
2804 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2805 FPMathTag, OpBundles),
2806 Folder(Folder) {
2807 SetInsertPoint(TheBB);
2808 }
2809
2810 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2811 ArrayRef<OperandBundleDef> OpBundles = {})
2812 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2813 FPMathTag, OpBundles) {
2814 SetInsertPoint(TheBB);
2815 }
2816
2817 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2818 ArrayRef<OperandBundleDef> OpBundles = {})
2819 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2820 OpBundles) {
2821 SetInsertPoint(IP);
2822 }
2823
2824 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2825 MDNode *FPMathTag = nullptr,
2826 ArrayRef<OperandBundleDef> OpBundles = {})
2827 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2828 FPMathTag, OpBundles),
2829 Folder(Folder) {
2830 SetInsertPoint(TheBB, IP);
2831 }
2832
2834 MDNode *FPMathTag = nullptr,
2835 ArrayRef<OperandBundleDef> OpBundles = {})
2836 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2837 FPMathTag, OpBundles) {
2838 SetInsertPoint(TheBB, IP);
2839 }
2840
2841 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2842 /// or FastMathFlagGuard instead.
2843 IRBuilder(const IRBuilder &) = delete;
2844
2845 InserterTy &getInserter() { return Inserter; }
2846 const InserterTy &getInserter() const { return Inserter; }
2847};
2848
2849template <typename FolderTy, typename InserterTy>
2850IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2853template <typename FolderTy>
2858template <typename FolderTy>
2863
2864
2865// Create wrappers for C Binding types (see CBindingWrapping.h).
2867
2868} // end namespace llvm
2869
2870#endif // LLVM_IR_IRBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
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_DEPRECATED(MSG, FIX)
Definition Compiler.h:252
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isSigned(unsigned int Opcode)
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:55
#define I(x, y, z)
Definition MD5.cpp:58
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.
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:41
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:472
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:678
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:681
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:695
@ ICMP_SLT
signed less than
Definition InstrTypes.h:707
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:708
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:684
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:693
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:682
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:683
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:702
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:701
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:705
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:692
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:686
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:689
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:703
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:690
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:685
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:687
@ ICMP_NE
not equal
Definition InstrTypes.h:700
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:706
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:694
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:704
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:691
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:680
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:688
bool isFPPredicate() const
Definition InstrTypes.h:784
static LLVM_ABI StringRef getPredicateName(Predicate P)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition Constants.h:1301
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:63
A debug info location.
Definition DebugLoc.h:124
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)
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Type * getValueType() const
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:2214
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2394
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:2473
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:2345
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2167
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1983
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
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2419
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2576
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:1869
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:2449
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:2571
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:1898
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:1936
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1830
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:2625
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:58
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2536
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:2155
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:1855
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1751
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2559
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="")
Definition IRBuilder.h:1737
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:2353
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:1864
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2399
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:2100
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:2162
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:2251
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:2190
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:2618
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:2632
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2182
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:2357
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:2128
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2003
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2434
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:202
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2029
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1891
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:2094
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2222
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2414
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2199
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:2637
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:1946
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:71
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:2036
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2238
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2661
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:2142
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:2384
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:1931
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:2263
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:2610
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:2429
FastMathFlags FMF
Definition IRBuilder.h:153
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2333
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:2457
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:1923
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:1809
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1781
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1851
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
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:2588
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:2601
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:2389
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.
Constant * CreateGlobalStringPtr(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr, bool AddNull=true)
Same as CreateGlobalString, but return a pointer with "i8*" type instead of a pointer to array of i8.
Definition IRBuilder.h:2053
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:2286
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2463
const IRBuilderDefaultInserter & Inserter
Definition IRBuilder.h:150
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2298
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2365
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2494
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2519
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1805
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:2329
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:2409
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:63
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:2656
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:2204
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:2337
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:1847
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:2082
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:2593
LLVMContext & getContext() const
Definition IRBuilder.h:203
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2369
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:1970
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2016
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:1860
LLVM_ABI CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
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:2194
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:2555
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:2651
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:2508
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:1911
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:2068
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 * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition IRBuilder.h:1725
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2581
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1993
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:2361
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:2341
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:2277
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2404
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:2646
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:2374
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
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1837
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:1956
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2566
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1883
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:2041
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2177
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:2530
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1795
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:2230
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2349
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2439
LLVM_ABI CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition IRBuilder.h:1731
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:1874
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1790
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:64
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:2115
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1308
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2209
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:43
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition IRBuilder.h:1786
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:2379
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:2424
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:2135
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:2780
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2797
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2792
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2786
InserterTy & getInserter()
Definition IRBuilder.h:2845
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2817
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2801
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2824
const InserterTy & getInserter() const
Definition IRBuilder.h:2846
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2833
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2810
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:1077
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1565
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:607
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:103
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h: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:298
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:297
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:281
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:295
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:296
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:231
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:294
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:301
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:286
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:285
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:284
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:283
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.
@ Offset
Definition DWP.cpp:477
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:649
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:37
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:74
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:548
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:1869
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
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:2122
@ 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:851
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:760
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:117