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