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