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