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