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