LLVM 19.0.0git
IRBuilder.h
Go to the documentation of this file.
1//===- llvm/IRBuilder.h - Builder for LLVM Instructions ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the IRBuilder class, which is used as a convenient way
10// to create LLVM instructions with a consistent and simplified interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_IRBUILDER_H
15#define LLVM_IR_IRBUILDER_H
16
17#include "llvm-c/Types.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/Twine.h"
22#include "llvm/IR/BasicBlock.h"
23#include "llvm/IR/Constant.h"
25#include "llvm/IR/Constants.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/DebugLoc.h"
29#include "llvm/IR/FPEnv.h"
30#include "llvm/IR/Function.h"
32#include "llvm/IR/InstrTypes.h"
33#include "llvm/IR/Instruction.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/LLVMContext.h"
37#include "llvm/IR/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,
224 llvm::MDNode::get(getContext(), std::nullopt));
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,
642 ArrayRef<OperandBundleDef> Bundles = std::nullopt);
643
645 Value *Size, Align Alignment,
646 uint32_t ElementSize,
647 MDNode *TBAATag = nullptr,
648 MDNode *ScopeTag = nullptr,
649 MDNode *NoAliasTag = nullptr);
650
651 /// Create and insert a memcpy between the specified pointers.
652 ///
653 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
654 /// specified, it will be added to the instruction. Likewise with alias.scope
655 /// and noalias tags.
657 MaybeAlign SrcAlign, uint64_t Size,
658 bool isVolatile = false, MDNode *TBAATag = nullptr,
659 MDNode *TBAAStructTag = nullptr,
660 MDNode *ScopeTag = nullptr,
661 MDNode *NoAliasTag = nullptr) {
662 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
663 isVolatile, TBAATag, TBAAStructTag, ScopeTag,
664 NoAliasTag);
665 }
666
668 Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
669 MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
670 MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
671 MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr);
672
674 MaybeAlign SrcAlign, Value *Size,
675 bool isVolatile = false, MDNode *TBAATag = nullptr,
676 MDNode *TBAAStructTag = nullptr,
677 MDNode *ScopeTag = nullptr,
678 MDNode *NoAliasTag = nullptr) {
679 return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
680 SrcAlign, Size, isVolatile, TBAATag,
681 TBAAStructTag, ScopeTag, NoAliasTag);
682 }
683
684 CallInst *
686 MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
687 MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
688 MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr) {
689 return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
690 SrcAlign, Size, isVolatile, TBAATag,
691 TBAAStructTag, ScopeTag, NoAliasTag);
692 }
693
694 /// Create and insert an element unordered-atomic memcpy between the
695 /// specified pointers.
696 ///
697 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
698 ///
699 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
700 /// specified, it will be added to the instruction. Likewise with alias.scope
701 /// and noalias tags.
703 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
704 uint32_t ElementSize, MDNode *TBAATag = nullptr,
705 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
706 MDNode *NoAliasTag = nullptr);
707
709 MaybeAlign SrcAlign, uint64_t Size,
710 bool isVolatile = false, MDNode *TBAATag = nullptr,
711 MDNode *ScopeTag = nullptr,
712 MDNode *NoAliasTag = nullptr) {
713 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
714 isVolatile, TBAATag, ScopeTag, NoAliasTag);
715 }
716
718 MaybeAlign SrcAlign, Value *Size,
719 bool isVolatile = false, MDNode *TBAATag = nullptr,
720 MDNode *ScopeTag = nullptr,
721 MDNode *NoAliasTag = nullptr) {
722 return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
723 SrcAlign, Size, isVolatile, TBAATag,
724 /*TBAAStructTag=*/nullptr, ScopeTag,
725 NoAliasTag);
726 }
727
728 /// \brief Create and insert an element unordered-atomic memmove between the
729 /// specified pointers.
730 ///
731 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
732 /// respectively.
733 ///
734 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
735 /// specified, it will be added to the instruction. Likewise with alias.scope
736 /// and noalias tags.
738 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
739 uint32_t ElementSize, MDNode *TBAATag = nullptr,
740 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
741 MDNode *NoAliasTag = nullptr);
742
743private:
744 CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
745
746public:
747 /// Create a sequential vector fadd reduction intrinsic of the source vector.
748 /// The first parameter is a scalar accumulator value. An unordered reduction
749 /// can be created by adding the reassoc fast-math flag to the resulting
750 /// sequential reduction.
752
753 /// Create a sequential vector fmul reduction intrinsic of the source vector.
754 /// The first parameter is a scalar accumulator value. An unordered reduction
755 /// can be created by adding the reassoc fast-math flag to the resulting
756 /// sequential reduction.
758
759 /// Create a vector int add reduction intrinsic of the source vector.
761
762 /// Create a vector int mul reduction intrinsic of the source vector.
764
765 /// Create a vector int AND reduction intrinsic of the source vector.
767
768 /// Create a vector int OR reduction intrinsic of the source vector.
770
771 /// Create a vector int XOR reduction intrinsic of the source vector.
773
774 /// Create a vector integer max reduction intrinsic of the source
775 /// vector.
776 CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
777
778 /// Create a vector integer min reduction intrinsic of the source
779 /// vector.
780 CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
781
782 /// Create a vector float max reduction intrinsic of the source
783 /// vector.
785
786 /// Create a vector float min reduction intrinsic of the source
787 /// vector.
789
790 /// Create a vector float maximum reduction intrinsic of the source
791 /// vector. This variant follows the NaN and signed zero semantic of
792 /// llvm.maximum intrinsic.
794
795 /// Create a vector float minimum reduction intrinsic of the source
796 /// vector. This variant follows the NaN and signed zero semantic of
797 /// llvm.minimum intrinsic.
799
800 /// Create a lifetime.start intrinsic.
801 ///
802 /// If the pointer isn't i8* it will be converted.
804
805 /// Create a lifetime.end intrinsic.
806 ///
807 /// If the pointer isn't i8* it will be converted.
809
810 /// Create a call to invariant.start intrinsic.
811 ///
812 /// If the pointer isn't i8* it will be converted.
814
815 /// Create a call to llvm.threadlocal.address intrinsic.
817
818 /// Create a call to Masked Load intrinsic
819 CallInst *CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask,
820 Value *PassThru = nullptr, const Twine &Name = "");
821
822 /// Create a call to Masked Store intrinsic
823 CallInst *CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment,
824 Value *Mask);
825
826 /// Create a call to Masked Gather intrinsic
827 CallInst *CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment,
828 Value *Mask = nullptr, Value *PassThru = nullptr,
829 const Twine &Name = "");
830
831 /// Create a call to Masked Scatter intrinsic
832 CallInst *CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment,
833 Value *Mask = nullptr);
834
835 /// Create a call to Masked Expand Load intrinsic
836 CallInst *CreateMaskedExpandLoad(Type *Ty, Value *Ptr, Value *Mask = nullptr,
837 Value *PassThru = nullptr,
838 const Twine &Name = "");
839
840 /// Create a call to Masked Compress Store intrinsic
842 Value *Mask = nullptr);
843
844 /// Return an all true boolean vector (mask) with \p NumElts lanes.
847 return Constant::getAllOnesValue(VTy);
848 }
849
850 /// Create an assume intrinsic call that allows the optimizer to
851 /// assume that the provided condition will be true.
852 ///
853 /// The optional argument \p OpBundles specifies operand bundles that are
854 /// added to the call instruction.
855 CallInst *
857 ArrayRef<OperandBundleDef> OpBundles = std::nullopt);
858
859 /// Create a llvm.experimental.noalias.scope.decl intrinsic call.
863 MetadataAsValue::get(Context, ScopeTag));
864 }
865
866 /// Create a call to the experimental.gc.statepoint intrinsic to
867 /// start a new statepoint sequence.
869 FunctionCallee ActualCallee,
870 ArrayRef<Value *> CallArgs,
871 std::optional<ArrayRef<Value *>> DeoptArgs,
872 ArrayRef<Value *> GCArgs,
873 const Twine &Name = "");
874
875 /// Create a call to the experimental.gc.statepoint intrinsic to
876 /// start a new statepoint sequence.
878 FunctionCallee ActualCallee, uint32_t Flags,
879 ArrayRef<Value *> CallArgs,
880 std::optional<ArrayRef<Use>> TransitionArgs,
881 std::optional<ArrayRef<Use>> DeoptArgs,
882 ArrayRef<Value *> GCArgs,
883 const Twine &Name = "");
884
885 /// Conveninence function for the common case when CallArgs are filled
886 /// in using ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
887 /// .get()'ed to get the Value pointer.
889 FunctionCallee ActualCallee,
890 ArrayRef<Use> CallArgs,
891 std::optional<ArrayRef<Value *>> DeoptArgs,
892 ArrayRef<Value *> GCArgs,
893 const Twine &Name = "");
894
895 /// Create an invoke to the experimental.gc.statepoint intrinsic to
896 /// start a new statepoint sequence.
897 InvokeInst *
899 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
900 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
901 std::optional<ArrayRef<Value *>> DeoptArgs,
902 ArrayRef<Value *> GCArgs, const Twine &Name = "");
903
904 /// Create an invoke to the experimental.gc.statepoint intrinsic to
905 /// start a new statepoint sequence.
907 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
908 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
909 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
910 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
911 const Twine &Name = "");
912
913 // Convenience function for the common case when CallArgs are filled in using
914 // ArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
915 // get the Value *.
916 InvokeInst *
918 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
919 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
920 std::optional<ArrayRef<Value *>> DeoptArgs,
921 ArrayRef<Value *> GCArgs, const Twine &Name = "");
922
923 /// Create a call to the experimental.gc.result intrinsic to extract
924 /// the result from a call wrapped in a statepoint.
926 Type *ResultType,
927 const Twine &Name = "");
928
929 /// Create a call to the experimental.gc.relocate intrinsics to
930 /// project the relocated value of one pointer from the statepoint.
932 int BaseOffset,
933 int DerivedOffset,
934 Type *ResultType,
935 const Twine &Name = "");
936
937 /// Create a call to the experimental.gc.pointer.base intrinsic to get the
938 /// base pointer for the specified derived pointer.
939 CallInst *CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name = "");
940
941 /// Create a call to the experimental.gc.get.pointer.offset intrinsic to get
942 /// the offset of the specified derived pointer from its base.
943 CallInst *CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name = "");
944
945 /// Create a call to llvm.vscale, multiplied by \p Scaling. The type of VScale
946 /// will be the same type as that of \p Scaling.
947 Value *CreateVScale(Constant *Scaling, const Twine &Name = "");
948
949 /// Create an expression which evaluates to the number of elements in \p EC
950 /// at runtime.
952
953 /// Create an expression which evaluates to the number of units in \p Size
954 /// at runtime. This works for both units of bits and bytes.
956
957 /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
958 Value *CreateStepVector(Type *DstType, const Twine &Name = "");
959
960 /// Create a call to intrinsic \p ID with 1 operand which is mangled on its
961 /// type.
963 Instruction *FMFSource = nullptr,
964 const Twine &Name = "");
965
966 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
967 /// first type.
969 Instruction *FMFSource = nullptr,
970 const Twine &Name = "");
971
972 /// Create a call to intrinsic \p ID with \p Args, mangled using \p Types. If
973 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
974 /// the intrinsic.
977 Instruction *FMFSource = nullptr,
978 const Twine &Name = "");
979
980 /// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
981 /// \p FMFSource is provided, copy fast-math-flags from that instruction to
982 /// the intrinsic.
985 Instruction *FMFSource = nullptr,
986 const Twine &Name = "");
987
988 /// Create call to the minnum intrinsic.
990 if (IsFPConstrained) {
992 Intrinsic::experimental_constrained_minnum, LHS, RHS, nullptr, Name);
993 }
994
995 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, nullptr, Name);
996 }
997
998 /// Create call to the maxnum intrinsic.
1000 if (IsFPConstrained) {
1002 Intrinsic::experimental_constrained_maxnum, LHS, RHS, nullptr, Name);
1003 }
1004
1005 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, nullptr, Name);
1006 }
1007
1008 /// Create call to the minimum intrinsic.
1010 return CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS, nullptr, Name);
1011 }
1012
1013 /// Create call to the maximum intrinsic.
1015 return CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS, nullptr, Name);
1016 }
1017
1018 /// Create call to the copysign intrinsic.
1020 Instruction *FMFSource = nullptr,
1021 const Twine &Name = "") {
1022 return CreateBinaryIntrinsic(Intrinsic::copysign, LHS, RHS, FMFSource,
1023 Name);
1024 }
1025
1026 /// Create a call to the arithmetic_fence intrinsic.
1028 const Twine &Name = "") {
1029 return CreateIntrinsic(Intrinsic::arithmetic_fence, DstType, Val, nullptr,
1030 Name);
1031 }
1032
1033 /// Create a call to the vector.extract intrinsic.
1035 const Twine &Name = "") {
1036 return CreateIntrinsic(Intrinsic::vector_extract,
1037 {DstType, SrcVec->getType()}, {SrcVec, Idx}, nullptr,
1038 Name);
1039 }
1040
1041 /// Create a call to the vector.insert intrinsic.
1042 CallInst *CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec,
1043 Value *Idx, const Twine &Name = "") {
1044 return CreateIntrinsic(Intrinsic::vector_insert,
1045 {DstType, SubVec->getType()}, {SrcVec, SubVec, Idx},
1046 nullptr, Name);
1047 }
1048
1049 /// Create a call to llvm.stacksave
1051 const DataLayout &DL = BB->getDataLayout();
1052 return CreateIntrinsic(Intrinsic::stacksave, {DL.getAllocaPtrType(Context)},
1053 {}, nullptr, Name);
1054 }
1055
1056 /// Create a call to llvm.stackrestore
1058 return CreateIntrinsic(Intrinsic::stackrestore, {Ptr->getType()}, {Ptr},
1059 nullptr, Name);
1060 }
1061
1062private:
1063 /// Create a call to a masked intrinsic with given Id.
1064 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
1065 ArrayRef<Type *> OverloadedTypes,
1066 const Twine &Name = "");
1067
1068 //===--------------------------------------------------------------------===//
1069 // Instruction creation methods: Terminators
1070 //===--------------------------------------------------------------------===//
1071
1072private:
1073 /// Helper to add branch weight and unpredictable metadata onto an
1074 /// instruction.
1075 /// \returns The annotated instruction.
1076 template <typename InstTy>
1077 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
1078 if (Weights)
1079 I->setMetadata(LLVMContext::MD_prof, Weights);
1080 if (Unpredictable)
1081 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
1082 return I;
1083 }
1084
1085public:
1086 /// Create a 'ret void' instruction.
1089 }
1090
1091 /// Create a 'ret <val>' instruction.
1093 return Insert(ReturnInst::Create(Context, V));
1094 }
1095
1096 /// Create a sequence of N insertvalue instructions,
1097 /// with one Value from the retVals array each, that build a aggregate
1098 /// return value one value at a time, and a ret instruction to return
1099 /// the resulting aggregate value.
1100 ///
1101 /// This is a convenience function for code that uses aggregate return values
1102 /// as a vehicle for having multiple return values.
1103 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
1105 for (unsigned i = 0; i != N; ++i)
1106 V = CreateInsertValue(V, retVals[i], i, "mrv");
1107 return Insert(ReturnInst::Create(Context, V));
1108 }
1109
1110 /// Create an unconditional 'br label X' instruction.
1112 return Insert(BranchInst::Create(Dest));
1113 }
1114
1115 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1116 /// instruction.
1118 MDNode *BranchWeights = nullptr,
1119 MDNode *Unpredictable = nullptr) {
1120 return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
1121 BranchWeights, Unpredictable));
1122 }
1123
1124 /// Create a conditional 'br Cond, TrueDest, FalseDest'
1125 /// instruction. Copy branch meta data if available.
1127 Instruction *MDSrc) {
1128 BranchInst *Br = BranchInst::Create(True, False, Cond);
1129 if (MDSrc) {
1130 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
1131 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
1132 Br->copyMetadata(*MDSrc, WL);
1133 }
1134 return Insert(Br);
1135 }
1136
1137 /// Create a switch instruction with the specified value, default dest,
1138 /// and with a hint for the number of cases that will be added (for efficient
1139 /// allocation).
1140 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
1141 MDNode *BranchWeights = nullptr,
1142 MDNode *Unpredictable = nullptr) {
1143 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
1144 BranchWeights, Unpredictable));
1145 }
1146
1147 /// Create an indirect branch instruction with the specified address
1148 /// operand, with an optional hint for the number of destinations that will be
1149 /// added (for efficient allocation).
1150 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
1151 return Insert(IndirectBrInst::Create(Addr, NumDests));
1152 }
1153
1154 /// Create an invoke instruction.
1156 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1157 ArrayRef<Value *> Args,
1159 const Twine &Name = "") {
1160 InvokeInst *II =
1161 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles);
1162 if (IsFPConstrained)
1164 return Insert(II, Name);
1165 }
1167 BasicBlock *NormalDest, BasicBlock *UnwindDest,
1168 ArrayRef<Value *> Args = std::nullopt,
1169 const Twine &Name = "") {
1170 InvokeInst *II =
1171 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
1172 if (IsFPConstrained)
1174 return Insert(II, Name);
1175 }
1176
1178 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
1180 const Twine &Name = "") {
1181 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1182 NormalDest, UnwindDest, Args, OpBundles, Name);
1183 }
1184
1186 BasicBlock *UnwindDest,
1187 ArrayRef<Value *> Args = std::nullopt,
1188 const Twine &Name = "") {
1189 return CreateInvoke(Callee.getFunctionType(), Callee.getCallee(),
1190 NormalDest, UnwindDest, Args, Name);
1191 }
1192
1193 /// \brief Create a callbr instruction.
1195 BasicBlock *DefaultDest,
1196 ArrayRef<BasicBlock *> IndirectDests,
1197 ArrayRef<Value *> Args = std::nullopt,
1198 const Twine &Name = "") {
1199 return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests,
1200 Args), Name);
1201 }
1203 BasicBlock *DefaultDest,
1204 ArrayRef<BasicBlock *> IndirectDests,
1205 ArrayRef<Value *> Args,
1207 const Twine &Name = "") {
1208 return Insert(
1209 CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args,
1210 OpBundles), Name);
1211 }
1212
1214 ArrayRef<BasicBlock *> IndirectDests,
1215 ArrayRef<Value *> Args = std::nullopt,
1216 const Twine &Name = "") {
1217 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1218 DefaultDest, IndirectDests, Args, Name);
1219 }
1221 ArrayRef<BasicBlock *> IndirectDests,
1222 ArrayRef<Value *> Args,
1224 const Twine &Name = "") {
1225 return CreateCallBr(Callee.getFunctionType(), Callee.getCallee(),
1226 DefaultDest, IndirectDests, Args, Name);
1227 }
1228
1230 return Insert(ResumeInst::Create(Exn));
1231 }
1232
1234 BasicBlock *UnwindBB = nullptr) {
1235 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
1236 }
1237
1239 unsigned NumHandlers,
1240 const Twine &Name = "") {
1241 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
1242 Name);
1243 }
1244
1246 const Twine &Name = "") {
1247 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
1248 }
1249
1251 ArrayRef<Value *> Args = std::nullopt,
1252 const Twine &Name = "") {
1253 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
1254 }
1255
1257 return Insert(CatchReturnInst::Create(CatchPad, BB));
1258 }
1259
1261 return Insert(new UnreachableInst(Context));
1262 }
1263
1264 //===--------------------------------------------------------------------===//
1265 // Instruction creation methods: Binary Operators
1266 //===--------------------------------------------------------------------===//
1267private:
1268 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
1269 Value *LHS, Value *RHS,
1270 const Twine &Name,
1271 bool HasNUW, bool HasNSW) {
1273 if (HasNUW) BO->setHasNoUnsignedWrap();
1274 if (HasNSW) BO->setHasNoSignedWrap();
1275 return BO;
1276 }
1277
1278 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
1279 FastMathFlags FMF) const {
1280 if (!FPMD)
1281 FPMD = DefaultFPMathTag;
1282 if (FPMD)
1283 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
1284 I->setFastMathFlags(FMF);
1285 return I;
1286 }
1287
1288 Value *getConstrainedFPRounding(std::optional<RoundingMode> Rounding) {
1290
1291 if (Rounding)
1292 UseRounding = *Rounding;
1293
1294 std::optional<StringRef> RoundingStr =
1295 convertRoundingModeToStr(UseRounding);
1296 assert(RoundingStr && "Garbage strict rounding mode!");
1297 auto *RoundingMDS = MDString::get(Context, *RoundingStr);
1298
1299 return MetadataAsValue::get(Context, RoundingMDS);
1300 }
1301
1302 Value *getConstrainedFPExcept(std::optional<fp::ExceptionBehavior> Except) {
1303 std::optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(
1304 Except.value_or(DefaultConstrainedExcept));
1305 assert(ExceptStr && "Garbage strict exception behavior!");
1306 auto *ExceptMDS = MDString::get(Context, *ExceptStr);
1307
1308 return MetadataAsValue::get(Context, ExceptMDS);
1309 }
1310
1311 Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
1312 assert(CmpInst::isFPPredicate(Predicate) &&
1313 Predicate != CmpInst::FCMP_FALSE &&
1314 Predicate != CmpInst::FCMP_TRUE &&
1315 "Invalid constrained FP comparison predicate!");
1316
1317 StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
1318 auto *PredicateMDS = MDString::get(Context, PredicateStr);
1319
1320 return MetadataAsValue::get(Context, PredicateMDS);
1321 }
1322
1323public:
1325 bool HasNUW = false, bool HasNSW = false) {
1326 if (Value *V =
1327 Folder.FoldNoWrapBinOp(Instruction::Add, LHS, RHS, HasNUW, HasNSW))
1328 return V;
1329 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW,
1330 HasNSW);
1331 }
1332
1334 return CreateAdd(LHS, RHS, Name, false, true);
1335 }
1336
1338 return CreateAdd(LHS, RHS, Name, true, false);
1339 }
1340
1342 bool HasNUW = false, bool HasNSW = false) {
1343 if (Value *V =
1344 Folder.FoldNoWrapBinOp(Instruction::Sub, LHS, RHS, HasNUW, HasNSW))
1345 return V;
1346 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW,
1347 HasNSW);
1348 }
1349
1351 return CreateSub(LHS, RHS, Name, false, true);
1352 }
1353
1355 return CreateSub(LHS, RHS, Name, true, false);
1356 }
1357
1359 bool HasNUW = false, bool HasNSW = false) {
1360 if (Value *V =
1361 Folder.FoldNoWrapBinOp(Instruction::Mul, LHS, RHS, HasNUW, HasNSW))
1362 return V;
1363 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW,
1364 HasNSW);
1365 }
1366
1368 return CreateMul(LHS, RHS, Name, false, true);
1369 }
1370
1372 return CreateMul(LHS, RHS, Name, true, false);
1373 }
1374
1376 bool isExact = false) {
1377 if (Value *V = Folder.FoldExactBinOp(Instruction::UDiv, LHS, RHS, isExact))
1378 return V;
1379 if (!isExact)
1380 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
1381 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
1382 }
1383
1385 return CreateUDiv(LHS, RHS, Name, true);
1386 }
1387
1389 bool isExact = false) {
1390 if (Value *V = Folder.FoldExactBinOp(Instruction::SDiv, LHS, RHS, isExact))
1391 return V;
1392 if (!isExact)
1393 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1394 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1395 }
1396
1398 return CreateSDiv(LHS, RHS, Name, true);
1399 }
1400
1402 if (Value *V = Folder.FoldBinOp(Instruction::URem, LHS, RHS))
1403 return V;
1404 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1405 }
1406
1408 if (Value *V = Folder.FoldBinOp(Instruction::SRem, LHS, RHS))
1409 return V;
1410 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1411 }
1412
1414 bool HasNUW = false, bool HasNSW = false) {
1415 if (Value *V =
1416 Folder.FoldNoWrapBinOp(Instruction::Shl, LHS, RHS, HasNUW, HasNSW))
1417 return V;
1418 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1419 HasNUW, HasNSW);
1420 }
1421
1422 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1423 bool HasNUW = false, bool HasNSW = false) {
1424 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1425 HasNUW, HasNSW);
1426 }
1427
1429 bool HasNUW = false, bool HasNSW = false) {
1430 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1431 HasNUW, HasNSW);
1432 }
1433
1435 bool isExact = false) {
1436 if (Value *V = Folder.FoldExactBinOp(Instruction::LShr, LHS, RHS, isExact))
1437 return V;
1438 if (!isExact)
1439 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1440 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1441 }
1442
1443 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1444 bool isExact = false) {
1445 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1446 }
1447
1449 bool isExact = false) {
1450 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1451 }
1452
1454 bool isExact = false) {
1455 if (Value *V = Folder.FoldExactBinOp(Instruction::AShr, LHS, RHS, isExact))
1456 return V;
1457 if (!isExact)
1458 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1459 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1460 }
1461
1462 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1463 bool isExact = false) {
1464 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1465 }
1466
1468 bool isExact = false) {
1469 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1470 }
1471
1473 if (auto *V = Folder.FoldBinOp(Instruction::And, LHS, RHS))
1474 return V;
1475 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1476 }
1477
1478 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1479 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1480 }
1481
1483 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1484 }
1485
1487 assert(!Ops.empty());
1488 Value *Accum = Ops[0];
1489 for (unsigned i = 1; i < Ops.size(); i++)
1490 Accum = CreateAnd(Accum, Ops[i]);
1491 return Accum;
1492 }
1493
1495 if (auto *V = Folder.FoldBinOp(Instruction::Or, LHS, RHS))
1496 return V;
1497 return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1498 }
1499
1500 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1501 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1502 }
1503
1505 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1506 }
1507
1509 assert(!Ops.empty());
1510 Value *Accum = Ops[0];
1511 for (unsigned i = 1; i < Ops.size(); i++)
1512 Accum = CreateOr(Accum, Ops[i]);
1513 return Accum;
1514 }
1515
1517 if (Value *V = Folder.FoldBinOp(Instruction::Xor, LHS, RHS))
1518 return V;
1519 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1520 }
1521
1522 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1523 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1524 }
1525
1527 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1528 }
1529
1530 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1531 MDNode *FPMD = nullptr) {
1532 if (IsFPConstrained)
1533 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1534 L, R, nullptr, Name, FPMD);
1535
1536 if (Value *V = Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMF))
1537 return V;
1538 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF);
1539 return Insert(I, Name);
1540 }
1541
1542 /// Copy fast-math-flags from an instruction rather than using the builder's
1543 /// default FMF.
1545 const Twine &Name = "") {
1546 if (IsFPConstrained)
1547 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd,
1548 L, R, FMFSource, Name);
1549
1550 FastMathFlags FMF = FMFSource->getFastMathFlags();
1551 if (Value *V = Folder.FoldBinOpFMF(Instruction::FAdd, L, R, FMF))
1552 return V;
1553 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr, FMF);
1554 return Insert(I, Name);
1555 }
1556
1557 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1558 MDNode *FPMD = nullptr) {
1559 if (IsFPConstrained)
1560 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1561 L, R, nullptr, Name, FPMD);
1562
1563 if (Value *V = Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMF))
1564 return V;
1565 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF);
1566 return Insert(I, Name);
1567 }
1568
1569 /// Copy fast-math-flags from an instruction rather than using the builder's
1570 /// default FMF.
1572 const Twine &Name = "") {
1573 if (IsFPConstrained)
1574 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub,
1575 L, R, FMFSource, Name);
1576
1577 FastMathFlags FMF = FMFSource->getFastMathFlags();
1578 if (Value *V = Folder.FoldBinOpFMF(Instruction::FSub, L, R, FMF))
1579 return V;
1580 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr, FMF);
1581 return Insert(I, Name);
1582 }
1583
1584 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1585 MDNode *FPMD = nullptr) {
1586 if (IsFPConstrained)
1587 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1588 L, R, nullptr, Name, FPMD);
1589
1590 if (Value *V = Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMF))
1591 return V;
1592 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF);
1593 return Insert(I, Name);
1594 }
1595
1596 /// Copy fast-math-flags from an instruction rather than using the builder's
1597 /// default FMF.
1599 const Twine &Name = "") {
1600 if (IsFPConstrained)
1601 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul,
1602 L, R, FMFSource, Name);
1603
1604 FastMathFlags FMF = FMFSource->getFastMathFlags();
1605 if (Value *V = Folder.FoldBinOpFMF(Instruction::FMul, L, R, FMF))
1606 return V;
1607 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr, FMF);
1608 return Insert(I, Name);
1609 }
1610
1611 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1612 MDNode *FPMD = nullptr) {
1613 if (IsFPConstrained)
1614 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1615 L, R, nullptr, Name, FPMD);
1616
1617 if (Value *V = Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMF))
1618 return V;
1619 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF);
1620 return Insert(I, Name);
1621 }
1622
1623 /// Copy fast-math-flags from an instruction rather than using the builder's
1624 /// default FMF.
1626 const Twine &Name = "") {
1627 if (IsFPConstrained)
1628 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
1629 L, R, FMFSource, Name);
1630
1631 FastMathFlags FMF = FMFSource->getFastMathFlags();
1632 if (Value *V = Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMF))
1633 return V;
1634 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr, FMF);
1635 return Insert(I, Name);
1636 }
1637
1638 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1639 MDNode *FPMD = nullptr) {
1640 if (IsFPConstrained)
1641 return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem,
1642 L, R, nullptr, Name, FPMD);
1643
1644 if (Value *V = Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMF)) return V;
1645 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(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_frem,
1655 L, R, FMFSource, Name);
1656
1657 FastMathFlags FMF = FMFSource->getFastMathFlags();
1658 if (Value *V = Folder.FoldBinOpFMF(Instruction::FRem, L, R, FMF)) return V;
1659 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr, FMF);
1660 return Insert(I, Name);
1661 }
1662
1664 Value *LHS, Value *RHS, const Twine &Name = "",
1665 MDNode *FPMathTag = nullptr) {
1666 if (Value *V = Folder.FoldBinOp(Opc, LHS, RHS)) return V;
1667 Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1668 if (isa<FPMathOperator>(BinOp))
1669 setFPAttrs(BinOp, FPMathTag, FMF);
1670 return Insert(BinOp, Name);
1671 }
1672
1673 Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "") {
1674 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1675 return CreateSelect(Cond1, Cond2,
1677 }
1678
1679 Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "") {
1680 assert(Cond2->getType()->isIntOrIntVectorTy(1));
1681 return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
1682 Cond2, Name);
1683 }
1684
1686 const Twine &Name = "") {
1687 switch (Opc) {
1688 case Instruction::And:
1689 return CreateLogicalAnd(Cond1, Cond2, Name);
1690 case Instruction::Or:
1691 return CreateLogicalOr(Cond1, Cond2, Name);
1692 default:
1693 break;
1694 }
1695 llvm_unreachable("Not a logical operation.");
1696 }
1697
1698 // NOTE: this is sequential, non-commutative, ordered reduction!
1700 assert(!Ops.empty());
1701 Value *Accum = Ops[0];
1702 for (unsigned i = 1; i < Ops.size(); i++)
1703 Accum = CreateLogicalOr(Accum, Ops[i]);
1704 return Accum;
1705 }
1706
1708 Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource = nullptr,
1709 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1710 std::optional<RoundingMode> Rounding = std::nullopt,
1711 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1712
1714 Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource = nullptr,
1715 const Twine &Name = "", MDNode *FPMathTag = nullptr,
1716 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
1717
1718 Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNSW = false) {
1719 return CreateSub(Constant::getNullValue(V->getType()), V, Name,
1720 /*HasNUW=*/0, HasNSW);
1721 }
1722
1723 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1724 return CreateNeg(V, Name, /*HasNSW=*/true);
1725 }
1726
1727 Value *CreateFNeg(Value *V, const Twine &Name = "",
1728 MDNode *FPMathTag = nullptr) {
1729 if (Value *Res = Folder.FoldUnOpFMF(Instruction::FNeg, V, FMF))
1730 return Res;
1731 return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), FPMathTag, FMF),
1732 Name);
1733 }
1734
1735 /// Copy fast-math-flags from an instruction rather than using the builder's
1736 /// default FMF.
1738 const Twine &Name = "") {
1739 FastMathFlags FMF = FMFSource->getFastMathFlags();
1740 if (Value *Res = Folder.FoldUnOpFMF(Instruction::FNeg, V, FMF))
1741 return Res;
1742 return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), nullptr, FMF),
1743 Name);
1744 }
1745
1746 Value *CreateNot(Value *V, const Twine &Name = "") {
1747 return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
1748 }
1749
1751 Value *V, const Twine &Name = "",
1752 MDNode *FPMathTag = nullptr) {
1753 if (Value *Res = Folder.FoldUnOpFMF(Opc, V, FMF))
1754 return Res;
1755 Instruction *UnOp = UnaryOperator::Create(Opc, V);
1756 if (isa<FPMathOperator>(UnOp))
1757 setFPAttrs(UnOp, FPMathTag, FMF);
1758 return Insert(UnOp, Name);
1759 }
1760
1761 /// Create either a UnaryOperator or BinaryOperator depending on \p Opc.
1762 /// Correct number of operands must be passed accordingly.
1763 Value *CreateNAryOp(unsigned Opc, ArrayRef<Value *> Ops,
1764 const Twine &Name = "", MDNode *FPMathTag = nullptr);
1765
1766 //===--------------------------------------------------------------------===//
1767 // Instruction creation methods: Memory Instructions
1768 //===--------------------------------------------------------------------===//
1769
1770 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1771 Value *ArraySize = nullptr, const Twine &Name = "") {
1772 const DataLayout &DL = BB->getDataLayout();
1773 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1774 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1775 }
1776
1777 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1778 const Twine &Name = "") {
1779 const DataLayout &DL = BB->getDataLayout();
1780 Align AllocaAlign = DL.getPrefTypeAlign(Ty);
1781 unsigned AddrSpace = DL.getAllocaAddrSpace();
1782 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize, AllocaAlign), Name);
1783 }
1784
1785 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
1786 /// converting the string to 'bool' for the isVolatile parameter.
1787 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1788 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1789 }
1790
1791 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1792 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), Name);
1793 }
1794
1795 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1796 const Twine &Name = "") {
1797 return CreateAlignedLoad(Ty, Ptr, MaybeAlign(), isVolatile, Name);
1798 }
1799
1800 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1801 return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile);
1802 }
1803
1805 const char *Name) {
1806 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1807 }
1808
1810 const Twine &Name = "") {
1811 return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name);
1812 }
1813
1815 bool isVolatile, const Twine &Name = "") {
1816 if (!Align) {
1817 const DataLayout &DL = BB->getDataLayout();
1818 Align = DL.getABITypeAlign(Ty);
1819 }
1820 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile, *Align), Name);
1821 }
1822
1824 bool isVolatile = false) {
1825 if (!Align) {
1826 const DataLayout &DL = BB->getDataLayout();
1827 Align = DL.getABITypeAlign(Val->getType());
1828 }
1829 return Insert(new StoreInst(Val, Ptr, isVolatile, *Align));
1830 }
1833 const Twine &Name = "") {
1834 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1835 }
1836
1839 AtomicOrdering SuccessOrdering,
1840 AtomicOrdering FailureOrdering,
1842 if (!Align) {
1843 const DataLayout &DL = BB->getDataLayout();
1844 Align = llvm::Align(DL.getTypeStoreSize(New->getType()));
1845 }
1846
1847 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, *Align, SuccessOrdering,
1848 FailureOrdering, SSID));
1849 }
1850
1852 Value *Val, MaybeAlign Align,
1853 AtomicOrdering Ordering,
1855 if (!Align) {
1856 const DataLayout &DL = BB->getDataLayout();
1857 Align = llvm::Align(DL.getTypeStoreSize(Val->getType()));
1858 }
1859
1860 return Insert(new AtomicRMWInst(Op, Ptr, Val, *Align, Ordering, SSID));
1861 }
1862
1864 const Twine &Name = "",
1866 if (auto *V = Folder.FoldGEP(Ty, Ptr, IdxList, NW))
1867 return V;
1868 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList, NW), Name);
1869 }
1870
1872 const Twine &Name = "") {
1873 return CreateGEP(Ty, Ptr, IdxList, Name, GEPNoWrapFlags::inBounds());
1874 }
1875
1876 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1877 const Twine &Name = "") {
1878 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1879
1880 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1881 return V;
1882
1884 }
1885
1887 const Twine &Name = "") {
1888 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1889
1890 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
1891 return V;
1892
1894 }
1895
1896 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1897 const Twine &Name = "") {
1898 Value *Idxs[] = {
1899 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1900 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1901 };
1902
1903 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::none()))
1904 return V;
1905
1906 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1907 }
1908
1910 unsigned Idx1, const Twine &Name = "") {
1911 Value *Idxs[] = {
1912 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1913 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1914 };
1915
1916 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
1917 return V;
1918
1920 }
1921
1923 const Twine &Name = "") {
1924 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1925
1926 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
1927 return V;
1928
1930 }
1931
1933 const Twine &Name = "") {
1934 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1935
1936 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
1937 return V;
1938
1940 }
1941
1943 const Twine &Name = "") {
1944 Value *Idxs[] = {
1945 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1946 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1947 };
1948
1949 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::none()))
1950 return V;
1951
1952 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1953 }
1954
1956 uint64_t Idx1, const Twine &Name = "") {
1957 Value *Idxs[] = {
1958 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1959 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1960 };
1961
1962 if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
1963 return V;
1964
1966 }
1967
1969 const Twine &Name = "") {
1970 return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1971 }
1972
1975 return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
1976 }
1977
1979 const Twine &Name = "") {
1980 return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
1982 }
1983
1984 /// Same as CreateGlobalString, but return a pointer with "i8*" type
1985 /// instead of a pointer to array of i8.
1986 ///
1987 /// If no module is given via \p M, it is take from the insertion point basic
1988 /// block.
1990 unsigned AddressSpace = 0,
1991 Module *M = nullptr, bool AddNull = true) {
1992 GlobalVariable *GV =
1993 CreateGlobalString(Str, Name, AddressSpace, M, AddNull);
1994 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1995 Constant *Indices[] = {Zero, Zero};
1997 Indices);
1998 }
1999
2000 //===--------------------------------------------------------------------===//
2001 // Instruction creation methods: Cast/Conversion Operators
2002 //===--------------------------------------------------------------------===//
2003
2004 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "",
2005 bool IsNUW = false, bool IsNSW = false) {
2006 if (V->getType() == DestTy)
2007 return V;
2008 if (Value *Folded = Folder.FoldCast(Instruction::Trunc, V, DestTy))
2009 return Folded;
2010 Instruction *I = CastInst::Create(Instruction::Trunc, V, DestTy);
2011 if (IsNUW)
2012 I->setHasNoUnsignedWrap();
2013 if (IsNSW)
2014 I->setHasNoSignedWrap();
2015 return Insert(I, Name);
2016 }
2017
2018 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
2019 bool IsNonNeg = false) {
2020 if (V->getType() == DestTy)
2021 return V;
2022 if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2023 return Folded;
2024 Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2025 if (IsNonNeg)
2026 I->setNonNeg();
2027 return I;
2028 }
2029
2030 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
2031 return CreateCast(Instruction::SExt, V, DestTy, Name);
2032 }
2033
2034 /// Create a ZExt or Trunc from the integer value V to DestTy. Return
2035 /// the value untouched if the type of V is already DestTy.
2037 const Twine &Name = "") {
2038 assert(V->getType()->isIntOrIntVectorTy() &&
2039 DestTy->isIntOrIntVectorTy() &&
2040 "Can only zero extend/truncate integers!");
2041 Type *VTy = V->getType();
2042 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2043 return CreateZExt(V, DestTy, Name);
2044 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2045 return CreateTrunc(V, DestTy, Name);
2046 return V;
2047 }
2048
2049 /// Create a SExt or Trunc from the integer value V to DestTy. Return
2050 /// the value untouched if the type of V is already DestTy.
2052 const Twine &Name = "") {
2053 assert(V->getType()->isIntOrIntVectorTy() &&
2054 DestTy->isIntOrIntVectorTy() &&
2055 "Can only sign extend/truncate integers!");
2056 Type *VTy = V->getType();
2057 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
2058 return CreateSExt(V, DestTy, Name);
2059 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
2060 return CreateTrunc(V, DestTy, Name);
2061 return V;
2062 }
2063
2064 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
2065 if (IsFPConstrained)
2066 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
2067 V, DestTy, nullptr, Name);
2068 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
2069 }
2070
2071 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
2072 if (IsFPConstrained)
2073 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
2074 V, DestTy, nullptr, Name);
2075 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
2076 }
2077
2078 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "",
2079 bool IsNonNeg = false) {
2080 if (IsFPConstrained)
2081 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp,
2082 V, DestTy, nullptr, Name);
2083 if (Value *Folded = Folder.FoldCast(Instruction::UIToFP, V, DestTy))
2084 return Folded;
2085 Instruction *I = Insert(new UIToFPInst(V, DestTy), Name);
2086 if (IsNonNeg)
2087 I->setNonNeg();
2088 return I;
2089 }
2090
2091 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
2092 if (IsFPConstrained)
2093 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp,
2094 V, DestTy, nullptr, Name);
2095 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
2096 }
2097
2099 const Twine &Name = "") {
2100 if (IsFPConstrained)
2102 Intrinsic::experimental_constrained_fptrunc, V, DestTy, nullptr,
2103 Name);
2104 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
2105 }
2106
2107 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
2108 if (IsFPConstrained)
2109 return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fpext,
2110 V, DestTy, nullptr, Name);
2111 return CreateCast(Instruction::FPExt, V, DestTy, Name);
2112 }
2113
2115 const Twine &Name = "") {
2116 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
2117 }
2118
2120 const Twine &Name = "") {
2121 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
2122 }
2123
2125 const Twine &Name = "") {
2126 return CreateCast(Instruction::BitCast, V, DestTy, Name);
2127 }
2128
2130 const Twine &Name = "") {
2131 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
2132 }
2133
2134 Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2135 Instruction::CastOps CastOp =
2136 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2137 ? Instruction::BitCast
2138 : Instruction::ZExt;
2139 return CreateCast(CastOp, V, DestTy, Name);
2140 }
2141
2142 Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2143 Instruction::CastOps CastOp =
2144 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2145 ? Instruction::BitCast
2146 : Instruction::SExt;
2147 return CreateCast(CastOp, V, DestTy, Name);
2148 }
2149
2150 Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") {
2151 Instruction::CastOps CastOp =
2152 V->getType()->getScalarSizeInBits() == DestTy->getScalarSizeInBits()
2153 ? Instruction::BitCast
2154 : Instruction::Trunc;
2155 return CreateCast(CastOp, V, DestTy, Name);
2156 }
2157
2159 const Twine &Name = "") {
2160 if (V->getType() == DestTy)
2161 return V;
2162 if (Value *Folded = Folder.FoldCast(Op, V, DestTy))
2163 return Folded;
2164 return Insert(CastInst::Create(Op, V, DestTy), Name);
2165 }
2166
2168 const Twine &Name = "") {
2169 if (V->getType() == DestTy)
2170 return V;
2171 if (auto *VC = dyn_cast<Constant>(V))
2172 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
2173 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
2174 }
2175
2176 // With opaque pointers enabled, this can be substituted with
2177 // CreateAddrSpaceCast.
2178 // TODO: Replace uses of this method and remove the method itself.
2180 const Twine &Name = "") {
2181 if (V->getType() == DestTy)
2182 return V;
2183
2184 if (auto *VC = dyn_cast<Constant>(V)) {
2186 Name);
2187 }
2188
2190 Name);
2191 }
2192
2194 const Twine &Name = "") {
2195 Instruction::CastOps CastOp =
2196 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2197 ? Instruction::Trunc
2198 : (isSigned ? Instruction::SExt : Instruction::ZExt);
2199 return CreateCast(CastOp, V, DestTy, Name);
2200 }
2201
2203 const Twine &Name = "") {
2204 if (V->getType() == DestTy)
2205 return V;
2206 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
2207 return CreatePtrToInt(V, DestTy, Name);
2208 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
2209 return CreateIntToPtr(V, DestTy, Name);
2210
2211 return CreateBitCast(V, DestTy, Name);
2212 }
2213
2214 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
2215 Instruction::CastOps CastOp =
2216 V->getType()->getScalarSizeInBits() > DestTy->getScalarSizeInBits()
2217 ? Instruction::FPTrunc
2218 : Instruction::FPExt;
2219 return CreateCast(CastOp, V, DestTy, Name);
2220 }
2221
2223 Intrinsic::ID ID, Value *V, Type *DestTy,
2224 Instruction *FMFSource = nullptr, const Twine &Name = "",
2225 MDNode *FPMathTag = nullptr,
2226 std::optional<RoundingMode> Rounding = std::nullopt,
2227 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2228
2229 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
2230 // compile time error, instead of converting the string to bool for the
2231 // isSigned parameter.
2232 Value *CreateIntCast(Value *, Type *, const char *) = delete;
2233
2234 //===--------------------------------------------------------------------===//
2235 // Instruction creation methods: Compare Instructions
2236 //===--------------------------------------------------------------------===//
2237
2240 }
2241
2244 }
2245
2248 }
2249
2252 }
2253
2256 }
2257
2260 }
2261
2264 }
2265
2268 }
2269
2272 }
2273
2276 }
2277
2279 MDNode *FPMathTag = nullptr) {
2280 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
2281 }
2282
2284 MDNode *FPMathTag = nullptr) {
2285 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
2286 }
2287
2289 MDNode *FPMathTag = nullptr) {
2290 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
2291 }
2292
2294 MDNode *FPMathTag = nullptr) {
2295 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
2296 }
2297
2299 MDNode *FPMathTag = nullptr) {
2300 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
2301 }
2302
2304 MDNode *FPMathTag = nullptr) {
2305 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
2306 }
2307
2309 MDNode *FPMathTag = nullptr) {
2310 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
2311 }
2312
2314 MDNode *FPMathTag = nullptr) {
2315 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
2316 }
2317
2319 MDNode *FPMathTag = nullptr) {
2320 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
2321 }
2322
2324 MDNode *FPMathTag = nullptr) {
2325 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
2326 }
2327
2329 MDNode *FPMathTag = nullptr) {
2330 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
2331 }
2332
2334 MDNode *FPMathTag = nullptr) {
2335 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
2336 }
2337
2339 MDNode *FPMathTag = nullptr) {
2340 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
2341 }
2342
2344 MDNode *FPMathTag = nullptr) {
2345 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
2346 }
2347
2349 const Twine &Name = "") {
2350 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
2351 return V;
2352 return Insert(new ICmpInst(P, LHS, RHS), Name);
2353 }
2354
2355 // Create a quiet floating-point comparison (i.e. one that raises an FP
2356 // exception only in the case where an input is a signaling NaN).
2357 // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
2359 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2360 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, false);
2361 }
2362
2364 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2365 return CmpInst::isFPPredicate(Pred)
2366 ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag)
2367 : CreateICmp(Pred, LHS, RHS, Name);
2368 }
2369
2370 // Create a signaling floating-point comparison (i.e. one that raises an FP
2371 // exception whenever an input is any NaN, signaling or quiet).
2372 // Note that this differs from CreateFCmp only if IsFPConstrained is true.
2374 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2375 return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, true);
2376 }
2377
2378private:
2379 // Helper routine to create either a signaling or a quiet FP comparison.
2380 Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2381 const Twine &Name, MDNode *FPMathTag,
2382 bool IsSignaling);
2383
2384public:
2387 const Twine &Name = "",
2388 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2389
2390 //===--------------------------------------------------------------------===//
2391 // Instruction creation methods: Other Instructions
2392 //===--------------------------------------------------------------------===//
2393
2394 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
2395 const Twine &Name = "") {
2396 PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2397 if (isa<FPMathOperator>(Phi))
2398 setFPAttrs(Phi, nullptr /* MDNode* */, FMF);
2399 return Insert(Phi, Name);
2400 }
2401
2402private:
2403 CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
2404 const Twine &Name = "",
2405 Instruction *FMFSource = nullptr,
2406 ArrayRef<OperandBundleDef> OpBundles = {});
2407
2408public:
2410 ArrayRef<Value *> Args = std::nullopt,
2411 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2412 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
2413 if (IsFPConstrained)
2415 if (isa<FPMathOperator>(CI))
2416 setFPAttrs(CI, FPMathTag, FMF);
2417 return Insert(CI, Name);
2418 }
2419
2422 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2423 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
2424 if (IsFPConstrained)
2426 if (isa<FPMathOperator>(CI))
2427 setFPAttrs(CI, FPMathTag, FMF);
2428 return Insert(CI, Name);
2429 }
2430
2432 ArrayRef<Value *> Args = std::nullopt,
2433 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2434 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args, Name,
2435 FPMathTag);
2436 }
2437
2440 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2441 return CreateCall(Callee.getFunctionType(), Callee.getCallee(), Args,
2442 OpBundles, Name, FPMathTag);
2443 }
2444
2446 Function *Callee, ArrayRef<Value *> Args, const Twine &Name = "",
2447 std::optional<RoundingMode> Rounding = std::nullopt,
2448 std::optional<fp::ExceptionBehavior> Except = std::nullopt);
2449
2450 Value *CreateSelect(Value *C, Value *True, Value *False,
2451 const Twine &Name = "", Instruction *MDFrom = nullptr);
2452
2454 return Insert(new VAArgInst(List, Ty), Name);
2455 }
2456
2458 const Twine &Name = "") {
2459 if (Value *V = Folder.FoldExtractElement(Vec, Idx))
2460 return V;
2462 }
2463
2465 const Twine &Name = "") {
2466 return CreateExtractElement(Vec, getInt64(Idx), Name);
2467 }
2468
2470 const Twine &Name = "") {
2471 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2472 }
2473
2475 const Twine &Name = "") {
2476 return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
2477 }
2478
2480 const Twine &Name = "") {
2481 if (Value *V = Folder.FoldInsertElement(Vec, NewElt, Idx))
2482 return V;
2483 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
2484 }
2485
2487 const Twine &Name = "") {
2488 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
2489 }
2490
2492 const Twine &Name = "") {
2493 SmallVector<int, 16> IntMask;
2494 ShuffleVectorInst::getShuffleMask(cast<Constant>(Mask), IntMask);
2495 return CreateShuffleVector(V1, V2, IntMask, Name);
2496 }
2497
2498 /// See class ShuffleVectorInst for a description of the mask representation.
2500 const Twine &Name = "") {
2501 if (Value *V = Folder.FoldShuffleVector(V1, V2, Mask))
2502 return V;
2503 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
2504 }
2505
2506 /// Create a unary shuffle. The second vector operand of the IR instruction
2507 /// is poison.
2509 const Twine &Name = "") {
2510 return CreateShuffleVector(V, PoisonValue::get(V->getType()), Mask, Name);
2511 }
2512
2514 const Twine &Name = "") {
2515 if (auto *V = Folder.FoldExtractValue(Agg, Idxs))
2516 return V;
2517 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
2518 }
2519
2521 const Twine &Name = "") {
2522 if (auto *V = Folder.FoldInsertValue(Agg, Val, Idxs))
2523 return V;
2524 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
2525 }
2526
2527 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
2528 const Twine &Name = "") {
2529 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
2530 }
2531
2532 Value *CreateFreeze(Value *V, const Twine &Name = "") {
2533 return Insert(new FreezeInst(V), Name);
2534 }
2535
2536 //===--------------------------------------------------------------------===//
2537 // Utility creation methods
2538 //===--------------------------------------------------------------------===//
2539
2540 /// Return a boolean value testing if \p Arg == 0.
2541 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
2542 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name);
2543 }
2544
2545 /// Return a boolean value testing if \p Arg != 0.
2546 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
2547 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name);
2548 }
2549
2550 /// Return a boolean value testing if \p Arg < 0.
2551 Value *CreateIsNeg(Value *Arg, const Twine &Name = "") {
2553 }
2554
2555 /// Return a boolean value testing if \p Arg > -1.
2556 Value *CreateIsNotNeg(Value *Arg, const Twine &Name = "") {
2558 Name);
2559 }
2560
2561 /// Return the i64 difference between two pointer values, dividing out
2562 /// the size of the pointed-to objects.
2563 ///
2564 /// This is intended to implement C-style pointer subtraction. As such, the
2565 /// pointers must be appropriately aligned for their element types and
2566 /// pointing into the same object.
2567 Value *CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS,
2568 const Twine &Name = "");
2569
2570 /// Create a launder.invariant.group intrinsic call. If Ptr type is
2571 /// different from pointer to i8, it's casted to pointer to i8 in the same
2572 /// address space before call and casted back to Ptr type after call.
2574
2575 /// \brief Create a strip.invariant.group intrinsic call. If Ptr type is
2576 /// different from pointer to i8, it's casted to pointer to i8 in the same
2577 /// address space before call and casted back to Ptr type after call.
2579
2580 /// Return a vector value that contains the vector V reversed
2581 Value *CreateVectorReverse(Value *V, const Twine &Name = "");
2582
2583 /// Return a vector splice intrinsic if using scalable vectors, otherwise
2584 /// return a shufflevector. If the immediate is positive, a vector is
2585 /// extracted from concat(V1, V2), starting at Imm. If the immediate
2586 /// is negative, we extract -Imm elements from V1 and the remaining
2587 /// elements from V2. Imm is a signed integer in the range
2588 /// -VL <= Imm < VL (where VL is the runtime vector length of the
2589 /// source/result vector)
2590 Value *CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
2591 const Twine &Name = "");
2592
2593 /// Return a vector value that contains \arg V broadcasted to \p
2594 /// NumElts elements.
2595 Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "");
2596
2597 /// Return a vector value that contains \arg V broadcasted to \p
2598 /// EC elements.
2599 Value *CreateVectorSplat(ElementCount EC, Value *V, const Twine &Name = "");
2600
2602 unsigned Dimension, unsigned LastIndex,
2603 MDNode *DbgInfo);
2604
2605 Value *CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex,
2606 MDNode *DbgInfo);
2607
2609 unsigned Index, unsigned FieldIndex,
2610 MDNode *DbgInfo);
2611
2612 Value *createIsFPClass(Value *FPNum, unsigned Test);
2613
2614private:
2615 /// Helper function that creates an assume intrinsic call that
2616 /// represents an alignment assumption on the provided pointer \p PtrValue
2617 /// with offset \p OffsetValue and alignment value \p AlignValue.
2618 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
2619 Value *PtrValue, Value *AlignValue,
2620 Value *OffsetValue);
2621
2622public:
2623 /// Create an assume intrinsic call that represents an alignment
2624 /// assumption on the provided pointer.
2625 ///
2626 /// An optional offset can be provided, and if it is provided, the offset
2627 /// must be subtracted from the provided pointer to get the pointer with the
2628 /// specified alignment.
2630 unsigned Alignment,
2631 Value *OffsetValue = nullptr);
2632
2633 /// Create an assume intrinsic call that represents an alignment
2634 /// assumption on the provided pointer.
2635 ///
2636 /// An optional offset can be provided, and if it is provided, the offset
2637 /// must be subtracted from the provided pointer to get the pointer with the
2638 /// specified alignment.
2639 ///
2640 /// This overload handles the condition where the Alignment is dependent
2641 /// on an existing value rather than a static value.
2643 Value *Alignment,
2644 Value *OffsetValue = nullptr);
2645};
2646
2647/// This provides a uniform API for creating instructions and inserting
2648/// them into a basic block: either at the end of a BasicBlock, or at a specific
2649/// iterator location in a block.
2650///
2651/// Note that the builder does not expose the full generality of LLVM
2652/// instructions. For access to extra instruction properties, use the mutators
2653/// (e.g. setVolatile) on the instructions after they have been
2654/// created. Convenience state exists to specify fast-math flags and fp-math
2655/// tags.
2656///
2657/// The first template argument specifies a class to use for creating constants.
2658/// This defaults to creating minimally folded constants. The second template
2659/// argument allows clients to specify custom insertion hooks that are called on
2660/// every newly created insertion.
2661template <typename FolderTy = ConstantFolder,
2662 typename InserterTy = IRBuilderDefaultInserter>
2663class IRBuilder : public IRBuilderBase {
2664private:
2665 FolderTy Folder;
2666 InserterTy Inserter;
2667
2668public:
2669 IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter = InserterTy(),
2670 MDNode *FPMathTag = nullptr,
2671 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2672 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles),
2673 Folder(Folder), Inserter(Inserter) {}
2674
2675 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
2676 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2677 : IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2678
2679 explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2680 MDNode *FPMathTag = nullptr,
2681 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2682 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2683 FPMathTag, OpBundles),
2684 Folder(Folder) {
2685 SetInsertPoint(TheBB);
2686 }
2687
2688 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2689 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2690 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2691 FPMathTag, OpBundles) {
2692 SetInsertPoint(TheBB);
2693 }
2694
2695 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2696 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2697 : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2698 OpBundles) {
2699 SetInsertPoint(IP);
2700 }
2701
2702 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2703 MDNode *FPMathTag = nullptr,
2704 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2705 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2706 FPMathTag, OpBundles),
2707 Folder(Folder) {
2708 SetInsertPoint(TheBB, IP);
2709 }
2710
2712 MDNode *FPMathTag = nullptr,
2713 ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2714 : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2715 FPMathTag, OpBundles) {
2716 SetInsertPoint(TheBB, IP);
2717 }
2718
2719 /// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2720 /// or FastMathFlagGuard instead.
2721 IRBuilder(const IRBuilder &) = delete;
2722
2723 InserterTy &getInserter() { return Inserter; }
2724 const InserterTy &getInserter() const { return Inserter; }
2725};
2726
2727template <typename FolderTy, typename InserterTy>
2728IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
2731template <typename FolderTy>
2736template <typename FolderTy>
2741
2742
2743// Create wrappers for C Binding types (see CBindingWrapping.h).
2745
2746} // end namespace llvm
2747
2748#endif // LLVM_IR_IRBUILDER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
std::string Name
uint64_t Size
static bool isSigned(unsigned int Opcode)
This file contains the declarations of entities that describe floating point environment and related ...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:77
an instruction to allocate memory on the stack
Definition: Instructions.h:60
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
Value handle that asserts if the Value is deleted.
Definition: ValueHandle.h:264
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:494
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:695
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:707
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
iterator end()
Definition: BasicBlock.h:451
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:209
const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
Definition: BasicBlock.cpp:294
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:167
const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Definition: BasicBlock.cpp:428
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1236
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args=std::nullopt, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:757
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:760
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:774
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:786
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:787
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:763
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:772
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:761
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:762
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:781
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:780
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:784
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:771
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:765
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:768
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:782
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:769
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:764
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:766
@ ICMP_EQ
equal
Definition: InstrTypes.h:778
@ ICMP_NE
not equal
Definition: InstrTypes.h:779
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:785
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:773
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:783
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:770
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition: InstrTypes.h:759
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:767
bool isFPPredicate() const
Definition: InstrTypes.h:864
static StringRef getPredicateName(Predicate P)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1267
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:850
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:857
This is an important base class in LLVM.
Definition: Constant.h:41
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:417
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:370
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
A debug info location.
Definition: DebugLoc.h:33
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
void clear()
Definition: FMF.h:61
An instruction for ordering other memory operations.
Definition: Instructions.h:419
This class represents a freeze function that returns random concrete value if an operand is either a ...
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
Class to represent function types.
Definition: DerivedTypes.h:103
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags none()
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Definition: Instructions.h:937
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:960
Type * getValueType() const
Definition: GlobalValue.h:296
This instruction compares its operands according to the predicate given to the constructor.
FastMathFlagGuard(const FastMathFlagGuard &)=delete
FastMathFlagGuard & operator=(const FastMathFlagGuard &)=delete
InsertPointGuard & operator=(const InsertPointGuard &)=delete
InsertPointGuard(const InsertPointGuard &)=delete
InsertPoint - A saved insertion point.
Definition: IRBuilder.h: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:1397
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2134
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:257
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2303
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:1544
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:2373
CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Definition: IRBuilder.cpp:705
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1166
BasicBlock * BB
Definition: IRBuilder.h:116
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1371
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:914
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:1107
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:438
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:418
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:687
Value * CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maxnum intrinsic.
Definition: IRBuilder.h:999
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2254
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1922
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Create a callbr instruction.
Definition: IRBuilder.h:1194
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1185
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:1118
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition: IRBuilder.h:1034
Value * CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2328
Value * CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2474
Value * CreateFPCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2214
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1407
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name="")
Definition: IRBuilder.h:1809
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1557
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:922
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2358
CatchPadInst * CreateCatchPad(Value *ParentPad, ArrayRef< Value * > Args, const Twine &Name="")
Definition: IRBuilder.h:1245
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2469
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:1448
AtomicCmpXchgInst * CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New, MaybeAlign Align, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1838
CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
Definition: IRBuilder.cpp:539
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition: IRBuilder.h:1876
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1770
void setDefaultOperandBundles(ArrayRef< OperandBundleDef > OpBundles)
Definition: IRBuilder.h:362
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
Definition: IRBuilder.h:1050
InvokeInst * CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:1177
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:508
Value * CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1896
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:673
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:2520
Value * CreateAnd(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1486
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:1150
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, Instruction *MDSrc)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:1126
Value * CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name="")
Definition: IRBuilder.h:1478
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:2438
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:1598
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:896
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1611
CallInst * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition: IRBuilder.h:1042
Value * CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1443
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:1571
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:1625
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2091
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:784
LoadInst * CreateLoad(Type *Ty, Value *Ptr, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1795
Value * CreateLogicalOr(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1699
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2457
Value * CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1685
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:2262
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2098
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition: IRBuilder.h:1804
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2308
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:2036
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:1651
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1530
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:1260
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:482
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:1062
CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles=std::nullopt)
Generate the IR for a call to the builtin free function.
Definition: IRBuilder.cpp:354
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:442
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:1166
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2167
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:1193
Value * CreateFRem(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1638
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition: IRBuilder.h:2513
Value * CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1482
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:2527
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:933
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:1737
Value * CreateMaximum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the maximum intrinsic.
Definition: IRBuilder.h:1014
Value * CreateMinNum(Value *LHS, Value *RHS, const Twine &Name="")
Create call to the minnum intrinsic.
Definition: IRBuilder.h:989
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1261
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:1307
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:579
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2266
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:1074
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:1091
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:1155
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:2064
Value * CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1942
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2343
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:172
Value * CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx, const Twine &Name="")
Definition: IRBuilder.h:1968
FenceInst * CreateFence(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, const Twine &Name="")
Definition: IRBuilder.h:1831
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:1220
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:905
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:2030
Value * CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2142
Value * CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2323
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2119
Value * CreateTypeSize(Type *DstType, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
Definition: IRBuilder.cpp:105
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:434
Value * CreateFreeze(Value *V, const Twine &Name="")
Definition: IRBuilder.h:2532
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:117
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1434
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:1886
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:1973
Value * CreateIsNotNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg > -1.
Definition: IRBuilder.h:2556
CatchReturnInst * CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB)
Definition: IRBuilder.h:1256
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:989
CleanupReturnInst * CreateCleanupRet(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB=nullptr)
Definition: IRBuilder.h:1233
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition: IRBuilder.h:2078
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:1092
Value * CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1333
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:1467
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:717
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:2293
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:1871
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:220
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1367
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:1500
Value * CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2179
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Definition: IRBuilder.cpp:1151
Value * CreateShuffleVector(Value *V, ArrayRef< int > Mask, const Twine &Name="")
Create a unary shuffle.
Definition: IRBuilder.h:2508
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:450
Value * CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1462
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1375
Value * CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2338
FastMathFlags FMF
Definition: IRBuilder.h:123
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2242
Value * CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1337
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:1863
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:1238
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition: IRBuilder.h:845
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1750
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
Definition: IRBuilder.h:1718
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const Twine &Name="")
Definition: IRBuilder.h:1791
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:446
CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
Definition: IRBuilder.cpp:302
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:470
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:474
Value * CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2486
Value * CreateShl(Value *LHS, uint64_t RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1428
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:2499
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:1103
Value * createIsFPClass(Value *FPNum, unsigned Test)
Definition: IRBuilder.cpp:1288
Value * CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2298
CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:466
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:1989
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:483
CallInst * CreateCall(FunctionCallee Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2431
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2202
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2363
const IRBuilderDefaultInserter & Inserter
Definition: IRBuilder.h:120
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2274
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Definition: IRBuilder.h:2394
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2420
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1746
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:1140
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2238
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:970
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2318
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:1009
IntegerType * getInt128Ty()
Fetch the type representing a 128-bit integer.
Definition: IRBuilder.h:533
Value * CreateIsNeg(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg < 0.
Definition: IRBuilder.h:2551
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:1341
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2124
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:1117
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:2246
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:1787
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1413
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:1006
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition: IRBuilder.h:2018
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:685
CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Definition: IRBuilder.cpp:552
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2491
LLVMContext & getContext() const
Definition: IRBuilder.h:173
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2278
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1472
FastMathFlags & getFastMathFlags()
Definition: IRBuilder.h:299
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:1087
Value * CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1350
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1909
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
Definition: IRBuilder.h:1955
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1242
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1800
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:454
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:599
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1324
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2114
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1388
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:2453
Value * CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1384
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:2546
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:861
Value * CreateShl(Value *LHS, const APInt &RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1422
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Definition: IRBuilder.h:1851
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:873
CleanupPadInst * CreateCleanupPad(Value *ParentPad, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1250
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition: IRBuilder.h:2004
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:497
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1494
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:1663
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition: IRBuilder.h:1111
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1673
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Definition: IRBuilder.cpp:100
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2479
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition: IRBuilder.h:1932
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:1021
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Definition: IRBuilder.h:166
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2270
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:373
ArrayRef< OperandBundleDef > DefaultOperandBundles
Definition: IRBuilder.h:129
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2158
CallBrInst * CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Definition: IRBuilder.h:1202
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2250
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:2193
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2313
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:2541
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2283
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
Definition: IRBuilder.h:1057
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:460
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
Value * CreateOr(ArrayRef< Value * > Ops)
Definition: IRBuilder.h:1508
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1777
Value * CreateExtractElement(Value *Vec, uint64_t Idx, const Twine &Name="")
Definition: IRBuilder.h:2464
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Definition: IRBuilder.h:1823
Value * CreateOr(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1504
void setConstrainedFPCallAttr(CallBase *I)
Definition: IRBuilder.h:358
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:840
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2409
CallBrInst * CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="")
Definition: IRBuilder.h:1213
const IRBuilderFolder & Folder
Definition: IRBuilder.h:119
Value * CreateInBoundsPtrAdd(Value *Ptr, Value *Offset, const Twine &Name="")
Definition: IRBuilder.h:1978
Value * CreateIntCast(Value *, Type *, const char *)=delete
CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.cpp:165
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1453
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
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2107
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1516
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:426
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2150
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2258
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2348
Value * CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name="")
Definition: IRBuilder.h:1679
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Definition: IRBuilder.h:1584
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name="")
Definition: IRBuilder.h:1814
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1727
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:884
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1401
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Definition: IRBuilder.cpp:110
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:656
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:708
Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1213
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
Definition: IRBuilder.h:2051
ResumeInst * CreateResume(Value *Exn)
Definition: IRBuilder.h:1229
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2129
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:1522
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Definition: IRBuilder.cpp:512
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1358
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
Definition: IRBuilder.cpp:563
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
Definition: IRBuilder.cpp:662
Value * CreateXor(Value *LHS, uint64_t RHS, const Twine &Name="")
Definition: IRBuilder.h:1526
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:1723
CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:478
Value * CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2288
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1134
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:631
Value * CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1354
Value * CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2333
CallInst * CreateArithmeticFence(Value *Val, Type *DstType, const Twine &Name="")
Create a call to the arithmetic_fence intrinsic.
Definition: IRBuilder.h:1027
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2071
Value * CreateCopySign(Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create call to the copysign intrinsic.
Definition: IRBuilder.h:1019
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:2663
IRBuilder(const IRBuilder &)=delete
Avoid copying the full IRBuilder.
IRBuilder(LLVMContext &C, FolderTy Folder, InserterTy Inserter=InserterTy(), MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2669
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2702
IRBuilder(Instruction *IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2695
IRBuilder(LLVMContext &C, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2675
InserterTy & getInserter()
Definition: IRBuilder.h:2723
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2711
IRBuilder(BasicBlock *TheBB, FolderTy Folder, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2679
IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag=nullptr, ArrayRef< OperandBundleDef > OpBundles=std::nullopt)
Definition: IRBuilder.h:2688
const InserterTy & getInserter() const
Definition: IRBuilder.h:2724
Indirect Branch Instruction.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Class to represent integer types.
Definition: DerivedTypes.h:40
Invoke instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
An instruction for reading from memory.
Definition: Instructions.h:173
Metadata node.
Definition: Metadata.h:1067
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:600
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:103
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Class to represent pointers.
Definition: DerivedTypes.h:646
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1814
Resume the propagation of an exception.
static ResumeInst * Create(Value *Exn, InsertPosition InsertBefore=nullptr)
Return a value (possibly void), from a function.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
This instruction constructs a fixed permutation of two input vectors.
ArrayRef< int > getShuffleMask() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:289
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Multiway switch.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static Type * getHalfTy(LLVMContext &C)
static Type * getDoubleTy(LLVMContext &C)
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:234
static IntegerType * getInt1Ty(LLVMContext &C)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt16Ty(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt128Ty(LLVMContext &C)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:262
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
This class represents a cast unsigned integer to floating point.
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
This function has undefined behavior.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:676
This class represents zero extension of integer types.
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: Types.h:110
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Rounding
Possible values of current rounding mode, which is specified in bits 23:22 of FPCR.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ System
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:57
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:38
@ ebStrict
This corresponds to "fpexcept.strict".
Definition: FPEnv.h:41
NodeAddr< UseNode * > Use
Definition: RDFGraph.h:385
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
AddressSpace
Definition: NVPTXBaseInfo.h:21
std::optional< StringRef > convertRoundingModeToStr(RoundingMode)
For any RoundingMode enumerator, returns a string valid as input in constrained intrinsic rounding mo...
Definition: FPEnv.cpp:37
std::optional< StringRef > convertExceptionBehaviorToStr(fp::ExceptionBehavior)
For any ExceptionBehavior enumerator, returns a string valid as input in constrained intrinsic except...
Definition: FPEnv.cpp:74
AtomicOrdering
Atomic ordering for LLVM's memory model.
RoundingMode
Rounding mode.
@ Dynamic
Denotes mode unknown at compile time.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:2051
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117