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