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