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