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