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