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 Instruction *MDFrom = nullptr) {
1727 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1728 return CreateSelect(Cond1, Cond2,
1729 ConstantInt::getNullValue(Cond2->getType()), Name,
1730 MDFrom);
1731 }
1732
1733 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
1734 Instruction *MDFrom = nullptr) {
1735 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1736 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1737 Cond2, Name, MDFrom);
1738 }
1739
1741 const Twine &Name = "") {
1742 switch (Opc) {
1743 case Instruction::And:
1744 return CreateLogicalAnd(Cond1, Cond2, Name);
1745 case Instruction::Or:
1746 return CreateLogicalOr(Cond1, Cond2, Name);
1747 default:
1748 break;
1749 }
1750 llvm_unreachable("Not a logical operation.");
1751 }
1752
1753 // NOTE: this is sequential, non-commutative, ordered reduction!
1755 assert(!Ops.empty());
1756 Value *Accum = Ops[0];
1757 for (unsigned i = 1; i < Ops.size(); i++)
1758 Accum = CreateLogicalOr(Accum, Ops[i]);
1759 return Accum;
1760 }
1761
1762 /// This function is like @ref CreateIntrinsic for constrained fp
1763 /// intrinsics. It sets the rounding mode and exception behavior of
1764 /// the created intrinsic call according to \p Rounding and \p
1765 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1766 /// defaults if a value equals nullopt/null.
1769 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1770 std::optional<RoundingMode> Rounding = std::nullopt,
1771 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1772
1775 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1776 std::optional<RoundingMode> Rounding = std::nullopt,
1777 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1778
1780 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1781 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1782 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1783
1784 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1785 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1786 /*HasNUW=*/0, HasNSW);
1787 }
1788
1789 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1790 return CreateNeg(V, Name, /*HasNSW=*/true);
1791 }
1792
1793 Value *CreateFNeg(Value *V, const Twine &Name = "",
1794 MDNode *FPMathTag = nullptr) {
1795 return CreateFNegFMF(V, {}, Name, FPMathTag);
1796 }
1797
1799 MDNode *FPMathTag = nullptr) {
1800 if (Value *Res =
1801 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1802 return Res;
1803 return Insert(
1804 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1805 Name);
1806 }
1807
1808 Value *CreateNot(Value *V, const Twine &Name = "") {
1809 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1810 }
1811
1813 Value *V, const Twine &Name = "",
1814 MDNode *FPMathTag = nullptr) {
1815 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1816 return Res;
1818 if (isa<FPMathOperator>(UnOp))
1819 setFPAttrs(UnOp, FPMathTag, FMF);
1820 return Insert(UnOp, Name);
1821 }
1822
1823 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1824 /// Correct number of operands must be passed accordingly.
1826 const Twine &Name = "",
1827 MDNode *FPMathTag = nullptr);
1828
1829 //===--------------------------------------------------------------------===//
1830 // Instruction creation methods: Memory Instructions
1831 //===--------------------------------------------------------------------===//
1832
1833 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1834 Value *ArraySize = nullptr, const Twine &Name = "") {
1835 const DataLayout &DL = BB->getDataLayout();
1836 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1837 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1838 }
1839
1840 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1841 const Twine &Name = "") {
1842 const DataLayout &DL = BB->getDataLayout();
1843 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1844 unsigned AddrSpace = DL.getAllocaAddrSpace();
1845 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1846 }
1847
1848 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1849 /// converting the string to 'bool' for the isVolatile parameter.
1850 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1851 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1852 }
1853
1854 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1855 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1856 }
1857
1858 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1859 const Twine &Name = "") {
1860 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1861 }
1862
1863 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1864 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1865 }
1866
1868 const char *Name) {
1869 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1870 }
1871
1873 const Twine &Name = "") {
1874 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1875 }
1876
1878 bool isVolatile, const Twine &Name = "") {
1879 if (!Align) {
1880 const DataLayout &DL = BB->getDataLayout();
1881 Align = DL.getABITypeAlign(Ty);
1882 }
1883 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1884 }
1885
1887 bool isVolatile = false) {
1888 if (!Align) {
1889 const DataLayout &DL = BB->getDataLayout();
1890 Align = DL.getABITypeAlign(Val->getType());
1891 }
1892 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1893 }
1896 const Twine &Name = "") {
1897 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1898 }
1899
1902 AtomicOrdering SuccessOrdering,
1903 AtomicOrdering FailureOrdering,
1905 if (!Align) {
1906 const DataLayout &DL = BB->getDataLayout();
1907 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1908 }
1909
1910 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1911 FailureOrdering, SSID));
1912 }
1913
1915 Value *Val, MaybeAlign Align,
1916 AtomicOrdering Ordering,
1918 if (!Align) {
1919 const DataLayout &DL = BB->getDataLayout();
1920 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1921 }
1922
1923 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1924 }
1925
1927 const Twine &Name = "",
1929 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, NW))
1930 return V;
1931 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList, NW), Name);
1932 }
1933
1935 const Twine &Name = "") {
1936 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
1937 }
1938
1939 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1940 const Twine &Name = "") {
1941 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1942
1943 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1944 return V;
1945
1946 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1947 }
1948
1950 const Twine &Name = "") {
1951 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1952
1953 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
1954 return V;
1955
1956 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1957 }
1958
1959 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1960 const Twine &Name = "",
1962 Value *Idxs[] = {
1963 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1964 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1965 };
1966
1967 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, NWFlags))
1968 return V;
1969
1970 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs, NWFlags), Name);
1971 }
1972
1974 unsigned Idx1, const Twine &Name = "") {
1975 Value *Idxs[] = {
1976 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1977 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1978 };
1979
1980 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
1981 return V;
1982
1983 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1984 }
1985
1987 const Twine &Name = "") {
1988 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1989
1990 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1991 return V;
1992
1993 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1994 }
1995
1997 const Twine &Name = "") {
1998 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1999
2000 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
2001 return V;
2002
2003 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
2004 }
2005
2007 const Twine &Name = "") {
2008 Value *Idxs[] = {
2009 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2010 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2011 };
2012
2013 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::none()))
2014 return V;
2015
2016 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
2017 }
2018
2020 uint64_t Idx1, const Twine &Name = "") {
2021 Value *Idxs[] = {
2022 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2023 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2024 };
2025
2026 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
2027 return V;
2028
2029 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
2030 }
2031
2032 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2033 const Twine &Name = "") {
2034 GEPNoWrapFlags NWFlags =
2036 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2037 }
2038
2041 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
2042 }
2043
2045 const Twine &Name = "") {
2046 return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
2048 }
2049
2050 /// Same as CreateGlobalString, but return a pointer with "i8*" type
2051 /// instead of a pointer to array of i8.
2052 ///
2053 /// If no module is given via \p M, it is take from the insertion point basic
2054 /// block.
2055 LLVM_DEPRECATED("Use CreateGlobalString instead", "CreateGlobalString")
2057 unsigned AddressSpace = 0,
2058 Module *M = nullptr, bool AddNull = true) {
2059 GlobalVariable *GV =
2060 CreateGlobalString(Str, Name, AddressSpace, M, AddNull);
2061 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
2062 Constant *Indices[] = {Zero, Zero};
2064 Indices);
2065 }
2066
2067 //===--------------------------------------------------------------------===//
2068 // Instruction creation methods: Cast/Conversion Operators
2069 //===--------------------------------------------------------------------===//
2070
2071 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2072 bool IsNUW = false, bool IsNSW = false) {
2073 if (V->getType() == DestTy)
2074 return V;
2075 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2076 return Folded;
2077 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2078 if (IsNUW)
2079 I->setHasNoUnsignedWrap();
2080 if (IsNSW)
2081 I->setHasNoSignedWrap();
2082 return Insert(I, Name);
2083 }
2084
2085 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2086 bool IsNonNeg = false) {
2087 if (V->getType() == DestTy)
2088 return V;
2089 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2090 return Folded;
2091 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2092 if (IsNonNeg)
2093 I->setNonNeg();
2094 return I;
2095 }
2096
2097 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2098 return CreateCast(Instruction::SExt, V, DestTy, Name);
2099 }
2100
2101 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2102 /// the value untouched if the type of V is already DestTy.
2104 const Twine &Name = "") {
2105 assert(V->getType()->isIntOrIntVectorTy() &&
2106 DestTy->isIntOrIntVectorTy() &&
2107 "Can only zero extend/truncate integers!");
2108 Type *VTy = V->getType();
2109 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2110 return CreateZExt(V, DestTy, Name);
2111 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2112 return CreateTrunc(V, DestTy, Name);
2113 return V;
2114 }
2115
2116 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2117 /// the value untouched if the type of V is already DestTy.
2119 const Twine &Name = "") {
2120 assert(V->getType()->isIntOrIntVectorTy() &&
2121 DestTy->isIntOrIntVectorTy() &&
2122 "Can only sign extend/truncate integers!");
2123 Type *VTy = V->getType();
2124 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2125 return CreateSExt(V, DestTy, Name);
2126 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2127 return CreateTrunc(V, DestTy, Name);
2128 return V;
2129 }
2130
2131 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2132 if (IsFPConstrained)
2133 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2134 V, DestTy, nullptr, Name);
2135 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2136 }
2137
2138 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2139 if (IsFPConstrained)
2140 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2141 V, DestTy, nullptr, Name);
2142 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2143 }
2144
2145 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2146 bool IsNonNeg = false) {
2147 if (IsFPConstrained)
2148 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2149 V, DestTy, nullptr, Name);
2150 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2151 return Folded;
2152 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2153 if (IsNonNeg)
2154 I->setNonNeg();
2155 return I;
2156 }
2157
2158 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2159 if (IsFPConstrained)
2160 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2161 V, DestTy, nullptr, Name);
2162 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2163 }
2164
2165 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2166 MDNode *FPMathTag = nullptr) {
2167 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2168 }
2169
2171 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2172 if (IsFPConstrained)
2174 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2175 Name, FPMathTag);
2176 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2177 FMFSource);
2178 }
2179
2180 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2181 MDNode *FPMathTag = nullptr) {
2182 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2183 }
2184
2186 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2187 if (IsFPConstrained)
2188 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2189 V, DestTy, FMFSource, Name, FPMathTag);
2190 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2191 FMFSource);
2192 }
2193 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2194 return CreateCast(Instruction::PtrToInt, V,
2195 BB->getDataLayout().getAddressType(V->getType()), Name);
2196 }
2198 const Twine &Name = "") {
2199 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2200 }
2201
2203 const Twine &Name = "") {
2204 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2205 }
2206
2208 const Twine &Name = "") {
2209 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2210 }
2211
2213 const Twine &Name = "") {
2214 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2215 }
2216
2217 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2218 Instruction::CastOps CastOp =
2219 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2220 ? Instruction::BitCast
2221 : Instruction::ZExt;
2222 return CreateCast(CastOp, V, DestTy, Name);
2223 }
2224
2225 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2226 Instruction::CastOps CastOp =
2227 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2228 ? Instruction::BitCast
2229 : Instruction::SExt;
2230 return CreateCast(CastOp, V, DestTy, Name);
2231 }
2232
2233 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2234 Instruction::CastOps CastOp =
2235 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2236 ? Instruction::BitCast
2237 : Instruction::Trunc;
2238 return CreateCast(CastOp, V, DestTy, Name);
2239 }
2240
2242 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2243 FMFSource FMFSource = {}) {
2244 if (V->getType() == DestTy)
2245 return V;
2246 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2247 return Folded;
2248 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2249 if (isa<FPMathOperator>(Cast))
2250 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2251 return Insert(Cast, Name);
2252 }
2253
2255 const Twine &Name = "") {
2256 if (V->getType() == DestTy)
2257 return V;
2258 if (auto *VC = dyn_cast<Constant>(V))
2259 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2260 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2261 }
2262
2263 // With opaque pointers enabled, this can be substituted with
2264 // CreateAddrSpaceCast.
2265 // TODO: Replace uses of this method and remove the method itself.
2267 const Twine &Name = "") {
2268 if (V->getType() == DestTy)
2269 return V;
2270
2271 if (auto *VC = dyn_cast<Constant>(V)) {
2272 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2273 Name);
2274 }
2275
2277 Name);
2278 }
2279
2281 const Twine &Name = "") {
2282 Instruction::CastOps CastOp =
2283 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2284 ? Instruction::Trunc
2285 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2286 return CreateCast(CastOp, V, DestTy, Name);
2287 }
2288
2290 const Twine &Name = "") {
2291 if (V->getType() == DestTy)
2292 return V;
2293 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2294 return CreatePtrToInt(V, DestTy, Name);
2295 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2296 return CreateIntToPtr(V, DestTy, Name);
2297
2298 return CreateBitCast(V, DestTy, Name);
2299 }
2300
2301 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2302 MDNode *FPMathTag = nullptr) {
2303 Instruction::CastOps CastOp =
2304 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2305 ? Instruction::FPTrunc
2306 : Instruction::FPExt;
2307 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2308 }
2309
2311 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2312 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2313 std::optional<RoundingMode> Rounding = std::nullopt,
2314 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2315
2316 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2317 // compile time error, instead of converting the string to bool for the
2318 // isSigned parameter.
2319 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2320
2321 /// Cast between aggregate types that must have identical structure but may
2322 /// differ in their leaf types. The leaf values are recursively extracted,
2323 /// casted, and then reinserted into a value of type DestTy. The leaf types
2324 /// must be castable using a bitcast or ptrcast, because signedness is
2325 /// not specified.
2327
2328 //===--------------------------------------------------------------------===//
2329 // Instruction creation methods: Compare Instructions
2330 //===--------------------------------------------------------------------===//
2331
2332 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2333 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2334 }
2335
2336 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2337 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2338 }
2339
2340 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2341 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2342 }
2343
2344 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2345 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2346 }
2347
2348 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2349 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2350 }
2351
2352 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2353 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2354 }
2355
2356 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2357 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2358 }
2359
2360 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2361 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2362 }
2363
2364 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2365 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2366 }
2367
2368 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2369 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2370 }
2371
2372 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2373 MDNode *FPMathTag = nullptr) {
2374 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2375 }
2376
2377 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2378 MDNode *FPMathTag = nullptr) {
2379 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2380 }
2381
2382 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2383 MDNode *FPMathTag = nullptr) {
2384 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2385 }
2386
2387 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2388 MDNode *FPMathTag = nullptr) {
2389 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2390 }
2391
2392 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2393 MDNode *FPMathTag = nullptr) {
2394 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2395 }
2396
2397 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2398 MDNode *FPMathTag = nullptr) {
2399 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2400 }
2401
2402 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2403 MDNode *FPMathTag = nullptr) {
2404 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2405 }
2406
2407 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2408 MDNode *FPMathTag = nullptr) {
2409 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2410 }
2411
2412 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2413 MDNode *FPMathTag = nullptr) {
2414 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2415 }
2416
2417 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2418 MDNode *FPMathTag = nullptr) {
2419 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2420 }
2421
2422 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2423 MDNode *FPMathTag = nullptr) {
2424 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2425 }
2426
2427 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2428 MDNode *FPMathTag = nullptr) {
2429 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2430 }
2431
2432 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2433 MDNode *FPMathTag = nullptr) {
2434 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2435 }
2436
2437 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2438 MDNode *FPMathTag = nullptr) {
2439 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2440 }
2441
2443 const Twine &Name = "") {
2444 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2445 return V;
2446 return Insert(new ICmpInst(P, LHS, RHS), Name);
2447 }
2448
2449 // Create a quiet floating-point comparison (i.e. one that raises an FP
2450 // exception only in the case where an input is a signaling NaN).
2451 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2453 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2454 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2455 }
2456
2457 // Create a quiet floating-point comparison (i.e. one that raises an FP
2458 // exception only in the case where an input is a signaling NaN).
2459 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2461 FMFSource FMFSource, const Twine &Name = "",
2462 MDNode *FPMathTag = nullptr) {
2463 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2464 }
2465
2467 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2468 return CmpInst::isFPPredicate(Pred)
2469 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2470 : CreateICmp(Pred, LHS, RHS, Name);
2471 }
2472
2473 // Create a signaling floating-point comparison (i.e. one that raises an FP
2474 // exception whenever an input is any NaN, signaling or quiet).
2475 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2477 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2478 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2479 }
2480
2481private:
2482 // Helper routine to create either a signaling or a quiet FP comparison.
2483 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2484 const Twine &Name, MDNode *FPMathTag,
2485 FMFSource FMFSource, bool IsSignaling);
2486
2487public:
2490 const Twine &Name = "",
2491 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2492
2493 //===--------------------------------------------------------------------===//
2494 // Instruction creation methods: Other Instructions
2495 //===--------------------------------------------------------------------===//
2496
2497 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2498 const Twine &Name = "") {
2499 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2500 if (isa<FPMathOperator>(Phi))
2501 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2502 return Insert(Phi, Name);
2503 }
2504
2505private:
2506 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2507 const Twine &Name = "", FMFSource FMFSource = {},
2508 ArrayRef<OperandBundleDef> OpBundles = {});
2509
2510public:
2512 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2513 MDNode *FPMathTag = nullptr) {
2514 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2515 if (IsFPConstrained)
2517 if (isa<FPMathOperator>(CI))
2518 setFPAttrs(CI, FPMathTag, FMF);
2519 return Insert(CI, Name);
2520 }
2521
2524 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2525 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2526 if (IsFPConstrained)
2528 if (isa<FPMathOperator>(CI))
2529 setFPAttrs(CI, FPMathTag, FMF);
2530 return Insert(CI, Name);
2531 }
2532
2534 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2535 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2536 FPMathTag);
2537 }
2538
2541 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2542 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2543 OpBundles, Name, FPMathTag);
2544 }
2545
2547 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2548 std::optional<RoundingMode> Rounding = std::nullopt,
2549 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2550
2551 LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
2552 const Twine &Name = "",
2553 Instruction *MDFrom = nullptr);
2554 LLVM_ABI Value *CreateSelectFMF(Value *C, Value *True, Value *False,
2555 FMFSource FMFSource, const Twine &Name = "",
2556 Instruction *MDFrom = nullptr);
2557
2558 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2559 return Insert(new VAArgInst(List, Ty), Name);
2560 }
2561
2563 const Twine &Name = "") {
2564 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2565 return V;
2566 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2567 }
2568
2570 const Twine &Name = "") {
2571 return CreateExtractElement(Vec, getInt64(Idx), Name);
2572 }
2573
2574 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2575 const Twine &Name = "") {
2576 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2577 }
2578
2580 const Twine &Name = "") {
2581 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2582 }
2583
2585 const Twine &Name = "") {
2586 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2587 return V;
2588 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2589 }
2590
2592 const Twine &Name = "") {
2593 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2594 }
2595
2597 const Twine &Name = "") {
2598 SmallVector<int, 16> IntMask;
2600 return CreateShuffleVector(V1, V2, IntMask, Name);
2601 }
2602
2603 /// See class ShuffleVectorInst for a description of the mask representation.
2605 const Twine &Name = "") {
2606 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2607 return V;
2608 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2609 }
2610
2611 /// Create a unary shuffle. The second vector operand of the IR instruction
2612 /// is poison.
2614 const Twine &Name = "") {
2615 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2616 }
2617
2619 const Twine &Name = "");
2620
2622 const Twine &Name = "") {
2623 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2624 return V;
2625 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2626 }
2627
2629 const Twine &Name = "") {
2630 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2631 return V;
2632 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2633 }
2634
2635 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2636 const Twine &Name = "") {
2637 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2638 }
2639
2640 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2641 return Insert(new FreezeInst(V), Name);
2642 }
2643
2644 //===--------------------------------------------------------------------===//
2645 // Utility creation methods
2646 //===--------------------------------------------------------------------===//
2647
2648 /// Return a boolean value testing if \p Arg == 0.
2649 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2650 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2651 }
2652
2653 /// Return a boolean value testing if \p Arg != 0.
2654 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2655 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2656 }
2657
2658 /// Return a boolean value testing if \p Arg < 0.
2659 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2660 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2661 }
2662
2663 /// Return a boolean value testing if \p Arg > -1.
2664 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2666 Name);
2667 }
2668
2669 /// Return the i64 difference between two pointer values, dividing out
2670 /// the size of the pointed-to objects.
2671 ///
2672 /// This is intended to implement C-style pointer subtraction. As such, the
2673 /// pointers must be appropriately aligned for their element types and
2674 /// pointing into the same object.
2676 const Twine &Name = "");
2677
2678 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2679 /// different from pointer to i8, it's casted to pointer to i8 in the same
2680 /// address space before call and casted back to Ptr type after call.
2682
2683 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2684 /// different from pointer to i8, it's casted to pointer to i8 in the same
2685 /// address space before call and casted back to Ptr type after call.
2687
2688 /// Return a vector value that contains the vector V reversed
2689 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2690
2691 /// Return a vector splice intrinsic if using scalable vectors, otherwise
2692 /// return a shufflevector. If the immediate is positive, a vector is
2693 /// extracted from concat(V1, V2), starting at Imm. If the immediate
2694 /// is negative, we extract -Imm elements from V1 and the remaining
2695 /// elements from V2. Imm is a signed integer in the range
2696 /// -VL <= Imm < VL (where VL is the runtime vector length of the
2697 /// source/result vector)
2698 LLVM_ABI Value *CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
2699 const Twine &Name = "");
2700
2701 /// Return a vector value that contains \arg V broadcasted to \p
2702 /// NumElts elements.
2703 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2704 const Twine &Name = "");
2705
2706 /// Return a vector value that contains \arg V broadcasted to \p
2707 /// EC elements.
2709 const Twine &Name = "");
2710
2712 unsigned Dimension,
2713 unsigned LastIndex,
2714 MDNode *DbgInfo);
2715
2717 unsigned FieldIndex,
2718 MDNode *DbgInfo);
2719
2721 unsigned Index,
2722 unsigned FieldIndex,
2723 MDNode *DbgInfo);
2724
2725 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2726
2727private:
2728 /// Helper function that creates an assume intrinsic call that
2729 /// represents an alignment assumption on the provided pointer \p PtrValue
2730 /// with offset \p OffsetValue and alignment value \p AlignValue.
2731 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2732 Value *PtrValue, Value *AlignValue,
2733 Value *OffsetValue);
2734
2735public:
2736 /// Create an assume intrinsic call that represents an alignment
2737 /// assumption on the provided pointer.
2738 ///
2739 /// An optional offset can be provided, and if it is provided, the offset
2740 /// must be subtracted from the provided pointer to get the pointer with the
2741 /// specified alignment.
2743 Value *PtrValue,
2744 unsigned Alignment,
2745 Value *OffsetValue = nullptr);
2746
2747 /// Create an assume intrinsic call that represents an alignment
2748 /// assumption on the provided pointer.
2749 ///
2750 /// An optional offset can be provided, and if it is provided, the offset
2751 /// must be subtracted from the provided pointer to get the pointer with the
2752 /// specified alignment.
2753 ///
2754 /// This overload handles the condition where the Alignment is dependent
2755 /// on an existing value rather than a static value.
2757 Value *PtrValue,
2758 Value *Alignment,
2759 Value *OffsetValue = nullptr);
2760
2761 /// Create an assume intrinsic call that represents an dereferencable
2762 /// assumption on the provided pointer.
2764 Value *SizeValue);
2765};
2766
2767/// This provides a uniform API for creating instructions and inserting
2768/// them into a basic block: either at the end of a BasicBlock, or at a specific
2769/// iterator location in a block.
2770///
2771/// Note that the builder does not expose the full generality of LLVM
2772/// instructions. For access to extra instruction properties, use the mutators
2773/// (e.g. setVolatile) on the instructions after they have been
2774/// created. Convenience state exists to specify fast-math flags and fp-math
2775/// tags.
2776///
2777/// The first template argument specifies a class to use for creating constants.
2778/// This defaults to creating minimally folded constants. The second template
2779/// argument allows clients to specify custom insertion hooks that are called on
2780/// every newly created insertion.
2781template <typename FolderTy = ConstantFolder,
2782 typename InserterTy = IRBuilderDefaultInserter>
2783class IRBuilder : public IRBuilderBase {
2784private:
2785 FolderTy Folder;
2786 InserterTy Inserter;
2787
2788public:
2789 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter,
2790 MDNode *FPMathTag = nullptr,
2791 ArrayRef<OperandBundleDef> OpBundles = {})
2792 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2794
2795 IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag = nullptr,
2796 ArrayRef<OperandBundleDef> OpBundles = {})
2797 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2798 Folder(Folder) {}
2799
2800 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2801 ArrayRef<OperandBundleDef> OpBundles = {})
2802 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2803
2804 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2805 MDNode *FPMathTag = nullptr,
2806 ArrayRef<OperandBundleDef> OpBundles = {})
2807 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2808 FPMathTag, OpBundles),
2809 Folder(Folder) {
2810 SetInsertPoint(TheBB);
2811 }
2812
2813 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2814 ArrayRef<OperandBundleDef> OpBundles = {})
2815 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2816 FPMathTag, OpBundles) {
2817 SetInsertPoint(TheBB);
2818 }
2819
2820 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2821 ArrayRef<OperandBundleDef> OpBundles = {})
2822 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2823 OpBundles) {
2824 SetInsertPoint(IP);
2825 }
2826
2827 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2828 MDNode *FPMathTag = nullptr,
2829 ArrayRef<OperandBundleDef> OpBundles = {})
2830 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2831 FPMathTag, OpBundles),
2832 Folder(Folder) {
2833 SetInsertPoint(TheBB, IP);
2834 }
2835
2837 MDNode *FPMathTag = nullptr,
2838 ArrayRef<OperandBundleDef> OpBundles = {})
2839 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2840 FPMathTag, OpBundles) {
2841 SetInsertPoint(TheBB, IP);
2842 }
2843
2844 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2845 /// or FastMathFlagGuard instead.
2846 IRBuilder(const IRBuilder &) = delete;
2847
2848 InserterTy &getInserter() { return Inserter; }
2849 const InserterTy &getInserter() const { return Inserter; }
2850};
2851
2852template <typename FolderTy, typename InserterTy>
2853IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2856template <typename FolderTy>
2861template <typename FolderTy>
2866
2867
2868// Create wrappers for C Binding types (see CBindingWrapping.h).
2870
2871} // end namespace llvm
2872
2873#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:676
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:679
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:693
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:682
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:691
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:680
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:681
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:690
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:684
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:687
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:688
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:683
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:698
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:692
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:689
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:678
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:686
bool isFPPredicate() const
Definition InstrTypes.h:782
static LLVM_ABI StringRef getPredicateName(Predicate P)
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:2217
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2397
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
Definition IRBuilder.h: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:2476
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:2348
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2170
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1986
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:2422
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2579
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1486
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition IRBuilder.h:1872
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1632
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2452
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:2574
void SetNoSanitizeMetadata()
Set nosanitize metadata.
Definition IRBuilder.h:254
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1527
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1901
LLVM_ABI CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition IRBuilder.h:1939
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1833
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition IRBuilder.h:399
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition IRBuilder.h:1121
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1257
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:547
LLVM_ABI CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2628
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:2539
LLVM_ABI CallInst * CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.pointer.base intrinsic to get the base pointer for the specified...
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h: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:2158
LLVM_ABI CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef< Value * > CallArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create a call to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1858
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1754
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2562
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="")
Definition IRBuilder.h:1740
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition IRBuilder.h:575
void setDefaultConstrainedExcept(fp::ExceptionBehavior NewExcept)
Set the exception handling to be used with constrained floating point.
Definition IRBuilder.h:357
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2356
LLVM_ABI CallInst * CreateLifetimeEnd(Value *Ptr)
Create a lifetime.end intrinsic.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition IRBuilder.h:1867
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2402
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:2103
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:2165
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:2254
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:2193
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:2621
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:2635
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2185
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:2360
LLVM_ABI CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVMContext & Context
Definition IRBuilder.h:148
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
Definition IRBuilder.h: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:2131
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2006
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2437
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:202
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2032
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1894
IntegerType * getIndexTy(const DataLayout &DL, unsigned AddrSpace)
Fetch the type of an integer that should be used to index GEP operations within AddressSpace.
Definition IRBuilder.h:617
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1299
LLVM_ABI CallInst * CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.get.pointer.offset intrinsic to get the offset of the specified ...
fp::ExceptionBehavior getDefaultConstrainedExcept()
Get the exception handling used with constrained floating point.
Definition IRBuilder.h:377
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2097
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2225
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2417
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2202
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:2640
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:1949
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:2039
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2241
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2664
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:2145
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:2387
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition IRBuilder.h:247
void SetInsertPointPastAllocas(Function *F)
This specifies that created instructions should inserted at the beginning end of the specified functi...
Definition IRBuilder.h:241
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:567
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition IRBuilder.h:1934
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1446
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition IRBuilder.h:316
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1583
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memmove between the specified pointers.
Value * CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2266
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:2613
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:2432
FastMathFlags FMF
Definition IRBuilder.h:153
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2336
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h: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:2460
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:1926
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:527
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:729
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition IRBuilder.h:1317
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition IRBuilder.h:862
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1812
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1784
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1854
LLVM_ABI CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
InsertPoint saveIP() const
Returns the current insert point.
Definition IRBuilder.h:311
void CollectMetadataToCopy(Instruction *Src, ArrayRef< unsigned > MetadataKinds)
Collect metadata with IDs MetadataKinds from Src which should be added to all created instructions.
Definition IRBuilder.h:262
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1725
LLVM_ABI CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
void SetInsertPoint(BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point,...
Definition IRBuilder.h:232
LLVM_ABI CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2591
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:2604
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:2392
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:2056
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:2289
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2466
const IRBuilderDefaultInserter & Inserter
Definition IRBuilder.h:150
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2301
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2368
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2497
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2522
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1808
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Definition IRBuilder.h:1220
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2332
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition IRBuilder.h:172
Value * CreateBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1714
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2412
void setIsFPConstrained(bool IsCon)
Enable/Disable use of constrained floating point math.
Definition IRBuilder.h:351
LLVM_ABI DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition IRBuilder.cpp: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:2659
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:2207
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:2340
LLVM_ABI CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1850
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition IRBuilder.h:651
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1492
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition IRBuilder.h:334
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert a memset to the specified pointer and the specified value.
Definition IRBuilder.h:630
LLVM_ABI Value * CreateNAryOp(unsigned Opc, ArrayRef< Value * > Ops, const Twine &Name="", MDNode *FPMathTag=nullptr)
Create either a UnaryOperator or BinaryOperator depending on Opc.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2085
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:2596
LLVMContext & getContext() const
Definition IRBuilder.h:203
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2372
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h: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:1973
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2019
Value * CreateMinNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the minnum intrinsic.
Definition IRBuilder.h:1012
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1265
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1101
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1863
LLVM_ABI CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
LLVM_ABI 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:2197
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:2558
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:2654
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:2511
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1501
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1914
LLVM_ABI CallInst * CreateGCResult(Instruction *Statepoint, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.result intrinsic to extract the result from a call wrapped in a ...
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition IRBuilder.h:2071
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:605
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1708
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition IRBuilder.h:1191
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2584
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:1996
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:2364
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition IRBuilder.h:517
MDNode * DefaultFPMathTag
Definition IRBuilder.h:152
LLVM_ABI Value * CreateTypeSize(Type *Ty, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
ArrayRef< OperandBundleDef > DefaultOperandBundles
Definition IRBuilder.h:159
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h: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:2344
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition IRBuilder.h:331
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2280
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2407
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition IRBuilder.h:323
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
Definition IRBuilder.h:2649
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:2377
CallInst * CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:709
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition IRBuilder.h:1128
LLVM_ABI CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:207
Type * getVoidTy()
Fetch the type representing void.
Definition IRBuilder.h:600
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1246
CallInst * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1115
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memcpy between the specified pointers.
Value * CreateOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1591
Value * CreateFAddFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1618
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1733
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1840
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:1959
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2569
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1886
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1587
void setConstrainedFPCallAttr(CallBase *I)
Definition IRBuilder.h:395
Value * CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minimumnum intrinsic.
Definition IRBuilder.h:1046
LLVM_ABI InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
LLVM_ABI CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
const IRBuilderFolder & Folder
Definition IRBuilder.h:149
Value * CreateInBoundsPtrAdd(Value *Ptr, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2044
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2180
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:2533
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1798
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1599
LLVM_ABI CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2233
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2352
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2442
LLVM_ABI CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1651
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1877
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1793
void setConstrainedFPFunctionAttr()
Definition IRBuilder.h:386
LLVM_ABI void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition IRBuilder.cpp: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:2118
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1308
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2212
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:1789
LLVM_ABI Value * CreateElementCount(Type *Ty, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
LLVM_ABI CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2382
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:2427
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:2138
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:2783
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2800
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2795
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2789
InserterTy & getInserter()
Definition IRBuilder.h:2848
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2820
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2804
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2827
const InserterTy & getInserter() const
Definition IRBuilder.h:2849
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2836
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition IRBuilder.h:2813
Indirect Branch Instruction.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Class to represent integer types.
Invoke instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static LLVM_ABI LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
An instruction for reading from memory.
Metadata node.
Definition Metadata.h:1078
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:608
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:104
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:644
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:560
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:867
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:761
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106