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 = false;
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
349
350 //===--------------------------------------------------------------------===//
351 // RAII helpers.
352 //===--------------------------------------------------------------------===//
353
354 // RAII object that stores the current insertion point and restores it
355 // when the object is destroyed. This includes the debug location.
357 IRBuilderBase &Builder;
359 DebugLoc DbgLoc;
360
361 public:
363 : Builder(B), Point(B.GetInsertPoint()),
364 DbgLoc(B.getCurrentDebugLocation()) {}
365
368
370 Builder.restoreIP(Point);
371 Builder.SetCurrentDebugLocation(DbgLoc);
372 }
373 };
374
375 // RAII object that stores the current fast math settings and restores
376 // them when the object is destroyed.
378 IRBuilderBase &Builder;
379 FastMathFlags FMF;
380 MDNode *FPMathTag;
381 bool IsFPConstrained;
382 fp::ExceptionBehavior DefaultConstrainedExcept;
383 RoundingMode DefaultConstrainedRounding;
384
385 public:
387 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag),
388 IsFPConstrained(B.IsFPConstrained),
389 DefaultConstrainedExcept(B.DefaultConstrainedExcept),
390 DefaultConstrainedRounding(B.DefaultConstrainedRounding) {}
391
394
396 Builder.FMF = FMF;
397 Builder.DefaultFPMathTag = FPMathTag;
398 Builder.IsFPConstrained = IsFPConstrained;
399 Builder.DefaultConstrainedExcept = DefaultConstrainedExcept;
400 Builder.DefaultConstrainedRounding = DefaultConstrainedRounding;
401 }
402 };
403
404 // RAII object that stores the current default operand bundles and restores
405 // them when the object is destroyed.
407 IRBuilderBase &Builder;
408 ArrayRef<OperandBundleDef> DefaultOperandBundles;
409
410 public:
412 : Builder(B), DefaultOperandBundles(B.DefaultOperandBundles) {}
413
416
418 Builder.DefaultOperandBundles = DefaultOperandBundles;
419 }
420 };
421
422
423 //===--------------------------------------------------------------------===//
424 // Miscellaneous creation methods.
425 //===--------------------------------------------------------------------===//
426
427 /// Make a new global variable with initializer type i8*
428 ///
429 /// Make a new global variable with an initializer that has array of i8 type
430 /// filled in with the null terminated string value specified. The new global
431 /// variable will be marked mergable with any others of the same contents. If
432 /// Name is specified, it is the name of the global variable created.
433 ///
434 /// If no module is given via \p M, it is take from the insertion point basic
435 /// block.
437 const Twine &Name = "",
438 unsigned AddressSpace = 0,
439 Module *M = nullptr,
440 bool AddNull = true);
441
442 /// Get a constant value representing either true or false.
444 return ConstantInt::get(getInt1Ty(), V);
445 }
446
447 /// Get the constant value for i1 true.
451
452 /// Get the constant value for i1 false.
456
457 /// Get a constant 8-bit value.
459 return ConstantInt::get(getInt8Ty(), C);
460 }
461
462 /// Get a constant 16-bit value.
464 return ConstantInt::get(getInt16Ty(), C);
465 }
466
467 /// Get a constant 32-bit value.
469 return ConstantInt::get(getInt32Ty(), C);
470 }
471
472 /// Get a constant 64-bit value.
474 return ConstantInt::get(getInt64Ty(), C);
475 }
476
477 /// Get a constant N-bit value, zero extended from a 64-bit value.
479 return ConstantInt::get(getIntNTy(N), C);
480 }
481
482 /// Get a constant integer value.
484 return ConstantInt::get(Context, AI);
485 }
486
487 //===--------------------------------------------------------------------===//
488 // Type creation methods
489 //===--------------------------------------------------------------------===//
490
491 /// Fetch the type representing an 8-bit byte.
493
494 /// Fetch the type representing a 16-bit byte.
496
497 /// Fetch the type representing a 32-bit byte.
499
500 /// Fetch the type representing a 64-bit byte.
502
503 /// Fetch the type representing a 128-bit byte.
505
506 /// Fetch the type representing an N-bit byte.
508
509 /// Fetch the type representing a single bit
513
514 /// Fetch the type representing an 8-bit integer.
518
519 /// Fetch the type representing a 16-bit integer.
523
524 /// Fetch the type representing a 32-bit integer.
528
529 /// Fetch the type representing a 64-bit integer.
533
534 /// Fetch the type representing a 128-bit integer.
536
537 /// Fetch the type representing an N-bit integer.
539 return Type::getIntNTy(Context, N);
540 }
541
542 /// Fetch the type representing a 16-bit floating point value.
544 return Type::getHalfTy(Context);
545 }
546
547 /// Fetch the type representing a 16-bit brain floating point value.
550 }
551
552 /// Fetch the type representing a 32-bit floating point value.
555 }
556
557 /// Fetch the type representing a 64-bit floating point value.
560 }
561
562 /// Fetch the type representing void.
564 return Type::getVoidTy(Context);
565 }
566
567 /// Fetch the type representing a pointer.
568 PointerType *getPtrTy(unsigned AddrSpace = 0) {
569 return PointerType::get(Context, AddrSpace);
570 }
571
572 /// Fetch the type of a byte with size at least as big as that of a
573 /// pointer in the given address space.
574 ByteType *getBytePtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
575 return DL.getBytePtrType(Context, AddrSpace);
576 }
577
578 /// Fetch the type of an integer with size at least as big as that of a
579 /// pointer in the given address space.
580 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
581 return DL.getIntPtrType(Context, AddrSpace);
582 }
583
584 /// Fetch the type of an integer that should be used to index GEP operations
585 /// within AddressSpace.
586 IntegerType *getIndexTy(const DataLayout &DL, unsigned AddrSpace) {
587 return DL.getIndexType(Context, AddrSpace);
588 }
589
590 //===--------------------------------------------------------------------===//
591 // Intrinsic creation methods
592 //===--------------------------------------------------------------------===//
593
594 /// Create and insert a memset to the specified pointer and the
595 /// specified value.
596 ///
597 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
598 /// specified, it will be added to the instruction.
600 MaybeAlign Align, bool isVolatile = false,
601 const AAMDNodes &AAInfo = AAMDNodes()) {
602 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
603 }
604
606 MaybeAlign Align, bool isVolatile = false,
607 const AAMDNodes &AAInfo = AAMDNodes());
608
610 Value *Val, Value *Size,
611 bool IsVolatile = false,
612 const AAMDNodes &AAInfo = AAMDNodes());
613
614 /// Create and insert an element unordered-atomic memset of the region of
615 /// memory starting at the given pointer to the given value.
616 ///
617 /// If the pointer isn't an i8*, it will be converted. If alias metadata is
618 /// specified, it will be added to the instruction.
619 CallInst *
621 Align Alignment, uint32_t ElementSize,
622 const AAMDNodes &AAInfo = AAMDNodes()) {
624 Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
625 }
626
628 Value *ArraySize,
630 Function *MallocF = nullptr,
631 const Twine &Name = "");
632
633 /// CreateMalloc - Generate the IR for a call to malloc:
634 /// 1. Compute the malloc call's argument as AllocSize, possibly multiplied
635 /// by the array size if the array size is not constant 1.
636 /// 2. Call malloc with that argument.
638 Value *ArraySize, Function *MallocF = nullptr,
639 const Twine &Name = "");
640 /// Generate the IR for a call to the builtin free function.
642 ArrayRef<OperandBundleDef> Bundles = {});
643
644 LLVM_ABI CallInst *
645 CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
646 Align Alignment, uint32_t ElementSize,
647 const AAMDNodes &AAInfo = AAMDNodes());
648
649 /// Create and insert a memcpy between the specified pointers.
650 ///
651 /// If the pointers aren't i8*, they will be converted. If alias metadata is
652 /// specified, it will be added to the instruction.
653 /// and noalias tags.
655 MaybeAlign SrcAlign, uint64_t Size,
656 bool isVolatile = false,
657 const AAMDNodes &AAInfo = AAMDNodes()) {
658 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
659 isVolatile, AAInfo);
660 }
661
664 Value *Src, MaybeAlign SrcAlign, Value *Size,
665 bool isVolatile = false,
666 const AAMDNodes &AAInfo = AAMDNodes());
667
669 MaybeAlign SrcAlign, Value *Size,
670 bool isVolatile = false,
671 const AAMDNodes &AAInfo = AAMDNodes()) {
672 return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
673 SrcAlign, Size, isVolatile, AAInfo);
674 }
675
677 MaybeAlign SrcAlign, Value *Size,
678 bool isVolatile = false,
679 const AAMDNodes &AAInfo = AAMDNodes()) {
680 return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
681 SrcAlign, Size, isVolatile, AAInfo);
682 }
683
684 /// Create and insert an element unordered-atomic memcpy between the
685 /// specified pointers.
686 ///
687 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
688 /// respectively.
689 ///
690 /// If the pointers aren't i8*, they will be converted. If alias metadata is
691 /// specified, it will be added to the instruction.
693 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
694 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
695
697 MaybeAlign SrcAlign, uint64_t Size,
698 bool isVolatile = false,
699 const AAMDNodes &AAInfo = AAMDNodes()) {
700 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
701 isVolatile, AAInfo);
702 }
703
705 MaybeAlign SrcAlign, Value *Size,
706 bool isVolatile = false,
707 const AAMDNodes &AAInfo = AAMDNodes()) {
708 return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
709 SrcAlign, Size, isVolatile, AAInfo);
710 }
711
712 /// \brief Create and insert an element unordered-atomic memmove between the
713 /// specified pointers.
714 ///
715 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
716 /// respectively.
717 ///
718 /// If the pointers aren't i8*, they will be converted. If alias metadata is
719 /// specified, it will be added to the instruction.
721 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
722 uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
723
724private:
725 Value *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
726
727public:
728 /// Create a sequential vector fadd reduction intrinsic of the source vector.
729 /// The first parameter is a scalar accumulator value. An unordered reduction
730 /// can be created by adding the reassoc fast-math flag to the resulting
731 /// sequential reduction.
733
734 /// Create a sequential vector fmul reduction intrinsic of the source vector.
735 /// The first parameter is a scalar accumulator value. An unordered reduction
736 /// can be created by adding the reassoc fast-math flag to the resulting
737 /// sequential reduction.
739
740 /// Create a vector int add reduction intrinsic of the source vector.
742
743 /// Create a vector int mul reduction intrinsic of the source vector.
745
746 /// Create a vector int AND reduction intrinsic of the source vector.
748
749 /// Create a vector int OR reduction intrinsic of the source vector.
751
752 /// Create a vector int XOR reduction intrinsic of the source vector.
754
755 /// Create a vector integer max reduction intrinsic of the source
756 /// vector.
757 LLVM_ABI Value *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
758
759 /// Create a vector integer min reduction intrinsic of the source
760 /// vector.
761 LLVM_ABI Value *CreateIntMinReduce(Value *Src, bool IsSigned = false);
762
763 /// Create a vector float max reduction intrinsic of the source
764 /// vector.
766
767 /// Create a vector float min reduction intrinsic of the source
768 /// vector.
770
771 /// Create a vector float maximum reduction intrinsic of the source
772 /// vector. This variant follows the NaN and signed zero semantic of
773 /// llvm.maximum intrinsic.
775
776 /// Create a vector float minimum reduction intrinsic of the source
777 /// vector. This variant follows the NaN and signed zero semantic of
778 /// llvm.minimum intrinsic.
780
781 /// Create a vector float maximum reduction intrinsic of the source
782 /// vector. This variant follows the NaN and signed zero semantic of
783 /// llvm.maximumnum intrinsic.
785
786 /// Create a vector float minimum reduction intrinsic of the source
787 /// vector. This variant follows the NaN and signed zero semantic of
788 /// llvm.minimumnum intrinsic.
790
791 /// Create a lifetime.start intrinsic.
793
794 /// Create a lifetime.end intrinsic.
796
797 /// Create a call to invariant.start intrinsic.
798 ///
799 /// If the pointer isn't i8* it will be converted.
801 ConstantInt *Size = nullptr);
802
803 /// Create a call to llvm.threadlocal.address intrinsic.
805
806 /// Create a call to Masked Load intrinsic
807 LLVM_ABI CallInst *CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment,
808 Value *Mask, Value *PassThru = nullptr,
809 const Twine &Name = "");
810
811 /// Create a call to Masked Store intrinsic
812 LLVM_ABI CallInst *CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment,
813 Value *Mask);
814
815 /// Create a call to Masked Gather intrinsic
816 LLVM_ABI CallInst *CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment,
817 Value *Mask = nullptr,
818 Value *PassThru = nullptr,
819 const Twine &Name = "");
820
821 /// Create a call to Masked Scatter intrinsic
823 Align Alignment,
824 Value *Mask = nullptr);
825
826 /// Create a call to Masked Expand Load intrinsic
829 Value *Mask = nullptr,
830 Value *PassThru = nullptr,
831 const Twine &Name = "");
832
833 /// Create a call to Masked Compress Store intrinsic
836 Value *Mask = nullptr);
837
838 /// Return an all true boolean vector (mask) with \p NumElts lanes.
843
844 /// Create an assume intrinsic call that allows the optimizer to
845 /// assume that the provided condition will be true.
847
848 /// Create an assume intrinsic call that allows the optimizer to
849 /// assume that the provided operand bundles hold.
851
852 /// Create a llvm.experimental.noalias.scope.decl intrinsic call.
858
859 /// Create a call to the experimental.gc.statepoint intrinsic to
860 /// start a new statepoint sequence.
862 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
863 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
864 ArrayRef<Value *> GCArgs, const Twine &Name = "");
865
866 /// Create a call to the experimental.gc.statepoint intrinsic to
867 /// start a new statepoint sequence.
869 CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
870 FunctionCallee ActualCallee, uint32_t Flags,
871 ArrayRef<Value *> CallArgs,
872 std::optional<ArrayRef<Use>> TransitionArgs,
873 std::optional<ArrayRef<Use>> DeoptArgs,
874 ArrayRef<Value *> GCArgs, const Twine &Name = "");
875
876 /// Conveninence function for the common case when CallArgs are filled
877 /// in using ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
878 /// .get()'ed to get the Value pointer.
880 CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
881 FunctionCallee ActualCallee, ArrayRef<Use> CallArgs,
882 std::optional<ArrayRef<Value *>> DeoptArgs,
883 ArrayRef<Value *> GCArgs, const Twine &Name = "");
884
885 /// Create an invoke to the experimental.gc.statepoint intrinsic to
886 /// start a new statepoint sequence.
889 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
890 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
891 std::optional<ArrayRef<Value *>> DeoptArgs,
892 ArrayRef<Value *> GCArgs, const Twine &Name = "");
893
894 /// Create an invoke to the experimental.gc.statepoint intrinsic to
895 /// start a new statepoint sequence.
897 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
898 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
899 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
900 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
901 const Twine &Name = "");
902
903 // Convenience function for the common case when CallArgs are filled in using
904 // ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
905 // get the Value *.
908 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
909 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
910 std::optional<ArrayRef<Value *>> DeoptArgs,
911 ArrayRef<Value *> GCArgs, const Twine &Name = "");
912
913 /// Create a call to the experimental.gc.result intrinsic to extract
914 /// the result from a call wrapped in a statepoint.
915 LLVM_ABI CallInst *CreateGCResult(Instruction *Statepoint, Type *ResultType,
916 const Twine &Name = "");
917
918 /// Create a call to the experimental.gc.relocate intrinsics to
919 /// project the relocated value of one pointer from the statepoint.
920 LLVM_ABI CallInst *CreateGCRelocate(Instruction *Statepoint, int BaseOffset,
921 int DerivedOffset, Type *ResultType,
922 const Twine &Name = "");
923
924 /// Create a call to the experimental.gc.pointer.base intrinsic to get the
925 /// base pointer for the specified derived pointer.
927 const Twine &Name = "");
928
929 /// Create a call to the experimental.gc.get.pointer.offset intrinsic to get
930 /// the offset of the specified derived pointer from its base.
932 const Twine &Name = "");
933
934 /// Create a call to llvm.vscale.<Ty>().
935 Value *CreateVScale(Type *Ty, const Twine &Name = "") {
936 return CreateIntrinsic(Intrinsic::vscale, {Ty}, {}, {}, Name);
937 }
938
939 /// Create an expression which evaluates to the number of elements in \p EC
940 /// at runtime. This can result in poison if type \p Ty is not big enough to
941 /// hold the value.
943
944 /// Create an expression which evaluates to the number of units in \p Size
945 /// at runtime. This works for both units of bits and bytes. This can result
946 /// in poison if type \p Ty is not big enough to hold the value.
948
949 /// Get allocation size of an alloca as a runtime Value* (handles both static
950 /// and dynamic allocas and vscale factor).
952
953 /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
954 LLVM_ABI Value *CreateStepVector(Type *DstType, const Twine &Name = "");
955
956 /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
957 /// type.
959 FMFSource FMFSource = {},
960 const Twine &Name = "");
961
962 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
963 /// first type.
965 Value *RHS, FMFSource FMFSource = {},
966 const Twine &Name = "");
967
968 /// Create a call to intrinsic \p ID with \p Args, mangled using
969 /// \p OverloadTypes. If \p FMFSource is provided, copy fast-math-flags from
970 /// that instruction to the intrinsic. It is guaranteed not to fold.
972 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
973 FMFSource FMFSource = {}, const Twine &Name = "",
974 ArrayRef<OperandBundleDef> OpBundles = {});
975
976 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
977 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
978 /// the intrinsic. It is guaranteed not to fold.
980 Intrinsic::ID ID,
982 FMFSource FMFSource = {},
983 const Twine &Name = "");
984
985 /// Create a call to non-overloaded intrinsic \p ID with \p Args. If
986 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
987 /// the intrinsic. It is guranteed not to fold.
990 FMFSource FMFSource = {},
991 const Twine &Name = "") {
992 return CreateIntrinsicWithoutFolding(ID, /*Types=*/{}, Args, FMFSource,
993 Name);
994 }
995
996 /// Variant to create a possibly constant-folded intrinsic. An optional \p
997 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
998 /// things like attributes.
1000 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
1001 FMFSource FMFSource = {}, const Twine &Name = "",
1002 ArrayRef<OperandBundleDef> OpBundles = {},
1003 function_ref<void(CallInst *)> SetFn = [](CallInst *) {});
1004
1005 /// Variant to create a possibly constant-folded intrinsic. An optional \p
1006 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
1007 /// things like attributes.
1009 Type *RetTy, Intrinsic::ID ID, ArrayRef<Value *> Args,
1010 FMFSource FMFSource = {}, const Twine &Name = "",
1011 function_ref<void(CallInst *)> SetFn = [](CallInst *) {});
1012
1013 /// Variant to create a possibly constant-folded intrinsic. An optional \p
1014 /// SetFn is called if the intrinsic doesn't fold, and can be used to set
1015 /// things like attributes.
1018 const Twine &Name = "",
1019 function_ref<void(CallInst *)> SetFn = [](CallInst *) {}) {
1020 return CreateIntrinsic(ID, /*Types=*/{}, Args, FMFSource, Name, {}, SetFn);
1021 }
1022
1023 /// Create call to the fabs intrinsic.
1025 const Twine &Name = "") {
1026 return CreateUnaryIntrinsic(Intrinsic::fabs, V, FMFSource, Name);
1027 }
1028
1029 /// Create call to the minnum intrinsic.
1031 const Twine &Name = "") {
1032 if (IsFPConstrained) {
1034 Intrinsic::experimental_constrained_minnum, LHS, RHS, FMFSource,
1035 Name);
1036 }
1037
1038 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, FMFSource, Name);
1039 }
1040
1041 /// Create call to the maxnum intrinsic.
1043 const Twine &Name = "") {
1044 if (IsFPConstrained) {
1046 Intrinsic::experimental_constrained_maxnum, LHS, RHS, FMFSource,
1047 Name);
1048 }
1049
1050 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, FMFSource, Name);
1051 }
1052
1053 /// Create call to the minimum intrinsic.
1054 Value *CreateMinimum(Value *LHS, Value *RHS, const Twine &Name = "") {
1055 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1056 }
1057
1058 /// Create call to the maximum intrinsic.
1059 Value *CreateMaximum(Value *LHS, Value *RHS, const Twine &Name = "") {
1060 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1061 }
1062
1063 /// Create call to the minimumnum intrinsic.
1064 Value *CreateMinimumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1065 return CreateBinaryIntrinsic(Intrinsic::minimumnum, LHS, RHS, nullptr,
1066 Name);
1067 }
1068
1069 /// Create call to the maximum intrinsic.
1070 Value *CreateMaximumNum(Value *LHS, Value *RHS, const Twine &Name = "") {
1071 return CreateBinaryIntrinsic(Intrinsic::maximumnum, LHS, RHS, nullptr,
1072 Name);
1073 }
1074
1075 /// Create call to the copysign intrinsic.
1077 const Twine &Name = "") {
1078 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1079 Name);
1080 }
1081
1082 /// Create call to the ldexp intrinsic.
1084 const Twine &Name = "") {
1085 assert(!IsFPConstrained && "TODO: Support strictfp");
1086 return CreateIntrinsic(Intrinsic::ldexp, {Src->getType(), Exp->getType()},
1087 {Src, Exp}, FMFSource, Name);
1088 }
1089
1090 /// Create call to the fma intrinsic.
1091 Value *CreateFMA(Value *Factor1, Value *Factor2, Value *Summand,
1092 FMFSource FMFSource = {}, const Twine &Name = "") {
1093 if (IsFPConstrained) {
1095 Intrinsic::experimental_constrained_fma, {Factor1->getType()},
1096 {Factor1, Factor2, Summand}, FMFSource, Name);
1097 }
1098
1099 return CreateIntrinsic(Intrinsic::fma, {Factor1->getType()},
1100 {Factor1, Factor2, Summand}, FMFSource, Name);
1101 }
1102
1103 /// Create a call to the arithmetic_fence intrinsic.
1105 const Twine &Name = "") {
1106 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1107 Name);
1108 }
1109
1110 /// Create a call to the vector.extract intrinsic.
1111 Value *CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx,
1112 const Twine &Name = "") {
1113 return CreateIntrinsic(Intrinsic::vector_extract,
1114 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1115 Name);
1116 }
1117
1118 /// Create a call to the vector.extract intrinsic.
1120 const Twine &Name = "") {
1121 return CreateExtractVector(DstType, SrcVec, getInt64(Idx), Name);
1122 }
1123
1124 /// Create a call to the vector.insert intrinsic.
1125 Value *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1126 Value *Idx, const Twine &Name = "") {
1127 return CreateIntrinsic(Intrinsic::vector_insert,
1128 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1129 nullptr, Name);
1130 }
1131
1132 /// Create a call to the vector.extract intrinsic.
1133 Value *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1134 uint64_t Idx, const Twine &Name = "") {
1135 return CreateInsertVector(DstType, SrcVec, SubVec, getInt64(Idx), Name);
1136 }
1137
1138 /// Create a call to llvm.stacksave
1139 CallInst *CreateStackSave(const Twine &Name = "") {
1140 const DataLayout &DL = getDataLayout();
1141 return CreateIntrinsicWithoutFolding(Intrinsic::stacksave,
1142 {DL.getAllocaPtrType(Context)}, {},
1143 nullptr, Name);
1144 }
1145
1146 /// Create a call to llvm.stackrestore
1147 CallInst *CreateStackRestore(Value *Ptr, const Twine &Name = "") {
1149 Intrinsic::stackrestore, {Ptr->getType()}, {Ptr}, nullptr, Name);
1150 }
1151
1152 /// Create a call to llvm.experimental_cttz_elts
1154 bool ZeroIsPoison = true,
1155 const Twine &Name = "") {
1156 return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
1157 {ResTy, Mask->getType()},
1158 {Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
1159 }
1160
1161private:
1162 /// Create a call to a masked intrinsic with given Id.
1163 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1164 ArrayRef<Type *> OverloadedTypes,
1165 const Twine &Name = "");
1166
1167 //===--------------------------------------------------------------------===//
1168 // Instruction creation methods: Terminators
1169 //===--------------------------------------------------------------------===//
1170
1171private:
1172 /// Helper to add branch weight and unpredictable metadata onto an
1173 /// instruction.
1174 /// \returns The annotated instruction.
1175 template <typename InstTy>
1176 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1177 if (Weights)
1178 I->setMetadata(LLVMContext::MD_prof, Weights);
1179 if (Unpredictable)
1180 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1181 return I;
1182 }
1183
1184public:
1185 /// Create a 'ret void' instruction.
1189
1190 /// Create a 'ret <val>' instruction.
1194
1195 /// Create a sequence of N insertvalue instructions, with one Value from the
1196 /// RetVals array each, that build a aggregate return value one value at a
1197 /// time, and a ret instruction to return the resulting aggregate value.
1198 ///
1199 /// This is a convenience function for code that uses aggregate return values
1200 /// as a vehicle for having multiple return values.
1203 for (size_t i = 0, N = RetVals.size(); i != N; ++i)
1204 V = CreateInsertValue(V, RetVals[i], i, "mrv");
1206 }
1207
1208 /// Create an unconditional 'br label X' instruction.
1210 return Insert(UncondBrInst::Create(Dest));
1211 }
1212
1213 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1214 /// instruction.
1216 MDNode *BranchWeights = nullptr,
1217 MDNode *Unpredictable = nullptr) {
1218 return Insert(addBranchMetadata(CondBrInst::Create(Cond, True, False),
1219 BranchWeights, Unpredictable));
1220 }
1221
1222 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1223 /// instruction. Copy branch meta data if available.
1225 Instruction *MDSrc) {
1227 if (MDSrc) {
1228 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1229 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1230 Br->copyMetadata(*MDSrc, WL);
1231 }
1232 return Insert(Br);
1233 }
1234
1235 /// Create a switch instruction with the specified value, default dest,
1236 /// and with a hint for the number of cases that will be added (for efficient
1237 /// allocation).
1238 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1239 MDNode *BranchWeights = nullptr,
1240 MDNode *Unpredictable = nullptr) {
1241 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1242 BranchWeights, Unpredictable));
1243 }
1244
1245 /// Create an indirect branch instruction with the specified address
1246 /// operand, with an optional hint for the number of destinations that will be
1247 /// added (for efficient allocation).
1248 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1249 return Insert(IndirectBrInst::Create(Addr, NumDests));
1250 }
1251
1252 /// Create an invoke instruction.
1254 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1255 ArrayRef<Value *> Args,
1257 const Twine &Name = "") {
1258 InvokeInst *II =
1259 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1260 if (IsFPConstrained)
1262 return Insert(II, Name);
1263 }
1265 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1266 ArrayRef<Value *> Args = {},
1267 const Twine &Name = "") {
1268 InvokeInst *II =
1269 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1270 if (IsFPConstrained)
1272 return Insert(II, Name);
1273 }
1274
1276 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1278 const Twine &Name = "") {
1279 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1280 NormalDest, UnwindDest, Args, OpBundles, Name);
1281 }
1282
1284 BasicBlock *UnwindDest, ArrayRef<Value *> Args = {},
1285 const Twine &Name = "") {
1286 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1287 NormalDest, UnwindDest, Args, Name);
1288 }
1289
1290 /// \brief Create a callbr instruction.
1292 BasicBlock *DefaultDest,
1293 ArrayRef<BasicBlock *> IndirectDests,
1294 ArrayRef<Value *> Args = {},
1295 const Twine &Name = "") {
1296 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1297 Args), Name);
1298 }
1300 BasicBlock *DefaultDest,
1301 ArrayRef<BasicBlock *> IndirectDests,
1302 ArrayRef<Value *> Args,
1304 const Twine &Name = "") {
1305 return Insert(
1306 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1307 OpBundles), Name);
1308 }
1309
1311 ArrayRef<BasicBlock *> IndirectDests,
1312 ArrayRef<Value *> Args = {},
1313 const Twine &Name = "") {
1314 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1315 DefaultDest, IndirectDests, Args, Name);
1316 }
1318 ArrayRef<BasicBlock *> IndirectDests,
1319 ArrayRef<Value *> Args,
1321 const Twine &Name = "") {
1322 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1323 DefaultDest, IndirectDests, Args, Name);
1324 }
1325
1327 return Insert(ResumeInst::Create(Exn));
1328 }
1329
1331 BasicBlock *UnwindBB = nullptr) {
1332 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1333 }
1334
1336 unsigned NumHandlers,
1337 const Twine &Name = "") {
1338 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1339 Name);
1340 }
1341
1343 const Twine &Name = "") {
1344 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1345 }
1346
1348 ArrayRef<Value *> Args = {},
1349 const Twine &Name = "") {
1350 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1351 }
1352
1354 return Insert(CatchReturnInst::Create(CatchPad, BB));
1355 }
1356
1360
1361 //===--------------------------------------------------------------------===//
1362 // Instruction creation methods: Binary Operators
1363 //===--------------------------------------------------------------------===//
1364private:
1365 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1366 Value *LHS, Value *RHS,
1367 const Twine &Name,
1368 bool HasNUW, bool HasNSW) {
1370 if (HasNUW) BO->setHasNoUnsignedWrap();
1371 if (HasNSW) BO->setHasNoSignedWrap();
1372 return BO;
1373 }
1374
1375 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1376 FastMathFlags FMF) const {
1377 if (!FPMD)
1378 FPMD = DefaultFPMathTag;
1379 if (FPMD)
1380 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1381 I->setFastMathFlags(FMF);
1382 return I;
1383 }
1384
1385 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1387
1388 if (Rounding)
1389 UseRounding = *Rounding;
1390
1391 std::optional<StringRef> RoundingStr =
1392 convertRoundingModeToStr(UseRounding);
1393 assert(RoundingStr && "Garbage strict rounding mode!");
1394 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1395
1396 return MetadataAsValue::get(Context, RoundingMDS);
1397 }
1398
1399 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1400 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1401 Except.value_or(DefaultConstrainedExcept));
1402 assert(ExceptStr && "Garbage strict exception behavior!");
1403 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1404
1405 return MetadataAsValue::get(Context, ExceptMDS);
1406 }
1407
1408 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1409 assert(CmpInst::isFPPredicate(Predicate) &&
1410 Predicate != CmpInst::FCMP_FALSE &&
1411 Predicate != CmpInst::FCMP_TRUE &&
1412 "Invalid constrained FP comparison predicate!");
1413
1414 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1415 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1416
1417 return MetadataAsValue::get(Context, PredicateMDS);
1418 }
1419
1420public:
1421 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
1422 bool HasNUW = false, bool HasNSW = false) {
1423 if (Value *V =
1424 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1425 return V;
1426 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1427 HasNSW);
1428 }
1429
1430 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1431 return CreateAdd(LHS, RHS, Name, false, true);
1432 }
1433
1434 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
1435 return CreateAdd(LHS, RHS, Name, true, false);
1436 }
1437
1438 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
1439 bool HasNUW = false, bool HasNSW = false) {
1440 if (Value *V =
1441 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1442 return V;
1443 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1444 HasNSW);
1445 }
1446
1447 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1448 return CreateSub(LHS, RHS, Name, false, true);
1449 }
1450
1451 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
1452 return CreateSub(LHS, RHS, Name, true, false);
1453 }
1454
1455 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
1456 bool HasNUW = false, bool HasNSW = false) {
1457 if (Value *V =
1458 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1459 return V;
1460 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1461 HasNSW);
1462 }
1463
1464 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1465 return CreateMul(LHS, RHS, Name, false, true);
1466 }
1467
1468 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
1469 return CreateMul(LHS, RHS, Name, true, false);
1470 }
1471
1472 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1473 bool isExact = false) {
1474 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1475 return V;
1476 if (!isExact)
1477 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1478 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1479 }
1480
1481 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1482 return CreateUDiv(LHS, RHS, Name, true);
1483 }
1484
1485 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1486 bool isExact = false) {
1487 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1488 return V;
1489 if (!isExact)
1490 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1491 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1492 }
1493
1494 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1495 return CreateSDiv(LHS, RHS, Name, true);
1496 }
1497
1498 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1499 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1500 return V;
1501 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1502 }
1503
1504 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1505 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1506 return V;
1507 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1508 }
1509
1510 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1511 bool HasNUW = false, bool HasNSW = false) {
1512 if (Value *V =
1513 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1514 return V;
1515 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1516 HasNUW, HasNSW);
1517 }
1518
1519 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1520 bool HasNUW = false, bool HasNSW = false) {
1521 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1522 HasNUW, HasNSW);
1523 }
1524
1525 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1526 bool HasNUW = false, bool HasNSW = false) {
1527 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1528 HasNUW, HasNSW);
1529 }
1530
1531 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1532 bool isExact = false) {
1533 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1534 return V;
1535 if (!isExact)
1536 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1537 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1538 }
1539
1540 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1541 bool isExact = false) {
1542 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1543 }
1544
1546 bool isExact = false) {
1547 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1548 }
1549
1550 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1551 bool isExact = false) {
1552 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1553 return V;
1554 if (!isExact)
1555 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1556 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1557 }
1558
1559 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1560 bool isExact = false) {
1561 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1562 }
1563
1565 bool isExact = false) {
1566 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1567 }
1568
1569 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1570 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1571 return V;
1572 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1573 }
1574
1575 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1576 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1577 }
1578
1579 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1580 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1581 }
1582
1584 assert(!Ops.empty());
1585 Value *Accum = Ops[0];
1586 for (unsigned i = 1; i < Ops.size(); i++)
1587 Accum = CreateAnd(Accum, Ops[i]);
1588 return Accum;
1589 }
1590
1591 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "",
1592 bool IsDisjoint = false) {
1593 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1594 return V;
1595 return Insert(
1596 IsDisjoint ? BinaryOperator::CreateDisjoint(Instruction::Or, LHS, RHS)
1597 : BinaryOperator::CreateOr(LHS, RHS),
1598 Name);
1599 }
1600
1601 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1602 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1603 }
1604
1605 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1606 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1607 }
1608
1610 assert(!Ops.empty());
1611 Value *Accum = Ops[0];
1612 for (unsigned i = 1; i < Ops.size(); i++)
1613 Accum = CreateOr(Accum, Ops[i]);
1614 return Accum;
1615 }
1616
1617 Value *CreateDisjointOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1618 return CreateOr(LHS, RHS, Name, true);
1619 }
1620
1621 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1622 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1623 return V;
1624 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1625 }
1626
1627 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1628 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1629 }
1630
1631 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1632 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1633 }
1634
1635 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1636 MDNode *FPMD = nullptr) {
1637 return CreateFAddFMF(L, R, {}, Name, FPMD);
1638 }
1639
1641 const Twine &Name = "", MDNode *FPMD = nullptr) {
1642 if (IsFPConstrained)
1643 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1644 L, R, FMFSource, Name, FPMD);
1645
1646 if (Value *V =
1647 Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMFSource.get(FMF)))
1648 return V;
1649 Instruction *I =
1650 setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMFSource.get(FMF));
1651 return Insert(I, Name);
1652 }
1653
1654 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1655 MDNode *FPMD = nullptr) {
1656 return CreateFSubFMF(L, R, {}, Name, FPMD);
1657 }
1658
1660 const Twine &Name = "", MDNode *FPMD = nullptr) {
1661 if (IsFPConstrained)
1662 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1663 L, R, FMFSource, Name, FPMD);
1664
1665 if (Value *V =
1666 Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMFSource.get(FMF)))
1667 return V;
1668 Instruction *I =
1669 setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMFSource.get(FMF));
1670 return Insert(I, Name);
1671 }
1672
1673 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1674 MDNode *FPMD = nullptr) {
1675 return CreateFMulFMF(L, R, {}, Name, FPMD);
1676 }
1677
1679 const Twine &Name = "", MDNode *FPMD = nullptr) {
1680 if (IsFPConstrained)
1681 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1682 L, R, FMFSource, Name, FPMD);
1683
1684 if (Value *V =
1685 Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMFSource.get(FMF)))
1686 return V;
1687 Instruction *I =
1688 setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMFSource.get(FMF));
1689 return Insert(I, Name);
1690 }
1691
1692 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1693 MDNode *FPMD = nullptr) {
1694 return CreateFDivFMF(L, R, {}, Name, FPMD);
1695 }
1696
1698 const Twine &Name = "", MDNode *FPMD = nullptr) {
1699 if (IsFPConstrained)
1700 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1701 L, R, FMFSource, Name, FPMD);
1702
1703 if (Value *V =
1704 Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMFSource.get(FMF)))
1705 return V;
1706 Instruction *I =
1707 setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMFSource.get(FMF));
1708 return Insert(I, Name);
1709 }
1710
1711 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1712 MDNode *FPMD = nullptr) {
1713 return CreateFRemFMF(L, R, {}, Name, FPMD);
1714 }
1715
1717 const Twine &Name = "", MDNode *FPMD = nullptr) {
1718 if (IsFPConstrained)
1719 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1720 L, R, FMFSource, Name, FPMD);
1721
1722 if (Value *V =
1723 Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMFSource.get(FMF)))
1724 return V;
1725 Instruction *I =
1726 setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMFSource.get(FMF));
1727 return Insert(I, Name);
1728 }
1729
1731 Value *LHS, Value *RHS, const Twine &Name = "",
1732 MDNode *FPMathTag = nullptr) {
1733 return CreateBinOpFMF(Opc, LHS, RHS, {}, Name, FPMathTag);
1734 }
1735
1737 FMFSource FMFSource, const Twine &Name = "",
1738 MDNode *FPMathTag = nullptr) {
1739 if (Value *V = Folder.FoldBinOpFMF(Opc, LHS, RHS, FMFSource.get(FMF)))
1740 return V;
1742 if (isa<FPMathOperator>(BinOp))
1743 setFPAttrs(BinOp, FPMathTag, FMFSource.get(FMF));
1744 return Insert(BinOp, Name);
1745 }
1746
1748 bool IsNUW, bool IsNSW, const Twine &Name = "") {
1749 if (Value *V = Folder.FoldNoWrapBinOp(Opc, LHS, RHS, IsNUW, IsNSW))
1750 return V;
1752 if (IsNUW)
1753 BinOp->setHasNoUnsignedWrap(IsNUW);
1754 if (IsNSW)
1755 BinOp->setHasNoSignedWrap(IsNSW);
1756 return Insert(BinOp, Name);
1757 }
1758
1760 bool IsExact, const Twine &Name = "") {
1761 if (Value *V = Folder.FoldExactBinOp(Opc, LHS, RHS, IsExact))
1762 return V;
1764 if (IsExact)
1765 BinOp->setIsExact(IsExact);
1766 return Insert(BinOp, Name);
1767 }
1768
1769 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "",
1770 Instruction *MDFrom = nullptr) {
1771 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1772 return CreateSelect(Cond1, Cond2,
1773 ConstantInt::getNullValue(Cond2->getType()), Name,
1774 MDFrom);
1775 }
1776
1777 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
1778 Instruction *MDFrom = nullptr) {
1779 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1780 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1781 Cond2, Name, MDFrom);
1782 }
1783
1785 const Twine &Name = "",
1786 Instruction *MDFrom = nullptr) {
1787 switch (Opc) {
1788 case Instruction::And:
1789 return CreateLogicalAnd(Cond1, Cond2, Name, MDFrom);
1790 case Instruction::Or:
1791 return CreateLogicalOr(Cond1, Cond2, Name, MDFrom);
1792 default:
1793 break;
1794 }
1795 llvm_unreachable("Not a logical operation.");
1796 }
1797
1798 // NOTE: this is sequential, non-commutative, ordered reduction!
1800 assert(!Ops.empty());
1801 Value *Accum = Ops[0];
1802 for (unsigned i = 1; i < Ops.size(); i++)
1803 Accum = CreateLogicalOr(Accum, Ops[i]);
1804 return Accum;
1805 }
1806
1807 /// This function is like @ref CreateIntrinsic for constrained fp
1808 /// intrinsics. It sets the rounding mode and exception behavior of
1809 /// the created intrinsic call according to \p Rounding and \p
1810 /// Except and it sets \p FPMathTag as the 'fpmath' metadata, using
1811 /// defaults if a value equals nullopt/null.
1814 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag = nullptr,
1815 std::optional<RoundingMode> Rounding = std::nullopt,
1816 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1817
1819 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1820 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1821 std::optional<RoundingMode> Rounding = std::nullopt,
1822 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1823
1825 Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource = {},
1826 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1827 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1828
1829 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1830 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1831 /*HasNUW=*/0, HasNSW);
1832 }
1833
1834 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1835 return CreateNeg(V, Name, /*HasNSW=*/true);
1836 }
1837
1838 Value *CreateFNeg(Value *V, const Twine &Name = "",
1839 MDNode *FPMathTag = nullptr) {
1840 return CreateFNegFMF(V, {}, Name, FPMathTag);
1841 }
1842
1844 MDNode *FPMathTag = nullptr) {
1845 if (Value *Res =
1846 Folder.FoldUnOpFMF(Instruction::FNeg, V, FMFSource.get(FMF)))
1847 return Res;
1848 return Insert(
1849 setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMFSource.get(FMF)),
1850 Name);
1851 }
1852
1853 Value *CreateNot(Value *V, const Twine &Name = "") {
1854 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1855 }
1856
1858 Value *V, const Twine &Name = "",
1859 MDNode *FPMathTag = nullptr) {
1860 return CreateUnOpFMF(Opc, V, {}, Name, FPMathTag);
1861 }
1862
1864 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1865 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMFSource.get(FMF)))
1866 return Res;
1868 if (isa<FPMathOperator>(UnOp))
1869 setFPAttrs(UnOp, FPMathTag, FMFSource.get(FMF));
1870 return Insert(UnOp, Name);
1871 }
1872
1873 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1874 /// Correct number of operands must be passed accordingly.
1876 const Twine &Name = "",
1877 MDNode *FPMathTag = nullptr);
1878
1879 //===--------------------------------------------------------------------===//
1880 // Instruction creation methods: Memory Instructions
1881 //===--------------------------------------------------------------------===//
1882
1883 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1884 Value *ArraySize = nullptr, const Twine &Name = "") {
1885 const DataLayout &DL = getDataLayout();
1886 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1887 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1888 }
1889
1890 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1891 const Twine &Name = "") {
1892 const DataLayout &DL = getDataLayout();
1893 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1894 unsigned AddrSpace = DL.getAllocaAddrSpace();
1895 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1896 }
1897
1899 const DataLayout &DL = getDataLayout();
1900 PointerType *PtrTy = DL.getAllocaPtrType(Context);
1901 auto *Output = CreateIntrinsicWithoutFolding(Intrinsic::structured_alloca,
1902 {PtrTy}, {}, {}, Name);
1903 Output->addRetAttr(
1904 Attribute::get(getContext(), Attribute::ElementType, BaseType));
1905 return Output;
1906 }
1907
1908 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1909 /// converting the string to 'bool' for the isVolatile parameter.
1910 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1911 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1912 }
1913 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1914 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1915 }
1916
1917 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1918 const Twine &Name = "") {
1919 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1920 }
1921
1923 const LoadStoreInstProperties &Props,
1924 const Twine &Name = "") {
1925 return Insert(new LoadInst(Ty, Ptr, Twine(), Props), Name);
1926 }
1927
1928 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1929 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1930 }
1931
1933 const LoadStoreInstProperties &Props) {
1934 return Insert(new StoreInst(Val, Ptr, Props));
1935 }
1936
1938 const char *Name) {
1939 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1940 }
1941
1943 const Twine &Name = "") {
1944 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1945 }
1946
1948 bool isVolatile, const Twine &Name = "") {
1949 if (!Align) {
1950 const DataLayout &DL = getDataLayout();
1951 Align = DL.getABITypeAlign(Ty);
1952 }
1953 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1954 }
1955
1957 bool isVolatile = false) {
1958 if (!Align) {
1959 const DataLayout &DL = getDataLayout();
1960 Align = DL.getABITypeAlign(Val->getType());
1961 }
1962 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1963 }
1966 const Twine &Name = "") {
1967 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1968 }
1969
1972 AtomicOrdering SuccessOrdering,
1973 AtomicOrdering FailureOrdering,
1975 if (!Align) {
1976 const DataLayout &DL = getDataLayout();
1977 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1978 }
1979
1980 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1981 FailureOrdering, SSID));
1982 }
1983
1985 Value *Val, MaybeAlign Align,
1986 AtomicOrdering Ordering,
1988 bool Elementwise = false) {
1989 if (!Align) {
1990 const DataLayout &DL = getDataLayout();
1991 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1992 }
1993
1994 return Insert(
1995 new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID, Elementwise));
1996 }
1997
1999 ArrayRef<Value *> Indices,
2000 const Twine &Name = "") {
2002 Args.push_back(PtrBase);
2003 llvm::append_range(Args, Indices);
2004
2005 return CreateIntrinsic(
2006 Intrinsic::structured_gep, {PtrBase->getType()}, Args, {}, Name, {},
2007 [&](CallInst *Output) {
2008 Output->addParamAttr(
2009 0,
2010 Attribute::get(getContext(), Attribute::ElementType, BaseType));
2011 });
2012 }
2013
2014 LLVM_ABI Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
2015 const Twine &Name = "",
2017
2019 const Twine &Name = "") {
2020 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
2021 }
2022
2023 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
2024 const Twine &Name = "") {
2025 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
2026 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
2027 }
2028
2029 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
2030 const Twine &Name = "") {
2031 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
2032 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
2033 }
2034
2035 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
2036 const Twine &Name = "",
2038 Value *Idxs[] = {
2039 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
2040 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
2041 };
2042 return CreateGEP(Ty, Ptr, Idxs, Name, NWFlags);
2043 }
2044
2045 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
2046 unsigned Idx1, const Twine &Name = "") {
2047 Value *Idxs[] = {
2048 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
2049 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
2050 };
2051 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2052 }
2053
2055 const Twine &Name = "") {
2056 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2057 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
2058 }
2059
2061 const Twine &Name = "") {
2062 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
2063 return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
2064 }
2065
2067 const Twine &Name = "") {
2068 Value *Idxs[] = {
2069 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2070 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2071 };
2072 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::none());
2073 }
2074
2076 uint64_t Idx1, const Twine &Name = "") {
2077 Value *Idxs[] = {
2078 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
2079 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
2080 };
2081 return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
2082 }
2083
2084 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
2085 const Twine &Name = "") {
2086 GEPNoWrapFlags NWFlags =
2088 return CreateConstGEP2_32(Ty, Ptr, 0, Idx, Name, NWFlags);
2089 }
2090
2091 Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
2093 assert(Offset->getType()->isIntOrIntVectorTy(
2094 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2095 "Offset must match index type");
2096 Type *Ty = getInt8Ty();
2097 if (auto *V = Folder.FoldGEP(getDataLayout(), Ty, Ptr, Offset, NW))
2098 return V;
2099 return Insert(GetElementPtrInst::Create(Ty, Ptr, Offset, NW), Name);
2100 }
2101
2103 const Twine &Name = "") {
2104 return CreatePtrAdd(Ptr, Offset, Name, GEPNoWrapFlags::inBounds());
2105 }
2106
2107 /// Create a ptradd with an unsigned constant offset. The offset must fit into
2108 /// the unsigned index type.
2109 Value *
2111 const Twine &Name = "",
2113 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2114 return CreatePtrAdd(Ptr, ConstantInt::get(IdxTy, Offset), Name, NW);
2115 }
2116
2117 /// Create a ptradd with a signed constant offset. The offset must fit into
2118 /// the signed index type.
2119 Value *
2121 const Twine &Name = "",
2123 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2124 return CreatePtrAdd(Ptr, ConstantInt::getSigned(IdxTy, Offset), Name, NW);
2125 }
2126
2127 /// Create a ptradd where the offset is sign-extended or truncated to the
2128 /// index type. Offset must match the vector-ness of the base pointer.
2129 Value *
2132 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2133 return CreatePtrAdd(Ptr, CreateSExtOrTrunc(Offset, IdxTy), Name, NW);
2134 }
2135
2136 /// Create a ptradd where the offset is zero-extended or truncated to the
2137 /// index type. Offset must match the vector-ness of the base pointer.
2138 Value *
2141 Type *IdxTy = getDataLayout().getIndexType(Ptr->getType());
2142 return CreatePtrAdd(Ptr, CreateZExtOrTrunc(Offset, IdxTy), Name, NW);
2143 }
2144
2146 const Twine &Name = "",
2148 assert(Offset->getType()->isIntOrIntVectorTy(
2149 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2150 "Offset must match index type");
2151 if (Scale == 1)
2152 return CreatePtrAdd(Ptr, Offset, Name, NW);
2153
2154 Type *Ty = ArrayType::get(getInt8Ty(), Scale);
2155 if (auto *V = Folder.FoldGEP(getDataLayout(), Ty, Ptr, Offset, NW))
2156 return V;
2157 return Insert(GetElementPtrInst::Create(Ty, Ptr, Offset, NW), Name);
2158 }
2159
2161 const Twine &Name = "",
2163 assert(Offset->getType()->isIntOrIntVectorTy(
2164 getDataLayout().getIndexTypeSizeInBits(Ptr->getType())) &&
2165 "Offset must match index type");
2166 if (Scale.isScalable()) {
2167 Value *VScale = CreateVScale(Offset->getType()->getScalarType());
2168 if (auto *VT = dyn_cast<VectorType>(Offset->getType()))
2169 VScale = CreateVectorSplat(VT->getElementCount(), VScale);
2170 Offset = CreateMul(VScale, Offset, "", NW.hasNoUnsignedWrap(),
2171 NW.hasNoUnsignedSignedWrap());
2172 }
2173 return CreateScaledPtrAdd(Ptr, Scale.getKnownMinValue(), Offset, Name, NW);
2174 }
2175
2176 //===--------------------------------------------------------------------===//
2177 // Instruction creation methods: Cast/Conversion Operators
2178 //===--------------------------------------------------------------------===//
2179
2180 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2181 bool IsNUW = false, bool IsNSW = false) {
2182 if (V->getType() == DestTy)
2183 return V;
2184 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2185 return Folded;
2186 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2187 if (IsNUW)
2188 I->setHasNoUnsignedWrap();
2189 if (IsNSW)
2190 I->setHasNoSignedWrap();
2191 return Insert(I, Name);
2192 }
2193
2194 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2195 bool IsNonNeg = false) {
2196 if (V->getType() == DestTy)
2197 return V;
2198 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2199 return Folded;
2200 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2201 if (IsNonNeg)
2202 I->setNonNeg();
2203 return I;
2204 }
2205
2206 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2207 return CreateCast(Instruction::SExt, V, DestTy, Name);
2208 }
2209
2210 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2211 /// the value untouched if the type of V is already DestTy.
2213 const Twine &Name = "") {
2214 assert(V->getType()->isIntOrIntVectorTy() &&
2215 DestTy->isIntOrIntVectorTy() &&
2216 "Can only zero extend/truncate integers!");
2217 Type *VTy = V->getType();
2218 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2219 return CreateZExt(V, DestTy, Name);
2220 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2221 return CreateTrunc(V, DestTy, Name);
2222 return V;
2223 }
2224
2225 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2226 /// the value untouched if the type of V is already DestTy.
2228 const Twine &Name = "") {
2229 assert(V->getType()->isIntOrIntVectorTy() &&
2230 DestTy->isIntOrIntVectorTy() &&
2231 "Can only sign extend/truncate integers!");
2232 Type *VTy = V->getType();
2233 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2234 return CreateSExt(V, DestTy, Name);
2235 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2236 return CreateTrunc(V, DestTy, Name);
2237 return V;
2238 }
2239
2240 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2241 if (IsFPConstrained)
2242 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2243 V, DestTy, nullptr, Name);
2244 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2245 }
2246
2247 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2248 if (IsFPConstrained)
2249 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2250 V, DestTy, nullptr, Name);
2251 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2252 }
2253
2254 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2255 bool IsNonNeg = false, MDNode *FPMathTag = nullptr) {
2256 if (IsFPConstrained)
2257 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2258 V, DestTy, nullptr, Name);
2259 Value *Val = CreateCast(Instruction::UIToFP, V, DestTy, Name, FPMathTag);
2260 if (auto *I = dyn_cast<Instruction>(Val))
2261 if (IsNonNeg)
2262 I->setNonNeg();
2263 return Val;
2264 }
2265
2266 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2267 MDNode *FPMathTag = nullptr) {
2268 if (IsFPConstrained)
2269 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2270 V, DestTy, nullptr, Name);
2271 return CreateCast(Instruction::SIToFP, V, DestTy, Name, FPMathTag);
2272 }
2273
2274 Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2275 MDNode *FPMathTag = nullptr) {
2276 return CreateFPTruncFMF(V, DestTy, {}, Name, FPMathTag);
2277 }
2278
2280 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2281 if (IsFPConstrained)
2283 Intrinsic::experimental_constrained_fptrunc, V, DestTy, FMFSource,
2284 Name, FPMathTag);
2285 return CreateCast(Instruction::FPTrunc, V, DestTy, Name, FPMathTag,
2286 FMFSource);
2287 }
2288
2289 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "",
2290 MDNode *FPMathTag = nullptr) {
2291 return CreateFPExtFMF(V, DestTy, {}, Name, FPMathTag);
2292 }
2293
2295 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2296 if (IsFPConstrained)
2297 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2298 V, DestTy, FMFSource, Name, FPMathTag);
2299 return CreateCast(Instruction::FPExt, V, DestTy, Name, FPMathTag,
2300 FMFSource);
2301 }
2302 Value *CreatePtrToAddr(Value *V, const Twine &Name = "") {
2303 return CreateCast(Instruction::PtrToAddr, V,
2304 getDataLayout().getAddressType(V->getType()), Name);
2305 }
2307 const Twine &Name = "") {
2308 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2309 }
2310
2312 const Twine &Name = "") {
2313 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2314 }
2315
2317 const Twine &Name = "") {
2318 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2319 }
2320
2321 Value *CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "",
2322 bool IsNonNull = false) {
2323 if (V->getType() == DestTy)
2324 return V;
2325 if (Value *Folded = Folder.FoldCast(Instruction::AddrSpaceCast, V, DestTy))
2326 return Folded;
2327 Instruction *I = Insert(new AddrSpaceCastInst(V, DestTy), Name);
2328 if (IsNonNull)
2329 cast<AddrSpaceCastInst>(I)->setNonNull();
2330 return I;
2331 }
2332
2333 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2334 Instruction::CastOps CastOp =
2335 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2336 ? Instruction::BitCast
2337 : Instruction::ZExt;
2338 return CreateCast(CastOp, V, DestTy, Name);
2339 }
2340
2341 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2342 Instruction::CastOps CastOp =
2343 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2344 ? Instruction::BitCast
2345 : Instruction::SExt;
2346 return CreateCast(CastOp, V, DestTy, Name);
2347 }
2348
2349 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2350 Instruction::CastOps CastOp =
2351 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2352 ? Instruction::BitCast
2353 : Instruction::Trunc;
2354 return CreateCast(CastOp, V, DestTy, Name);
2355 }
2356
2358 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2359 FMFSource FMFSource = {}) {
2360 if (V->getType() == DestTy)
2361 return V;
2362 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2363 return Folded;
2364 Instruction *Cast = CastInst::Create(Op, V, DestTy);
2365 if (isa<FPMathOperator>(Cast))
2366 setFPAttrs(Cast, FPMathTag, FMFSource.get(FMF));
2367 return Insert(Cast, Name);
2368 }
2369
2371 const Twine &Name = "") {
2372 if (V->getType() == DestTy)
2373 return V;
2374 if (auto *VC = dyn_cast<Constant>(V))
2375 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2376 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2377 }
2378
2379 // With opaque pointers enabled, this can be substituted with
2380 // CreateAddrSpaceCast.
2381 // TODO: Replace uses of this method and remove the method itself.
2383 const Twine &Name = "") {
2384 if (V->getType() == DestTy)
2385 return V;
2386
2387 if (auto *VC = dyn_cast<Constant>(V)) {
2388 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
2389 Name);
2390 }
2391
2393 Name);
2394 }
2395
2397 const Twine &Name = "") {
2398 Instruction::CastOps CastOp =
2399 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2400 ? Instruction::Trunc
2401 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2402 return CreateCast(CastOp, V, DestTy, Name);
2403 }
2404
2406 const Twine &Name = "") {
2407 if (V->getType() == DestTy)
2408 return V;
2409 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2410 return CreatePtrToInt(V, DestTy, Name);
2411 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2412 return CreateIntToPtr(V, DestTy, Name);
2413
2414 return CreateBitCast(V, DestTy, Name);
2415 }
2416
2417 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "",
2418 MDNode *FPMathTag = nullptr) {
2419 Instruction::CastOps CastOp =
2420 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2421 ? Instruction::FPTrunc
2422 : Instruction::FPExt;
2423 return CreateCast(CastOp, V, DestTy, Name, FPMathTag);
2424 }
2425
2427 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource = {},
2428 const Twine &Name = "", MDNode *FPMathTag = nullptr,
2429 std::optional<RoundingMode> Rounding = std::nullopt,
2430 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2431
2432 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2433 // compile time error, instead of converting the string to bool for the
2434 // isSigned parameter.
2435 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2436
2437 /// Cast between aggregate types that must have identical structure but may
2438 /// differ in their leaf types. The leaf values are recursively extracted,
2439 /// casted, and then reinserted into a value of type DestTy. The leaf types
2440 /// must be castable using a bitcast or ptrcast, because signedness is
2441 /// not specified.
2443
2444 /// Create a chain of casts to convert V to NewTy, preserving the bit pattern
2445 /// of V. This may involve multiple casts (e.g., ptr -> i64 -> <2 x i32>).
2446 /// The created cast instructions are inserted into the current basic block.
2447 /// If no casts are needed, V is returned.
2449 Type *NewTy);
2450
2451 //===--------------------------------------------------------------------===//
2452 // Instruction creation methods: Compare Instructions
2453 //===--------------------------------------------------------------------===//
2454
2455 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
2456 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
2457 }
2458
2459 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
2460 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
2461 }
2462
2463 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2464 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
2465 }
2466
2467 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2468 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
2469 }
2470
2471 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
2472 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
2473 }
2474
2475 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
2476 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
2477 }
2478
2479 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
2480 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
2481 }
2482
2483 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
2484 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
2485 }
2486
2487 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
2488 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
2489 }
2490
2491 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
2492 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
2493 }
2494
2495 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2496 MDNode *FPMathTag = nullptr) {
2497 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2498 }
2499
2500 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
2501 MDNode *FPMathTag = nullptr) {
2502 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2503 }
2504
2505 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
2506 MDNode *FPMathTag = nullptr) {
2507 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2508 }
2509
2510 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
2511 MDNode *FPMathTag = nullptr) {
2512 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2513 }
2514
2515 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
2516 MDNode *FPMathTag = nullptr) {
2517 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2518 }
2519
2520 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
2521 MDNode *FPMathTag = nullptr) {
2522 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2523 }
2524
2525 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
2526 MDNode *FPMathTag = nullptr) {
2527 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2528 }
2529
2530 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
2531 MDNode *FPMathTag = nullptr) {
2532 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2533 }
2534
2535 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
2536 MDNode *FPMathTag = nullptr) {
2537 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2538 }
2539
2540 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
2541 MDNode *FPMathTag = nullptr) {
2542 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2543 }
2544
2545 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
2546 MDNode *FPMathTag = nullptr) {
2547 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2548 }
2549
2550 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
2551 MDNode *FPMathTag = nullptr) {
2552 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2553 }
2554
2555 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
2556 MDNode *FPMathTag = nullptr) {
2557 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2558 }
2559
2560 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
2561 MDNode *FPMathTag = nullptr) {
2562 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2563 }
2564
2566 const Twine &Name = "") {
2567 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2568 return V;
2569 return Insert(new ICmpInst(P, LHS, RHS), Name);
2570 }
2571
2572 // Create a quiet floating-point comparison (i.e. one that raises an FP
2573 // exception only in the case where an input is a signaling NaN).
2574 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2576 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2577 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, false);
2578 }
2579
2580 // Create a quiet floating-point comparison (i.e. one that raises an FP
2581 // exception only in the case where an input is a signaling NaN).
2582 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2584 FMFSource FMFSource, const Twine &Name = "",
2585 MDNode *FPMathTag = nullptr) {
2586 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, FMFSource, false);
2587 }
2588
2590 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2592 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2593 : CreateICmp(Pred, LHS, RHS, Name);
2594 }
2595
2596 // Create a signaling floating-point comparison (i.e. one that raises an FP
2597 // exception whenever an input is any NaN, signaling or quiet).
2598 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2600 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2601 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, {}, true);
2602 }
2603
2604private:
2605 // Helper routine to create either a signaling or a quiet FP comparison.
2606 LLVM_ABI Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2607 const Twine &Name, MDNode *FPMathTag,
2608 FMFSource FMFSource, bool IsSignaling);
2609
2610public:
2613 const Twine &Name = "",
2614 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2615
2616 //===--------------------------------------------------------------------===//
2617 // Instruction creation methods: Other Instructions
2618 //===--------------------------------------------------------------------===//
2619
2620 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2621 const Twine &Name = "") {
2622 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2623 if (isa<FPMathOperator>(Phi))
2624 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2625 return Insert(Phi, Name);
2626 }
2627
2628private:
2629 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2630 const Twine &Name = "", FMFSource FMFSource = {},
2631 ArrayRef<OperandBundleDef> OpBundles = {});
2632
2633public:
2635 ArrayRef<Value *> Args = {}, const Twine &Name = "",
2636 MDNode *FPMathTag = nullptr) {
2637 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2638 if (IsFPConstrained)
2640 if (isa<FPMathOperator>(CI))
2641 setFPAttrs(CI, FPMathTag, FMF);
2642 return Insert(CI, Name);
2643 }
2644
2646 FMFSource FMFSource, const Twine &Name = "",
2647 MDNode *FPMathTag = nullptr) {
2648 return CreateCall(FTy, Callee, Args, DefaultOperandBundles, FMFSource, Name,
2649 FPMathTag);
2650 }
2651
2654 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2655 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2656 if (IsFPConstrained)
2658 if (isa<FPMathOperator>(CI))
2659 setFPAttrs(CI, FPMathTag, FMF);
2660 return Insert(CI, Name);
2661 }
2662
2665 FMFSource FMFSource, const Twine &Name = "",
2666 MDNode *FPMathTag = nullptr) {
2667 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2668 if (IsFPConstrained)
2670 if (isa<FPMathOperator>(CI))
2671 setFPAttrs(CI, FPMathTag, FMFSource.get(FMF));
2672 return Insert(CI, Name);
2673 }
2674
2676 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2677 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2678 FPMathTag);
2679 }
2680
2682 FMFSource FMFSource, const Twine &Name = "",
2683 MDNode *FPMathTag = nullptr) {
2684 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2685 FMFSource, Name, FPMathTag);
2686 }
2687
2690 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2691 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2692 OpBundles, Name, FPMathTag);
2693 }
2694
2697 FMFSource FMFSource, const Twine &Name = "",
2698 MDNode *FPMathTag = nullptr) {
2699 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2700 OpBundles, FMFSource, Name, FPMathTag);
2701 }
2702
2704 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2705 std::optional<RoundingMode> Rounding = std::nullopt,
2706 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2707
2709 Value *False,
2711 const Twine &Name = "");
2712
2714 Value *False,
2717 const Twine &Name = "");
2718
2720 const Twine &Name = "",
2721 Instruction *MDFrom = nullptr);
2723 FMFSource FMFSource, const Twine &Name = "",
2724 Instruction *MDFrom = nullptr);
2725
2726 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
2727 return Insert(new VAArgInst(List, Ty), Name);
2728 }
2729
2731 const Twine &Name = "") {
2732 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2733 return V;
2734 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
2735 }
2736
2738 const Twine &Name = "") {
2739 return CreateExtractElement(Vec, getInt64(Idx), Name);
2740 }
2741
2742 Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
2743 const Twine &Name = "") {
2744 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2745 }
2746
2748 const Twine &Name = "") {
2749 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2750 }
2751
2753 const Twine &Name = "") {
2754 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2755 return V;
2756 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2757 }
2758
2760 const Twine &Name = "") {
2761 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2762 }
2763
2765 const Twine &Name = "") {
2766 SmallVector<int, 16> IntMask;
2768 return CreateShuffleVector(V1, V2, IntMask, Name);
2769 }
2770
2771 /// See class ShuffleVectorInst for a description of the mask representation.
2773 const Twine &Name = "") {
2774 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2775 return V;
2776 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2777 }
2778
2779 /// Create a unary shuffle. The second vector operand of the IR instruction
2780 /// is poison.
2782 const Twine &Name = "") {
2783 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2784 }
2785
2787 const Twine &Name = "");
2788
2790 const Twine &Name = "") {
2791 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2792 return V;
2793 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2794 }
2795
2797 const Twine &Name = "") {
2798 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2799 return V;
2800 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2801 }
2802
2803 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2804 const Twine &Name = "") {
2805 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2806 }
2807
2808 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2809 return Insert(new FreezeInst(V), Name);
2810 }
2811
2813 const Twine &Name = "") {
2814 if (Value *V = Folder.FoldBitInsert(Base, Val, Offset))
2815 return V;
2816 return Insert(BitInsertInst::Create(Base, Val, Offset), Name);
2817 }
2818
2820 const Twine &Name = "") {
2821 if (Value *V = Folder.FoldBitExtract(Ty, Src, Offset))
2822 return V;
2823 return Insert(BitExtractInst::Create(Ty, Src, Offset), Name);
2824 }
2825
2826 //===--------------------------------------------------------------------===//
2827 // Utility creation methods
2828 //===--------------------------------------------------------------------===//
2829
2830 /// Return a boolean value testing if \p Arg == 0.
2831 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2832 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2833 }
2834
2835 /// Return a boolean value testing if \p Arg != 0.
2836 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2837 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2838 }
2839
2840 /// Return a boolean value testing if \p Arg < 0.
2841 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2842 return CreateICmpSLT(Arg, ConstantInt::getNullValue(Arg->getType()), Name);
2843 }
2844
2845 /// Return a boolean value testing if \p Arg > -1.
2846 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2848 Name);
2849 }
2850
2851 /// Return the difference between two pointer values. The returned value
2852 /// type is the address type of the pointers.
2853 LLVM_ABI Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "",
2854 bool IsNUW = false);
2855
2856 /// Return the difference between two pointer values, dividing out the size
2857 /// of the pointed-to objects. The returned value type is the address type
2858 /// of the pointers.
2859 ///
2860 /// This is intended to implement C-style pointer subtraction. As such, the
2861 /// pointers must be appropriately aligned for their element types and
2862 /// pointing into the same object.
2864 const Twine &Name = "");
2865
2866 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2867 /// different from pointer to i8, it's casted to pointer to i8 in the same
2868 /// address space before call and casted back to Ptr type after call.
2870
2871 /// Return a vector value that contains the vector V reversed
2872 LLVM_ABI Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2873
2874 /// Create a vector.splice.left intrinsic call, or a shufflevector that
2875 /// produces the same result if the result type is a fixed-length vector and
2876 /// \p Offset is a constant.
2878 const Twine &Name = "");
2879
2881 const Twine &Name = "") {
2882 return CreateVectorSpliceLeft(V1, V2, getInt32(Offset), Name);
2883 }
2884
2885 /// Create a vector.splice.right intrinsic call, or a shufflevector that
2886 /// produces the same result if the result type is a fixed-length vector and
2887 /// \p Offset is a constant.
2889 const Twine &Name = "");
2890
2892 const Twine &Name = "") {
2893 return CreateVectorSpliceRight(V1, V2, getInt32(Offset), Name);
2894 }
2895
2896 /// Return a vector value that contains \arg V broadcasted to \p
2897 /// NumElts elements.
2898 LLVM_ABI Value *CreateVectorSplat(unsigned NumElts, Value *V,
2899 const Twine &Name = "");
2900
2901 /// Return a vector value that contains \arg V broadcasted to \p
2902 /// EC elements.
2904 const Twine &Name = "");
2905
2907 unsigned Dimension,
2908 unsigned LastIndex,
2909 MDNode *DbgInfo);
2910
2912 unsigned FieldIndex,
2913 MDNode *DbgInfo);
2914
2916 unsigned Index,
2917 unsigned FieldIndex,
2918 MDNode *DbgInfo);
2919
2920 LLVM_ABI Value *createIsFPClass(Value *FPNum, unsigned Test);
2921
2922private:
2923 /// Helper function that creates an assume intrinsic call that
2924 /// represents an alignment assumption on the provided pointer \p PtrValue
2925 /// with offset \p OffsetValue and alignment value \p AlignValue.
2926 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2927 Value *PtrValue, Value *AlignValue,
2928 Value *OffsetValue);
2929
2930public:
2931 /// Create an assume intrinsic call that represents an alignment
2932 /// assumption on the provided pointer.
2933 ///
2934 /// An optional offset can be provided, and if it is provided, the offset
2935 /// must be subtracted from the provided pointer to get the pointer with the
2936 /// specified alignment.
2938 Value *PtrValue,
2939 uint64_t Alignment,
2940 Value *OffsetValue = nullptr);
2941
2942 /// Create an assume intrinsic call that represents an alignment
2943 /// assumption on the provided pointer.
2944 ///
2945 /// An optional offset can be provided, and if it is provided, the offset
2946 /// must be subtracted from the provided pointer to get the pointer with the
2947 /// specified alignment.
2948 ///
2949 /// This overload handles the condition where the Alignment is dependent
2950 /// on an existing value rather than a static value.
2952 Value *PtrValue,
2953 Value *Alignment,
2954 Value *OffsetValue = nullptr);
2955
2956 /// Create an assume intrinsic call that represents a dereferencable
2957 /// assumption on the provided pointer.
2959 Value *SizeValue);
2960
2961 /// Create an assume intrinsic call that represents a nonnull assumption on
2962 /// the provided pointer.
2964
2966};
2967
2968/// This provides a uniform API for creating instructions and inserting
2969/// them into a basic block: either at the end of a BasicBlock, or at a specific
2970/// iterator location in a block.
2971///
2972/// Note that the builder does not expose the full generality of LLVM
2973/// instructions. For access to extra instruction properties, use the mutators
2974/// (e.g. setVolatile) on the instructions after they have been
2975/// created. Convenience state exists to specify fast-math flags and fp-math
2976/// tags.
2977///
2978/// The first template argument specifies a class to use for creating constants.
2979/// This defaults to creating minimally folded constants. The second template
2980/// argument allows clients to specify custom insertion hooks that are called on
2981/// every newly created insertion.
2982template <typename FolderTy = ConstantFolder,
2983 typename InserterTy = IRBuilderDefaultInserter>
2984class IRBuilder : public IRBuilderBase {
2985private:
2986 FolderTy Folder;
2987 InserterTy Inserter;
2988
2989 static void CallInsertHelper(const IRBuilderBase &IRB, Instruction *I,
2990 const Twine &Name,
2992 static_cast<const IRBuilder *>(&IRB)->Inserter.InsertHelper(I, Name,
2993 InsertPt);
2994 }
2995
2996public:
2997 [[deprecated("Use the overload taking Module instead")]]
2998 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter)
2999 : IRBuilderBase(C, this->Folder, CallInsertHelper), Folder(Folder),
3000 Inserter(Inserter) {}
3001
3002 [[deprecated("Use the overload taking Module instead")]]
3003 IRBuilder(LLVMContext &C, FolderTy Folder)
3004 : IRBuilderBase(C, this->Folder, CallInsertHelper), Folder(Folder) {}
3005
3006 [[deprecated("Use the overload taking Module instead")]]
3008 : IRBuilderBase(C, this->Folder, CallInsertHelper) {}
3009
3010 IRBuilder(Module &M, FolderTy Folder, InserterTy Inserter)
3011 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper),
3012 Folder(Folder), Inserter(Inserter) {}
3013
3014 IRBuilder(Module &M, FolderTy Folder)
3015 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper),
3016 Folder(Folder) {}
3017
3018 explicit IRBuilder(Module &M)
3019 : IRBuilderBase(M.getContext(), this->Folder, CallInsertHelper) {}
3020
3021 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder)
3022 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper),
3023 Folder(Folder) {
3024 SetInsertPoint(TheBB);
3025 }
3026
3027 explicit IRBuilder(BasicBlock *TheBB)
3028 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper) {
3029 SetInsertPoint(TheBB);
3030 }
3031
3033 : IRBuilderBase(IP->getContext(), this->Folder, CallInsertHelper) {
3034 SetInsertPoint(IP);
3035 }
3036
3037 [[deprecated("Use the overload without BasicBlock argument instead")]]
3038 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder)
3039 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper),
3040 Folder(Folder) {
3041 SetInsertPoint(IP);
3042 }
3043
3044 [[deprecated("Use the overload without BasicBlock argument instead")]]
3046 : IRBuilderBase(TheBB->getContext(), this->Folder, CallInsertHelper) {
3047 SetInsertPoint(IP);
3048 }
3049
3050 IRBuilder(BasicBlock::iterator IP, FolderTy Folder, InserterTy Inserter)
3051 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3052 CallInsertHelper),
3053 Folder(Folder), Inserter(Inserter) {
3054 SetInsertPoint(IP);
3055 }
3056
3057 IRBuilder(BasicBlock::iterator IP, FolderTy Folder)
3058 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3059 CallInsertHelper),
3060 Folder(Folder) {
3061 SetInsertPoint(IP);
3062 }
3063
3065 : IRBuilderBase(IP.getNodeParent()->getContext(), this->Folder,
3066 CallInsertHelper) {
3067 SetInsertPoint(IP);
3068 }
3069
3070 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
3071 /// or FastMathFlagGuard instead.
3072 IRBuilder(const IRBuilder &) = delete;
3073
3074 InserterTy &getInserter() { return Inserter; }
3075 const InserterTy &getInserter() const { return Inserter; }
3076};
3077
3078template <typename FolderTy, typename InserterTy>
3079IRBuilder(LLVMContext &, FolderTy, InserterTy)
3082template <typename FolderTy, typename InserterTy>
3084template <typename FolderTy>
3087template <typename FolderTy>
3091template <typename FolderTy>
3094template <typename FolderTy, typename InserterTy>
3095IRBuilder(BasicBlock::iterator, FolderTy, InserterTy)
3097template <typename FolderTy>
3100
3101/// Unwrap C API builder reference.
3103
3104} // end namespace llvm
3105
3106#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:1494
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2333
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2520
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
Definition IRBuilder.h:1083
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:443
Value * CreateExtractVector(Type *DstType, Value *SrcVec, uint64_t Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1119
Value * CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2599
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:1468
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1347
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:1659
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2471
Value * CreateFPTruncFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2279
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2054
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:2321
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:2545
CallInst * CreateStructuredAlloca(Type *BaseType, const Twine &Name="")
Definition IRBuilder.h:1898
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2747
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1504
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition IRBuilder.h:1942
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:1922
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1654
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:2575
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition IRBuilder.h:1342
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:2742
Value * CreateVectorSpliceLeft(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2880
Value * CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1545
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:2110
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition IRBuilder.h:1971
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:2023
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1883
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition IRBuilder.h:344
Value * CreateBitExtract(Type *Ty, Value *Src, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2819
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition IRBuilder.h:1139
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1275
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:510
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:2796
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1583
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:1248
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1575
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:2145
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:507
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2688
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:1692
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:1540
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:1917
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1799
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2730
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:538
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:2479
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:1937
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2525
Value * CreateStructuredGEP(Type *BaseType, Value *PtrBase, ArrayRef< Value * > Indices, const Twine &Name="")
Definition IRBuilder.h:1998
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Definition IRBuilder.h:558
Value * CreateNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsNUW, bool IsNSW, const Twine &Name="")
Definition IRBuilder.h:1747
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2212
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:654
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:1215
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1635
UnreachableInst * CreateUnreachable()
Definition IRBuilder.h:1357
Value * CreateBitInsert(Value *Base, Value *Val, Value *Offset, const Twine &Name="")
Definition IRBuilder.h:2812
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:2274
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2370
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:2302
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:1711
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2789
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1579
ConstantInt * getTrue()
Get the constant value for i1 true.
Definition IRBuilder.h:448
StoreInst * CreateStore(Value *Val, Value *Ptr, const LoadStoreInstProperties &Props)
Definition IRBuilder.h:1932
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:2139
Value * Insert(Value *V, const Twine &Name="") const
Definition IRBuilder.h:159
LandingPadInst * CreateLandingPad(Type *Ty, unsigned NumClauses, const Twine &Name="")
Definition IRBuilder.h:2803
Value * CreateFPExtFMF(Value *V, Type *DestTy, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2294
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition IRBuilder.h:1059
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:2483
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:1253
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:2663
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:2240
Value * CreateVectorSpliceRight(Value *V1, Value *V2, uint32_t Offset, const Twine &Name="")
Definition IRBuilder.h:2891
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2066
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2560
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:177
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition IRBuilder.h:2084
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition IRBuilder.h:1964
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:586
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition IRBuilder.h:1317
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:2206
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2341
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2540
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2311
Value * CreateFreeze(Value *V, const Twine &Name="")
Definition IRBuilder.h:2808
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2695
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:1201
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args={}, const Twine &Name="")
Create a callbr instruction.
Definition IRBuilder.h:1291
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:1531
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:580
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition IRBuilder.h:525
Value * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1111
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition IRBuilder.h:2029
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:458
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2091
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
Definition IRBuilder.h:2357
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition IRBuilder.h:2846
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition IRBuilder.h:1353
LLVM_ABI CallInst * CreateRangeAssumption(Value *Int, ConstantRange Range)
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition IRBuilder.h:1330
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition IRBuilder.h:1191
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:1430
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:2254
Value * CreateVScale(Type *Ty, const Twine &Name="")
Create a call to llvm.vscale.<Ty>().
Definition IRBuilder.h:935
Value * CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1564
BasicBlock * GetInsertBlock() const
Definition IRBuilder.h:174
Type * getHalfTy()
Fetch the type representing a 16-bit floating point value.
Definition IRBuilder.h:543
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:2510
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:530
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition IRBuilder.h:2018
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1464
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:1601
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:2382
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:2781
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:2130
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1559
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1472
Value * CreateFAbs(Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fabs intrinsic.
Definition IRBuilder.h:1024
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2555
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:2459
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1434
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
Definition IRBuilder.h:520
Value * CreateFCmpFMF(CmpInst::Predicate P, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2583
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:473
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:696
CatchSwitchInst * CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, unsigned NumHandlers, const Twine &Name="")
Definition IRBuilder.h:1335
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:839
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:1857
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition IRBuilder.h:1829
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition IRBuilder.h:1913
UncondBrInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition IRBuilder.h:1209
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:1104
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1769
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:2759
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1525
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:2772
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:2515
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:468
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:1042
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2405
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2589
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1784
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2417
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2491
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition IRBuilder.h:2620
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:2652
CondBrInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition IRBuilder.h:1224
Value * CreateNot(Value *V, const Twine &Name="")
Definition IRBuilder.h:1853
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:1238
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2455
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:1736
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2535
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:1054
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition IRBuilder.h:535
Value * CreateCountTrailingZeroElems(Type *ResTy, Value *Mask, bool ZeroIsPoison=true, const Twine &Name="")
Create a call to llvm.experimental_cttz_elts.
Definition IRBuilder.h:1153
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition IRBuilder.h:2841
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:1438
Value * CreateFMA(Value *Factor1, Value *Factor2, Value *Summand, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fma intrinsic.
Definition IRBuilder.h:1091
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2316
ByteType * getByte128Ty()
Fetch the type representing a 128-bit byte.
Definition IRBuilder.h:504
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended from a 64-bit value.
Definition IRBuilder.h:478
Value * CreateDisjointOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1617
ByteType * getByte16Ty()
Fetch the type representing a 16-bit byte.
Definition IRBuilder.h:495
Value * CreateCopySign(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the copysign intrinsic.
Definition IRBuilder.h:1076
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:2463
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:1910
Value * CreateUnOpFMF(Instruction::UnaryOps Opc, Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1863
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:620
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1510
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:599
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:1016
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2194
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:2764
LLVMContext & getContext() const
Definition IRBuilder.h:178
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2495
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1569
FastMathFlags & getFastMathFlags()
Definition IRBuilder.h:280
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition IRBuilder.h:1186
ByteType * getByte32Ty()
Fetch the type representing a 32-bit byte.
Definition IRBuilder.h:498
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:1070
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1447
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition IRBuilder.h:2045
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition IRBuilder.h:2075
Value * CreateMinNum(Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create call to the minnum intrinsic.
Definition IRBuilder.h:1030
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1283
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1928
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:1421
Value * CreateExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact, const Twine &Name="")
Definition IRBuilder.h:1759
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2306
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1485
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition IRBuilder.h:453
VAArgInst * CreateVAArg(Value *List, Type *Ty, const Twine &Name="")
Definition IRBuilder.h:2726
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1481
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Definition IRBuilder.h:553
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition IRBuilder.h:2836
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:854
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2634
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1519
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:574
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:2180
Value * CreateScaledPtrAdd(Value *Ptr, TypeSize Scale, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition IRBuilder.h:2160
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:568
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:1730
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2752
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2060
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:1310
ByteType * getByte8Ty()
Fetch the type representing an 8-bit byte.
Definition IRBuilder.h:492
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2487
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition IRBuilder.h:463
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:1299
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:988
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2467
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:2396
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2530
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:2831
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:668
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2500
CallInst * CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:676
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition IRBuilder.h:1147
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:563
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args={}, const Twine &Name="")
Definition IRBuilder.h:1264
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:2120
Value * CreateOr(ArrayRef< Value * > Ops)
Definition IRBuilder.h:1609
Value * CreateFAddFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1640
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1777
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1890
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="", GEPNoWrapFlags NWFlags=GEPNoWrapFlags::none())
Definition IRBuilder.h:2035
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition IRBuilder.h:2737
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition IRBuilder.h:1956
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1605
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:1064
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:501
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:2102
Value * CreateIntCast(Value *, Type *, const char *)=delete
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2289
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:1550
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2675
Value * CreateFNegFMF(Value *V, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1843
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1621
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2681
IRBuilderBase(const IRBuilderBase &)=delete
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2349
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2475
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2266
LLVM_ABI Value * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2565
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:1673
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition IRBuilder.h:1947
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1838
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:1591
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:515
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
Definition IRBuilder.h:483
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:1697
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1498
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:2227
ResumeInst * CreateResume(Value *Exn)
Definition IRBuilder.h:1326
Value * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition IRBuilder.h:1125
Type * getBFloatTy()
Fetch the type representing a 16-bit brain floating point value.
Definition IRBuilder.h:548
Value * CreateFMulFMF(Value *L, Value *R, FMFSource FMFSource, const Twine &Name="", MDNode *FPMD=nullptr)
Definition IRBuilder.h:1678
Value * CreateXor(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition IRBuilder.h:1627
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:1455
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:1133
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:1716
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition IRBuilder.h:1631
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:1984
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:1834
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:2505
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Definition IRBuilder.h:704
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:1451
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2550
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2247
void enableGEPCanonicalization()
Definition IRBuilder.h:348
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2645
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:2984
IRBuilder(Module &M)
Definition IRBuilder.h:3018
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(BasicBlock *TheBB)
Definition IRBuilder.h:3027
IRBuilder(Instruction *IP)
Definition IRBuilder.h:3032
IRBuilder(BasicBlock *TheBB, FolderTy Folder)
Definition IRBuilder.h:3021
IRBuilder(LLVMContext &C, FolderTy Folder)
Definition IRBuilder.h:3003
InserterTy & getInserter()
Definition IRBuilder.h:3074
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:2998
IRBuilder(Module &M, FolderTy Folder)
Definition IRBuilder.h:3014
IRBuilder(LLVMContext &C)
Definition IRBuilder.h:3007
IRBuilder(BasicBlock::iterator IP, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:3050
IRBuilder(Module &M, FolderTy Folder, InserterTy Inserter)
Definition IRBuilder.h:3010
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder)
Definition IRBuilder.h:3038
IRBuilder(BasicBlock::iterator IP, FolderTy Folder)
Definition IRBuilder.h:3057
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP)
Definition IRBuilder.h:3045
IRBuilder(BasicBlock::iterator IP)
Definition IRBuilder.h:3064
const InserterTy & getInserter() const
Definition IRBuilder.h:3075
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:396
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