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