LLVM 24.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/Module.h"
38#include "llvm/IR/Operator.h"
39#include "llvm/IR/Type.h"
40#include "llvm/IR/Value.h"
41#include "llvm/IR/ValueHandle.h"
46#include <cassert>
47#include <cstdint>
48#include <functional>
49#include <optional>
50#include <utility>
51
52namespace llvm {
53
54class APInt;
55class Use;
56
57/// This provides the default implementation of the IRBuilder
58/// 'InsertHelper' method that is called whenever an instruction is created by
59/// IRBuilder and needs to be inserted.
60///
61/// By default, this inserts the instruction at the insertion point.
63public:
64 void InsertHelper(Instruction *I, const Twine &Name,
65 BasicBlock::iterator InsertPt) const {
66 if (InsertPt.isValid())
67 I->insertInto(InsertPt.getNodeParent(), InsertPt);
68 I->setName(Name);
69 }
70};
71
72/// Provides an 'InsertHelper' that calls a user-provided callback after
73/// performing the default insertion.
75 std::function<void(Instruction *)> Callback;
76
77public:
78 IRBuilderCallbackInserter(std::function<void(Instruction *)> Callback)
79 : Callback(std::move(Callback)) {}
80
81 void InsertHelper(Instruction *I, const Twine &Name,
82 BasicBlock::iterator InsertPt) const {
84 Callback(I);
85 }
86};
87
88/// This provides a helper for copying FMF from an instruction or setting
89/// specified flags.
90class FMFSource {
91 std::optional<FastMathFlags> FMF;
92
93public:
94 FMFSource() = default;
96 if (Source)
97 FMF = Source->getFastMathFlags();
98 }
99 FMFSource(FastMathFlags FMF) : FMF(FMF) {}
101 return FMF.value_or(Default);
102 }
103 /// Intersect the FMF from two instructions.
108};
109
110/// Common base class shared among various IRBuilders.
112 /// The DebugLoc that will be applied to instructions inserted by this
113 /// builder.
114 DebugLoc StoredDL;
115
116protected:
117 using InsertFn = void (*)(const IRBuilderBase &, Instruction *, const Twine &,
119
124
127
128 bool CanonicalizeGEPs = true;
129 bool IsFPConstrained = false;
132
134
140
141public:
142 // IRBuilderBase contains references to IRBuilder members and is not safe
143 // to copy.
144 IRBuilderBase(const IRBuilderBase &) = delete;
145
146 /// Insert and return the specified instruction.
147 template<typename InstTy>
148 InstTy *Insert(InstTy *I, const Twine &Name = "") const {
149 InsertCB(*this, I, Name, InsertPt);
151 return I;
152 }
153
154 /// No-op overload to handle constants.
155 Constant *Insert(Constant *C, const Twine& = "") const {
156 return C;
157 }
158
159 Value *Insert(Value *V, const Twine &Name = "") const {
161 return Insert(I, Name);
163 return V;
164 }
165
166 //===--------------------------------------------------------------------===//
167 // Builder configuration methods
168 //===--------------------------------------------------------------------===//
169
170 /// Clear the insertion point: created instructions will not be
171 /// inserted into a block.
173
175 return InsertPt.isValid() ? InsertPt.getNodeParent() : nullptr;
176 }
178 LLVMContext &getContext() const { return Context; }
179
180 /// Get data layout. Requires that an insertion point is set and connected
181 /// to a module.
182 const DataLayout &getDataLayout() const {
183 assert(InsertPt.isValid() &&
184 "Must have insertion point to get data layout");
185 return InsertPt.getNodeParent()->getDataLayout();
186 }
187
188 /// Get the module. Requires that an insertion point is set and connected
189 /// to a module.
190 Module *getModule() const {
191 assert(InsertPt.isValid() && "Must have insertion point to get module");
192 return InsertPt.getNodeParent()->getModule();
193 }
194
195 /// This specifies that created instructions should be appended to the
196 /// end of the specified block.
197 void SetInsertPoint(BasicBlock *TheBB) { InsertPt = TheBB->end(); }
198
199 /// This specifies that created instructions should be inserted before
200 /// the specified instruction.
202 InsertPt = I->getIterator();
203 SetCurrentDebugLocation(I->getDebugLoc());
204 }
205
206 /// This specifies that created instructions should be inserted at the
207 /// specified point.
208 [[deprecated("Use the overload without BasicBlock argument instead")]]
212
213 /// This specifies that created instructions should be inserted at
214 /// the specified point.
216 InsertPt = IP;
217 if (IP != IP.getNodeParent()->end())
218 SetCurrentDebugLocation(IP->getDebugLoc());
219 }
220
221 /// This specifies that created instructions should inserted at the beginning
222 /// end of the specified function, but after already existing static alloca
223 /// instructions that are at the start.
225 InsertPt = F->getEntryBlock().getFirstNonPHIOrAlloca();
226 }
227
228 /// Set location information used by debugging information.
230 // For !dbg metadata attachments, we use DebugLoc instead of the raw MDNode
231 // to include optional introspection data for use in Debugify.
232 StoredDL = L;
233 }
234
235 /// Set location information used by debugging information.
237 // For !dbg metadata attachments, we use DebugLoc instead of the raw MDNode
238 // to include optional introspection data for use in Debugify.
239 StoredDL = std::move(L);
240 }
241
242 /// Get location information used by debugging information.
244
245 /// If this builder has a current debug location, set it on the
246 /// specified instruction.
248
249 /// Get the return type of the current function that we're emitting
250 /// into.
252
253 /// InsertPoint - A saved insertion point.
255
256 /// Returns the current insert point.
257 InsertPoint saveIP() const { return GetInsertPoint(); }
258
259 /// Returns the current insert point, clearing it in the process.
263 return IP;
264 }
265
266 /// Sets the current insert point to a previously-saved location.
268 if (IP.isValid())
269 SetInsertPoint(IP);
270 else
272 }
273
274 /// Get the floating point math metadata being used.
276
277 /// Get the flags to be applied to created floating point ops
279
281
282 /// Clear the fast-math flags.
283 void clearFastMathFlags() { FMF.clear(); }
284
285 /// Set the floating point math metadata to be used.
286 void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
287
288 /// Set the fast-math flags to be used with generated fp-math operators
289 void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
290
291 /// Enable/Disable use of constrained floating point math. When
292 /// enabled the CreateF<op>() calls instead create constrained
293 /// floating point intrinsic calls. Fast math flags are unaffected
294 /// by this setting.
295 void setIsFPConstrained(bool IsCon) { IsFPConstrained = IsCon; }
296
297 /// Query for the use of constrained floating point math
299
300 /// Set the exception handling to be used with constrained floating point
302#ifndef NDEBUG
303 std::optional<StringRef> ExceptStr =
305 assert(ExceptStr && "Garbage strict exception behavior!");
306#endif
307 DefaultConstrainedExcept = NewExcept;
308 }
309
310 /// Set the rounding mode handling to be used with constrained floating point
312#ifndef NDEBUG
313 std::optional<StringRef> RoundingStr =
314 convertRoundingModeToStr(NewRounding);
315 assert(RoundingStr && "Garbage strict rounding mode!");
316#endif
317 DefaultConstrainedRounding = NewRounding;
318 }
319
320 /// Get the exception handling used with constrained floating point
324
325 /// Get the rounding mode handling used with constrained floating point
329
332 assert(BB && "Must have a basic block to set any function attributes!");
333
334 Function *F = BB->getParent();
335 if (!F->hasFnAttribute(Attribute::StrictFP)) {
336 F->addFnAttr(Attribute::StrictFP);
337 }
338 }
339
341 I->addFnAttr(Attribute::StrictFP);
342 }
343
347
348 /// Disable canonicalization of getelementptr instructions to ptradd form.
349 /// This is a temporary test migration helper and will be removed in the
350 /// future.
352
353 //===--------------------------------------------------------------------===//
354 // RAII helpers.
355 //===--------------------------------------------------------------------===//
356
357 // RAII object that stores the current insertion point and restores it
358 // when the object is destroyed. This includes the debug location.
360 IRBuilderBase &Builder;
362 DebugLoc DbgLoc;
363
364 public:
366 : Builder(B), Point(B.GetInsertPoint()),
367 DbgLoc(B.getCurrentDebugLocation()) {}
368
371
373 Builder.restoreIP(Point);
374 Builder.SetCurrentDebugLocation(DbgLoc);
375 }
376 };
377
378 // RAII object that stores the current fast math settings and restores
379 // them when the object is destroyed.
381 IRBuilderBase &Builder;
382 FastMathFlags FMF;
383 MDNode *FPMathTag;
384 bool IsFPConstrained;
385 fp::ExceptionBehavior DefaultConstrainedExcept;
386 RoundingMode DefaultConstrainedRounding;
387
388 public:
390 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag),
391 IsFPConstrained(B.IsFPConstrained),
392 DefaultConstrainedExcept(B.DefaultConstrainedExcept),
393 DefaultConstrainedRounding(B.DefaultConstrainedRounding) {}
394
397
399 Builder.FMF = FMF;
400 Builder.DefaultFPMathTag = FPMathTag;
401 Builder.IsFPConstrained = IsFPConstrained;
402 Builder.DefaultConstrainedExcept = DefaultConstrainedExcept;
403 Builder.DefaultConstrainedRounding = DefaultConstrainedRounding;
404 }
405 };
406
407 // RAII object that stores the current default operand bundles and restores
408 // them when the object is destroyed.
410 IRBuilderBase &Builder;
411 ArrayRef<OperandBundleDef> DefaultOperandBundles;
412
413 public:
415 : Builder(B), DefaultOperandBundles(B.DefaultOperandBundles) {}
416
419
421 Builder.DefaultOperandBundles = DefaultOperandBundles;
422 }
423 };
424
425
426 //===--------------------------------------------------------------------===//
427 // Miscellaneous creation methods.
428 //===--------------------------------------------------------------------===//
429
430 /// Make a new global variable with initializer type i8*
431 ///
432 /// Make a new global variable with an initializer that has array of i8 type
433 /// filled in with the null terminated string value specified. The new global
434 /// variable will be marked mergable with any others of the same contents. If
435 /// Name is specified, it is the name of the global variable created.
436 ///
437 /// If no module is given via \p M, it is take from the insertion point basic
438 /// block.
440 const Twine &Name = "",
441 unsigned AddressSpace = 0,
442 Module *M = nullptr,
443 bool AddNull = true);
444
445 /// Get a constant value representing either true or false.
447 return ConstantInt::get(getInt1Ty(), V);
448 }
449
450 /// Get the constant value for i1 true.
454
455 /// Get the constant value for i1 false.
459
460 /// Get a constant 8-bit value.
462 return ConstantInt::get(getInt8Ty(), C);
463 }
464
465 /// Get a constant 16-bit value.
467 return ConstantInt::get(getInt16Ty(), C);
468 }
469
470 /// Get a constant 32-bit value.
472 return ConstantInt::get(getInt32Ty(), C);
473 }
474
475 /// Get a constant 64-bit value.
477 return ConstantInt::get(getInt64Ty(), C);
478 }
479
480 /// Get a constant N-bit value, zero extended from a 64-bit value.
482 return ConstantInt::get(getIntNTy(N), C);
483 }
484
485 /// Get a constant integer value.
487 return ConstantInt::get(Context, AI);
488 }
489
490 //===--------------------------------------------------------------------===//
491 // Type creation methods
492 //===--------------------------------------------------------------------===//
493
494 /// Fetch the type representing an 8-bit byte.
496
497 /// Fetch the type representing a 16-bit byte.
499
500 /// Fetch the type representing a 32-bit byte.
502
503 /// Fetch the type representing a 64-bit byte.
505
506 /// Fetch the type representing a 128-bit byte.
508
509 /// Fetch the type representing an N-bit byte.
511
512 /// Fetch the type representing a single bit
516
517 /// Fetch the type representing an 8-bit integer.
521
522 /// Fetch the type representing a 16-bit integer.
526
527 /// Fetch the type representing a 32-bit integer.
531
532 /// Fetch the type representing a 64-bit integer.
536
537 /// Fetch the type representing a 128-bit integer.
539
540 /// Fetch the type representing an N-bit integer.
542 return Type::getIntNTy(Context, N);
543 }
544
545 /// Fetch the type representing a 16-bit floating point value.
547 return Type::getHalfTy(Context);
548 }
549
550 /// Fetch the type representing a 16-bit brain floating point value.
553 }
554
555 /// Fetch the type representing a 32-bit floating point value.
558 }
559
560 /// Fetch the type representing a 64-bit floating point value.
563 }
564
565 /// Fetch the type representing void.
567 return Type::getVoidTy(Context);
568 }
569
570 /// Fetch the type representing a pointer.
571 PointerType *getPtrTy(unsigned AddrSpace = 0) {
572 return PointerType::get(Context, AddrSpace);
573 }
574
575 /// Fetch the type of a byte with size at least as big as that of a
576 /// pointer in the given address space.
577 ByteType *getBytePtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
578 return DL.getBytePtrType(Context, AddrSpace);
579 }
580
581 /// Fetch the type of an integer with size at least as big as that of a
582 /// pointer in the given address space.
583 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
584 return DL.getIntPtrType(Context, AddrSpace);
585 }
586
587 /// Fetch the type of an integer that should be used to index GEP operations
588 /// within AddressSpace.
589 IntegerType *getIndexTy(const DataLayout &DL, unsigned AddrSpace) {
590 return DL.getIndexType(Context, AddrSpace);
591 }
592
593 //===--------------------------------------------------------------------===//
594 // Intrinsic creation methods
595 //===--------------------------------------------------------------------===//
596
597 /// Create and insert a memset to the specified pointer and the
598 /// specified value.
599 ///
600 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
601 /// specified, it will be added to the instruction.
603 MaybeAlign Align, bool isVolatile = false,
604 const AAMDNodes &AAInfo = AAMDNodes()) {
605 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
606 }
607
609 MaybeAlign Align, bool isVolatile = false,
610 const AAMDNodes &AAInfo = AAMDNodes());
611
613 Value *Val, Value *Size,
614 bool IsVolatile = false,
615 const AAMDNodes &AAInfo = AAMDNodes());
616
617 /// Create and insert an element unordered-atomic memset of the region of
618 /// memory starting at the given pointer to the given value.
619 ///
620 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
621 /// specified, it will be added to the instruction.
622 CallInst *
624 Align Alignment, uint32_t ElementSize,
625 const AAMDNodes &AAInfo = AAMDNodes()) {
627 Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
628 }
629
631 Value *ArraySize,
633 Function *MallocF = nullptr,
634 const Twine &Name = "");
635
636 /// CreateMalloc - Generate the IR for a call to malloc:
637 /// 1. Compute the malloc call's argument as AllocSize, possibly multiplied
638 /// by the array size if the array size is not constant 1.
639 /// 2. Call malloc with that argument.
641 Value *ArraySize, Function *MallocF = nullptr,
642 const Twine &Name = "");
643 /// Generate the IR for a call to the builtin free function.
645 ArrayRef<OperandBundleDef> Bundles = {});
646
647 LLVM_ABI CallInst *
648 CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
649 Align Alignment, uint32_t ElementSize,
650 const AAMDNodes &AAInfo = AAMDNodes());
651
652 /// Create and insert a memcpy between the specified pointers.
653 ///
654 /// If the pointers aren't i8*, they will be converted. If alias metadata is
655 /// specified, it will be added to the instruction.
656 /// and noalias tags.
658 MaybeAlign SrcAlign, uint64_t Size,
659 bool isVolatile = false,
660 const AAMDNodes &AAInfo = AAMDNodes()) {
661 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
662 isVolatile, AAInfo);
663 }
664
667 Value *Src, MaybeAlign SrcAlign, Value *Size,
668 bool isVolatile = false,
669 const AAMDNodes &AAInfo = AAMDNodes());
670
672 MaybeAlign SrcAlign, Value *Size,
673 bool isVolatile = false,
674 const AAMDNodes &AAInfo = AAMDNodes()) {
675 return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
676 SrcAlign, Size, isVolatile, AAInfo);
677 }
678
680 MaybeAlign SrcAlign, Value *Size,
681 bool isVolatile = false,
682 const AAMDNodes &AAInfo = AAMDNodes()) {
683 return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
684 SrcAlign, Size, isVolatile, AAInfo);
685 }
686
687 /// Create and insert an element unordered-atomic memcpy between the
688 /// specified pointers.
689 ///
690 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
691 /// respectively.
692 ///
693 /// If the pointers aren't i8*, they will be converted. If alias metadata is
694 /// specified, it will be added to the instruction.
696 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
697 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
698
700 MaybeAlign SrcAlign, uint64_t Size,
701 bool isVolatile = false,
702 const AAMDNodes &AAInfo = AAMDNodes()) {
703 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
704 isVolatile, AAInfo);
705 }
706
708 MaybeAlign SrcAlign, Value *Size,
709 bool isVolatile = false,
710 const AAMDNodes &AAInfo = AAMDNodes()) {
711 return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
712 SrcAlign, Size, isVolatile, AAInfo);
713 }
714
715 /// \brief Create and insert an element unordered-atomic memmove between the
716 /// specified pointers.
717 ///
718 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
719 /// respectively.
720 ///
721 /// If the pointers aren't i8*, they will be converted. If alias metadata is
722 /// specified, it will be added to the instruction.
724 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
725 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
726
727private:
728 Value *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
729
730public:
731 /// Create a sequential vector fadd reduction intrinsic of the source vector.
732 /// The first parameter is a scalar accumulator value. An unordered reduction
733 /// can be created by adding the reassoc fast-math flag to the resulting
734 /// sequential reduction.
736
737 /// Create a sequential vector fmul reduction intrinsic of the source vector.
738 /// The first parameter is a scalar accumulator value. An unordered reduction
739 /// can be created by adding the reassoc fast-math flag to the resulting
740 /// sequential reduction.
742
743 /// Create a vector int add reduction intrinsic of the source vector.
745
746 /// Create a vector int mul reduction intrinsic of the source vector.
748
749 /// Create a vector int AND reduction intrinsic of the source vector.
751
752 /// Create a vector int OR reduction intrinsic of the source vector.
754
755 /// Create a vector int XOR reduction intrinsic of the source vector.
757
758 /// Create a vector integer max reduction intrinsic of the source
759 /// vector.
760 LLVM_ABI Value *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
761
762 /// Create a vector integer min reduction intrinsic of the source
763 /// vector.
764 LLVM_ABI Value *CreateIntMinReduce(Value *Src, bool IsSigned = false);
765
766 /// Create a vector float max reduction intrinsic of the source
767 /// vector.
769
770 /// Create a vector float min reduction intrinsic of the source
771 /// vector.
773
774 /// Create a vector float maximum reduction intrinsic of the source
775 /// vector. This variant follows the NaN and signed zero semantic of
776 /// llvm.maximum intrinsic.
778
779 /// Create a vector float minimum reduction intrinsic of the source
780 /// vector. This variant follows the NaN and signed zero semantic of
781 /// llvm.minimum intrinsic.
783
784 /// Create a vector float maximum reduction intrinsic of the source
785 /// vector. This variant follows the NaN and signed zero semantic of
786 /// llvm.maximumnum intrinsic.
788
789 /// Create a vector float minimum reduction intrinsic of the source
790 /// vector. This variant follows the NaN and signed zero semantic of
791 /// llvm.minimumnum intrinsic.
793
794 /// Create a lifetime.start intrinsic.
796
797 /// Create a lifetime.end intrinsic.
799
800 /// Create a call to invariant.start intrinsic.
801 ///
802 /// If the pointer isn't i8* it will be converted.
804 ConstantInt *Size = nullptr);
805
806 /// Create a call to llvm.threadlocal.address intrinsic.
808
809 /// Create a call to Masked Load intrinsic
810 LLVM_ABI CallInst *CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment,
811 Value *Mask, Value *PassThru = nullptr,
812 const Twine &Name = "");
813
814 /// Create a call to Masked Store intrinsic
815 LLVM_ABI CallInst *CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment,
816 Value *Mask);
817
818 /// Create a call to Masked Gather intrinsic
819 LLVM_ABI CallInst *CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment,
820 Value *Mask = nullptr,
821 Value *PassThru = nullptr,
822 const Twine &Name = "");
823
824 /// Create a call to Masked Scatter intrinsic
826 Align Alignment,
827 Value *Mask = nullptr);
828
829 /// Create a call to Masked Expand Load intrinsic
832 Value *Mask = nullptr,
833 Value *PassThru = nullptr,
834 const Twine &Name = "");
835
836 /// Create a call to Masked Compress Store intrinsic
839 Value *Mask = nullptr);
840
841 /// Return an all true boolean vector (mask) with \p NumElts lanes.
846
847 /// Create an assume intrinsic call that allows the optimizer to
848 /// assume that the provided condition will be true.
850
851 /// Create an assume intrinsic call that allows the optimizer to
852 /// assume that the provided operand bundles hold.
854
855 /// Create a llvm.experimental.noalias.scope.decl intrinsic call.
861
862 /// Create a call to the experimental.gc.statepoint intrinsic to
863 /// start a new statepoint sequence.
865 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
866 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
867 ArrayRef<Value *> GCArgs, const Twine &Name = "");
868
869 /// Create a call to the experimental.gc.statepoint intrinsic to
870 /// start a new statepoint sequence.
872 CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
873 FunctionCallee ActualCallee, uint32_t Flags,
874 ArrayRef<Value *> CallArgs,
875 std::optional<ArrayRef<Use>> TransitionArgs,
876 std::optional<ArrayRef<Use>> DeoptArgs,
877 ArrayRef<Value *> GCArgs, const Twine &Name = "");
878
879 /// Conveninence function for the common case when CallArgs are filled
880 /// in using ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
881 /// .get()'ed to get the Value pointer.
883 CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
884 FunctionCallee ActualCallee, ArrayRef<Use> CallArgs,
885 std::optional<ArrayRef<Value *>> DeoptArgs,
886 ArrayRef<Value *> GCArgs, const Twine &Name = "");
887
888 /// Create an invoke to the experimental.gc.statepoint intrinsic to
889 /// start a new statepoint sequence.
892 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
893 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
894 std::optional<ArrayRef<Value *>> DeoptArgs,
895 ArrayRef<Value *> GCArgs, const Twine &Name = "");
896
897 /// Create an invoke to the experimental.gc.statepoint intrinsic to
898 /// start a new statepoint sequence.
900 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
901 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
902 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
903 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
904 const Twine &Name = "");
905
906 // Convenience function for the common case when CallArgs are filled in using
907 // ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
908 // get the Value *.
911 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
912 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
913 std::optional<ArrayRef<Value *>> DeoptArgs,
914 ArrayRef<Value *> GCArgs, const Twine &Name = "");
915
916 /// Create a call to the experimental.gc.result intrinsic to extract
917 /// the result from a call wrapped in a statepoint.
918 LLVM_ABI CallInst *CreateGCResult(Instruction *Statepoint, Type *ResultType,
919 const Twine &Name = "");
920
921 /// Create a call to the experimental.gc.relocate intrinsics to
922 /// project the relocated value of one pointer from the statepoint.
923 LLVM_ABI CallInst *CreateGCRelocate(Instruction *Statepoint, int BaseOffset,
924 int DerivedOffset, Type *ResultType,
925 const Twine &Name = "");
926
927 /// Create a call to the experimental.gc.pointer.base intrinsic to get the
928 /// base pointer for the specified derived pointer.
930 const Twine &Name = "");
931
932 /// Create a call to the experimental.gc.get.pointer.offset intrinsic to get
933 /// the offset of the specified derived pointer from its base.
935 const Twine &Name = "");
936
937 /// Create a call to llvm.vscale.<Ty>().
938 Value *CreateVScale(Type *Ty, const Twine &Name = "") {
939 return CreateIntrinsic(Intrinsic::vscale, {Ty}, {}, {}, Name);
940 }
941
942 /// Create an expression which evaluates to the number of elements in \p EC
943 /// at runtime. This can result in poison if type \p Ty is not big enough to
944 /// hold the value.
946
947 /// Create an expression which evaluates to the number of units in \p Size
948 /// at runtime. This works for both units of bits and bytes. This can result
949 /// in poison if type \p Ty is not big enough to hold the value.
951
952 /// Get allocation size of an alloca as a runtime Value* (handles both static
953 /// and dynamic allocas and vscale factor).
955
956 /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
957 LLVM_ABI Value *CreateStepVector(Type *DstType, const Twine &Name = "");
958
959 /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
960 /// type.
962 FMFSource FMFSource = {},
963 const Twine &Name = "");
964
965 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
966 /// first type.
968 Value *RHS, FMFSource FMFSource = {},
969 const Twine &Name = "");
970
971 /// Create a call to intrinsic \p ID with \p Args, mangled using
972 /// \p OverloadTypes. If \p FMFSource is provided, copy fast-math-flags from
973 /// that instruction to the intrinsic. It is guaranteed not to fold.
975 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
976 FMFSource FMFSource = {}, const Twine &Name = "",
977 ArrayRef<OperandBundleDef> OpBundles = {});
978
979 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
980 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
981 /// the intrinsic. It is guaranteed not to fold.
983 Intrinsic::ID ID,
985 FMFSource FMFSource = {},
986 const Twine &Name = "");
987
988 /// Create a call to non-overloaded intrinsic \p ID with \p Args. If
989 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
990 /// the intrinsic. It is guranteed not to fold.
993 FMFSource FMFSource = {},
994 const Twine &Name = "") {
995 return CreateIntrinsicWithoutFolding(ID, /*Types=*/{}, Args, FMFSource,
996 Name);
997 }
998
999 /// Variant to create a possibly constant-folded intrinsic. An optional \p
1000 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
1001 /// things like attributes.
1003 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
1004 FMFSource FMFSource = {}, const Twine &Name = "",
1005 ArrayRef<OperandBundleDef> OpBundles = {},
1006 function_ref<void(CallInst *)> SetFn = [](CallInst *) {});
1007
1008 /// Variant to create a possibly constant-folded intrinsic. An optional \p
1009 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
1010 /// things like attributes.
1012 Type *RetTy, Intrinsic::ID ID, ArrayRef<Value *> Args,
1013 FMFSource FMFSource = {}, const Twine &Name = "",
1014 function_ref<void(CallInst *)> SetFn = [](CallInst *) {});
1015
1016 /// Variant to create a possibly constant-folded intrinsic. An optional \p
1017 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
1018 /// things like attributes.
1021 const Twine &Name = "",
1022 function_ref<void(CallInst *)> SetFn = [](CallInst *) {}) {
1023 return CreateIntrinsic(ID, /*Types=*/{}, Args, FMFSource, Name, {}, SetFn);
1024 }
1025
1026 /// Create call to the fabs intrinsic.
1028 const Twine &Name = "") {
1029 return CreateUnaryIntrinsic(Intrinsic::fabs, V, FMFSource, Name);
1030 }
1031
1032 /// Create call to the minnum intrinsic.
1034 const Twine &Name = "") {
1035 if (IsFPConstrained) {
1037 Intrinsic::experimental_constrained_minnum, LHS, RHS, FMFSource,
1038 Name);
1039 }
1040
1041 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, FMFSource, Name);
1042 }
1043
1044 /// Create call to the maxnum intrinsic.
1046 const Twine &Name = "") {
1047 if (IsFPConstrained) {
1049 Intrinsic::experimental_constrained_maxnum, LHS, RHS, FMFSource,
1050 Name);
1051 }
1052
1053 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, FMFSource, Name);
1054 }
1055
1056 /// Create call to the minimum intrinsic.
1057 Value *CreateMinimum(Value *LHS, Value *RHS, const Twine &Name = "") {
1058 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1059 }
1060
1061 /// Create call to the maximum intrinsic.
1062 Value *CreateMaximum(Value *LHS, Value *RHS, const Twine &Name = "") {
1063 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1064 }
1065
1066 /// Create call to the minimumnum intrinsic.
1067 Value *CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1068 return CreateBinaryIntrinsic(Intrinsic::minimumnum, LHS, RHS, nullptr,
1069 Name);
1070 }
1071
1072 /// Create call to the maximum intrinsic.
1073 Value *CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1074 return CreateBinaryIntrinsic(Intrinsic::maximumnum, LHS, RHS, nullptr,
1075 Name);
1076 }
1077
1078 /// Create call to the copysign intrinsic.
1080 const Twine &Name = "") {
1081 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1082 Name);
1083 }
1084
1085 /// Create call to the ldexp intrinsic.
1087 const Twine &Name = "") {
1088 assert(!IsFPConstrained && "TODO: Support strictfp");
1089 return CreateIntrinsic(Intrinsic::ldexp, {Src->getType(), Exp->getType()},
1090 {Src, Exp}, FMFSource, Name);
1091 }
1092
1093 /// Create call to the fma intrinsic.
1094 Value *CreateFMA(Value *Factor1, Value *Factor2, Value *Summand,
1095 FMFSource FMFSource = {}, const Twine &Name = "") {
1096 if (IsFPConstrained) {
1098 Intrinsic::experimental_constrained_fma, {Factor1->getType()},
1099 {Factor1, Factor2, Summand}, FMFSource, Name);
1100 }
1101
1102 return CreateIntrinsic(Intrinsic::fma, {Factor1->getType()},
1103 {Factor1, Factor2, Summand}, FMFSource, Name);
1104 }
1105
1106 /// Create a call to the arithmetic_fence intrinsic.
1108 const Twine &Name = "") {
1109 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1110 Name);
1111 }
1112
1113 /// Create a call to the vector.extract intrinsic.
1114 Value *CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx,
1115 const Twine &Name = "") {
1116 return CreateIntrinsic(Intrinsic::vector_extract,
1117 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1118 Name);
1119 }
1120
1121 /// Create a call to the vector.extract intrinsic.
1123 const Twine &Name = "") {
1124 return CreateExtractVector(DstType, SrcVec, getInt64(Idx), Name);
1125 }
1126
1127 /// Create a call to the vector.insert intrinsic.
1128 Value *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1129 Value *Idx, const Twine &Name = "") {
1130 return CreateIntrinsic(Intrinsic::vector_insert,
1131 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1132 nullptr, Name);
1133 }
1134
1135 /// Create a call to the vector.extract intrinsic.
1136 Value *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1137 uint64_t Idx, const Twine &Name = "") {
1138 return CreateInsertVector(DstType, SrcVec, SubVec, getInt64(Idx), Name);
1139 }
1140
1141 /// Create a call to llvm.stacksave
1142 CallInst *CreateStackSave(const Twine &Name = "") {
1143 const DataLayout &DL = getDataLayout();
1144 return CreateIntrinsicWithoutFolding(Intrinsic::stacksave,
1145 {DL.getAllocaPtrType(Context)}, {},
1146 nullptr, Name);
1147 }
1148
1149 /// Create a call to llvm.stackrestore
1150 CallInst *CreateStackRestore(Value *Ptr, const Twine &Name = "") {
1152 Intrinsic::stackrestore, {Ptr->getType()}, {Ptr}, nullptr, Name);
1153 }
1154
1155 /// Create a call to llvm.experimental_cttz_elts
1157 bool ZeroIsPoison = true,
1158 const Twine &Name = "") {
1159 return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
1160 {ResTy, Mask->getType()},
1161 {Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
1162 }
1163
1164private:
1165 /// Create a call to a masked intrinsic with given Id.
1166 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1167 ArrayRef<Type *> OverloadedTypes,
1168 const Twine &Name = "");
1169
1170 //===--------------------------------------------------------------------===//
1171 // Instruction creation methods: Terminators
1172 //===--------------------------------------------------------------------===//
1173
1174private:
1175 /// Helper to add branch weight and unpredictable metadata onto an
1176 /// instruction.
1177 /// \returns The annotated instruction.
1178 template <typename InstTy>
1179 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1180 if (Weights)
1181 I->setMetadata(LLVMContext::MD_prof, Weights);
1182 if (Unpredictable)
1183 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1184 return I;
1185 }
1186
1187public:
1188 /// Create a 'ret void' instruction.
1192
1193 /// Create a 'ret <val>' instruction.
1197
1198 /// Create a sequence of N insertvalue instructions, with one Value from the
1199 /// RetVals array each, that build a aggregate return value one value at a
1200 /// time, and a ret instruction to return the resulting aggregate value.
1201 ///
1202 /// This is a convenience function for code that uses aggregate return values
1203 /// as a vehicle for having multiple return values.
1206 for (size_t i = 0, N = RetVals.size(); i != N; ++i)
1207 V = CreateInsertValue(V, RetVals[i], i, "mrv");
1209 }
1210
1211 /// Create an unconditional 'br label X' instruction.
1213 return Insert(UncondBrInst::Create(Dest));
1214 }
1215
1216 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1217 /// instruction.
1219 MDNode *BranchWeights = nullptr,
1220 MDNode *Unpredictable = nullptr) {
1221 return Insert(addBranchMetadata(CondBrInst::Create(Cond, True, False),
1222 BranchWeights, Unpredictable));
1223 }
1224
1225 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1226 /// instruction. Copy branch meta data if available.
1228 Instruction *MDSrc) {
1230 if (MDSrc) {
1231 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1232 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1233 Br->copyMetadata(*MDSrc, WL);
1234 }
1235 return Insert(Br);
1236 }
1237
1238 /// Create a switch instruction with the specified value, default dest,
1239 /// and with a hint for the number of cases that will be added (for efficient
1240 /// allocation).
1241 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1242 MDNode *BranchWeights = nullptr,
1243 MDNode *Unpredictable = nullptr) {
1244 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1245 BranchWeights, Unpredictable));
1246 }
1247
1248 /// Create an indirect branch instruction with the specified address
1249 /// operand, with an optional hint for the number of destinations that will be
1250 /// added (for efficient allocation).
1251 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1252 return Insert(IndirectBrInst::Create(Addr, NumDests));
1253 }
1254
1255 /// Create an invoke instruction.
1257 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1258 ArrayRef<Value *> Args,
1260 const Twine &Name = "") {
1261 InvokeInst *II =
1262 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1263 if (IsFPConstrained)
1265 return Insert(II, Name);
1266 }
1268 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1269 ArrayRef<Value *> Args = {},
1270 const Twine &Name = "") {
1271 InvokeInst *II =
1272 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1273 if (IsFPConstrained)
1275 return Insert(II, Name);
1276 }
1277
1279 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1281 const Twine &Name = "") {
1282 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1283 NormalDest, UnwindDest, Args, OpBundles, Name);
1284 }
1285
1287 BasicBlock *UnwindDest, ArrayRef<Value *> Args = {},
1288 const Twine &Name = "") {
1289 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1290 NormalDest, UnwindDest, Args, Name);
1291 }
1292
1293 /// \brief Create a callbr instruction.
1295 BasicBlock *DefaultDest,
1296 ArrayRef<BasicBlock *> IndirectDests,
1297 ArrayRef<Value *> Args = {},
1298 const Twine &Name = "") {
1299 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1300 Args), Name);
1301 }
1303 BasicBlock *DefaultDest,
1304 ArrayRef<BasicBlock *> IndirectDests,
1305 ArrayRef<Value *> Args,
1307 const Twine &Name = "") {
1308 return Insert(
1309 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1310 OpBundles), Name);
1311 }
1312
1314 ArrayRef<BasicBlock *> IndirectDests,
1315 ArrayRef<Value *> Args = {},
1316 const Twine &Name = "") {
1317 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1318 DefaultDest, IndirectDests, Args, Name);
1319 }
1321 ArrayRef<BasicBlock *> IndirectDests,
1322 ArrayRef<Value *> Args,
1324 const Twine &Name = "") {
1325 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1326 DefaultDest, IndirectDests, Args, Name);
1327 }
1328
1330 return Insert(ResumeInst::Create(Exn));
1331 }
1332
1334 BasicBlock *UnwindBB = nullptr) {
1335 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1336 }
1337
1339 unsigned NumHandlers,
1340 const Twine &Name = "") {
1341 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1342 Name);
1343 }
1344
1346 const Twine &Name = "") {
1347 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1348 }
1349
1351 ArrayRef<Value *> Args = {},
1352 const Twine &Name = "") {
1353 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1354 }
1355
1357 return Insert(CatchReturnInst::Create(CatchPad, BB));
1358 }
1359
1363
1364 //===--------------------------------------------------------------------===//
1365 // Instruction creation methods: Binary Operators
1366 //===--------------------------------------------------------------------===//
1367private:
1368 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1369 Value *LHS, Value *RHS,
1370 const Twine &Name,
1371 bool HasNUW, bool HasNSW) {
1373 if (HasNUW) BO->setHasNoUnsignedWrap();
1374 if (HasNSW) BO->setHasNoSignedWrap();
1375 return BO;
1376 }
1377
1378 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1379 FastMathFlags FMF) const {
1380 if (!FPMD)
1381 FPMD = DefaultFPMathTag;
1382 if (FPMD)
1383 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1384 I->setFastMathFlags(FMF);
1385 return I;
1386 }
1387
1388 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1390
1391 if (Rounding)
1392 UseRounding = *Rounding;
1393
1394 std::optional<StringRef> RoundingStr =
1395 convertRoundingModeToStr(UseRounding);
1396 assert(RoundingStr && "Garbage strict rounding mode!");
1397 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1398
1399 return MetadataAsValue::get(Context, RoundingMDS);
1400 }
1401
1402 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1403 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1404 Except.value_or(DefaultConstrainedExcept));
1405 assert(ExceptStr && "Garbage strict exception behavior!");
1406 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1407
1408 return MetadataAsValue::get(Context, ExceptMDS);
1409 }
1410
1411 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1412 assert(CmpInst::isFPPredicate(Predicate) &&
1413 Predicate != CmpInst::FCMP_FALSE &&
1414 Predicate != CmpInst::FCMP_TRUE &&
1415 "Invalid constrained FP comparison predicate!");
1416
1417 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1418 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1419
1420 return MetadataAsValue::get(Context, PredicateMDS);
1421 }
1422
1423public:
1424 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
1425 bool HasNUW = false, bool HasNSW = false) {
1426 if (Value *V =
1427 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1428 return V;
1429 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1430 HasNSW);
1431 }
1432
1433 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1434 return CreateAdd(LHS, RHS, Name, false, true);
1435 }
1436
1437 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1438 return CreateAdd(LHS, RHS, Name, true, false);
1439 }
1440
1441 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
1442 bool HasNUW = false, bool HasNSW = false) {
1443 if (Value *V =
1444 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1445 return V;
1446 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1447 HasNSW);
1448 }
1449
1450 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1451 return CreateSub(LHS, RHS, Name, false, true);
1452 }
1453
1454 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1455 return CreateSub(LHS, RHS, Name, true, false);
1456 }
1457
1458 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1459 bool HasNUW = false, bool HasNSW = false) {
1460 if (Value *V =
1461 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1462 return V;
1463 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1464 HasNSW);
1465 }
1466
1467 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1468 return CreateMul(LHS, RHS, Name, false, true);
1469 }
1470
1471 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1472 return CreateMul(LHS, RHS, Name, true, false);
1473 }
1474
1475 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1476 bool isExact = false) {
1477 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1478 return V;
1479 if (!isExact)
1480 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1481 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1482 }
1483
1484 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1485 return CreateUDiv(LHS, RHS, Name, true);
1486 }
1487
1488 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1489 bool isExact = false) {
1490 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1491 return V;
1492 if (!isExact)
1493 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1494 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1495 }
1496
1497 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1498 return CreateSDiv(LHS, RHS, Name, true);
1499 }
1500
1501 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1502 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1503 return V;
1504 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1505 }
1506
1507 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1508 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1509 return V;
1510 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1511 }
1512
1513 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1514 bool HasNUW = false, bool HasNSW = false) {
1515 if (Value *V =
1516 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1517 return V;
1518 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1519 HasNUW, HasNSW);
1520 }
1521
1522 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1523 bool HasNUW = false, bool HasNSW = false) {
1524 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1525 HasNUW, HasNSW);
1526 }
1527
1528 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1529 bool HasNUW = false, bool HasNSW = false) {
1530 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1531 HasNUW, HasNSW);
1532 }
1533
1534 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1535 bool isExact = false) {
1536 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1537 return V;
1538 if (!isExact)
1539 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1540 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1541 }
1542
1543 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1544 bool isExact = false) {
1545 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1546 }
1547
1549 bool isExact = false) {
1550 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1551 }
1552
1553 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1554 bool isExact = false) {
1555 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1556 return V;
1557 if (!isExact)
1558 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1559 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1560 }
1561
1562 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1563 bool isExact = false) {
1564 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1565 }
1566
1568 bool isExact = false) {
1569 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1570 }
1571
1572 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1573 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1574 return V;
1575 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1576 }
1577
1578 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1579 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1580 }
1581
1582 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1583 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1584 }
1585
1587 assert(!Ops.empty());
1588 Value *Accum = Ops[0];
1589 for (unsigned i = 1; i < Ops.size(); i++)
1590 Accum = CreateAnd(Accum, Ops[i]);
1591 return Accum;
1592 }
1593
1594 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "",
1595 bool IsDisjoint = false) {
1596 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1597 return V;
1598 return Insert(
1599 IsDisjoint ? BinaryOperator::CreateDisjoint(Instruction::Or, LHS, RHS)
1600 : BinaryOperator::CreateOr(LHS, RHS),
1601 Name);
1602 }
1603
1604 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1605 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1606 }
1607
1608 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1609 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1610 }
1611
1613 assert(!Ops.empty());
1614 Value *Accum = Ops[0];
1615 for (unsigned i = 1; i < Ops.size(); i++)
1616 Accum = CreateOr(Accum, Ops[i]);
1617 return Accum;
1618 }
1619
1620 Value *CreateDisjointOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1621 return CreateOr(LHS, RHS, Name, true);
1622 }
1623
1624 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1625 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1626 return V;
1627 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1628 }
1629
1630 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1631 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1632 }
1633
1634 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1635 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1636 }
1637
1638 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1639 MDNode *FPMD = nullptr) {
1640 return CreateFAddFMF(L, R, {}, Name, FPMD);
1641 }
1642
1644 const Twine &Name = "", MDNode *FPMD = nullptr) {
1645 if (IsFPConstrained)
1646 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1647 L, R, FMFSource, Name, FPMD);
1648
1649 if (Value *V =
1650 Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMFSource.get(FMF)))
1651 return V;
1652 Instruction *I =
1653 setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMFSource.get(FMF));
1654 return Insert(I, Name);
1655 }
1656
1657 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1658 MDNode *FPMD = nullptr) {
1659 return CreateFSubFMF(L, R, {}, Name, FPMD);
1660 }
1661
1663 const Twine &Name = "", MDNode *FPMD = nullptr) {
1664 if (IsFPConstrained)
1665 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1666 L, R, FMFSource, Name, FPMD);
1667
1668 if (Value *V =
1669 Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMFSource.get(FMF)))
1670 return V;
1671 Instruction *I =
1672 setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMFSource.get(FMF));
1673 return Insert(I, Name);
1674 }
1675
1676 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1677 MDNode *FPMD = nullptr) {
1678 return CreateFMulFMF(L, R, {}, Name, FPMD);
1679 }
1680
1682 const Twine &Name = "", MDNode *FPMD = nullptr) {
1683 if (IsFPConstrained)
1684 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1685 L, R, FMFSource, Name, FPMD);
1686
1687 if (Value *V =
1688 Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMFSource.get(FMF)))
1689 return V;
1690 Instruction *I =
1691 setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMFSource.get(FMF));
1692 return Insert(I, Name);
1693 }
1694
1695 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1696 MDNode *FPMD = nullptr) {
1697 return CreateFDivFMF(L, R, {}, Name, FPMD);
1698 }
1699
1701 const Twine &Name = "", MDNode *FPMD = nullptr) {
1702 if (IsFPConstrained)
1703 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1704 L, R, FMFSource, Name, FPMD);
1705
1706 if (Value *V =
1707 Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMFSource.get(FMF)))
1708 return V;
1709 Instruction *I =
1710 setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMFSource.get(FMF));
1711 return Insert(I, Name);
1712 }
1713
1714 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1715 MDNode *FPMD = nullptr) {
1716 return CreateFRemFMF(L, R, {}, Name, FPMD);
1717 }
1718
1720 const Twine &Name = "", MDNode *FPMD = nullptr) {
1721 if (IsFPConstrained)
1722 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1723 L, R, FMFSource, Name, FPMD);
1724
1725 if (Value *V =
1726 Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMFSource.get(FMF)))
1727 return V;
1728 Instruction *I =
1729 setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMFSource.get(FMF));
1730 return Insert(I, Name);
1731 }
1732
1734 Value *LHS, Value *RHS, const Twine &Name = "",
1735 MDNode *FPMathTag = nullptr) {
1736 return CreateBinOpFMF(Opc, LHS, RHS, {}, Name, FPMathTag);
1737 }
1738
1740 FMFSource FMFSource, const Twine &Name = "",
1741 MDNode *FPMathTag = nullptr) {
1742 if (Value *V = Folder.FoldBinOpFMF(Opc, LHS, RHS, FMFSource.get(FMF)))
1743 return V;
1745 if (isa<FPMathOperator>(BinOp))
1746 setFPAttrs(BinOp, FPMathTag, FMFSource.get(FMF));
1747 return Insert(BinOp, Name);
1748 }
1749
1751 bool IsNUW, bool IsNSW, const Twine &Name = "") {
1752 if (Value *V = Folder.FoldNoWrapBinOp(Opc, LHS, RHS, IsNUW, IsNSW))
1753 return V;
1755 if (IsNUW)
1756 BinOp->setHasNoUnsignedWrap(IsNUW);
1757 if (IsNSW)
1758 BinOp->setHasNoSignedWrap(IsNSW);
1759 return Insert(BinOp, Name);
1760 }
1761
1763 bool IsExact, const Twine &Name = "") {
1764 if (Value *V = Folder.FoldExactBinOp(Opc, LHS, RHS, IsExact))
1765 return V;
1767 if (IsExact)
1768 BinOp->setIsExact(IsExact);
1769 return Insert(BinOp, Name);
1770 }
1771
1772 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "",
1773 Instruction *MDFrom = nullptr) {
1774 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1775 return CreateSelect(Cond1, Cond2,
1776 ConstantInt::getNullValue(Cond2->getType()), Name,
1777 MDFrom);
1778 }
1779
1780 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
1781 Instruction *MDFrom = nullptr) {
1782 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1783 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1784 Cond2, Name, MDFrom);
1785 }
1786
1788 const Twine &Name = "",
1789 Instruction *MDFrom = nullptr) {
1790 switch (Opc) {
1791 case Instruction::And:
1792 return CreateLogicalAnd(Cond1, Cond2, Name, MDFrom);
1793 case Instruction::Or:
1794 return CreateLogicalOr(Cond1, Cond2, Name, MDFrom);
1795 default:
1796 break;
1797 }
1798 llvm_unreachable("Not a logical operation.");
1799 }
1800
1801 // NOTE: this is sequential, non-commutative, ordered reduction!
1803 assert(!Ops.empty());
1804 Value *Accum = Ops[0];
1805 for (unsigned i = 1; i < Ops.size(); i++)
1806 Accum = CreateLogicalOr(Accum, Ops[i]);
1807 return Accum;
1808 }
1809
1810 /// This function is like @ref CreateIntrinsic for constrained fp
1811 /// intrinsics. It sets the rounding mode and exception behavior of
1812 /// the created intrinsic call according to \p Rounding and \p
1813 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1814 /// defaults if a value equals nullopt/null.
1817 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1818 std::optional<RoundingMode> Rounding = std::nullopt,
1819 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1820
1822 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1823 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1824 std::optional<RoundingMode> Rounding = std::nullopt,
1825 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1826
1828 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1829 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1830 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1831
1832 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1833 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1834 /*HasNUW=*/0, HasNSW);
1835 }
1836
1837 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1838 return CreateNeg(V, Name, /*HasNSW=*/true);
1839 }
1840
1841 Value *CreateFNeg(Value *V, const Twine &Name = "",
1842 MDNode *FPMathTag = nullptr) {
1843 return CreateFNegFMF(V, {}, Name, FPMathTag);
1844 }
1845
1847 MDNode *FPMathTag = nullptr) {
1848 if (Value *Res =
1849 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1850 return Res;
1851 return Insert(
1852 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1853 Name);
1854 }
1855
1856 Value *CreateNot(Value *V, const Twine &Name = "") {
1857 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1858 }
1859
1861 Value *V, const Twine &Name = "",
1862 MDNode *FPMathTag = nullptr) {
1863 return CreateUnOpFMF(Opc, V, {}, Name, FPMathTag);
1864 }
1865
1867 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1868 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMFSource.get(FMF)))
1869 return Res;
1871 if (isa<FPMathOperator>(UnOp))
1872 setFPAttrs(UnOp, FPMathTag, FMFSource.get(FMF));
1873 return Insert(UnOp, Name);
1874 }
1875
1876 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1877 /// Correct number of operands must be passed accordingly.
1879 const Twine &Name = "",
1880 MDNode *FPMathTag = nullptr);
1881
1882 //===--------------------------------------------------------------------===//
1883 // Instruction creation methods: Memory Instructions
1884 //===--------------------------------------------------------------------===//
1885
1886 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1887 Value *ArraySize = nullptr, const Twine &Name = "") {
1888 const DataLayout &DL = getDataLayout();
1889 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1890 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1891 }
1892
1893 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1894 const Twine &Name = "") {
1895 const DataLayout &DL = getDataLayout();
1896 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1897 unsigned AddrSpace = DL.getAllocaAddrSpace();
1898 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1899 }
1900
1902 const DataLayout &DL = getDataLayout();
1903 PointerType *PtrTy = DL.getAllocaPtrType(Context);
1904 auto *Output = CreateIntrinsicWithoutFolding(Intrinsic::structured_alloca,
1905 {PtrTy}, {}, {}, Name);
1906 Output->addRetAttr(
1907 Attribute::get(getContext(), Attribute::ElementType, BaseType));
1908 return Output;
1909 }
1910
1911 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1912 /// converting the string to 'bool' for the isVolatile parameter.
1913 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1914 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1915 }
1916 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1917 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1918 }
1919
1920 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1921 const Twine &Name = "") {
1922 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1923 }
1924
1926 const LoadStoreInstProperties &Props,
1927 const Twine &Name = "") {
1928 return Insert(new LoadInst(Ty, Ptr, Twine(), Props), Name);
1929 }
1930
1931 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1932 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1933 }
1934
1936 const LoadStoreInstProperties &Props) {
1937 return Insert(new StoreInst(Val, Ptr, Props));
1938 }
1939
1941 const char *Name) {
1942 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1943 }
1944
1946 const Twine &Name = "") {
1947 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1948 }
1949
1951 bool isVolatile, const Twine &Name = "") {
1952 if (!Align) {
1953 const DataLayout &DL = getDataLayout();
1954 Align = DL.getABITypeAlign(Ty);
1955 }
1956 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1957 }
1958
1960 bool isVolatile = false) {
1961 if (!Align) {
1962 const DataLayout &DL = getDataLayout();
1963 Align = DL.getABITypeAlign(Val->getType());
1964 }
1965 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1966 }
1969 const Twine &Name = "") {
1970 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1971 }
1972
1975 AtomicOrdering SuccessOrdering,
1976 AtomicOrdering FailureOrdering,
1978 if (!Align) {
1979 const DataLayout &DL = getDataLayout();
1980 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1981 }
1982
1983 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1984 FailureOrdering, SSID));
1985 }
1986
1988 Value *Val, MaybeAlign Align,
1989 AtomicOrdering Ordering,
1991 bool Elementwise = false) {
1992 if (!Align) {
1993 const DataLayout &DL = getDataLayout();
1994 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1995 }
1996
1997 return Insert(
1998 new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID, Elementwise));
1999 }
2000
2002 ArrayRef<Value *> Indices,
2003 const Twine &Name = "") {
2005 Args.push_back(PtrBase);
2006 llvm::append_range(Args, Indices);
2007
2008 return CreateIntrinsic(
2009 Intrinsic::structured_gep, {PtrBase->getType()}, Args, {}, Name, {},
2010 [&](CallInst *Output) {
2011 Output->addParamAttr(
2012 0,
2013 Attribute::get(getContext(), Attribute::ElementType, BaseType));
2014 });
2015 }
2016
2017 LLVM_ABI Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
2018 const Twine &Name = "",
2020
2022 const Twine &Name = "") {
2023 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
2024 }
2025
2026 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
2027 const Twine &Name = "") {
2028 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
2029 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
2030 }
2031
2032 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
2033 const Twine &Name = "") {
2034 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
2035 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
2036 }
2037
2038 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
2039 const Twine &Name = "",
2041 Value *Idxs[] = {
2042 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
2043 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
2044 };
2045 return CreateGEP(Ty, Ptr, Idxs, Name, NWFlags);
2046 }
2047
2048 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
2049 unsigned Idx1, const Twine &Name = "") {
2050 Value *Idxs[] = {
2051 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
2052 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
2053 };
2054 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2055 }
2056
2058 const Twine &Name = "") {
2059 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2060 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
2061 }
2062
2064 const Twine &Name = "") {
2065 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2066 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
2067 }
2068
2070 const Twine &Name = "") {
2071 Value *Idxs[] = {
2072 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2073 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2074 };
2075 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::none());
2076 }
2077
2079 uint64_t Idx1, const Twine &Name = "") {
2080 Value *Idxs[] = {
2081 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2082 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2083 };
2084 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2085 }
2086
2087 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2088 const Twine &Name = "") {
2089 GEPNoWrapFlags NWFlags =
2091 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2092 }
2093
2094 Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
2096 assert(Offset->getType()->isIntOrIntVectorTy(
2097 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2098 "Offset must match index type");
2099 Type *Ty = getInt8Ty();
2100 if (auto *V = Folder.FoldGEP(getDataLayout(), Ty, Ptr, Offset, NW))
2101 return V;
2102 return Insert(GetElementPtrInst::Create(Ty, Ptr, Offset, NW), Name);
2103 }
2104
2106 const Twine &Name = "") {
2107 return CreatePtrAdd(Ptr, Offset, Name, GEPNoWrapFlags::inBounds());
2108 }
2109
2110 /// Create a ptradd with an unsigned constant offset. The offset must fit into
2111 /// the unsigned index type.
2112 Value *
2114 const Twine &Name = "",
2116 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2117 return CreatePtrAdd(Ptr, ConstantInt::get(IdxTy, Offset), Name, NW);
2118 }
2119
2120 /// Create a ptradd with a signed constant offset. The offset must fit into
2121 /// the signed index type.
2122 Value *
2124 const Twine &Name = "",
2126 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2127 return CreatePtrAdd(Ptr, ConstantInt::getSigned(IdxTy, Offset), Name, NW);
2128 }
2129
2130 /// Create a ptradd where the offset is sign-extended or truncated to the
2131 /// index type. Offset must match the vector-ness of the base pointer.
2132 Value *
2135 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2136 return CreatePtrAdd(Ptr, CreateSExtOrTrunc(Offset, IdxTy), Name, NW);
2137 }
2138
2139 /// Create a ptradd where the offset is zero-extended or truncated to the
2140 /// index type. Offset must match the vector-ness of the base pointer.
2141 Value *
2144 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2145 return CreatePtrAdd(Ptr, CreateZExtOrTrunc(Offset, IdxTy), Name, NW);
2146 }
2147
2149 const Twine &Name = "",
2151 assert(Offset->getType()->isIntOrIntVectorTy(
2152 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2153 "Offset must match index type");
2154 if (Scale == 1)
2155 return CreatePtrAdd(Ptr, Offset, Name, NW);
2156
2157 Type *Ty = ArrayType::get(getInt8Ty(), Scale);
2158 if (auto *V = Folder.FoldGEP(getDataLayout(), Ty, Ptr, Offset, NW))
2159 return V;
2160 return Insert(GetElementPtrInst::Create(Ty, Ptr, Offset, NW), Name);
2161 }
2162
2164 const Twine &Name = "",
2166 assert(Offset->getType()->isIntOrIntVectorTy(
2167 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2168 "Offset must match index type");
2169 if (Scale.isScalable()) {
2170 Value *VScale = CreateVScale(Offset->getType()->getScalarType());
2171 if (auto *VT = dyn_cast<VectorType>(Offset->getType()))
2172 VScale = CreateVectorSplat(VT->getElementCount(), VScale);
2173 Offset = CreateMul(VScale, Offset, "", NW.hasNoUnsignedWrap(),
2174 NW.hasNoUnsignedSignedWrap());
2175 }
2176 return CreateScaledPtrAdd(Ptr, Scale.getKnownMinValue(), Offset, Name, NW);
2177 }
2178
2179 //===--------------------------------------------------------------------===//
2180 // Instruction creation methods: Cast/Conversion Operators
2181 //===--------------------------------------------------------------------===//
2182
2183 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2184 bool IsNUW = false, bool IsNSW = false) {
2185 if (V->getType() == DestTy)
2186 return V;
2187 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2188 return Folded;
2189 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2190 if (IsNUW)
2191 I->setHasNoUnsignedWrap();
2192 if (IsNSW)
2193 I->setHasNoSignedWrap();
2194 return Insert(I, Name);
2195 }
2196
2197 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2198 bool IsNonNeg = false) {
2199 if (V->getType() == DestTy)
2200 return V;
2201 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2202 return Folded;
2203 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2204 if (IsNonNeg)
2205 I->setNonNeg();
2206 return I;
2207 }
2208
2209 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2210 return CreateCast(Instruction::SExt, V, DestTy, Name);
2211 }
2212
2213 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2214 /// the value untouched if the type of V is already DestTy.
2216 const Twine &Name = "") {
2217 assert(V->getType()->isIntOrIntVectorTy() &&
2218 DestTy->isIntOrIntVectorTy() &&
2219 "Can only zero extend/truncate integers!");
2220 Type *VTy = V->getType();
2221 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2222 return CreateZExt(V, DestTy, Name);
2223 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2224 return CreateTrunc(V, DestTy, Name);
2225 return V;
2226 }
2227
2228 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2229 /// the value untouched if the type of V is already DestTy.
2231 const Twine &Name = "") {
2232 assert(V->getType()->isIntOrIntVectorTy() &&
2233 DestTy->isIntOrIntVectorTy() &&
2234 "Can only sign extend/truncate integers!");
2235 Type *VTy = V->getType();
2236 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2237 return CreateSExt(V, DestTy, Name);
2238 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2239 return CreateTrunc(V, DestTy, Name);
2240 return V;
2241 }
2242
2243 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2244 if (IsFPConstrained)
2245 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2246 V, DestTy, nullptr, Name);
2247 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2248 }
2249
2250 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2251 if (IsFPConstrained)
2252 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2253 V, DestTy, nullptr, Name);
2254 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2255 }
2256
2257 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2258 bool IsNonNeg = false, MDNode *FPMathTag = nullptr) {
2259 if (IsFPConstrained)
2260 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2261 V, DestTy, nullptr, Name);
2262 Value *Val = CreateCast(Instruction::UIToFP, V, DestTy, Name, FPMathTag);
2263 if (auto *I = dyn_cast<Instruction>(Val))
2264 if (IsNonNeg)
2265 I->setNonNeg();
2266 return Val;
2267 }
2268
2269 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2270 MDNode *FPMathTag = nullptr) {
2271 if (IsFPConstrained)
2272 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2273 V, DestTy, nullptr, Name);
2274 return CreateCast(Instruction::SIToFP, V, DestTy, Name, FPMathTag);
2275 }
2276
2277 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2278 MDNode *FPMathTag = nullptr) {
2279 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2280 }
2281
2283 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2284 if (IsFPConstrained)
2286 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2287 Name, FPMathTag);
2288 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2289 FMFSource);
2290 }
2291
2292 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2293 MDNode *FPMathTag = nullptr) {
2294 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2295 }
2296
2298 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2299 if (IsFPConstrained)
2300 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2301 V, DestTy, FMFSource, Name, FPMathTag);
2302 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2303 FMFSource);
2304 }
2305 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2306 return CreateCast(Instruction::PtrToAddr, V,
2307 getDataLayout().getAddressType(V->getType()), Name);
2308 }
2310 const Twine &Name = "") {
2311 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2312 }
2313
2315 const Twine &Name = "") {
2316 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2317 }
2318
2320 const Twine &Name = "") {
2321 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2322 }
2323
2324 Value *CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "",
2325 bool IsNonNull = false) {
2326 if (V->getType() == DestTy)
2327 return V;
2328 if (Value *Folded = Folder.FoldCast(Instruction::AddrSpaceCast, V, DestTy))
2329 return Folded;
2330 Instruction *I = Insert(new AddrSpaceCastInst(V, DestTy), Name);
2331 if (IsNonNull)
2332 cast<AddrSpaceCastInst>(I)->setNonNull();
2333 return I;
2334 }
2335
2336 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2337 Instruction::CastOps CastOp =
2338 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2339 ? Instruction::BitCast
2340 : Instruction::ZExt;
2341 return CreateCast(CastOp, V, DestTy, Name);
2342 }
2343
2344 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2345 Instruction::CastOps CastOp =
2346 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2347 ? Instruction::BitCast
2348 : Instruction::SExt;
2349 return CreateCast(CastOp, V, DestTy, Name);
2350 }
2351
2352 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2353 Instruction::CastOps CastOp =
2354 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2355 ? Instruction::BitCast
2356 : Instruction::Trunc;
2357 return CreateCast(CastOp, V, DestTy, Name);
2358 }
2359
2361 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2362 FMFSource FMFSource = {}) {
2363 if (V->getType() == DestTy)
2364 return V;
2365 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2366 return Folded;
2367 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2368 if (isa<FPMathOperator>(Cast))
2369 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2370 return Insert(Cast, Name);
2371 }
2372
2374 const Twine &Name = "") {
2375 if (V->getType() == DestTy)
2376 return V;
2377 if (auto *VC = dyn_cast<Constant>(V))
2378 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2379 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2380 }
2381
2382 // With opaque pointers enabled, this can be substituted with
2383 // CreateAddrSpaceCast.
2384 // TODO: Replace uses of this method and remove the method itself.
2386 const Twine &Name = "") {
2387 if (V->getType() == DestTy)
2388 return V;
2389
2390 if (auto *VC = dyn_cast<Constant>(V)) {
2391 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2392 Name);
2393 }
2394
2396 Name);
2397 }
2398
2400 const Twine &Name = "") {
2401 Instruction::CastOps CastOp =
2402 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2403 ? Instruction::Trunc
2404 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2405 return CreateCast(CastOp, V, DestTy, Name);
2406 }
2407
2409 const Twine &Name = "") {
2410 if (V->getType() == DestTy)
2411 return V;
2412 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2413 return CreatePtrToInt(V, DestTy, Name);
2414 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2415 return CreateIntToPtr(V, DestTy, Name);
2416
2417 return CreateBitCast(V, DestTy, Name);
2418 }
2419
2420 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2421 MDNode *FPMathTag = nullptr) {
2422 Instruction::CastOps CastOp =
2423 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2424 ? Instruction::FPTrunc
2425 : Instruction::FPExt;
2426 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2427 }
2428
2430 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2431 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2432 std::optional<RoundingMode> Rounding = std::nullopt,
2433 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2434
2435 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2436 // compile time error, instead of converting the string to bool for the
2437 // isSigned parameter.
2438 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2439
2440 /// Cast between aggregate types that must have identical structure but may
2441 /// differ in their leaf types. The leaf values are recursively extracted,
2442 /// casted, and then reinserted into a value of type DestTy. The leaf types
2443 /// must be castable using a bitcast or ptrcast, because signedness is
2444 /// not specified.
2446
2447 /// Create a chain of casts to convert V to NewTy, preserving the bit pattern
2448 /// of V. This may involve multiple casts (e.g., ptr -> i64 -> <2 x i32>).
2449 /// The created cast instructions are inserted into the current basic block.
2450 /// If no casts are needed, V is returned.
2452 Type *NewTy);
2453
2454 //===--------------------------------------------------------------------===//
2455 // Instruction creation methods: Compare Instructions
2456 //===--------------------------------------------------------------------===//
2457
2458 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2459 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2460 }
2461
2462 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2463 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2464 }
2465
2466 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2467 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2468 }
2469
2470 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2471 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2472 }
2473
2474 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2475 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2476 }
2477
2478 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2479 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2480 }
2481
2482 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2483 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2484 }
2485
2486 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2487 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2488 }
2489
2490 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2491 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2492 }
2493
2494 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2495 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2496 }
2497
2498 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2499 MDNode *FPMathTag = nullptr) {
2500 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2501 }
2502
2503 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2504 MDNode *FPMathTag = nullptr) {
2505 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2506 }
2507
2508 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2509 MDNode *FPMathTag = nullptr) {
2510 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2511 }
2512
2513 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2514 MDNode *FPMathTag = nullptr) {
2515 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2516 }
2517
2518 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2519 MDNode *FPMathTag = nullptr) {
2520 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2521 }
2522
2523 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2524 MDNode *FPMathTag = nullptr) {
2525 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2526 }
2527
2528 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2529 MDNode *FPMathTag = nullptr) {
2530 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2531 }
2532
2533 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2534 MDNode *FPMathTag = nullptr) {
2535 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2536 }
2537
2538 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2539 MDNode *FPMathTag = nullptr) {
2540 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2541 }
2542
2543 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2544 MDNode *FPMathTag = nullptr) {
2545 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2546 }
2547
2548 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2549 MDNode *FPMathTag = nullptr) {
2550 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2551 }
2552
2553 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2554 MDNode *FPMathTag = nullptr) {
2555 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2556 }
2557
2558 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2559 MDNode *FPMathTag = nullptr) {
2560 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2561 }
2562
2563 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2564 MDNode *FPMathTag = nullptr) {
2565 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2566 }
2567
2569 const Twine &Name = "", bool HasSameSign = false) {
2570 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2571 return V;
2572 ICmpInst *I = Insert(new ICmpInst(P, LHS, RHS), Name);
2573 if (HasSameSign)
2574 I->setSameSign();
2575 return I;
2576 }
2577
2578 // Create a quiet floating-point comparison (i.e. one that raises an FP
2579 // exception only in the case where an input is a signaling NaN).
2580 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2582 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2583 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2584 }
2585
2586 // Create a quiet floating-point comparison (i.e. one that raises an FP
2587 // exception only in the case where an input is a signaling NaN).
2588 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2590 FMFSource FMFSource, const Twine &Name = "",
2591 MDNode *FPMathTag = nullptr) {
2592 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2593 }
2594
2596 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2598 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2599 : CreateICmp(Pred, LHS, RHS, Name);
2600 }
2601
2602 // Create a signaling floating-point comparison (i.e. one that raises an FP
2603 // exception whenever an input is any NaN, signaling or quiet).
2604 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2606 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2607 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2608 }
2609
2610private:
2611 // Helper routine to create either a signaling or a quiet FP comparison.
2612 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2613 const Twine &Name, MDNode *FPMathTag,
2614 FMFSource FMFSource, bool IsSignaling);
2615
2616public:
2619 const Twine &Name = "",
2620 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2621
2622 //===--------------------------------------------------------------------===//
2623 // Instruction creation methods: Other Instructions
2624 //===--------------------------------------------------------------------===//
2625
2626 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2627 const Twine &Name = "") {
2628 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2629 if (isa<FPMathOperator>(Phi))
2630 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2631 return Insert(Phi, Name);
2632 }
2633
2634private:
2635 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2636 const Twine &Name = "", FMFSource FMFSource = {},
2637 ArrayRef<OperandBundleDef> OpBundles = {});
2638
2639public:
2641 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2642 MDNode *FPMathTag = nullptr) {
2643 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2644 if (IsFPConstrained)
2646 if (isa<FPMathOperator>(CI))
2647 setFPAttrs(CI, FPMathTag, FMF);
2648 return Insert(CI, Name);
2649 }
2650
2652 FMFSource FMFSource, const Twine &Name = "",
2653 MDNode *FPMathTag = nullptr) {
2654 return CreateCall(FTy, Callee, Args, DefaultOperandBundles, FMFSource, Name,
2655 FPMathTag);
2656 }
2657
2660 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2661 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2662 if (IsFPConstrained)
2664 if (isa<FPMathOperator>(CI))
2665 setFPAttrs(CI, FPMathTag, FMF);
2666 return Insert(CI, Name);
2667 }
2668
2671 FMFSource FMFSource, const Twine &Name = "",
2672 MDNode *FPMathTag = nullptr) {
2673 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2674 if (IsFPConstrained)
2676 if (isa<FPMathOperator>(CI))
2677 setFPAttrs(CI, FPMathTag, FMFSource.get(FMF));
2678 return Insert(CI, Name);
2679 }
2680
2682 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2683 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2684 FPMathTag);
2685 }
2686
2688 FMFSource FMFSource, const Twine &Name = "",
2689 MDNode *FPMathTag = nullptr) {
2690 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2691 FMFSource, Name, FPMathTag);
2692 }
2693
2696 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2697 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2698 OpBundles, Name, FPMathTag);
2699 }
2700
2703 FMFSource FMFSource, const Twine &Name = "",
2704 MDNode *FPMathTag = nullptr) {
2705 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2706 OpBundles, FMFSource, Name, FPMathTag);
2707 }
2708
2710 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2711 std::optional<RoundingMode> Rounding = std::nullopt,
2712 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2713
2715 Value *False,
2717 const Twine &Name = "");
2718
2720 Value *False,
2723 const Twine &Name = "");
2724
2726 const Twine &Name = "",
2727 Instruction *MDFrom = nullptr);
2729 FMFSource FMFSource, const Twine &Name = "",
2730 Instruction *MDFrom = nullptr);
2731
2732 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2733 return Insert(new VAArgInst(List, Ty), Name);
2734 }
2735
2737 const Twine &Name = "") {
2738 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2739 return V;
2740 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2741 }
2742
2744 const Twine &Name = "") {
2745 return CreateExtractElement(Vec, getInt64(Idx), Name);
2746 }
2747
2748 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2749 const Twine &Name = "") {
2750 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2751 }
2752
2754 const Twine &Name = "") {
2755 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2756 }
2757
2759 const Twine &Name = "") {
2760 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2761 return V;
2762 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2763 }
2764
2766 const Twine &Name = "") {
2767 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2768 }
2769
2771 const Twine &Name = "") {
2772 SmallVector<int, 16> IntMask;
2774 return CreateShuffleVector(V1, V2, IntMask, Name);
2775 }
2776
2777 /// See class ShuffleVectorInst for a description of the mask representation.
2779 const Twine &Name = "") {
2780 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2781 return V;
2782 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2783 }
2784
2785 /// Create a unary shuffle. The second vector operand of the IR instruction
2786 /// is poison.
2788 const Twine &Name = "") {
2789 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2790 }
2791
2793 const Twine &Name = "");
2794
2796 const Twine &Name = "") {
2797 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2798 return V;
2799 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2800 }
2801
2803 const Twine &Name = "") {
2804 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2805 return V;
2806 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2807 }
2808
2809 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2810 const Twine &Name = "") {
2811 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2812 }
2813
2814 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2815 return Insert(new FreezeInst(V), Name);
2816 }
2817
2819 const Twine &Name = "") {
2820 if (Value *V = Folder.FoldBitInsert(Base, Val, Offset))
2821 return V;
2822 return Insert(BitInsertInst::Create(Base, Val, Offset), Name);
2823 }
2824
2826 const Twine &Name = "") {
2827 if (Value *V = Folder.FoldBitExtract(Ty, Src, Offset))
2828 return V;
2829 return Insert(BitExtractInst::Create(Ty, Src, Offset), Name);
2830 }
2831
2832 //===--------------------------------------------------------------------===//
2833 // Utility creation methods
2834 //===--------------------------------------------------------------------===//
2835
2836 /// Return a boolean value testing if \p Arg == 0.
2837 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2838 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2839 }
2840
2841 /// Return a boolean value testing if \p Arg != 0.
2842 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2843 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2844 }
2845
2846 /// Return a boolean value testing if \p Arg < 0.
2847 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2848 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2849 }
2850
2851 /// Return a boolean value testing if \p Arg > -1.
2852 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2854 Name);
2855 }
2856
2857 /// Return the difference between two pointer values. The returned value
2858 /// type is the address type of the pointers.
2859 LLVM_ABI Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "",
2860 bool IsNUW = false);
2861
2862 /// Return the difference between two pointer values, dividing out the size
2863 /// of the pointed-to objects. The returned value type is the address type
2864 /// of the pointers.
2865 ///
2866 /// This is intended to implement C-style pointer subtraction. As such, the
2867 /// pointers must be appropriately aligned for their element types and
2868 /// pointing into the same object.
2870 const Twine &Name = "");
2871
2872 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2873 /// different from pointer to i8, it's casted to pointer to i8 in the same
2874 /// address space before call and casted back to Ptr type after call.
2876
2877 /// Return a vector value that contains the vector V reversed
2878 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2879
2880 /// Create a vector.splice.left intrinsic call, or a shufflevector that
2881 /// produces the same result if the result type is a fixed-length vector and
2882 /// \p Offset is a constant.
2884 const Twine &Name = "");
2885
2887 const Twine &Name = "") {
2888 return CreateVectorSpliceLeft(V1, V2, getInt32(Offset), Name);
2889 }
2890
2891 /// Create a vector.splice.right intrinsic call, or a shufflevector that
2892 /// produces the same result if the result type is a fixed-length vector and
2893 /// \p Offset is a constant.
2895 const Twine &Name = "");
2896
2898 const Twine &Name = "") {
2899 return CreateVectorSpliceRight(V1, V2, getInt32(Offset), Name);
2900 }
2901
2902 /// Return a vector value that contains \arg V broadcasted to \p
2903 /// NumElts elements.
2904 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2905 const Twine &Name = "");
2906
2907 /// Return a vector value that contains \arg V broadcasted to \p
2908 /// EC elements.
2910 const Twine &Name = "");
2911
2913 unsigned Dimension,
2914 unsigned LastIndex,
2915 MDNode *DbgInfo);
2916
2918 unsigned FieldIndex,
2919 MDNode *DbgInfo);
2920
2922 unsigned Index,
2923 unsigned FieldIndex,
2924 MDNode *DbgInfo);
2925
2926 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2927
2928private:
2929 /// Helper function that creates an assume intrinsic call that
2930 /// represents an alignment assumption on the provided pointer \p PtrValue
2931 /// with offset \p OffsetValue and alignment value \p AlignValue.
2932 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2933 Value *PtrValue, Value *AlignValue,
2934 Value *OffsetValue);
2935
2936public:
2937 /// Create an assume intrinsic call that represents an alignment
2938 /// assumption on the provided pointer.
2939 ///
2940 /// An optional offset can be provided, and if it is provided, the offset
2941 /// must be subtracted from the provided pointer to get the pointer with the
2942 /// specified alignment.
2944 Value *PtrValue,
2945 uint64_t Alignment,
2946 Value *OffsetValue = nullptr);
2947
2948 /// Create an assume intrinsic call that represents an alignment
2949 /// assumption on the provided pointer.
2950 ///
2951 /// An optional offset can be provided, and if it is provided, the offset
2952 /// must be subtracted from the provided pointer to get the pointer with the
2953 /// specified alignment.
2954 ///
2955 /// This overload handles the condition where the Alignment is dependent
2956 /// on an existing value rather than a static value.
2958 Value *PtrValue,
2959 Value *Alignment,
2960 Value *OffsetValue = nullptr);
2961
2962 /// Create an assume intrinsic call that represents a dereferencable
2963 /// assumption on the provided pointer.
2965 Value *SizeValue);
2966
2967 /// Create an assume intrinsic call that represents a nonnull assumption on
2968 /// the provided pointer.
2970
2972};
2973
2974/// This provides a uniform API for creating instructions and inserting
2975/// them into a basic block: either at the end of a BasicBlock, or at a specific
2976/// iterator location in a block.
2977///
2978/// Note that the builder does not expose the full generality of LLVM
2979/// instructions. For access to extra instruction properties, use the mutators
2980/// (e.g. setVolatile) on the instructions after they have been
2981/// created. Convenience state exists to specify fast-math flags and fp-math
2982/// tags.
2983///
2984/// The first template argument specifies a class to use for creating constants.
2985/// This defaults to creating minimally folded constants. The second template
2986/// argument allows clients to specify custom insertion hooks that are called on
2987/// every newly created insertion.
2988template <typename FolderTy = ConstantFolder,
2989 typename InserterTy = IRBuilderDefaultInserter>
2990class IRBuilder : public IRBuilderBase {
2991private:
2992 FolderTy Folder;
2993 InserterTy Inserter;
2994
2995 static void CallInsertHelper(const IRBuilderBase &IRB, Instruction *I,
2996 const Twine &Name,
2998 static_cast<const IRBuilder *>(&IRB)->Inserter.InsertHelper(I, Name,
2999 InsertPt);
3000 }
3001
3002public:
3003 [[deprecated("Use the overload taking Module instead")]]
3004 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter)
3005 : IRBuilderBase(C, this->Folder, CallInsertHelper), Folder(Folder),
3006 Inserter(Inserter) {}
3007
3008 [[deprecated("Use the overload taking Module instead")]]
3009 IRBuilder(LLVMContext &C, FolderTy Folder)
3010 : IRBuilderBase(C, this->Folder, CallInsertHelper), Folder(Folder) {}
3011
3012 [[deprecated("Use the overload taking Module instead")]]
3014 : IRBuilderBase(C, this->Folder, CallInsertHelper) {}
3015
3016 IRBuilder(Module &M, FolderTy Folder, InserterTy Inserter)
3017 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper),
3018 Folder(Folder), Inserter(Inserter) {}
3019
3020 IRBuilder(Module &M, FolderTy Folder)
3021 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper),
3022 Folder(Folder) {}
3023
3024 explicit IRBuilder(Module &M)
3025 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper) {}
3026
3027 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder)
3028 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper),
3029 Folder(Folder) {
3030 SetInsertPoint(TheBB);
3031 }
3032
3033 explicit IRBuilder(BasicBlock *TheBB)
3034 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper) {
3035 SetInsertPoint(TheBB);
3036 }
3037
3039 : IRBuilderBase(IP->getContext(), this->Folder, CallInsertHelper) {
3040 SetInsertPoint(IP);
3041 }
3042
3043 [[deprecated("Use the overload without BasicBlock argument instead")]]
3044 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder)
3045 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper),
3046 Folder(Folder) {
3047 SetInsertPoint(IP);
3048 }
3049
3050 [[deprecated("Use the overload without BasicBlock argument instead")]]
3052 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper) {
3053 SetInsertPoint(IP);
3054 }
3055
3056 IRBuilder(BasicBlock::iterator IP, FolderTy Folder, InserterTy Inserter)
3057 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3058 CallInsertHelper),
3059 Folder(Folder), Inserter(Inserter) {
3060 SetInsertPoint(IP);
3061 }
3062
3063 IRBuilder(BasicBlock::iterator IP, FolderTy Folder)
3064 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3065 CallInsertHelper),
3066 Folder(Folder) {
3067 SetInsertPoint(IP);
3068 }
3069
3071 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3072 CallInsertHelper) {
3073 SetInsertPoint(IP);
3074 }
3075
3076 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
3077 /// or FastMathFlagGuard instead.
3078 IRBuilder(const IRBuilder &) = delete;
3079
3080 InserterTy &getInserter() { return Inserter; }
3081 const InserterTy &getInserter() const { return Inserter; }
3082};
3083
3084template <typename FolderTy, typename InserterTy>
3085IRBuilder(LLVMContext &, FolderTy, InserterTy)
3088template <typename FolderTy, typename InserterTy>
3090template <typename FolderTy>
3093template <typename FolderTy>
3097template <typename FolderTy>
3100template <typename FolderTy, typename InserterTy>
3101IRBuilder(BasicBlock::iterator, FolderTy, InserterTy)
3103template <typename FolderTy>
3106
3107/// Unwrap C API builder reference.
3109
3110} // end namespace llvm
3111
3112#endif // LLVM_IR_IRBUILDER_H
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isSigned(unsigned Opcode)
This file contains the declarations of entities that describe floating point environment and related ...
Module.h This file contains the declarations for the Module class.
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
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define P(N)
MachineBasicBlock * Folded
SmallVector< MachineOperand, 4 > Cond
static unsigned getFastMathFlags(const MachineInstr &I, const SPIRVSubtarget &ST)
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
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
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:453
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
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:459
static BitExtractInst * Create(Type *Ty, Value *Src, Value *Offset, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static BitInsertInst * Create(Value *Base, Value *Val, Value *Offset, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Class to represent byte types.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:757
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:749
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:742
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
bool isFPPredicate() const
Definition InstrTypes.h:845
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 ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
This class represents a range of values.
This is an important base class in LLVM.
Definition Constant.h:44
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
LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
A debug info location.
Definition DebugLoc.h:126
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:90
FMFSource(Instruction *Source)
Definition IRBuilder.h:95
FMFSource()=default
FastMathFlags get(FastMathFlags Default) const
Definition IRBuilder.h:100
FMFSource(FastMathFlags FMF)
Definition IRBuilder.h:99
static FMFSource intersect(Value *A, Value *B)
Intersect the FMF from two instructions.
Definition IRBuilder.h:104
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
OperandBundlesGuard(const OperandBundlesGuard &)=delete
OperandBundlesGuard & operator=(const OperandBundlesGuard &)=delete
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1497
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2336
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2523
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
Definition IRBuilder.h:1086
void SetCurrentDebugLocation(DebugLoc &&L)
Set location information used by debugging information.
Definition IRBuilder.h:236
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition IRBuilder.h:446
Value * CreateExtractVector(Type *DstType, Value *SrcVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1122
Value * CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2605
LLVM_ABI CallInst * CreateIntrinsicWithoutFolding(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={})
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1471
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1350
LLVM_ABI Value * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Value * CreateFSubFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1662
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2474
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2282
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2057
IRBuilderBase(LLVMContext &context, const IRBuilderFolder &Folder, InsertFn InsertCB)
Definition IRBuilder.h:135
LLVM_ABI Value * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNull=false)
Definition IRBuilder.h:2324
RoundingMode DefaultConstrainedRounding
Definition IRBuilder.h:131
LLVM_ABI Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
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:2548
CallInst * CreateStructuredAlloca(Type *BaseType, const Twine &Name="")
Definition IRBuilder.h:1901
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2753
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1507
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition IRBuilder.h:1945
const DataLayout & getDataLayout() const
Get data layout.
Definition IRBuilder.h:182
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const LoadStoreInstProperties &Props, const Twine &Name="")
Definition IRBuilder.h:1925
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1657
LLVM_ABI Value * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2581
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition IRBuilder.h:1345
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:2748
Value * CreateVectorSpliceLeft(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2886
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1548
Value * CreatePtrAddWithUnsignedOffset(Value *Ptr, uint64_t Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Create a ptradd with an unsigned constant offset.
Definition IRBuilder.h:2113
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1974
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:2026
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1886
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition IRBuilder.h:344
Value * CreateBitExtract(Type *Ty, Value *Src, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2825
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition IRBuilder.h:1142
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1278
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:513
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:2802
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1586
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:1251
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1578
void setDefaultFPMathTag(MDNode *FPMathTag)
Set the floating point math metadata to be used.
Definition IRBuilder.h:286
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...
Value * CreateScaledPtrAdd(Value *Ptr, uint64_t Scale, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2148
LLVM_ABI Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition IRBuilder.cpp:61
ByteType * getByteNTy(unsigned N)
Fetch the type representing an N-bit byte.
Definition IRBuilder.h:510
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2694
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:1695
LLVM_ABI CallInst * CreateLifetimeStart(Value *Ptr)
Create a lifetime.start intrinsic.
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1543
void clearFastMathFlags()
Clear the fast-math flags.
Definition IRBuilder.h:283
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.
LLVM_ABI CallInst * CreateNonnullAssumption(Value *PtrValue)
Create an assume intrinsic call that represents a nonnull assumption on the provided pointer.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1920
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1802
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2736
LLVM_ABI Value * CreateFPMaximumNumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition IRBuilder.h:541
LLVM_ABI Value * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
void setDefaultConstrainedExcept(fp::ExceptionBehavior NewExcept)
Set the exception handling to be used with constrained floating point.
Definition IRBuilder.h:301
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2482
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:1940
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2528
Value * CreateStructuredGEP(Type *BaseType, Value *PtrBase, ArrayRef< Value * > Indices, const Twine &Name="")
Definition IRBuilder.h:2001
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition IRBuilder.h:561
Value * CreateNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsNUW, bool IsNSW, const Twine &Name="")
Definition IRBuilder.h:1750
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2215
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:657
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:1218
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1638
UnreachableInst * CreateUnreachable()
Definition IRBuilder.h:1360
Value * CreateBitInsert(Value *Base, Value *Val, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2818
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)
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2277
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2373
LLVM_ABI Value * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
void setDefaultConstrainedRounding(RoundingMode NewRounding)
Set the rounding mode handling to be used with constrained floating point.
Definition IRBuilder.h:311
Value * CreatePtrToAddr(Value *V, const Twine &Name="")
Definition IRBuilder.h:2305
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:1714
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2795
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1582
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition IRBuilder.h:451
StoreInst * CreateStore(Value *Val, Value *Ptr, const LoadStoreInstProperties &Props)
Definition IRBuilder.h:1935
Value * CreatePtrAddWithZExtOrTrunc(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Create a ptradd where the offset is zero-extended or truncated to the index type.
Definition IRBuilder.h:2142
Value * Insert(Value *V, const Twine &Name="") const
Definition IRBuilder.h:159
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
Definition IRBuilder.h:2809
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2297
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1062
LLVM_ABI Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
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:2486
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)
LLVM_ABI Value * CreateFPMinimumNumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
LLVMContext & Context
Definition IRBuilder.h:121
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:1256
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2669
RoundingMode getDefaultConstrainedRounding()
Get the rounding mode handling used with constrained floating point.
Definition IRBuilder.h:326
LLVM_ABI Value * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2243
Value * CreateVectorSpliceRight(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2897
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2069
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2563
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:177
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2087
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1967
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:589
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1320
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:321
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2209
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2344
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2543
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2314
Value * CreateFreeze(Value *V, const Twine &Name="")
Definition IRBuilder.h:2814
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2701
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
Definition IRBuilder.h:229
BasicBlock::iterator InsertPt
Definition IRBuilder.h:120
ReturnInst * CreateAggregateRet(ArrayRef< Value * > RetVals)
Create a sequence of N insertvalue instructions, with one Value from the RetVals array each,...
Definition IRBuilder.h:1204
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Create a callbr instruction.
Definition IRBuilder.h:1294
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:1534
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:583
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition IRBuilder.h:528
Value * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1114
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition IRBuilder.h:2032
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:75
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition IRBuilder.h:461
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2094
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2360
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2852
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition IRBuilder.h:1356
LLVM_ABI CallInst * CreateRangeAssumption(Value *Int, ConstantRange Range)
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition IRBuilder.h:1333
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition IRBuilder.h:1194
LLVM_ABI CallInst * CreateAssumption(Value *Cond)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1433
bool getIsFPConstrained()
Query for the use of constrained floating point math.
Definition IRBuilder.h:298
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false, MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2257
Value * CreateVScale(Type *Ty, const Twine &Name="")
Create a call to llvm.vscale.<Ty>().
Definition IRBuilder.h:938
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1567
BasicBlock * GetInsertBlock() const
Definition IRBuilder.h:174
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition IRBuilder.h:546
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Definition IRBuilder.h:289
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2513
void SetInsertPointPastAllocas(Function *F)
This specifies that created instructions should inserted at the beginning end of the specified functi...
Definition IRBuilder.h:224
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:533
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition IRBuilder.h:2021
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", bool HasSameSign=false)
Definition IRBuilder.h:2568
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1467
InsertPoint saveAndClearIP()
Returns the current insert point, clearing it in the process.
Definition IRBuilder.h:260
Value * CreateOr(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1604
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:2385
Module * getModule() const
Get the module.
Definition IRBuilder.h:190
LLVM_ABI Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
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:2787
Value * CreatePtrAddWithSExtOrTrunc(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Create a ptradd where the offset is sign-extended or truncated to the index type.
Definition IRBuilder.h:2133
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1562
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1475
Value * CreateFAbs(Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fabs intrinsic.
Definition IRBuilder.h:1027
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2558
FastMathFlags FMF
Definition IRBuilder.h:126
LLVM_ABI Value * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
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:2462
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1437
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition IRBuilder.h:523
Value * CreateFCmpFMF(CmpInst::Predicate P, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2589
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:476
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:699
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition IRBuilder.h:1338
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:842
LLVM_ABI Value * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1860
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1832
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1916
UncondBrInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition IRBuilder.h:1212
InsertPoint saveIP() const
Returns the current insert point.
Definition IRBuilder.h:257
Value * CreateArithmeticFence(Value *Val, Type *DstType, const Twine &Name="")
Create a call to the arithmetic_fence intrinsic.
Definition IRBuilder.h:1107
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1772
void SetInsertPoint(BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
Definition IRBuilder.h:215
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2765
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1528
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:2778
LLVM_ABI Value * createIsFPClass(Value *FPNum, unsigned Test)
LLVM_ABI Value * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2518
void disableGEPCanonicalization()
Disable canonicalization of getelementptr instructions to ptradd form.
Definition IRBuilder.h:351
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:471
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:1045
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2408
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2595
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1787
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2420
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2494
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2626
LLVM_ABI Value * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2658
CondBrInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition IRBuilder.h:1227
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1856
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:1241
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2458
BasicBlock::iterator InsertPoint
InsertPoint - A saved insertion point.
Definition IRBuilder.h:254
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition IRBuilder.h:148
Value * CreateBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1739
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2538
LLVM_ABI Value * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
void setIsFPConstrained(bool IsCon)
Enable/Disable use of constrained floating point math.
Definition IRBuilder.h:295
LLVM_ABI DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition IRBuilder.cpp:67
Value * CreateMinimum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minimum intrinsic.
Definition IRBuilder.h:1057
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition IRBuilder.h:538
Value * CreateCountTrailingZeroElems(Type *ResTy, Value *Mask, bool ZeroIsPoison=true, const Twine &Name="")
Create a call to llvm.experimental_cttz_elts.
Definition IRBuilder.h:1156
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition IRBuilder.h:2847
Constant * Insert(Constant *C, const Twine &="") const
No-op overload to handle constants.
Definition IRBuilder.h:155
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1441
Value * CreateFMA(Value *Factor1, Value *Factor2, Value *Summand, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fma intrinsic.
Definition IRBuilder.h:1094
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2319
ByteType * getByte128Ty()
Fetch the type representing a 128-bit byte.
Definition IRBuilder.h:507
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended from a 64-bit value.
Definition IRBuilder.h:481
Value * CreateDisjointOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1620
ByteType * getByte16Ty()
Fetch the type representing a 16-bit byte.
Definition IRBuilder.h:498
Value * CreateCopySign(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the copysign intrinsic.
Definition IRBuilder.h:1079
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:2466
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:1913
Value * CreateUnOpFMF(Instruction::UnaryOps Opc, Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1866
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:623
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1513
FastMathFlags getFastMathFlags() const
Get the flags to be applied to created floating point ops.
Definition IRBuilder.h:278
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:602
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 * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
Definition IRBuilder.h:1019
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2197
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:2770
LLVMContext & getContext() const
Definition IRBuilder.h:178
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2498
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1572
FastMathFlags & getFastMathFlags()
Definition IRBuilder.h:280
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition IRBuilder.h:1189
ByteType * getByte32Ty()
Fetch the type representing a 32-bit byte.
Definition IRBuilder.h:501
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
Value * CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1073
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1450
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition IRBuilder.h:2048
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2078
Value * CreateMinNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the minnum intrinsic.
Definition IRBuilder.h:1033
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1286
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1931
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:1424
Value * CreateExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact, const Twine &Name="")
Definition IRBuilder.h:1762
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2309
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1488
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition IRBuilder.h:456
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition IRBuilder.h:2732
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1484
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition IRBuilder.h:556
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition IRBuilder.h:2842
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
Definition IRBuilder.h:209
Instruction * CreateNoAliasScopeDeclaration(MDNode *ScopeTag)
Definition IRBuilder.h:857
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2640
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1522
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:577
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:2183
Value * CreateScaledPtrAdd(Value *Ptr, TypeSize Scale, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2163
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:571
LLVM_ABI CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, uint64_t Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1733
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2758
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2063
fp::ExceptionBehavior DefaultConstrainedExcept
Definition IRBuilder.h:130
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition IRBuilder.h:172
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1313
ByteType * getByte8Ty()
Fetch the type representing an 8-bit byte.
Definition IRBuilder.h:495
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2490
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition IRBuilder.h:466
MDNode * DefaultFPMathTag
Definition IRBuilder.h:125
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:133
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1302
LLVM_ABI CallInst * CreateDereferenceableAssumption(Value *PtrValue, Value *SizeValue)
Create an assume intrinsic call that represents a dereferencable assumption on the provided pointer.
CallInst * CreateIntrinsicWithoutFolding(Intrinsic::ID ID, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to non-overloaded intrinsic ID with Args.
Definition IRBuilder.h:991
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2470
MDNode * getDefaultFPMathTag() const
Get the floating point math metadata being used.
Definition IRBuilder.h:275
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2399
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2533
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition IRBuilder.h:267
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
Definition IRBuilder.h:2837
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:671
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2503
CallInst * CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:679
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition IRBuilder.h:1150
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:197
Type * getVoidTy()
Fetch the type representing void.
Definition IRBuilder.h:566
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1267
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 * CreatePtrAddWithSignedOffset(Value *Ptr, int64_t Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Create a ptradd with a signed constant offset.
Definition IRBuilder.h:2123
Value * CreateOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1612
Value * CreateFAddFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1643
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1780
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1893
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:2038
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2743
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1959
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1608
void setConstrainedFPCallAttr(CallBase *I)
Definition IRBuilder.h:340
Value * CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minimumnum intrinsic.
Definition IRBuilder.h:1067
LLVM_ABI Value * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
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:504
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:122
Value * CreateInBoundsPtrAdd(Value *Ptr, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2105
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2292
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:1553
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2681
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1846
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1624
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2687
IRBuilderBase(const IRBuilderBase &)=delete
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2352
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2478
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2269
LLVM_ABI Value * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
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:1676
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1950
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1841
void setConstrainedFPFunctionAttr()
Definition IRBuilder.h:330
LLVM_ABI void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition IRBuilder.cpp:68
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
Definition IRBuilder.h:1594
void SetInsertPoint(Instruction *I)
This specifies that created instructions should be inserted before the specified instruction.
Definition IRBuilder.h:201
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:518
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition IRBuilder.h:486
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:1700
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1501
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:2230
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1329
Value * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition IRBuilder.h:1128
Type * getBFloatTy()
Fetch the type representing a 16-bit brain floating point value.
Definition IRBuilder.h:551
Value * CreateFMulFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1681
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1630
LLVM_ABI CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
void(*)(const IRBuilderBase &, Instruction *, const Twine &, BasicBlock::iterator) InsertFn
Definition IRBuilder.h:117
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1458
Value * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1136
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:1719
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1634
LLVM_ABI Value * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *Op, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, bool Elementwise=false)
Definition IRBuilder.h:1987
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:46
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Definition IRBuilder.h:1837
LLVM_ABI Value * CreateElementCount(Type *Ty, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2508
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:707
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 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:1454
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2553
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2250
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2651
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock::iterator InsertPt) const
Definition IRBuilder.h:81
IRBuilderCallbackInserter(std::function< void(Instruction *)> Callback)
Definition IRBuilder.h:78
This provides the default implementation of the IRBuilder 'InsertHelper' method that is called whenev...
Definition IRBuilder.h:62
void InsertHelper(Instruction *I, const Twine &Name, BasicBlock::iterator InsertPt) const
Definition IRBuilder.h:64
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:2990
IRBuilder(Module &M)
Definition IRBuilder.h:3024
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(BasicBlock *TheBB)
Definition IRBuilder.h:3033
IRBuilder(Instruction *IP)
Definition IRBuilder.h:3038
IRBuilder(BasicBlock *TheBB, FolderTy Folder)
Definition IRBuilder.h:3027
IRBuilder(LLVMContext &C, FolderTy Folder)
Definition IRBuilder.h:3009
InserterTy & getInserter()
Definition IRBuilder.h:3080
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:3004
IRBuilder(Module &M, FolderTy Folder)
Definition IRBuilder.h:3020
IRBuilder(LLVMContext &C)
Definition IRBuilder.h:3013
IRBuilder(BasicBlock::iterator IP, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:3056
IRBuilder(Module &M, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:3016
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder)
Definition IRBuilder.h:3044
IRBuilder(BasicBlock::iterator IP, FolderTy Folder)
Definition IRBuilder.h:3063
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP)
Definition IRBuilder.h:3051
IRBuilder(BasicBlock::iterator IP)
Definition IRBuilder.h:3070
const InserterTy & getInserter() const
Definition IRBuilder.h:3081
Indirect Branch Instruction.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Class to represent integer types.
Invoke instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
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:1081
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:595
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:105
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:887
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:287
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
Definition Type.cpp:301
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
static LLVM_ABI ByteType * getByte32Ty(LLVMContext &C)
Definition Type.cpp:288
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:272
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:298
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
static LLVM_ABI ByteType * getByte8Ty(LLVMContext &C)
Definition Type.cpp:286
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI ByteType * getByte128Ty(LLVMContext &C)
Definition Type.cpp:290
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:280
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:303
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:277
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:276
static LLVM_ABI ByteType * getByteNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:292
static LLVM_ABI ByteType * getByte64Ty(LLVMContext &C)
Definition Type.cpp:289
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:275
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:274
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:257
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.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
An efficient, type-erasing, non-owning reference to a callable.
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:66
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:577
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:2224
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
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:68
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
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.
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:397
IntPtrTy
Definition InstrProf.h:82
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:1933
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:774
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
A structure representing the properties of a load or store instruction.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111