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