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